Skip to content

Commit

Permalink
fix: use latest executed block for eth_getTransactionCount when runni…
Browse files Browse the repository at this point in the history
…ng as sequencer
  • Loading branch information
MorettiGeorgiev committed Oct 21, 2024
1 parent 7d2fc91 commit 367cbf6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (bn *BlockNumber) MarshallJson() string {
case -5:
return "latestExecuted"
default:
return fmt.Sprintf("0x%x", int64(*bn))
return fmt.Sprintf("0x%x", bn.Int64())
}
}

Expand Down
11 changes: 11 additions & 0 deletions turbo/jsonrpc/eth_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ func (api *APIImpl) GetTransactionCount(ctx context.Context, address libcommon.A
return nil, fmt.Errorf("getTransactionCount cannot open tx: %w", err1)
}
defer tx.Rollback()

latestExecutedBlockNumber, err := rpchelper.GetLatestExecutedBlockNumber(tx)
if err != nil {
return nil, fmt.Errorf("getTransactionCount cannot get latest executed block number: %w", err)
}

if blockNrOrHash.BlockNumber != nil && *blockNrOrHash.BlockNumber == rpc.BlockNumber(latestExecutedBlockNumber) {
blockNumber := rpc.BlockNumber(rpc.LatestExecutedBlockNumber)
blockNrOrHash.BlockNumber = &blockNumber
}

reader, err := rpchelper.CreateStateReader(ctx, tx, *blockNrOrHash, 0, api.filters, api.stateCache, api.historyV3(tx), "")
if err != nil {
return nil, err
Expand Down

0 comments on commit 367cbf6

Please sign in to comment.