fix(core): fix genesis error in #2019 (#2034)

This commit is contained in:
Daniel Liu 2026-02-10 12:22:17 +08:00 committed by GitHub
parent b53fa6c6d9
commit 81ac9cfb7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 7 additions and 10 deletions

View file

@ -65,7 +65,7 @@ func (x *XDPoS_v2) verifyHeader(chain consensus.ChainReader, header *types.Heade
if err != nil && parent.Number.Sign() != 0 { // skip genesis block
return err
}
// Ensure gas used is less than or equal to gas limit
if header.GasUsed > header.GasLimit {
return fmt.Errorf("gas used exceeded gaslimit, gas used: %d, gas limit: %d", header.GasUsed, header.GasLimit)

View file

@ -225,7 +225,7 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig
genesis = DefaultGenesisBlock()
}
// Ensure the stored genesis matches with the given one.
hash := genesis.ToBlock(nil).Hash()
hash := genesis.ToBlock().Hash()
if hash != stored {
return genesis.Config, hash, &GenesisMismatchError{stored, hash}
}

View file

@ -121,7 +121,7 @@ func TestSetupGenesis(t *testing.T) {
{
name: "genesis header present but state missing",
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, error) {
block := DefaultGenesisBlock().ToBlock(nil)
block := DefaultGenesisBlock().ToBlock()
rawdb.WriteCanonicalHash(db, block.Hash(), 0)
rawdb.WriteHeader(db, block.Header())
return SetupGenesisBlock(db, nil)
@ -132,7 +132,7 @@ func TestSetupGenesis(t *testing.T) {
{
name: "genesis block without chain config",
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, error) {
block := DefaultGenesisBlock().ToBlock(db)
block := DefaultGenesisBlock().ToBlock()
rawdb.WriteBlock(db, block)
rawdb.WriteCanonicalHash(db, block.Hash(), 0)
return SetupGenesisBlock(db, nil)
@ -143,10 +143,7 @@ func TestSetupGenesis(t *testing.T) {
{
name: "missing block number for head header hash",
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, error) {
block := DefaultGenesisBlock().ToBlock(db)
rawdb.WriteBlock(db, block)
rawdb.WriteCanonicalHash(db, block.Hash(), 0)
rawdb.WriteChainConfig(db, block.Hash(), params.XDCMainnetChainConfig)
DefaultGenesisBlock().MustCommit(db)
rawdb.WriteHeadHeaderHash(db, common.HexToHash("0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
return SetupGenesisBlock(db, nil)
},

View file

@ -525,8 +525,8 @@ func (s *Service) login(conn *connWrapper) error {
auth := &authMsg{
ID: s.node,
Info: nodeInfo{
Name: s.node,
Node: infos.Name,
Name: s.node,
Node: infos.Name,
Coinbase: s.coinbase,
Port: infos.Ports.Listener,
Network: network,