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

Staking locked balances can be more than the actual free balances #409

Closed
liuchengxu opened this issue Dec 2, 2020 · 0 comments · Fixed by #408
Closed

Staking locked balances can be more than the actual free balances #409

liuchengxu opened this issue Dec 2, 2020 · 0 comments · Fixed by #408
Labels
F2-bug 🐜 The client fails to follow expected behavior.

Comments

@liuchengxu
Copy link
Contributor

liuchengxu commented Dec 2, 2020

ensure!(value <= Self::free_balance(&sender), Error::<T>::InsufficientBalance);

This line will cause there are more Staking votes than the actual balances, which also means we might lock more funds than a user has. For instance, 5UW4LiYMc1r1X3yQVLCVi281wi5GCyRCwJZ3d9jHpbBSGW5Y has negative usable balances due to the over-staking-lock.

~/.../chainx-org/chainx-cli ❯❯❯ ./target/release/chainx-cli --url ws://116.62.46.8:8087 xstaking storage locks 5UW4LiYMc1r1X3yQVLCVi281wi5GCyRCwJZ3d9jHpbBSGW5Y --block-number 107671
d719d3036ac37da50627651e2353873f5eb9cdbce547ee5684b0618171bf7d0a (5GvjpjTY...): {
    Bonded: 2073339270000,
    BondedWithdrawal: 1264702800000,
}
# The usable is -5339.75070541PCX
~/.../chainx-org/chainx-cli ❯❯❯ ./target/release/chainx-cli --url ws://116.62.46.8:8087 system account-info 5UW4LiYMc1r1X3yQVLCVi281wi5GCyRCwJZ3d9jHpbBSGW5Y --block-number 107671
AccountInfo of d719d3036ac37da50627651e2353873f5eb9cdbce547ee5684b0618171bf7d0a (5GvjpjTY...): AccountInfo {
    nonce: 37,
    refcount: 2,
    data: AccountData {
        free: 2804066999459,
        reserved: 1000000,
        misc_frozen: 3338042070000,
        fee_frozen: 3338042070000,
    },
}
{
	"id":1,
	"jsonrpc":"2.0",
	"method":"xstaking_getNominationByAccount",
	"params":["5UW4LiYMc1r1X3yQVLCVi281wi5GCyRCwJZ3d9jHpbBSGW5Y", "0x923161c814c5d0d01c3926d36acee704a97c18cdb59ade0cbd72b3da667066c3"]
}

We expect 1 PCX 1 vote in theory, but there are more Staking votes now, the consequence is that some stakers are earning more rewards than they should. If someone's frozen balances are more than his free balance, then he has more unexpected gains due to this bug, at the same time some other people will have fewer rewards as the reward pot per validator is correct. This bug only relates to the distribution of all nominators behind a validator, some earn more and some others earn less.

Should be fixed by #408.
https://github.com/chainx-org/ChainX/pull/408/files#diff-acfc4fead7dba36919225985639fe230fc951b8b6630dc3e48d15fb5a3366076R351-R354 will ensure 1 PCX 1 vote again.

The stakers having any windfall, especially these have negative usable balance now, will have to wait for the fix using XStaking::force_reset_staking_lock().

Update: This bug is not the root cause of the staking reward drop as there only are 10 accounts with negative usable balance, the total involved money is less than 6000PCX, which is too small compared to the total stakes(6M+). The main reason is when we migrated to 2.0, we settled all the latest vote weight of 1.0. And the vote weight is measured by blocks, which means we have to spend 3 times the time to obtain the same vote weight in 2.0, so the users with legacy vote weight earns more, but once they make their first claim on 2.0, they will have no advantages.

@liuchengxu liuchengxu added the F2-bug 🐜 The client fails to follow expected behavior. label Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F2-bug 🐜 The client fails to follow expected behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant