Skip to content

Commit 342b02f

Browse files
committed
use enum instead of bool for flushing the vm
1 parent 002c584 commit 342b02f

3 files changed

Lines changed: 21 additions & 10 deletions

File tree

src/rpc/methods/eth.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use crate::shim::gas::GasOutputs;
5454
use crate::shim::message::Message;
5555
use crate::shim::trace::{CallReturn, ExecutionEvent};
5656
use crate::shim::{clock::ChainEpoch, state_tree::StateTree};
57-
use crate::state_manager::StateLookupPolicy;
57+
use crate::state_manager::{StateLookupPolicy, VMFlush};
5858
use crate::utils::cache::SizeTrackingLruCache;
5959
use crate::utils::db::BlockstoreExt as _;
6060
use crate::utils::encoding::from_slice_with_fallback;
@@ -2159,7 +2159,7 @@ where
21592159
{
21602160
let (invoc_res, _) = ctx
21612161
.state_manager
2162-
.apply_on_state_with_gas(tipset, msg, StateLookupPolicy::Enabled, false)
2162+
.apply_on_state_with_gas(tipset, msg, StateLookupPolicy::Enabled, VMFlush::Skip)
21632163
.await
21642164
.map_err(|e| anyhow::anyhow!("failed to apply on state with gas: {e}"))?;
21652165

@@ -2256,7 +2256,7 @@ where
22562256
Some(ts),
22572257
VMTrace::NotTraced,
22582258
StateLookupPolicy::Enabled,
2259-
false,
2259+
VMFlush::Skip,
22602260
)
22612261
.await?;
22622262
Ok(apply_ret.msg_receipt().exit_code().is_success())
@@ -4027,7 +4027,7 @@ impl RpcMethod<3> for EthTraceCall {
40274027
Some(ts.clone()),
40284028
msg.clone(),
40294029
StateLookupPolicy::Enabled,
4030-
true,
4030+
VMFlush::Flush,
40314031
)
40324032
.await
40334033
.map_err(|e| anyhow::anyhow!("failed to apply message: {e}"))?;

src/rpc/methods/gas.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::shim::{
1515
econ::{BLOCK_GAS_LIMIT, TokenAmount},
1616
message::Message,
1717
};
18-
use crate::state_manager::StateLookupPolicy;
18+
use crate::state_manager::{StateLookupPolicy, VMFlush};
1919
use anyhow::{Context, Result};
2020
use enumflags2::BitFlags;
2121
use fvm_ipld_blockstore::Blockstore;
@@ -263,7 +263,7 @@ impl GasEstimateGasLimit {
263263
Some(ts.clone()),
264264
trace_config,
265265
StateLookupPolicy::Enabled,
266-
false,
266+
VMFlush::Skip,
267267
)
268268
.await?;
269269
Ok((invoc_res, apply_ret, prior_messages, ts))

src/state_manager/mod.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ where
683683
tipset: Option<Tipset>,
684684
msg: Message,
685685
state_lookup: StateLookupPolicy,
686-
flush: bool,
686+
vm_flush: VMFlush,
687687
) -> anyhow::Result<(ApiInvocResult, Option<Cid>)> {
688688
let ts = tipset.unwrap_or_else(|| self.heaviest_tipset());
689689

@@ -713,7 +713,7 @@ where
713713
Some(ts),
714714
VMTrace::Traced,
715715
state_lookup,
716-
flush,
716+
vm_flush,
717717
)
718718
.await?;
719719

@@ -741,7 +741,7 @@ where
741741
tipset: Option<Tipset>,
742742
trace_config: VMTrace,
743743
state_lookup: StateLookupPolicy,
744-
flush: bool,
744+
vm_flush: VMFlush,
745745
) -> Result<(InvocResult, ApplyRet, Duration, Option<Cid>), Error> {
746746
let ts = tipset.unwrap_or_else(|| self.heaviest_tipset());
747747
let (st, _) = self
@@ -787,7 +787,10 @@ where
787787

788788
message.set_sequence(from_actor.sequence);
789789
let (ret, duration) = vm.apply_message(message)?;
790-
let state_root = if flush { Some(vm.flush()?) } else { None };
790+
let state_root = match vm_flush {
791+
VMFlush::Flush => Some(vm.flush()?),
792+
VMFlush::Skip => None,
793+
};
791794
Ok((ret, duration, state_root))
792795
})?;
793796

@@ -2109,3 +2112,11 @@ pub enum StateLookupPolicy {
21092112
Enabled,
21102113
Disabled,
21112114
}
2115+
2116+
/// Controls whether the VM should flush its state after execution
2117+
#[derive(Debug, Copy, Clone, Default)]
2118+
pub enum VMFlush {
2119+
Flush,
2120+
#[default]
2121+
Skip,
2122+
}

0 commit comments

Comments
 (0)