Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rpc/jsonrpc/eth_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (api *APIImpl) GetTransactionCount(ctx context.Context, address common.Addr
reply.Nonce++
return (*hexutil.Uint64)(&reply.Nonce), nil
}
// txpool doesn't know about this address yet: fall through to DB lookup
}
tx, err1 := api.db.BeginTemporalRo(ctx)
if err1 != nil {
Expand Down
7 changes: 5 additions & 2 deletions rpc/jsonrpc/eth_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ func (api *APIImpl) GetBlockTransactionCountByNumber(ctx context.Context, blockN
return nil, err
}
if b == nil {
return nil, nil
// No pending block available: return 0x0
n := hexutil.Uint(0)
return &n, nil
}
n := hexutil.Uint(len(b.Transactions()))
return &n, nil
Expand Down Expand Up @@ -471,5 +473,6 @@ func (api *APIImpl) blockByNumber(ctx context.Context, blockNumber rpc.BlockNumb
return block, nil
}

return api.blockByNumberWithSenders(ctx, tx, blockNumber.Uint64())
// No pending block available: return nil
return nil, nil
}
8 changes: 8 additions & 0 deletions rpc/jsonrpc/eth_receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,14 @@ func (api *APIImpl) GetBlockReceipts(ctx context.Context, numberOrHash rpc.Block
return nil, err
}
defer tx.Rollback()

// Pending block receipts are only available if the miner has a pending block
// with executed transactions. Erigon receives only header+txs from the miner
// and cannot compute receipts on-the-fly.
if numberOrHash.BlockNumber != nil && *numberOrHash.BlockNumber == rpc.PendingBlockNumber {
return nil, errors.New("pending receipts are not available")
}

blockNum, blockHash, _, err := rpchelper.GetCanonicalBlockNumber(ctx, numberOrHash, tx, api._blockReader, api.filters)
if err != nil {
if errors.As(err, &rpc.BlockNotFoundErr{}) {
Expand Down
26 changes: 26 additions & 0 deletions rpc/jsonrpc/eth_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,21 @@ func (api *APIImpl) GetTransactionByBlockNumberAndIndex(ctx context.Context, blo
return nil, err
}

if blockNr == rpc.PendingBlockNumber {
b, err := api.blockByNumber(ctx, blockNr, tx)
if err != nil {
return nil, err
}
if b == nil {
return nil, errors.New("pending block is not available")
}
txs := b.Transactions()
if uint64(txIndex) >= uint64(len(txs)) {
return nil, nil
}
return ethapi.NewRPCTransaction(txs[txIndex], common.Hash{}, b.Time(), 0, uint64(txIndex), b.BaseFee()), nil
}

// https://www.quicknode.com/docs/ethereum/eth_getTransactionByBlockNumberAndIndex
blockNum, hash, _, err := rpchelper.GetBlockNumber(ctx, rpc.BlockNumberOrHashWithNumber(blockNr), tx, api._blockReader, api.filters)
if err != nil {
Expand Down Expand Up @@ -353,6 +368,17 @@ func (api *APIImpl) GetRawTransactionByBlockNumberAndIndex(ctx context.Context,
}
defer tx.Rollback()

if blockNr == rpc.PendingBlockNumber {
b, err := api.blockByNumber(ctx, blockNr, tx)
if err != nil {
return nil, err
}
if b == nil {
return nil, errors.New("pending block is not available")
}
return newRPCRawTransactionFromBlockIndex(b, uint64(index))
}

err = api.BaseAPI.checkPruneHistory(ctx, tx, blockNr.Uint64())
if err != nil {
return nil, err
Expand Down
Loading