Skip to main content

Endblocker

EndBlocker​

EndBlocker is the function that calls at the end of each block. In x/gov module it is responsible for handling proposals, especially changing their states and execute them if needed. For OversightCommittee flow we are going to change the stages when the Proposal is about to be executed.

Normally, when VotingPeriod is ended and there are enough VotingPower to move the Proposal to the execution stage, EndBlocker makes next phases:

  • Vote routine
  • Execution routine

Vote routine​

Vote routine includes all the voting steps and calculations, like:

  • Remove all the Votes related to the Proposal from the state.
  • TallyResult is calculated on this phase.

Execution routine​

Execution routine is responsible for the following:

  • Execute messages, attached to the Proposal, by passing them to MsgRouter
  • Mark Proposal as PASSED in case of successful execution or FAILED in case of unsuccessful.

Proposal status delayed​

For OversightCommittee flow we are introducing another state for the Proposal - ProposalStatusDelayed. It includes all the previous steps, except real message execution and moving Proposal to final states, like PASSED or FAILED.

The main points, regarding new state:

  • All the steps from Voting routine are done
  • Actions related to deposit are executed, like burn deposit or return to proposer.

Having this modified EndBlocker changes Proposal's status to ProposalStatusDelayed and returns it back into ActiveProposalsQueue but with shifted VotingPeriodEnd by Grace Period from OversightCommitteeParams.

When the shifted VotingPeriodEnd is reached, the Proposal goes to the Execution routine.

The AfterProposalVotingPeriodEnded hook fires once per Proposal, on the pass that tallies it and moves it to ProposalStatusDelayed. The later execution pass does not fire it again.

While the Proposal is delayed:

  • An OversightCommittee veto marks it REJECTED and removes it from the ActiveProposalsQueue, so the EndBlocker never tallies or executes it again. The FinalTallyResult recorded at the end of the voting period is kept.
  • A message that fails during the execution routine marks the Proposal as FAILED with the error in FailedReason. As in upstream x/gov, this is not an EndBlocker error and does not halt the chain.

Events and logs​

The EndBlocker reports each pass over a Proposal twice: once in the upstream active_proposal event, once in a typed dgov event that carries the structured data the string event cannot.

active_proposal is emitted on every pass, exactly as in upstream x/gov. Its proposal_result attribute tells the passes apart:

Passproposal_result
Voting period ended, proposal passedproposal_delayed
Voting period ended, proposal rejectedproposal_rejected
Expedited threshold missedexpedited_proposal_rejected (converted to a regular one)
Grace period endedproposal_passed or proposal_failed

As upstream already emits several active_proposal events for an expedited proposal, consumers must key on proposal_result rather than on the event type. proposal_delayed is the only value added by dgov.

The typed events are:

  • d.dgov.v1.EventProposalTallied, emitted once per tally, on the pass that ends a voting period. It carries the result of the pass (same values as proposal_result above), the TallyResult that is stored on the proposal as FinalTallyResult, and the two totals the verdict was derived from: total_voting_power, the power that actually voted (the quorum numerator), and total_val_power, the power of the whole bonded validator set at tally time (the quorum denominator). Without them turnout and vote shares cannot be reconstructed later.
  • d.dgov.v1.EventProposalExecuted, emitted once, on the pass that ends the grace period. result is proposal_passed or proposal_failed, and failed_reason carries the handler error when the execution failed.

The log lines follow the same split: proposal tallied on the tally pass and proposal executed on the execution pass. Neither event nor log is allowed to fail the block: an error from emitting a typed event is logged and ignored.