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 Implementation #540

Merged
merged 54 commits into from
Mar 28, 2018
Merged

Staking Implementation #540

merged 54 commits into from
Mar 28, 2018

Conversation

rigelrozanski
Copy link
Contributor

@rigelrozanski rigelrozanski commented Mar 1, 2018

pre-MVP staking logic

    ____________========
   /      o          | |
 /                    ||
 v v v v               |
  ^ ^ ^ ^              |
  \........            |

@rigelrozanski rigelrozanski requested a review from ebuchman as a code owner March 1, 2018 16:28
@rigelrozanski rigelrozanski mentioned this pull request Mar 1, 2018
@codecov
Copy link

codecov bot commented Mar 1, 2018

Codecov Report

Merging #540 into develop will decrease coverage by 3.98%.
The diff coverage is 47.63%.

@@             Coverage Diff             @@
##           develop     #540      +/-   ##
===========================================
- Coverage     63.3%   59.32%   -3.99%     
===========================================
  Files           44       62      +18     
  Lines         2055     3255    +1200     
===========================================
+ Hits          1301     1931     +630     
- Misses         639     1183     +544     
- Partials       115      141      +26

@adrianbrink adrianbrink changed the title WIP Staking WIP: Staking Mar 12, 2018
@adrianbrink adrianbrink changed the title WIP: Staking WIP: Staking Implementation Mar 12, 2018
@rigelrozanski rigelrozanski force-pushed the rigel/staking branch 6 times, most recently from 355a1dc to 6eb2a12 Compare March 20, 2018 13:56
@martindale martindale mentioned this pull request Mar 22, 2018
@adrianbrink
Copy link
Contributor

What's the message for Unbonding as a Candidate?

if msg.Description.Details != "" {
candidate.Description.Details = msg.Description.Details
}

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 care about candidates having the ability to clear previously set metadata?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

opening an issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}
store := ctx.KVStore(k.storeKey)
b := store.Get(ParamKey)
if b == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Desirable to move store initialization logic into a single function for clarity? Also avoids strange results were a store to return nil incorrectly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

created an issue, I think this can wait until after the MVP though #724

Inflation: sdk.NewRat(7, 100),
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Desirable to load default staking params / pool params from a config file? That way clients can customize without recompiling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as previous response above ^

// Perform all the actions required to bond tokens to a delegator bond from their account
func (k Keeper) BondCoins(ctx sdk.Context, bond DelegatorBond, candidate Candidate, amount sdk.Coin) sdk.Error {

_, err := k.coinKeeper.SubtractCoins(ctx, bond.DelegatorAddr, sdk.Coins{amount})
Copy link
Contributor

Choose a reason for hiding this comment

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

Spec says coins should be transferred to pool account - is that account not necessary to track explicitly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed; spec should change @milosevic - no longer a need for a pool account.

receivedGlobalShares = k.addTokensUnbonded(ctx, amount)
}
candidate.Assets = candidate.Assets.Add(receivedGlobalShares)

Copy link
Contributor

@cwgoes cwgoes Mar 26, 2018

Choose a reason for hiding this comment

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

Spec defines issuedShares and receivedGlobalShares as two different variables, but the latter is used nowhere else in the spec - are they supposed to be the same (as they are 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.

they are not the same here - can go over with you tomorrow

bond.Shares = bond.Shares.Sub(shares)

// get pubKey candidate
candidate, found := k.GetCandidate(ctx, msg.CandidateAddr)
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 want to also check candidate existence in CheckTx calls?

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

}

// deduct shares from the candidate
if candidate.Liabilities.IsZero() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Per spec, this check should be for candidate.Assets (globalStakeShares)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

conceptually makes more sense yes - although I think both should work

type MsgEditCandidacy struct {
Description
CandidateAddr sdk.Address `json:"address"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Spec also includes provision for changingcommission

Copy link
Contributor Author

Choose a reason for hiding this comment

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

commission not yet implemented

}

// subtract bond tokens from delegator bond
if bond.Shares.LT(shares) { // bond shares < msg shares
Copy link
Contributor

Choose a reason for hiding this comment

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

Check redundant? Either bond.Shares.GT(shares) is true or shares == bond.Shares

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool was partially redundant, moved stuff around to make clear / remove redundancy

@rigelrozanski
Copy link
Contributor Author

Many issues: #713

@rigelrozanski rigelrozanski changed the title WIP: Staking Implementation Staking Implementation Mar 28, 2018
//_______________________________________________________________________

// DelegatedProofOfStake - interface to enforce delegation stake
type delegatedProofOfStake interface {
Copy link
Member

Choose a reason for hiding this comment

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

nice!

@ebuchman ebuchman merged commit 2e5943e into develop Mar 28, 2018
@ebuchman ebuchman deleted the rigel/staking branch March 28, 2018 17:08
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

Successfully merging this pull request may close these issues.

5 participants