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 stacking locks #57

Merged
merged 47 commits into from
Jun 21, 2023
Merged

External stacking locks #57

merged 47 commits into from
Jun 21, 2023

Conversation

maurolacy
Copy link
Collaborator

@maurolacy maurolacy commented Jun 15, 2023

Alternative to #54, but using Lockable for synchronisation.

Proves that Lockable is a useful abstraction around this.

TODO:

  • Send tx id in msg.
  • User info locking.
  • Commit / rollback msgs.
  • Adapt existing tests.
  • Write tx-specific tests
    • commit_tx.
    • rollback_tx.
    • In flight / collision.

@maurolacy maurolacy changed the base branch from main to add-lock-sync-primitives June 15, 2023 10:28
Base automatically changed from add-lock-sync-primitives to main June 15, 2023 10:34
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 like a good start. Add some detailed comments, but it is really minor stuff.

Updating the external-staking (and mock-external-staking) contracts is an important step for tests. The real one should just send back a message in the same tx to commit_tx. When there is IBC, we can change it, but at least you upgrade the vault <-> external staking communication to be "IBC safe"

contracts/provider/external-staking/src/multitest.rs Outdated Show resolved Hide resolved
contracts/provider/external-staking/src/contract.rs Outdated Show resolved Hide resolved
contracts/provider/vault/src/contract.rs Show resolved Hide resolved
contracts/provider/vault/src/contract.rs Outdated Show resolved Hide resolved
contracts/provider/vault/src/contract.rs Outdated Show resolved Hide resolved
contracts/provider/vault/src/contract.rs Show resolved Hide resolved
contracts/provider/vault/src/contract.rs Outdated Show resolved Hide resolved
)?;

// Rollback user's max_lien
let mut user = self.users.load(ctx.deps.storage, &tx.user)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, this is kind of why I wouldn't apply it in the beginning, just lock and only apply on the success case.

Calculating maximum is harder when reducing (are there others higher?) vs raising (compare my new value with the max). This is an argument in favor of approach 2 above

contracts/provider/vault/src/contract.rs Outdated Show resolved Hide resolved
packages/mocks/src/cross_staking.rs Show resolved Hide resolved
@ethanfrey ethanfrey mentioned this pull request Jun 15, 2023
@maurolacy maurolacy force-pushed the external-stacking-locks branch 3 times, most recently from 8c5f3f3 to 4a251b6 Compare June 16, 2023 11:47
@maurolacy maurolacy marked this pull request as ready for review June 16, 2023 12:01
@maurolacy maurolacy mentioned this pull request Jun 20, 2023
7 tasks
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.

General design looks good.
Added a number of smaller style comments for cleanup.
It would be good to see integration into external-staking, but even more, we need to start IBC and figure out how to test well.

contracts/provider/external-staking/src/multitest.rs Outdated Show resolved Hide resolved
contracts/provider/vault/src/txs.rs Outdated Show resolved Hide resolved
@@ -71,4 +81,24 @@ impl VaultApiHelper {
};
Ok(wasm)
}

pub fn commit_tx(&self, tx_id: u64) -> Result<WasmMsg, StdError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good to add here, but question - isn't such a helper class now auto-generated?
Maybe a worthwhile PR to remove these and replace with mt autogen types (please do independent from this PR)

}
}

pub fn next_tx_id(&self, store: &mut dyn Storage) -> StdResult<u64> {
let id: u64 = self.tx_count.may_load(store)?.unwrap_or_default() + 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note: this may be the best use of update. You can use it as a return result directly.
(But it may require initializing the count to 0 in instantiate)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copied this from somewhere else. Will refactor if possible.

contracts/provider/vault/src/contract.rs Show resolved Hide resolved
contracts/provider/vault/src/contract.rs Outdated Show resolved Hide resolved
contracts/provider/vault/src/contract.rs Outdated Show resolved Hide resolved
contracts/provider/vault/src/contract.rs Outdated Show resolved Hide resolved
contracts/provider/vault/src/contract.rs Show resolved Hide resolved
@maurolacy maurolacy merged commit c5b4d9f into main Jun 21, 2023
@maurolacy maurolacy deleted the external-stacking-locks branch June 22, 2023 10:55
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