Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit 9a30eea

Browse files
committed
consortium-v1: add an option to disable checkpoint header check
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.
1 parent c7ec136 commit 9a30eea

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

cmd/utils/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2230,7 +2230,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
22302230
} else if config.Consortium != nil {
22312231
ethApiBackend, setupAPIBackend = eth.MakeEthApiBackend(chainDb)
22322232
ethApi := ethapi.NewPublicBlockChainAPI(ethApiBackend)
2233-
engine = consortium.New(config, chainDb, ethApi)
2233+
engine = consortium.New(config, chainDb, ethApi, true)
22342234
} else {
22352235
engine = ethash.NewFaker()
22362236
if !ctx.Bool(FakePoWFlag.Name) {

consensus/consortium/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ type Consortium struct {
2727
}
2828

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

3535
return &Consortium{

consensus/consortium/v1/consortium.go

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ type Consortium struct {
117117

118118
getSCValidators func() ([]common.Address, error) // Get the list of validator from contract
119119
getFenixValidators func() ([]common.Address, error) // Get the validator list from Ronin Validator contract of Fenix hardfork
120+
121+
skipCheckpointHeaderCheck bool
120122
}
121123

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

134136
consortium := Consortium{
135-
chainConfig: chainConfig,
136-
config: &consortiumConfig,
137-
db: db,
138-
recents: recents,
139-
signatures: signatures,
140-
ethAPI: ethAPI,
141-
proposals: make(map[common.Address]bool),
142-
signer: types.NewEIP155Signer(chainConfig.ChainID),
137+
chainConfig: chainConfig,
138+
config: &consortiumConfig,
139+
db: db,
140+
recents: recents,
141+
signatures: signatures,
142+
ethAPI: ethAPI,
143+
proposals: make(map[common.Address]bool),
144+
signer: types.NewEIP155Signer(chainConfig.ChainID),
145+
skipCheckpointHeaderCheck: skipCheckpointHeaderCheck,
143146
}
144147

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

280-
signers, err := c.getValidatorsFromContract(chain, number-1)
281-
if err != nil {
282-
return err
283-
}
283+
if !c.skipCheckpointHeaderCheck {
284+
signers, err := c.getValidatorsFromContract(chain, number-1)
285+
if err != nil {
286+
return err
287+
}
284288

285-
extraSuffix := len(header.Extra) - consortiumCommon.ExtraSeal
286-
checkpointHeaders := consortiumCommon.ExtractAddressFromBytes(header.Extra[extraVanity:extraSuffix])
287-
validSigners := consortiumCommon.CompareSignersLists(checkpointHeaders, signers)
288-
if !validSigners {
289-
log.Error("signers lists are different in checkpoint header and snapshot", "number", number, "signersHeader", checkpointHeaders, "signers", signers)
290-
return consortiumCommon.ErrInvalidCheckpointSigners
289+
extraSuffix := len(header.Extra) - consortiumCommon.ExtraSeal
290+
checkpointHeaders := consortiumCommon.ExtractAddressFromBytes(header.Extra[extraVanity:extraSuffix])
291+
validSigners := consortiumCommon.CompareSignersLists(checkpointHeaders, signers)
292+
if !validSigners {
293+
log.Error("signers lists are different in checkpoint header and snapshot", "number", number, "signersHeader", checkpointHeaders, "signers", signers)
294+
return consortiumCommon.ErrInvalidCheckpointSigners
295+
}
291296
}
292297

293298
// All basic checks passed, verify the seal and return

eth/ethconfig/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func CreateConsensusEngine(
239239
return clique.New(chainConfig.Clique, db)
240240
}
241241
if chainConfig.Consortium != nil {
242-
return consortium.New(chainConfig, db, ee)
242+
return consortium.New(chainConfig, db, ee, false)
243243
}
244244
// Otherwise assume proof-of-work
245245
switch config.PowMode {

0 commit comments

Comments
 (0)