Skip to content

Commit ae73d8a

Browse files
committed
feat(fvm): add flush_all_blocks option to also write intermediate blocks
1 parent 0579984 commit ae73d8a

File tree

6 files changed

+58
-108
lines changed

6 files changed

+58
-108
lines changed

cgo/fvm.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package cgo
88
*/
99
import "C"
1010

11-
func CreateFvmMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestamp, chainId, baseFeeHi, baseFeeLo, baseCircSupplyHi, baseCircSupplyLo, networkVersion uint64, stateRoot SliceRefUint8, tracing bool, blockstoreId, externsId uint64) (*FvmMachine, error) {
11+
func CreateFvmMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestamp, chainId, baseFeeHi, baseFeeLo, baseCircSupplyHi, baseCircSupplyLo, networkVersion uint64, stateRoot SliceRefUint8, tracing, flushAllBlocks bool, blockstoreId, externsId uint64) (*FvmMachine, error) {
1212
resp := (*resultFvmMachine)(C.create_fvm_machine(
1313
(C.FvmRegisteredVersion_t)(fvmVersion),
1414
C.uint64_t(chainEpoch),
@@ -21,6 +21,7 @@ func CreateFvmMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestam
2121
C.uint32_t(networkVersion),
2222
(C.slice_ref_uint8_t)(stateRoot),
2323
C.bool(tracing),
24+
C.bool(flushAllBlocks),
2425
C.uint64_t(blockstoreId),
2526
C.uint64_t(externsId),
2627
))
@@ -36,7 +37,7 @@ func CreateFvmMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestam
3637
return executor, nil
3738
}
3839

39-
func CreateFvmDebugMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestamp, chainId, baseFeeHi, baseFeeLo, baseCircSupplyHi, baseCircSupplyLo, networkVersion uint64, stateRoot SliceRefUint8, actorRedirect SliceRefUint8, tracing bool, blockstoreId, externsId uint64) (*FvmMachine, error) {
40+
func CreateFvmDebugMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTimestamp, chainId, baseFeeHi, baseFeeLo, baseCircSupplyHi, baseCircSupplyLo, networkVersion uint64, stateRoot SliceRefUint8, actorRedirect SliceRefUint8, tracing, flushAllBlocks bool, blockstoreId, externsId uint64) (*FvmMachine, error) {
4041
resp := (*resultFvmMachine)(C.create_fvm_debug_machine(
4142
(C.FvmRegisteredVersion_t)(fvmVersion),
4243
C.uint64_t(chainEpoch),
@@ -50,6 +51,7 @@ func CreateFvmDebugMachine(fvmVersion FvmRegisteredVersion, chainEpoch, chainTim
5051
(C.slice_ref_uint8_t)(stateRoot),
5152
(C.slice_ref_uint8_t)(actorRedirect),
5253
C.bool(tracing),
54+
C.bool(flushAllBlocks),
5355
C.uint64_t(blockstoreId),
5456
C.uint64_t(externsId),
5557
))
@@ -90,10 +92,3 @@ func FvmMachineFlush(executor *FvmMachine) ([]byte, error) {
9092
}
9193
return (SliceBoxedUint8)(resp.value).copy(), nil
9294
}
93-
94-
func FvmMachineDumpCache(executor *FvmMachine, blockstoreId uint64) error {
95-
resp := C.fvm_machine_dump_cache(executor, C.uint64_t(blockstoreId))
96-
defer resp.destroy()
97-
98-
return CheckErr(resp)
99-
}

fvm.go

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/filecoin-project/go-state-types/abi"
2020
"github.com/filecoin-project/go-state-types/big"
2121
"github.com/filecoin-project/go-state-types/network"
22-
"github.com/ipfs/boxo/blockstore"
2322
"github.com/ipfs/go-cid"
2423
"golang.org/x/xerrors"
2524
)
@@ -45,6 +44,7 @@ type FVMOpts struct {
4544
NetworkVersion network.Version
4645
StateBase cid.Cid
4746
Tracing bool
47+
FlushAllBlocks bool
4848

4949
Debug bool
5050
ActorRedirect cid.Cid
@@ -75,6 +75,7 @@ func CreateFVM(opts *FVMOpts) (*FVM, error) {
7575
uint64(opts.NetworkVersion),
7676
cgo.AsSliceRefUint8(opts.StateBase.Bytes()),
7777
opts.Tracing,
78+
opts.FlushAllBlocks,
7879
exHandle, exHandle,
7980
)
8081
} else {
@@ -90,6 +91,7 @@ func CreateFVM(opts *FVMOpts) (*FVM, error) {
9091
cgo.AsSliceRefUint8(opts.StateBase.Bytes()),
9192
cgo.AsSliceRefUint8(opts.ActorRedirect.Bytes()),
9293
true,
94+
opts.FlushAllBlocks,
9395
exHandle, exHandle,
9496
)
9597
}
@@ -188,14 +190,6 @@ func (f *FVM) Flush() (cid.Cid, error) {
188190
return cid.Cast(stateRoot)
189191
}
190192

