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

External staking locks 2 #60

Merged
merged 27 commits into from
Jun 23, 2023
Merged

External staking locks 2 #60

merged 27 commits into from
Jun 23, 2023

Conversation

maurolacy
Copy link
Collaborator

@maurolacy maurolacy commented Jun 20, 2023

#57 follow-up. Implementation of staking locks for the external-staking contract.

TODO:

  • Staking commit / rollback.
  • Unstake commit / rollback.
  • Adjust tests.
  • Send IBC packets
  • Route IBC ack/timeout to commit / rollback methods.
  • Write tx-specific tests.
  • Use a proper testing mechanism for commit / rollback (IBC messages).

@maurolacy maurolacy requested a review from ethanfrey June 20, 2023 06:29
@maurolacy maurolacy changed the base branch from main to external-stacking-locks June 20, 2023 06:30
@maurolacy maurolacy requested a review from hashedone June 20, 2023 07:24
@maurolacy maurolacy self-assigned this Jun 20, 2023
@maurolacy maurolacy force-pushed the external-staking-locks-2 branch 3 times, most recently from 132606f to 639873f Compare June 22, 2023 10:53
@maurolacy maurolacy changed the base branch from external-stacking-locks to main June 22, 2023 10:53
Copy link
Collaborator

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Looks quite good.

A few missing TODOs I commented on, and some minor code nits.

Main point is removing lock on distribution.
And then exposing these commit/rollback methods as SudoMsg for testing.

If you can fix this up, I can work on the corresponding side for converter (and write the external-staking ack handlers as well if you want... just pull out the logic for an easy call)

contracts/provider/external-staking/src/msg.rs Outdated Show resolved Hide resolved
contracts/provider/external-staking/src/multitest.rs Outdated Show resolved Hide resolved
@@ -451,6 +451,8 @@ fn get_last_pending_tx_id(vault: &VaultContractProxy) -> Option<u64> {
let txs = vault.all_pending_txs_desc(None, None).unwrap().txs;
txs.first().map(|tx| match tx {
Tx::InFlightStaking { id, .. } => *id,
Tx::InFlightRemoteStaking { id, .. } => *id,
Tx::InFlightRemoteUnstaking { id, .. } => *id,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit. I think it is easier to not include the other enum now.
And only add it when you want to implement it, so the compiler shows you all the places that need the updates

(easier than searching for unimplemented!())

/// Remote validator
validator: String,
},
// IBC flight
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better rustdoc here and above?

} => {
write!(
f,
"InFlightRemoteStaking {{ id: {}, amount: {}, user: {}, validator: {} }}",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is basically the Debug format, right?
I would assume Display to do something more custom. Or just delegate to Debug.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, simplifying this to InFlightRemoteStaking {{ id: {}}} makes sense.

contracts/provider/external-staking/src/contract.rs Outdated Show resolved Hide resolved
contracts/provider/external-staking/src/contract.rs Outdated Show resolved Hide resolved
contracts/provider/external-staking/src/contract.rs Outdated Show resolved Hide resolved
contracts/provider/external-staking/src/contract.rs Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

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

Some comments on your recent changes.

contracts/provider/external-staking/src/contract.rs Outdated Show resolved Hide resolved
contracts/provider/external-staking/src/contract.rs Outdated Show resolved Hide resolved
contracts/provider/external-staking/src/contract.rs Outdated Show resolved Hide resolved
}

// put this later so compiler doens't complain about mut in test mode
resp = resp.add_attribute("owner", ctx.info.sender);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nit: Move all the add_attribute calls here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I refer to amount.amount which is used in the conditionally compiled block, so moving would force an unnecessary clone.

Kinda annoying to make clippy happy on both branches (test / not(test))

Happy for your cleanup on this later

/// Must be called by the IBC callback handler on failed remote staking.
#[msg(exec)]
fn test_rollback_stake(&self, ctx: ExecCtx, tx_id: u64) -> Result<Response, ContractError> {
#[cfg(test)]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The pattern in converter, in which you call an internal method here for tests and do nothing otherwise is better / clearer. I'll think you'll refactor to that, when connecting with the IBC handlers.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yup, I just refactored to that, working on one step at a time to keep tests passing.

contracts/provider/external-staking/src/contract.rs Outdated Show resolved Hide resolved
@ethanfrey ethanfrey marked this pull request as ready for review June 23, 2023 09:41
@ethanfrey ethanfrey merged commit 158d25e into main Jun 23, 2023
@ethanfrey ethanfrey deleted the external-staking-locks-2 branch June 23, 2023 09:49
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.

2 participants