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

Integrate with batch transactions #24

Merged
merged 14 commits into from
Jan 26, 2024
Merged

Integrate with batch transactions #24

merged 14 commits into from
Jan 26, 2024

Conversation

boojamya
Copy link
Member

@boojamya boojamya commented Dec 12, 2023

Batch tx example: https://etherscan.io/tx/0x55dcde141614c0baf34827d1dcdced183b2ea166cec0b849a5c8eb029ec0bb92

Prior to this PR, the relayer couldn't handle batch transactions.
As you can see here:
https://github.com/strangelove-ventures/noble-cctp-relayer/blob/bd7b450e96529bfa75f8e2274591424fa94d11c3/cmd/process.go#L92-L94

We were storing and loading messages by a lookup key created by the SourceTxHash and the Type, however batch transactions could have the same SourceTxHash and the Type but different message MsgSendBytes.

So as a transactions with multiple messages would come in, they would overwrite each other in the processingQueue

@boojamya boojamya marked this pull request as ready for review December 13, 2023 00:09
@boojamya boojamya requested a review from johnletey December 13, 2023 00:13
@boojamya boojamya linked an issue Dec 13, 2023 that may be closed by this pull request
Copy link
Member

@jtieri jtieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had a couple nits, a few questions and i think just one real issue i pointed out regarding the pointer equality stuff!

cmd/noble/broadcast.go Outdated Show resolved Hide resolved
cmd/process.go Outdated
Comment on lines 107 to 112
batchPosition = 0
State.Store(dequeuedMsg.SourceTxHash, []*types.MessageState{dequeuedMsg})
msg, _ = State.Load(dequeuedMsg.SourceTxHash)
p.Mu.Lock()
msg[batchPosition].Status = types.Created
p.Mu.Unlock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does the MessageState need to be stored, then loaded before mutating the msg at index 0 to set Status = types.Created?

couldn't you set Status = types.Created before calling Store?

cmd/process.go Outdated
Comment on lines 119 to 124
if s == dequeuedMsg {
batchPosition = pos
found = true
break
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like this if statement is checking the equality of two pointer types which may not have the intended behavior here. see: https://stackoverflow.com/questions/34276205/comparing-pointers-in-go

dequeuedMsg is read from the processingQueue channel, which i'm guessing is reading data from over the network, and s is loaded from state so even if the two underlying structs have the same data fields the pointers are pointing to different locations in memory.

to properly check the equality of two different instances of MessageState you will want to make use of an Equals method which explicitly checks the equality of each field in the structs.

cmd/process.go Show resolved Hide resolved
cmd/process.go Outdated
p.Mu.Lock()
msg[batchPosition].Status = types.Pending
msg[batchPosition].Updated = time.Now()
p.Mu.Unlock()
time.Sleep(10 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity why do we need to wait 10 seconds before sending the msg over the processingQueue channel?

Comment on lines 63 to 66
p.Mu.RLock()
require.Equal(t, types.Created, actualState[0].Status)
p.Mu.RUnlock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the lock necessary in this test case?

Comment on lines 95 to 98
p.Mu.RLock()
require.Equal(t, types.Complete, actualState[0].Status)
p.Mu.RUnlock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous question about locks being used in these test cases

SourceTxHash: txHash,
IrisLookupId: "123",
Status: Filtered,
MsgSentBytes: []byte("i like turtles"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 🐢

@boojamya boojamya changed the base branch from main to andrew/multiple January 26, 2024 18:35
@boojamya boojamya merged commit df87b89 into andrew/multiple Jan 26, 2024
1 check passed
@joelsmith-2019 joelsmith-2019 deleted the dan/batch-tx branch June 12, 2024 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

This cctp relayer should handle batch messages
3 participants