From 36c98a31e292be4f9d47c235b2179462d52a1c1b Mon Sep 17 00:00:00 2001 From: jsvisa Date: Thu, 3 Oct 2024 20:45:00 +0800 Subject: [PATCH] trace: retrieve from txpool Signed-off-by: jsvisa --- core/tracing/hooks.go | 1 + eth/tracers/live/live_api_eth.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/tracing/hooks.go b/core/tracing/hooks.go index 26495cd4ff..1b36cf6d24 100644 --- a/core/tracing/hooks.go +++ b/core/tracing/hooks.go @@ -73,6 +73,7 @@ type BlockEvent struct { // Backend interface provides the common API services (that are provided by // both full and light clients) with access to necessary functions. type Backend interface { + CurrentHeader() *types.Header HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) diff --git a/eth/tracers/live/live_api_eth.go b/eth/tracers/live/live_api_eth.go index c3edbc6a4b..5848eb2410 100644 --- a/eth/tracers/live/live_api_eth.go +++ b/eth/tracers/live/live_api_eth.go @@ -18,7 +18,12 @@ type ethAPI struct { func (n *ethAPI) GetTransactionBySenderAndNonce(ctx context.Context, sender common.Address, nonce hexutil.Uint) (*ethapi.RPCTransaction, error) { // TODO: // 1. return nil if sender is a contract - // 2. check with txpool first + + // Retrieve from txpool first + if tx := n.backend.GetPoolTransactionBySenderAndNonce(sender, uint64(nonce)); tx != nil { + return ethapi.NewRPCPendingTransaction(tx, n.backend.CurrentHeader(), n.backend.ChainConfig()), nil + } + txHash, err := n.live.kvdb.Get(append(sender.Bytes(), encodeNumber(uint64(nonce))...)) if err != nil { return nil, nil