-
Notifications
You must be signed in to change notification settings - Fork 296
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
Define staking events #4449
Conversation
cd04238
to
f094f22
Compare
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.
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 👼
crates/core/component/stake/src/component/validator_handler/validator_manager.rs
Show resolved
Hide resolved
f094f22
to
35624bb
Compare
79e63d1
to
2556702
Compare
2556702
to
caebf11
Compare
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. |
Is anything blocking merging this? |
Only review |
crates/core/app/src/app/mod.rs
Outdated
// 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); | ||
} |
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.
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.
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.
Is there another way we should handle it?
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.
@zbuc sorry, i got distracted doing the full writeup and was delayed. filled in the comment now
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.
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.
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.
@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.
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.
Concerns about data model (will elaborate inline)
2f9501b
to
1ac30d2
Compare
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.
LGTM pending requested changes
1ac30d2
to
c8880a1
Compare
Generate code based on new staking events
…lashing penalty events
c8880a1
to
17225d8
Compare
Describe your changes
Resolves #4336, emitting events for validator definitions and state transitions. Included events:
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: