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

Support slashing & simply data structure for phase 2 #37

Merged
merged 6 commits into from
Oct 30, 2024

Conversation

jrwbabylonlab
Copy link
Collaborator

@jrwbabylonlab jrwbabylonlab commented Oct 23, 2024

What’s changed in this PR:

  • Added two new methods to support slashing functionality.
  • Removed the Delegation interface from the code. This decision was made after implementing the EOI transaction in simple-staking. The original design of the Delegation object and the Staking/Observable classes were well-suited for phase-1 delegation, where transactions were created one by one (i.e., stakingTx -> Unbonding -> Withdrawal). However, in phase-2, we create multiple transactions within a single operation (EOI), and there is no delegation present at the time of EOI creation. Therefore, moving common fields into the class constructor has proven to be a more efficient approach, allowing us to generate multiple types of transactions with fewer input fields being passed around.

src/utils/btc.ts Outdated Show resolved Hide resolved
@jrwbabylonlab jrwbabylonlab requested review from gbarkhatov and removed request for vitsalis, totraev, KonradStaniec and gbarkhatov October 24, 2024 07:15
@jrwbabylonlab jrwbabylonlab changed the title Support slashing in phase 2 [WIP] Support slashing in phase 2 Oct 24, 2024
@jrwbabylonlab jrwbabylonlab changed the title [WIP] Support slashing in phase 2 Support slashing & simply data structure for phase 2 Oct 24, 2024
Copy link

@KonradStaniec KonradStaniec left a comment

Choose a reason for hiding this comment

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

Few minor comments nothing blocking.

Though I would strongly consider naming adjustments in slashing transactions building functions.

src/staking/index.ts Outdated Show resolved Hide resolved
src/staking/index.ts Show resolved Hide resolved
src/staking/index.ts Outdated Show resolved Hide resolved
} = delegation;
public createUnbondingTransaction(
stakingTx: Transaction,
stakingOutputIndex: number,
Copy link
Collaborator Author

@jrwbabylonlab jrwbabylonlab Oct 25, 2024

Choose a reason for hiding this comment

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

@KonradStaniec @gitferry do we actually need this outputIndex?

It seems that i could rebuild the stakingOutput by doing below

// Build outputs
const scriptTree: Taptree = [
  {
    output: scripts.slashingScript,
  },
  [{ output: scripts.unbondingScript }, { output: scripts.timelockScript }],
];

// Create an pay-2-taproot (p2tr) output using the staking script
const stakingOutput = payments.p2tr({
  internalPubkey,
  scriptTree,
  network,
});

then grab the stakingOutput.address and check each of the stakingTx output, see if it matches?

Choose a reason for hiding this comment

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

in theory you could do that, thought isn't it simpler to use stakingOutputIndex if you already have it ? I think we already store it in Babylon node database and return it in queries to avoid such re-creation.

Copy link
Collaborator Author

@jrwbabylonlab jrwbabylonlab Oct 25, 2024

Choose a reason for hiding this comment

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

@KonradStaniec
In phase-1, yes, but No in phase-2 as i don't have it at the time of EOI creation.

Copy link
Member

@vitsalis vitsalis left a comment

Choose a reason for hiding this comment

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

lgtm, nice work! Did not check the tests due to bandwidth constraints, let me know if there's something specific there you would like me to take a look at.

src/staking/index.ts Outdated Show resolved Hide resolved
stakerPkNoCoordHex
} = delegation;
public createUnbondingTransaction(
stakingTx: Transaction,
Copy link
Member

Choose a reason for hiding this comment

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

Note for a future development. It would be interesting to see this class be able to identify the staking transaction by itself for unbonding/withdrawal transactions in order to avoid having the transactions passed as parameters and risking having a transaction that does not correspond to the params passed in the constructor.

i.e. the class always has access to all the information to build all transactions by default, and each instance of this class corresponds to all the staking paths starting from a unique staking transaction.

src/staking/index.ts Show resolved Hide resolved
src/staking/index.ts Outdated Show resolved Hide resolved
src/staking/index.ts Outdated Show resolved Hide resolved
public createStakingOutputSlashingTransaction(
stakingTx: Transaction,
) : PsbtTransactionResult {
if (!this.params.slashing) {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have the option to avoid setting the slashing parameters?

Copy link
Collaborator Author

@jrwbabylonlab jrwbabylonlab Oct 30, 2024

Choose a reason for hiding this comment

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

Backwards compatibility with Observable, there is no slashing params in phase-1

src/staking/index.ts Outdated Show resolved Hide resolved
@jrwbabylonlab jrwbabylonlab merged commit 48a0237 into dev Oct 30, 2024
1 check passed
@jrwbabylonlab jrwbabylonlab deleted the support-slashing-in-phase-2 branch October 30, 2024 01:37
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.

4 participants