Skip to content

Commit

Permalink
remove additional data from the state
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradStaniec committed Oct 22, 2024
1 parent f83f1e2 commit 74db17e
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 455 deletions.
5 changes: 0 additions & 5 deletions proto/babylon/btcstaking/v1/btcstaking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ message DelegatorUnbondingInfo {
// filled only if spend_stake_tx is different than unbonding_tx registered
// on the Babylon chain.
bytes spend_stake_tx = 1;
// spend_stake_tx_inclusion_block_hash is the block hash of the block in which
// spend_stake_tx was included
bytes spend_stake_tx_inclusion_block_hash = 2;
// spend_stake_tx_inclusion_index is the index of spend_stake_tx in the block
uint32 spend_stake_tx_inclusion_index = 3;
}

// BTCUndelegation contains the information about the early unbonding path of the BTC delegation
Expand Down
8 changes: 2 additions & 6 deletions proto/babylon/btcstaking/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,9 @@ message BTCDelegationResponse {
// DelegatorUnbondingInfoResponse provides all necessary info about transaction
// which spent the staking output
message DelegatorUnbondingInfoResponse {
// spend_stake_tx_hex is the transaction which spent the staking output
// spend_stake_tx_hex is the transaction which spent the staking output. It is
// filled only if the spend_stake_tx_hex is different than the unbonding_tx_hex
string spend_stake_tx_hex = 1;
// spend_stake_tx_inclusion_block_hash_hex is the block hash of the block in which
// spend_stake_tx was included
string spend_stake_tx_inclusion_block_hash_hex = 2;
// spend_stake_tx_inclusion_index is the index of spend_stake_tx in the block
uint32 spend_stake_tx_inclusion_index = 3;
}

// BTCUndelegationResponse provides all necessary info about the undeleagation
Expand Down
10 changes: 1 addition & 9 deletions test/e2e/btc_staking_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,16 +869,8 @@ func ParseRespBTCDelToBTCDel(resp *bstypes.BTCDelegationResponse) (btcDel *bstyp
}
}

unbondingHeader, err := bbn.NewBTCHeaderHashBytesFromHex(ud.DelegatorUnbondingInfoResponse.SpendStakeTxInclusionBlockHashHex)

if err != nil {
return nil, err
}

btcDel.BtcUndelegation.DelegatorUnbondingInfo = &bstypes.DelegatorUnbondingInfo{
SpendStakeTx: spendStakeTx,
SpendStakeTxInclusionBlockHash: unbondingHeader,
SpendStakeTxInclusionIndex: ud.DelegatorUnbondingInfoResponse.SpendStakeTxInclusionIndex,
SpendStakeTx: spendStakeTx,
}
}
}
Expand Down
28 changes: 0 additions & 28 deletions x/btcstaking/keeper/btc_delegations.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,34 +161,6 @@ func (k Keeper) btcUndelegate(
btcDel.BtcUndelegation.DelegatorUnbondingInfo = u
k.setBTCDelegation(ctx, btcDel)

// stake is unbonding through unexpected tx, emit additional event
if len(u.SpendStakeTx) > 0 {
tx, err := bbn.NewBTCTxFromBytes(u.SpendStakeTx)

if err != nil {
panic(fmt.Errorf("failed to parse spend stake tx that should be valid: %w", err))
}

spendStakeTxHash := tx.TxHash().String()

headerHash, err := chainhash.NewHash(u.SpendStakeTxInclusionBlockHash)

if err != nil {
panic(fmt.Errorf("failed to parse header hash that should be valid: %w", err))
}

ev := &types.EventUnexpectedUnbondingTx{
StakingTxHash: btcDel.MustGetStakingTxHash().String(),
SpendStakeTxHash: spendStakeTxHash,
SpendStakeTxHeaderHash: headerHash.String(),
SpendStakeTxBlockIndex: u.SpendStakeTxInclusionIndex,
}

if err := ctx.EventManager().EmitTypedEvent(ev); err != nil {
panic(fmt.Errorf("failed to emit EventUnexpectedUnbondingTx event: %w", err))
}
}

if !btcDel.HasInclusionProof() {
return
}
Expand Down
19 changes: 13 additions & 6 deletions x/btcstaking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,7 @@ func (ms msgServer) BTCUndelegate(goCtx context.Context, req *types.MsgBTCUndele
delegatorUnbondingInfo = &types.DelegatorUnbondingInfo{
// if the stake spending tx is the same as the registered unbonding tx,
// we do not need to save it in the database
SpendStakeTx: []byte{},
SpendStakeTxInclusionBlockHash: req.StakeSpendingTxInclusionProof.Key.Hash.MustMarshal(),
SpendStakeTxInclusionIndex: req.StakeSpendingTxInclusionProof.Key.Index,
SpendStakeTx: []byte{},
}
} else {
// stakeSpendingTx is not unbonding tx, first we need to verify whether it
Expand All @@ -598,9 +596,18 @@ func (ms msgServer) BTCUndelegate(goCtx context.Context, req *types.MsgBTCUndele
}

delegatorUnbondingInfo = &types.DelegatorUnbondingInfo{
SpendStakeTx: req.StakeSpendingTx,
SpendStakeTxInclusionBlockHash: req.StakeSpendingTxInclusionProof.Key.Hash.MustMarshal(),
SpendStakeTxInclusionIndex: req.StakeSpendingTxInclusionProof.Key.Index,
SpendStakeTx: req.StakeSpendingTx,
}

ev := &types.EventUnexpectedUnbondingTx{
StakingTxHash: btcDel.MustGetStakingTxHash().String(),
SpendStakeTxHash: spendStakeTxHash.String(),
SpendStakeTxHeaderHash: req.StakeSpendingTxInclusionProof.Key.Hash.MarshalHex(),
SpendStakeTxBlockIndex: req.StakeSpendingTxInclusionProof.Key.Index,
}

if err := ctx.EventManager().EmitTypedEvent(ev); err != nil {
panic(fmt.Errorf("failed to emit EventUnexpectedUnbondingTx event: %w", err))
}
}

Expand Down
Loading

0 comments on commit 74db17e

Please sign in to comment.