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

Commit 59bde3d

Browse files
committed
consensus: get Validators from genesis instead of triedb in v1 consortium. (#624)
In snap sync, we will disable accessing/mark stale to triedb when enabling path scheme for protecting the persistent storing, so the data of validators only used for checking in some first blocks which we can return hardcore list from genesis data for following the flow of snap-sync from go-eth team.
1 parent 1acc754 commit 59bde3d

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

consensus/consortium/v1/consortium.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,10 @@ func (c *Consortium) snapshot(chain consensus.ChainHeaderReader, number uint64,
338338
if cpHeader != nil {
339339
hash := cpHeader.Hash()
340340

341-
validators, err := c.getValidatorsFromContract(chain, number)
341+
validators, err := c.getValidatorsFromGenesis()
342342
if err != nil {
343343
return nil, err
344344
}
345-
346345
snap = newSnapshot(c.config, c.signatures, number, hash, validators)
347346
if err := snap.store(c.db); err != nil {
348347
return nil, err
@@ -756,6 +755,31 @@ func (c *Consortium) doCalcDifficulty(signer common.Address, number uint64, vali
756755
return new(big.Int).Set(diffNoTurn)
757756
}
758757

758+
// getValidatorsFromGenesis gets the list of validators from the genesis block support backward compatibility in v1, only used with Snap Sync.
759+
func (c *Consortium) getValidatorsFromGenesis() ([]common.Address, error) {
760+
var validatorSet []string
761+
switch {
762+
case c.chainConfig.ChainID.Cmp(big.NewInt(2020)) == 0:
763+
validatorSet = []string{
764+
"0x000000000000000000000000f224beff587362a88d859e899d0d80c080e1e812",
765+
"0x00000000000000000000000011360eacdedd59bc433afad4fc8f0417d1fbebab",
766+
"0x00000000000000000000000070bb1fb41c8c42f6ddd53a708e2b82209495e455",
767+
}
768+
case c.chainConfig.ChainID.Cmp(big.NewInt(2021)) == 0:
769+
validatorSet = []string{
770+
"0x0000000000000000000000004a4bc674a97737376cfe990ae2fe0d2b6e738393",
771+
"0x000000000000000000000000b6bc5bc0410773a3f86b1537ce7495c52e38f88b",
772+
}
773+
default:
774+
return nil, errors.New("no validator set for this chain only support Mainnet & Testnet")
775+
}
776+
var addresses []common.Address
777+
for _, str := range validatorSet {
778+
addresses = append(addresses, common.HexToAddress(str))
779+
}
780+
return addresses, nil
781+
}
782+
759783
// Read the validator list from contract
760784
func (c *Consortium) getValidatorsFromContract(chain consensus.ChainHeaderReader, number uint64) ([]common.Address, error) {
761785
if chain.Config().IsFenix(big.NewInt(int64(number))) {
@@ -779,7 +803,7 @@ func (c *Consortium) getValidatorsFromLastCheckpoint(chain consensus.ChainHeader
779803

780804
if lastCheckpoint == 0 {
781805
// TODO(andy): Review if we should put validators in genesis block's extra data
782-
return c.getValidatorsFromContract(chain, number)
806+
return c.getValidatorsFromGenesis()
783807
}
784808

785809
var header *types.Header

0 commit comments

Comments
 (0)