Repository navigation
fix(staking): keep reserve-capacity floor on deposits - #5653
Closed
sbackend123 wants to merge 1 commit into
Closed
sbackend123 wants to merge 1 commit into
sbackend123 wants to merge 1 commit into
Conversation
Contributor
Author
|
Closed: the description was meant to stay in review notes, not to open a pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
Description
Deposits at height above zero must leave potential stake at least
MIN_STAKE * 2^height.#5571dropped that Bee-side floor when it started mirroring the contract. This puts the floor back insidecalculateMinDeposit, next to the commitment check from#5571. If commitment requires more than the floor, the larger amount is still reported.How the staking contract treats height
StakeRegistry.manageStakehas two amount reverts, then writesheightunconditionally.The absolute floor applies only to the first stake. The comment in the contract says so, and the condition is
_stakingSet == 0(lastUpdatedBlockNumber == 0):MIN_STAKEis10^17. A new node at height 1 must deposit at least2 * 10^17. An existing stake skips this check entirely.After that, a non-zero deposit may not decrease commitment. Equality is allowed:
Height is then stored with no further comparison to
MIN_STAKE * 2^height:A price drop can make that second check free. Stake
10^17at price 48000 and height 0:Price then falls to 24000 and the node calls
manageStakewith height 1 and 1 PLUR:DecreasedCommitmentdoes not fire,BelowMinimumStakedoes not apply, and the contract records height 1 with potential10^17 + 1. A new node at that same height would have been rejected below2 * 10^17. Redistribution then uses the stored height (depth - height), so the doubled reserve is credited without the stake a new node must post.A zero-amount
manageStakedoes not even recompute commitment.node.goalready refuses that path (UpdateHeight) whenreserve-capacity-doubling > 0and potential is below2^h * MIN. Every deposit also sends the configured height, and#5571no longer blocked that write.What
#5571removed, and what this restoresBefore
#5571,DepositStakerejected a deposit unlesspotential + deposit >= (1 << height) * MIN. That included height 0, so an existing stake that had fallen belowMINcould not be topped up until it was back atMIN.#5571replaced that check withcalculateMinDeposit, which copies the contract:MIN * 2^heightcommitted * price * 2^heightfrom decreasing, or 1 PLUR when there is no gapThat commitment math stays. It is why a price increase still raises
minimumDeposit, and why an existing height-0 stake belowMIN(slashed, or withdrawn to zero potential) can still deposit 1 PLUR. The contract accepts those, andGET /stakemust keep reporting them.What
#5571also dropped is the reserve-capacity floor for height above zero. This PR adds it back in the same function, after the commitment gap:GET /stakeandDepositStaketherefore agree. In the price-drop case above, commitment allows 1 PLUR and the floor raises the reported minimum to10^17, which brings potential to2 * 10^17before height 1 is published. If commitment already requires more than that gap, the commitment amount is kept.Height 0 is unchanged on purpose.
(1 << 0) * MINis the old blanket floor, and restoring it would undo the#5571rule that an existing stake belowMINis not forced back up.node.goapplies the same limit only whenreserve-capacity-doubling > 0.Open API Spec Version Changes (if applicable)
None.
GET /stakeandPOST /stake/{amount}keep theminimumDepositfield added in#5571. For height above zero the value can be higher than the contract's own minimum.Motivation and Context (Optional)
#5571correctly pre-validatesBelowMinimumStakeandDecreasedCommitment. The contract does not re-checkMIN * 2^heightonce a stake exists, so mirroring it let a deposit publish a reserve-capacity height thatnode.gorefuses to publish viaUpdateHeight.Related Issue (Optional)
Follow-up to
#5571.Screenshots (if appropriate):
AI Disclosure
Made with Cursor