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

Starlight <> Ethereum: Rewards mapping #761

Merged
merged 69 commits into from
Dec 10, 2024
Merged

Conversation

Agusrodri
Copy link
Contributor

@Agusrodri Agusrodri commented Nov 25, 2024

What does it do?

This PR takes care of generating a specific command called ReportRewards, which is used to map and encode rewards data happening in Starlight. This information will then be used by Symbiotic smart contracts on the Ethereum side to perform specific computation/checks related to rewards.

More specifically, the ReportRewards command has the following structure:

    ReportRewards {
        // block timestamp
        timestamp: u64,
        // index of the era we are sending info of
        era_index: u32,
        // total_points for the era
        total_points: u128,
        // new tokens inflated during the era
        tokens_inflated: u128,
        // merkle root of vec![(validatorId, rewardPoints)]
        rewards_merkle_root: H256,
    }

Addition of runtime api

In this PR, a ExternalValidatorsRewardsApi runtime api was added, containing two main functions:

sp_api::decl_runtime_apis! {
    pub trait ExternalValidatorsRewardsApi<AccountId, EraIndex>
    where
        AccountId: parity_scale_codec::Codec,
        EraIndex: parity_scale_codec::Codec,
    {
        fn generate_rewards_merkle_proof(account_id: AccountId, era_index: EraIndex) -> Option<MerkleProof>;
        fn verify_rewards_merkle_proof(merkle_proof: MerkleProof) -> bool;
    }
}

Where:

  • generate_rewards_merkle_proof: generates a merkle proof for a given account_id and era_index. If the account_id was not rewarded in that era or was not present in the validator set for some reason, it returns None.
  • verify_rewards_merkle_proof: verifies a merkle proof (that could be previously generated by calling generate_rewards_merkle_proof).

Copy link
Contributor

github-actions bot commented Nov 28, 2024

Coverage Report

(master)

@@                   Coverage Diff                   @@
##           master   agustin-map-rewards      +/-   ##
=======================================================
+ Coverage   64.56%                64.73%   +0.17%     
+ Files         320                   323       +3     
+ Lines       55422                 55578     +156     
=======================================================
+ Hits        35781                 35974     +193     
- Misses      19641                 19604      -37     
Files Changed Coverage
/pallets/external-validators/src/lib.rs 91.07% (+0.36%)
/pallets/external-validators-rewards/src/lib.rs 89.58% (+7.12%)
/primitives/bridge/src/custom_send_message.rs 85.71% (+85.71%)
/primitives/bridge/src/lib.rs 58.72% (+58.72%)
/primitives/traits/src/lib.rs 63.11% (-2.46%)
/solo-chains/runtime/dancelight/src/lib.rs 66.91% (+0.70%)

Coverage generated Tue Dec 10 13:04:20 UTC 2024

@Agusrodri Agusrodri marked this pull request as ready for review November 29, 2024 16:46
Copy link
Collaborator

@girazoki girazoki left a comment

Choose a reason for hiding this comment

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

minor comments, the rest looks good to me

@Agusrodri Agusrodri merged commit 354bbb8 into master Dec 10, 2024
42 checks passed
@Agusrodri Agusrodri deleted the agustin-map-rewards branch December 10, 2024 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes breaking Needs to be mentioned in breaking changes D5-nicetohaveaudit⚠️ PR contains trivial changes to logic that should be properly reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants