ExocoreNetwork / exocore

5 stars 9 forks source link

feat(delegation): load genesis state #26

Closed MaxMustermann2 closed 2 months ago

MaxMustermann2 commented 3 months ago

This PR subsumes #27 within itself, and therefore should be merged after that one. For ease of review, this PR may be reviewed after the merge of #27 happens and this PR is rebased.

The x/delegation module needs to load the genesis state of delegations (for each possible combination of staker, asset and operator) for the network to successfully bootstrap with the rPOS process.

The genesis state is structured as follows.

{
    "delegations": [
        {
            "staker_id": "0xaaaaaa_0x65",
            "delegations": [
                {
                    "asset_id": "0xbbbb_0x65",
                    "per_operator_amounts": [
                        {"key": "exo1.....", "value": {"amount": "700"}},
                        {"key": "exo1.....", "value": {"amount": "500"}}, {...}
                    ]
                }, {...}
            ]
        }, {...}
    ]
}

At genesis, the module should perform these delegations as it would if the chain were live. To do this, we call the exact same DelegateTo function that is called by the precompile and use a flag to skip (1) the operator frozen check, (2) the operator module update and (3) the delegation hooks.

The stateless validation uses this algorithm: