-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathengine.rs
More file actions
727 lines (668 loc) · 29.8 KB
/
Copy pathengine.rs
File metadata and controls
727 lines (668 loc) · 29.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use anyhow::anyhow;
use cid::Cid;
use fvm2::machine::MultiEngine as MultiEngine2;
use fvm3::engine::MultiEngine as MultiEngine3;
use fvm4::engine::MultiEngine as MultiEngine4;
use fvm4::executor::{ApplyKind, ApplyRet};
use fvm4_shared::econ::TokenAmount;
use fvm4_shared::message::Message;
use super::blockstore::CgoBlockstore;
use super::externs::CgoExterns;
use super::types::*;
// Generic executor; uses the current engine types
pub trait CgoExecutor: Send {
fn execute_message(
&mut self,
msg: Message,
apply_kind: ApplyKind,
raw_length: usize,
) -> anyhow::Result<ApplyRet>;
fn flush(&mut self) -> anyhow::Result<Cid>;
}
pub struct Config {
pub network_version: u32,
pub chain_id: u64,
pub chain_epoch: u64,
pub chain_timestamp: u64,
pub state_root: Cid,
pub base_fee: TokenAmount,
pub circulating_supply: TokenAmount,
pub tracing: bool,
pub actor_debugging: bool,
pub actor_redirect: Vec<(Cid, Cid)>,
pub flush_all_blocks: bool,
}
// The generic engine interface
pub trait AbstractMultiEngine: Send + Sync {
fn new_executor(
&self,
config: Config,
blockstore: CgoBlockstore,
externs: CgoExterns,
) -> anyhow::Result<InnerFvmMachine>;
}
#[derive(Eq, PartialEq, Hash, Debug, Copy, Clone)]
enum EngineVersion {
V1,
V2,
V3,
}
// The generic engine container
pub struct MultiEngineContainer {
concurrency: u32,
engines: Mutex<HashMap<EngineVersion, Arc<dyn AbstractMultiEngine + 'static>>>,
}
impl TryFrom<u32> for EngineVersion {
type Error = anyhow::Error;
fn try_from(value: u32) -> Result<Self, Self::Error> {
match value {
16 | 17 => Ok(EngineVersion::V1),
18..=20 => Ok(EngineVersion::V2),
21..=28 => Ok(EngineVersion::V3),
_ => Err(anyhow!("network version not supported")),
}
}
}
impl MultiEngineContainer {
pub fn with_concurrency(concurrency: u32) -> MultiEngineContainer {
MultiEngineContainer {
engines: Mutex::new(HashMap::new()),
// The number of messages that can be executed simultaniously on any given engine (i.e.,
// on any given network version/config).
concurrency,
}
}
pub fn get(&self, nv: u32) -> anyhow::Result<Arc<dyn AbstractMultiEngine + 'static>> {
let engine_version = nv.try_into()?;
let mut locked = self
.engines
.lock()
.map_err(|e| anyhow!("engine lock poisoned: {e}"))?;
Ok(locked
.entry(engine_version)
.or_insert_with(|| match engine_version {
EngineVersion::V1 => {
Arc::new(MultiEngine2::new()) as Arc<dyn AbstractMultiEngine + 'static>
}
EngineVersion::V2 => Arc::new(MultiEngine3::new(self.concurrency))
as Arc<dyn AbstractMultiEngine + 'static>,
EngineVersion::V3 => Arc::new(MultiEngine4::new(self.concurrency))
as Arc<dyn AbstractMultiEngine + 'static>,
})
.clone())
}
}
// fvm v4 implementation
mod v4 {
use cid::Cid;
use std::sync::Mutex;
use fvm4::call_manager::DefaultCallManager as DefaultCallManager4;
use fvm4::engine::{EnginePool as EnginePool4, MultiEngine as MultiEngine4};
use fvm4::executor::{ApplyKind, ApplyRet, DefaultExecutor as DefaultExecutor4};
use fvm4::kernel::filecoin::DefaultFilecoinKernel as DefaultFilecoinKernel4;
use fvm4::machine::{DefaultMachine as DefaultMachine4, NetworkConfig};
use fvm4_shared::{chainid::ChainID, clock::ChainEpoch, message::Message};
use crate::fvm::engine::{
AbstractMultiEngine, CgoBlockstore, CgoExecutor, CgoExterns, InnerFvmMachine,
};
use super::Config;
type CgoMachine4 = DefaultMachine4<CgoBlockstore, CgoExterns>;
type CgoExecutor4 = DefaultExecutor4<DefaultFilecoinKernel4<DefaultCallManager4<CgoMachine4>>>;
fn new_executor(
engine_pool: EnginePool4,
machine: CgoMachine4,
) -> anyhow::Result<CgoExecutor4> {
CgoExecutor4::new(engine_pool, machine)
}
impl CgoExecutor for CgoExecutor4 {
fn execute_message(
&mut self,
msg: Message,
apply_kind: ApplyKind,
raw_length: usize,
) -> anyhow::Result<ApplyRet> {
fvm4::executor::Executor::execute_message(self, msg, apply_kind, raw_length)
}
fn flush(&mut self) -> anyhow::Result<Cid> {
fvm4::executor::Executor::flush(self)
}
}
impl AbstractMultiEngine for MultiEngine4 {
fn new_executor(
&self,
cfg: Config,
blockstore: CgoBlockstore,
externs: CgoExterns,
) -> anyhow::Result<InnerFvmMachine> {
let mut network_config = NetworkConfig::new(cfg.network_version.into());
network_config.chain_id(ChainID::from(cfg.chain_id));
if cfg.actor_debugging {
network_config.enable_actor_debugging();
}
network_config.redirect_actors(cfg.actor_redirect);
let mut machine_context = network_config.for_epoch(
cfg.chain_epoch as ChainEpoch,
cfg.chain_timestamp,
cfg.state_root,
);
machine_context.set_base_fee(cfg.base_fee);
machine_context.set_circulating_supply(cfg.circulating_supply);
if cfg.tracing {
machine_context.enable_tracing();
}
if cfg.flush_all_blocks {
machine_context.enable_flush_all_blocks();
}
let engine = self.get(&network_config)?;
let machine = CgoMachine4::new(&machine_context, blockstore, externs)?;
Ok(InnerFvmMachine {
machine: Some(Mutex::new(Box::new(new_executor(engine, machine)?))),
})
}
}
}
// fvm v3 implementation
mod v3 {
use anyhow::Context;
use cid::Cid;
use fvm4_shared::event::{self, ActorEvent, Entry, StampedEvent};
use num_traits::FromPrimitive;
use std::sync::Mutex;
use fvm3::call_manager::{
backtrace::Cause as Cause3, DefaultCallManager as DefaultCallManager3,
};
use fvm3::engine::{EnginePool as EnginePool3, MultiEngine as MultiEngine3};
use fvm3::executor::{
ApplyFailure as ApplyFailure3, ApplyKind as ApplyKind3, DefaultExecutor as DefaultExecutor3,
};
use fvm3::machine::{DefaultMachine as DefaultMachine3, NetworkConfig as NetworkConfig3};
use fvm3::trace::ExecutionEvent as ExecutionEvent3;
use fvm3::DefaultKernel as DefaultKernel3;
use fvm3_shared::{
address::Address as Address3, chainid::ChainID as ChainID3,
clock::ChainEpoch as ChainEpoch3, econ::TokenAmount as TokenAmount3,
message::Message as Message3,
};
use fvm4::call_manager::{backtrace::Backtrace, backtrace::Cause, backtrace::Frame};
use fvm4::executor::{ApplyFailure, ApplyKind, ApplyRet};
use fvm4::gas::{Gas, GasCharge, GasDuration};
use fvm4::kernel::SyscallError;
use fvm4::trace::ExecutionEvent;
use fvm4_shared::{
address::Address, econ::TokenAmount, error::ErrorNumber, error::ExitCode, message::Message,
receipt::Receipt, state::ActorState,
};
use crate::fvm::engine::{
AbstractMultiEngine, CgoBlockstore, CgoExecutor, CgoExterns, InnerFvmMachine,
};
use super::Config;
type CgoMachine3 = DefaultMachine3<CgoBlockstore, CgoExterns>;
type CgoExecutor3 = DefaultExecutor3<DefaultKernel3<DefaultCallManager3<CgoMachine3>>>;
fn new_executor(
engine_pool: EnginePool3,
machine: CgoMachine3,
) -> anyhow::Result<CgoExecutor3> {
CgoExecutor3::new(engine_pool, machine)
}
impl CgoExecutor for CgoExecutor3 {
fn execute_message(
&mut self,
msg: Message,
apply_kind: ApplyKind,
raw_length: usize,
) -> anyhow::Result<ApplyRet> {
let res = fvm3::executor::Executor::execute_message(
self,
Message3 {
version: msg.version,
from: Address3::from_bytes(&msg.from.to_bytes())
.context("unsupported from address")?,
to: Address3::from_bytes(&msg.to.to_bytes())
.context("unsupported to address")?,
sequence: msg.sequence,
value: TokenAmount3::from_atto(msg.value.atto().clone()),
method_num: msg.method_num,
params: msg.params,
gas_limit: msg.gas_limit,
gas_fee_cap: TokenAmount3::from_atto(msg.gas_fee_cap.atto().clone()),
gas_premium: TokenAmount3::from_atto(msg.gas_premium.atto().clone()),
},
match apply_kind {
ApplyKind::Explicit => ApplyKind3::Explicit,
ApplyKind::Implicit => ApplyKind3::Implicit,
},
raw_length,
);
match res {
Ok(ret) => Ok(ApplyRet {
msg_receipt: Receipt {
exit_code: ExitCode::new(ret.msg_receipt.exit_code.value()),
return_data: ret.msg_receipt.return_data,
gas_used: ret.msg_receipt.gas_used,
events_root: ret.msg_receipt.events_root,
},
penalty: TokenAmount::from_atto(ret.penalty.atto().clone()),
miner_tip: TokenAmount::from_atto(ret.miner_tip.atto().clone()),
base_fee_burn: TokenAmount::from_atto(ret.base_fee_burn.atto().clone()),
over_estimation_burn: TokenAmount::from_atto(
ret.over_estimation_burn.atto().clone(),
),
refund: TokenAmount::from_atto(ret.refund.atto().clone()),
gas_refund: ret.gas_refund,
gas_burned: ret.gas_burned,
failure_info: ret.failure_info.map(|failure| match failure {
ApplyFailure3::MessageBacktrace(bt) => {
ApplyFailure::MessageBacktrace(Backtrace {
frames: bt
.frames
.into_iter()
.map(|f| Frame {
source: f.source,
method: f.method,
code: ExitCode::new(f.code.value()),
message: f.message,
})
.collect(),
cause: bt.cause.map(|cause| match cause {
Cause3::Syscall {
module,
function,
error,
message,
} => Cause::Syscall {
module,
function,
error: ErrorNumber::from_u32(error as u32)
.unwrap_or(ErrorNumber::AssertionFailed),
message,
},
Cause3::Fatal {
error_msg,
backtrace,
} => Cause::Fatal {
error_msg,
backtrace,
},
}),
})
}
ApplyFailure3::PreValidation(s) => ApplyFailure::PreValidation(s),
}),
exec_trace: ret
.exec_trace
.into_iter()
.filter_map(|tr| match tr {
ExecutionEvent3::GasCharge(charge) => {
Some(ExecutionEvent::GasCharge(GasCharge {
name: charge.name,
compute_gas: Gas::from_milligas(
charge.compute_gas.as_milligas(),
),
other_gas: Gas::from_milligas(charge.other_gas.as_milligas()),
elapsed: charge
.elapsed
.get()
.copied()
.map(GasDuration::from)
.unwrap_or_default(),
}))
}
ExecutionEvent3::Call {
from,
to,
method,
params,
value,
read_only,
gas_limit,
} => Some(ExecutionEvent::Call {
from,
to: Address::from_bytes(&to.to_bytes())
// There's nothing we can do here, so we use the "chaos" actor
// ID.
.unwrap_or_else(|_| Address::new_id(98)),
method,
params,
value: TokenAmount::from_atto(value.atto().clone()),
gas_limit,
read_only,
}),
ExecutionEvent3::CallReturn(code, ret) => {
Some(ExecutionEvent::CallReturn(ExitCode::new(code.value()), ret))
}
ExecutionEvent3::CallError(err) => {
Some(ExecutionEvent::CallError(SyscallError(
err.0,
ErrorNumber::from_u32(err.1 as u32)
.unwrap_or(ErrorNumber::AssertionFailed),
)))
}
ExecutionEvent3::InvokeActor { id, state } => {
Some(ExecutionEvent::InvokeActor {
id,
state: ActorState {
code: state.code,
state: state.state,
sequence: state.sequence,
balance: TokenAmount::from_atto(
state.balance.atto().clone(),
),
delegated_address: state
.delegated_address
// Do our best to convert the address, or drop it if
// that's impossible for some reason.
.and_then(|a| Address::from_bytes(&a.to_bytes()).ok()),
},
})
}
_ => None,
})
.collect(),
events: ret
.events
.into_iter()
.map(|e| StampedEvent {
emitter: e.emitter,
event: ActorEvent {
entries: e
.event
.entries
.into_iter()
.map(|e| Entry {
flags: event::Flags::from_bits_retain(e.flags.bits()),
key: e.key,
codec: e.codec,
value: e.value,
})
.collect(),
},
})
.collect(),
}),
Err(x) => Err(x),
}
}
fn flush(&mut self) -> anyhow::Result<Cid> {
fvm3::executor::Executor::flush(self)
}
}
impl AbstractMultiEngine for MultiEngine3 {
fn new_executor(
&self,
cfg: Config,
blockstore: CgoBlockstore,
externs: CgoExterns,
) -> anyhow::Result<InnerFvmMachine> {
let mut network_config = NetworkConfig3::new(cfg.network_version.into());
network_config.chain_id(ChainID3::from(cfg.chain_id));
if cfg.actor_debugging {
network_config.enable_actor_debugging();
}
network_config.redirect_actors(cfg.actor_redirect);
let mut machine_context = network_config.for_epoch(
cfg.chain_epoch as ChainEpoch3,
cfg.chain_timestamp,
cfg.state_root,
);
machine_context.set_base_fee(TokenAmount3::from_atto(cfg.base_fee.atto().clone()));
machine_context.set_circulating_supply(TokenAmount3::from_atto(
cfg.circulating_supply.atto().clone(),
));
if cfg.tracing {
machine_context.enable_tracing();
}
let engine = self.get(&network_config)?;
let machine = CgoMachine3::new(&machine_context, blockstore, externs)?;
Ok(InnerFvmMachine {
machine: Some(Mutex::new(Box::new(new_executor(engine, machine)?))),
})
}
}
}
// fvm v2 implementation
mod v2 {
use anyhow::{anyhow, Context};
use cid::Cid;
use fvm_ipld_encoding::ipld_block::IpldBlock;
use num_traits::FromPrimitive;
use std::sync::Mutex;
use fvm2::call_manager::{
backtrace::Cause as Cause2, DefaultCallManager as DefaultCallManager2,
};
use fvm2::executor::{
ApplyFailure as ApplyFailure2, ApplyKind as ApplyKind2, DefaultExecutor as DefaultExecutor2,
};
use fvm2::machine::{
DefaultMachine as DefaultMachine2, MultiEngine as MultiEngine2,
NetworkConfig as NetworkConfig2,
};
use fvm2::trace::ExecutionEvent as ExecutionEvent2;
use fvm2::DefaultKernel as DefaultKernel2;
use fvm2_shared::{
address::Address as Address2, clock::ChainEpoch as ChainEpoch2,
econ::TokenAmount as TokenAmount2, message::Message as Message2,
};
use fvm4::call_manager::{backtrace::Backtrace, backtrace::Cause, backtrace::Frame};
use fvm4::executor::{ApplyFailure, ApplyKind, ApplyRet};
use fvm4::gas::{Gas, GasCharge};
use fvm4::kernel::SyscallError;
use fvm4::trace::ExecutionEvent;
use fvm4_shared::{
address::Address, econ::TokenAmount, error::ErrorNumber, error::ExitCode, message::Message,
receipt::Receipt,
};
use fvm_ipld_encoding::{RawBytes, DAG_CBOR};
use crate::fvm::engine::{
AbstractMultiEngine, CgoBlockstore, CgoExecutor, CgoExterns, InnerFvmMachine,
};
use super::Config;
type CgoMachine2 = DefaultMachine2<CgoBlockstore, CgoExterns>;
type CgoExecutor2 = DefaultExecutor2<DefaultKernel2<DefaultCallManager2<CgoMachine2>>>;
fn new_executor(machine: CgoMachine2) -> CgoExecutor2 {
CgoExecutor2::new(machine)
}
fn bytes_to_block(bytes: RawBytes) -> Option<IpldBlock> {
if bytes.is_empty() {
None
} else {
Some(IpldBlock {
data: bytes.into(),
codec: DAG_CBOR,
})
}
}
impl CgoExecutor for CgoExecutor2 {
fn execute_message(
&mut self,
msg: Message,
apply_kind: ApplyKind,
raw_length: usize,
) -> anyhow::Result<ApplyRet> {
let res = fvm2::executor::Executor::execute_message(
self,
Message2 {
version: msg.version.try_into().context("invalid message version")?,
from: Address2::from_bytes(&msg.from.to_bytes())
.context("unsupported from address")?,
to: Address2::from_bytes(&msg.to.to_bytes())
.context("unsupported to address")?,
sequence: msg.sequence,
value: TokenAmount2::from_atto(msg.value.atto().clone()),
method_num: msg.method_num,
params: msg.params,
gas_limit: msg.gas_limit.try_into().context("invalid gas limit")?,
gas_fee_cap: TokenAmount2::from_atto(msg.gas_fee_cap.atto().clone()),
gas_premium: TokenAmount2::from_atto(msg.gas_premium.atto().clone()),
},
match apply_kind {
ApplyKind::Explicit => ApplyKind2::Explicit,
ApplyKind::Implicit => ApplyKind2::Implicit,
},
raw_length,
);
match res {
Ok(ret) => Ok(ApplyRet {
msg_receipt: Receipt {
exit_code: ExitCode::new(ret.msg_receipt.exit_code.value()),
return_data: RawBytes::new(ret.msg_receipt.return_data.into()),
gas_used: ret
.msg_receipt
.gas_used
.try_into()
.context("negative gas used")?,
events_root: None,
},
penalty: TokenAmount::from_atto(ret.penalty.atto().clone()),
miner_tip: TokenAmount::from_atto(ret.miner_tip.atto().clone()),
base_fee_burn: TokenAmount::from_atto(ret.base_fee_burn.atto().clone()),
over_estimation_burn: TokenAmount::from_atto(
ret.over_estimation_burn.atto().clone(),
),
refund: TokenAmount::from_atto(ret.refund.atto().clone()),
gas_refund: ret.gas_refund.try_into().context("negative gas refund")?,
gas_burned: ret.gas_burned.try_into().context("negative gas burned")?,
failure_info: ret.failure_info.map(|failure| match failure {
ApplyFailure2::MessageBacktrace(bt) => {
ApplyFailure::MessageBacktrace(Backtrace {
frames: bt
.frames
.into_iter()
.map(|f| Frame {
source: f.source,
method: f.method,
code: ExitCode::new(f.code.value()),
message: f.message,
})
.collect(),
cause: bt.cause.map(|cause| match cause {
Cause2::Syscall {
module,
function,
error,
message,
} => Cause::Syscall {
module,
function,
error: ErrorNumber::from_u32(error as u32)
.unwrap_or(ErrorNumber::AssertionFailed),
message,
},
Cause2::Fatal {
error_msg,
backtrace,
} => Cause::Fatal {
error_msg,
backtrace,
},
}),
})
}
ApplyFailure2::PreValidation(s) => ApplyFailure::PreValidation(s),
}),
exec_trace: ret
.exec_trace
.into_iter()
.filter_map(|tr| match tr {
ExecutionEvent2::GasCharge(charge) => {
// We set the gas for "negative" charges to 0. This isn't correct,
// but it won't matter in practice (the sum of the gas charges in
// the trace aren't guaranteed to equal the total gas charge
// anyways).
Some(ExecutionEvent::GasCharge(GasCharge {
name: charge.name,
compute_gas: Gas::from_milligas(
charge
.compute_gas
.as_milligas()
.try_into()
.unwrap_or_default(),
),
other_gas: Gas::from_milligas(
charge
.storage_gas
.as_milligas()
.try_into()
.unwrap_or_default(),
),
elapsed: Default::default(), // no timing information for v2.
}))
}
ExecutionEvent2::Call {
from,
to,
method,
params,
value,
} => Some(ExecutionEvent::Call {
from,
to: Address::from_bytes(&to.to_bytes())
// There's nothing we can do here, so we use the "chaos" actor
// ID.
.unwrap_or_else(|_| Address::new_id(98)),
method,
params: bytes_to_block(params),
value: TokenAmount::from_atto(value.atto().clone()),
gas_limit: msg.gas_limit,
read_only: false,
}),
ExecutionEvent2::CallReturn(ret) => Some(ExecutionEvent::CallReturn(
ExitCode::OK,
bytes_to_block(ret),
)),
ExecutionEvent2::CallAbort(ec) => {
Some(ExecutionEvent::CallReturn(ExitCode::new(ec.value()), None))
}
ExecutionEvent2::CallError(err) => {
Some(ExecutionEvent::CallError(SyscallError(
err.0,
ErrorNumber::from_u32(err.1 as u32)
.unwrap_or(ErrorNumber::AssertionFailed),
)))
}
_ => None,
})
.collect(),
events: vec![],
}),
Err(x) => Err(x),
}
}
fn flush(&mut self) -> anyhow::Result<Cid> {
fvm2::executor::Executor::flush(self)
}
}
impl AbstractMultiEngine for MultiEngine2 {
fn new_executor(
&self,
cfg: Config,
blockstore: CgoBlockstore,
externs: CgoExterns,
) -> anyhow::Result<InnerFvmMachine> {
let mut network_config = NetworkConfig2::new(
cfg.network_version
.try_into()
.map_err(|nv| anyhow!("network version {nv} not supported"))?,
);
if cfg.actor_debugging {
network_config.enable_actor_debugging();
}
network_config.redirect_actors(cfg.actor_redirect);
let mut machine_context =
network_config.for_epoch(cfg.chain_epoch as ChainEpoch2, cfg.state_root);
machine_context.set_base_fee(TokenAmount2::from_atto(cfg.base_fee.atto().clone()));
machine_context.set_circulating_supply(TokenAmount2::from_atto(
cfg.circulating_supply.atto().clone(),
));
if cfg.tracing {
machine_context.enable_tracing();
}
let engine = self.get(&network_config)?;
let machine = CgoMachine2::new(&engine, &machine_context, blockstore, externs)?;
Ok(InnerFvmMachine {
machine: Some(Mutex::new(Box::new(new_executor(machine)))),
})
}
}
}