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

runtime node slashing (ADR 0005) #3640

Merged
merged 3 commits into from
Feb 10, 2021
Merged

Conversation

ptrus
Copy link
Member

@ptrus ptrus commented Jan 19, 2021

  • roothash/api: add evidence types
  • tendermint/roothash: add tx endpoint for submitting evidence of equivocation
  • roothash: add tests for the new evidence submission
  • roothash/pool: slash non-majority for SlashRuntimeIncorrectResults
  • e2e tests
  • configurable amount of rewards should be awarded to nodes contributing evidence (or resolving discrepancies), add per runtime staking parameters
  • rewards to nodes should be escrowed (currently these are awarded into the general balance)

@ptrus ptrus force-pushed the ptrus/feature/runtime-slashing branch from f2d964e to 0ab8e88 Compare January 19, 2021 16:39
@ptrus ptrus force-pushed the ptrus/feature/runtime-slashing branch 3 times, most recently from 71c815f to a37dc25 Compare January 20, 2021 08:37
@codecov
Copy link

codecov bot commented Jan 20, 2021

Codecov Report

Merging #3640 (253376f) into master (9cdfa91) will increase coverage by 0.10%.
The diff coverage is 75.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3640      +/-   ##
==========================================
+ Coverage   66.66%   66.77%   +0.10%     
==========================================
  Files         393      394       +1     
  Lines       38373    38821     +448     
==========================================
+ Hits        25581    25922     +341     
- Misses       9119     9157      +38     
- Partials     3673     3742      +69     
Impacted Files Coverage Δ
go/registry/api/runtime.go 44.72% <0.00%> (-1.14%) ⬇️
go/roothash/api/commitment/pool.go 71.02% <ø> (ø)
go/oasis-node/cmd/registry/runtime/runtime.go 58.49% <57.14%> (-0.07%) ⬇️
...o/consensus/tendermint/apps/staking/state/state.go 60.98% <58.33%> (+2.57%) ⬆️
go/consensus/tendermint/apps/roothash/slashing.go 62.26% <62.26%> (ø)
go/roothash/api/api.go 76.25% <79.31%> (+8.06%) ⬆️
...consensus/tendermint/apps/roothash/transactions.go 69.52% <81.48%> (+14.48%) ⬆️
go/consensus/tendermint/apps/roothash/roothash.go 75.25% <84.00%> (+1.26%) ⬆️
.../consensus/tendermint/apps/roothash/state/state.go 74.48% <88.88%> (+0.73%) ⬆️
go/roothash/tests/tester.go 88.70% <90.00%> (+0.18%) ⬆️
... and 38 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9cdfa91...253376f. Read the comment docs.

@ptrus ptrus force-pushed the ptrus/feature/runtime-slashing branch 4 times, most recently from 8f89667 to 030b662 Compare January 21, 2021 10:10
@ptrus ptrus force-pushed the ptrus/feature/runtime-slashing branch 10 times, most recently from 849b34f to 4fde045 Compare January 22, 2021 14:29
go/consensus/tendermint/apps/roothash/roothash.go Outdated Show resolved Hide resolved
go/consensus/tendermint/apps/roothash/roothash.go Outdated Show resolved Hide resolved
go/consensus/tendermint/apps/roothash/roothash.go Outdated Show resolved Hide resolved
go/consensus/tendermint/apps/roothash/slashing.go Outdated Show resolved Hide resolved
go/consensus/tendermint/apps/roothash/slashing.go Outdated Show resolved Hide resolved
go/consensus/tendermint/apps/roothash/slashing.go Outdated Show resolved Hide resolved
go/consensus/tendermint/apps/roothash/state/state.go Outdated Show resolved Hide resolved
go/consensus/tendermint/apps/roothash/transactions.go Outdated Show resolved Hide resolved
go/staking/api/slashing.go Outdated Show resolved Hide resolved
@ptrus ptrus force-pushed the ptrus/feature/runtime-slashing branch 2 times, most recently from dd78a6f to 879b43e Compare January 25, 2021 22:17
@kostko kostko force-pushed the ptrus/feature/runtime-slashing branch 5 times, most recently from c75ee0f to 6e4096e Compare February 5, 2021 14:04
@kostko kostko force-pushed the ptrus/feature/runtime-slashing branch 5 times, most recently from d7f6eec to 5d1c759 Compare February 8, 2021 11:55
@kostko kostko marked this pull request as ready for review February 8, 2021 12:00
docs/adr/0005-runtime-compute-slashing.md Show resolved Hide resolved
go/consensus/tendermint/apps/roothash/slashing.go Outdated Show resolved Hide resolved
return err
}

