Skip to content

Commit

Permalink
consortium-v1: add an option to disable checkpoint header check
Browse files Browse the repository at this point in the history
In version 1, the checkpoint header check happens early in the header
verification step. This makes statedb read sometimes happens in incorrect
statedb. While full sync, this leads to peer drop but still be able to continue
syncing with other peers. However, while running import chain command or fast
sync, this could lead to error. Add a option to disable checkpoint header check
in these cases.
  • Loading branch information
minh-bq committed May 21, 2024
1 parent c7ec136 commit 9a30eea
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2230,7 +2230,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
} else if config.Consortium != nil {
ethApiBackend, setupAPIBackend = eth.MakeEthApiBackend(chainDb)
ethApi := ethapi.NewPublicBlockChainAPI(ethApiBackend)
engine = consortium.New(config, chainDb, ethApi)
engine = consortium.New(config, chainDb, ethApi, true)
} else {
engine = ethash.NewFaker()
if !ctx.Bool(FakePoWFlag.Name) {
Expand Down
4 changes: 2 additions & 2 deletions consensus/consortium/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ type Consortium struct {
}

// New creates a Consortium proxy that decides what Consortium version will be called
func New(chainConfig *params.ChainConfig, db ethdb.Database, ee *ethapi.PublicBlockChainAPI) *Consortium {
func New(chainConfig *params.ChainConfig, db ethdb.Database, ee *ethapi.PublicBlockChainAPI, skipV1Check bool) *Consortium {
// Set any missing consensus parameters to their defaults
consortiumV1 := v1.New(chainConfig, db, ee)
consortiumV1 := v1.New(chainConfig, db, ee, skipV1Check)
consortiumV2 := v2.New(chainConfig, db, ee, consortiumV1)

return &Consortium{
Expand Down
43 changes: 24 additions & 19 deletions consensus/consortium/v1/consortium.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ type Consortium struct {

getSCValidators func() ([]common.Address, error) // Get the list of validator from contract
getFenixValidators func() ([]common.Address, error) // Get the validator list from Ronin Validator contract of Fenix hardfork

skipCheckpointHeaderCheck bool
}

// New creates a Consortium proof-of-authority consensus engine with the initial
// signers set to the ones provided by the user.
func New(chainConfig *params.ChainConfig, db ethdb.Database, ethAPI *ethapi.PublicBlockChainAPI) *Consortium {
func New(chainConfig *params.ChainConfig, db ethdb.Database, ethAPI *ethapi.PublicBlockChainAPI, skipCheckpointHeaderCheck bool) *Consortium {
// Set any missing consensus parameters to their defaults
consortiumConfig := *chainConfig.Consortium
if consortiumConfig.Epoch == 0 {
Expand All @@ -132,14 +134,15 @@ func New(chainConfig *params.ChainConfig, db ethdb.Database, ethAPI *ethapi.Publ
signatures, _ := lru.NewARC(inmemorySignatures)

consortium := Consortium{
chainConfig: chainConfig,
config: &consortiumConfig,
db: db,
recents: recents,
signatures: signatures,
ethAPI: ethAPI,
proposals: make(map[common.Address]bool),
signer: types.NewEIP155Signer(chainConfig.ChainID),
chainConfig: chainConfig,
config: &consortiumConfig,
db: db,
recents: recents,
signatures: signatures,
ethAPI: ethAPI,
proposals: make(map[common.Address]bool),
signer: types.NewEIP155Signer(chainConfig.ChainID),
skipCheckpointHeaderCheck: skipCheckpointHeaderCheck,
}

err := consortium.initContract(common.Address{}, nil)
Expand Down Expand Up @@ -277,17 +280,19 @@ func (c *Consortium) verifyCascadingFields(chain consensus.ChainHeaderReader, he
return c.verifySeal(chain, header, parents)
}

signers, err := c.getValidatorsFromContract(chain, number-1)
if err != nil {
return err
}
if !c.skipCheckpointHeaderCheck {
signers, err := c.getValidatorsFromContract(chain, number-1)
if err != nil {
return err
}

extraSuffix := len(header.Extra) - consortiumCommon.ExtraSeal
checkpointHeaders := consortiumCommon.ExtractAddressFromBytes(header.Extra[extraVanity:extraSuffix])
validSigners := consortiumCommon.CompareSignersLists(checkpointHeaders, signers)
if !validSigners {
log.Error("signers lists are different in checkpoint header and snapshot", "number", number, "signersHeader", checkpointHeaders, "signers", signers)
return consortiumCommon.ErrInvalidCheckpointSigners
extraSuffix := len(header.Extra) - consortiumCommon.ExtraSeal
checkpointHeaders := consortiumCommon.ExtractAddressFromBytes(header.Extra[extraVanity:extraSuffix])
validSigners := consortiumCommon.CompareSignersLists(checkpointHeaders, signers)
if !validSigners {
log.Error("signers lists are different in checkpoint header and snapshot", "number", number, "signersHeader", checkpointHeaders, "signers", signers)
return consortiumCommon.ErrInvalidCheckpointSigners
}
}

// All basic checks passed, verify the seal and return
Expand Down
2 changes: 1 addition & 1 deletion eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func CreateConsensusEngine(
return clique.New(chainConfig.Clique, db)
}
if chainConfig.Consortium != nil {
return consortium.New(chainConfig, db, ee)
return consortium.New(chainConfig, db, ee, false)
}
// Otherwise assume proof-of-work
switch config.PowMode {
Expand Down

0 comments on commit 9a30eea

Please sign in to comment.