fix pruner block tool bug, add some check logic

This commit is contained in:
user 2022-03-25 15:22:21 +08:00
parent 21a3b11d17
commit c0c6396509
5 changed files with 18 additions and 2 deletions

@ -278,7 +278,8 @@ func pruneBlock(ctx *cli.Context) error {
var newAncientPath string
oldAncientPath := ctx.GlobalString(utils.AncientFlag.Name)
if !filepath.IsAbs(oldAncientPath) {
oldAncientPath = stack.ResolvePath(oldAncientPath)
// force absolute paths, which often fail due to the splicing of relative paths
return errors.New("datadir.ancient not abs path")
}
path, _ := filepath.Split(oldAncientPath)

@ -250,6 +250,9 @@ func (hc *HeaderChain) writeHeaders(headers []*types.Header) (result *headerWrit
headHeader = hc.GetHeader(headHash, headNumber)
)
for rawdb.ReadCanonicalHash(hc.chainDb, headNumber) != headHash {
if frozen, _ := hc.chainDb.Ancients(); frozen == headNumber {
break
}
rawdb.WriteCanonicalHash(markerBatch, headHash, headNumber)
headHash = headHeader.ParentHash
headNumber = headHeader.Number.Uint64() - 1

@ -95,7 +95,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
}
threads := to - from

@ -74,6 +74,9 @@ func (eth *Ethereum) stateAtBlock(block *types.Block, reexec uint64, base *state
// The optional base statedb is given, mark the start point as parent block
statedb, database, report = base, base.Database(), false
current = eth.blockchain.GetBlock(block.ParentHash(), block.NumberU64()-1)
if current == nil {
return 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

@ -1774,10 +1774,16 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceiptsByBlockNumber(ctx conte
if err != nil {
return nil, err
}
if receipts == nil {
return nil, fmt.Errorf("block %d receipts not found", blockNumber)
}
block, err := s.b.BlockByHash(ctx, blockHash)
if err != nil {
return nil, err
}
if block == nil {
return nil, fmt.Errorf("block %d not found", blockNumber)
}
txs := block.Transactions()
if len(txs) != len(receipts) {
return nil, fmt.Errorf("txs length doesn't equal to receipts' length")