Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add trace filter API #12123

Merged
merged 48 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
95bec19
initial commit for trace filter wip
snissn Jun 20, 2024
0ec7286
trace filter for gateway
snissn Jun 20, 2024
5751fba
trace filter implementation
snissn Jun 20, 2024
f773ca5
make gen
snissn Jun 20, 2024
9fd949d
implement after properly in trace_filter
snissn Jun 20, 2024
afae821
accept block numbers in hex format
snissn Jun 20, 2024
1f641ab
Merge branch 'master' into mikers/traceFilter
snissn Jun 25, 2024
ee51aac
trace_filter support for pending/latest/safe block numbers
snissn Jun 25, 2024
ac53ddb
run filter.FromBlock and filter.ToBlock through gw.checkBlkParam to m…
snissn Jun 27, 2024
10bdb58
Update node/impl/full/eth.go
snissn Jun 27, 2024
7b4c464
docsgen merge
snissn Jul 1, 2024
f67055d
document EthTraceFilterCriteria
snissn Jul 1, 2024
f74fd60
refactor: Handle nil pointers and optional defaults in EthBlockNumber…
snissn Jul 1, 2024
3d3609b
decode ToAddress and FromAddress in the caller function and re-use th…
snissn Jul 2, 2024
9edb692
bugfix for create trace and improve tests for trace filter
snissn Jul 3, 2024
f2f5458
Update node/impl/full/eth.go
snissn Jul 4, 2024
4344a52
fix for create type eth trace filter and improve tests
Jul 4, 2024
4bdd290
make gen
Jul 4, 2024
3473837
To and From slices do not need to be pointers
Jul 4, 2024
7598de6
use ethtypes.EthAddressList for FromAddress/ToAddress for trace_filter
Jul 5, 2024
9e5eac6
use *EthUint64 for filter.Count and filter.After
snissn Jul 16, 2024
ab9d541
merge
snissn Jul 16, 2024
c6597eb
changelog
snissn Jul 16, 2024
0173fc4
fix test type
snissn Jul 16, 2024
5cc2b26
decodeAddressFilter is unused
snissn Jul 16, 2024
1323ec7
improve trace filter example doc
snissn Jul 17, 2024
78c6162
Configuring EthTraceFilterMaxResults sets a limit to how many results…
snissn Jul 18, 2024
3ccbfc5
Merge branch 'master' into mikers/traceFilter
snissn Jul 18, 2024
d981c8f
config gen
snissn Jul 18, 2024
d470b2f
block number is flaky and not needed for test
snissn Jul 18, 2024
0569aef
Update node/impl/full/eth.go
snissn Jul 23, 2024
aabb500
Update node/impl/full/eth.go
snissn Jul 23, 2024
bfe56fb
bugfix
snissn Jul 23, 2024
1deb787
remove indentation style fix
snissn Jul 23, 2024
3b30a55
add null pointer check
snissn Jul 23, 2024
63e6cf3
Create a copy of blockTrace to avoid pointer quirks
snissn Jul 23, 2024
5a30419
method can be private
snissn Jul 23, 2024
bab6e1e
clean up doc for EthTraceFilterCriteria
snissn Jul 23, 2024
68def91
increase EthTraceFilterMaxResults to 500
snissn Jul 23, 2024
494deab
clean up earliest
snissn Jul 23, 2024
3a49b84
bury getEthBlockNumberFromString into EthTraceFilter to reduce confusion
snissn Jul 23, 2024
38fe510
merge
snissn Jul 23, 2024
bfbfacc
Update node/config/types.go
snissn Jul 24, 2024
0db2efe
Update node/impl/full/eth.go
snissn Jul 24, 2024
94dab56
Update node/impl/full/eth.go
snissn Jul 24, 2024
b9d898f
type fixes a.EthTraceFilterMaxResults
snissn Jul 24, 2024
56440b5
make docsgen-cli
snissn Jul 24, 2024
16468a6
merge + run make docs gen
snissn Jul 24, 2024
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
Prev Previous commit
Next Next commit
bugfix for create trace and improve tests for trace filter
  • Loading branch information
snissn committed Jul 3, 2024
commit 9edb692f8f4d60ef68f9394c0dc46a63f48adc2f
12 changes: 8 additions & 4 deletions gateway/proxy_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,16 @@ func (gw *Node) EthTraceFilter(ctx context.Context, filter ethtypes.EthTraceFilt
return nil, err
}

