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

Slashing v2 #1278

Merged
merged 147 commits into from
Jun 30, 2018
Merged
Show file tree
Hide file tree
Changes from 144 commits
Commits
Show all changes
147 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
bdc437e
Tweak constants for testnet, tag address correctly
cwgoes Jun 16, 2018
2f42a2b
Unbond and jail validators when they double-sign
cwgoes Jun 22, 2018
72d36d1
Pass power through x/slashing/tick & ValidatorSet.Slash
cwgoes Jun 22, 2018
182d0cb
SlashingKeeper DRY
cwgoes Jun 22, 2018
683b64a
Use power at time of equivocation
cwgoes Jun 22, 2018
0d38a72
Updated slash function in progress
cwgoes Jun 23, 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
c7433c9
Add iterator functions over redelegations & unbonding delegations by …
cwgoes Jun 25, 2018
f5dbcfd
Merge branch 'rigel/unbonding' into cwgoes/slashing-version-two
cwgoes Jun 25, 2018
de8b5b1
Iterate through unbonding delegations & redelegations in keeper.Slash()
cwgoes Jun 25, 2018
3e18286
Initialize unbonding delegation & redelegation properly
cwgoes Jun 25, 2018
40b9faf
stake lcd fix
rigelrozanski Jun 25, 2018
a500931
...
rigelrozanski Jun 25, 2018
c916f21
...
rigelrozanski Jun 25, 2018
587e9fd
Update staking testcase, update slashing docs
cwgoes Jun 25, 2018
82f3529
Merge branch 'develop' into rigel/unbonding
ebuchman Jun 25, 2018
2a34342
Reorder slashing end block docs, s/equivocation/infraction/g
cwgoes 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
a0c9fed
Changelog & slashing REST handler
cwgoes Jun 25, 2018
86439ee
Add signing info query function
cwgoes Jun 25, 2018
a029cb9
...
rigelrozanski Jun 25, 2018
9cddb06
fix lint, update lint make command for spelling
rigelrozanski Jun 25, 2018
41bcf70
Separate out keeper.Slash()
cwgoes Jun 25, 2018
54b6ae5
Update slashing testcases
cwgoes Jun 26, 2018
e56c08b
Add testcases for revoke/unrevoke
cwgoes Jun 26, 2018
2659120
Remove hard-coded parameters from testcases
cwgoes Jun 26, 2018
3841a7a
Remove constant dependence from tick_test.go
cwgoes Jun 26, 2018
03273a7
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes Jun 26, 2018
c17b8e6
Slashing unit tests in progress
cwgoes Jun 26, 2018
dd3bdcb
Tweak testcases to avoid rounding issues
cwgoes Jun 26, 2018
48d1107
Minor optimizations; comments
cwgoes Jun 26, 2018
d93502d
Merge branch 'rigel/unbonding' into cwgoes/slashing-version-two
cwgoes Jun 26, 2018
c565dab
Testcases; minor bugfixes
cwgoes Jun 26, 2018
303fbe5
Add unit test for slashing with both an unbonding delegation & a rede…
cwgoes Jun 26, 2018
7170bd9
Merge remote-tracking branch 'origin/develop' into rigel/unbonding
rigelrozanski Jun 26, 2018
b7ece9a
Merge branch 'rigel/unbonding' into cwgoes/slashing-version-two
cwgoes Jun 26, 2018
74e0fb8
lowercase error string
rigelrozanski Jun 26, 2018
5329d73
don't expose coinkeeper in staking
rigelrozanski Jun 26, 2018
9be314e
Merge branch 'rigel/unbonding' into cwgoes/slashing-version-two
cwgoes 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
0663984
Fix merge errors
cwgoes Jun 26, 2018
70605a2
Merge branch 'rigel/unbonding' into cwgoes/slashing-version-two
cwgoes Jun 26, 2018
6f2c29b
chain_id in stake lcd tests
rigelrozanski Jun 26, 2018
a6c0381
Pool account in progress
cwgoes 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
44378a1
Clarify comment
cwgoes Jun 27, 2018
a901ed6
Merge branch 'rigel/unbonding' into cwgoes/slashing-version-two
cwgoes Jun 27, 2018
5449296
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes Jun 27, 2018
12fc6a9
Remove accidental changelog entry from merge
cwgoes Jun 27, 2018
08597c9
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes Jun 27, 2018
cff38d8
Add LCD test for signing info REST handler
cwgoes Jun 27, 2018
1d97ed6
Update democoin mock validator set
cwgoes Jun 27, 2018
f178308
Address some PR comments
cwgoes Jun 28, 2018
1e75912
Add efficiency optimizations
cwgoes Jun 28, 2018
a133bc5
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes Jun 28, 2018
8895552
Address more PR comments
cwgoes Jun 28, 2018
97eed84
Add more explanatory comments
cwgoes Jun 28, 2018
3d3189c
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes Jun 28, 2018
220d03f
Overslashing / recursive slashing tests for unbonding delegations
cwgoes Jun 28, 2018
7ab62b4
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes Jun 29, 2018
554a72b
More unit tests
cwgoes Jun 29, 2018
3c25861
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes Jun 29, 2018
99fec69
Add additional testcase clauses
cwgoes Jun 29, 2018
e43bbef
Update slashing parameters
cwgoes Jun 29, 2018
c76a8e1
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes Jun 29, 2018
cb85459
Linter fixes
cwgoes Jun 29, 2018
4edb773
Add slashing test to x/stake handler
cwgoes Jun 29, 2018
78ac9ae
Clarify a few comments
cwgoes Jun 29, 2018
b00a0a1
Unify comment format
cwgoes Jun 29, 2018
f8dd859
Remove redundant sdk.Coin{}
cwgoes Jun 29, 2018
c1987da
Update changelog
cwgoes Jun 30, 2018
9bc99f1
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes Jun 30, 2018
30d9d90
Change CircleCI config slightly
cwgoes Jun 30, 2018
aeea789
Merge branch 'develop' into cwgoes/slashing-version-two
cwgoes Jun 30, 2018
9ff81a6
Change jail durations to five minutes
cwgoes Jun 30, 2018
5a479e0
Address PR comments
cwgoes Jun 30, 2018
e46e687
Add additional comment
cwgoes Jun 30, 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
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
test_cover:
<<: *defaults
parallelism: 1
parallelism: 2
steps:
- attach_workspace:
at: /tmp/workspace
Expand All @@ -126,6 +126,7 @@ jobs:

