Skip to content

Commit

Permalink
docs(protocol): fix lifecycle info and add consensus view (#882)
Browse files Browse the repository at this point in the history
Explain consensus with figure and ammend inaccurate code refs

task: none
  • Loading branch information
idea404 authored Apr 19, 2024
1 parent cb5cbb0 commit 62b4c37
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions docs/site/docs/protocol/evmengine/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,45 @@ sidebar_position: 4

A transaction within the Omni EVM undergoes several key phases in its lifecycle, including proposal preparation, payload generation, and consensus-reaching, before being executed and permanently included in the blockchain state. This process not only ensures the integrity and security of transactions but also maintains the scalability and performance of the Omni network.

## Consensus

The following diagram illustrates the consensus process used by CometBFT in together with ABCI++ and EVM Engine.

<figure>
<img src="/img/consensus.png" alt="Consensus in halo" />
<figcaption>*The consensus process in `halo`*</figcaption>
</figure>

### Proposal Preparation and Payload Generation

The initial step in the EVM lifecycle involves the preparation of a proposal for the next block. This phase is crucial for organizing transactions into a coherent block structure that can be processed by the consensus mechanism.

In this stage, the `Keeper` module acts by handling unexpected transactions and leveraging the optimistic payload or creating a new one to ensure the smooth progression of the block preparation process.

Below is a stubbed fragment from source for the function declaration of [the preparation of proposals by the `Keeper`](https://github.com/omni-network/omni/blob/1439d8a99f66a3bb3b7d113c63f8f073512c5377/halo/evmengine/keeper/abci.go#L24-L98):

```go
// PrepareProposal function snippet
func (k *Keeper) PrepareProposal(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) {
// Proposal preparation logic...
}
```

In this stage, the Keeper module plays a pivotal role, handling unexpected transactions and leveraging the optimistic payload or creating a new one to ensure the smooth progression of the block preparation process.

### Consensus and Finalization

Once a proposal is prepared, it enters the consensus mechanism, where validators work together to agree on the final state of the block. Upon reaching consensus, the block is finalized and state transitions are applied to the blockchain.

The processing of proposals is handled by the [base cosmos SDK app's `ProcessProposal`](https://github.com/cosmos/cosmos-sdk/blob/5e7aae0db1f5ee4cdcb1b0ff4d0003d09bfd047a/baseapp/abci.go#L471-L561).

Below is a stubbed function declaration [from source](https://github.com/omni-network/omni/blob/82ab876283a73300b091ebae2e9d14d8204a41f2/halo/app/prouter.go#L20-L65) of where this assignment takes place in the `halo` app:

```go
// ExecutionPayload function snippet
func (s msgServer) ExecutionPayload(ctx context.Context, msg *types.MsgExecutionPayload) (*types.ExecutionPayloadResponse, error) {
// Execution payload handling logic...
// Makes a new process proposal handler
func makeProcessProposalHandler(app *App) sdk.ProcessProposalHandler {
// assigns the process proposal handling for baseapp cosmos SDK use
}
```

Finally, proposals are finalized by the cosmos SDK app's `FinalizeBlock`, [see source](https://github.com/cosmos/cosmos-sdk/blob/5e7aae0db1f5ee4cdcb1b0ff4d0003d09bfd047a/baseapp/abci.go#L874-L911).

This phase is critical for the execution of smart contracts and the application of transactions to the blockchain state, ensuring that all operations are accurately reflected in the network's ledger.
Binary file added docs/site/static/img/consensus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 62b4c37

Please sign in to comment.