if len(rtState.Runtime.Staking.Slashing) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Go doesn't require this extra check, right? we already rely on the Slashing[xxx] to return a zeroed Slash struct if it's not found, and then we return the same error

Copy link
Member

Choose a reason for hiding this comment

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

But it could be nil and derefing a nil map is an error. In case of Slashing from the (global) staking consensus parameters, the Slashing() state accessor method returns a non-nil map in case the parameters are unset/nil but here this is not the case.

Copy link
Contributor

Choose a reason for hiding this comment

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

https://golang.org/ref/spec#Index_expressions language spec says reading from a nil map gives the zero value

go/roothash/api/api.go Outdated Show resolved Hide resolved
go/roothash/api/api.go Outdated Show resolved Hide resolved
// TODO: part of slashed amount (configurable) should be transferred to the transaction submitter.
// If the caller is a node, distribute slashed funds to the controlling entity instead of the
// caller directly.
rewardAddr := ctx.CallerAddress()
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if people frontrun transactions like these, to take the reward for themselves

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that's a valid concern. Incentivizing evidence submission seems like it introduces more problems than it solves :-)

go/oasis-node/cmd/registry/runtime/runtime.go Outdated Show resolved Hide resolved
go/roothash/api/commitment/pool.go Outdated Show resolved Hide resolved
return fmt.Errorf("tendermint/roothash: runtimeAccReward.Quo(100): %w", err)
}
runtimeAddr := staking.NewRuntimeAddress(runtimeID)
if _, err := stakeState.TransferFromCommon(ctx, runtimeAddr, runtimeAccReward, false); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

Currently these rewards ignore the commission schedule and the whole reward is split between all delegators of the entity, is this fine or should the owning entity be able to take commission?

Copy link
Member Author

@ptrus ptrus Feb 9, 2021

Choose a reason for hiding this comment

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

(note: this comment should be in line 193, here we transfer to the runtime account anyway)

Copy link
Member

Choose a reason for hiding this comment

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

Hm, actually currently the delegators get nothing, it is treated the same as if the entity just increased its self-delegation. Do we want the delegators to get a cut as well?

Copy link
Member Author

@ptrus ptrus Feb 9, 2021

Choose a reason for hiding this comment

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

Oh right yeah i miss-checked that. I think that probably yes? (since if the node is slashed, delegators do lose proportionately). But i'm not sure if it's currently worth the additional complexity. Maybe a good future improvement. I would at least add some notes that runtime slashing rewards are not rewarded to delegators.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, I changed the code to take all delegators and commission into account.

@kostko kostko force-pushed the ptrus/feature/runtime-slashing branch 4 times, most recently from 361e4c2 to 97a1aa3 Compare February 9, 2021 13:29
Copy link
Member Author

@ptrus ptrus left a comment

Choose a reason for hiding this comment

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

✔️ Thanks for finishing the PR (can't actually approve as i'm the author).

}

// If escrow is requested, escrow the transferred stake immediately.
if escrow {
Copy link
Member Author

Choose a reason for hiding this comment

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

Hm I think (not 100% sure, didn't check in detail) we can now also simplify the AddRewards method by calling TransferFromCommon from the accounts loop.

@kostko kostko force-pushed the ptrus/feature/runtime-slashing branch 3 times, most recently from 432d32e to 9dd2bbd Compare February 10, 2021 09:28
@kostko kostko force-pushed the ptrus/feature/runtime-slashing branch from 9dd2bbd to 253376f Compare February 10, 2021 09:57
@kostko kostko merged commit 6e8ec70 into master Feb 10, 2021
@kostko kostko deleted the ptrus/feature/runtime-slashing branch February 10, 2021 10:53
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.

None yet

3 participants