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

fix(relayer): ensure submission order #2198

Merged
merged 2 commits into from
Oct 18, 2024
Merged

Conversation

corverroos
Copy link
Collaborator

@corverroos corverroos commented Oct 17, 2024

Fixes race condition in relayer that resulted in unordered submissions sometimes.

This refactors the Sender to reserve nonces synchronously, but do the actual sending asynchronously. Active buffer refactored to reserves nonces synchronously ensuring strictly ordered submissions.

issue: https://github.com/omni-network/ops/issues/533

@corverroos corverroos changed the title wip: ordered submissions fix(relayer): ensure submission order Oct 18, 2024
@corverroos corverroos marked this pull request as ready for review October 18, 2024 09:02
returnErr := func(err error) chan error {
resp := make(chan error, 1)
resp <- err

Copy link
Contributor

Choose a reason for hiding this comment

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

we should close resp channel

Suggested change
close(resp)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is buffered, and we either add err or nil so I do not think we need to close it

}
asyncResp := make(chan error, 1) // Actual async response populated by goroutine below.
go func() {
tx, rec, err := s.txMgr.Send(ctx, candidate)
Copy link
Contributor

Choose a reason for hiding this comment

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

we should close asyncResp channel, to prevent routine leak

Suggested change
tx, rec, err := s.txMgr.Send(ctx, candidate)
defer close(asyncResp)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no goroutines to leak

relayer/app/sender.go Outdated Show resolved Hide resolved
relayer/app/sender.go Outdated Show resolved Hide resolved
@@ -187,7 +187,7 @@ func newMsgStreamMapper(network netconf.Network) msgStreamMapper {

func (w *Worker) newCallback(
msgFilter *msgCursorFilter,
sender SendFunc,
sendBuffer func(context.Context, xchain.Submission) error,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
sendBuffer func(context.Context, xchain.Submission) error,
mempoolSubmit func(context.Context, xchain.Submission) error,

nit: using sender was a bit confusing when first looking at the code

Copy link
Contributor

@kc1116 kc1116 left a comment

Choose a reason for hiding this comment

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

Nicely done 🚀

@corverroos corverroos enabled auto-merge (squash) October 18, 2024 14:26
@corverroos corverroos merged commit 27b79e9 into main Oct 18, 2024
18 checks passed
@corverroos corverroos deleted the corver/orderedsubmits branch October 18, 2024 16:26
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.

3 participants