-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
R4R remove global shares #1644
R4R remove global shares #1644
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed quickly, looks vastly simplified, a few tiny suggestions.
types/rational.go
Outdated
@@ -252,3 +252,11 @@ func RatsEqual(r1s, r2s []Rat) bool { | |||
func RatEq(t *testing.T, exp, got Rat) (*testing.T, bool, string, Rat, Rat) { | |||
return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp, got | |||
} | |||
|
|||
// test if two rat arrays are the equal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return the lesser of two rats?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to minimum rational between two
x/stake/types/pool.go
Outdated
p.BondedTokens += amount | ||
p.LooseTokens -= amount | ||
if p.LooseTokens < 0 { | ||
func (p Pool) addBondedTokens(bondedTokens sdk.Rat) Pool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename looseTokensToBonded
perhaps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that's more concise - good idea - changed
x/stake/types/pool.go
Outdated
p.BondedTokens -= removedTokens | ||
p.LooseTokens += removedTokens | ||
if p.UnbondedTokens < 0 { | ||
func (p Pool) removeBondedTokens(bondedTokens sdk.Rat) Pool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed bondedTokensToLoose
perhaps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
The "don't get your spot back for equal heights and tokens" test is failing under |
I also get: --- FAIL: TestSlashWithRedelegation (0.01s)
Error Trace: slash_test.go:361
Error: func (assert.PanicTestFunc)(0x9bae00) should not panic
Panic value: sanity check: bonded tokens negative, pool: {23/1 -1/1 0 7/100 0 0/1}
Test: TestSlashWithRedelegation |
x/stake/types/validator.go
Outdated
issuedDelegatorShares := equivalentBondedShares.Quo(exRate) | ||
v.DelegatorShares = v.DelegatorShares.Add(issuedDelegatorShares) | ||
v.Tokens = v.Tokens.Add(sdk.NewRat(amount)) | ||
issuedShares := v.Tokens.Quo(exRate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rigelrozanski I think this line is the problem - computing v.Tokens.Quo(exRate)
(all shares), but I think we want sdk.NewRat(amount).Quo(exRate)
(newly added shares)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for resolving
Codecov Report
@@ Coverage Diff @@
## master #1644 +/- ##
==========================================
- Coverage 62.83% 62.53% -0.31%
==========================================
Files 124 123 -1
Lines 6998 6995 -3
==========================================
- Hits 4397 4374 -23
- Misses 2349 2370 +21
+ Partials 252 251 -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approving changes to state.md. let's revise the approval process sooner rather than later 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor comments
docs/spec/staking/state.md
Outdated
validator shares for stake in the global pools, moving Atom inflation | ||
information, etc. | ||
information about the total amounts of Atoms in all states, moving Atom | ||
inflation information, etc. | ||
|
||
```golang | ||
type Pool struct { | ||
LooseTokens int64 // tokens not associated with any validator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LooseTokens
is now tokens not associated with any bonded validator, right? (it includes tokens associated with *unbonded validators)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct - just updated the comment to reflect this
docs/spec/staking/state.md
Outdated
@@ -85,7 +74,9 @@ type Validator struct { | |||
ConsensusPubKey crypto.PubKey // Tendermint consensus pubkey of validator | |||
Revoked bool // has the validator been revoked? | |||
|
|||
PoolShares PoolShares // total shares for tokens held in the pool | |||
PoolShares sdk.BondStatus // total shares for tokens held in the pool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this line be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, removed
pool, poolShares = pool.addTokensUnbonding(amount) | ||
case sdk.Bonded: | ||
pool, poolShares = pool.addTokensBonded(amount) | ||
if v.Status == sdk.Bonded { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amountRat
can be declared a line earlier to avoid the extra sdk.Rat
allocation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
x/stake/types/validator.go
Outdated
|
||
return v, pool, issuedDelegatorShares | ||
return v, pool, issuedShares | ||
} | ||
|
||
// RemoveDelShares removes delegator shares from a validator. | ||
// | ||
// NOTE: This function assumes the shares have already been updated for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment no longer applicable I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct - removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second pass
x/stake/handler.go
Outdated
|
||
// Process types.Validator Provisions | ||
blockTime := ctx.BlockHeader().Time | ||
if pool.InflationLastTime+blockTime >= 3600 { | ||
pool.InflationLastTime = blockTime | ||
pool = k.ProcessProvisions(ctx) | ||
pool.ProcessProvisions(params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to capture the returned Pool
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, THANK YOU - added
x/stake/keeper/slash.go
Outdated
} | ||
|
||
// Cannot decrease balance below zero | ||
sharesToRemove := sdk.MinInt(remainingSlashAmount, validator.PoolShares.Amount.RoundInt()) | ||
burned := sdk.MinRat(remainingSlashAmount, validator.Tokens) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit confusing; maybe tokensToBurn
? They aren't burned until a few lines later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay - added
x/stake/types/pool.go
Outdated
} | ||
|
||
//____________________________________________________________________ | ||
|
||
// get the bond ratio of the global state | ||
func (p Pool) BondedRatio() sdk.Rat { | ||
if p.TokenSupply() > 0 { | ||
return sdk.NewRat(p.BondedTokens, p.TokenSupply()) | ||
if p.TokenSupply().GT(sdk.ZeroRat()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
supply = p.TokenSupply()
, avoid calculating twice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
p.BondedTokens = p.BondedTokens.Sub(bondedTokens) | ||
p.LooseTokens = p.LooseTokens.Add(bondedTokens) | ||
if p.BondedTokens.LT(sdk.ZeroRat()) { | ||
panic(fmt.Sprintf("sanity check: bonded tokens negative, pool: %v", p)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should have a sdk.URat
type (not for this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah could maybe be good
} | ||
pool, tokens = pool.removeSharesUnbonded(v.PoolShares.Amount) | ||
|
||
case sdk.Unbonding: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we ever use this status (sdk.Unbonding
)? I only see it in validator_test.go
and I'm not clear why we need it in the model; unbonding delegations / redelegations seem to provide the requisite tracking
Also see #1673
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect - we need this status for when an entire validator begins unbonding (with it's delegators still attached) because it has been revoked - opening an issue to verify that this is happening
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed comments - if there is anything else small - feel free to push to this branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ACK
9ea3b6a
to
597dbfc
Compare
closes #1215