Skip to content

Commit

Permalink
using cancun for block-stm metadata instead of napoli
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikspatil024 committed Jan 22, 2024
1 parent c2efa54 commit c6b947f
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 32 deletions.
1 change: 0 additions & 1 deletion builder/files/genesis-mainnet-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"bor": {
"jaipurBlock": 23850000,
"delhiBlock": 38189056,
"napoliBlock": 0,
"indoreBlock": 44934656,
"stateSyncConfirmationDelay": {
"44934656": 128
Expand Down
1 change: 0 additions & 1 deletion builder/files/genesis-testnet-v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"bor": {
"jaipurBlock": 22770000,
"delhiBlock": 29638656,
"napoliBlock": 0,
"indoreBlock": 37075456,
"stateSyncConfirmationDelay": {
"37075456": 128
Expand Down
14 changes: 7 additions & 7 deletions consensus/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (c *Bor) verifyHeader(chain consensus.ChainHeaderReader, header *types.Head
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.GetValidatorBytes(c.config))
signersBytes := len(header.GetValidatorBytes(c.chainConfig))

if !isSprintEnd && signersBytes != 0 {
return errExtraValidators
Expand Down Expand Up @@ -472,7 +472,7 @@ func (c *Bor) verifyCascadingFields(chain consensus.ChainHeaderReader, header *t

sort.Sort(valset.ValidatorsByAddress(newValidators))

headerVals, err := valset.ParseValidators(header.GetValidatorBytes(c.config))
headerVals, err := valset.ParseValidators(header.GetValidatorBytes(c.chainConfig))
if err != nil {
return err
}
Expand All @@ -490,7 +490,7 @@ func (c *Bor) verifyCascadingFields(chain consensus.ChainHeaderReader, header *t

// verify the validator list in the last sprint block
if IsSprintStart(number, c.config.CalculateSprint(number)) {
parentValidatorBytes := parent.GetValidatorBytes(c.config)
parentValidatorBytes := parent.GetValidatorBytes(c.chainConfig)
validatorsBytes := make([]byte, len(snap.ValidatorSet.Validators)*validatorHeaderBytesLength)

currentValidators := snap.ValidatorSet.Copy().Validators
Expand Down Expand Up @@ -521,7 +521,7 @@ func (c *Bor) snapshot(chain consensus.ChainHeaderReader, number uint64, hash co
val := valset.NewValidator(signer, 1000)
validatorset := valset.NewValidatorSet([]*valset.Validator{val})

snapshot := newSnapshot(c.config, c.signatures, number, hash, validatorset.Validators)
snapshot := newSnapshot(c.chainConfig, c.config, c.signatures, number, hash, validatorset.Validators)

return snapshot, nil
}
Expand Down Expand Up @@ -570,7 +570,7 @@ func (c *Bor) snapshot(chain consensus.ChainHeaderReader, number uint64, hash co
}

// new snap shot
snap = newSnapshot(c.config, c.signatures, number, hash, validators)
snap = newSnapshot(c.chainConfig, c.config, c.signatures, number, hash, validators)
if err := snap.store(c.db); err != nil {
return nil, err
}
Expand Down Expand Up @@ -742,7 +742,7 @@ func (c *Bor) Prepare(chain consensus.ChainHeaderReader, header *types.Header) e
// sort validator by address
sort.Sort(valset.ValidatorsByAddress(newValidators))

if c.config.IsNapoli(header.Number) {
if c.chainConfig.IsCancun(header.Number) {
var tempValidatorBytes []byte

for _, validator := range newValidators {
Expand All @@ -766,7 +766,7 @@ func (c *Bor) Prepare(chain consensus.ChainHeaderReader, header *types.Header) e
header.Extra = append(header.Extra, validator.HeaderBytes()...)
}
}
} else if c.config.IsNapoli(header.Number) {
} else if c.chainConfig.IsCancun(header.Number) {
blockExtraData := &types.BlockExtraData{
ValidatorBytes: nil,
TxDependency: nil,
Expand Down
6 changes: 5 additions & 1 deletion consensus/bor/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

// Snapshot is the state of the authorization voting at a given point in time.
type Snapshot struct {
chainConfig *params.ChainConfig

config *params.BorConfig // Consensus engine parameters to fine tune behavior
sigcache *lru.ARCCache // Cache of recent block signatures to speed up ecrecover

Expand All @@ -28,13 +30,15 @@ type Snapshot struct {
// method does not initialize the set of recent signers, so only ever use if for
// the genesis block.
func newSnapshot(
chainConfig *params.ChainConfig,
config *params.BorConfig,
sigcache *lru.ARCCache,
number uint64,
hash common.Hash,
validators []*valset.Validator,
) *Snapshot {
snap := &Snapshot{
chainConfig: chainConfig,
config: config,
sigcache: sigcache,
Number: number,
Expand Down Expand Up @@ -150,7 +154,7 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
return nil, err
}

validatorBytes := header.GetValidatorBytes(s.config)
validatorBytes := header.GetValidatorBytes(s.chainConfig)

// get validators from headers and use that for new validator set
newVals, _ := valset.ParseValidators(validatorBytes)
Expand Down
4 changes: 2 additions & 2 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ func (b *Block) GetTxDependency() [][]uint64 {
return blockExtraData.TxDependency
}

func (h *Header) GetValidatorBytes(config *params.BorConfig) []byte {
if !config.IsNapoli(h.Number) {
func (h *Header) GetValidatorBytes(chainConfig *params.ChainConfig) []byte {
if !chainConfig.IsCancun(h.Number) {
return h.Extra[ExtraVanityLength : len(h.Extra)-ExtraSealLength]
}

Expand Down
1 change: 0 additions & 1 deletion core/types/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func TestBlockEncoding(t *testing.T) {
}

// This is a replica of `(h *Header) GetValidatorBytes` function
// This was needed because currently, `IsNapoli` will always return false.
func GetValidatorBytesTest(h *Header) []byte {
if len(h.Extra) < ExtraVanityLength+ExtraSealLength {
log.Error("length of extra less is than vanity and seal")
Expand Down
1 change: 0 additions & 1 deletion internal/cli/server/chains/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var mainnetBor = &Chain{
Bor: &params.BorConfig{
JaipurBlock: big.NewInt(23850000),
DelhiBlock: big.NewInt(38189056),
NapoliBlock: big.NewInt(0),
IndoreBlock: big.NewInt(44934656),
StateSyncConfirmationDelay: map[string]uint64{
"44934656": 128,
Expand Down
1 change: 0 additions & 1 deletion internal/cli/server/chains/mumbai.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var mumbaiTestnet = &Chain{
Bor: &params.BorConfig{
JaipurBlock: big.NewInt(22770000),
DelhiBlock: big.NewInt(29638656),
NapoliBlock: big.NewInt(0),
IndoreBlock: big.NewInt(37075456),
StateSyncConfirmationDelay: map[string]uint64{
"37075456": 128,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
},
"jaipurBlock": 22770000,
"delhiBlock": 29638656,
"napoliBlock": 0,
"indoreBlock": 37075456,
"stateSyncConfirmationDelay": {
"37075456": 128
Expand Down
1 change: 0 additions & 1 deletion internal/cli/server/chains/test_files/chain_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
},
"jaipurBlock":22770000,
"delhiBlock": 29638656,
"napoliBlock": 0,
"indoreBlock": 37075456,
"stateSyncConfirmationDelay": {
"37075456": 128
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn

var depsWg sync.WaitGroup

EnableMVHashMap := w.chainConfig.Bor.IsNapoli(env.header.Number)
EnableMVHashMap := w.chainConfig.IsCancun(env.header.Number)

// create and add empty mvHashMap in statedb
if EnableMVHashMap {
Expand Down
2 changes: 1 addition & 1 deletion miner/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ func BenchmarkBorMining(b *testing.B) {
}

// uses core.NewParallelBlockChain to use the dependencies present in the block header
// params.BorUnittestChainConfig contains the NapoliBlock ad big.NewInt(5), so the first 4 blocks will not have metadata.
// params.BorUnittestChainConfig contains the NapoliBlock as big.NewInt(5), so the first 4 blocks will not have metadata.
// nolint: gocognit
func BenchmarkBorMiningBlockSTMMetadata(b *testing.B) {
chainConfig := params.BorUnittestChainConfig
Expand Down
22 changes: 9 additions & 13 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ var (
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
Bor: &BorConfig{
NapoliBlock: big.NewInt(5),
Period: map[string]uint64{
"0": 1,
},
Expand Down Expand Up @@ -200,7 +199,6 @@ var (
Bor: &BorConfig{
JaipurBlock: big.NewInt(22770000),
DelhiBlock: big.NewInt(29638656),
NapoliBlock: big.NewInt(0),
IndoreBlock: big.NewInt(37075456),
StateSyncConfirmationDelay: map[string]uint64{
"37075456": 128,
Expand Down Expand Up @@ -266,7 +264,6 @@ var (
Bor: &BorConfig{
JaipurBlock: big.NewInt(23850000),
DelhiBlock: big.NewInt(38189056),
NapoliBlock: big.NewInt(0),
IndoreBlock: big.NewInt(44934656),
StateSyncConfirmationDelay: map[string]uint64{
"44934656": 128,
Expand Down Expand Up @@ -567,7 +564,6 @@ type BorConfig struct {
BurntContract map[string]string `json:"burntContract"` // governance contract where the token will be sent to and burnt in london fork
JaipurBlock *big.Int `json:"jaipurBlock"` // Jaipur switch block (nil = no fork, 0 = already on jaipur)
DelhiBlock *big.Int `json:"delhiBlock"` // Delhi switch block (nil = no fork, 0 = already on delhi)
NapoliBlock *big.Int `json:"napoliBlock"` // TODO: update all occurrence, change name and finalize number (hardfork for block-stm related changes)
IndoreBlock *big.Int `json:"indoreBlock"` // Indore switch block (nil = no fork, 0 = already on indore)
StateSyncConfirmationDelay map[string]uint64 `json:"stateSyncConfirmationDelay"` // StateSync Confirmation Delay, in seconds, to calculate `to`
}
Expand Down Expand Up @@ -609,16 +605,16 @@ func (c *BorConfig) CalculateStateSyncDelay(number uint64) uint64 {
return borKeyValueConfigHelper(c.StateSyncConfirmationDelay, number)
}

// TODO: modify this function once the block number is finalized
func (c *BorConfig) IsNapoli(number *big.Int) bool {
if c.NapoliBlock != nil {
if c.NapoliBlock.Cmp(big.NewInt(0)) == 0 {
return false
}
}
// // TODO: modify this function once the block number is finalized
// func (c *BorConfig) IsNapoli(number *big.Int) bool {
// if c.NapoliBlock != nil {
// if c.NapoliBlock.Cmp(big.NewInt(0)) == 0 {
// return false
// }
// }

return isBlockForked(c.NapoliBlock, number)
}
// return isBlockForked(c.NapoliBlock, number)
// }

func (c *BorConfig) IsSprintStart(number uint64) bool {
return number%c.CalculateSprint(number) == 0
Expand Down

0 comments on commit c6b947f

Please sign in to comment.