Skip to content

Commit

Permalink
chore: add new field to transaction tracked of tx hash of btc delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Nov 26, 2024
1 parent 9958f45 commit 417d18f
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 124 deletions.
2 changes: 1 addition & 1 deletion itest/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ func TestStakeFromPhase1(t *testing.T) {
params, err := cl.Params()
require.NoError(t, err)

tm.mineNEmptyBlocks(t, params.ConfirmationTimeBlocks, true)
tm.mineNEmptyBlocks(t, params.ConfirmationTimeBlocks+1, true)
tm.waitForStakingTxState(t, txHash, proto.TransactionState_SENT_TO_BABYLON)

pend, err := tm.BabylonClient.QueryPendingBTCDelegations()
Expand Down
3 changes: 3 additions & 0 deletions itest/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,8 @@ func (tm *TestManager) insertCovenantSigForDelegation(
btcutil.Amount(btcDel.TotalSat),
regtestParams,
)
require.NoError(t, err)

slashingPathInfo, err := stakingInfo.SlashingPathSpendInfo()
require.NoError(t, err)

Expand All @@ -1159,6 +1161,7 @@ func (tm *TestManager) insertCovenantSigForDelegation(
// slash unbonding tx spends unbonding tx
unbondingMsgTx, _, err := bbntypes.NewBTCTxFromHex(btcDel.UndelegationResponse.UnbondingTxHex)
require.NoError(t, err)

unbondingInfo, err := staking.BuildUnbondingInfo(
btcDel.BtcPk.MustToBTCPK(),
fpBTCPKs,
Expand Down
161 changes: 50 additions & 111 deletions proto/transaction.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proto/transaction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ message TrackedTransaction {
bool watched = 11;
// this data is only filled if tracked transactions state is >= SENT_TO_BABYLON
UnbondingTxData unbonding_tx_data = 12;
string btcDelegationTxHash = 13;
}
7 changes: 4 additions & 3 deletions staker/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ func (event *stakingTxBtcConfirmedEvent) EventDesc() string {
}

type delegationSubmittedToBabylonEvent struct {
stakingTxHash chainhash.Hash
unbondingTx *wire.MsgTx
unbondingTime uint16
stakingTxHash chainhash.Hash
btcDelegationTxHash string
unbondingTx *wire.MsgTx
unbondingTime uint16
}

func (event *delegationSubmittedToBabylonEvent) EventID() chainhash.Hash {
Expand Down
21 changes: 14 additions & 7 deletions staker/stakerapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,6 @@ func (app *App) handlePostApprovalCmd(
bestBlockHeight := app.currentBestBlockHeight.Load()

err := app.wc.UnlockWallet(defaultWalletUnlockTimeout)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1575,15 +1574,23 @@ func (app *App) handleStakingCommands() {
continue
}

if err := app.txTracker.SetTxSentToBabylon(&stkTxHash, delData.Ud.UnbondingTransaction, delData.Ud.UnbondingTxUnbondingTime); err != nil {
cmd.errChan <- err
continue
err = app.txTracker.SetTxSentToBabylon(&stkTxHash, resp.TxHash, delData.Ud.UnbondingTransaction, delData.Ud.UnbondingTxUnbondingTime)
if err != nil {
utils.PushOrQuit(
cmd.errChan,
err,
app.quit,
)
} else {
utils.PushOrQuit(
cmd.successChanTxHash,
resp.TxHash,
app.quit,
)
}

app.logger.WithFields(logrus.Fields{
"consumerBtcDelegationTxHash": resp.TxHash,
}).Debugf("Sending BTC delegation was a success")
cmd.successChanTxHash <- resp.TxHash
case <-app.quit:
return
}
Expand Down Expand Up @@ -1635,7 +1642,7 @@ func (app *App) handleStakingEvents() {

case ev := <-app.delegationSubmittedToBabylonEvChan:
app.logStakingEventReceived(ev)
if err := app.txTracker.SetTxSentToBabylon(&ev.stakingTxHash, ev.unbondingTx, ev.unbondingTime); err != nil {
if err := app.txTracker.SetTxSentToBabylon(&ev.stakingTxHash, ev.btcDelegationTxHash, ev.unbondingTx, ev.unbondingTime); err != nil {
// TODO: handle this error somehow, it means we received confirmation for tx which we do not store
// which is seems like programming error. Maybe panic?
app.logger.Fatalf("Error setting state for tx %s: %s", ev.stakingTxHash, err)
Expand Down
3 changes: 2 additions & 1 deletion stakerdb/trackedtranactionstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,11 +974,11 @@ func (c *TrackedTransactionStore) SetTxConfirmed(

func (c *TrackedTransactionStore) SetTxSentToBabylon(
txHash *chainhash.Hash,
btcDelegationTxHash string,
unbondingTx *wire.MsgTx,
unbondingTime uint16,
) error {
update, err := newInitialUnbondingTxData(unbondingTx, unbondingTime)

if err != nil {
return err
}
Expand All @@ -990,6 +990,7 @@ func (c *TrackedTransactionStore) SetTxSentToBabylon(

tx.State = proto.TransactionState_SENT_TO_BABYLON
tx.UnbondingTxData = update
tx.BtcDelegationTxHash = btcDelegationTxHash
return nil
}

Expand Down
Loading

0 comments on commit 417d18f

Please sign in to comment.