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

Unable to bond extra #6984

Open
xlc opened this issue Dec 23, 2024 · 3 comments
Open

Unable to bond extra #6984

xlc opened this issue Dec 23, 2024 · 3 comments

Comments

@xlc
Copy link
Contributor

xlc commented Dec 23, 2024

Address: 14DsLzVyTUTDMm2eP3czwPbH53KgqnQRp3CJJZS9GR7yxGDP
This tx failed: https://polkadot.subscan.io/extrinsic/23965894-2
It is trying to bond extra 1 dot and I have 30+ transferable DOT and the bond failed
And I am able to transfer 1 DOT out of this account: https://polkadot.subscan.io/extrinsic/23966216-2

@xlc
Copy link
Contributor Author

xlc commented Dec 23, 2024

It is this line failed

asset::stakeable_balance::<T>(stash)
.checked_sub(&ledger.total)
.ok_or(ArithmeticError::Overflow)?,

Relevant state at block 23965893

staking.ledger: Option<PalletStakingStakingLedger>
{
  stash: 14DsLzVyTUTDMm2eP3czwPbH53KgqnQRp3CJJZS9GR7yxGDP
  total: 12,929,164,149,143
  active: 12,929,164,149,143
  unlocking: []
  legacyClaimedRewards: []
}

system.account: FrameSystemAccountInfo
{
  nonce: 515
  consumers: 2
  providers: 1
  sufficients: 0
  data: {
    free: 11,929,004,994,238
    reserved: 1,302,990,000,000
    frozen: 12,929,164,149,143
    flags: 170,141,183,460,469,231,731,687,309,715,884,105,728
  }
}

So it failed because free is less than ledger.total
But the transferable amount suppose to be frozen - (free + reserved) and I see no reason to not use it for max staking amount calculation?

@bkchr
Copy link
Member

bkchr commented Dec 23, 2024

CC @Ank4n @kianenigma

@paritytech paritytech deleted a comment from AlexLiveBot11549 Jan 3, 2025
@gui1117
Copy link
Contributor

gui1117 commented Jan 5, 2025

The same logic is implemented when calling bond. In both case the maximum stakeable amount is Currency::free_balance, and doesn't include the reserved amount. Maybe we should change like this:

diff --git a/substrate/frame/staking/src/asset.rs b/substrate/frame/staking/src/asset.rs
index 23368b1f8fc..b939987ae72 100644
--- a/substrate/frame/staking/src/asset.rs
+++ b/substrate/frame/staking/src/asset.rs
@@ -41,7 +41,7 @@ pub fn total_balance<T: Config>(who: &T::AccountId) -> BalanceOf<T> {
 ///
 /// This includes balance free to stake along with any balance that is already staked.
 pub fn stakeable_balance<T: Config>(who: &T::AccountId) -> BalanceOf<T> {
-       T::Currency::free_balance(who)
+       T::Currency::total_balance(who)
 }
 
 /// Balance of `who` that is currently at stake.

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

No branches or pull requests

3 participants