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 19, 2024
1 parent fe59497 commit 26fc35f
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.Info("382y429nedjwjkoe")
return consensus.ErrPrunedAncestor
}
return nil
Expand Down
9 changes: 6 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -2261,19 +2261,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 +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-- {
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
9 changes: 5 additions & 4 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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:]
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
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 26fc35f

Please sign in to comment.