Skip to content

Commit

Permalink
core: check of ancientdb, backport bnb-chain/bsc#817
Browse files Browse the repository at this point in the history
Signed-off-by: Delweng <delweng@gmail.com>
  • Loading branch information
jsvisa authored and manav2401 committed Apr 9, 2024
1 parent cf08b90 commit f031033
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions core/headerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ func (hc *HeaderChain) Reorg(headers []*types.Header) error {
)

for rawdb.ReadCanonicalHash(hc.chainDb, headNumber) != headHash {
if frozen, _ := hc.chainDb.Ancients(); frozen == headNumber {
break
}
rawdb.WriteCanonicalHash(batch, headHash, headNumber)

if headNumber == 0 {
Expand Down
6 changes: 4 additions & 2 deletions core/rawdb/chain_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ func iterateTransactions(db ethdb.Database, from uint64, to uint64, reverse bool
number uint64
rlp rlp.RawValue
}

if to == from {
if offset := db.AncientOffSet(); offset > from {
from = offset
}
if to <= from {
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions eth/state_accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func (eth *Ethereum) hashState(ctx context.Context, block *types.Block, reexec u
// The optional base statedb is given, mark the start point as parent block
statedb, database, triedb, report = base, base.Database(), base.Database().TrieDB(), false
current = eth.blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1)
if current == nil {
return nil, nil, fmt.Errorf("missing parent block %v %d", block.ParentHash(), block.NumberU64()-1)
}
} else {
// Otherwise, try to reexec blocks until we find a state or reach our limit
current = block
Expand Down
3 changes: 3 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,9 @@ func (s *BlockChainAPI) GetTransactionReceiptsByBlock(ctx context.Context, block
if err != nil {
return nil, err
}
if receipts == nil {
return nil, fmt.Errorf("block %d receipts not found", block.NumberU64())
}

txs := block.Transactions()

Expand Down

0 comments on commit f031033

Please sign in to comment.