Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: forest-tool snapshot compute-state #3430

Merged
merged 193 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
193 commits
Select commit Hold shift + click to select a range
d1ce733
Scaffolding command
elmattic Jul 10, 2023
ff23be1
Remove memory db
elmattic Jul 10, 2023
0857cb9
cargo fmt
elmattic Jul 10, 2023
9485a3e
Move code to state subcommand
elmattic Jul 11, 2023
50c8577
Add state_compute rpc
elmattic Jul 11, 2023
9dcdf58
Move to a CarBackedBlockstore
elmattic Jul 11, 2023
5868195
Clean up
elmattic Jul 11, 2023
ba634aa
Add print before CarBackedBlockstore constructor
elmattic Jul 11, 2023
bab5c8c
Fix doc comment
elmattic Jul 11, 2023
f6e4a3b
Print computed state root hash
elmattic Jul 11, 2023
7ed786f
Remove message flag
elmattic Jul 12, 2023
78116e4
Merge branch 'main' into elmattic/compute-state-cli
elmattic Jul 12, 2023
b33ea85
Untangle apply_blocks from StateManager (wip)
elmattic Jul 12, 2023
d259a51
Add missing callbacks
elmattic Jul 12, 2023
27a2482
Remove passing of chainstore
elmattic Jul 12, 2023
09e44a2
Add print of json trace (wip)
elmattic Jul 13, 2023
bb118b2
Merge branch 'main' into elmattic/compute-state-cli
elmattic Jul 13, 2023
615eff9
Remove read_header
elmattic Jul 13, 2023
4566e50
Remove endpoint
elmattic Jul 13, 2023
b1987d2
exec traces (wip)
elmattic Jul 13, 2023
1e66d3a
cargo fmt
elmattic Jul 13, 2023
db3a037
Add comment
elmattic Jul 13, 2023
9dabe0f
Remove ExecutionEvent
elmattic Jul 13, 2023
99bc952
Use similar data structures than Lotus for exec trace
elmattic Jul 15, 2023
94b7d21
Add strict_bytes
elmattic Jul 15, 2023
7358f99
cleanup
elmattic Jul 15, 2023
c050a5b
Move serialization to json modules (wip)
elmattic Jul 21, 2023
6836aa0
Add message return
elmattic Jul 21, 2023
8e10dff
Add subcalls
elmattic Jul 21, 2023
db12aa5
Add gas trace charges
elmattic Jul 21, 2023
bce4f05
Uncomment code
elmattic Jul 21, 2023
8264f69
Add back option
elmattic Jul 21, 2023
d5d7527
Better output for trace message and trace return
elmattic Jul 21, 2023
dc1daa4
Rename some fields during json ser
elmattic Jul 24, 2023
e87c962
Format code
elmattic Jul 24, 2023
f8f645a
Add more fields to MessageGasCost
elmattic Jul 24, 2023
e314fee
Add total_cost field
elmattic Jul 24, 2023
22953a7
Fix message cid
elmattic Jul 24, 2023
0f05740
Fix gas_used field
elmattic Jul 24, 2023
2630215
Remove unused imports
elmattic Jul 24, 2023
011e8cd
Add events_root field
elmattic Jul 24, 2023
149aefc
Use failure_info instead
elmattic Jul 24, 2023
fa1e531
Add reward message (wip)
elmattic Jul 24, 2023
948ea7c
Add cron message trace
elmattic Jul 24, 2023
eccfd25
Merge branch 'main' into elmattic/compute-state-cli
elmattic Jul 24, 2023
6371c6e
Fix previous merge with main
elmattic Jul 25, 2023
9cdacf6
Formatting
elmattic Jul 25, 2023
460c29e
Remove borrows
elmattic Jul 25, 2023
ad15173
Some cleanup
elmattic Jul 25, 2023
f79b600
Revert changes to parity test
elmattic Jul 25, 2023
bbf0d51
Remove public trait
elmattic Jul 25, 2023
23452e4
Apply clippy suggestion
elmattic Jul 25, 2023
dadf5de
Rename type
elmattic Jul 25, 2023
71a6d70
Use dedicated json module for base64
elmattic Jul 25, 2023
2b785eb
Normalize output for base64 string
elmattic Jul 25, 2023
2aae25d
Add duration field
elmattic Jul 25, 2023
ee5b7d9
Remove prints
elmattic Jul 25, 2023
df7b3be
Merge branch 'main' into elmattic/compute-state-cli
elmattic Jul 25, 2023
21d43ea
Add tests
elmattic Jul 26, 2023
f0f9f4b
Ignore clippy warning
elmattic Jul 26, 2023
e70e6de
Some cleaning
elmattic Jul 26, 2023
c052eb6
Update comment
elmattic Jul 26, 2023
916d5cb
Add comment
elmattic Jul 26, 2023
224dac7
Add test for trace message
elmattic Jul 26, 2023
e243ef4
Add test for trace gas charge
elmattic Jul 26, 2023
dd48e72
Try to add a quickcheck test
elmattic Jul 26, 2023
50f328e
Fix spelling mistakes
elmattic Jul 26, 2023
f15d509
Fix spelling mistakes
elmattic Jul 26, 2023
6f3ca5e
Add special arbitrary version for Trace
elmattic Jul 26, 2023
46a4179
Ignore test
elmattic Jul 26, 2023
cbc7aa7
Fix test
elmattic Jul 26, 2023
4d667d3
Merge branch 'main' into elmattic/compute-state-cli
elmattic Jul 26, 2023
5c0ee3a
Refactor using a ctor
elmattic Jul 26, 2023
946e7aa
Rename variables
elmattic Jul 26, 2023
fa3d0c0
Add missing tests
elmattic Jul 27, 2023
e4c0a73
Merge branch 'main' into elmattic/compute-state-cli
elmattic Jul 27, 2023
1331201
Move to AnyCar
elmattic Jul 27, 2023
3fe891e
Empty commit
elmattic Jul 27, 2023
71bf7f8
Remove usage of StateManager
elmattic Jul 27, 2023
28fc5f6
Remove ChainStore
elmattic Jul 27, 2023
6f98406
Remove config
elmattic Jul 27, 2023
d0cb76c
Merge branch 'main' into elmattic/compute-state-cli
elmattic Jul 27, 2023
396c73f
Cosmetic changes
elmattic Jul 27, 2023
c5d96c1
Fix trace for implicit messages
elmattic Jul 27, 2023
cc3e231
Fix gas_limit for implicit messages
elmattic Jul 27, 2023
76e9718
Merge branch 'main' into elmattic/compute-state-cli
elmattic Jul 27, 2023
e707519
Fix documentation error
elmattic Jul 27, 2023
130dfda
Add tracking issue
elmattic Jul 27, 2023
abbb929
Move subcommand to snapshot ones
elmattic Jul 27, 2023
98251fd
Add support of address prefix
elmattic Jul 27, 2023
d7d36bc
Merge branch 'main' into elmattic/compute-state-cli
elmattic Aug 7, 2023
8c5466f
Use try::from constructor
elmattic Aug 7, 2023
a5cda56
Remove json modules for owned types
elmattic Aug 7, 2023
cf1db63
Merge branch 'main' into elmattic/compute-state-cli
elmattic Aug 7, 2023
3ff7c66
Merge branch 'main' into elmattic/compute-state-cli
elmattic Aug 8, 2023
95974e6
Merge branch 'main' into elmattic/compute-state-cli
elmattic Aug 10, 2023
f837818
Merge branch 'main' into elmattic/compute-state-cli
elmattic Aug 14, 2023
f8e1f51
Merge branch 'main' into elmattic/compute-state-cli
elmattic Aug 14, 2023
68b3fda
Merge branch 'main' into elmattic/compute-state-cli
elmattic Aug 16, 2023
b747653
Merge branch 'main' into elmattic/compute-state-cli
elmattic Aug 16, 2023
4b67594
Remove call to is_empty
elmattic Aug 16, 2023
c12f25d
Merge branch 'main' into elmattic/compute-state-cli
elmattic Aug 16, 2023
d01f534
Merge branch 'main' into elmattic/compute-state-cli
elmattic Aug 17, 2023
127b868
dev: add reference json
aatifsyed Aug 17, 2023
b132371
refactor: port crate::json::message_gas_cost to crate::lotus_json::me…
aatifsyed Aug 17, 2023
2d6313e
catchup: remove json::message
aatifsyed Aug 17, 2023
3077374
catchup: remove json::message_receipt
aatifsyed Aug 17, 2023
04c5c44
catchup: remove json::message_receipt
aatifsyed Aug 17, 2023
35eb0f4
catchup: tweaks
aatifsyed Aug 17, 2023
3a814ea
fix: remove dead method
aatifsyed Aug 17, 2023
5042bd3
run: ./make-output.bash
aatifsyed Aug 17, 2023
13cac99
run: rm make-output.bash output-3a814eaca.json output-d01f534f5.json …
aatifsyed Aug 17, 2023
a94b156
run: ./scripts/add_license.sh || true
aatifsyed Aug 17, 2023
ea9862f
fix: tweak InvocResult
aatifsyed Aug 17, 2023
8647d0d
Merge remote-tracking branch 'origin/main' into elmattic/compute-stat…
aatifsyed Aug 17, 2023
9f5495b
review: add TraceAction
aatifsyed Aug 21, 2023
b3256cd
refactor: remove MessageGastCostLotusJson
aatifsyed Aug 22, 2023
6409445
refactor: move interpreter structs into interpreter::vm::trace
aatifsyed Aug 22, 2023
b0bef67
refactor: get rid of Trace type alias
aatifsyed Aug 22, 2023
93c17b7
refactor: move TraceAction to crate::interpreter::vm::trace
aatifsyed Aug 22, 2023
d0ccf92
doc: tracing
aatifsyed Aug 22, 2023
4776636
refactor: do not spread the structs around the codebase
aatifsyed Aug 22, 2023
04744ae
refactor: rename structs
aatifsyed Aug 22, 2023
ca22663
doc: compute-state
aatifsyed Aug 23, 2023
96d8ea8
refactor: Cid -> NetworkChain helper
aatifsyed Aug 23, 2023
a4c035a
review: suggestion
aatifsyed Aug 23, 2023
4523cf5
Revert "run: rm make-output.bash output-3a814eaca.json output-d01f534…
aatifsyed Aug 24, 2023
a130113
feat: enum VMTrace and CalledAt
aatifsyed Aug 30, 2023
479520d
note: reflog of previous progress
aatifsyed Aug 30, 2023
0c0039e
fix: StateManager::replay callback ignores cron messages
aatifsyed Aug 30, 2023
2d3a8a6
fix: unpollute API
aatifsyed Aug 30, 2023
9a5ca80
refactor: remove trace module
aatifsyed Aug 30, 2023
3eeb41d
feat: parse ExecutionEvents
aatifsyed Aug 30, 2023
e5b229d
chore: why is this code so weird??
aatifsyed Aug 30, 2023
46a18fd
wip
aatifsyed Aug 30, 2023
18e8158
feat: parse_events, with proper documentation
aatifsyed Aug 30, 2023
d86a558
feat: initial clean implementation
aatifsyed Aug 30, 2023
86519ac
fix: infinite compiler recursion for &mut &mut ...: Iterator
aatifsyed Aug 30, 2023
52637ea
fix: ignore trailing gas charges
aatifsyed Aug 30, 2023
fab3198
run: ./make-output.bash
aatifsyed Aug 30, 2023
212991c
fix: remove trace from output
aatifsyed Aug 30, 2023
7bbbac2
run: sort-json-object-keys --in-place output-3a814eaca.json output-52…
aatifsyed Aug 30, 2023
819a532
fix: parse_events only returns one CallTree
aatifsyed Aug 31, 2023
1858047
run: ./make-output.bash
aatifsyed Aug 31, 2023
745fb81
feat: clean-json helper
aatifsyed Aug 31, 2023
0675b2a
run: cargo run --example clean-json -- output-3a814eaca.json output-5…
aatifsyed Aug 31, 2023
4e12b1c
fix: trivial differences
aatifsyed Aug 31, 2023
17c7f9f
run: ./make-output.bash
aatifsyed Aug 31, 2023
c1603f9
fix: empty Vec<u8> are represented as null by lotus
aatifsyed Aug 31, 2023
4405108
refactor: RawBytes delegates to VecU8LotusJson
aatifsyed Aug 31, 2023
1f1dcea
tweaks: add comments and customise make-output
aatifsyed Aug 31, 2023
f7feb9f
fix: json { "Params": null }
aatifsyed Aug 31, 2023
702ea5e
fix: include CID in LotusJson<Message>
aatifsyed Aug 31, 2023
e9c1fda
fix: explicit vs implicit messages
aatifsyed Aug 31, 2023
12673c2
run: ./make-output.bash
aatifsyed Aug 31, 2023
c4a188d
prove: use trailing gas charges differs from reference
aatifsyed Aug 31, 2023
6c3c5ab
Revert "prove: use trailing gas charges differs from reference"
aatifsyed Aug 31, 2023
b734643
run: mv /home/aatif/chainsafe/forest.worktrees/elmattic/compute-state…
aatifsyed Aug 31, 2023
9fa8754
run: cargo run --example clean-json -- output-a4c035ae2.json
aatifsyed Aug 31, 2023
c719157
note: GasLimit is wrong on old branch too...
aatifsyed Aug 31, 2023
c9d2b01
run: mv /home/aatif/chainsafe/forest.worktrees/elmattic/compute-state…
aatifsyed Aug 31, 2023
a1a5739
run: cargo run --example clean-json -- output-c12f25dfb.json
aatifsyed Aug 31, 2023
9e36bf0
note: previous code also had differring GasLimit
aatifsyed Aug 31, 2023
df9e532
note: 4611686018427387903 is i64::MAX/2, and is the number that is wrong
aatifsyed Aug 31, 2023
a03cd44
run: mv /home/aatif/sources/lotus/big-gas-limits.patch .
aatifsyed Aug 31, 2023
7abc972
note: lotus 1.23.0 and the tests pass - so not an error lotus side
aatifsyed Aug 31, 2023
6e22dcf
run: rm output-3a814eaca.json output-4e12b1c94.json output-819a53210.…
aatifsyed Sep 1, 2023
a4d6c8f
refactor: give reference files more helpful names
aatifsyed Sep 1, 2023
263f4c9
fix: GasUsed should be 0 not null
aatifsyed Sep 1, 2023
47c1996
run: env ofile=this-branch.json ./make-output.bash
aatifsyed Sep 1, 2023
f0d9df4
run: cp /home/aatif/scratch/lotus/output-v1.23.3.json reference.json
aatifsyed Sep 1, 2023
50b4bc8
run: cargo run --example clean-json reference.json
aatifsyed Sep 1, 2023
d648e98
run: rm -rf examples/ make-output.bash original.json reference.json t…
aatifsyed Sep 1, 2023
2d4af08
run: rm big-gas-limits.patch
aatifsyed Sep 1, 2023
def619c
Merge remote-tracking branch 'origin/main' into aatifsyed/refactor-co…
aatifsyed Sep 4, 2023
fa061b6
refactor: cleanup returns
aatifsyed Sep 5, 2023
7bc7ec9
wip: callback attempt 2
aatifsyed Sep 5, 2023
e553de9
wip: more bad time refactoring callbacks
aatifsyed Sep 5, 2023
aa04e81
refactor: callback
aatifsyed Sep 5, 2023
8ddc7b9
refactor: callback ty
aatifsyed Sep 5, 2023
7bb0183
refactor: callback args, what explicit means
aatifsyed Sep 5, 2023
9d2de00
refactor: cleanup comments and add tracking issues
aatifsyed Sep 5, 2023
901fba2
docs: changelog entry
aatifsyed Sep 5, 2023
0cfb650
docs: https://github.com/ChainSafe/forest/issues/3463
aatifsyed Sep 5, 2023
b236657
fix: shim::GasCharge.0 should not have been mode public
aatifsyed Sep 6, 2023
06abae5
fix: show EventsRoot, it may be important
aatifsyed Sep 6, 2023
b76be32
feat: shim for ExecutionEvents
aatifsyed Sep 6, 2023
8d67f71
wip
aatifsyed Sep 6, 2023
0b028b5
refactor: shim::ErrorNumber
aatifsyed Sep 6, 2023
3911ba9
refactor: use shim types
aatifsyed Sep 6, 2023
b8061a4
fix: bad re-export from previous branch
aatifsyed Sep 7, 2023
8983806
run: ./scripts/add_license.sh || true
aatifsyed Sep 7, 2023
4aeeb30
chore: spellcheck
aatifsyed Sep 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@

