From 2422000babcd13a52cc8fdb66e38d5f638022e7b Mon Sep 17 00:00:00 2001 From: Krish Date: Sun, 23 Jun 2024 23:01:00 +0800 Subject: [PATCH] logs added --- core/blockchain.go | 34 ++++++++++++++++++++++++++++------ core/blockchain_reader.go | 6 ++++++ core/rawdb/accessors_chain.go | 21 +++++++++++++++++++++ eth/catalyst/api.go | 13 +++++++++++-- miner/payload_building.go | 2 +- miner/worker.go | 1 + trie/triedb/pathdb/database.go | 1 + 7 files changed, 69 insertions(+), 9 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index c85a5c4b73..6b6f677df5 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -562,7 +562,7 @@ func (bc *BlockChain) loadLastState() error { return bc.Reset() } // Everything seems to be fine, set as the head block - bc.currentBlock.Store(headBlock.Header()) + bc.currentBlock.Store(headBlock.Header()) //这里是获取后改的地方 headBlockGauge.Update(int64(headBlock.NumberU64())) // Restore the last known head header @@ -589,7 +589,9 @@ func (bc *BlockChain) loadLastState() error { // Note: the safe block is not stored on disk and it is set to the last // known finalized block on startup if head := rawdb.ReadFinalizedBlockHash(bc.db); head != (common.Hash{}) { + log.Info("ZXL: finalized from db exist") if block := bc.GetBlockByHash(head); block != nil { + log.Info("ZXL: finalized from db", "finalized", block.Number().Uint64()) bc.currentFinalBlock.Store(block.Header()) headFinalizedBlockGauge.Update(int64(block.NumberU64())) bc.currentSafeBlock.Store(block.Header()) @@ -604,7 +606,9 @@ func (bc *BlockChain) loadLastState() error { headerTd = bc.GetTd(headHeader.Hash(), headHeader.Number.Uint64()) blockTd = bc.GetTd(headBlock.Hash(), headBlock.NumberU64()) ) + //headHeader是DB里读出来的 if headHeader.Hash() != headBlock.Hash() { + //这里确实不一样,header是没有回退过的,和打点结果一样,header没有回退保持为重启前 log.Info("Loaded most recent local header", "number", headHeader.Number, "hash", headHeader.Hash(), "td", headerTd, "age", common.PrettyAge(time.Unix(int64(headHeader.Time), 0))) } log.Info("Loaded most recent local block", "number", headBlock.Number(), "hash", headBlock.Hash(), "td", blockTd, "age", common.PrettyAge(time.Unix(int64(headBlock.Time()), 0))) @@ -728,13 +732,19 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha beyondRoot := (root == common.Hash{}) // Flag whether we're beyond the requested root (no root, always true) for { + log.Info("ZXL: step into for loop", "newHeadBlock", newHeadBlock.Number().Uint64()) + // If a root threshold was requested but not yet crossed, check if root != (common.Hash{}) && !beyondRoot && newHeadBlock.Root() == root { + log.Info("ZXL: step into newHeadBlock.Root() == root") beyondRoot, rootNumber = true, newHeadBlock.NumberU64() } if !bc.HasState(newHeadBlock.Root()) && !bc.stateRecoverable(newHeadBlock.Root()) { log.Trace("Block state missing, rewinding further", "number", newHeadBlock.NumberU64(), "hash", newHeadBlock.Hash()) if pivot == nil || newHeadBlock.NumberU64() > *pivot { + if pivot == nil { + log.Info("ZXL step into null pivot", "newHeadBlock", newHeadBlock.Number().Uint64()) + } parent := bc.GetBlock(newHeadBlock.ParentHash(), newHeadBlock.NumberU64()-1) if parent != nil { newHeadBlock = parent @@ -756,6 +766,8 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha } log.Debug("Rewound to block with state", "number", newHeadBlock.NumberU64(), "hash", newHeadBlock.Hash()) } + log.Info("ZXL step into found newhead logic", "newHeadBlock", newHeadBlock.Number().Uint64()) + break } log.Debug("Skipping block with threshold state", "number", newHeadBlock.NumberU64(), "hash", newHeadBlock.Hash(), "root", newHeadBlock.Root()) @@ -764,11 +776,17 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha } rawdb.WriteHeadBlockHash(db, newHeadBlock.Hash()) //这里已经写入的是带MPT的高度 + /* + rawdb.WriteFinalizedBlockHash() + rawdb.WriteCanonicalHash() + */ + // Degrade the chain markers if they are explicitly reverted. // In theory we should update all in-memory markers in the // 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()) + bc.currentBlock.Store(newHeadBlock.Header()) //这里是改的地方 + //这里是内存还是数据库?像是内存 log.Info("ZXL: rewind header now is", "header", newHeadBlock.Header().Number.Uint64()) headBlockGauge.Update(int64(newHeadBlock.NumberU64())) @@ -784,6 +802,8 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha // Rewind the snap block in a simpleton way to the target head if currentSnapBlock := bc.CurrentSnapBlock(); currentSnapBlock != nil && header.Number.Uint64() < currentSnapBlock.Number.Uint64() { newHeadSnapBlock := bc.GetBlock(header.Hash(), header.Number.Uint64()) + log.Info("ZXL: step into snap logic", "newHeadSnapBlock", newHeadSnapBlock.Number().Uint64()) + // If either blocks reached nil, reset to the genesis state if newHeadSnapBlock == nil { newHeadSnapBlock = bc.genesisBlock @@ -808,6 +828,7 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha if headNumber+1 < frozen { wipe = pivot == nil || headNumber >= *pivot } + //TODO 这里加上清理逻辑 return headHeader, wipe // Only force wipe if full synced } // Rewind the header chain, deleting all block bodies until then @@ -868,7 +889,7 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha headHeaderUpdated := bc.CurrentBlock() var safe *types.Header if safe = bc.CurrentSafeBlock(); safe != nil && headHeaderUpdated.Number.Uint64() < safe.Number.Uint64() { - log.Warn("SetHead invalidated safe block", "before", safe.Number.Uint64(), "after", headHeaderUpdated.Number.Uint64()) + log.Warn("1.SetHead invalidated safe block", "before", safe.Number.Uint64(), "after", headHeaderUpdated.Number.Uint64()) bc.SetSafe(headHeaderUpdated) } log.Info("ZXL", "safe before set", safe.Number.Uint64(), "after", bc.CurrentSafeBlock().Number.Uint64()) @@ -876,7 +897,7 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha var finalized *types.Header if finalized = bc.CurrentFinalBlock(); finalized != nil && headHeaderUpdated.Number.Uint64() < finalized.Number.Uint64() { - log.Error("SetHead invalidated finalized block", "before", finalized.Number.Uint64(), "after", headHeaderUpdated.Number.Uint64()) + log.Error("1.SetHead invalidated finalized block", "before", finalized.Number.Uint64(), "after", headHeaderUpdated.Number.Uint64()) bc.SetFinalized(headHeaderUpdated) } log.Info("ZXL", "finalized before set", finalized.Number.Uint64(), "after", bc.CurrentFinalBlock().Number.Uint64()) @@ -884,7 +905,7 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha // Clear safe block, finalized block if needed var safe *types.Header if safe = bc.CurrentSafeBlock(); safe != nil && head < safe.Number.Uint64() { - log.Warn("SetHead invalidated safe block") + log.Warn("2.SetHead invalidated safe block") bc.SetSafe(nil) } log.Info("ZXL", "safe after set", safe.Number.Uint64(), "head", head) @@ -892,7 +913,7 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha var finalized *types.Header if finalized = bc.CurrentFinalBlock(); finalized != nil && head < finalized.Number.Uint64() { - log.Error("SetHead invalidated finalized block") + log.Error("2.SetHead invalidated finalized block") bc.SetFinalized(nil) } log.Info("ZXL", "finalized after set", finalized.Number.Uint64(), "head", head) @@ -2475,6 +2496,7 @@ func (bc *BlockChain) InsertBlockWithoutSetHead(block *types.Block) error { } defer bc.chainmu.Unlock() + log.Info("ZXL: insert chain", "block", block.NumberU64()) _, err := bc.insertChain(types.Blocks{block}, false) return err } diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index 716ee2fccc..f1250d93de 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -31,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" + "github.com/ethereum/go-ethereum/log" ) // CurrentHeader retrieves the current head header of the canonical chain. The @@ -160,10 +161,15 @@ func (bc *BlockChain) HasFastBlock(hash common.Hash, number uint64) bool { func (bc *BlockChain) GetBlock(hash common.Hash, number uint64) *types.Block { // Short circuit if the block's already in the cache, retrieve otherwise if block, ok := bc.blockCache.Get(hash); ok { + log.Debug("zxl get from cache", "block", number) return block } block := rawdb.ReadBlock(bc.db, hash, number) + log.Debug("zxl get from db not cache", "block", number) if block == nil { + if number == 3942690 { + log.Info("zxl: block 3942690 nil") + } return nil } // Cache the found block for next time and return diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index 40d60236c1..c505037a0f 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -359,10 +359,16 @@ func ReadHeaderRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValu // the canonical data. data, _ = reader.Ancient(ChainFreezerHeaderTable, number) if len(data) > 0 && crypto.Keccak256Hash(data) == hash { + if number == 3942690 { + log.Info("zxl: read header 3942690 Ancient") + } return nil } // If not, try reading from leveldb data, _ = db.Get(headerKey(number, hash)) + if number == 3942690 { + log.Info("zxl: read header 3942690 db") + } return nil }) return data @@ -383,6 +389,9 @@ func HasHeader(db ethdb.Reader, hash common.Hash, number uint64) bool { func ReadHeader(db ethdb.Reader, hash common.Hash, number uint64) *types.Header { data := ReadHeaderRLP(db, hash, number) if len(data) == 0 { + if number == 3942690 { + log.Info("zxl: 3942690 header nil") + } return nil } header := new(types.Header) @@ -450,10 +459,16 @@ func ReadBodyRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValue // Check if the data is in ancients if isCanon(reader, number, hash) { data, _ = reader.Ancient(ChainFreezerBodiesTable, number) + if number == 3942690 { + log.Info("zxl: read body 3942690 from Ancient") + } return nil } // If not, try reading from leveldb data, _ = db.Get(blockBodyKey(number, hash)) + if number == 3942690 { + log.Info("zxl: read body 3942690 from leveldb") + } return nil }) return data @@ -772,10 +787,16 @@ func ReadLogs(db ethdb.Reader, hash common.Hash, number uint64) [][]*types.Log { func ReadBlock(db ethdb.Reader, hash common.Hash, number uint64) *types.Block { header := ReadHeader(db, hash, number) if header == nil { + if number == 3942690 { + log.Debug("3242690 header nil") + } return nil } body := ReadBody(db, hash, number) if body == nil { + if number == 3942690 { + log.Debug("3242690 body nil") + } return nil } return types.NewBlockWithHeader(header).WithBody(body.Transactions, body.Uncles).WithWithdrawals(body.Withdrawals) diff --git a/eth/catalyst/api.go b/eth/catalyst/api.go index 5f09ffcb93..a481fe25a3 100644 --- a/eth/catalyst/api.go +++ b/eth/catalyst/api.go @@ -241,7 +241,7 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl api.forkchoiceLock.Lock() defer api.forkchoiceLock.Unlock() - log.Trace("Engine API request received", "method", "ForkchoiceUpdated", "head", update.HeadBlockHash, "finalized", update.FinalizedBlockHash, "safe", update.SafeBlockHash) + log.Debug("Engine API request received", "method", "ForkchoiceUpdated", "head", update.HeadBlockHash, "finalized", update.FinalizedBlockHash, "safe", update.SafeBlockHash) if update.HeadBlockHash == (common.Hash{}) { log.Warn("Forkchoice requested update to zero hash") return engine.STATUS_INVALID, nil // TODO(karalabe): Why does someone send us this? @@ -324,6 +324,7 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl } if rawdb.ReadCanonicalHash(api.eth.ChainDb(), block.NumberU64()) != update.HeadBlockHash { // Block is not canonical, set head. + log.Debug("ZXL not Canonical") if latestValid, err := api.eth.BlockChain().SetCanonical(block); err != nil { return engine.ForkChoiceResponse{PayloadStatus: engine.PayloadStatusV1{Status: engine.INVALID, LatestValidHash: &latestValid}}, err } @@ -355,6 +356,7 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl return engine.STATUS_INVALID, engine.InvalidForkChoiceState.With(errors.New("final block not in canonical chain")) } // Set the finalized block + log.Info("ZXL: finalized set", "finalized", finalBlock.Number().Uint64()) api.eth.BlockChain().SetFinalized(finalBlock.Header()) } // Check if the safe block hash is in our canonical tree, if not somethings wrong @@ -369,12 +371,14 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl return engine.STATUS_INVALID, engine.InvalidForkChoiceState.With(errors.New("safe block not in canonical chain")) } // Set the safe block + log.Info("ZXL: safe set", "safe", safeBlock.Number().Uint64()) api.eth.BlockChain().SetSafe(safeBlock.Header()) } // If payload generation was requested, create a new block to be potentially // sealed by the beacon client. The payload will be requested later, and we // will replace it arbitrarily many times in between. if payloadAttributes != nil { + log.Warn("ZXL: fcu payloadAttributes has values") if api.eth.BlockChain().Config().Optimism != nil && payloadAttributes.GasLimit == nil { return engine.STATUS_INVALID, engine.InvalidPayloadAttributes.With(errors.New("gasLimit parameter is required")) } @@ -549,7 +553,7 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData, versionedHashe api.newPayloadLock.Lock() defer api.newPayloadLock.Unlock() - log.Trace("Engine API request received", "method", "NewPayload", "number", params.Number, "hash", params.BlockHash) + log.Debug("Engine API request received", "method", "NewPayload", "number", params.Number, "hash", params.BlockHash) block, err := engine.ExecutableDataToBlock(params, versionedHashes, beaconRoot) if err != nil { log.Warn("Invalid NewPayload params", "params", params, "error", err) @@ -562,6 +566,11 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData, versionedHashe // If we already have the block locally, ignore the entire execution and just // return a fake success. + + log.Info("zxl current block", "block", api.eth.BlockChain().CurrentBlock().Number) + log.Info("zxl current safe", "safe", api.eth.BlockChain().CurrentSafeBlock().Number) + log.Info("zxl current header", "header", api.eth.BlockChain().CurrentHeader().Number) + 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() diff --git a/miner/payload_building.go b/miner/payload_building.go index f3b8382783..2efe1671ca 100644 --- a/miner/payload_building.go +++ b/miner/payload_building.go @@ -286,7 +286,7 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) { log.Error("Built empty payload error", "id", args.Id(), "error", empty.err) return nil, empty.err } - log.Info("Built empty payload succeed", "id", args.Id(), "number", empty.block.NumberU64(), "hash", empty.block.Hash(), "elapsed", common.PrettyDuration(time.Since(start))) + log.Info("Built empty payload succeed", "id", args.Id(), "number", empty.block.NumberU64(), "hash", empty.block.Hash(), "root", empty.block.Header().Root, "elapsed", common.PrettyDuration(time.Since(start))) payload := newPayload(empty.block, args.Id()) // make sure to make it appear as full, otherwise it will wait indefinitely for payload building to complete. diff --git a/miner/worker.go b/miner/worker.go index fd9fa7e043..9ed61d3656 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -765,6 +765,7 @@ func (w *worker) makeEnv(parent *types.Header, header *types.Header, coinbase co } } if err != nil { + log.Error("zxl error occured here", "missing block", parent.Number.Uint64(), "root", parent.Root) return nil, err } state.StartPrefetcher("miner") diff --git a/trie/triedb/pathdb/database.go b/trie/triedb/pathdb/database.go index 962f7a8a64..8fdfde2cb9 100644 --- a/trie/triedb/pathdb/database.go +++ b/trie/triedb/pathdb/database.go @@ -221,6 +221,7 @@ func New(diskdb ethdb.Database, config *Config) *Database { // Reader retrieves a layer belonging to the given state root. func (db *Database) Reader(root common.Hash) (layer, error) { + log.Info("zxl get mpt", "root", root) l := db.tree.get(root) if l == nil { r, err := db.tree.bottom().buffer.proposedBlockReader(root)