if err := gw.checkBlkParam(ctx, filter.ToBlock, 0); err != nil {
return nil, err
if filter.ToBlock != nil {
if err := gw.checkBlkParam(ctx, *filter.ToBlock, 0); err != nil {
return nil, err
}
}

if err := gw.checkBlkParam(ctx, filter.FromBlock, 0); err != nil {
return nil, err
if filter.FromBlock != nil {
if err := gw.checkBlkParam(ctx, *filter.FromBlock, 0); err != nil {
return nil, err
}
}

return gw.target.EthTraceFilter(ctx, filter)
Expand Down
12 changes: 10 additions & 2 deletions itests/eth_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,11 @@ func TestTraceFilter(t *testing.T) {
defer cancel()

// Define filter criteria
fromBlock := "0x1"
toBlock := "latest"
filter := ethtypes.EthTraceFilterCriteria{
FromBlock: "0x1",
ToBlock: "latest",
FromBlock: &fromBlock,
ToBlock: &toBlock,
}

// Example of creating and submitting a transaction
Expand Down Expand Up @@ -688,4 +690,10 @@ func TestTraceFilter(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, traces)
require.NotEmpty(t, traces)

//our transaction will be in the third element of traces at block 8 with the expected hash
require.EqualValues(t, traces[2].BlockNumber, 8)
require.EqualValues(t, traces[2].TransactionPosition, 1)
require.EqualValues(t, traces[2].TransactionHash, hash)

}
48 changes: 37 additions & 11 deletions node/impl/full/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,14 +1080,21 @@ func (a *EthModule) EthTraceFilter(ctx context.Context, filter ethtypes.EthTrace

traceCounter := 0

fromDecodedAddresses, fromErr := decodeAddressFilter(filter.FromAddress)
if fromErr != nil {
return nil, xerrors.Errorf("cannot decode FromAddress: %w", fromErr)
var fromDecodedAddresses *[]ethtypes.EthAddress
var toDecodedAddresses *[]ethtypes.EthAddress

if filter.FromAddress != nil {
fromDecodedAddresses, err = decodeAddressFilter(filter.FromAddress)
if err != nil {
return nil, xerrors.Errorf("cannot decode FromAddress: %w", err)
}
}

toDecodedAddresses, toErr := decodeAddressFilter(filter.ToAddress)
if toErr != nil {
return nil, xerrors.Errorf("cannot decode ToAddress: %w", toErr)
if filter.ToAddress != nil {
toDecodedAddresses, err = decodeAddressFilter(filter.ToAddress)
if err != nil {
return nil, xerrors.Errorf("cannot decode ToAddress: %w", err)
}
}

for blkNum := fromBlock; blkNum <= toBlock; blkNum++ {
Expand All @@ -1099,7 +1106,7 @@ func (a *EthModule) EthTraceFilter(ctx context.Context, filter ethtypes.EthTrace
for _, blockTrace := range blockTraces {
if matchFilterCriteria(blockTrace, filter, fromDecodedAddresses, toDecodedAddresses) {
traceCounter++
if traceCounter <= *filter.After {
if filter.After != nil && traceCounter <= *filter.After {
continue
}

Expand Down Expand Up @@ -1142,16 +1149,35 @@ func decodeAddressFilter(addresses *[]string) (*[]ethtypes.EthAddress, error) {

// matchFilterCriteria checks if a trace matches the filter criteria.
func matchFilterCriteria(trace *ethtypes.EthTraceBlock, filter ethtypes.EthTraceFilterCriteria, fromDecodedAddresses *[]ethtypes.EthAddress, toDecodedAddresses *[]ethtypes.EthAddress) bool {
var actionTo ethtypes.EthAddress
var actionFrom ethtypes.EthAddress
action, ok := trace.Action.(*ethtypes.EthCallTraceAction)
if !ok {
return false
if ok {
actionTo = action.To
actionFrom = action.From
} else {
actionCreate, okCreate := trace.Action.(*ethtypes.EthCreateTraceAction)
if okCreate {
//actionTo = actionCreate.To
actionFrom = actionCreate.From
resultCreate, okResult := trace.Action.(*ethtypes.EthCreateTraceResult)
if okResult {
if resultCreate.Address != nil {
actionTo = *resultCreate.Address
}
} else {
return false
}
} else {
return false
}
}

// Match FromAddress
if fromDecodedAddresses != nil && len(*fromDecodedAddresses) > 0 {
fromMatch := false
for _, ethAddr := range *fromDecodedAddresses {
if action.From == ethAddr {
if actionFrom == ethAddr {
fromMatch = true
break
}
Expand All @@ -1165,7 +1191,7 @@ func matchFilterCriteria(trace *ethtypes.EthTraceBlock, filter ethtypes.EthTrace
if toDecodedAddresses != nil && len(*toDecodedAddresses) > 0 {
toMatch := false
for _, ethAddr := range *toDecodedAddresses {
if action.To == ethAddr {
if actionTo == ethAddr {
toMatch = true
break
}
Expand Down
Loading