191-
// DumpCache dumps the intermediate blockstore cache of the FVM to the provided blockstore.
192-
func (f *FVM) DumpCache(bs blockstore.Blockstore) error {
193-
defer runtime.KeepAlive(f)
194-
bsHandle := cgo.Register(context.TODO(), blockStoreAsExterns{Blockstore: bs})
195-
defer cgo.Unregister(bsHandle)
196-
return cgo.FvmMachineDumpCache(f.executor, bsHandle)
197-
}
198-
199193
type ApplyRet struct {
200194
Return []byte
201195
ExitCode uint64
@@ -247,32 +241,3 @@ func reformBigInt(hi, lo uint64) big.Int {
247241
int.SetBits(words)
248242
return big.NewFromGo(int)
249243
}
250-
251-
// blockStoreAsExterns is a wrapper around a blockstore.Blockstore that implements the cgo.Externs.
252-
// It is only intended for use strictly as a Blockstore, and does not support any of the other
253-
// Externs methods.
254-
type blockStoreAsExterns struct {
255-
blockstore.Blockstore
256-
}
257-
258-
var _ cgo.Externs = blockStoreAsExterns{}
259-
260-
func (b blockStoreAsExterns) GetChainRandomness(ctx context.Context, epoch abi.ChainEpoch) ([32]byte, error) {
261-
return [32]byte{}, xerrors.Errorf("GetChainRandomness not supported")
262-
}
263-
264-
func (b blockStoreAsExterns) GetBeaconRandomness(ctx context.Context, epoch abi.ChainEpoch) ([32]byte, error) {
265-
return [32]byte{}, xerrors.Errorf("GetBeaconRandomness not supported")
266-
}
267-
268-
func (b blockStoreAsExterns) VerifyConsensusFault(ctx context.Context, h1, h2, extra []byte) (*cgo.ConsensusFault, int64) {
269-
panic("VerifyConsensusFault not supported")
270-
}
271-
272-
func (b blockStoreAsExterns) TipsetCid(ctx context.Context, epoch abi.ChainEpoch) (cid.Cid, error) {
273-
return cid.Undef, xerrors.Errorf("TipsetCid not supported")
274-
}
275-
276-
func (b blockStoreAsExterns) View(ctx context.Context, cid cid.Cid, callback func([]byte) error) error {
277-
return xerrors.Errorf("View not supported")
278-
}

rust/Cargo.lock

Lines changed: 39 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ filecoin-proofs-api = { version = "18.1", default-features = false }
5151
yastl = "0.1.2"
5252

5353
[patch.crates-io]
54-
fvm4 = { package = "fvm", path = "/home/rvagg/git/pl/filecoin-project/ref-fvm/fvm" }
55-
fvm4_shared = { package = "fvm_shared", path = "/home/rvagg/git/pl/filecoin-project/ref-fvm/shared" }
54+
fvm = { path = "/home/rvagg/git/pl/filecoin-project/ref-fvm/fvm" }
55+
fvm_shared = { path = "/home/rvagg/git/pl/filecoin-project/ref-fvm/shared" }
5656
fvm_ipld_blockstore = { path = "/home/rvagg/git/pl/filecoin-project/ref-fvm/ipld/blockstore" }
5757
fvm_ipld_encoding = { path = "/home/rvagg/git/pl/filecoin-project/ref-fvm/ipld/encoding" }
5858

rust/src/fvm/engine.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ pub trait CgoExecutor: Send {
2626
) -> anyhow::Result<ApplyRet>;
2727

2828
fn flush(&mut self) -> anyhow::Result<Cid>;
29-
30-
fn dump_cache(&mut self, bs: CgoBlockstore) -> anyhow::Result<()>;
3129
}
3230

3331
pub struct Config {
@@ -41,6 +39,7 @@ pub struct Config {
4139
pub tracing: bool,
4240
pub actor_debugging: bool,
4341
pub actor_redirect: Vec<(Cid, Cid)>,
42+
pub flush_all_blocks: bool,
4443
}
4544

4645
// The generic engine interface
@@ -150,11 +149,6 @@ mod v4 {
150149
fn flush(&mut self) -> anyhow::Result<Cid> {
151150
fvm4::executor::Executor::flush(self)
152151
}
153-
154-
fn dump_cache(&mut self, bs: CgoBlockstore) -> anyhow::Result<()> {
155-
log::info!("CgoExecutor4::dump_cache");
156-
fvm4::executor::Executor::dump_cache(self, bs)
157-
}
158152
}
159153

160154
impl AbstractMultiEngine for MultiEngine4 {
@@ -185,6 +179,9 @@ mod v4 {
185179
if cfg.tracing {
186180
machine_context.enable_tracing();
187181
}
182+
if cfg.flush_all_blocks {
183+
machine_context.enable_flush_all_blocks();
184+
}
188185
let engine = self.get(&network_config)?;
189186
let machine = CgoMachine4::new(&machine_context, blockstore, externs)?;
190187
Ok(InnerFvmMachine {
@@ -427,11 +424,6 @@ mod v3 {
427424
fn flush(&mut self) -> anyhow::Result<Cid> {
428425
fvm3::executor::Executor::flush(self)
429426
}
430-
431-
// dump_cache is only implemented in v4
432-
fn dump_cache(&mut self, _: CgoBlockstore) -> anyhow::Result<()> {
433-
Err(anyhow::anyhow!("dump_cache not implemented for fvm v3"))
434-
}
435427
}
436428

437429
impl AbstractMultiEngine for MultiEngine3 {
@@ -693,11 +685,6 @@ mod v2 {
693685
fn flush(&mut self) -> anyhow::Result<Cid> {
694686
fvm2::executor::Executor::flush(self)
695687
}
696-
697-
// dump_cache is only implemented in v4
698-
fn dump_cache(&mut self, _: CgoBlockstore) -> anyhow::Result<()> {
699-
Err(anyhow::anyhow!("dump_cache not implemented for fvm v2"))
700-
}
701688
}
702689

703690
impl AbstractMultiEngine for MultiEngine2 {

0 commit comments

Comments
 (0)