Skip to content

Commit

Permalink
Add more info to staking creation event (#238)
Browse files Browse the repository at this point in the history
Fixes: #237

- Adding `PkScript` makes is possible to listen to confirmation event
using lnd libraries (and therefore btc lightclients)
- Addinng `StakingOutputIndex` makes it possible to identify staking
output as utxo i.e tuple (hash, idx)
  • Loading branch information
KonradStaniec authored Oct 30, 2024
1 parent a98cfd9 commit c7eddc9
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 108 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* [#235](https://github.com/babylonlabs-io/babylon/pull/235) Change default values
for iavl cache when using `testnet` command

### API Breaking

* [238](https://github.com/babylonlabs-io/babylon/pull/238) Add additional data
to delegation creation event

## v0.14.1

### API Breaking
Expand Down
20 changes: 12 additions & 8 deletions proto/babylon/btcstaking/v1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -147,26 +147,30 @@ message EventBTCDelegationCreated {
// staking_tx_hash is the hash of the staking tx.
// It uniquely identifies a BTC delegation
string staking_tx_hash = 1 [(amino.dont_omitempty) = true];
// staking_output_pk_script is the hex encoded PK script of the staking output
string staking_output_pk_script = 2 [(amino.dont_omitempty) = true];
// staking_output_index is the index of the staking output in the staking tx
string staking_output_index = 3 [(amino.dont_omitempty) = true];
// version of the params used to validate the delegation
string params_version = 2 [(amino.dont_omitempty) = true];
string params_version = 4 [(amino.dont_omitempty) = true];
// finality_provider_btc_pks_hex is the list of hex str of Bitcoin secp256k1 PK of
// the finality providers that this BTC delegation delegates to
// the PK follows encoding in BIP-340 spec
repeated string finality_provider_btc_pks_hex = 3 [(amino.dont_omitempty) = true];
repeated string finality_provider_btc_pks_hex = 5 [(amino.dont_omitempty) = true];
// staker_btc_pk_hex is the hex str of Bitcoin secp256k1 PK of the staker that
// creates this BTC delegation the PK follows encoding in BIP-340 spec
string staker_btc_pk_hex = 4 [(amino.dont_omitempty) = true];
string staker_btc_pk_hex = 6 [(amino.dont_omitempty) = true];
// staking_time is the timelock of the staking tx specified in the BTC script
string staking_time = 5 [(amino.dont_omitempty) = true];
string staking_time = 7 [(amino.dont_omitempty) = true];
// staking_amount is the total amount of BTC stake in this delegation
// quantified in satoshi
string staking_amount = 6 [(amino.dont_omitempty) = true];
string staking_amount = 8 [(amino.dont_omitempty) = true];
// unbonding_time is the time is timelock on unbonding tx chosen by the staker
string unbonding_time = 7 [(amino.dont_omitempty) = true];
string unbonding_time = 9 [(amino.dont_omitempty) = true];
// unbonding_tx is hex encoded bytes of the unsigned unbonding tx
string unbonding_tx = 8 [(amino.dont_omitempty) = true];
string unbonding_tx = 10 [(amino.dont_omitempty) = true];
// new_state of the BTC delegation
string new_state = 9 [(amino.dont_omitempty) = true];
string new_state = 11 [(amino.dont_omitempty) = true];
}

// EventCovenantSignatureReceived is the event emitted when a covenant committee
Expand Down
10 changes: 10 additions & 0 deletions x/btcstaking/types/btc_delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ func (d *BTCDelegation) MustGetStakingTxHash() chainhash.Hash {
return txHash
}

func (d *BTCDelegation) MustGetStakingTx() *wire.MsgTx {
stakingTx, err := bbn.NewBTCTxFromBytes(d.StakingTx)

if err != nil {
panic(err)
}

return stakingTx
}

func (d *BTCDelegation) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(d.StakerAddr); err != nil {
return fmt.Errorf("invalid staker address: %s - %w", d.StakerAddr, err)
Expand Down
2 changes: 2 additions & 0 deletions x/btcstaking/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func NewBtcDelCreationEvent(
) *EventBTCDelegationCreated {
return &EventBTCDelegationCreated{
StakingTxHash: stakingTxHash,
StakingOutputPkScript: hex.EncodeToString(btcDel.MustGetStakingTx().TxOut[btcDel.StakingOutputIdx].PkScript),
StakingOutputIndex: strconv.FormatUint(uint64(btcDel.StakingOutputIdx), 10),
ParamsVersion: strconv.FormatUint(uint64(btcDel.ParamsVersion), 10),
FinalityProviderBtcPksHex: btcDel.FinalityProviderKeys(),
StakerBtcPkHex: btcDel.BtcPk.MarshalHex(),
Expand Down
Loading

0 comments on commit c7eddc9

Please sign in to comment.