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(sew): ADR-029 generalized unbonding and babylon v0.13.0 #87

Merged
merged 10 commits into from
Oct 24, 2024

Conversation

Lazar955
Copy link
Member

@Lazar955 Lazar955 commented Oct 23, 2024

Extends staking event watcher to be able to send whole stake spending tx as well as inclusion proof.

@Lazar955 Lazar955 requested a review from RafilxTenfen October 23, 2024 14:56
@@ -426,7 +427,7 @@ func (sew *StakingEventWatcher) watchForSpend(spendEvent *notifier.SpendEvent, t
return
}

schnorrSignature, err := tryParseStakerSignatureFromSpentTx(spendingTx, td)
_, err := tryParseStakerSignatureFromSpentTx(spendingTx, td)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this function actually checks whether stake spending transaction is unbonding transaction registered to Babylon.

So imo we can leave it but we should send inclusion proof through sew.reportUnbondingToBabylon(quitCtx, delegationId, spendingTx, proof) even if it returns error (as now we have possibility to report even invalid unbondings to Babylon)

So the only difference between error case and non err case is metrics which we are incrementing.

return nil, err
}

if status != btcclient.TxInChain {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder whether we need this check i.e whether <-spendEvent.Spend: return when tx is in the mempool or in chain. (eitherway better to have it just in case)

func (sew *StakingEventWatcher) buildSpendingTxProof(spendingTx *wire.MsgTx) (*btcstakingtypes.InclusionProof, error) {
txHash := spendingTx.TxHash()
if len(spendingTx.TxOut) == 0 {
return nil, fmt.Errorf("stake spending tx has no outputs")
Copy link
Collaborator

Choose a reason for hiding this comment

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

tbh this should not happen as we are handling tx after we detected it was included in mempool/chain. Maybe panic here or have some error which we do not retry ? (imo this means our assumptions are broken so we should do something drastic)

signer := bca.babylonClient.MustGetAddr()

var stakeSpendingTxBuf bytes.Buffer
if err := stakeSpendingTx.Serialize(&stakeSpendingTxBuf); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

on bbn (bbn "github.com/babylonlabs-io/babylon/types")we have this helper - bbn.SerializeBTCTx(

sew.logger.Errorf("unbonding tx %s for staking tx %s proof not built", spendingTxHash, delegationId)
return
}
sew.reportUnbondingToBabylon(quitCtx, delegationId, spendingTx, proof)
sew.waitForDelegationToStopBeingActive(quitCtx, delegationId)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we probably do not need it here any more, as after succesful unbonding report delegation won't be active (and reportUnbondingToBabylon has acitvity check inside)

@Lazar955 Lazar955 changed the title feat(sew): ADR-029 generalized unbonding feat(sew): ADR-029 generalized unbonding and babylon v0.13.0 Oct 24, 2024
@Lazar955 Lazar955 merged commit 8ab1b14 into main Oct 24, 2024
12 checks passed
@Lazar955 Lazar955 deleted the lazar/update-adr-029 branch October 24, 2024 07:47
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