Skip to content

Commit

Permalink
Add staking tx to the creation event (#273) (#274)
Browse files Browse the repository at this point in the history
- Add staking tx to the event
- Removes from the event data than can be retrieved from staking tx:
  - staking tx hash
  - staking output pk script
  - staking output amount
  • Loading branch information
KonradStaniec authored Nov 18, 2024
1 parent e0ba5bc commit cb04c01
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 242 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### API Breaking

- [#273](https://github.com/babylonlabs-io/babylon/pull/273) Add full staking tx to BTC delegation creation event

## v0.16.0

### Improvements
Expand Down
26 changes: 10 additions & 16 deletions proto/babylon/btcstaking/v1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -144,33 +144,27 @@ enum FinalityProviderStatus {
// EventBTCDelegationCreated is the event emitted when a BTC delegation is created
// on the Babylon chain
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_tx_hex is the hex encoded staking tx
string staking_tx_hex = 1 [(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];
string staking_output_index = 2 [(amino.dont_omitempty) = true];
// version of the params used to validate the delegation
string params_version = 4 [(amino.dont_omitempty) = true];
string params_version = 3 [(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 = 5 [(amino.dont_omitempty) = true];
repeated string finality_provider_btc_pks_hex = 4 [(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 = 6 [(amino.dont_omitempty) = true];
string staker_btc_pk_hex = 5 [(amino.dont_omitempty) = true];
// staking_time is the timelock of the staking tx specified in the BTC script
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 = 8 [(amino.dont_omitempty) = true];
string staking_time = 6 [(amino.dont_omitempty) = true];
// unbonding_time is the time is timelock on unbonding tx chosen by the staker
string unbonding_time = 9 [(amino.dont_omitempty) = true];
string unbonding_time = 7 [(amino.dont_omitempty) = true];
// unbonding_tx is hex encoded bytes of the unsigned unbonding tx
string unbonding_tx = 10 [(amino.dont_omitempty) = true];
string unbonding_tx = 8 [(amino.dont_omitempty) = true];
// new_state of the BTC delegation
string new_state = 11 [(amino.dont_omitempty) = true];
string new_state = 9 [(amino.dont_omitempty) = true];
}

// EventCovenantSignatureReceived is the event emitted when a covenant committee
Expand Down
1 change: 0 additions & 1 deletion x/btcstaking/keeper/btc_delegations.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (k Keeper) AddBTCDelegation(
k.setBTCDelegation(ctx, btcDel)

if err := ctx.EventManager().EmitTypedEvents(types.NewBtcDelCreationEvent(
stakingTxHash.String(),
btcDel,
)); err != nil {
panic(fmt.Errorf("failed to emit events for the new pending BTC delegation: %w", err))
Expand Down
5 changes: 1 addition & 4 deletions x/btcstaking/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,15 @@ func NewInclusionProofEvent(
}

func NewBtcDelCreationEvent(
stakingTxHash string,
btcDel *BTCDelegation,
) *EventBTCDelegationCreated {
return &EventBTCDelegationCreated{
StakingTxHash: stakingTxHash,
StakingOutputPkScript: hex.EncodeToString(btcDel.MustGetStakingTx().TxOut[btcDel.StakingOutputIdx].PkScript),
StakingTxHex: hex.EncodeToString(btcDel.StakingTx),
StakingOutputIndex: strconv.FormatUint(uint64(btcDel.StakingOutputIdx), 10),
ParamsVersion: strconv.FormatUint(uint64(btcDel.ParamsVersion), 10),
FinalityProviderBtcPksHex: btcDel.FinalityProviderKeys(),
StakerBtcPkHex: btcDel.BtcPk.MarshalHex(),
StakingTime: strconv.FormatUint(uint64(btcDel.StakingTime), 10),
StakingAmount: strconv.FormatUint(btcDel.TotalSat, 10),
UnbondingTime: strconv.FormatUint(uint64(btcDel.UnbondingTime), 10),
UnbondingTx: hex.EncodeToString(btcDel.BtcUndelegation.UnbondingTx),
NewState: BTCDelegationStatus_PENDING.String(),
Expand Down
Loading

0 comments on commit cb04c01

Please sign in to comment.