### Added

- [#3430](https://github.com/ChainSafe/forest/pull/3430): Add
`forest-tool snapshot compute-state ...` subcommand.
- [#3321](https://github.com/ChainSafe/forest/issues/3321): Support for
multi-threaded car-backed block stores.
- [#3316](https://github.com/ChainSafe/forest/pull/3316): Add
Expand Down
2 changes: 2 additions & 0 deletions src/chain/store/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::sync::Arc;
use crate::blocks::{BlockHeader, Tipset, TipsetKeys, TxMeta};
use crate::fil_cns;
use crate::interpreter::BlockMessages;
use crate::interpreter::VMTrace;
use crate::ipld::FrozenCids;
use crate::libp2p_bitswap::{BitswapStoreRead, BitswapStoreReadWrite};
use crate::message::{ChainMessage, Message as MessageTrait, SignedMessage};
Expand Down Expand Up @@ -292,6 +293,7 @@ where
&crate::shim::machine::MultiEngine::default(),
Arc::clone(&heaviest_tipset),
crate::state_manager::NO_CALLBACK,
VMTrace::NotTraced,
)
.map_err(|e| Error::Other(e.to_string()))?;
return Ok((heaviest_tipset, state));
Expand Down
111 changes: 89 additions & 22 deletions src/interpreter/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::blocks::Tipset;
use crate::chain::block_messages;
use crate::chain::index::ChainIndex;
use crate::chain::store::Error;
use crate::interpreter::{fvm2::ForestExternsV2, fvm3::ForestExterns as ForestExternsV3};
use crate::message::ChainMessage;
use crate::message::Message as MessageTrait;
use crate::networks::{ChainConfig, NetworkChain};
Expand Down Expand Up @@ -40,11 +41,9 @@ use fvm3::{
};
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::{to_vec, RawBytes};
use fvm_shared2::{clock::ChainEpoch, BLOCK_GAS_LIMIT};
use fvm_shared2::clock::ChainEpoch;
use num::Zero;

use crate::interpreter::{fvm2::ForestExternsV2, fvm3::ForestExterns as ForestExternsV3};

pub(in crate::interpreter) type ForestMachineV2<DB> =
DefaultMachine_v2<Arc<DB>, ForestExternsV2<DB>>;
pub(in crate::interpreter) type ForestMachineV3<DB> =
Expand All @@ -57,6 +56,9 @@ type ForestKernelV3<DB> =
type ForestExecutorV2<DB> = DefaultExecutor_v2<ForestKernelV2<DB>>;
type ForestExecutorV3<DB> = DefaultExecutor_v3<ForestKernelV3<DB>>;

/// Comes from <https://github.com/filecoin-project/lotus/blob/v1.23.2/chain/vm/fvm.go#L473>
const IMPLICIT_MESSAGE_GAS_LIMIT: i64 = i64::MAX / 2;

/// Contains all messages to process through the VM as well as miner information
/// for block rewards.
#[derive(Debug)]
Expand Down Expand Up @@ -159,6 +161,7 @@ where
timestamp,
}: ExecutionContext<DB>,
multi_engine: &MultiEngine,
enable_tracing: VMTrace,
) -> Result<Self, anyhow::Error> {
let network_version = chain_config.network_version(epoch);
if network_version >= NetworkVersion::V18 {
Expand All @@ -173,6 +176,8 @@ where
let mut context = config.for_epoch(epoch, timestamp, state_tree_root);
context.set_base_fee(base_fee.into());
context.set_circulating_supply(circ_supply.into());
context.tracing = enable_tracing.is_traced();

let fvm: ForestMachineV3<DB> = ForestMachineV3::new(
&context,
Arc::clone(&chain_index.db),
Expand All @@ -193,6 +198,8 @@ where
let mut context = config.for_epoch(epoch, state_tree_root);
context.set_base_fee(base_fee.into());
context.set_circulating_supply(circ_supply.into());
context.tracing = enable_tracing.is_traced();

let fvm: ForestMachineV2<DB> = ForestMachineV2::new(
&engine,
&context,
Expand Down Expand Up @@ -242,17 +249,15 @@ where
pub fn run_cron(
&mut self,
epoch: ChainEpoch,
callback: Option<
&mut impl FnMut(&Cid, &ChainMessage, &ApplyRet) -> Result<(), anyhow::Error>,
>,
) -> Result<(), anyhow::Error> {
callback: Option<impl FnMut(&MessageCallbackCtx) -> anyhow::Result<()>>,
) -> anyhow::Result<()> {
let cron_msg: Message = Message_v3 {
from: Address::SYSTEM_ACTOR.into(),
to: Address::CRON_ACTOR.into(),
// Epoch as sequence is intentional
sequence: epoch as u64,
// Arbitrarily large gas limit for cron (matching Lotus value)
gas_limit: BLOCK_GAS_LIMIT as u64 * 10000,
gas_limit: IMPLICIT_MESSAGE_GAS_LIMIT as u64,
method_num: cron::Method::EpochTick as u64,
params: Default::default(),
value: Default::default(),
Expand All @@ -267,8 +272,13 @@ where
anyhow::bail!("failed to apply block cron message: {}", err);
}

if let Some(callback) = callback {
callback(&(cron_msg.cid()?), &ChainMessage::Unsigned(cron_msg), &ret)?;
if let Some(mut callback) = callback {
callback(&MessageCallbackCtx {
cid: cron_msg.cid()?,
message: &ChainMessage::Unsigned(cron_msg),
apply_ret: &ret,
at: CalledAt::Cron,
})?;
}
Ok(())
}
Expand All @@ -279,9 +289,9 @@ where
&mut self,
messages: &[BlockMessages],
epoch: ChainEpoch,
mut callback: Option<
impl FnMut(&Cid, &ChainMessage, &ApplyRet) -> Result<(), anyhow::Error>,
>,
// note: we take &MessageCallbackCtx rather than MessageCallbackCtx<'_>
// because I'm not smart enough to make the second one work
mut callback: Option<impl FnMut(&MessageCallbackCtx) -> anyhow::Result<()>>,
) -> Result<Vec<Receipt>, anyhow::Error> {
let mut receipts = Vec::new();
let mut processed = HashSet::<Cid>::default();
Expand All @@ -290,22 +300,28 @@ where
let mut penalty = TokenAmount::zero();
let mut gas_reward = TokenAmount::zero();

let mut process_msg = |msg: &ChainMessage| -> Result<(), anyhow::Error> {
let cid = msg.cid()?;
let mut process_msg = |message: &ChainMessage| -> Result<(), anyhow::Error> {
let cid = message.cid()?;
// Ensure no duplicate processing of a message
if processed.contains(&cid) {
return Ok(());
}
let ret = self.apply_message(msg)?;
let ret = self.apply_message(message)?;

if let Some(cb) = &mut callback {
cb(&cid, msg, &ret)?;
cb(&MessageCallbackCtx {
cid,
message,
apply_ret: &ret,
at: CalledAt::Applied,
})?;
}

// Update totals
gas_reward += ret.miner_tip();
penalty += ret.penalty();
receipts.push(ret.msg_receipt());
let msg_receipt = ret.msg_receipt();
receipts.push(msg_receipt.clone());

// Add processed Cid to set of processed messages
processed.insert(cid);
Expand Down Expand Up @@ -335,20 +351,27 @@ where
ret.msg_receipt().exit_code()
);
}

if let Some(callback) = &mut callback {
callback(&(rew_msg.cid()?), &ChainMessage::Unsigned(rew_msg), &ret)?;
callback(&MessageCallbackCtx {
cid: rew_msg.cid()?,
message: &ChainMessage::Unsigned(rew_msg),
apply_ret: &ret,
at: CalledAt::Reward,
})?
}
}
}

if let Err(e) = self.run_cron(epoch, callback.as_mut()) {
tracing::error!("End of epoch cron failed to run: {}", e);
}

Ok(receipts)
}

/// Applies single message through VM and returns result from execution.
pub fn apply_implicit_message(&mut self, msg: &Message) -> Result<ApplyRet, anyhow::Error> {
pub fn apply_implicit_message(&mut self, msg: &Message) -> anyhow::Result<ApplyRet> {
// raw_length is not used for Implicit messages.
let raw_length = to_vec(msg).expect("encoding error").len();

Expand All @@ -375,7 +398,7 @@ where
/// Applies the state transition for a single message.
/// Returns `ApplyRet` structure which contains the message receipt and some
/// meta data.
pub fn apply_message(&mut self, msg: &ChainMessage) -> Result<ApplyRet, anyhow::Error> {
pub fn apply_message(&mut self, msg: &ChainMessage) -> anyhow::Result<ApplyRet> {
// Basic validity check
msg.message().check()?;

Expand Down Expand Up @@ -440,7 +463,7 @@ where
params,
// Epoch as sequence is intentional
sequence: epoch as u64,
gas_limit: 1 << 30,
gas_limit: IMPLICIT_MESSAGE_GAS_LIMIT as u64,
value: Default::default(),
version: Default::default(),
gas_fee_cap: Default::default(),
Expand All @@ -449,3 +472,47 @@ where
Ok(Some(rew_msg.into()))
}
}

#[derive(Debug, Clone, Copy)]
pub struct MessageCallbackCtx<'a> {
pub cid: Cid,
pub message: &'a ChainMessage,
pub apply_ret: &'a ApplyRet,
pub at: CalledAt,
}

#[derive(Debug, Clone, Copy)]
pub enum CalledAt {
Applied,
Reward,
Cron,
}

impl CalledAt {
/// Was [`VM::apply_message`] or [`VM::apply_implicit_message`] called?
pub fn apply_kind(&self) -> fvm3::executor::ApplyKind {
use fvm3::executor::ApplyKind;
match self {
CalledAt::Applied => ApplyKind::Explicit,
CalledAt::Reward | CalledAt::Cron => ApplyKind::Implicit,
}
}
}

/// Tracing a Filecoin VM has a performance penalty.
/// This controls whether a VM should be traced or not when it is created.
#[derive(Default, Clone, Copy)]
pub enum VMTrace {
/// Collect trace for the given operation
Traced,
/// Do not collect trace
#[default]
NotTraced,
}

impl VMTrace {
/// Should tracing be collected?
pub fn is_traced(&self) -> bool {
matches!(self, VMTrace::Traced)
}
}
2 changes: 1 addition & 1 deletion src/lotus_json/beacon_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl HasLotusJson for BeaconEntry {
type LotusJson = BeaconEntryLotusJson;

fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(json!({"Round": 0, "Data": ""}), BeaconEntry::default())]
vec![(json!({"Round": 0, "Data": null}), BeaconEntry::default())]
}

fn into_lotus_json(self) -> Self::LotusJson {
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/election_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl HasLotusJson for ElectionProof {
vec![(
json!({
"WinCount": 0,
"VRFProof": ""
"VRFProof": null
}),
ElectionProof::default(),
)]
Expand Down
20 changes: 15 additions & 5 deletions src/lotus_json/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ pub struct MessageLotusJson {
method: LotusJson<u64>,
#[serde(skip_serializing_if = "LotusJson::is_none", default)]
params: LotusJson<Option<RawBytes>>,
// This is a bit of a hack - `Message`s don't really store their CID, but they're
// serialized with it.
// However, getting a message's CID is fallible...
// So we keep this as an `Option`, and ignore it if it fails.
// We also ignore it when serializing from json.
// I wouldn't be surprised if this causes issues with arbitrary tests
#[serde(rename = "CID", skip_serializing_if = "LotusJson::is_none", default)]
cid: LotusJson<Option<Cid>>,
}
Expand All @@ -33,20 +39,24 @@ impl HasLotusJson for Message {
json!({
"From": "f00",
"GasFeeCap": "0",
"GasLimit": 0, // BUG?(aatifsyed)
"GasLimit": 0,
"GasPremium": "0",
"Method": 0,
"Nonce": 0,
"Params": "", // BUG?(aatifsyed)
"Params": null,
"To": "f00",
"Value": "0",
"Version": 0
"Version": 0,
"CID": {
"/": "bafy2bzaced3xdk2uf6azekyxgcttujvy3fzyeqmibtpjf2fxcpfdx2zcx4s3g"
}
}),
Message::default(),
)]
}

fn into_lotus_json(self) -> Self::LotusJson {
let cid = self.cid().ok();
let Self {
version,
from,
Expand All @@ -70,7 +80,7 @@ impl HasLotusJson for Message {
gas_premium: gas_premium.into(),
method: method_num.into(),
params: Some(params).into(),
cid: None.into(),
cid: cid.into(),
}
}

Expand All @@ -86,7 +96,7 @@ impl HasLotusJson for Message {
gas_premium,
method,
params,
cid: _ignored, // BUG?(aatifsyed)
cid: _ignored,
} = lotus_json;
Self {
version: version.into_inner(),
Expand Down
14 changes: 12 additions & 2 deletions src/lotus_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@
//! - Use destructuring to ensure exhaustiveness
//!
//! ### Optional fields
//! Optional fields must have the following annotations:
//! It's not clear if optional fields should be serialized as `null` or not.
//! See e.g `LotusJson<Receipt>`.
//!
//! For now, fields are recommended to have the following annotations:
//! ```rust,ignore
//! # struct Foo {
//! #[serde(skip_serializing_if = "LotusJson::is_none", default)]
Expand Down Expand Up @@ -371,4 +374,11 @@ macro_rules! lotus_json_with_self {
}
}

lotus_json_with_self!(u32, u64, i64, String, chrono::DateTime<chrono::Utc>);
lotus_json_with_self!(
u32,
u64,
i64,
String,
chrono::DateTime<chrono::Utc>,
serde_json::Value,
);
Loading
Loading