mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
eth: handle nil blocks and state when pending is not available (#1053)
* eth: handle nil blocks and state when pending is not available * internal/ethapi: handle nil state and err in send condtional tx api
This commit is contained in:
parent
e1898d5aea
commit
260deb873d
4 changed files with 23 additions and 1 deletions
|
|
@ -277,6 +277,9 @@ func (api *DebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error) {
|
|||
// both the pending block as well as the pending state from
|
||||
// the miner and operate on those
|
||||
_, stateDb := api.eth.miner.Pending()
|
||||
if stateDb == nil {
|
||||
return state.Dump{}, errors.New("pending state is not available")
|
||||
}
|
||||
return stateDb.RawDump(opts), nil
|
||||
}
|
||||
|
||||
|
|
@ -385,6 +388,9 @@ func (api *DebugAPI) AccountRange(blockNrOrHash rpc.BlockNumberOrHash, start hex
|
|||
// both the pending block as well as the pending state from
|
||||
// the miner and operate on those
|
||||
_, stateDb = api.eth.miner.Pending()
|
||||
if stateDb == nil {
|
||||
return state.IteratorDump{}, errors.New("pending state is not available")
|
||||
}
|
||||
} else {
|
||||
var header *types.Header
|
||||
if number == rpc.LatestBlockNumber {
|
||||
|
|
|
|||
|
|
@ -68,6 +68,9 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb
|
|||
// Pending block is only known by the miner
|
||||
if number == rpc.PendingBlockNumber {
|
||||
block := b.eth.miner.PendingBlock()
|
||||
if block == nil {
|
||||
return nil, errors.New("pending block is not available")
|
||||
}
|
||||
return block.Header(), nil
|
||||
}
|
||||
// Otherwise resolve and return the block
|
||||
|
|
@ -136,6 +139,9 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
|
|||
// Pending block is only known by the miner
|
||||
if number == rpc.PendingBlockNumber {
|
||||
block := b.eth.miner.PendingBlock()
|
||||
if block == nil {
|
||||
return nil, errors.New("pending block is not available")
|
||||
}
|
||||
return block, nil
|
||||
}
|
||||
// Otherwise resolve and return the block
|
||||
|
|
@ -217,6 +223,9 @@ func (b *EthAPIBackend) StateAndHeaderByNumber(ctx context.Context, number rpc.B
|
|||
// Pending state is only known by the miner
|
||||
if number == rpc.PendingBlockNumber {
|
||||
block, state := b.eth.miner.Pending()
|
||||
if block == nil || state == nil {
|
||||
return nil, nil, errors.New("pending state is not available")
|
||||
}
|
||||
return state, block.Header(), nil
|
||||
}
|
||||
// Otherwise resolve the block number and return its state
|
||||
|
|
|
|||
|
|
@ -328,6 +328,9 @@ func (f *Filter) checkMatches(ctx context.Context, header *types.Header) ([]*typ
|
|||
// pendingLogs returns the logs matching the filter criteria within the pending block.
|
||||
func (f *Filter) pendingLogs() ([]*types.Log, error) {
|
||||
block, receipts := f.sys.backend.PendingBlockAndReceipts()
|
||||
if block == nil || receipts == nil {
|
||||
return nil, errors.New("pending block is not available")
|
||||
}
|
||||
if bloomFilter(block.Bloom(), f.addresses, f.topics) {
|
||||
var unfiltered []*types.Log
|
||||
for _, r := range receipts {
|
||||
|
|
|
|||
|
|
@ -74,7 +74,11 @@ func (api *BorAPI) SendRawTransactionConditional(ctx context.Context, input hexu
|
|||
}
|
||||
|
||||
currentHeader := api.b.CurrentHeader()
|
||||
currentState, _, _ := api.b.StateAndHeaderByNumber(ctx, rpc.BlockNumber(currentHeader.Number.Int64()))
|
||||
currentState, _, err := api.b.StateAndHeaderByNumber(ctx, rpc.BlockNumber(currentHeader.Number.Int64()))
|
||||
|
||||
if currentState == nil || err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
|
||||
// check block number range
|
||||
if err := currentHeader.ValidateBlockNumberOptions4337(options.BlockNumberMin, options.BlockNumberMax); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue