Skip to content

Conversation

@azarovh
Copy link
Contributor

@azarovh azarovh commented May 16, 2023

This PR introduces 3 new TxOutput types: CreateDelegationId, DelegateStaking and SpendShareFromDelegation.

Here I followed the same design approach as with create/decommission pool but I think we should reconsider it: #893

Some implementation details to pay attention to:

  • SpendShareFromDelegation doesn't perform any accounting operation as actual balance decrease is done when spending DelegateStaking utxo
  • SpendShareFromDelegation is timelocked by the value from the chain config
  • DelegateStacking output can only be spent with the key provided by CreateDelegationId::spend_destination
  • DelegateStacking can be spent partially by producing another DelegateStacking for a change
  • Operations of creating delegation and adding balance to it can't be done in a single tx
  • There is a TODO to fix mismatched delegation id in input/output (but I think it should be fixed with Reconsider TxOutput types for decommissioning and spending delegation shares #893)
  • If a pool has been decommissioned and the delegation balance is 0 then delegation id is removed

Closes #873

Copy link
Contributor

@iljakuklic iljakuklic left a comment

Choose a reason for hiding this comment

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

Looking forward for the simplifying follow up. Some initial comments below.

Comment on lines +19 to 21
use crypto::random::{CryptoRng, Rng, RngCore};
use rstest::rstest;
use test_utils::random::{make_seedable_rng, Seed};
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to this PR: It may make sense for test_utils::random to reexport stuff from crypto::random since these are so frequently used together. Also possibly test_utils could reexport rstest to serve as a thin abstraction layer over it. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't mind reexporting crypto::random through test_utils::random.

Ok(())
}

// single DelegateStaking input; zero or one DelegateStakingOutput + any number of SpendShareFromDelegation
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we allow zero? That basically burns the bridge, unless the balance there is zero.

Copy link
Contributor

Choose a reason for hiding this comment

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

... balance is zero + pool is decommissioned.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this allows tx like DelegateStaking -> LockThenTransfer to completely spend the share without change

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if people attempt to burn the bridge. Meaning, they attempt to spend without the DelegateStaking output while they still have balance?

@TheQuantumPhysicist
Copy link
Contributor

Looking fine. Though I'd appreciate more documentation into this. Also, perhaps combining this with the upcoming changes will make this easier for the eyes. I don't know which should come first.

@azarovh
Copy link
Contributor Author

azarovh commented May 18, 2023

Also, perhaps combining this with the upcoming changes will make this easier for the eyes. I don't know which should come first.

I created a PR #902, you can take a look and if you like the approach in general I'll merge it and we can continue combined review here

@TheQuantumPhysicist
Copy link
Contributor

Also, perhaps combining this with the upcoming changes will make this easier for the eyes. I don't know which should come first.

I created a PR #902, you can take a look and if you like the approach in general I'll merge it and we can continue combined review here

Very well. I'll review that, then we merge it into this if it looks good. Cheers!

@azarovh azarovh marked this pull request as draft May 19, 2023 09:06
@azarovh azarovh force-pushed the feat/delegate_staking branch 2 times, most recently from 10a1bc0 to 8b49635 Compare May 22, 2023 10:12
@azarovh azarovh marked this pull request as ready for review May 22, 2023 10:26
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to put block reward limitations on ConsensusData::None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd say yes, but the maturity distance is 0

Copy link
Contributor

@TheQuantumPhysicist TheQuantumPhysicist left a comment

Choose a reason for hiding this comment

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

.

@azarovh azarovh force-pushed the feat/delegate_staking branch from 70d114c to 38aabce Compare May 24, 2023 12:29
@azarovh azarovh force-pushed the feat/delegate_staking branch from 38aabce to 8db32f0 Compare May 24, 2023 12:33
@TheQuantumPhysicist TheQuantumPhysicist merged commit fd369e8 into master May 24, 2023
@TheQuantumPhysicist TheQuantumPhysicist deleted the feat/delegate_staking branch May 24, 2023 18:22
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.

Clean up delegation ids from db

4 participants