-
Notifications
You must be signed in to change notification settings - Fork 1
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
tgrade-valset: Interface for distribution rewards by external contract #198
Conversation
1d9c411
to
84c2f62
Compare
52de51d
to
d0a2ef0
Compare
This comment has been minimized.
This comment has been minimized.
7c45ebb
to
4e8ef65
Compare
…ct on contract instantiation
… is also queryable as config part)
2b5446b
to
1f73104
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, this looks quite good and thorough.
The logic for handling the response (MsgInstantiateContract) would be good to pull out as a general utility helper and then see if we use protobuf, prost, or just hard-code a decoding (as there are 2 simple types and we may need that to avoid code bloat). (Created CosmWasm/cw-plus#480 and put it in the backlog)
Other than that, I just think there are a few events and a message that could be optional (only emitted when non-empty). Please ping when you fix those so I can approve and merge
syntax = "proto3"; | ||
|
||
// MsgInstantiateContractResponse defines the Msg/InstantiateContract response type. | ||
message MsgInstantiateContractResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to pull this out and add the autogen.
Honestly, I find prost easier to work with than the protobuf package.
We could merge like this, but it would be good to pull this into a common helpers package. Eventually optimising for minimum code-size, dependency bloat. I think I have this in another contract or two somewhere. And others ask for it. Something that could be added to cw-plus (as cw-proto
package?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it could be. It is just making maintenance easier (no risk of committing not regenerated message)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those proto types are a stable part of the 1.0 api. they will not change.
contracts/tgrade-valset/README.md
Outdated
|
||
```json | ||
{ | ||
"_contract_addr": "valset_addr" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comma
.map(|vi| ValidatorUpdate { | ||
pubkey: vi.validator_pubkey.clone(), | ||
power: vi.power, | ||
.map(|vi| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this with unzip to do 2 at once.
|
||
pub fn rewards_instantiate_reply(deps: DepsMut, msg: Reply) -> Result<Response, ContractError> { | ||
let id = msg.id; | ||
let res: MsgInstantiateContractResponse = Message::parse_from_bytes( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a good logic to pull out into a helper. In addition to the proto logic.
The only time we need to use this struct is handling SubMsg where we want to get info from another contract.
(Pulling into cw-plus can be a separate PR and shouldn't block this one)
|
||
// diff between empty and vals must be removals | ||
let diff = calculate_diff(empty, vals.clone()); | ||
assert_eq!(diff.diffs.len(), 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These updates look fine and fair to remove this length check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actual reason I did it is that they are only making failure messages worse. You got info test failed, but you don't have diff output, so it may be harder to reason about what happened (you would probably add prints and rerun test...). It would fail anyway line below ;)
pub fn withdraw_validation_reward(&mut self, executor: &str) -> AnyResult<AppResponse> { | ||
self.app.execute_contract( | ||
Addr::unchecked(executor), | ||
self.rewards_contract.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice one, letting the tests interact with the rewards contract, just like the main contract.
I was surprised how clean those tests were, but this is very nice abstraction for the suite.
let denom = self.token.clone(); | ||
let admin = Addr::unchecked(&self.admin); | ||
let recipient = self.valset.to_string(); | ||
self.app.init_modules(move |router, api, storage| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good use of the API.
Question: does it make sense to provide some easier approach for this?
I thought of (maybe did???) add a SudoMsg::Bank
to allow minting in some version of multi-test. Can you see if you can use that here? We should make this normal use case easy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I spend like couple hours to find this function (its name isn't helping here). I would actually just make the .custom_message
on app which sends sudo message directly, so it would just look like:
self.app.custom_message(TgradeMsg::MintTokens {
denom,
amount: amount.into(),
recipient,
}).unwrap();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one optimization missing (don't send update messages on no change). Otherwise, good to merge.
}) | ||
.collect(); | ||
.unzip(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
err: "Missing reply data".to_owned(), | ||
})? | ||
.as_slice(), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. Only question is, do we really need to use protobuf here, or this could be handled with serde and Deserialize
/ from_binary
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is protobuf coming from wasmd.
And yes, you do need to parse it.
We never need to create it (it happens when we dispatch a message and check data on reply).
We should document this better here CosmWasm/wasmd#623 and then add helpers here CosmWasm/cw-plus#480
(No rush on these... they are lower in the backlog but good to flag this as an issue)
Closes #138