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

R4R remove global shares #1644

Merged
merged 29 commits into from
Jul 13, 2018
Merged

R4R remove global shares #1644

merged 29 commits into from
Jul 13, 2018

Conversation

rigelrozanski
Copy link
Contributor

@rigelrozanski rigelrozanski commented Jul 11, 2018

closes #1215

  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG.md
  • Updated Gaia/Examples
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)
  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)

Copy link
Contributor

@cwgoes cwgoes left a 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.

@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

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

p.BondedTokens += amount
p.LooseTokens -= amount
if p.LooseTokens < 0 {
func (p Pool) addBondedTokens(bondedTokens sdk.Rat) Pool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename looseTokensToBonded perhaps?

Copy link
Contributor Author

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

p.BondedTokens -= removedTokens
p.LooseTokens += removedTokens
if p.UnbondedTokens < 0 {
func (p Pool) removeBondedTokens(bondedTokens sdk.Rat) Pool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed bondedTokensToLoose perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@rigelrozanski
Copy link
Contributor Author

The "don't get your spot back for equal heights and tokens" test is failing under x/stake/keeper/validator_test.go

@cwgoes
Copy link
Contributor

cwgoes commented Jul 13, 2018

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

issuedDelegatorShares := equivalentBondedShares.Quo(exRate)
v.DelegatorShares = v.DelegatorShares.Add(issuedDelegatorShares)
v.Tokens = v.Tokens.Add(sdk.NewRat(amount))
issuedShares := v.Tokens.Quo(exRate)
Copy link
Contributor

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)

Copy link
Contributor Author

@rigelrozanski rigelrozanski Jul 13, 2018

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
Copy link

codecov bot commented Jul 13, 2018

Codecov Report

Merging #1644 into master will decrease coverage by 0.3%.
The diff coverage is 75%.

@@            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

@rigelrozanski rigelrozanski changed the title WIP remove global shares R4R remove global shares Jul 13, 2018
@rigelrozanski rigelrozanski removed the wip label Jul 13, 2018
Copy link
Contributor

@jbibla jbibla left a 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 😄

Copy link
Contributor

@cwgoes cwgoes left a 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

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
Copy link
Contributor

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)

Copy link
Contributor Author

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

@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed


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
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct - removed

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second pass


// Process types.Validator Provisions
blockTime := ctx.BlockHeader().Time
if pool.InflationLastTime+blockTime >= 3600 {
pool.InflationLastTime = blockTime
pool = k.ProcessProvisions(ctx)
pool.ProcessProvisions(params)
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, THANK YOU - added

}

// Cannot decrease balance below zero
sharesToRemove := sdk.MinInt(remainingSlashAmount, validator.PoolShares.Amount.RoundInt())
burned := sdk.MinRat(remainingSlashAmount, validator.Tokens)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay - added

}

//____________________________________________________________________

// 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()) {
Copy link
Contributor

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

Copy link
Contributor Author

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))
Copy link
Contributor

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)

Copy link
Contributor Author

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:
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rigelrozanski
Copy link
Contributor Author

Addressed comments - if there is anything else small - feel free to push to this branch

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested ACK

@cwgoes cwgoes force-pushed the rigel/remove-global-shares branch from 9ea3b6a to 597dbfc Compare July 13, 2018 19:40
@ebuchman ebuchman merged commit 3231daa into master Jul 13, 2018
@ebuchman ebuchman deleted the rigel/remove-global-shares branch July 13, 2018 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants