Skip to content

Commit

Permalink
Add default implementations to Component trait
Browse files Browse the repository at this point in the history
This allows components that don't do anything for a particular method to skip implementing it at
all.
  • Loading branch information
plaidfinch committed Aug 18, 2023
1 parent 83ec4c8 commit 9c97b29
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions crates/core/component/component/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub trait Component {
/// This method is called once per chain, and should only perform
/// writes, since the backing tree for the [`State`] will
/// be empty.
async fn init_chain<S: StateWrite>(state: S, app_state: &Self::AppState);
async fn init_chain<S: StateWrite>(_state: S, _app_state: &Self::AppState) {}

/// Begins a new block, optionally inspecting the ABCI
/// [`BeginBlock`](abci::request::BeginBlock) request.
Expand All @@ -31,9 +31,10 @@ pub trait Component {
/// implementor MUST ensure that any clones of the `Arc` are dropped before
/// it returns, so that `state.get_mut().is_some()` on completion.
async fn begin_block<S: StateWrite + 'static>(
state: &mut Arc<S>,
begin_block: &abci::request::BeginBlock,
);
_state: &mut Arc<S>,
_begin_block: &abci::request::BeginBlock,
) {
}

/// Ends the block, optionally inspecting the ABCI
/// [`EndBlock`](abci::request::EndBlock) request, and performing any batch
Expand All @@ -50,9 +51,10 @@ pub trait Component {
/// implementor MUST ensure that any clones of the `Arc` are dropped before
/// it returns, so that `state.get_mut().is_some()` on completion.
async fn end_block<S: StateWrite + 'static>(
state: &mut Arc<S>,
end_block: &abci::request::EndBlock,
);
_state: &mut Arc<S>,
_end_block: &abci::request::EndBlock,
) {
}

/// Ends the epoch, applying component-specific state transitions that should occur when an epoch ends.
///
Expand All @@ -63,5 +65,7 @@ pub trait Component {
/// called, `state.get_mut().is_some()`, i.e., the `Arc` is not shared. The
/// implementor MUST ensure that any clones of the `Arc` are dropped before
/// it returns, so that `state.get_mut().is_some()` on completion.
async fn end_epoch<S: StateWrite + 'static>(state: &mut Arc<S>) -> Result<()>;
async fn end_epoch<S: StateWrite + 'static>(_state: &mut Arc<S>) -> Result<()> {
Ok(())
}
}

0 comments on commit 9c97b29

Please sign in to comment.