mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-01 09:33:46 +00:00
sprint type change
This commit is contained in:
parent
bf60c6ce06
commit
062ea8b505
12 changed files with 122 additions and 92 deletions
|
|
@ -19,7 +19,9 @@
|
|||
"0": 2
|
||||
},
|
||||
"producerDelay": 6,
|
||||
"sprint": 64,
|
||||
"sprint": {
|
||||
"0": 64
|
||||
},
|
||||
"backupMultiplier": {
|
||||
"0": 2
|
||||
},
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@
|
|||
"25275000": 5
|
||||
},
|
||||
"producerDelay": 6,
|
||||
"sprint": 64,
|
||||
"sprint": {
|
||||
"0": 64
|
||||
},
|
||||
"backupMultiplier": {
|
||||
"0": 2,
|
||||
"25275000": 5
|
||||
|
|
|
|||
|
|
@ -46,7 +46,9 @@ const (
|
|||
|
||||
// Bor protocol constants.
|
||||
var (
|
||||
defaultSprintLength = uint64(64) // Default number of blocks after which to checkpoint and reset the pending votes
|
||||
defaultSprintLength = map[string]uint64{
|
||||
"0": 64,
|
||||
} // 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
|
||||
|
|
@ -176,7 +178,7 @@ func CalcProducerDelay(number uint64, succession int, c *params.BorConfig) uint6
|
|||
// When the block is the first block of the sprint, it is expected to be delayed by `producerDelay`.
|
||||
// That is to allow time for block propagation in the last sprint
|
||||
delay := c.CalculatePeriod(number)
|
||||
if number%c.Sprint == 0 {
|
||||
if number%c.CalculateSprint(number) == 0 {
|
||||
delay = c.ProducerDelay
|
||||
}
|
||||
|
||||
|
|
@ -238,7 +240,7 @@ func New(
|
|||
borConfig := chainConfig.Bor
|
||||
|
||||
// Set any missing consensus parameters to their defaults
|
||||
if borConfig != nil && borConfig.Sprint == 0 {
|
||||
if borConfig != nil && borConfig.CalculateSprint(0) == 0 {
|
||||
borConfig.Sprint = defaultSprintLength
|
||||
}
|
||||
// Allocate the snapshot caches and create the engine
|
||||
|
|
@ -321,7 +323,7 @@ func (c *Bor) verifyHeader(chain consensus.ChainHeaderReader, header *types.Head
|
|||
}
|
||||
|
||||
// check extr adata
|
||||
isSprintEnd := IsSprintStart(number+1, c.config.Sprint)
|
||||
isSprintEnd := IsSprintStart(number+1, c.config.CalculateSprint(number))
|
||||
|
||||
// Ensure that the extra-data contains a signer list on checkpoint, but none otherwise
|
||||
signersBytes := len(header.Extra) - extraVanity - extraSeal
|
||||
|
|
@ -435,7 +437,7 @@ func (c *Bor) verifyCascadingFields(chain consensus.ChainHeaderReader, header *t
|
|||
}
|
||||
|
||||
// verify the validator list in the last sprint block
|
||||
if IsSprintStart(number, c.config.Sprint) {
|
||||
if IsSprintStart(number, c.config.CalculateSprint(number)) {
|
||||
parentValidatorBytes := parent.Extra[extraVanity : len(parent.Extra)-extraSeal]
|
||||
validatorsBytes := make([]byte, len(snap.ValidatorSet.Validators)*validatorHeaderBytesLength)
|
||||
|
||||
|
|
@ -667,7 +669,7 @@ func (c *Bor) Prepare(chain consensus.ChainHeaderReader, header *types.Header) e
|
|||
header.Extra = header.Extra[:extraVanity]
|
||||
|
||||
// get validator set if number
|
||||
if IsSprintStart(number+1, c.config.Sprint) {
|
||||
if IsSprintStart(number+1, c.config.CalculateSprint(number)) {
|
||||
newValidators, err := c.spanner.GetCurrentValidators(context.Background(), header.ParentHash, number+1)
|
||||
if err != nil {
|
||||
return errors.New("unknown validators")
|
||||
|
|
@ -720,7 +722,7 @@ func (c *Bor) Finalize(chain consensus.ChainHeaderReader, header *types.Header,
|
|||
|
||||
headerNumber := header.Number.Uint64()
|
||||
|
||||
if IsSprintStart(headerNumber, c.config.Sprint) {
|
||||
if IsSprintStart(headerNumber, c.config.CalculateSprint(headerNumber)) {
|
||||
ctx := context.Background()
|
||||
|
||||
cx := statefull.ChainContext{Chain: chain, Bor: c}
|
||||
|
|
@ -794,7 +796,7 @@ func (c *Bor) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *typ
|
|||
|
||||
headerNumber := header.Number.Uint64()
|
||||
|
||||
if IsSprintStart(headerNumber, c.config.Sprint) {
|
||||
if IsSprintStart(headerNumber, c.config.CalculateSprint(headerNumber)) {
|
||||
ctx := context.Background()
|
||||
|
||||
cx := statefull.ChainContext{Chain: chain, Bor: c}
|
||||
|
|
@ -1011,7 +1013,7 @@ func (c *Bor) needToCommitSpan(currentSpan *span.Span, headerNumber uint64) bool
|
|||
}
|
||||
|
||||
// if current block is first block of last sprint in current span
|
||||
if currentSpan.EndBlock > c.config.Sprint && currentSpan.EndBlock-c.config.Sprint+1 == headerNumber {
|
||||
if currentSpan.EndBlock > c.config.CalculateSprint(headerNumber) && currentSpan.EndBlock-c.config.CalculateSprint(headerNumber)+1 == headerNumber {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
@ -1070,7 +1072,7 @@ func (c *Bor) CommitStates(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
to := time.Unix(int64(chain.Chain.GetHeaderByNumber(number-c.config.Sprint).Time), 0)
|
||||
to := time.Unix(int64(chain.Chain.GetHeaderByNumber(number-c.config.CalculateSprint(number)).Time), 0)
|
||||
lastStateID := _lastStateID.Uint64()
|
||||
|
||||
log.Info(
|
||||
|
|
@ -1182,7 +1184,7 @@ func (c *Bor) getNextHeimdallSpanForTest(
|
|||
spanBor.StartBlock = spanBor.EndBlock + 1
|
||||
}
|
||||
|
||||
spanBor.EndBlock = spanBor.StartBlock + (100 * c.config.Sprint) - 1
|
||||
spanBor.EndBlock = spanBor.StartBlock + (100 * c.config.CalculateSprint(headerNumber)) - 1
|
||||
|
||||
selectedProducers := make([]valset.Validator, len(snap.ValidatorSet.Validators))
|
||||
for i, v := range snap.ValidatorSet.Validators {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ func TestGenesisContractChange(t *testing.T) {
|
|||
|
||||
b := &Bor{
|
||||
config: ¶ms.BorConfig{
|
||||
Sprint: 10, // skip sprint transactions in sprint
|
||||
Sprint: map[string]uint64{
|
||||
"0": 10,
|
||||
}, // skip sprint transactions in sprint
|
||||
BlockAlloc: map[string]interface{}{
|
||||
// write as interface since that is how it is decoded in genesis
|
||||
"2": map[string]interface{}{
|
||||
|
|
|
|||
|
|
@ -120,8 +120,8 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
|
|||
number := header.Number.Uint64()
|
||||
|
||||
// Delete the oldest signer from the recent list to allow it signing again
|
||||
if number >= s.config.Sprint {
|
||||
delete(snap.Recents, number-s.config.Sprint)
|
||||
if number >= s.config.CalculateSprint(number) {
|
||||
delete(snap.Recents, number-s.config.CalculateSprint(number))
|
||||
}
|
||||
|
||||
// Resolve the authorization key and check against signers
|
||||
|
|
@ -143,7 +143,7 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
|
|||
snap.Recents[number] = signer
|
||||
|
||||
// change validator set and change proposer
|
||||
if number > 0 && (number+1)%s.config.Sprint == 0 {
|
||||
if number > 0 && (number+1)%s.config.CalculateSprint(number) == 0 {
|
||||
if err := validateHeaderExtraField(header.Extra); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1826,7 +1826,7 @@ func testRepair(t *testing.T, tt *rewindTest, snapshots bool) {
|
|||
sideblocks, _ = core.GenerateChain(params.BorUnittestChainConfig, genesis, engine, rawdb.NewMemoryDatabase(), tt.sidechainBlocks, func(i int, b *core.BlockGen) {
|
||||
b.SetCoinbase(testAddress1)
|
||||
|
||||
if bor.IsSprintStart(b.Number().Uint64(), params.BorUnittestChainConfig.Bor.Sprint) {
|
||||
if bor.IsSprintStart(b.Number().Uint64(), params.BorUnittestChainConfig.Bor.CalculateSprint(b.Number().Uint64())) {
|
||||
b.SetExtra(back.Genesis.ExtraData)
|
||||
} else {
|
||||
b.SetExtra(make([]byte, 32+crypto.SignatureLength))
|
||||
|
|
@ -1841,7 +1841,7 @@ func testRepair(t *testing.T, tt *rewindTest, snapshots bool) {
|
|||
b.SetCoinbase(miner.TestBankAddress)
|
||||
b.SetDifficulty(big.NewInt(1000000))
|
||||
|
||||
if bor.IsSprintStart(b.Number().Uint64(), params.BorUnittestChainConfig.Bor.Sprint) {
|
||||
if bor.IsSprintStart(b.Number().Uint64(), params.BorUnittestChainConfig.Bor.CalculateSprint(b.Number().Uint64())) {
|
||||
b.SetExtra(back.Genesis.ExtraData)
|
||||
} else {
|
||||
b.SetExtra(make([]byte, 32+crypto.SignatureLength))
|
||||
|
|
|
|||
|
|
@ -34,7 +34,9 @@ var mainnetBor = &Chain{
|
|||
"0": 2,
|
||||
},
|
||||
ProducerDelay: 6,
|
||||
Sprint: 64,
|
||||
Sprint: map[string]uint64{
|
||||
"0": 64,
|
||||
},
|
||||
BackupMultiplier: map[string]uint64{
|
||||
"0": 2,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -35,7 +35,9 @@ var mumbaiTestnet = &Chain{
|
|||
"25275000": 5,
|
||||
},
|
||||
ProducerDelay: 6,
|
||||
Sprint: 64,
|
||||
Sprint: map[string]uint64{
|
||||
"0": 64,
|
||||
},
|
||||
BackupMultiplier: map[string]uint64{
|
||||
"0": 2,
|
||||
"25275000": 5,
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -21,7 +21,9 @@
|
|||
"0":2
|
||||
},
|
||||
"producerDelay":6,
|
||||
"sprint":64,
|
||||
"sprint":{
|
||||
"0": 64
|
||||
},
|
||||
"backupMultiplier":{
|
||||
"0":2
|
||||
},
|
||||
|
|
|
|||
|
|
@ -279,7 +279,9 @@ var (
|
|||
"0": 2,
|
||||
},
|
||||
ProducerDelay: 6,
|
||||
Sprint: 64,
|
||||
Sprint: map[string]uint64{
|
||||
"0": 64,
|
||||
},
|
||||
BackupMultiplier: map[string]uint64{
|
||||
"0": 2,
|
||||
},
|
||||
|
|
@ -311,7 +313,9 @@ var (
|
|||
"0": 1,
|
||||
},
|
||||
ProducerDelay: 3,
|
||||
Sprint: 32,
|
||||
Sprint: map[string]uint64{
|
||||
"0": 32,
|
||||
},
|
||||
BackupMultiplier: map[string]uint64{
|
||||
"0": 2,
|
||||
},
|
||||
|
|
@ -347,7 +351,9 @@ var (
|
|||
"25275000": 5,
|
||||
},
|
||||
ProducerDelay: 6,
|
||||
Sprint: 64,
|
||||
Sprint: map[string]uint64{
|
||||
"0": 64,
|
||||
},
|
||||
BackupMultiplier: map[string]uint64{
|
||||
"0": 2,
|
||||
"25275000": 5,
|
||||
|
|
@ -391,7 +397,9 @@ var (
|
|||
"0": 2,
|
||||
},
|
||||
ProducerDelay: 6,
|
||||
Sprint: 64,
|
||||
Sprint: map[string]uint64{
|
||||
"0": 64,
|
||||
},
|
||||
BackupMultiplier: map[string]uint64{
|
||||
"0": 2,
|
||||
},
|
||||
|
|
@ -551,7 +559,7 @@ func (c *CliqueConfig) String() string {
|
|||
type BorConfig struct {
|
||||
Period map[string]uint64 `json:"period"` // Number of seconds between blocks to enforce
|
||||
ProducerDelay uint64 `json:"producerDelay"` // Number of seconds delay between two producer interval
|
||||
Sprint uint64 `json:"sprint"` // Epoch length to proposer
|
||||
Sprint map[string]uint64 `json:"sprint"` // Epoch length to proposer
|
||||
BackupMultiplier map[string]uint64 `json:"backupMultiplier"` // Backup multiplier to determine the wiggle time
|
||||
ValidatorContract string `json:"validatorContract"` // Validator set contract
|
||||
StateReceiverContract string `json:"stateReceiverContract"` // State receiver contract
|
||||
|
|
@ -566,6 +574,10 @@ func (b *BorConfig) String() string {
|
|||
return "bor"
|
||||
}
|
||||
|
||||
func (c *BorConfig) CalculateSprint(number uint64) uint64 {
|
||||
return c.calculateBorConfigHelper(c.Sprint, number)
|
||||
}
|
||||
|
||||
func (c *BorConfig) CalculateBackupMultiplier(number uint64) uint64 {
|
||||
return c.calculateBorConfigHelper(c.BackupMultiplier, number)
|
||||
}
|
||||
|
|
|
|||
4
tests/bor/testdata/genesis.json
vendored
4
tests/bor/testdata/genesis.json
vendored
|
|
@ -19,7 +19,9 @@
|
|||
"0": 1
|
||||
},
|
||||
"producerDelay": 4,
|
||||
"sprint": 4,
|
||||
"sprint": {
|
||||
"0": 4
|
||||
},
|
||||
"backupMultiplier": {
|
||||
"0": 1
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue