mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-05 15:52:55 +00:00
core: remove unused fields (#29569)
This commit is contained in:
parent
5f95145308
commit
b5902cf595
1 changed files with 15 additions and 23 deletions
|
|
@ -17,12 +17,9 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
crand "crypto/rand"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
mrand "math/rand"
|
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -43,45 +40,41 @@ const (
|
||||||
numberCacheLimit = 2048
|
numberCacheLimit = 2048
|
||||||
)
|
)
|
||||||
|
|
||||||
// HeaderChain implements the basic block header chain logic that is shared by
|
// HeaderChain implements the basic block header chain logic. It is not usable
|
||||||
// core.BlockChain and light.LightChain. It is not usable in itself, only as
|
// in itself, but rather an internal structure of core.Blockchain.
|
||||||
// a part of either structure.
|
|
||||||
//
|
//
|
||||||
// HeaderChain is responsible for maintaining the header chain including the
|
// HeaderChain is responsible for maintaining the header chain including the
|
||||||
// header query and updating.
|
// header query and updating.
|
||||||
//
|
//
|
||||||
// The components maintained by headerchain includes: (1) total difficulty
|
// The data components maintained by HeaderChain include:
|
||||||
// (2) header (3) block hash -> number mapping (4) canonical number -> hash mapping
|
|
||||||
// and (5) head header flag.
|
|
||||||
//
|
//
|
||||||
// It is not thread safe either, the encapsulating chain structures should do
|
// - total difficulty
|
||||||
// the necessary mutex locking/unlocking.
|
// - header
|
||||||
|
// - block hash -> number mapping
|
||||||
|
// - canonical number -> hash mapping
|
||||||
|
// - head header flag.
|
||||||
|
//
|
||||||
|
// It is not thread safe, the encapsulating chain structures should do the
|
||||||
|
// necessary mutex locking/unlocking.
|
||||||
type HeaderChain struct {
|
type HeaderChain struct {
|
||||||
config *params.ChainConfig
|
config *params.ChainConfig
|
||||||
chainDb ethdb.Database
|
chainDb ethdb.Database
|
||||||
genesisHeader *types.Header
|
genesisHeader *types.Header
|
||||||
|
|
||||||
currentHeader atomic.Value // Current head of the header chain (may be above the block chain!)
|
currentHeader atomic.Pointer[types.Header] // Current head of the header chain (maybe above the block chain!)
|
||||||
currentHeaderHash common.Hash // Hash of the current head of the header chain (prevent recomputing all the time)
|
currentHeaderHash common.Hash // Hash of the current head of the header chain (prevent recomputing all the time)
|
||||||
|
|
||||||
headerCache *lru.Cache[common.Hash, *types.Header]
|
headerCache *lru.Cache[common.Hash, *types.Header]
|
||||||
tdCache *lru.Cache[common.Hash, *big.Int] // most recent total difficulties
|
tdCache *lru.Cache[common.Hash, *big.Int] // most recent total difficulties
|
||||||
numberCache *lru.Cache[common.Hash, uint64] // most recent block numbers
|
numberCache *lru.Cache[common.Hash, uint64] // most recent block numbers
|
||||||
|
|
||||||
procInterrupt func() bool
|
procInterrupt func() bool
|
||||||
|
engine consensus.Engine
|
||||||
rand *mrand.Rand
|
|
||||||
engine consensus.Engine
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHeaderChain creates a new HeaderChain structure. ProcInterrupt points
|
// NewHeaderChain creates a new HeaderChain structure. ProcInterrupt points
|
||||||
// to the parent's interrupt semaphore.
|
// to the parent's interrupt semaphore.
|
||||||
func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine consensus.Engine, procInterrupt func() bool) (*HeaderChain, error) {
|
func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine consensus.Engine, procInterrupt func() bool) (*HeaderChain, error) {
|
||||||
// Seed a fast but crypto originating random generator
|
|
||||||
seed, err := crand.Int(crand.Reader, big.NewInt(math.MaxInt64))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
hc := &HeaderChain{
|
hc := &HeaderChain{
|
||||||
config: config,
|
config: config,
|
||||||
chainDb: chainDb,
|
chainDb: chainDb,
|
||||||
|
|
@ -89,7 +82,6 @@ func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine c
|
||||||
tdCache: lru.NewCache[common.Hash, *big.Int](tdCacheLimit),
|
tdCache: lru.NewCache[common.Hash, *big.Int](tdCacheLimit),
|
||||||
numberCache: lru.NewCache[common.Hash, uint64](numberCacheLimit),
|
numberCache: lru.NewCache[common.Hash, uint64](numberCacheLimit),
|
||||||
procInterrupt: procInterrupt,
|
procInterrupt: procInterrupt,
|
||||||
rand: mrand.New(mrand.NewSource(seed.Int64())),
|
|
||||||
engine: engine,
|
engine: engine,
|
||||||
}
|
}
|
||||||
hc.genesisHeader = hc.GetHeaderByNumber(0)
|
hc.genesisHeader = hc.GetHeaderByNumber(0)
|
||||||
|
|
@ -525,7 +517,7 @@ func (hc *HeaderChain) GetCanonicalHash(number uint64) common.Hash {
|
||||||
// CurrentHeader retrieves the current head header of the canonical chain. The
|
// CurrentHeader retrieves the current head header of the canonical chain. The
|
||||||
// header is retrieved from the HeaderChain's internal cache.
|
// header is retrieved from the HeaderChain's internal cache.
|
||||||
func (hc *HeaderChain) CurrentHeader() *types.Header {
|
func (hc *HeaderChain) CurrentHeader() *types.Header {
|
||||||
return hc.currentHeader.Load().(*types.Header)
|
return hc.currentHeader.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCurrentHeader sets the in-memory head header marker of the canonical chan
|
// SetCurrentHeader sets the in-memory head header marker of the canonical chan
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue