Skip to content

Commit 2eebc81

Browse files
authored
receipts improvements (#331)
1 parent 922e358 commit 2eebc81

17 files changed

+297
-209
lines changed

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ toolchain go1.24.2
77
// replace github.com/0xsequence/ethkit => ../ethkit
88

99
require (
10-
github.com/0xsequence/ethkit v1.38.6
10+
github.com/0xsequence/ethkit v1.39.0
1111
github.com/0xsequence/go-ethauth v0.14.0
1212
github.com/BurntSushi/toml v1.2.1
1313
github.com/davecgh/go-spew v1.1.1
@@ -41,7 +41,6 @@ require (
4141
github.com/gorilla/websocket v1.5.3 // indirect
4242
github.com/goware/breaker v0.2.0 // indirect
4343
github.com/goware/cachestore-mem v0.2.2 // indirect
44-
github.com/goware/calc v0.2.0 // indirect
4544
github.com/goware/channel v0.5.0 // indirect
4645
github.com/goware/singleflight v0.3.0 // indirect
4746
github.com/goware/superr v0.0.2 // indirect
@@ -55,7 +54,6 @@ require (
5554
github.com/supranational/blst v0.3.16 // indirect
5655
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
5756
github.com/zeebo/xxh3 v1.0.2 // indirect
58-
golang.org/x/exp v0.0.0-20251009144603-d2f985daa21b // indirect
5957
golang.org/x/net v0.47.0 // indirect
6058
golang.org/x/sync v0.18.0 // indirect
6159
golang.org/x/sys v0.38.0 // indirect

go.sum

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.work.sum

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

intent_config_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
"github.com/0xsequence/go-sequence/contracts"
1919
v3 "github.com/0xsequence/go-sequence/core/v3"
20+
"github.com/0xsequence/go-sequence/receipts"
2021
"github.com/0xsequence/go-sequence/testutil"
2122
"github.com/stretchr/testify/assert"
2223
"github.com/stretchr/testify/require"
@@ -591,7 +592,7 @@ func TestIntentTransactionToGuestModuleDeployAndCall(t *testing.T) {
591592
assert.Equal(t, "2255", ret[0])
592593

593594
// Assert sequence.WaitForMetaTxn is able to find the metaTxnID
594-
result, _, _, err := sequence.FetchMetaTransactionReceipt(context.Background(), testChain.ReceiptsListener, sequence.MetaTxnID(opPayload.Digest().Hash.Hex()[2:]))
595+
result, _, _, err := receipts.FetchMetaTransactionReceipt(context.Background(), testChain.ReceiptsListener, sequence.MetaTxnID(opPayload.Digest().Hash.Hex()[2:]))
595596
assert.NoError(t, err)
596597
assert.True(t, result.Status == sequence.MetaTxnExecuted)
597598

@@ -775,7 +776,7 @@ func TestIntentTransactionToGuestModuleDeployAndCallMultiplePayloads(t *testing.
775776
expectedMetaTxnID := sequence.MetaTxnID(opPayload.Digest().Hash.Hex()[2:])
776777
fmt.Printf("Expected MetaTxnID Payload %d: %s\n", i+1, expectedMetaTxnID)
777778

778-
result, _, _, err := sequence.FetchMetaTransactionReceipt(context.Background(), testChain.ReceiptsListener, expectedMetaTxnID)
779+
result, _, _, err := receipts.FetchMetaTransactionReceipt(context.Background(), testChain.ReceiptsListener, expectedMetaTxnID)
779780
assert.NoError(t, err)
780781
assert.True(t, result.Status == sequence.MetaTxnExecuted)
781782
}

receipt_fetcher.go

Lines changed: 0 additions & 120 deletions
This file was deleted.

receipts.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (r *Receipt) setNativeReceipt(receipt *types.Receipt) {
5959

6060
// This method is duplicated code from: `compressor/contract.go`
6161
// can't be used directly, because it would create a circular dependency
62-
func DecompressCalldata(ctx context.Context, to *common.Address, data []byte, provider *ethrpc.Provider) (common.Address, []byte, error) {
62+
func DecompressCalldata(ctx context.Context, to *common.Address, data []byte, provider ethrpc.Interface) (common.Address, []byte, error) {
6363
if len(data) == 0 {
6464
return common.Address{}, nil, fmt.Errorf("empty transaction data")
6565
}
@@ -213,6 +213,7 @@ func V3DecodeCallSucceededEvent(log *types.Log) (common.Hash, *big.Int, error) {
213213

214214
switch len(log.Topics) {
215215
case 1:
216+
// TODO: we can remove this as its the old v3-rc.4 and earlier format
216217
legacyInputs := make(abi.Arguments, len(event.Inputs))
217218
copy(legacyInputs, event.Inputs)
218219
legacyInputs[0].Indexed = false
Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ import (
1212
sequence "github.com/0xsequence/go-sequence"
1313
)
1414

15-
const MaxFilterBlockRange = 10_000
15+
const MaxFilterBlockRange = 7500
1616

17-
// FetchReceipts looks up the transaction that emitted Call* events for the given
18-
// digest and returns all decoded Sequence receipts along with the native receipt.
17+
// FetchMetaTransactionReceiptByETHGetLogs looks up the transaction that emitted Call*
18+
// events for the given digest and returns all decoded Sequence receipts along with
19+
// the native receipt.
1920
//
20-
// The `opHash` is also known as the "MetaTxnID"
21+
// The `opHash` is also known as the "MetaTxnID" but please make sure
22+
// it has the "0x" prefix when passing as a common.Hash, even though
23+
// sometimes we represent a MetaTxnID without the 0x prefix as a string.
2124
//
2225
// NOTE: toBlock can also be nil, in which case the latest block is used.
2326
//
@@ -27,9 +30,9 @@ const MaxFilterBlockRange = 10_000
2730
// receipt directly. However, this is not to be confused with where a "Call" inside
2831
// of the native transaction fails, but the native transaction itself succeeds which
2932
// is more common and works fine.
30-
func FetchReceipts(ctx context.Context, opHash common.Hash, provider *ethrpc.Provider, fromBlock, toBlock *big.Int) (Receipts, *types.Receipt, error) {
33+
func FetchMetaTransactionReceiptByETHGetLogs(ctx context.Context, opHash common.Hash, provider ethrpc.Interface, fromBlock, toBlock *big.Int) (Receipts, *types.Receipt, error) {
3134
if provider == nil {
32-
return Receipts{}, nil, fmt.Errorf("no provider")
35+
return Receipts{}, nil, fmt.Errorf("receipts: no provider")
3336
}
3437

3538
fromBlock_ := fromBlock
@@ -54,25 +57,22 @@ func FetchReceipts(ctx context.Context, opHash common.Hash, provider *ethrpc.Pro
5457
FromBlock: fromBlock,
5558
ToBlock: toBlock,
5659
Topics: [][]common.Hash{
57-
{sequence.V3CallSucceeded, sequence.V3CallFailed, sequence.V3CallAborted, sequence.V3CallSkipped},
60+
{sequence.V3CallSucceeded, sequence.V3CallFailed}, //, sequence.V3CallAborted, sequence.V3CallSkipped},
5861
{opHash},
5962
},
6063
}
6164

65+
// TODO: what if there is a node failure here, we should retry a few times
66+
// and also check the type of error from the node to see how we should behave/handle.
6267
logs, err := provider.FilterLogs(ctx, query)
6368
if err != nil {
6469
return Receipts{}, nil, fmt.Errorf("unable to filter logs: %w", err)
6570
}
6671
if len(logs) == 0 {
67-
// Fallback for legacy events where the digest is not indexed.
68-
query.Topics = [][]common.Hash{{sequence.V3CallSucceeded, sequence.V3CallFailed, sequence.V3CallAborted, sequence.V3CallSkipped}}
69-
logs, err = provider.FilterLogs(ctx, query)
70-
if err != nil {
71-
return Receipts{}, nil, fmt.Errorf("unable to filter logs without digest topic: %w", err)
72-
}
72+
return Receipts{}, nil, ethereum.NotFound
7373
}
7474

75-
log, err := findDigestLog(logs, opHash)
75+
log, err := findV3CallsDigestLog(logs, opHash)
7676
if err != nil {
7777
return Receipts{}, nil, err
7878
}
@@ -91,33 +91,27 @@ func FetchReceipts(ctx context.Context, opHash common.Hash, provider *ethrpc.Pro
9191
if receipts == nil {
9292
return Receipts{}, receipt, fmt.Errorf("decoded receipts do not include digest %v", opHash)
9393
}
94-
9594
return *receipts, receipt, nil
9695
}
9796

98-
func findDigestLog(logs []types.Log, digest common.Hash) (*types.Log, error) {
97+
func findV3CallsDigestLog(logs []types.Log, digest common.Hash) (*types.Log, error) {
9998
var selected *types.Log
100-
10199
for i := range logs {
102100
log := &logs[i]
103-
104-
if !matchesDigest(log, digest) {
101+
if !matchesV3CallsDigest(log, digest) {
105102
continue
106103
}
107-
108104
if selected == nil || isNewerLog(log, selected) {
109105
selected = log
110106
}
111107
}
112-
113108
if selected == nil {
114109
return nil, fmt.Errorf("no Call* events found for digest %v", digest)
115110
}
116-
117111
return selected, nil
118112
}
119113

120-
func matchesDigest(log *types.Log, digest common.Hash) bool {
114+
func matchesV3CallsDigest(log *types.Log, digest common.Hash) bool {
121115
if hash, _, err := sequence.V3DecodeCallSucceededEvent(log); err == nil && hash == digest {
122116
return true
123117
}

0 commit comments

Comments
 (0)