upload_coverage:
<<: *defaults
parallelism: 1
steps:
- attach_workspace:
at: /tmp/workspace
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ BREAKING CHANGES
* `gaiacli stake complete-unbonding`
* `gaiacli stake begin-redelegation`
* `gaiacli stake complete-redelegation`
* [slashing] update slashing for unbonding period
* Slash according to power at time of infraction instead of power at
time of discovery
* Iterate through unbonding delegations & redelegations which contributed
to an infraction, slash them proportional to their stake at the time
* Add REST endpoint to unrevoke a validator previously revoked for downtime
* Add REST endpoint to retrieve liveness signing information for a validator

FEATURES
* [gaiacli] You can now attach a simple text-only memo to any transaction, with the `--memo` flag
Expand Down
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/stake"
stakerest "github.com/cosmos/cosmos-sdk/x/stake/client/rest"
)
Expand Down Expand Up @@ -521,6 +522,19 @@ func TestVote(t *testing.T) {
require.Equal(t, gov.VoteOptionToString(gov.OptionYes), vote.Option)
}

func TestUnrevoke(t *testing.T) {
_, password := "test", "1234567890"
addr, _ := CreateAddr(t, "test", password, GetKB(t))
cleanup, pks, port := InitializeTestLCD(t, 1, []sdk.Address{addr})
defer cleanup()

signingInfo := getSigningInfo(t, port, pks[0].Address())
tests.WaitForHeight(4, port)
Copy link
Contributor

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

require.Equal(t, true, signingInfo.IndexOffset > 0)
require.Equal(t, int64(0), signingInfo.JailedUntil)
require.Equal(t, true, signingInfo.SignedBlocksCounter > 0)
}

