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

Feature/use delegation rates #741

Merged
merged 3 commits into from
Aug 18, 2021
Merged

Feature/use delegation rates #741

merged 3 commits into from
Aug 18, 2021

Conversation

neacsu
Copy link
Contributor

@neacsu neacsu commented Aug 16, 2021

No description provided.

neacsu added 2 commits August 16, 2021 12:25
Calculate delegation rewards per epoch for mixnodes and gateways, which
are used when the delegators are rewarded for their stake.
Copy link
Contributor

@jstuczyn jstuczyn 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 to me, the only remaining thing would be writing some simple migration code to handle changes to State struct. For that you have two options:

a) via serde defaults
meaning you'd have to slap #[serde(default = "your_default_fn")] on State and StateParams, i.e.

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct StateParams {
    pub epoch_length: u32, // length of an epoch, expressed in hours

    pub minimum_mixnode_bond: Uint128, // minimum amount a mixnode must bond to get into the system
    pub minimum_gateway_bond: Uint128, // minimum amount a gateway must bond to get into the system
    pub mixnode_bond_reward_rate: Decimal, // annual reward rate, expressed as a decimal like 1.25
    pub gateway_bond_reward_rate: Decimal, // annual reward rate, expressed as a decimal like 1.25
    #[serde(default = "your_default_fn")]
    pub mixnode_delegation_reward_rate: Decimal, // annual reward rate, expressed as a decimal like 1.25
    #[serde(default = "your_default_fn")]
    pub gateway_delegation_reward_rate: Decimal, // annual reward rate, expressed as a decimal like 1.25
    pub mixnode_active_set_size: u32,
}

//

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct State {
    pub owner: Addr, // only the owner account can update state
    pub network_monitor_address: Addr,
    pub params: StateParams,

    // helper values to avoid having to recalculate them on every single payment operation
    pub mixnode_epoch_bond_reward: Decimal, // reward per epoch expressed as a decimal like 0.05
    pub gateway_epoch_bond_reward: Decimal, // reward per epoch expressed as a decimal like 0.05
    #[serde(default = "your_default_fn")]
    pub mixnode_epoch_delegation_reward: Decimal, // reward per epoch expressed as a decimal like 0.05
    #[serde(default = "your_default_fn")]
    pub gateway_epoch_delegation_reward: Decimal, // reward per epoch expressed as a decimal like 0.05
}

and then resaving it in the migration (so literally just load the state and save it again). Then after migration itself is finished, another PR should be made to remove those serde macros.

b) via intermediate structs

basically inside migrate() function define struct OldState and struct OldStateParams, deserialize to those, create the "proper" structs and save that data.

But whatever you do, please do the sanity check first, i.e. initialise contract with the old version on your localnet (before you made any changes), set some non-default parameters, migrate contract and try to do something to it.

@neacsu
Copy link
Contributor Author

neacsu commented Aug 18, 2021

Added the migration code and tested it locally. Thank you for the suggestions @jstuczyn . Will remove the last commit in a separate PR

@neacsu neacsu requested a review from jstuczyn August 18, 2021 11:29
Copy link
Contributor

@jstuczyn jstuczyn left a comment

Choose a reason for hiding this comment

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

If you're saying the migration works locally for you, that's good enough for me

@neacsu neacsu merged commit eec211e into develop Aug 18, 2021
@neacsu neacsu deleted the feature/use_delegation_rates branch August 18, 2021 13:24
@neacsu neacsu restored the feature/use_delegation_rates branch August 23, 2021 08:37
@neacsu neacsu deleted the feature/use_delegation_rates branch August 23, 2021 08:37
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