Skip to content

Commit

Permalink
mock-consensus: 👷 block data is implicitly empty, can be appended (#4004
Browse files Browse the repository at this point in the history
)

fixes #3936. based upon #4002. see #3588.

this changes the type of the block builder's `data`, allowing it to be
implicitly kept empty. this is useful when e.g. fast forwarding a number
of blocks _(see #4002)_. this spares us the need to call
`with_data(vec![])`, and additionally means that the block builder is
never in an uninitialized state _(making #4003 needless)._

* #3936
* #4002
* #3588
  • Loading branch information
cratelyn authored Mar 12, 2024
1 parent 0dcba24 commit 6e892a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
21 changes: 10 additions & 11 deletions crates/test/mock-consensus/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use {
crate::TestNode,
anyhow::bail,
tap::Tap,
tendermint::{
account,
Expand All @@ -25,7 +24,7 @@ pub struct Builder<'e, C> {
test_node: &'e mut TestNode<C>,

/// Transaction data.
data: Option<Vec<Vec<u8>>>,
data: Vec<Vec<u8>>,

/// Evidence of malfeasance.
evidence: evidence::List,
Expand All @@ -47,10 +46,13 @@ impl<C> TestNode<C> {
impl<'e, C> Builder<'e, C> {
/// Sets the data for this block.
pub fn with_data(self, data: Vec<Vec<u8>>) -> Self {
Self {
data: Some(data),
..self
}
Self { data, ..self }
}

/// Appends the given tx to this block's data.
pub fn add_tx(mut self, tx: Vec<u8>) -> Self {
self.data.push(tx);
self
}

/// Sets the evidence [`List`][evidence::List] for this block.
Expand Down Expand Up @@ -112,13 +114,10 @@ where
fn finish(self) -> Result<(&'e mut TestNode<C>, Block), anyhow::Error> {
tracing::trace!("building block");
let Self {
data: Some(data),
data,
evidence,
test_node,
} = self
else {
bail!("builder was not fully initialized")
};
} = self;

let height = {
let height = test_node.height.increment();
Expand Down
1 change: 0 additions & 1 deletion crates/test/mock-consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ where

for i in 0..blocks {
self.block()
.with_data(vec![])
.execute()
.tap(|_| trace!(%i, "executing empty block"))
.await
Expand Down

0 comments on commit 6e892a2

Please sign in to comment.