Skip to content

Commit

Permalink
separate functions for validate and apply proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
imabdulbasit committed Apr 11, 2024
1 parent 8ae58f5 commit 768e0d1
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 236 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion sequencer/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ impl BlockPayload for Payload<TxTableEntryWord> {
BuilderCommitment::from_raw_digest(digest.finalize())
}

fn get_transactions(&self, _: &Self::Metadata) -> &Vec<Self::Transaction> {
fn get_transactions(&self, _metadata: &Self::Metadata) -> &Vec<Self::Transaction> {
// self.enumerate(metadata).map(|(i, t)| t).collect()

unimplemented!()
}
}
Expand Down
38 changes: 12 additions & 26 deletions sequencer/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@ mod test_headers {
use crate::{
catchup::mock::MockStateCatchup,
l1_client::L1Client,
state::{validate_and_apply_proposal, BlockMerkleTree, Delta, FeeMerkleTree},
state::{
apply_proposal, get_l1_deposits, validate_proposal, BlockMerkleTree, Delta,
FeeMerkleTree,
},
NodeState,
};
use async_compatibility_layer::logging::{setup_backtrace, setup_logging};
Expand Down Expand Up @@ -655,17 +658,11 @@ mod test_headers {
validated_state.block_merkle_tree = block_merkle_tree.clone();
parent_header.block_merkle_tree_root = block_merkle_tree_root;
let mut proposal = parent_header.clone();
let mut delta = Delta::default();

// Advance `proposal.height` to trigger validation error.
let result = validate_and_apply_proposal(
&mut validated_state,
&mut delta,
&parent_leaf,
&proposal,
vec![],
)
.unwrap_err();
let mut delta = Delta::default();
apply_proposal(&mut validated_state, &mut delta, &parent_leaf, vec![]);
let result = validate_proposal(&validated_state, &parent_leaf, &proposal).unwrap_err();
assert_eq!(
format!("{}", result.root_cause()),
"Invalid Height Error: 0, 0"
Expand All @@ -674,14 +671,7 @@ mod test_headers {
// proposed `Header` root should include parent +
// parent.commit
proposal.height += 1;
let result = validate_and_apply_proposal(
&mut validated_state,
&mut delta,
&parent_leaf,
&proposal,
vec![],
)
.unwrap_err();
let result = validate_proposal(&validated_state, &parent_leaf, &proposal).unwrap_err();
// Fails b/c `proposal` has not advanced from `parent`
assert!(format!("{}", result.root_cause()).contains("Invalid Block Root Error"));
}
Expand Down Expand Up @@ -749,15 +739,11 @@ mod test_headers {
let mut block_merkle_tree = proposal_state.block_merkle_tree.clone();
block_merkle_tree.push(proposal.commit()).unwrap();

let l1_deposits = get_l1_deposits(&genesis_state, &proposal, &parent_leaf).await;

let mut delta = Delta::default();
validate_and_apply_proposal(
&mut proposal_state,
&mut delta,
&parent_leaf,
&proposal.clone(),
vec![],
)
.unwrap();
apply_proposal(&mut proposal_state, &mut delta, &parent_leaf, l1_deposits);
validate_proposal(&proposal_state, &parent_leaf, &proposal.clone()).unwrap();
assert_eq!(
proposal_state.block_merkle_tree.commitment(),
proposal.block_merkle_tree_root
Expand Down
Loading

0 comments on commit 768e0d1

Please sign in to comment.