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(submitter): stateful submitter #43

Merged
merged 10 commits into from
Sep 16, 2024
Merged

Conversation

Lazar955
Copy link
Member

In case of a restart, we want to avoid wasting fees if we have already submitted transactions for a certain epoch.
Basic idea:
A crash occurs after sending both checkpoint transactions for epoch n to the BTC and recording them in the database. Upon restarting, we find that epoch n is still marked as sealed.

Before resending the transactions we first check our database and confirm that the transactions for this epoch have already been sent. Since the transactions were previously sent, the next step is to verify their status on our Bitcoin node.

If the Bitcoin node is aware of the transactions and they are present in the mempool, no further action is needed.
However, if the node does not recognize the transactions, this indicates they were lost, and we must resend them to the network.

References

@Lazar955 Lazar955 marked this pull request as ready for review September 13, 2024 11:43
// that has already been processed.
// Returns true if the first transactions are in the mempool (no resubmission needed),
// and false if any transaction was re-sent from the store.
func maybeResendFromStore(
Copy link
Member Author

@Lazar955 Lazar955 Sep 13, 2024

Choose a reason for hiding this comment

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

Meat and potato of the PR

"testing"
)

func Test_maybeResendFromStore(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

e2e test for this would be quite hard to implement with timings, opt for a unit

Copy link
Member

@gitferry gitferry left a comment

Choose a reason for hiding this comment

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

Great work! Minor comments:

Comment on lines +104 to +116
hasBeenProcessed, err := maybeResendFromStore(
ckptEpoch,
rl.store.LatestCheckpoint,
rl.GetRawTransaction,
rl.sendTxToBTC,
)
if err != nil {
return err
}

if hasBeenProcessed {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

seems this chunk of code is irrelevant to whether we should send a complete ckpt or only the second half. Can we move it out to avoid duplicate code?

Comment on lines +127 to +130
err = storeCkptFunc(submittedCkpt.Tx1.Tx, submittedCkpt.Tx2.Tx, submittedCkpt.Epoch)
if err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

same here

@Lazar955 Lazar955 merged commit 6f22cde into main Sep 16, 2024
8 checks passed
@Lazar955 Lazar955 deleted the lazar/stateful-submitter branch September 16, 2024 08:19
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.

2 participants