Skip to content

Commit

Permalink
changed to progressive commit
Browse files Browse the repository at this point in the history
  • Loading branch information
EdHastingsCasperAssociation committed Apr 1, 2024
1 parent b2507b8 commit 06223f7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
19 changes: 18 additions & 1 deletion node/src/components/contract_runtime/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ pub fn execute_finalized_block(
BalanceIdentifier::Payment
}
};
state_root_hash =
scratch_state.commit(state_root_hash, pay_result.effects().clone())?;
artifact_builder
.with_wasm_v1_result(pay_result)
.map_err(|_| BlockExecutionError::RootNotFound(state_root_hash))?;
Expand Down Expand Up @@ -250,6 +252,8 @@ pub fn execute_finalized_block(
runtime_args,
));
let consumed = gas_limit;
state_root_hash =
scratch_state.commit(state_root_hash, transfer_result.effects().clone())?;
artifact_builder
.with_added_consumed(consumed)
.with_transfer_result(transfer_result)
Expand All @@ -273,6 +277,8 @@ pub fn execute_finalized_block(
auction_method,
));
let consumed = gas_limit;
state_root_hash = scratch_state
.commit(state_root_hash, bidding_result.effects().clone())?;
artifact_builder
.with_added_consumed(consumed)
.with_bidding_result(bidding_result)
Expand Down Expand Up @@ -300,6 +306,8 @@ pub fn execute_finalized_block(
let wasm_v1_result =
execution_engine_v1.execute(&scratch_state, wasm_v1_request);
trace!(%transaction_hash, ?category, ?wasm_v1_result, "able to get wasm v1 result");
state_root_hash = scratch_state
.commit(state_root_hash, wasm_v1_result.effects().clone())?;
// note: consumed is scraped from wasm_v1_result along w/ other fields
artifact_builder
.with_wasm_v1_result(wasm_v1_result)
Expand Down Expand Up @@ -329,6 +337,8 @@ pub fn execute_finalized_block(
HandlePaymentMode::clear_holds(balance_identifier.clone(), holds_epoch),
);
let handle_payment_result = scratch_state.handle_payment(handle_payment_request);
state_root_hash = scratch_state
.commit(state_root_hash, handle_payment_result.effects().clone())?;
artifact_builder
.with_handle_payment_result(&handle_payment_result)
.map_err(|_| BlockExecutionError::RootNotFound(state_root_hash))?;
Expand All @@ -342,6 +352,8 @@ pub fn execute_finalized_block(
holds_epoch,
insufficient_balance_handling,
));
state_root_hash =
scratch_state.commit(state_root_hash, hold_result.effects().clone())?;
artifact_builder
.with_balance_hold_result(&hold_result)
.map_err(|_| BlockExecutionError::RootNotFound(state_root_hash))?;
Expand All @@ -365,6 +377,8 @@ pub fn execute_finalized_block(
),
);
let handle_payment_result = scratch_state.handle_payment(handle_payment_request);
state_root_hash = scratch_state
.commit(state_root_hash, handle_payment_result.effects().clone())?;
artifact_builder
.with_handle_payment_result(&handle_payment_result)
.map_err(|_| BlockExecutionError::RootNotFound(state_root_hash))?;
Expand All @@ -389,6 +403,8 @@ pub fn execute_finalized_block(
),
);
let handle_payment_result = scratch_state.handle_payment(handle_payment_request);
state_root_hash = scratch_state
.commit(state_root_hash, handle_payment_result.effects().clone())?;
artifact_builder
.with_handle_payment_result(&handle_payment_result)
.map_err(|_| BlockExecutionError::RootNotFound(state_root_hash))?;
Expand All @@ -403,13 +419,14 @@ pub fn execute_finalized_block(
HandlePaymentMode::burn(balance_identifier, Some(consumed)),
);
let handle_payment_result = scratch_state.handle_payment(handle_payment_request);
state_root_hash = scratch_state
.commit(state_root_hash, handle_payment_result.effects().clone())?;
artifact_builder
.with_handle_payment_result(&handle_payment_result)
.map_err(|_| BlockExecutionError::RootNotFound(state_root_hash))?;
}
}

scratch_state.commit(state_root_hash, artifact_builder.effects())?;
if let Some(metrics) = metrics.as_ref() {
metrics
.commit_effects
Expand Down
4 changes: 0 additions & 4 deletions node/src/components/contract_runtime/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ impl ExecutionArtifactBuilder {
}
}

pub fn effects(&self) -> Effects {
self.effects.clone()
}

pub fn consumed(&self) -> U512 {
self.consumed.value()
}
Expand Down
10 changes: 10 additions & 0 deletions storage/src/data_access_layer/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,13 @@ pub enum TransferResult {
/// Transfer failed
Failure(TransferError),
}

impl TransferResult {
/// Returns the effects, if any.
pub fn effects(&self) -> Effects {
match self {
TransferResult::RootNotFound | TransferResult::Failure(_) => Effects::new(),
TransferResult::Success { effects, .. } => effects.clone(),
}
}
}

0 comments on commit 06223f7

Please sign in to comment.