Skip to content

Conversation

@ethanfrey
Copy link
Contributor

@ethanfrey ethanfrey commented Apr 23, 2020

Replaces #211

Closes #174

I think everything is now implemented except for the test cases. Happy for a review and feedback,

  • Add new types
  • Update CHANGELOG
  • Generate proper schemas
  • Add mock Querier support
  • Test MockQuerier, especially StakingQuerier

For another PR:

  • Demo usage in a contract

Note: I like the feature flag approach, as it allows us to downgrade and support non-PoS chains easily (eg. if someone wants to run cosmwasm in a PoA environment or other novel consensus mechanism.). However, I realize that the schemas generated for cosmwasm_std are now incomplete.... We can either generate them with or without staking info.

My idea (which I tentatively did in a15b22b) is to make staking on by default and use --no-default-features to disable it, as it will be the case in almost all cosmwasm chains in the near future. And the other chains can just ignore some entries in the schema (rather than having missing specs). Open for more ideas.

@ethanfrey ethanfrey requested a review from webmaster128 April 23, 2020 09:12
@ethanfrey ethanfrey force-pushed the new-staking-messages branch from 6fef990 to a15b22b Compare April 23, 2020 09:16
Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

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

Looks good as far as I can see. I just have mixed feelings about the introduction of all those feature flags. The iterator alone is annoyance, and we're working towards many more.

command: cargo wasm --locked --features iterator
- run:
name: Run unit tests (with iterator support)
name: Run unit tests (with iterator and staking support)
Copy link
Member

Choose a reason for hiding this comment

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

So you want to test minimal and full feature set (and skip default)? Would be good to describe that in the steps somehow. Also there is --all-features available. I don't have a brilliant idea how to origanize all of this, but is getting complex now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, these features are independent, so I was thinking all or nothing. Sometimes the code doesn't work with the cfg feature blocks missing. (I had that happen a few times).

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 like the --all-features flag and used it here: b7b1ac7

@ethanfrey
Copy link
Contributor Author

I agree with limiting feature flags. I would be careful to add more, but I also think if we get some dynamic check from #301 that maybe we can remove the compiler feature for staking and add that as a runtime argument controlling upload of contracts. I agree this is suboptimal, and we definitely don't want to add 10 more.

@ethanfrey ethanfrey force-pushed the new-staking-messages branch from b4ab089 to 4c9aaef Compare April 23, 2020 15:50
@ethanfrey
Copy link
Contributor Author

@webmaster128 This should be complete now. Let me know what you think.

The actual types we used have been discussed with @yys in #211, so the question is mainly on the organization (and feature flags). As I said above, I would love to remove the feature flag when #301 is in and we have another way to check for optional features.

@ethanfrey ethanfrey mentioned this pull request Apr 23, 2020
7 tasks
Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

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

Looks good

// delegator is automatically set to address of the calling contract
validator: HumanAddr,
// this is the "withdraw address", the one that should receive the rewards
// if None, then use delegator address
Copy link
Member

Choose a reason for hiding this comment

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

Can we make such field-specific comments doc comments (///) to allows IDEs and JSON schema to utilize them? Note that when rendered there is no resulting line break as long as it is the same paragraph, so a trailing . would be good.

Of course, this is not for // delegator is automatically set to address of the calling contract, which is not a field description.

pub fn new(balances: &[(&HumanAddr, &[Coin])]) -> Self {
MockQuerier {
bank: BankQuerier::new(balances),
staking: staking::StakingQuerier::new(&[], &[]),
Copy link
Member

Choose a reason for hiding this comment

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

This could probably be staking::StakingQuerier::default()

#[cfg(feature = "staking")]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
/// DelegationsResponse is data format returned from StakingRequest::Delegations query
Copy link
Member

Choose a reason for hiding this comment

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

Side note: Rust will most likely converge towards doc comments first. The reasoning is to better support long doc comments, that otherwise move other attributes out of the screen. This is specified but not yet implemented in rustfmt: rust-lang/rustfmt#3303

No issue here as tooling will sort them for us one day and we don't typically have long doc comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice note, I have no opinion, put them close to the struct to make sure they bind, but the other way (doc comments first) does look cleaner.

@ethanfrey
Copy link
Contributor Author

Thanks for the tips, I will keep the rustdoc more in mind. I really need to set up (and review) the public rustdoc for this package. Would make a nice last-minute pre-0.8 polish.

@webmaster128
Copy link
Member

I will keep the rustdoc more in mind. I really need to set up (and review) the public rustdoc for this package. Would make a nice last-minute pre-0.8 polish.

Any idea if it is possible to publish pre-releases to crates.io? I did not find a possibility without overriding the "latest" version.

@ethanfrey
Copy link
Contributor Author

Any idea if it is possible to publish pre-releases to crates.io? I did not find a possibility without overriding the "latest" version.

AFAIK the latest version is always taken, so not really a "pre-release". I guess we could call it 0.8.0-alpha or 0.8.0-rc1 if that is what you mean?

We can also check rustdoc locally and make sure the 0.7.2 is published, to prepare for the update, if that is why you are asking.

@webmaster128
Copy link
Member

Publishing a pre-release like 0.8.0-rc1 would be easy. However, we don't want people that do cargo add cosmwasm-std to use that version. But then again, this command does not exist in Rust world and users need to manually add entries to their Cargo.toml, so maybe it does not hurt to publish pre-releases.

@ethanfrey ethanfrey merged commit edca8be into master Apr 24, 2020
@ethanfrey ethanfrey deleted the new-staking-messages branch April 24, 2020 09:43
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.

Add staking messages to CosmosMsg

3 participants