Skip to content

Commit d034bf6

Browse files
committed
fix: handle changes to the executor and gas tracing
1 parent 60c5434 commit d034bf6

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

rust/src/fvm/engine.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use anyhow::anyhow;
66
use cid::Cid;
77

88
use fvm2::machine::MultiEngine as MultiEngine2;
9+
use fvm3::engine::MultiEngine as MultiEngine3;
910
use fvm3::executor::{ApplyKind, ApplyRet};
10-
use fvm3::machine::{MachineContext, MultiEngine as MultiEngine3, NetworkConfig};
11+
use fvm3::machine::{MachineContext, NetworkConfig};
1112
use fvm3_shared::{message::Message, version::NetworkVersion};
1213

1314
use super::blockstore::{CgoBlockstore, OverlayBlockstore};
@@ -39,13 +40,17 @@ pub trait AbstractMultiEngine: Send + Sync {
3940

4041
// The generic engine container
4142
pub struct MultiEngineContainer {
43+
concurrency: u32,
4244
engines: Mutex<HashMap<u32, Arc<dyn AbstractMultiEngine + 'static>>>,
4345
}
4446

4547
impl MultiEngineContainer {
4648
pub fn new() -> MultiEngineContainer {
4749
MultiEngineContainer {
4850
engines: Mutex::new(HashMap::new()),
51+
// The number of messages that can be executed simultaniously on any given engine (i.e.,
52+
// on any given network version/config).
53+
concurrency: 1,
4954
}
5055
}
5156

@@ -61,9 +66,8 @@ impl MultiEngineContainer {
6166
NetworkVersion::V16 | NetworkVersion::V17 => {
6267
Arc::new(MultiEngine2::new()) as Arc<dyn AbstractMultiEngine + 'static>
6368
}
64-
NetworkVersion::V18 => {
65-
Arc::new(MultiEngine3::new()) as Arc<dyn AbstractMultiEngine + 'static>
66-
}
69+
NetworkVersion::V18 => Arc::new(MultiEngine3::new(self.concurrency))
70+
as Arc<dyn AbstractMultiEngine + 'static>,
6771
_ => return Err(anyhow!("network version not supported")),
6872
})
6973
.clone(),
@@ -83,14 +87,12 @@ mod v3 {
8387
use std::sync::Mutex;
8488

8589
use fvm3::call_manager::DefaultCallManager as DefaultCallManager3;
90+
use fvm3::engine::{EnginePool as EnginePool3, MultiEngine as MultiEngine3};
8691
use fvm3::executor::{
8792
ApplyKind, ApplyRet, DefaultExecutor as DefaultExecutor3,
8893
ThreadedExecutor as ThreadedExecutor3,
8994
};
90-
use fvm3::machine::{
91-
DefaultMachine as DefaultMachine3, MachineContext, MultiEngine as MultiEngine3,
92-
NetworkConfig,
93-
};
95+
use fvm3::machine::{DefaultMachine as DefaultMachine3, MachineContext, NetworkConfig};
9496
use fvm3::DefaultKernel as DefaultKernel3;
9597
use fvm3_shared::message::Message;
9698

@@ -103,8 +105,11 @@ mod v3 {
103105
type BaseExecutor3 = DefaultExecutor3<DefaultKernel3<DefaultCallManager3<CgoMachine3>>>;
104106
type CgoExecutor3 = ThreadedExecutor3<BaseExecutor3>;
105107

106-
fn new_executor(machine: CgoMachine3) -> CgoExecutor3 {
107-
ThreadedExecutor3(BaseExecutor3::new(machine))
108+
fn new_executor(
109+
engine_pool: EnginePool3,
110+
machine: CgoMachine3,
111+
) -> anyhow::Result<CgoExecutor3> {
112+
Ok(ThreadedExecutor3(BaseExecutor3::new(engine_pool, machine)?))
108113
}
109114

110115
impl CgoExecutor for CgoExecutor3 {
@@ -131,9 +136,9 @@ mod v3 {
131136
externs: CgoExterns,
132137
) -> anyhow::Result<InnerFvmMachine> {
133138
let engine = self.get(&cfg)?;
134-
let machine = CgoMachine3::new(&engine, &ctx, blockstore, externs)?;
139+
let machine = CgoMachine3::new(&ctx, blockstore, externs)?;
135140
Ok(InnerFvmMachine {
136-
machine: Some(Mutex::new(Box::new(new_executor(machine)))),
141+
machine: Some(Mutex::new(Box::new(new_executor(engine, machine)?))),
137142
})
138143
}
139144
}
@@ -284,6 +289,7 @@ mod v2 {
284289
storage_gas: Gas::from_milligas(
285290
charge.storage_gas.as_milligas(),
286291
),
292+
elapsed: Default::default(), // no timing information for v2.
287293
}))
288294
}
289295
ExecutionEvent2::Call {

rust/src/fvm/machine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ fn build_lotus_trace(
449449
name,
450450
compute_gas,
451451
storage_gas,
452+
elapsed: _, // TODO: thread timing through to lotus.
452453
}) => {
453454
new_trace.gas_charges.push(LotusGasCharge {
454455
name,

0 commit comments

Comments
 (0)