Skip to content

Commit

Permalink
revert fcu change
Browse files Browse the repository at this point in the history
  • Loading branch information
krish-nr committed Jun 26, 2024
1 parent 14cf8f5 commit 5454a7a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
12 changes: 11 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
// if there is no available state, waiting for state sync.
head := bc.CurrentBlock()
if !bc.NoTries() && !bc.HasState(head.Root) {
log.Info("zxl 现在有啦哈哈哈哈")
if head.Number.Uint64() == 0 {
// The genesis state is missing, which is only possible in the path-based
// scheme. This situation occurs when the initial state sync is not finished
Expand All @@ -412,6 +413,9 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
diskRoot = bc.triedb.Head()
}
}

log.Info("zxl get header and block", "headerchain header", bc.hc.CurrentHeader().Number.Uint64(), "currentheader", bc.CurrentBlock().Number.Uint64())

if diskRoot != (common.Hash{}) {
log.Warn("Head state missing, repairing", "number", head.Number, "hash", head.Hash(), "snaproot", diskRoot)

Expand Down Expand Up @@ -786,7 +790,7 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha
// last step, however the direction of SetHead is from high
// to low, so it's safe to update in-memory markers directly.
bc.currentBlock.Store(newHeadBlock.Header()) //这里是改的地方
//这里是内存还是数据库?像是内存
//这里是内存
log.Info("ZXL: rewind header now is", "header", newHeadBlock.Header().Number.Uint64())
headBlockGauge.Update(int64(newHeadBlock.NumberU64()))

Expand Down Expand Up @@ -833,9 +837,11 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha
}
// Rewind the header chain, deleting all block bodies until then
delFn := func(db ethdb.KeyValueWriter, hash common.Hash, num uint64) {
log.Info("zxl step into del fn")
// Ignore the error here since light client won't hit this path
frozen, _ := bc.db.Ancients()
if num+1 <= frozen {
log.Info("zxl step into frozen del fn")
// Truncate all relative data(header, total difficulty, body, receipt
// and canonical hash) from ancient store.
if _, err := bc.db.TruncateHead(num); err != nil {
Expand All @@ -844,6 +850,7 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha
// Remove the hash <-> number mapping from the active store.
rawdb.DeleteHeaderNumber(db, hash)
} else {
log.Info("zxl step into non-frozen del fn")
// Remove relative body and receipts from the active store.
// The header, total difficulty and canonical hash will be
// removed in the hc.SetHead function.
Expand All @@ -859,6 +866,9 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha
log.Info("ZXL: force set head", "head", target.Number.Uint64())
bc.hc.SetHead(target.Number.Uint64(), updateFn, delFn)
}
//zxl reset anyway
//bc.hc.SetHead(target.Number.Uint64(), updateFn, delFn)

} else {
// Rewind the chain to the requested head and keep going backwards until a
// block with a state is found or snap sync pivot is passed
Expand Down
16 changes: 9 additions & 7 deletions eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,20 +572,22 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData, versionedHashe
log.Info("zxl current header", "header", api.eth.BlockChain().CurrentHeader().Number)

//ZXL 这里改条件
if api.eth.BlockChain().HasBlockAndState(params.BlockHash, params.Number) {
log.Warn("Ignoring already known beacon payload", "number", params.Number, "hash", params.BlockHash, "age", common.PrettyAge(time.Unix(int64(block.Time()), 0)))
hash := block.Hash()
return engine.PayloadStatusV1{Status: engine.VALID, LatestValidHash: &hash}, nil
}

/*
if block := api.eth.BlockChain().GetBlockByHash(params.BlockHash); block != nil {
if api.eth.BlockChain().HasBlockAndState(params.BlockHash, params.Number) {
log.Warn("Ignoring already known beacon payload", "number", params.Number, "hash", params.BlockHash, "age", common.PrettyAge(time.Unix(int64(block.Time()), 0)))
hash := block.Hash()
return engine.PayloadStatusV1{Status: engine.VALID, LatestValidHash: &hash}, nil
}
*/

if block := api.eth.BlockChain().GetBlockByHash(params.BlockHash); block != nil {
log.Warn("Ignoring already known beacon payload", "number", params.Number, "hash", params.BlockHash, "age", common.PrettyAge(time.Unix(int64(block.Time()), 0)))
hash := block.Hash()
return engine.PayloadStatusV1{Status: engine.VALID, LatestValidHash: &hash}, nil
}

// If this block was rejected previously, keep rejecting it
if res := api.checkInvalidAncestor(block.Hash(), block.Hash()); res != nil {
return *res, nil
Expand Down

0 comments on commit 5454a7a

Please sign in to comment.