-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Slashing v2 #1278
Merged
Merged
Slashing v2 #1278
Changes from 129 commits
Commits
Show all changes
147 commits
Select commit
Hold shift + click to select a range
3d0e7ff
stake/fees spec updates
rigelrozanski 43a0ed9
staking overview.md revisions, moving files
rigelrozanski a49f9cb
docs reorganization
rigelrozanski f972cab
staking spec state revisions
rigelrozanski 752f084
transaction stake updates
rigelrozanski 5a77d7d
complete staking spec update
rigelrozanski 26681a8
WIP adding unbonding/redelegation commands
rigelrozanski 8e677e8
added msg types for unbonding, redelegation
rigelrozanski 43429ef
stake sub-package reorg
rigelrozanski 482a3c5
...
rigelrozanski fd1eb5f
working stake reorg
rigelrozanski 63a0dcc
...
rigelrozanski 7eaa715
...
rigelrozanski 3fac834
modify lcd tests to not use hardcoded json strings
rigelrozanski d69d179
add description update
rigelrozanski 0efb0a4
index keys
rigelrozanski 2153e0d
...
rigelrozanski f6b9893
...
rigelrozanski e460c06
key managment for unbonding redelegation complete
rigelrozanski 8639f91
...
rigelrozanski 9ee70ea
update stake errors
rigelrozanski bd41980
...
rigelrozanski 40ad0a5
completed handleMsgCompleteUnbonding fn
rigelrozanski 4be5e41
updated to use begin/complete unbonding/redelegation
rigelrozanski 03c6804
...
rigelrozanski 98dad7d
fix token shares bug
rigelrozanski 4601bd5
develop docs into unbonding
rigelrozanski fc6ee07
...
rigelrozanski ffc8cc4
...
rigelrozanski 6a5bc2d
Merge remote-tracking branch 'origin/develop' into rigel/unbonding
rigelrozanski 436f32d
got non-tests compiling after merge develop
rigelrozanski 37190aa
working fixing tests
rigelrozanski ed7b90e
PrivlegedKeeper -> PrivilegedKeeper
rigelrozanski af4fd6e
tests compile
rigelrozanski 1d7d4d4
Merge remote-tracking branch 'origin/develop' into rigel/unbonding
rigelrozanski d427af7
fix some tests
rigelrozanski a0ac5e9
fixing tests
rigelrozanski b72a219
Merge branch 'develop' into rigel/unbonding
rigelrozanski 8860fa3
remove PrivilegedKeeper
rigelrozanski 24395fd
...
rigelrozanski 258834f
...
rigelrozanski 9ce6759
get unbonding bug
rigelrozanski 1ae48da
only rpc sig verification failed tests now
rigelrozanski bc2e0d7
Merge branch 'develop' into rigel/unbonding
rigelrozanski ad73cd1
...
rigelrozanski 60158d5
move percent unbonding/redelegation to the CLI and out of handler logic
rigelrozanski b1cb149
remove min unbonding height
rigelrozanski 3cd8478
add lcd txs
rigelrozanski a3e04ce
add pool sanity checks, fix a buncha tests
rigelrozanski 782afbb
fix ante. set lcd log to debug (#1322)
ebuchman ad9da64
Merge branch 'develop' into rigel/unbonding
rigelrozanski 071d47b
redelegation tests, adding query functionality for bonds
rigelrozanski 5dc163c
add self-delegations at genesis ref #1165
rigelrozanski bdc437e
Tweak constants for testnet, tag address correctly
cwgoes 2f42a2b
Unbond and jail validators when they double-sign
cwgoes 72d36d1
Pass power through x/slashing/tick & ValidatorSet.Slash
cwgoes 182d0cb
SlashingKeeper DRY
cwgoes 683b64a
Use power at time of equivocation
cwgoes 0d38a72
Updated slash function in progress
cwgoes 6e2c66c
PR comments (mostly) addressed
rigelrozanski f004c6c
cleanup, added Query LCD functionality
rigelrozanski ceb8856
test cleanup/fixes
rigelrozanski 9f99a17
Merge remote-tracking branch 'origin/develop' into rigel/unbonding
rigelrozanski 32b75c5
fix governance test
rigelrozanski 85c3639
Merge branch 'develop' into rigel/unbonding
rigelrozanski 177ab4c
SlashValidatorSet -> ValidatorSet
rigelrozanski 3f4e528
changelog
rigelrozanski c7433c9
Add iterator functions over redelegations & unbonding delegations by …
cwgoes f5dbcfd
Merge branch 'rigel/unbonding' into cwgoes/slashing-version-two
cwgoes de8b5b1
Iterate through unbonding delegations & redelegations in keeper.Slash()
cwgoes 3e18286
Initialize unbonding delegation & redelegation properly
cwgoes 40b9faf
stake lcd fix
rigelrozanski a500931
...
rigelrozanski c916f21
...
rigelrozanski 587e9fd
Update staking testcase, update slashing docs
cwgoes 82f3529
Merge branch 'develop' into rigel/unbonding
ebuchman 2a34342
Reorder slashing end block docs, s/equivocation/infraction/g
cwgoes d5ab2f3
x/auth: fix chainID in ante
ebuchman b8571b6
Merge branch 'rigel/unbonding' of https://github.com/cosmos/cosmos-sd…
rigelrozanski 2511ef1
fix lcd test
rigelrozanski a0c9fed
Changelog & slashing REST handler
cwgoes 86439ee
Add signing info query function
cwgoes a029cb9
...
rigelrozanski 9cddb06
fix lint, update lint make command for spelling
rigelrozanski 41bcf70
Separate out keeper.Slash()
cwgoes 54b6ae5
Update slashing testcases
cwgoes e56c08b
Add testcases for revoke/unrevoke
cwgoes 2659120
Remove hard-coded parameters from testcases
cwgoes 3841a7a
Remove constant dependence from tick_test.go
cwgoes 03273a7
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes c17b8e6
Slashing unit tests in progress
cwgoes dd3bdcb
Tweak testcases to avoid rounding issues
cwgoes 48d1107
Minor optimizations; comments
cwgoes d93502d
Merge branch 'rigel/unbonding' into cwgoes/slashing-version-two
cwgoes c565dab
Testcases; minor bugfixes
cwgoes 303fbe5
Add unit test for slashing with both an unbonding delegation & a rede…
cwgoes 7170bd9
Merge remote-tracking branch 'origin/develop' into rigel/unbonding
rigelrozanski b7ece9a
Merge branch 'rigel/unbonding' into cwgoes/slashing-version-two
cwgoes 74e0fb8
lowercase error string
rigelrozanski 5329d73
don't expose coinkeeper in staking
rigelrozanski 9be314e
Merge branch 'rigel/unbonding' into cwgoes/slashing-version-two
cwgoes 1a945a2
Merge remote-tracking branch 'origin/develop' into rigel/unbonding
rigelrozanski ffaefec
remove a few duplicate lines in changelog
rigelrozanski 0012a46
...
rigelrozanski 0663984
Fix merge errors
cwgoes 70605a2
Merge branch 'rigel/unbonding' into cwgoes/slashing-version-two
cwgoes 6f2c29b
chain_id in stake lcd tests
rigelrozanski a6c0381
Pool account in progress
cwgoes 637b275
Merge branch 'develop' into rigel/unbonding
cwgoes 4908504
added transient redelegation
rigelrozanski 34e46ac
Merge branch 'rigel/unbonding' of https://github.com/cosmos/cosmos-sd…
rigelrozanski f499b88
'transient' => 'transitive'
cwgoes bcace44
Merge branch 'develop' into rigel/unbonding
cwgoes de77006
Re-add nolint instruction
cwgoes 791ad9c
Fix tiny linter error
cwgoes 44378a1
Clarify comment
cwgoes a901ed6
Merge branch 'rigel/unbonding' into cwgoes/slashing-version-two
cwgoes 5449296
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes 12fc6a9
Remove accidental changelog entry from merge
cwgoes 08597c9
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes cff38d8
Add LCD test for signing info REST handler
cwgoes 1d97ed6
Update democoin mock validator set
cwgoes f178308
Address some PR comments
cwgoes 1e75912
Add efficiency optimizations
cwgoes a133bc5
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes 8895552
Address more PR comments
cwgoes 97eed84
Add more explanatory comments
cwgoes 3d3189c
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes 220d03f
Overslashing / recursive slashing tests for unbonding delegations
cwgoes 7ab62b4
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes 554a72b
More unit tests
cwgoes 3c25861
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes 99fec69
Add additional testcase clauses
cwgoes e43bbef
Update slashing parameters
cwgoes c76a8e1
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes cb85459
Linter fixes
cwgoes 4edb773
Add slashing test to x/stake handler
cwgoes 78ac9ae
Clarify a few comments
cwgoes b00a0a1
Unify comment format
cwgoes f8dd859
Remove redundant sdk.Coin{}
cwgoes c1987da
Update changelog
cwgoes 9bc99f1
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes 30d9d90
Change CircleCI config slightly
cwgoes aeea789
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes 9ff81a6
Change jail durations to five minutes
cwgoes 5a479e0
Address PR comments
cwgoes e46e687
Add additional comment
cwgoes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,11 @@ func (v Validator) GetDelegatorShares() sdk.Rat { | |
return sdk.ZeroRat() | ||
} | ||
|
||
// Implements sdk.Validator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this sdk.Validator, or There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is |
||
func (v Validator) GetRevoked() bool { | ||
return false | ||
} | ||
|
||
// Implements sdk.Validator | ||
func (v Validator) GetBondHeight() int64 { | ||
return 0 | ||
|
@@ -107,7 +112,7 @@ func (vs *ValidatorSet) RemoveValidator(addr sdk.Address) { | |
} | ||
|
||
// Implements sdk.ValidatorSet | ||
func (vs *ValidatorSet) Slash(ctx sdk.Context, pubkey crypto.PubKey, height int64, amt sdk.Rat) { | ||
func (vs *ValidatorSet) Slash(ctx sdk.Context, pubkey crypto.PubKey, height int64, power int64, amt sdk.Rat) { | ||
panic("not implemented") | ||
} | ||
|
||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package rest | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/context" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/wire" | ||
"github.com/cosmos/cosmos-sdk/x/slashing" | ||
) | ||
|
||
func registerQueryRoutes(ctx context.CoreContext, r *mux.Router, cdc *wire.Codec) { | ||
r.HandleFunc( | ||
"/slashing/signing_info/{validator}", | ||
signingInfoHandlerFn(ctx, "slashing", cdc), | ||
).Methods("GET") | ||
} | ||
|
||
// http request handler to query signing info | ||
func signingInfoHandlerFn(ctx context.CoreContext, storeName string, cdc *wire.Codec) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
|
||
// read parameters | ||
vars := mux.Vars(r) | ||
bech32validator := vars["validator"] | ||
|
||
validatorAddr, err := sdk.GetValAddressBech32(bech32validator) | ||
if err != nil { | ||
w.WriteHeader(http.StatusBadRequest) | ||
w.Write([]byte(err.Error())) | ||
return | ||
} | ||
|
||
key := slashing.GetValidatorSigningInfoKey(validatorAddr) | ||
res, err := ctx.QueryStore(key, storeName) | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
w.Write([]byte(fmt.Sprintf("couldn't query signing info. Error: %s", err.Error()))) | ||
return | ||
} | ||
|
||
var signingInfo slashing.ValidatorSigningInfo | ||
err = cdc.UnmarshalBinary(res, &signingInfo) | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
w.Write([]byte(fmt.Sprintf("couldn't decode signing info. Error: %s", err.Error()))) | ||
return | ||
} | ||
|
||
output, err := cdc.MarshalJSON(signingInfo) | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
w.Write([]byte(err.Error())) | ||
return | ||
} | ||
|
||
w.Write(output) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package rest | ||
|
||
import ( | ||
"github.com/gorilla/mux" | ||
"github.com/tendermint/go-crypto/keys" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/context" | ||
"github.com/cosmos/cosmos-sdk/wire" | ||
) | ||
|
||
// RegisterRoutes registers staking-related REST handlers to a router | ||
func RegisterRoutes(ctx context.CoreContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) { | ||
registerQueryRoutes(ctx, r, cdc) | ||
registerTxRoutes(ctx, r, cdc, kb) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package rest | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/tendermint/go-crypto/keys" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/context" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/wire" | ||
"github.com/cosmos/cosmos-sdk/x/slashing" | ||
) | ||
|
||
func registerTxRoutes(ctx context.CoreContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) { | ||
r.HandleFunc( | ||
"/slashing/unrevoke", | ||
unrevokeRequestHandlerFn(cdc, kb, ctx), | ||
).Methods("POST") | ||
} | ||
|
||
// Unrevoke TX body | ||
type UnrevokeBody struct { | ||
LocalAccountName string `json:"name"` | ||
Password string `json:"password"` | ||
ChainID string `json:"chain_id"` | ||
AccountNumber int64 `json:"account_number"` | ||
Sequence int64 `json:"sequence"` | ||
Gas int64 `json:"gas"` | ||
ValidatorAddr string `json:"validator_addr"` | ||
} | ||
|
||
func unrevokeRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx context.CoreContext) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
var m UnrevokeBody | ||
body, err := ioutil.ReadAll(r.Body) | ||
if err != nil { | ||
w.WriteHeader(http.StatusBadRequest) | ||
w.Write([]byte(err.Error())) | ||
return | ||
} | ||
err = json.Unmarshal(body, &m) | ||
if err != nil { | ||
w.WriteHeader(http.StatusBadRequest) | ||
w.Write([]byte(err.Error())) | ||
return | ||
} | ||
|
||
info, err := kb.Get(m.LocalAccountName) | ||
if err != nil { | ||
w.WriteHeader(http.StatusUnauthorized) | ||
w.Write([]byte(err.Error())) | ||
return | ||
} | ||
|
||
validatorAddr, err := sdk.GetAccAddressBech32(m.ValidatorAddr) | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
w.Write([]byte(fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))) | ||
return | ||
} | ||
|
||
if !bytes.Equal(info.Address(), validatorAddr) { | ||
w.WriteHeader(http.StatusUnauthorized) | ||
w.Write([]byte("Must use own validator address")) | ||
return | ||
} | ||
|
||
ctx = ctx.WithGas(m.Gas) | ||
ctx = ctx.WithChainID(m.ChainID) | ||
ctx = ctx.WithAccountNumber(m.AccountNumber) | ||
ctx = ctx.WithSequence(m.Sequence) | ||
|
||
msg := slashing.NewMsgUnrevoke(validatorAddr) | ||
|
||
txBytes, err := ctx.SignAndBuild(m.LocalAccountName, m.Password, []sdk.Msg{msg}, cdc) | ||
if err != nil { | ||
w.WriteHeader(http.StatusUnauthorized) | ||
w.Write([]byte(err.Error())) | ||
return | ||
} | ||
|
||
res, err := ctx.BroadcastTx(txBytes) | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
w.Write([]byte(err.Error())) | ||
return | ||
} | ||
|
||
output, err := json.MarshalIndent(res, "", " ") | ||
if err != nil { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
w.Write([]byte(err.Error())) | ||
return | ||
} | ||
|
||
w.Write(output) | ||
} | ||
} |
This file contains 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
Oops, something went wrong.
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.
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.
Would be better to use
tests.WaitForNextNBlocksTM