Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions scripts/tests/api_compare/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ services:
- RUST_LOG=info,forest::tool::subcommands=debug
- FOREST_RPC_DEFAULT_TIMEOUT=120
- FIL_PROOFS_PARAMETER_CACHE=${FIL_PROOFS_PARAMETER_CACHE}
- FOREST_STRICT_JSON=1
entrypoint: ["/bin/bash", "-c"]
user: 0:0
command:
Expand Down Expand Up @@ -310,6 +311,7 @@ services:
- RUST_LOG=info,forest::tool::subcommands=debug
- FOREST_RPC_DEFAULT_TIMEOUT=120
- FIL_PROOFS_PARAMETER_CACHE=${FIL_PROOFS_PARAMETER_CACHE}
- FOREST_STRICT_JSON=1
entrypoint: ["/bin/bash", "-c"]
user: 0:0
command:
Expand Down Expand Up @@ -379,6 +381,7 @@ services:
- RUST_LOG=info,forest::tool::subcommands=debug
- FOREST_RPC_DEFAULT_TIMEOUT=120
- FIL_PROOFS_PARAMETER_CACHE=${FIL_PROOFS_PARAMETER_CACHE}
- FOREST_STRICT_JSON=1
entrypoint: ["/bin/bash", "-c"]
user: 0:0
command:
Expand Down
17 changes: 16 additions & 1 deletion src/lotus_json/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::*;

use crate::shim::{address::Address, econ::TokenAmount, message::Message};
use fvm_ipld_encoding::RawBytes;
use ::cid::Cid;

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
Expand Down Expand Up @@ -40,13 +41,23 @@ pub struct MessageLotusJson {
default
)]
params: Option<RawBytes>,
#[schemars(with = "LotusJson<Option<Cid>>")]
#[serde(
with = "crate::lotus_json",
rename = "CID",
default,
skip_serializing_if = "Option::is_none"
)]
cid: Option<Cid>,
}

