Skip to content

Commit

Permalink
add GenesisHeader to ChainHeaderReader
Browse files Browse the repository at this point in the history
  • Loading branch information
buddh0 committed Feb 28, 2024
1 parent ba58f57 commit 9bca3df
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type ChainHeaderReader interface {
// Config retrieves the blockchain's chain configuration.
Config() *params.ChainConfig

// GenesisHeader retrieves the chain's genesis block header.
GenesisHeader() *types.Header

// CurrentHeader retrieves the current header from the local chain.
CurrentHeader() *types.Header

Expand Down
6 changes: 2 additions & 4 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,7 @@ func (p *Parlia) Prepare(chain consensus.ChainHeaderReader, header *types.Header
}

header.Extra = header.Extra[:extraVanity-nextForkHashSize]
genesisTime := chain.GetHeader(p.genesisHash, 0).Time
nextForkHash := forkid.NextForkHash(p.chainConfig, p.genesisHash, genesisTime, number, header.Time)
nextForkHash := forkid.NextForkHash(p.chainConfig, p.genesisHash, chain.GenesisHeader().Time, number, header.Time)
header.Extra = append(header.Extra, nextForkHash[:]...)

if err := p.prepareValidators(header); err != nil {
Expand Down Expand Up @@ -1117,8 +1116,7 @@ func (p *Parlia) Finalize(chain consensus.ChainHeaderReader, header *types.Heade
if err != nil {
return err
}
genesisTime := chain.GetHeader(p.genesisHash, 0).Time
nextForkHash := forkid.NextForkHash(p.chainConfig, p.genesisHash, genesisTime, number, header.Time)
nextForkHash := forkid.NextForkHash(p.chainConfig, p.genesisHash, chain.GenesisHeader().Time, number, header.Time)
if !snap.isMajorityFork(hex.EncodeToString(nextForkHash[:])) {
log.Debug("there is a possible fork, and your client is not the majority. Please check...", "nextForkHash", hex.EncodeToString(nextForkHash[:]))
}
Expand Down
5 changes: 5 additions & 0 deletions core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@ func (bc *BlockChain) Genesis() *types.Block {
return bc.genesisBlock
}

// GenesisHeader retrieves the chain's genesis block header.
func (bc *BlockChain) GenesisHeader() *types.Header {
return bc.genesisBlock.Header()
}

// TxIndexProgress returns the transaction indexing progress.
func (bc *BlockChain) TxIndexProgress() (TxIndexProgress, error) {
if bc.txIndexer == nil {
Expand Down
4 changes: 4 additions & 0 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,10 @@ func (cm *chainMaker) GetHeaderByHash(hash common.Hash) *types.Header {
return b.Header()
}

func (cm *chainMaker) GenesisHeader() *types.Header {
panic("not supported")
}

func (cm *chainMaker) GetHeader(hash common.Hash, number uint64) *types.Header {
return cm.GetHeaderByNumber(number)
}
Expand Down
4 changes: 4 additions & 0 deletions core/headerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func (hc *HeaderChain) getFinalizedNumber(header *types.Header) uint64 {
return 0
}

func (hc *HeaderChain) GenesisHeader() *types.Header {
panic("not supported")
}

// GetBlockNumber retrieves the block number belonging to the given hash
// from the cache or database
func (hc *HeaderChain) GetBlockNumber(hash common.Hash) *uint64 {
Expand Down

0 comments on commit 9bca3df

Please sign in to comment.