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

Define staking events #4449

Merged
merged 9 commits into from
Jun 14, 2024
Merged

Define staking events #4449

merged 9 commits into from
Jun 14, 2024

Conversation

plaidfinch
Copy link
Collaborator

@plaidfinch plaidfinch commented May 23, 2024

Describe your changes

Resolves #4336, emitting events for validator definitions and state transitions. Included events:

  • validator state change
  • validator voting power change
  • validator bonding state change
  • validator rate data change
  • validator definition upload
  • validator missed block
  • slashing penalty applied
  • delegate
  • undelegate
  • funding stream rewards

All of these are proto-based events, and emitted both at genesis, when relevant, and when changed later.

Emitting events at genesis is technically impossible because the ABCI interface does not accept events as a response to InitChain, so instead genesis events are emitted at the start of the first block.

Issue ticket number and link

Resolves #4336. Closes #3797. Closes #4512.

Checklist before requesting a review

  • If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason:

    This adds new events, but does not affect consensus.

@cratelyn cratelyn added A-staking Area: Design and implementation of staking and delegation protobuf-changes Makes changes to the protobuf definitions. labels May 23, 2024
Copy link
Contributor

@cratelyn cratelyn left a comment

Choose a reason for hiding this comment

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

this looks like it is coming together well! pardon the drive-by comments on a draft, i have one question to ask before these protobuf definitions ossify 👼

@zbuc zbuc marked this pull request as ready for review June 5, 2024 22:04
@zbuc
Copy link
Member

zbuc commented Jun 5, 2024

This LGTM, I made a couple code organization changes and tested it and confirmed the deferred events work properly.

I have not tested it between upgrades however.

@hdevalence
Copy link
Member

Is anything blocking merging this?

@zbuc
Copy link
Member

zbuc commented Jun 12, 2024

Is anything blocking merging this?

Only review

Comment on lines 155 to 167
// Apply the state from `init_chain` and return the events generated during genesis. These
// cannot be emitted at this time due to a limitation of ABCI, but they will be emitted
// during the first BeginBlock.
let events = state_tx.apply().1;

// Commit the genesis events to the state.
let mut state_tx = self
.state
.try_begin_transaction()
.expect("state Arc should not be referenced elsewhere");
for (i, event) in events.into_iter().enumerate() {
state_tx.put_deferred_event(i, event);
}
Copy link
Member

@hdevalence hdevalence Jun 12, 2024

Choose a reason for hiding this comment

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

On reflection I have more concerns that this may be the wrong approach and I think we probably shouldn't do it.

One of the good things about the ABCI design is that it separates the "init chain" and "apply block" methods, so that a block is always "apply changes to a previous valid state". In contrast, Bitcoin or other chains have a notion of a "genesis block", which is a delta-update-from-an-empty state that then has special validation rules. This turns out to be problematic because all the downstream code has to have special case handling.

I worry that this design means that anything consuming ABCI events can no longer assume that an ABCI event is a delta update to an existing state. Instead, downstream consumers of events have to figure out whether or not there was a valid previous state and implement "transition from empty" logic.

Stepping back a bit, why did we want to do this at all? The problem we're trying to solve is that the ABCI events emitted as part of blocks are only recording changes to the existing state, so something that's consuming the events doesn't know what the start is. But, we're trying to fix that by changing the meaning of events, rather than by having a starting state. Instead, I think it would be a better design to assume that an indexer has access to the genesis data and can use that for its own initialization.

Copy link
Member

Choose a reason for hiding this comment

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

Is there another way we should handle it?

Copy link
Member

Choose a reason for hiding this comment

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

@zbuc sorry, i got distracted doing the full writeup and was delayed. filled in the comment now

Copy link
Member

Choose a reason for hiding this comment

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

So the idea is that we remove this specially cased event emission and then let the indexers use genesis JSON to bootstrap initial state? Sounds fine to me.

Copy link
Member

@zbuc zbuc Jun 12, 2024

Choose a reason for hiding this comment

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

@hdevalence indexers would also need to handle the genesis data checkpointed during upgrades. In the case of an upgrade it might be preferable for an indexer to wipe their database and start from the new genesis data.

Copy link
Member

@hdevalence hdevalence left a comment

Choose a reason for hiding this comment

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

Concerns about data model (will elaborate inline)

Copy link
Contributor

@aubrika aubrika left a comment

Choose a reason for hiding this comment

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

LGTM pending requested changes

@zbuc zbuc merged commit 16750b4 into main Jun 14, 2024
13 checks passed
@zbuc zbuc deleted the define-staking-events branch June 14, 2024 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-staking Area: Design and implementation of staking and delegation protobuf-changes Makes changes to the protobuf definitions.
Projects
Status: Done
5 participants