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

Unbonding, Redelegation #1119

Merged
merged 84 commits into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
3d0e7ff
stake/fees spec updates
rigelrozanski May 17, 2018
43a0ed9
staking overview.md revisions, moving files
rigelrozanski May 18, 2018
a49f9cb
docs reorganization
rigelrozanski May 18, 2018
f972cab
staking spec state revisions
rigelrozanski May 23, 2018
752f084
transaction stake updates
rigelrozanski May 25, 2018
5a77d7d
complete staking spec update
rigelrozanski May 29, 2018
26681a8
WIP adding unbonding/redelegation commands
rigelrozanski Jun 2, 2018
8e677e8
added msg types for unbonding, redelegation
rigelrozanski Jun 2, 2018
43429ef
stake sub-package reorg
rigelrozanski Jun 2, 2018
482a3c5
...
rigelrozanski Jun 2, 2018
fd1eb5f
working stake reorg
rigelrozanski Jun 3, 2018
63a0dcc
...
rigelrozanski Jun 5, 2018
7eaa715
...
rigelrozanski Jun 5, 2018
3fac834
modify lcd tests to not use hardcoded json strings
rigelrozanski Jun 5, 2018
d69d179
add description update
rigelrozanski Jun 5, 2018
0efb0a4
index keys
rigelrozanski Jun 5, 2018
2153e0d
...
rigelrozanski Jun 5, 2018
f6b9893
...
rigelrozanski Jun 5, 2018
e460c06
key managment for unbonding redelegation complete
rigelrozanski Jun 6, 2018
8639f91
...
rigelrozanski Jun 6, 2018
9ee70ea
update stake errors
rigelrozanski Jun 6, 2018
bd41980
...
rigelrozanski Jun 6, 2018
40ad0a5
completed handleMsgCompleteUnbonding fn
rigelrozanski Jun 6, 2018
4be5e41
updated to use begin/complete unbonding/redelegation
rigelrozanski Jun 7, 2018
03c6804
...
rigelrozanski Jun 7, 2018
98dad7d
fix token shares bug
rigelrozanski Jun 13, 2018
4601bd5
develop docs into unbonding
rigelrozanski Jun 14, 2018
fc6ee07
...
rigelrozanski Jun 14, 2018
ffc8cc4
...
rigelrozanski Jun 14, 2018
6a5bc2d
Merge remote-tracking branch 'origin/develop' into rigel/unbonding
rigelrozanski Jun 16, 2018
436f32d
got non-tests compiling after merge develop
rigelrozanski Jun 17, 2018
37190aa
working fixing tests
rigelrozanski Jun 19, 2018
ed7b90e
PrivlegedKeeper -> PrivilegedKeeper
rigelrozanski Jun 19, 2018
af4fd6e
tests compile
rigelrozanski Jun 19, 2018
1d7d4d4
Merge remote-tracking branch 'origin/develop' into rigel/unbonding
rigelrozanski Jun 20, 2018
d427af7
fix some tests
rigelrozanski Jun 20, 2018
a0ac5e9
fixing tests
rigelrozanski Jun 20, 2018
b72a219
Merge branch 'develop' into rigel/unbonding
rigelrozanski Jun 20, 2018
8860fa3
remove PrivilegedKeeper
rigelrozanski Jun 20, 2018
24395fd
...
rigelrozanski Jun 20, 2018
258834f
...
rigelrozanski Jun 20, 2018
9ce6759
get unbonding bug
rigelrozanski Jun 20, 2018
1ae48da
only rpc sig verification failed tests now
rigelrozanski Jun 20, 2018
bc2e0d7
Merge branch 'develop' into rigel/unbonding
rigelrozanski Jun 20, 2018
ad73cd1
...
rigelrozanski Jun 20, 2018
60158d5
move percent unbonding/redelegation to the CLI and out of handler logic
rigelrozanski Jun 20, 2018
b1cb149
remove min unbonding height
rigelrozanski Jun 21, 2018
3cd8478
add lcd txs
rigelrozanski Jun 21, 2018
a3e04ce
add pool sanity checks, fix a buncha tests
rigelrozanski Jun 21, 2018
782afbb
fix ante. set lcd log to debug (#1322)
ebuchman Jun 21, 2018
ad9da64
Merge branch 'develop' into rigel/unbonding
rigelrozanski Jun 21, 2018
071d47b
redelegation tests, adding query functionality for bonds
rigelrozanski Jun 22, 2018
5dc163c
add self-delegations at genesis ref #1165
rigelrozanski Jun 22, 2018
6e2c66c
PR comments (mostly) addressed
rigelrozanski Jun 23, 2018
f004c6c
cleanup, added Query LCD functionality
rigelrozanski Jun 25, 2018
ceb8856
test cleanup/fixes
rigelrozanski Jun 25, 2018
9f99a17
Merge remote-tracking branch 'origin/develop' into rigel/unbonding
rigelrozanski Jun 25, 2018
32b75c5
fix governance test
rigelrozanski Jun 25, 2018
85c3639
Merge branch 'develop' into rigel/unbonding
rigelrozanski Jun 25, 2018
177ab4c
SlashValidatorSet -> ValidatorSet
rigelrozanski Jun 25, 2018
3f4e528
changelog
rigelrozanski Jun 25, 2018
40b9faf
stake lcd fix
rigelrozanski Jun 25, 2018
a500931
...
rigelrozanski Jun 25, 2018
c916f21
...
rigelrozanski Jun 25, 2018
82f3529
Merge branch 'develop' into rigel/unbonding
ebuchman Jun 25, 2018
d5ab2f3
x/auth: fix chainID in ante
ebuchman Jun 25, 2018
b8571b6
Merge branch 'rigel/unbonding' of https://github.com/cosmos/cosmos-sd…
rigelrozanski Jun 25, 2018
2511ef1
fix lcd test
rigelrozanski Jun 25, 2018
a029cb9
...
rigelrozanski Jun 25, 2018
9cddb06
fix lint, update lint make command for spelling
rigelrozanski Jun 25, 2018
7170bd9
Merge remote-tracking branch 'origin/develop' into rigel/unbonding
rigelrozanski Jun 26, 2018
74e0fb8
lowercase error string
rigelrozanski Jun 26, 2018
5329d73
don't expose coinkeeper in staking
rigelrozanski Jun 26, 2018
1a945a2
Merge remote-tracking branch 'origin/develop' into rigel/unbonding
rigelrozanski Jun 26, 2018
ffaefec
remove a few duplicate lines in changelog
rigelrozanski Jun 26, 2018
0012a46
...
rigelrozanski Jun 26, 2018
6f2c29b
chain_id in stake lcd tests
rigelrozanski Jun 26, 2018
637b275
Merge branch 'develop' into rigel/unbonding
cwgoes Jun 27, 2018
4908504
added transient redelegation
rigelrozanski Jun 27, 2018
34e46ac
Merge branch 'rigel/unbonding' of https://github.com/cosmos/cosmos-sd…
rigelrozanski Jun 27, 2018
f499b88
'transient' => 'transitive'
cwgoes Jun 27, 2018
bcace44
Merge branch 'develop' into rigel/unbonding
cwgoes Jun 27, 2018
de77006
Re-add nolint instruction
cwgoes Jun 27, 2018
791ad9c
Fix tiny linter error
cwgoes Jun 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Changelog

## 0.20.0

*TBD*

BREAKING CHANGES
Expand All @@ -13,7 +11,39 @@ FEATURES
* [lcd] Queried TXs now include the tx hash to identify each tx
* [mockapp] CompleteSetup() no longer takes a testing parameter

FIXES
* [gaia] Added self delegation for validators in the genesis creation

## 0.20.0

BREAKING CHANGES
* [cli] rearranged commands under subcommands
* [stake] remove Tick and add EndBlocker
* [stake] introduce concept of unbonding for delegations and validators
* `gaiacli stake unbond` replaced with `gaiacli stake begin-unbonding`
* introduced:
* `gaiacli stake complete-unbonding`
* `gaiacli stake begin-redelegation`
* `gaiacli stake complete-redelegation`

IMPROVEMENTS
* bank module uses go-wire codec instead of 'encoding/json'
* auth module uses go-wire codec instead of 'encoding/json'
* revised use of endblock and beginblock
* [stake] module reorganized to include `types` and `keeper` package
* [stake] keeper always loads the store (instead passing around which doesn't really boost efficiency)
* [stake] edit-validator changes now can use the keyword [do-not-modify] to not modify unspecified `--flag` (aka won't set them to `""` value)
* [types] added common tag constants
* [stake] offload more generic functionality from the handler into the keeper

FIXES
* [cli] fixed cli-bash tests
* [ci] added cli-bash tests
* [basecoin] updated basecoin for stake and slashing
* [docs] fixed references to old cli commands
Copy link
Contributor

Choose a reason for hiding this comment

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

Did that happen in this PR? Some of these changelog entries look unrelated

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 not sure how that got in there, removed the duplicate lines

* [lcd] tests now don't depend on raw json text
* [stake] error strings lower case
* [stake] pool loose tokens now accounts for unbonding and unbonding tokens not associated with any validator
* \#1259 - fix bug where certain tests that could have a nil pointer in defer
* Retry on HTTP request failure in CLI tests, add option to retry tests in Makefile
* Fixed bug where chain ID wasn't passed properly in x/bank REST handler
Expand Down
69 changes: 60 additions & 9 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ func TestValidatorsQuery(t *testing.T) {
assert.True(t, foundVal2, "pk2Bech %v, owner1 %v, owner2 %v", pk2Bech, validators[0].Owner, validators[1].Owner)
}

// XXX Test Redelegation
func TestBonding(t *testing.T) {
name, password, denom := "test", "1234567890", "steak"
addr, seed := CreateAddr(t, "test", password, GetKB(t))
Expand All @@ -383,7 +384,7 @@ func TestBonding(t *testing.T) {
validator1Owner := pks[0].Address()

// create bond TX
resultTx := doBond(t, port, seed, name, password, addr, validator1Owner)
resultTx := doDelegate(t, port, seed, name, password, addr, validator1Owner)
tests.WaitForHeight(resultTx.Height+1, port)

// check if tx was commited
Expand All @@ -404,7 +405,7 @@ func TestBonding(t *testing.T) {
// testing unbonding

// create unbond TX
resultTx = doUnbond(t, port, seed, name, password, addr, validator1Owner)
resultTx = doBeginUnbonding(t, port, seed, name, password, addr, validator1Owner)
tests.WaitForHeight(resultTx.Height+1, port)

// query validator
Expand Down Expand Up @@ -523,7 +524,7 @@ func getDelegation(t *testing.T, port string, delegatorAddr, validatorAddr sdk.A
return bond
}

func doBond(t *testing.T, port, seed, name, password string, delegatorAddr, validatorAddr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) {
func doDelegate(t *testing.T, port, seed, name, password string, delegatorAddr, validatorAddr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) {
// get the account to get the sequence
acc := getAccount(t, port, delegatorAddr)
accnum := acc.GetAccountNumber()
Expand All @@ -539,14 +540,17 @@ func doBond(t *testing.T, port, seed, name, password string, delegatorAddr, vali
"account_number": %d,
"sequence": %d,
"gas": 10000,
"delegate": [
"delegations": [
{
"delegator_addr": "%s",
"validator_addr": "%s",
"bond": { "denom": "%s", "amount": 60 }
}
],
"unbond": []
"begin_unbondings": [],
"complete_unbondings": [],
"begin_redelegates": [],
"complete_redelegates": []
Copy link
Contributor

Choose a reason for hiding this comment

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

chain_id might be needed here if not specified already (can't see entire JSON struct in diff)

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, using viper to receive in the test (which needs to be changed), I think that'll be my next PR, refactor out viper usage, pretty much the same as using global variables

}`, name, password, accnum, sequence, delegatorAddrBech, validatorAddrBech, "steak"))
res, body := Request(t, port, "POST", "/stake/delegations", jsonStr)
require.Equal(t, http.StatusOK, res.StatusCode, body)
Expand All @@ -558,7 +562,9 @@ func doBond(t *testing.T, port, seed, name, password string, delegatorAddr, vali
return results[0]
}

func doUnbond(t *testing.T, port, seed, name, password string, delegatorAddr, validatorAddr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) {
func doBeginUnbonding(t *testing.T, port, seed, name, password string,
delegatorAddr, validatorAddr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) {

// get the account to get the sequence
acc := getAccount(t, port, delegatorAddr)
accnum := acc.GetAccountNumber()
Expand All @@ -574,14 +580,17 @@ func doUnbond(t *testing.T, port, seed, name, password string, delegatorAddr, va
"account_number": %d,
"sequence": %d,
"gas": 10000,
"delegate": [],
"unbond": [
"delegations": [],
"begin_unbondings": [
{
"delegator_addr": "%s",
"validator_addr": "%s",
"shares": "30"
}
]
],
"complete_unbondings": [],
"begin_redelegates": [],
"complete_redelegates": []
Copy link
Contributor

Choose a reason for hiding this comment

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

chain_id might be needed here (can't see entire JSON struct in diff)

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 above

}`, name, password, accnum, sequence, delegatorAddrBech, validatorAddrBech))
res, body := Request(t, port, "POST", "/stake/delegations", jsonStr)
require.Equal(t, http.StatusOK, res.StatusCode, body)
Expand All @@ -593,6 +602,48 @@ func doUnbond(t *testing.T, port, seed, name, password string, delegatorAddr, va
return results[0]
}

func doBeginRedelegation(t *testing.T, port, seed, name, password string,
delegatorAddr, validatorSrcAddr, validatorDstAddr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) {

// get the account to get the sequence
acc := getAccount(t, port, delegatorAddr)
accnum := acc.GetAccountNumber()
sequence := acc.GetSequence()

delegatorAddrBech := sdk.MustBech32ifyAcc(delegatorAddr)
validatorSrcAddrBech := sdk.MustBech32ifyVal(validatorSrcAddr)
validatorDstAddrBech := sdk.MustBech32ifyVal(validatorDstAddr)

// send
jsonStr := []byte(fmt.Sprintf(`{
Copy link
Contributor

Choose a reason for hiding this comment

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

Here might be where you want to pass chain_id, and set ctx.ChainID = body.ChainID in the handler

"name": "%s",
"password": "%s",
"account_number": %d,
"sequence": %d,
"gas": 10000,
"delegations": [],
"begin_unbondings": [],
"complete_unbondings": [],
"begin_redelegates": [
{
"delegator_addr": "%s",
"validator_src_addr": "%s",
"validator_dst_addr": "%s",
"shares": "30"
}
],
"complete_redelegates": []
}`, name, password, accnum, sequence, delegatorAddrBech, validatorSrcAddrBech, validatorDstAddrBech))
res, body := Request(t, port, "POST", "/stake/delegations", jsonStr)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var results []ctypes.ResultBroadcastTxCommit
err := cdc.UnmarshalJSON([]byte(body), &results)
require.Nil(t, err)

return results[0]
}

func getValidators(t *testing.T, port string) []stakerest.StakeValidatorOutput {
// get the account to get the sequence
res, body := Request(t, port, "GET", "/stake/validators", nil)
Expand Down
2 changes: 1 addition & 1 deletion client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.Address) (
config.TxIndex.IndexAllTags = true

logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
logger = log.NewFilter(logger, log.AllowError())
logger = log.NewFilter(logger, log.AllowDebug())
privValidatorFile := config.PrivValidatorFile()
privVal := pvm.LoadOrGenFilePV(privValidatorFile)
privVal.Reset()
Expand Down
6 changes: 3 additions & 3 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (app *GaiaApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci
}

// load the initial stake information
stake.InitGenesis(ctx, app.stakeKeeper, genesisState.StakeData)
app.stakeKeeper.InitGenesis(ctx, genesisState.StakeData)

return abci.ResponseInitChain{}
}
Expand All @@ -170,12 +170,12 @@ func (app *GaiaApp) ExportAppStateAndValidators() (appState json.RawMessage, val

genState := GenesisState{
Accounts: accounts,
StakeData: stake.WriteGenesis(ctx, app.stakeKeeper),
StakeData: app.stakeKeeper.WriteGenesis(ctx),
}
appState, err = wire.MarshalJSONIndent(app.cdc, genState)
if err != nil {
return nil, nil, err
}
validators = stake.WriteValidators(ctx, app.stakeKeeper)
validators = app.stakeKeeper.WriteValidators(ctx)
return appState, validators, nil
}
28 changes: 19 additions & 9 deletions cmd/gaia/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"encoding/json"
"errors"

"github.com/spf13/pflag"
crypto "github.com/tendermint/go-crypto"
tmtypes "github.com/tendermint/tendermint/types"
Expand All @@ -17,8 +18,8 @@ import (

var (
// bonded tokens given to genesis validators/accounts
freeFermionVal = sdk.NewInt(100)
freeFermionsAcc = sdk.NewInt(50)
freeFermionVal = int64(100)
freeFermionsAcc = int64(50)
)

// State to Unmarshal
Expand Down Expand Up @@ -123,7 +124,7 @@ func GaiaAppGenTxNF(cdc *wire.Codec, pk crypto.PubKey, addr sdk.Address, name st

validator = tmtypes.GenesisValidator{
PubKey: pk,
Power: freeFermionVal.Int64(),
Power: freeFermionVal,
}
return
}
Expand Down Expand Up @@ -154,22 +155,31 @@ func GaiaAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (genesisState
accAuth := auth.NewBaseAccountWithAddress(genTx.Address)
accAuth.Coins = sdk.Coins{
{genTx.Name + "Token", sdk.NewInt(1000)},
{"steak", freeFermionsAcc},
{"steak", sdk.NewInt(freeFermionsAcc)},
}
acc := NewGenesisAccount(&accAuth)
genaccs[i] = acc
stakeData.Pool.LooseUnbondedTokens = stakeData.Pool.LooseUnbondedTokens.Add(freeFermionsAcc) // increase the supply
stakeData.Pool.LooseTokens = stakeData.Pool.LooseTokens + freeFermionsAcc // increase the supply

// add the validator
if len(genTx.Name) > 0 {
desc := stake.NewDescription(genTx.Name, "", "", "")
validator := stake.NewValidator(genTx.Address, genTx.PubKey, desc)
validator.PoolShares = stake.NewBondedShares(sdk.NewRatFromInt(freeFermionVal))

// add some new shares to the validator
var issuedDelShares sdk.Rat
validator, stakeData.Pool, issuedDelShares = validator.AddTokensFromDel(stakeData.Pool, freeFermionVal)
stakeData.Validators = append(stakeData.Validators, validator)

// pool logic
stakeData.Pool.BondedTokens = stakeData.Pool.BondedTokens.Add(freeFermionVal)
stakeData.Pool.BondedShares = sdk.NewRatFromInt(stakeData.Pool.BondedTokens)
// create the self delegation from the issuedDelShares
delegation := stake.Delegation{
DelegatorAddr: validator.Owner,
ValidatorAddr: validator.Owner,
Shares: issuedDelShares,
Height: 0,
}

stakeData.Bonds = append(stakeData.Bonds, delegation)
}
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/gaia/cmd/gaiacli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func main() {
stakecmd.GetCmdCreateValidator(cdc),
stakecmd.GetCmdEditValidator(cdc),
stakecmd.GetCmdDelegate(cdc),
stakecmd.GetCmdUnbond(cdc),
stakecmd.GetCmdUnbond("stake", cdc),
stakecmd.GetCmdRedelegate("stake", cdc),
slashingcmd.GetCmdUnrevoke(cdc),
)...)
rootCmd.AddCommand(
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/cmd/gaiadebug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (app *GaiaApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci
}

// load the initial stake information
stake.InitGenesis(ctx, app.stakeKeeper, genesisState.StakeData)
app.stakeKeeper.InitGenesis(ctx, genesisState.StakeData)
return abci.ResponseInitChain{}

}
4 changes: 2 additions & 2 deletions docs/spec/staking/end_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ processProvisions():

provisions = pool.Inflation * (pool.TotalSupply / hrsPerYr)

pool.LooseUnbondedTokens += provisions
feePool += LooseUnbondedTokens
pool.LooseTokens += provisions
feePool += LooseTokens

setPool(pool)

Expand Down
2 changes: 1 addition & 1 deletion docs/spec/staking/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ information, etc.

```golang
type Pool struct {
LooseUnbondedTokens int64 // tokens not associated with any validator
LooseTokens int64 // tokens not associated with any validator
UnbondedTokens int64 // reserve of unbonded tokens held with validators
UnbondingTokens int64 // tokens moving from bonded to unbonded pool
BondedTokens int64 // reserve of bonded tokens
Expand Down
4 changes: 2 additions & 2 deletions examples/basecoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (app *BasecoinApp) initChainer(ctx sdk.Context, req abci.RequestInitChain)
}

// load the initial stake information
stake.InitGenesis(ctx, app.stakeKeeper, genesisState.StakeData)
app.stakeKeeper.InitGenesis(ctx, genesisState.StakeData)

return abci.ResponseInitChain{}
}
Expand Down Expand Up @@ -179,6 +179,6 @@ func (app *BasecoinApp) ExportAppStateAndValidators() (appState json.RawMessage,
if err != nil {
return nil, nil, err
}
validators = stake.WriteValidators(ctx, app.stakeKeeper)
validators = app.stakeKeeper.WriteValidators(ctx)
return appState, validators, err
}
6 changes: 5 additions & 1 deletion examples/basecoin/cmd/basecli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func main() {
// add query/post commands (custom to binary)
rootCmd.AddCommand(
client.GetCommands(
stakecmd.GetCmdQueryValidator("stake", cdc),
stakecmd.GetCmdQueryValidators("stake", cdc),
stakecmd.GetCmdQueryDelegation("stake", cdc),
stakecmd.GetCmdQueryDelegations("stake", cdc),
authcmd.GetAccountCmd("acc", cdc, types.GetAccountDecoder(cdc)),
)...)

Expand All @@ -62,7 +66,7 @@ func main() {
stakecmd.GetCmdCreateValidator(cdc),
stakecmd.GetCmdEditValidator(cdc),
stakecmd.GetCmdDelegate(cdc),
stakecmd.GetCmdUnbond(cdc),
stakecmd.GetCmdUnbond("stake", cdc),
)...)

// add proxy, version and key info
Expand Down
2 changes: 2 additions & 0 deletions types/rational.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ func (r Rat) Denom() int64 { return r.Rat.Denom().Int64() } // Denom - ret
func (r Rat) IsZero() bool { return r.Num() == 0 } // IsZero - Is the Rat equal to zero
func (r Rat) Equal(r2 Rat) bool { return (&(r.Rat)).Cmp(&(r2.Rat)) == 0 }
func (r Rat) GT(r2 Rat) bool { return (&(r.Rat)).Cmp(&(r2.Rat)) == 1 } // greater than
func (r Rat) GTE(r2 Rat) bool { return !r.LT(r2) } // greater than or equal
func (r Rat) LT(r2 Rat) bool { return (&(r.Rat)).Cmp(&(r2.Rat)) == -1 } // less than
func (r Rat) LTE(r2 Rat) bool { return !r.GT(r2) } // less than or equal
func (r Rat) Mul(r2 Rat) Rat { return Rat{*new(big.Rat).Mul(&(r.Rat), &(r2.Rat))} } // Mul - multiplication
func (r Rat) Quo(r2 Rat) Rat { return Rat{*new(big.Rat).Quo(&(r.Rat), &(r2.Rat))} } // Quo - quotient
func (r Rat) Add(r2 Rat) Rat { return Rat{*new(big.Rat).Add(&(r.Rat), &(r2.Rat))} } // Add - addition
Expand Down
11 changes: 8 additions & 3 deletions types/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ type ValidatorSet interface {
IterateValidatorsBonded(Context,
func(index int64, validator Validator) (stop bool))

Validator(Context, Address) Validator // get a particular validator by owner address
TotalPower(Context) Rat // total power of the validator set
Validator(Context, Address) Validator // get a particular validator by owner address
TotalPower(Context) Rat // total power of the validator set
}

// ValidatorSet that can slash and revoke (affect the validator set)
type SlashValidatorSet interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Interfaces are clean, but I don't think they accomplish the object-capability guarantees we want; anyone receiving a ValidatorSet can cast it to a SlashValidatorSet if the underlying type fulfills the latter interface.

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 just adding everything to validator set for now

ValidatorSet
Slash(Context, crypto.PubKey, int64, Rat) // slash the validator and delegators of the validator, specifying offence height & slash fraction
Revoke(Context, crypto.PubKey) // revoke a validator
Unrevoke(Context, crypto.PubKey) // unrevoke a validator
Expand All @@ -79,6 +84,6 @@ type DelegationSet interface {

// iterate through all delegations from one delegator by validator-address,
// execute func for each validator
IterateDelegators(Context, delegator Address,
IterateDelegators(context Context, delegator Address,
fn func(index int64, delegation Delegation) (stop bool))
}
Loading