Skip to content

Commit

Permalink
fix: add debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
VM committed Mar 18, 2024
1 parent fe59497 commit c4a2a3f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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.Error("ErrPrunedAncestor happens")
return consensus.ErrPrunedAncestor
}
return nil
Expand Down
10 changes: 7 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
if setHead {
// First block is pruned, insert as sidechain and reorg only if TD grows enough
log.Debug("Pruned ancestor, inserting as sidechain", "number", block.Number(), "hash", block.Hash())
log.Info("qwuq8wqeiwew8ew Insert side chain")
return bc.insertSideChain(block, it)
} else {
// We're post-merge and the parent is pruned, try to recover the parent state
Expand Down Expand Up @@ -2008,7 +2009,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()
}
Expand Down Expand Up @@ -2261,19 +2262,22 @@ 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())
numbers = append(numbers, parent.Number.Uint64())

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 (
Expand Down Expand Up @@ -2343,7 +2347,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-- {
Expand Down
4 changes: 4 additions & 0 deletions core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,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:]
Expand Down Expand Up @@ -1305,7 +1305,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)
}
}
}
Expand Down Expand Up @@ -1402,7 +1402,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
}
Expand Down Expand Up @@ -1600,7 +1600,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
}
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit c4a2a3f

Please sign in to comment.