GetRecepts: Read receipts from the DB. (#453)

This commit is contained in:
Igor Mandrigin 2020-04-14 15:50:47 +03:00 committed by GitHub
parent 339316deb2
commit d7e0122b1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -182,9 +182,22 @@ func (b *EthAPIBackend) StateAndHeaderByNumberOrHash(ctx context.Context, blockN
}
func (b *EthAPIBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
if number := rawdb.ReadHeaderNumber(b.eth.chainDb, hash); number != nil {
number := rawdb.ReadHeaderNumber(b.eth.chainDb, hash)
if number == nil {
return nil, nil
}
block := rawdb.ReadBlock(b.eth.chainDb, hash, *number)
dbstate := state.NewDbState(b.eth.chainDb, *number-1)
if cached := b.tryGetReceiptsFromDb(block); cached != nil {
return cached, nil
}
return b.getReceiptsByReApplyingTransactions(block, *number)
}
func (b *EthAPIBackend) getReceiptsByReApplyingTransactions(block *types.Block, number uint64) (types.Receipts, error) {
dbstate := state.NewDbState(b.eth.chainDb, number-1)
statedb := state.New(dbstate)
header := block.Header()
var receipts types.Receipts
@ -193,15 +206,25 @@ func (b *EthAPIBackend) GetReceipts(ctx context.Context, hash common.Hash) (type
vmConfig := vm.Config{}
for i, tx := range block.Transactions() {
statedb.Prepare(tx.Hash(), block.Hash(), i)
receipt, err := core.ApplyTransaction(b.ChainConfig(), b.eth.blockchain, nil, gp, statedb, dbstate, header, tx, usedGas, vmConfig)
if err != nil {
return nil, err
}
receipts = append(receipts, receipt)
}
return receipts, nil
}
return nil, nil
func (b *EthAPIBackend) tryGetReceiptsFromDb(block *types.Block) types.Receipts {
return rawdb.ReadReceipts(
b.eth.chainDb,
block.Hash(),
block.NumberU64(),
b.eth.blockchain.Config(),
)
}
func (b *EthAPIBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) {