consensus/XDPoS: convert variables to const, close XFN-123 (#1688)

This commit is contained in:
Daniel Liu 2025-11-03 15:16:35 +08:00 committed by GitHub
parent fc748cc52a
commit 7614a0ad9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 34 deletions

View file

@ -97,10 +97,10 @@ func New(chainConfig *params.ChainConfig, db ethdb.Database) *XDPoS_v1 {
config: &conf,
db: db,
recents: lru.NewCache[common.Hash, *SnapshotV1](utils.InmemorySnapshots),
signatures: lru.NewCache[common.Hash, common.Address](utils.InmemorySnapshots),
verifiedHeaders: lru.NewCache[common.Hash, struct{}](utils.InmemorySnapshots),
validatorSignatures: lru.NewCache[common.Hash, common.Address](utils.InmemorySnapshots),
recents: lru.NewCache[common.Hash, *SnapshotV1](utils.InMemorySnapshots),
signatures: lru.NewCache[common.Hash, common.Address](utils.InMemorySnapshots),
verifiedHeaders: lru.NewCache[common.Hash, struct{}](utils.InMemorySnapshots),
validatorSignatures: lru.NewCache[common.Hash, common.Address](utils.InMemorySnapshots),
proposals: make(map[common.Address]bool),
}
}
@ -1040,10 +1040,10 @@ func NewFaker(db ethdb.Database, chainConfig *params.ChainConfig) *XDPoS_v1 {
config: conf,
db: db,
recents: lru.NewCache[common.Hash, *SnapshotV1](utils.InmemorySnapshots),
signatures: lru.NewCache[common.Hash, common.Address](utils.InmemorySnapshots),
verifiedHeaders: lru.NewCache[common.Hash, struct{}](utils.InmemorySnapshots),
validatorSignatures: lru.NewCache[common.Hash, common.Address](utils.InmemorySnapshots),
recents: lru.NewCache[common.Hash, *SnapshotV1](utils.InMemorySnapshots),
signatures: lru.NewCache[common.Hash, common.Address](utils.InMemorySnapshots),
verifiedHeaders: lru.NewCache[common.Hash, struct{}](utils.InMemorySnapshots),
validatorSignatures: lru.NewCache[common.Hash, common.Address](utils.InMemorySnapshots),
proposals: make(map[common.Address]bool),
}
return fakeEngine

View file

@ -98,17 +98,17 @@ func New(chainConfig *params.ChainConfig, db ethdb.Database, minePeriodCh chan i
db: db,
isInitilised: false,
signatures: lru.NewCache[common.Hash, common.Address](utils.InmemorySnapshots),
signatures: lru.NewCache[common.Hash, common.Address](utils.InMemorySnapshots),
verifiedHeaders: lru.NewCache[common.Hash, struct{}](utils.InmemorySnapshots),
snapshots: lru.NewCache[common.Hash, *SnapshotV2](utils.InmemorySnapshots),
epochSwitches: lru.NewCache[common.Hash, *types.EpochSwitchInfo](int(utils.InmemoryEpochs)),
verifiedHeaders: lru.NewCache[common.Hash, struct{}](utils.InMemorySnapshots),
snapshots: lru.NewCache[common.Hash, *SnapshotV2](utils.InMemorySnapshots),
epochSwitches: lru.NewCache[common.Hash, *types.EpochSwitchInfo](int(utils.InMemoryEpochs)),
timeoutWorker: timeoutTimer,
BroadcastCh: make(chan interface{}),
minePeriodCh: minePeriodCh,
newRoundCh: newRoundCh,
round2epochBlockInfo: lru.NewCache[types.Round, *types.BlockInfo](utils.InmemoryRound2Epochs),
round2epochBlockInfo: lru.NewCache[types.Round, *types.BlockInfo](utils.InMemoryRound2Epochs),
timeoutPool: timeoutPool,
votePool: votePool,

View file

@ -6,28 +6,21 @@ import (
)
// XDPoS delegated-proof-of-stake protocol constants.
const (
BlockSignersCacheLimit = 9000
EpochLength = uint64(900) // Default number of blocks after which to checkpoint and reset the pending votes
ExtraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity
ExtraSeal = 65 // Fixed number of extra-data suffix bytes reserved for signer seal
InMemoryEpochs = 5 * EpochLength // Number of mapping from block to epoch switch infos to keep in memory
InMemoryRound2Epochs = 65536 // Number of mapping of epoch switch blocks for quickly locating epoch switch block. One epoch ~ 0.5hours, so 65536 epochs ~ 3.7 years. And it uses ~ 10MB memory.
InMemorySnapshots = 128 // Number of recent vote snapshots to keep in memory
M2ByteLength = 4
PeriodicJobPeriod = 60
PoolHygieneRound = 10
)
var (
EpochLength = uint64(900) // Default number of blocks after which to checkpoint and reset the pending votes
ExtraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity
ExtraSeal = 65 // Fixed number of extra-data suffix bytes reserved for signer seal
NonceAuthVote = hexutil.MustDecode("0xffffffffffffffff") // Magic nonce number to vote on adding a new signer
NonceDropVote = hexutil.MustDecode("0x0000000000000000") // Magic nonce number to vote on removing a signer.
UncleHash = types.CalcUncleHash(nil) // Always Keccak256(RLP([])) as uncles are meaningless outside of PoW.
InmemoryEpochs = 5 * EpochLength // Number of mapping from block to epoch switch infos to keep in memory
InmemoryRound2Epochs = 65536 // Number of mapping of epoch switch blocks for quickly locating epoch switch block. One epoch ~ 0.5hours, so 65536 epochs ~ 3.7 years. And it uses ~ 10MB memory.
)
const (
InmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory
BlockSignersCacheLimit = 9000
M2ByteLength = 4
)
const (
PeriodicJobPeriod = 60
PoolHygieneRound = 10
UncleHash = types.CalcUncleHash(nil) // Always Keccak256(RLP([])) as uncles are meaningless outside of PoW.
)