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

kaiax/staking,reward: Introduce consensus liquidity #176

Merged
merged 3 commits into from
Dec 13, 2024

Conversation

hyeonLewis
Copy link
Contributor

@hyeonLewis hyeonLewis commented Dec 12, 2024

Proposed changes

This PR introduces consensus liquidity to staking, reward modules.

The consensus liquidity will be activated for network activating Prague hardfork and istanbul.policy == 2 && reward.deferredtxfee = true.

Staking module

When GetStakingInfo, if condition met, it reads CLInfos from CLRegistry defined in KIP-226. If Registry hasn't been installed (by any reason), it skips CL and don't panic. If CLRegistry hasn't been registered, it will return empty arrays.

Reward module

When ConsolidatedNodes(), if condition met, it consolidates CLInfos by CLNodeId, not CLRewardAddr.

Let's assume we have following entries in AddressBook and CLRegistry.

// From AddressBook
NodeIds = [n1, n2, n3]
CNStaking = [c1, c2, c4]
RewardAddrs = [r1, r1, r2]

// From CLRegistry
CLNodeIds = [n2]
CLPools = [p1]
CLRewardAddrs = [clr1]

Then, the clr1 isn't neither r1 nor r2. But it will be consolidated into [n1, n2] since it has CLNodeId == n2. The result consolidated nodes are:

{
  NodeId = [n1, n2]
  StakingContracts = [c1, c2]
  RewardAddr = [r1]
  StakingAmount = balance(c1+c2)
  CLStakingInfo {
    CLNodeId = n2
    CLPoolAddr = p1
    CLRewardAddr = clr1
    CLStakingAmount = balance(p1)
  }
}, 
{
  // Node3
  ...
}

If CLNodeId doesn't belong to any of node, then it'll be ignored. Note that CLNodeId can be any of NodeId, not first NodeId.

Reward distribution

If validator has CL, then the staking in CL also summed up to total staking amount if staking in AB >= minStaking.
The excess staking amount will be calculated by:

// Before Prague
excess = StakingAmont > minStaking ? StakingAmount - minStaking : 0

// After Prague
excess = StakingAmont >= minStaking ? StakingAmount + CLStakingAmount - minStaking : 0

Both the proposer and staking rewards will be proportionally distributed to RewardAddr and CLRewardAddr. For proposer, please see #specWithProposerAndFunds.

API

The kaia.GetStakingInfo will be affected and CLStakingInfos field will be null before prague HF or empty CLRegistry entries.

Testing

The unit tests are included in this PR. I'll start testing in private network once this PR stabilized.

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have read the CLA and signed by comment I have read the CLA Document and I hereby sign the CLA in first time contribute
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

  • Please leave the issue numbers or links related to this PR here.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

kaiax/staking/staking_info.go Show resolved Hide resolved
kaiax/staking/staking_info.go Outdated Show resolved Hide resolved
Co-authored-by: Yunjong Jeong (ollie) <5933330+blukat29@users.noreply.github.com>
@blukat29 blukat29 merged commit 6552a96 into kaiachain:dev Dec 13, 2024
11 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants