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: Implement ADR-29 - generalized unbonding #215

Merged
merged 7 commits into from
Oct 22, 2024

Conversation

KonradStaniec
Copy link
Collaborator

@KonradStaniec KonradStaniec commented Oct 21, 2024

Highlights:

  • Now MsgBTCUndelegate contains stake spending transaction as well as inclusion proof
  • BTCDelegation contains news field DelegatorUnbondingInfo instead of old staker signature field
  • new field DelegatorUnbondingInfo contains information about in which header unbonding happened. Also, if StakeSpendingTx in the message was different that registered UnbondingTx, DelegatorUnbondingInfo contains whole stake spending tx.
  • New event is emitted if unbonding happens through different transaction the the pre-registered one.

@KonradStaniec KonradStaniec added api breaking breaks grpc api in non-compatible way consensus breaking change modifies `appHash` of the application labels Oct 21, 2024
@KonradStaniec KonradStaniec marked this pull request as ready for review October 21, 2024 08:21
@KonradStaniec KonradStaniec requested a review from a team as a code owner October 21, 2024 08:21
@KonradStaniec KonradStaniec requested review from Lazar955, samricotta, gitferry and SebastianElvis and removed request for a team October 21, 2024 08:21
@KonradStaniec
Copy link
Collaborator Author

added more reviewers than normal as this is pretty substantial change to the protocol

Copy link
Member

@Lazar955 Lazar955 left a comment

Choose a reason for hiding this comment

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

Great job! lgtm

Comment on lines 123 to 127
// 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;
Copy link
Member

@SebastianElvis SebastianElvis Oct 21, 2024

Choose a reason for hiding this comment

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

Do we need to keep L123-127 in the KV store? It seems not as they are only be used upon verification but nothing else

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tbh my main use for those fields was to make it possible to easily check this transaction on Bitcoin node i.e when you have blockhash and transaction index you can retrieve tx from BTC node even if it does not have --txindex flag.

So later it is easier to check unbondings (normal or not) against BTC network , and the cost is only additional 40bytes of data. Do you think it is useful or overkill from node perspective ?

Copy link
Member

Choose a reason for hiding this comment

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

It's a bit overkill imo -- since we have millions of BTC delegations these extra fields might still incur some cost in the states. Also since we know the tx hash, we can find relevant block that contains this tx using Bitcoind APIs. Wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a bit overkill imo -- since we have millions of BTC delegations these extra fields might still incur some cost in the states

For 5m delegation it will be around 50MB of data which seems negligible, but I understand your point: 50MB here, 50MB there and it adds up.

In 74db17e:

  • I have removed it from the state
  • though I left it in the event, as this is not part of the state and this piece of data maybe important for somebody

Comment on lines +118 to +123
message DelegatorUnbondingInfo {
// spend_stake_tx is the transaction which spent the staking output. It is
// filled only if spend_stake_tx is different than unbonding_tx registered
// on the Babylon chain.
bytes spend_stake_tx = 1;
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this struct given that it only contains 1 field?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yup, this signals whether unbonding actually happened i.e

if del.BtcUndelegation.DelegatorUnbondingInfo != nil

delegation is considered unbonded.

And if

len(del.BtcUndelegation.DelegatorUnbondingInfo.SpendStakeTx) > 0 

then unbonding happened through unexpected unbonding transaction i.e the transaction different that del.BtcUndelegation.UnbondingTx

Assuming most of unbondings will happen through unbonding transaction committed to Babylon, this modelling enables us to save space i.e we do not store stake spending transaction if it happens to be already known unbonding transaction.

Copy link
Member

Choose a reason for hiding this comment

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

OK sounds good. Probably we can wrap some functions for BTCDelegation to signal these in the future 👍

@KonradStaniec KonradStaniec merged commit 6a0ccac into main Oct 22, 2024
20 checks passed
@KonradStaniec KonradStaniec deleted the konradstaniec/ubonding-adr-29 branch October 22, 2024 09:09
Comment on lines +115 to +117
// - spend_stake_tx_inclusion_block_hash: the block hash of the block in which
// spend_stake_tx was included
// - spend_stake_tx_sig_inclusion_index: the index of spend_stake_tx in the block
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: remove outdated documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api breaking breaks grpc api in non-compatible way consensus breaking change modifies `appHash` of the application
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants