aboutsummaryrefslogtreecommitdiff
path: root/eth/api_backend.go
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2020-09-20 16:53:47 -0400
committerDeterminant <[email protected]>2020-09-20 16:53:47 -0400
commite86ccf90bd33de6dc8694eb914b7b541aca53db6 (patch)
tree39a14ff66c42f95b805ce6fcf040c305460f5fce /eth/api_backend.go
parent30fae395d465eb79ee8bc122d67a58cea3ccfcf2 (diff)
parente233062dfde3ac938b937c860bc96caf57a7fe3f (diff)
Merge remote-tracking branch 'origin/master' into masterv0.3.3-rc.3
Diffstat (limited to 'eth/api_backend.go')
-rw-r--r--eth/api_backend.go28
1 files changed, 16 insertions, 12 deletions
diff --git a/eth/api_backend.go b/eth/api_backend.go
index bbc8691..6c5ebd8 100644
--- a/eth/api_backend.go
+++ b/eth/api_backend.go
@@ -65,10 +65,12 @@ func (b *EthAPIBackend) SetHead(number uint64) {
}
func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) {
- // Pending block is only known by the miner
+ // Pending block is only known by the miner in
+ // Ethereum, but Coreth does not have the same notion.
+ // So we treat requests for the pending block identically
+ // to the latest accepted block instead
if number == rpc.PendingBlockNumber {
- block := b.eth.miner.PendingBlock()
- return block.Header(), nil
+ return b.eth.AcceptedBlock().Header(), nil
}
// Otherwise resolve and return the block
if number == rpc.LatestBlockNumber {
@@ -102,10 +104,12 @@ func (b *EthAPIBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*ty
}
func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) {
- // Pending block is only known by the miner
+ // Pending block is only known by the miner in
+ // Ethereum, but Coreth does not have the same notion.
+ // So we treat requests for the pending block identically
+ // to the latest accepted block instead
if number == rpc.PendingBlockNumber {
- block := b.eth.miner.PendingBlock()
- return block, nil
+ return b.eth.AcceptedBlock(), nil
}
// Otherwise resolve and return the block
if number == rpc.LatestBlockNumber {
@@ -143,12 +147,12 @@ func (b *EthAPIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r
}
func (b *EthAPIBackend) StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error) {
- // Pending state is only known by the miner
- if number == rpc.PendingBlockNumber {
- block, state := b.eth.miner.Pending()
- return state, block.Header(), nil
- }
- // Otherwise resolve the block number and return its state
+ // Note: Ethereum typically first checks if the request is for
+ // the pending block (by rpc.PendingBlockNumber), but Coreth
+ // does not have the same notion of the miner having a pending
+ // block, so this is skipped here
+
+ // Request the block by its number and retrieve its state
header, err := b.HeaderByNumber(ctx, number)
if err != nil {
return nil, nil, err