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

Prune EthereumSignatures and EthereumEventVoteRecords #517

Merged
merged 85 commits into from
Aug 10, 2023
Merged

Conversation

cbrit
Copy link
Member

@cbrit cbrit commented Apr 26, 2023

  1. Introduces CompletedOutgoingTxs store. When an OutgoingTx is observed or timed out, it is moved to this new store and the original deleted. This new store is used for slashing. A completed OutgoingTx is pruned after it leaves the slashing window. Signer sets are a special case, their OutgoingTx is still used for slashing.
  2. Prunes EthereumSignature at the time of CompletedOutgoingTx deletion for each type, which occurs after the slashing has passed
  3. Prunes EthereumEventVoteRecords with nonces older than the last observed event nonce.
  4. Adds CompletedOutgoingTxs and EventVoteRecords queries
  5. Includes both uncompleted and completed OutgoingTxs in the results returned by the Unsigned*Txs queries so that new signers can sign completed txs and not get slashed.

Closes #431
Closes #349

@cbrit cbrit requested review from mvid and EricBolten April 26, 2023 19:36
@cbrit cbrit marked this pull request as draft April 26, 2023 19:49
@cbrit cbrit temporarily deployed to CI April 26, 2023 19:57 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI April 26, 2023 19:57 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI April 26, 2023 19:57 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI April 26, 2023 19:57 — with GitHub Actions Inactive
@cbrit cbrit marked this pull request as ready for review April 27, 2023 01:45
@codecov-commenter
Copy link

codecov-commenter commented Apr 27, 2023

Codecov Report

Merging #517 (64f09b2) into main (174d9e3) will increase coverage by 0.10%.
Report is 2 commits behind head on main.
The diff coverage is 31.83%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #517      +/-   ##
==========================================
+ Coverage   29.90%   30.01%   +0.10%     
==========================================
  Files          47       48       +1     
  Lines        6503     6987     +484     
==========================================
+ Hits         1945     2097     +152     
- Misses       4402     4708     +306     
- Partials      156      182      +26     
Files Changed Coverage Δ
module/x/gravity/client/cli/query.go 0.00% <0.00%> (ø)
module/x/gravity/keeper/ethereum_event_handler.go 5.30% <0.00%> (+0.26%) ⬆️
module/x/gravity/keeper/slashing.go 0.00% <0.00%> (ø)
module/x/gravity/types/key.go 0.00% <0.00%> (ø)
module/x/gravity/keeper/grpc_query.go 15.64% <2.11%> (-1.53%) ⬇️
module/x/gravity/keeper/ethereum_event_vote.go 47.96% <28.57%> (-2.78%) ⬇️
module/x/gravity/types/genesis.go 39.08% <39.13%> (+<0.01%) ⬆️
module/x/gravity/keeper/keeper.go 85.18% <68.90%> (-3.84%) ⬇️
module/x/gravity/keeper/signer_set.go 71.79% <71.79%> (ø)
module/x/gravity/keeper/batch.go 82.22% <78.57%> (-3.27%) ⬇️
... and 4 more

... and 2 files with indirect coverage changes

@cbrit cbrit temporarily deployed to CI April 27, 2023 02:27 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI April 27, 2023 02:27 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI April 27, 2023 19:27 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI April 27, 2023 19:27 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI April 27, 2023 19:27 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI April 27, 2023 19:27 — with GitHub Actions Inactive
Copy link
Contributor

@EricBolten EricBolten left a comment

Choose a reason for hiding this comment

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

Some comments.

@@ -27,6 +27,8 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
// EndBlocker is called at the end of every block
func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
outgoingTxSlashing(ctx, k)
// Do we need to concern ourselves with future slashing windows for this pruning?
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you elaborate on this question?

Copy link
Member Author

Choose a reason for hiding this comment

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

there is a window of blocks for which the chain waits to prune batch votes so that validators have time to sign them before getting slashed. At the time when I commented this I didn't fully understand how vote records work for events as distinct from signatures for outgoing TXs. There's no reason to keep event vote records around after the last observed event nonce has incremented so I'll remove this comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now that you have me thinking about it, I think there's certainly an argument to be made for a slashing window for the oracle function as well. It's as necessary to complete the bridge transaction lifecycle as signatures are. From this perspective, we may want to keep a sliding window's worth of history for both.

panic(err)
}
eventNonce := event.GetEventNonce()
if eventNonce <= lastObservedEventNonce {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be < rather than <=?

Copy link
Member Author

@cbrit cbrit May 9, 2023

Choose a reason for hiding this comment

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

If the nonce has been canonically observed there is no need to keep new votes for it right?

Copy link
Contributor

Choose a reason for hiding this comment

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

One thing I have noticed while helping validators diagnose issues with their orchestrators is that it's valuable to have evidence they have or have not been submitting things correctly. If we prune everything every time, it's very hard to query for this sort of information. I think leaving some small bit of history before pruning might be worthwhile.

module/x/gravity/abci.go Show resolved Hide resolved
module/x/gravity/abci.go Outdated Show resolved Hide resolved
@cbrit
Copy link
Member Author

cbrit commented May 9, 2023

Need to look into replacing the scan iteration when getting the vote attestation map into a lookup

@cbrit cbrit temporarily deployed to CI May 9, 2023 19:35 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI May 9, 2023 19:35 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI May 9, 2023 19:35 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI May 9, 2023 19:35 — with GitHub Actions Inactive
Copy link
Contributor

@EricBolten EricBolten left a comment

Choose a reason for hiding this comment

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

A small suggestion. Also responded to some of the existing comment threads.

@@ -464,6 +464,7 @@ func (k Keeper) SetOutgoingTx(ctx sdk.Context, outgoing types.OutgoingTx) {
// DeleteOutgoingTx deletes a given outgoingtx
func (k Keeper) DeleteOutgoingTx(ctx sdk.Context, storeIndex []byte) {
ctx.KVStore(k.storeKey).Delete(types.MakeOutgoingTxKey(storeIndex))
k.DeleteEthereumSignatures(ctx, storeIndex)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not certain if it matters in practice here, but I would suggest cleaning up the "child" records (the signatures) before deleting the "parent" record (the outgoing TX).

@cbrit cbrit temporarily deployed to CI August 9, 2023 20:00 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 9, 2023 20:00 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 9, 2023 20:00 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 9, 2023 20:00 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 9, 2023 20:45 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 9, 2023 20:45 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 9, 2023 20:45 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 9, 2023 20:45 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 10, 2023 02:45 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 10, 2023 02:45 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 10, 2023 14:46 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 10, 2023 14:46 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 10, 2023 14:46 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 10, 2023 16:54 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 10, 2023 16:54 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 10, 2023 16:54 — with GitHub Actions Inactive
@cbrit cbrit temporarily deployed to CI August 10, 2023 16:54 — with GitHub Actions Inactive
Copy link
Contributor

@EricBolten EricBolten left a comment

Choose a reason for hiding this comment

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

LGTM

@EricBolten EricBolten merged commit 76006da into main Aug 10, 2023
15 of 16 checks passed
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.

Prune attestations after being handled Investigate pruning of eth signatures for batches
4 participants