From 26fc35fb5aacc56187898b0275af68af04f371a6 Mon Sep 17 00:00:00 2001 From: VM Date: Mon, 18 Mar 2024 20:32:11 +0800 Subject: [PATCH] fix: add debug logs --- cmd/utils/flags.go | 2 +- core/block_validator.go | 2 ++ core/blockchain.go | 9 ++++++--- core/blockchain_reader.go | 4 ++++ eth/downloader/downloader.go | 9 +++++---- miner/worker.go | 2 +- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 3f334dc7c0..48f9fefc64 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2089,7 +2089,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) { cfg.Genesis = nil // fallback to db content - //validate genesis has PoS enabled in block 0 + // validate genesis has PoS enabled in block 0 genesis, err := core.ReadGenesis(chaindb) if err != nil { Fatalf("Could not read genesis from database: %v", err) diff --git a/core/block_validator.go b/core/block_validator.go index ce4b95f6c4..e3a7b11596 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -25,6 +25,7 @@ import ( "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/trie" ) @@ -140,6 +141,7 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error { if !v.bc.HasBlock(block.ParentHash(), block.NumberU64()-1) { return consensus.ErrUnknownAncestor } + log.Info("382y429nedjwjkoe") return consensus.ErrPrunedAncestor } return nil diff --git a/core/blockchain.go b/core/blockchain.go index 62b1e56f60..c0f82ef20c 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2008,7 +2008,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) go throwaway.TriePrefetchInAdvance(block, signer) } - //Process block using the parent state as reference point + // Process block using the parent state as reference point if bc.pipeCommit { statedb.EnablePipeCommit() } @@ -2261,10 +2261,12 @@ func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator) (i ) parent := it.previous() for parent != nil && !bc.HasState(parent.Root) { + log.Info("000 print parent", "block number", parent.Number.Uint64()) if bc.stateRecoverable(parent.Root) { if err := bc.triedb.Recover(parent.Root); err != nil { return 0, err } + log.Info("ttttt", "block number", parent.Number.Uint64()) break } hashes = append(hashes, parent.Hash()) @@ -2272,8 +2274,9 @@ func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator) (i parent = bc.GetHeader(parent.ParentHash, parent.Number.Uint64()-1) } + log.Info("uuuuu") if parent == nil { - return it.index, errors.New("missing parent") + return it.index, errors.New("555 missing parent") } // Import all the pruned blocks to make the state available var ( @@ -2343,7 +2346,7 @@ func (bc *BlockChain) recoverAncestors(block *types.Block) (common.Hash, error) } } if parent == nil { - return common.Hash{}, errors.New("missing parent") + return common.Hash{}, errors.New("666 missing parent") } // Import all the pruned blocks to make the state available for i := len(hashes) - 1; i >= 0; i-- { diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index 36cc1f5514..805c53118f 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -27,6 +27,7 @@ import ( "github.com/ethereum/go-ethereum/core/state/snapshot" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/triedb" @@ -323,15 +324,18 @@ func (bc *BlockChain) GetTd(hash common.Hash, number uint64) *big.Int { // HasState checks if state trie is fully present in the database or not. func (bc *BlockChain) HasState(hash common.Hash) bool { if bc.NoTries() { + log.Info("HasState no trie uuuuuu") return bc.snaps != nil && bc.snaps.Snapshot(hash) != nil } if bc.pipeCommit && bc.snaps != nil { + log.Info("lllllllll") // If parent snap is pending on verification, treat it as state exist if s := bc.snaps.Snapshot(hash); s != nil && !s.Verified() { return true } } _, err := bc.stateCache.OpenTrie(hash) + log.Error("qqqqqq", "error", err) return err == nil } diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 7e7e63bef9..d4e675a8a3 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -383,6 +383,7 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td, ttd *big.Int, // subsequent state reads, explicitly disable the trie database and state // syncer is responsible to address and correct any state missing. if d.blockchain.TrieDB().Scheme() == rawdb.PathScheme { + log.Info("ewiugdfewugfweyg") if err := d.blockchain.TrieDB().Disable(); err != nil { return err } @@ -1097,7 +1098,7 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64, head uint64) e filled, hashset, proced, err := d.fillHeaderSkeleton(from, headers) if err != nil { p.log.Debug("Skeleton chain invalid", "err", err) - return fmt.Errorf("%w: %v", errInvalidChain, err) + return fmt.Errorf("111 %w: %v", errInvalidChain, err) } headers = filled[proced:] hashes = hashset[proced:] @@ -1305,7 +1306,7 @@ func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode if len(chunkHeaders) > 0 { if n, err := d.lightchain.InsertHeaderChain(chunkHeaders); err != nil { log.Warn("Invalid header encountered", "number", chunkHeaders[n].Number, "hash", chunkHashes[n], "parent", chunkHeaders[n].ParentHash, "err", err) - return fmt.Errorf("%w: %v", errInvalidChain, err) + return fmt.Errorf("222 %w: %v", errInvalidChain, err) } } } @@ -1402,7 +1403,7 @@ func (d *Downloader) importBlockResults(results []*fetchResult) error { if errors.Is(err, core.ErrAncestorHasNotBeenVerified) { return err } - return fmt.Errorf("%w: %v", errInvalidChain, err) + return fmt.Errorf("333 %w: %v", errInvalidChain, err) } return nil } @@ -1600,7 +1601,7 @@ func (d *Downloader) commitSnapSyncData(results []*fetchResult, stateSync *state } if index, err := d.blockchain.InsertReceiptChain(blocks, receipts, d.ancientLimit); err != nil { log.Debug("Downloaded item processing failed", "number", results[index].Header.Number, "hash", results[index].Header.Hash(), "err", err) - return fmt.Errorf("%w: %v", errInvalidChain, err) + return fmt.Errorf("444 %w: %v", errInvalidChain, err) } return nil } diff --git a/miner/worker.go b/miner/worker.go index ba5afdf41f..9043f03a88 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -957,7 +957,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) { if genParams.parentHash != (common.Hash{}) { block := w.chain.GetBlockByHash(genParams.parentHash) if block == nil { - return nil, errors.New("missing parent") + return nil, errors.New("777 missing parent") } parent = block.Header() }