-
Notifications
You must be signed in to change notification settings - Fork 33
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(rfq-relayer): wait for finality before proving #3062
Changes from 13 commits
d3e88af
c23ae24
f00f3c8
7036c04
97df029
6842788
a5286c8
212d9b8
f45dad8
108c64d
12715d9
3524d13
19dd299
99e5d50
6d41b64
978bcf2
65a06e0
db7f9fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -378,8 +378,28 @@ | |
// Step 6: ProvePosting | ||
// | ||
// This is the sixth step in the bridge process. Here we submit the claim transaction to the origin chain. | ||
func (q *QuoteRequestHandler) handleRelayCompleted(ctx context.Context, _ trace.Span, request reldb.QuoteRequest) (err error) { | ||
// relays been completed, it's time to go back to the origin chain and try to prove | ||
func (q *QuoteRequestHandler) handleRelayCompleted(ctx context.Context, span trace.Span, request reldb.QuoteRequest) (err error) { | ||
relayBlockNumber, err := q.getRelayBlockNumber(ctx, request) | ||
if err != nil { | ||
return fmt.Errorf("could not get relay block number: %w", err) | ||
} | ||
currentBlockNumber := q.Origin.LatestBlock() | ||
proveConfirmations, err := q.cfg.GetFinalityConfirmations(int(q.Dest.ChainID)) | ||
if err != nil { | ||
return fmt.Errorf("could not get prove confirmations: %w", err) | ||
} | ||
|
||
span.SetAttributes( | ||
attribute.Int("current_block_number", int(currentBlockNumber)), | ||
attribute.Int("relay_block_number", int(relayBlockNumber)), | ||
attribute.Int("prove_confirmations", int(proveConfirmations)), | ||
) | ||
if currentBlockNumber < relayBlockNumber+proveConfirmations { | ||
span.AddEvent("not enough confirmations") | ||
return nil | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM! Ensure tests cover the new logic. The changes improve the reliability of the proof submission process by ensuring that it only occurs when the blockchain state is sufficiently advanced. Ensure that the new logic is adequately tested. Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
// relay has been finalized, it's time to go back to the origin chain and try to prove | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dwasse we need to do a check similar to Guard's In the event where we submitted a tx, witnessed a The current code will still get a valid receipt for |
||
_, err = q.Origin.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { | ||
tx, err = q.Origin.Bridge.Prove(transactor, request.RawRequest, request.DestTxHash) | ||
if err != nil { | ||
|
@@ -399,6 +419,36 @@ | |
return nil | ||
} | ||
|
||
// getRelayBlockNumber fetches the block number of the relay transaction for a given quote request. | ||
func (q *QuoteRequestHandler) getRelayBlockNumber(ctx context.Context, request reldb.QuoteRequest) (blockNumber uint64, err error) { | ||
// fetch the transaction receipt for corresponding tx hash | ||
receipt, err := q.Dest.Client.TransactionReceipt(ctx, request.DestTxHash) | ||
if err != nil { | ||
return blockNumber, fmt.Errorf("could not get transaction receipt: %w", err) | ||
} | ||
parser, err := fastbridge.NewParser(q.Dest.Bridge.Address()) | ||
if err != nil { | ||
return blockNumber, fmt.Errorf("could not create parser: %w", err) | ||
} | ||
|
||
// check that a Relayed event was emitted | ||
for _, log := range receipt.Logs { | ||
if log == nil { | ||
continue | ||
} | ||
_, parsedEvent, ok := parser.ParseEvent(*log) | ||
if !ok { | ||
continue | ||
} | ||
_, ok = parsedEvent.(*fastbridge.FastBridgeBridgeRelayed) | ||
if ok { | ||
return receipt.BlockNumber.Uint64(), nil | ||
} | ||
} | ||
|
||
return blockNumber, fmt.Errorf("relayed event not found for dest tx hash: %s", request.DestTxHash.Hex()) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM! Consider adding error handling for potential reorgs. The function encapsulates the logic for fetching the block number of the relay transaction, improving code modularity and readability. Consider adding error handling for potential reorgs to ensure robustness. Add error handling for potential reorgs. |
||
|
||
// handleProofProvided handles the ProofProvided event emitted by the Bridge. | ||
// Step 7: ProvePosted | ||
// | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add unit tests for the new function.
The function should include unit tests to ensure its correctness.
Do you want me to generate the unit testing code or open a GitHub issue to track this task?
Tools
GitHub Check: codecov/patch
Correct the error message in the type assertion failure.
The error message should mention
uint64
instead ofint
.Committable suggestion
Tools
GitHub Check: codecov/patch