Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct header version when computing merklized state update #1757

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sequencer/src/api/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl Options {
let get_node_state = async move { state.node_state().await.clone() };
tasks.spawn(
"merklized state storage update loop",
update_state_storage_loop(ds, get_node_state, Ver::version()),
update_state_storage_loop(ds, get_node_state),
);
}

Expand Down
30 changes: 12 additions & 18 deletions sequencer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use hotshot_query_service::{
types::HeightIndexed,
};
use jf_merkle_tree::{LookupResult, MerkleTreeScheme, ToTraversalPath, UniversalMerkleTreeScheme};
use vbs::version::Version;

use crate::{
api::data_source::CatchupDataSource, catchup::SqlStateCatchup,
Expand All @@ -27,14 +26,19 @@ async fn compute_state_update(
instance: &NodeState,
parent_leaf: &LeafQueryData<SeqTypes>,
proposed_leaf: &LeafQueryData<SeqTypes>,
version: Version,
) -> anyhow::Result<(ValidatedState, Delta)> {
let proposed_leaf = proposed_leaf.leaf();
let parent_leaf = parent_leaf.leaf();
let header = proposed_leaf.block_header();

// Check internal consistency.
let parent_header = parent_leaf.block_header();
ensure!(
state.chain_config.commit() == parent_header.chain_config().commit(),
"internal error! in-memory chain config {:?} does not match parent header {:?}",
state.chain_config,
parent_header.chain_config(),
);
ensure!(
state.block_merkle_tree.commitment() == parent_header.block_merkle_tree_root(),
"internal error! in-memory block tree {:?} does not match parent header {:?}",
Expand All @@ -49,7 +53,7 @@ async fn compute_state_update(
);

state
.apply_header(instance, parent_leaf, header, version)
.apply_header(instance, parent_leaf, header, header.version())
.await
}

Expand Down Expand Up @@ -132,14 +136,12 @@ async fn update_state_storage(
instance: &NodeState,
parent_leaf: &LeafQueryData<SeqTypes>,
proposed_leaf: &LeafQueryData<SeqTypes>,
version: Version,
) -> anyhow::Result<ValidatedState> {
let parent_chain_config = parent_state.chain_config;

let (state, delta) =
compute_state_update(parent_state, instance, parent_leaf, proposed_leaf, version)
.await
.context("computing state update")?;
let (state, delta) = compute_state_update(parent_state, instance, parent_leaf, proposed_leaf)
.await
.context("computing state update")?;

let mut storage = storage.write().await;
if let Err(err) = store_state_update(&mut *storage, proposed_leaf.height(), &state, delta).await
Expand Down Expand Up @@ -199,7 +201,6 @@ async fn store_genesis_state(
pub(crate) async fn update_state_storage_loop(
storage: Arc<RwLock<impl SequencerStateDataSource>>,
instance: impl Future<Output = NodeState>,
version: Version,
) -> anyhow::Result<()> {
let mut instance = instance.await;
instance.peers = Arc::new(SqlStateCatchup::new(storage.clone(), Default::default()));
Expand Down Expand Up @@ -240,15 +241,8 @@ pub(crate) async fn update_state_storage_loop(

while let Some(leaf) = leaves.next().await {
loop {
match update_state_storage(
&parent_state,
&storage,
&instance,
&parent_leaf,
&leaf,
version,
)
.await
match update_state_storage(&parent_state, &storage, &instance, &parent_leaf, &leaf)
.await
{
Ok(state) => {
parent_leaf = leaf;
Expand Down
4 changes: 4 additions & 0 deletions types/src/v0/impls/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ impl ValidatedState {

/// Charge a fee to an account, transferring the funds to the fee recipient account.
pub fn charge_fee(&mut self, fee_info: FeeInfo, recipient: FeeAccount) -> Result<(), FeeError> {
if fee_info.amount == 0.into() {
return Ok(());
}

let fee_state = self.fee_merkle_tree.clone();

// Deduct the fee from the paying account.
Expand Down
Loading