-
Notifications
You must be signed in to change notification settings - Fork 4
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
chore(relayer): prevent tx1 resubmission #28
Changes from 23 commits
3f0bb19
1991b21
55c846d
eaa9900
8575dd1
998cee9
376bc3a
93f04e3
3d19173
e3eb8b7
bdf4f9e
f7335e2
df198b3
e47d580
4fd5176
10de19b
ec26580
db30811
f2ca5f9
066a526
f74d816
c8a5c36
543812d
d90117d
c773f7d
a6a0da0
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 | ||
---|---|---|---|---|
|
@@ -80,9 +80,15 @@ func (rl *Relayer) SendCheckpointToBTC(ckpt *ckpttypes.RawCheckpointWithMetaResp | |||
return nil | ||||
} | ||||
|
||||
if rl.lastSubmittedCheckpoint == nil || rl.lastSubmittedCheckpoint.Epoch < ckptEpoch { | ||||
if rl.lastSubmittedCheckpoint == nil || | ||||
rl.lastSubmittedCheckpoint.Tx1 == nil || | ||||
rl.lastSubmittedCheckpoint.Epoch < ckptEpoch { | ||||
rl.logger.Infof("Submitting a raw checkpoint for epoch %v for the first time", ckptEpoch) | ||||
|
||||
if rl.lastSubmittedCheckpoint == 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. Can we separate the two cases? if |
||||
rl.lastSubmittedCheckpoint = &types.CheckpointInfo{} | ||||
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. Init the 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. Can we add this to the default structure at vigilante/submitter/relayer/relayer.go Line 47 in c8a5c36
and then simplify the check by removing |
||||
} | ||||
|
||||
submittedCheckpoint, err := rl.convertCkptToTwoTxAndSubmit(ckpt.Ckpt) | ||||
if err != nil { | ||||
return err | ||||
|
@@ -295,14 +301,21 @@ func (rl *Relayer) convertCkptToTwoTxAndSubmit(ckpt *ckpttypes.RawCheckpointResp | |||
func (rl *Relayer) ChainTwoTxAndSend(data1 []byte, data2 []byte) (*types.BtcTxInfo, *types.BtcTxInfo, error) { | ||||
// recipient is a change address that all the | ||||
// remaining balance of the utxo is sent to | ||||
tx1, err := rl.buildTxWithData(data1, nil) | ||||
if err != nil { | ||||
return nil, nil, fmt.Errorf("failed to add data to tx1: %w", err) | ||||
} | ||||
tx1 := rl.lastSubmittedCheckpoint.Tx1 | ||||
// prevent resending tx1 if it was successful | ||||
if rl.lastSubmittedCheckpoint.Tx1 == 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. Relevant changes here, cache the TX1 if successful 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. is there any chance for |
||||
var err error | ||||
tx1, err = rl.buildTxWithData(data1, nil) | ||||
if err != nil { | ||||
return nil, nil, fmt.Errorf("failed to add data to tx1: %w", err) | ||||
} | ||||
|
||||
tx1.TxId, err = rl.sendTxToBTC(tx1.Tx) | ||||
if err != nil { | ||||
return nil, nil, fmt.Errorf("failed to send tx1 to BTC: %w", err) | ||||
tx1.TxId, err = rl.sendTxToBTC(tx1.Tx) | ||||
if err != nil { | ||||
return nil, nil, fmt.Errorf("failed to send tx1 to BTC: %w", err) | ||||
} | ||||
// cache a successful tx1 submission | ||||
rl.lastSubmittedCheckpoint.Tx1 = tx1 | ||||
} | ||||
|
||||
// the second tx consumes the second output (index 1) | ||||
|
@@ -317,8 +330,6 @@ func (rl *Relayer) ChainTwoTxAndSend(data1 []byte, data2 []byte) (*types.BtcTxIn | |||
return nil, nil, fmt.Errorf("failed to send tx2 to BTC: %w", err) | ||||
} | ||||
|
||||
// TODO: if tx1 succeeds but tx2 fails, we should not resent tx1 | ||||
|
||||
return tx1, tx2, nil | ||||
} | ||||
|
||||
|
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.
maybe it's not the first time due to failure