func TestProposalsQuery(t *testing.T) {
name, password1 := "test", "1234567890"
name2, password2 := "test2", "1234567890"
Expand Down Expand Up @@ -679,6 +693,16 @@ func doIBCTransfer(t *testing.T, port, seed, name, password string, addr sdk.Add
return resultTx
}

func getSigningInfo(t *testing.T, port string, validatorAddr sdk.Address) slashing.ValidatorSigningInfo {
validatorAddrBech := sdk.MustBech32ifyVal(validatorAddr)
res, body := Request(t, port, "GET", "/slashing/signing_info/"+validatorAddrBech, nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
var signingInfo slashing.ValidatorSigningInfo
err := cdc.UnmarshalJSON([]byte(body), &signingInfo)
require.Nil(t, err)
return signingInfo
}

func getDelegation(t *testing.T, port string, delegatorAddr, validatorAddr sdk.Address) stake.Delegation {

delegatorAddrBech := sdk.MustBech32ifyAcc(delegatorAddr)
Expand Down
2 changes: 2 additions & 0 deletions client/lcd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
bank "github.com/cosmos/cosmos-sdk/x/bank/client/rest"
gov "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
ibc "github.com/cosmos/cosmos-sdk/x/ibc/client/rest"
slashing "github.com/cosmos/cosmos-sdk/x/slashing/client/rest"
stake "github.com/cosmos/cosmos-sdk/x/stake/client/rest"
)

Expand Down Expand Up @@ -84,6 +85,7 @@ func createHandler(cdc *wire.Codec) http.Handler {
bank.RegisterRoutes(ctx, r, cdc, kb)
ibc.RegisterRoutes(ctx, r, cdc, kb)
stake.RegisterRoutes(ctx, r, cdc, kb)
slashing.RegisterRoutes(ctx, r, cdc, kb)
gov.RegisterRoutes(ctx, r, cdc)
return r
}
51 changes: 32 additions & 19 deletions docs/spec/slashing/end_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,28 @@ For some `evidence` to be valid, it must satisfy:
where `evidence.Timestamp` is the timestamp in the block at height
`evidence.Height` and `block.Timestamp` is the current block timestamp.

If valid evidence is included in a block, the validator's stake is reduced by `SLASH_PROPORTION` of
what their stake was when the equivocation occurred (rather than when the evidence was discovered):
If valid evidence is included in a block, the validator's stake is reduced by `SLASH_PROPORTION` of
what their stake was when the infraction occurred (rather than when the evidence was discovered).
We want to "follow the stake": the stake which contributed to the infraction should be
slashed, even if it has since been redelegated or started unbonding.

```
curVal := validator
oldVal := loadValidator(evidence.Height, evidence.Address)

slashAmount := SLASH_PROPORTION * oldVal.Shares
We first need to loop through the unbondings and redelegations from the slashed validator
and track how much stake has since moved:

curVal.Shares = max(0, curVal.Shares - slashAmount)
```
slashAmountUnbondings := 0
slashAmountRedelegations := 0

This ensures that offending validators are punished the same amount whether they
act as a single validator with X stake or as N validators with collectively X
stake.

We also need to loop through the unbondings and redelegations to slash them as
well:

```
unbondings := getUnbondings(validator.Address)
for unbond in unbondings {
if was not bonded before evidence.Height {

if was not bonded before evidence.Height or started unbonding before unbonding period ago {
continue
}
unbond.InitialTokens

burn := unbond.InitialTokens * SLASH_PROPORTION
slashAmountUnbondings += burn

unbond.Tokens = max(0, unbond.Tokens - burn)
}

Expand All @@ -51,17 +46,35 @@ for unbond in unbondings {
redels := getRedelegationsBySource(validator.Address)
for redel in redels {

if was not bonded before evidence.Height {
if was not bonded before evidence.Height or started redelegating before unbonding period ago {
continue
}

burn := redel.InitialTokens * SLASH_PROPORTION
slashAmountRedelegations += burn

amount := unbondFromValidator(redel.Destination, burn)
destroy(amount)
}
```

We then slash the validator:

```
curVal := validator
oldVal := loadValidator(evidence.Height, evidence.Address)

slashAmount := SLASH_PROPORTION * oldVal.Shares
slashAmount -= slashAmountUnbondings
slashAmount -= slashAmountRedelegations

curVal.Shares = max(0, curVal.Shares - slashAmount)
```

This ensures that offending validators are punished the same amount whether they
act as a single validator with X stake or as N validators with collectively X
stake.

## Automatic Unbonding

At the beginning of each block, we update the signing info for each validator and check if they should be automatically unbonded:
Expand Down
7 changes: 6 additions & 1 deletion examples/democoin/mock/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func (v Validator) GetDelegatorShares() sdk.Rat {
return sdk.ZeroRat()
}

// Implements sdk.Validator
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this sdk.Validator, or x/stake/types.Validator?`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is sdk.Validator (types/stake.go), to which GetRevoked() was added.

func (v Validator) GetRevoked() bool {
return false
}

// Implements sdk.Validator
func (v Validator) GetBondHeight() int64 {
return 0
Expand Down Expand Up @@ -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")
}

Expand Down
8 changes: 5 additions & 3 deletions types/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func BondStatusToString(b BondStatus) string {

// validator for a delegated proof of stake system
type Validator interface {
GetRevoked() bool // whether the validator is revoked
GetMoniker() string // moniker of the validator
GetStatus() BondStatus // status of the validator
GetOwner() Address // owner address to receive/return validators coins
Expand Down Expand Up @@ -62,9 +63,10 @@ type ValidatorSet interface {
Validator(Context, Address) Validator // get a particular validator by owner address
TotalPower(Context) Rat // total power of the validator set

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
// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
Slash(Context, crypto.PubKey, int64, int64, Rat)
Revoke(Context, crypto.PubKey) // revoke a validator
Unrevoke(Context, crypto.PubKey) // unrevoke a validator
}

//_______________________________________________________________________________
Expand Down
62 changes: 62 additions & 0 deletions x/slashing/client/rest/query.go
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)
}
}
15 changes: 15 additions & 0 deletions x/slashing/client/rest/rest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package rest

import (
"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/crypto/keys"
"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)
}
Loading