Skip to content

Commit

Permalink
Renamed pendingHeader in Slice to pendingHeaderHeadHash
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers authored and wizeguyy committed Jan 25, 2023
1 parent 0a75b75 commit 26dc990
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand All @@ -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]
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 26dc990

Please sign in to comment.