From 26dc990677e1906dc0fbc7eecf435f4894d239c4 Mon Sep 17 00:00:00 2001 From: gop Date: Wed, 30 Nov 2022 14:30:11 -0600 Subject: [PATCH] Renamed pendingHeader in Slice to pendingHeaderHeadHash --- core/slice.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/slice.go b/core/slice.go index 53c48009d2..b30711e7d7 100644 --- a/core/slice.go +++ b/core/slice.go @@ -53,8 +53,8 @@ type Slice struct { phCachemu sync.RWMutex - pendingHeader common.Hash - phCache map[common.Hash]types.PendingHeader + pendingHeaderHeadHash common.Hash + phCache map[common.Hash]types.PendingHeader } func NewSlice(db ethdb.Database, config *Config, txConfig *TxPoolConfig, isLocalBlock func(block *types.Header) bool, chainConfig *params.ChainConfig, domClientUrl string, subClientUrls []string, engine consensus.Engine, cacheConfig *CacheConfig, vmConfig vm.Config, genesis *Genesis) (*Slice, error) { @@ -213,8 +213,8 @@ func (sl *Slice) relayPh(pendingHeaderWithTermini types.PendingHeader, updateMin if nodeCtx == common.ZONE_CTX { if updateMiner { - sl.phCache[sl.pendingHeader].Header.SetLocation(common.NodeLocation) - sl.miner.worker.pendingHeaderFeed.Send(sl.phCache[sl.pendingHeader].Header) + sl.phCache[sl.pendingHeaderHeadHash].Header.SetLocation(common.NodeLocation) + sl.miner.worker.pendingHeaderFeed.Send(sl.phCache[sl.pendingHeaderHeadHash].Header) return } } else if !domOrigin { @@ -321,7 +321,7 @@ func (sl *Slice) calcTd(header *types.Header) (*big.Int, error) { // GetPendingHeader is used by the miner to request the current pending header func (sl *Slice) GetPendingHeader() (*types.Header, error) { - return sl.phCache[sl.pendingHeader].Header, nil + return sl.phCache[sl.pendingHeaderHeadHash].Header, nil } // SubRelayPendingHeader takes a pending header from the sender (ie dominant), updates the phCache with a composited header and relays result to subordinates @@ -337,7 +337,7 @@ func (sl *Slice) SubRelayPendingHeader(pendingHeader types.PendingHeader, reorg } } else { sl.updatePhCacheFromDom(pendingHeader, common.NodeLocation.Zone(), []int{common.PRIME_CTX, common.REGION_CTX}, reorg) - bestPh, exists := sl.phCache[sl.pendingHeader] + bestPh, exists := sl.phCache[sl.pendingHeaderHeadHash] if exists { sl.miner.worker.pendingHeaderFeed.Send(bestPh.Header) } @@ -380,7 +380,7 @@ func (sl *Slice) updatePhCacheFromDom(pendingHeader types.PendingHeader, termini sl.phCache[hash] = localPendingHeader if reorg { - sl.pendingHeader = hash + sl.pendingHeaderHeadHash = hash } } log.Warn("no pending header found for", "terminus", hash) @@ -394,7 +394,7 @@ func (sl *Slice) writeToPhCache(pendingHeaderWithTermini types.PendingHeader) { // pickPhCacheHead determines if the provided pendingHeader should be selected and returns true if selected func (sl *Slice) pickPhCacheHead(reorg bool, externPendingHeaderWithTermini types.PendingHeader) bool { if reorg { - sl.pendingHeader = externPendingHeaderWithTermini.Termini[terminiIndex] + sl.pendingHeaderHeadHash = externPendingHeaderWithTermini.Termini[terminiIndex] return true } @@ -409,10 +409,10 @@ func (sl *Slice) pickPhCacheHead(reorg bool, externPendingHeaderWithTermini type // updateCurrentPendingHeader compares the externPh parent td to the sl.pendingHeader parent td and sets sl.pendingHeader to the exterPh if the td is greater func (sl *Slice) updateCurrentPendingHeader(externPendingHeader types.PendingHeader) { externTd := sl.hc.GetTdByHash(externPendingHeader.Header.ParentHash()) - currentTd := sl.hc.GetTdByHash(sl.phCache[sl.pendingHeader].Header.ParentHash()) - log.Debug("updateCurrentPendingHeader:", "currentParent:", sl.phCache[sl.pendingHeader].Header.ParentHash(), "currentTd:", currentTd, "externParent:", externPendingHeader.Header.ParentHash(), "externTd:", externTd) + currentTd := sl.hc.GetTdByHash(sl.phCache[sl.pendingHeaderHeadHash].Header.ParentHash()) + log.Debug("updateCurrentPendingHeader:", "currentParent:", sl.phCache[sl.pendingHeaderHeadHash].Header.ParentHash(), "currentTd:", currentTd, "externParent:", externPendingHeader.Header.ParentHash(), "externTd:", externTd) if currentTd.Cmp(externTd) < 0 { - sl.pendingHeader = externPendingHeader.Termini[terminiIndex] + sl.pendingHeaderHeadHash = externPendingHeader.Termini[terminiIndex] } } @@ -425,7 +425,7 @@ func (sl *Slice) init(genesis *Genesis) error { // Initialize slice state for genesis knot genesisHash := sl.Config().GenesisHash genesisTermini := []common.Hash{genesisHash, genesisHash, genesisHash, genesisHash} - sl.pendingHeader = genesisHash + sl.pendingHeaderHeadHash = genesisHash rawdb.WriteTermini(sl.sliceDb, genesisHash, genesisTermini) // Append each of the knot blocks @@ -611,14 +611,14 @@ func (sl *Slice) updatePendingHeadersCache() { // loadLastState loads the phCache and the slice pending header hash from the db. func (sl *Slice) loadLastState() error { sl.phCache = rawdb.ReadPhCache(sl.sliceDb) - sl.pendingHeader = rawdb.ReadCurrentPendingHeaderHash(sl.sliceDb) + sl.pendingHeaderHeadHash = rawdb.ReadCurrentPendingHeaderHash(sl.sliceDb) return nil } // Stop stores the phCache and the sl.pendingHeader hash value to the db. func (sl *Slice) Stop() { // write the ph head hash to the db. - rawdb.WriteCurrentPendingHeaderHash(sl.sliceDb, sl.pendingHeader) + rawdb.WriteCurrentPendingHeaderHash(sl.sliceDb, sl.pendingHeaderHeadHash) // Write the ph cache to the dd. rawdb.WritePhCache(sl.sliceDb, sl.phCache)