impl HasLotusJson for Message {
type LotusJson = MessageLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
let msg = Message::default();
let cid = msg.cid();
vec![(
json!({
"From": "f00",
Expand All @@ -59,12 +70,14 @@ impl HasLotusJson for Message {
"To": "f00",
"Value": "0",
"Version": 0,
"CID": { "/": cid.to_string() },
}),
Message::default(),
msg,
)]
}

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

Expand All @@ -103,6 +117,7 @@ impl HasLotusJson for Message {
gas_premium,
method,
params,
cid: _,
} = lotus_json;
Self {
version,
Expand Down
5 changes: 4 additions & 1 deletion src/lotus_json/signed_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ impl HasLotusJson for SignedMessage {

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
let msg = Message::default();
let msg_cid = msg.cid();
vec![(
json!({
"Message": {
Expand All @@ -52,14 +54,15 @@ impl HasLotusJson for SignedMessage {
"To": "f00",
"Value": "0",
"Version": 0,
"CID": { "/": msg_cid.to_string() },
},
"Signature": {"Type": 2, "Data": "aGVsbG8gd29ybGQh"},
"CID": {
"/": "bafy2bzaced3xdk2uf6azekyxgcttujvy3fzyeqmibtpjf2fxcpfdx2zcx4s3g"
},
}),
SignedMessage {
message: Message::default(),
message: msg,
signature: Signature {
sig_type: crate::shim::crypto::SignatureType::Bls,
bytes: Vec::from_iter(*b"hello world!"),
Expand Down
21 changes: 3 additions & 18 deletions src/rpc/methods/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl RpcMethod<1> for ChainGetMessage {
const DESCRIPTION: Option<&'static str> = Some("Returns the message with the specified CID.");

type Params = (Cid,);
type Ok = FlattenedApiMessage;
type Ok = Message;

async fn handle(
ctx: Ctx<impl Blockstore>,
Expand All @@ -193,13 +193,10 @@ impl RpcMethod<1> for ChainGetMessage {
.store()
.get_cbor(&message_cid)?
.with_context(|| format!("can't find message with cid {message_cid}"))?;
let message = match chain_message {
Ok(match chain_message {
ChainMessage::Signed(m) => Arc::unwrap_or_clone(m).into_message(),
ChainMessage::Unsigned(m) => Arc::unwrap_or_clone(m),
};

let cid = message.cid();
Ok(FlattenedApiMessage { message, cid })
})
}
}

Expand Down Expand Up @@ -1511,18 +1508,6 @@ pub struct ApiMessage {

lotus_json_with_self!(ApiMessage);

#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug, Eq, PartialEq)]
pub struct FlattenedApiMessage {
#[serde(flatten, with = "crate::lotus_json")]
#[schemars(with = "LotusJson<Message>")]
pub message: Message,
#[serde(rename = "CID", with = "crate::lotus_json")]
#[schemars(with = "LotusJson<Cid>")]
pub cid: Cid,
}

lotus_json_with_self!(FlattenedApiMessage);

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct ForestChainExportParams {
pub version: FilecoinSnapshotVersion,
Expand Down
3 changes: 3 additions & 0 deletions src/rpc/methods/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl RpcMethod<0> for Version {
// For the API v0, we don't support it but it should be `1.5.0`.
api_version: ShiftingVersion::new(2, 3, 0),
block_delay: ctx.chain_config().block_delay_secs,
agent: None,
})
}
}
Expand Down Expand Up @@ -106,6 +107,8 @@ pub struct PublicVersion {
#[serde(rename = "APIVersion")]
pub api_version: ShiftingVersion,
pub block_delay: u32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub agent: Option<String>,
}
lotus_json_with_self!(PublicVersion);

Expand Down
2 changes: 2 additions & 0 deletions src/rpc/methods/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4502,6 +4502,8 @@ mod test {
invoked_actor: None,
gas_charges: vec![],
subcalls: vec![],
logs: vec![],
ipld_ops: vec![],
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/rpc/methods/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use super::state::InvocResult;
use crate::blocks::Tipset;
use crate::chain::{BASE_FEE_MAX_CHANGE_DENOM, BLOCK_GAS_TARGET};
use crate::message::{ChainMessage, MessageRead as _, MessageReadWrite as _, SignedMessage};
use crate::rpc::chain::FlattenedApiMessage;
use crate::rpc::{ApiPaths, Ctx, Permission, RpcMethod, error::ServerError, types::*};
use crate::shim::executor::ApplyRet;
use crate::shim::{
Expand Down Expand Up @@ -305,16 +304,14 @@ impl RpcMethod<3> for GasEstimateMessageGas {
Some("Returns the estimated gas for the given parameters.");

type Params = (Message, Option<MessageSendSpec>, ApiTipsetKey);
type Ok = FlattenedApiMessage;
type Ok = Message;

async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(msg, spec, tsk): Self::Params,
_: &http::Extensions,
) -> Result<Self::Ok, ServerError> {
let message = estimate_message_gas(&ctx, msg, spec, tsk).await?;
let cid = message.cid();
Ok(FlattenedApiMessage { message, cid })
estimate_message_gas(&ctx, msg, spec, tsk).await
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/rpc/methods/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3172,6 +3172,7 @@ impl RpcMethod<0> for StateGetNetworkParams {
fork_upgrade_params: ForkUpgradeParams::try_from(config)
.context("Failed to get fork upgrade params")?,
eip155_chain_id: config.eth_chain_id,
genesis_timestamp: ctx.chain_store().genesis_block_header().timestamp,
};

Ok(params)
Expand All @@ -3190,6 +3191,7 @@ pub struct NetworkParams {
fork_upgrade_params: ForkUpgradeParams,
#[serde(rename = "Eip155ChainID")]
eip155_chain_id: EthChainId,
genesis_timestamp: u64,
}

lotus_json_with_self!(NetworkParams);
Expand Down Expand Up @@ -3229,7 +3231,7 @@ pub struct ForkUpgradeParams {
upgrade_teep_height: ChainEpoch,
upgrade_tock_height: ChainEpoch,
upgrade_golden_week_height: ChainEpoch,
//upgrade_xxx_height: ChainEpoch,
upgrade_xx_height: ChainEpoch,
}

impl TryFrom<&ChainConfig> for ForkUpgradeParams {
Expand Down Expand Up @@ -3279,6 +3281,7 @@ impl TryFrom<&ChainConfig> for ForkUpgradeParams {
upgrade_tock_height: get_height(Tock)?,
upgrade_golden_week_height: get_height(GoldenWeek)?,
//upgrade_firehorse_height: get_height(FireHorse)?,
upgrade_xx_height: 999_999_999_999_999,
})
}
}
Expand Down
65 changes: 63 additions & 2 deletions src/rpc/methods/state/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ use crate::shim::{
use cid::Cid;
use fvm_ipld_encoding::RawBytes;
use num::Zero as _;
use schemars::JsonSchema;
use schemars::{JsonSchema, Schema, SchemaGenerator};
use serde::{Deserialize, Serialize};
use serde_with::{DeserializeFromStr, SerializeDisplay};

#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, PartialEq)]
#[serde(rename_all = "PascalCase")]
Expand Down Expand Up @@ -110,6 +111,51 @@ pub struct MessageGasCost {

lotus_json_with_self!(MessageGasCost);

/// IPLD operation kind for [`TraceIpld`].
#[derive(
Debug,
Clone,
PartialEq,
Eq,
SerializeDisplay,
DeserializeFromStr,
strum::Display,
strum::EnumString,
)]
#[strum(serialize_all = "PascalCase")]
pub enum TraceIpldOp {
Get,
Put,
#[strum(to_string = "Unknown", default)]
Unknown(String),
}

impl JsonSchema for TraceIpldOp {
fn schema_name() -> std::borrow::Cow<'static, str> {
"TraceIpldOp".into()
}

fn json_schema(_: &mut SchemaGenerator) -> Schema {
schemars::json_schema!({
"type": "string",
"enum": ["Get", "Put", "Unknown"],
})
}
}

/// IPLD operation details attached to an [`ExecutionTrace`].
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct TraceIpld {
pub op: TraceIpldOp,
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<Cid>")]
pub cid: Cid,
pub size: u64,
}

lotus_json_with_self!(TraceIpld);

impl MessageGasCost {
fn is_zero_cost(&self) -> bool {
self.base_fee_burn.is_zero()
Expand Down Expand Up @@ -139,7 +185,7 @@ impl MessageGasCost {
}
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct ExecutionTrace {
pub msg: MessageTrace,
Expand All @@ -149,6 +195,21 @@ pub struct ExecutionTrace {
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<Vec<ExecutionTrace>>")]
pub subcalls: Vec<ExecutionTrace>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub logs: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub ipld_ops: Vec<TraceIpld>,
}

impl PartialEq for ExecutionTrace {
/// Ignore [`Self::logs`] and [`Self::ipld_ops`] as they are implementation-dependent
fn eq(&self, other: &Self) -> bool {
self.msg == other.msg
&& self.msg_rct == other.msg_rct
&& self.invoked_actor == other.invoked_actor
&& self.gas_charges == other.gas_charges
&& self.subcalls == other.subcalls
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

impl ExecutionTrace {
Expand Down
Loading
Loading