Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into hm/ci-test-lotus-1.27
Browse files Browse the repository at this point in the history
  • Loading branch information
hanabi1224 committed May 9, 2024
2 parents f891f9f + e5066ba commit 6857cf1
Show file tree
Hide file tree
Showing 40 changed files with 244 additions and 117 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
- [#4267](https://github.com/ChainSafe/forest/pull/4267) Fixed potential panics
in `forest-tool api compare`.

- [#4297](https://github.com/ChainSafe/forest/pull/4297) Fixed double decoding
of message in the `Filecoin.WalletSign` RPC method.

## Forest 0.17.2 "Dovakhin"

This is a **mandatory** release for all mainnet node operators. It changes the
Expand Down
32 changes: 32 additions & 0 deletions documentation/src/developer_documentation/rpc_api_compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,35 @@ Checklist for adding a new RPC method:
5. Implement Forest endpoint in `src/rpc/`, add it to the method list in
`src/rpc/mod.rs`
6. Verify that the test from step 4 shows `Valid` for Forest.

## Creating own miner for tests

Use commands along the lines of the following script to create a miner for
testing. Note that the `miner create` will take a while to complete.

```bash
#!/bin/bash
# Owner
# The owner keypair is provided by the miner ahead of registration and its public key associated with the miner address.
# The owner keypair can be used to administer a miner and withdraw funds.
OWNER=$(lotus wallet new bls)
WORKER=$(lotus wallet new bls)
SENDER=$(lotus wallet new bls)

# print the owner address and order the user to send FIL from faucet to it. Wait for the confirmation from the user.
echo "Owner: $OWNER"
echo "Please send some FIL to the owner address and press enter to continue. Ensure that that the transaction is confirmed."
read

# Send some FIL to the worker and sender from the owner address
lotus send --from $OWNER $WORKER 10
lotus send --from $OWNER $SENDER 10

echo "Wait till the funds are confirmed and press enter to continue."
read

lotus-shed miner create $SENDER $OWNER $WORKER 32GiB
```

Afterwards, use the `lotus wallet export` and `lotus wallet import` commands to
persist and restore the keys.
1 change: 1 addition & 0 deletions scripts/tests/api_compare/.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ CHAIN=calibnet
# The process is too lengthy to create the miner on the fly (needs to send FIL to the miner, wait for confirmations, etc)
# It's fine to use this miner for testing purposes, e.g., signing messages in tests.
MINER_ADDRESS=t0111551 # t2nfplhzpyeck5dcc4fokj5ar6nbs3mhbdmq6xu3q
MINER_WORKER_ADDRESS=t3sw466j35hqjbch5x7tcr7ona6idsgzypoturfci2ajqsfrrwhp7ty3ythtd7x646adaidnvxpdr5b2ftcciq
MINER_WORKER_KEY=7b2254797065223a22626c73222c22507269766174654b6579223a225a6c4c784f55666d666f44332b577a2f386175482f6b2f456f4b674443365365584256563447714c4c6d6b3d227d
3 changes: 2 additions & 1 deletion scripts/tests/api_compare/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ services:
--lotus $$LOTUS_API_INFO \
--n-tipsets 10 \
--filter-file /data/filter-list \
--miner-address ${MINER_ADDRESS}
--miner-address ${MINER_ADDRESS} \
--worker-address ${MINER_WORKER_ADDRESS}
api-compare-offline:
depends_on:
lotus-sync-wait:
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/snapshot_parity/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ services:
- |
set -euxo pipefail
lotus daemon --remove-existing-chain --import-snapshot $(ls /data/*.car.zst | tail -n 1) &
lotus wait-api --timeout 10m
lotus wait-api --timeout 20m
lotus sync wait
lotus chain export --tipset @$(ls /data/*.car.zst | tail -n 1 | grep -Eo '[0-9]+' | tail -n 1) --recent-stateroots ${EXPORT_EPOCHS} --skip-old-msgs /data/exported/lotus.car
kill -KILL $!
Expand Down
39 changes: 10 additions & 29 deletions src/blocks/tipset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,41 +515,25 @@ mod lotus_json {
use crate::blocks::{CachingBlockHeader, Tipset};
use crate::lotus_json::*;
use nunny::Vec as NonEmpty;
use schemars::{gen::SchemaGenerator, schema::Schema, JsonSchema};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use schemars::JsonSchema;
use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer};

use super::TipsetKey;

#[derive(Clone)]
pub struct TipsetLotusJson(Tipset);
#[derive(Clone, JsonSchema)]
#[schemars(rename = "Tipset")]
pub struct TipsetLotusJson(#[schemars(with = "TipsetLotusJsonInner")] Tipset);

impl JsonSchema for TipsetLotusJson {
fn schema_name() -> String {
String::from("TipsetLotusJson")
}
fn json_schema(gen: &mut SchemaGenerator) -> Schema {
// can't impl JsonSchema for NonEmpty...
#[derive(JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[allow(unused)]
struct Helper {
cids: LotusJson<TipsetKey>,
blocks: LotusJson<Vec<CachingBlockHeader>>,
height: LotusJson<i64>,
}
Helper::json_schema(gen)
}
}

// NOTE: keep this in sync with JsonSchema implementation above
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "Tipset")]
#[serde(rename_all = "PascalCase")]
struct TipsetLotusJsonInner {
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<TipsetKey>")]
cids: TipsetKey,
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<NonEmpty<CachingBlockHeader>>")]
blocks: NonEmpty<CachingBlockHeader>,
#[serde(with = "crate::lotus_json")]
height: i64,
}

Expand All @@ -564,10 +548,7 @@ mod lotus_json {
height: _ignored1,
} = Deserialize::deserialize(deserializer)?;

Ok(Self(Tipset {
headers: blocks,
key: Default::default(),
}))
Ok(Self(Tipset::new(blocks).map_err(D::Error::custom)?))
}
}

Expand Down
1 change: 1 addition & 0 deletions src/lotus_json/actor_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ::cid::Cid;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "ActorState")]
pub struct ActorStateLotusJson {
#[schemars(with = "LotusJson<Cid>")]
#[serde(with = "crate::lotus_json")]
Expand Down
15 changes: 11 additions & 4 deletions src/lotus_json/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use super::*;

use crate::shim::address::Address;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "Address")]
pub struct AddressLotusJson(
#[schemars(with = "String")]
#[serde(with = "crate::lotus_json::stringify")]
Address,
);

impl HasLotusJson for Address {
type LotusJson = Stringify<Address>;
type LotusJson = AddressLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(json!("f00"), Address::default())]
}

fn into_lotus_json(self) -> Self::LotusJson {
self.into()
AddressLotusJson(self)
}

fn from_lotus_json(Stringify(address): Self::LotusJson) -> Self {
fn from_lotus_json(AddressLotusJson(address): Self::LotusJson) -> Self {
address
}
}
6 changes: 2 additions & 4 deletions src/lotus_json/beacon_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::*;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "BeaconEntry")]
pub struct BeaconEntryLotusJson {
round: u64,
#[schemars(with = "LotusJson<Vec<u8>>")]
Expand All @@ -24,10 +25,7 @@ impl HasLotusJson for BeaconEntry {

fn into_lotus_json(self) -> Self::LotusJson {
let (round, data) = self.into_parts();
Self::LotusJson {
round,
data,
}
Self::LotusJson { round, data }
}

fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
Expand Down
14 changes: 11 additions & 3 deletions src/lotus_json/big_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@ use super::*;

use num::BigInt;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "BigInt")]
pub struct BigIntLotusJson(
#[schemars(with = "String")]
#[serde(with = "crate::lotus_json::stringify")]
BigInt,
);

impl HasLotusJson for BigInt {
type LotusJson = Stringify<BigInt>;
type LotusJson = BigIntLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
vec![(json!("1"), BigInt::from(1))]
}

fn into_lotus_json(self) -> Self::LotusJson {
self.into()
BigIntLotusJson(self)
}

fn from_lotus_json(Stringify(big_int): Self::LotusJson) -> Self {
fn from_lotus_json(BigIntLotusJson(big_int): Self::LotusJson) -> Self {
big_int
}
}
1 change: 1 addition & 0 deletions src/lotus_json/bit_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::*;
use fil_actors_shared::fvm_ipld_bitfield::{json::BitFieldJson, BitField};

#[derive(Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "BitField")]
pub struct BitFieldLotusJson(#[schemars(with = "Option<Vec<u8>>")] pub BitFieldJson);

impl Clone for BitFieldLotusJson {
Expand Down
1 change: 1 addition & 0 deletions src/lotus_json/block_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::blocks::{CachingBlockHeader, RawBlockHeader};

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "BlockHeader")]
pub struct BlockHeaderLotusJson {
#[schemars(with = "LotusJson<Address>")]
#[serde(with = "crate::lotus_json")]
Expand Down
10 changes: 6 additions & 4 deletions src/lotus_json/cid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
use super::*;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "Cid")]
pub struct CidLotusJsonGeneric<const S: usize> {
#[serde(rename = "/")]
slash: Stringify<::cid::CidGeneric<S>>,
#[schemars(with = "String")]
#[serde(rename = "/", with = "crate::lotus_json::stringify")]
slash: ::cid::CidGeneric<S>,
}

impl<const S: usize> HasLotusJson for ::cid::CidGeneric<S> {
Expand All @@ -18,12 +20,12 @@ impl<const S: usize> HasLotusJson for ::cid::CidGeneric<S> {
}

fn into_lotus_json(self) -> Self::LotusJson {
Self::LotusJson { slash: self.into() }
Self::LotusJson { slash: self }
}

fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
let Self::LotusJson { slash } = lotus_json;
slash.into_inner()
slash
}
}

Expand Down
1 change: 1 addition & 0 deletions src/lotus_json/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::*;

#[derive(Default, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "Claim")]
pub struct ClaimLotusJson {
#[schemars(with = "LotusJson<num::BigInt>")]
#[serde(with = "crate::lotus_json")]
Expand Down
1 change: 1 addition & 0 deletions src/lotus_json/election_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::*;

#[derive(Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "ElectionProof")]
pub struct ElectionProofLotusJson {
#[schemars(with = "LotusJson<VRFProof>")]
#[serde(with = "crate::lotus_json")]
Expand Down
1 change: 1 addition & 0 deletions src/lotus_json/gossip_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use ::cid::Cid;

#[derive(Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "GossipBlock")]
pub struct GossipBlockLotusJson {
#[schemars(with = "LotusJson<CachingBlockHeader>")]
#[serde(with = "crate::lotus_json")]
Expand Down
1 change: 1 addition & 0 deletions src/lotus_json/ipld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use libipld::{ipld, Ipld};
use serde::de;

#[derive(Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "Ipld")]
pub struct IpldLotusJson(
#[serde(with = "self")]
#[schemars(with = "serde_json::Value")] // opt-out of JsonSchema for now
Expand Down
1 change: 1 addition & 0 deletions src/lotus_json/key_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{key_management::KeyInfo, shim::crypto::SignatureType};

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "KeyInfo")]
pub struct KeyInfoLotusJson {
#[schemars(with = "LotusJson<SignatureType>")]
#[serde(with = "crate::lotus_json")]
Expand Down
1 change: 1 addition & 0 deletions src/lotus_json/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use fvm_ipld_encoding::RawBytes;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "Message")]
pub struct MessageLotusJson {
version: u64,
#[schemars(with = "LotusJson<Address>")]
Expand Down
27 changes: 0 additions & 27 deletions src/lotus_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,33 +467,6 @@ impl<T> LotusJson<T> {
}
}

/// A struct that is (de) serialized through its [`Display`] and [`FromStr`] implementations.
#[derive(Serialize, Deserialize, From, Default)]
#[serde(bound = "T: Display + FromStr, T::Err: Display")]
pub struct Stringify<T>(#[serde(with = "stringify")] pub T);

impl<T> Stringify<T> {
pub fn into_inner(self) -> T {
self.0
}
}

impl<T> JsonSchema for Stringify<T> {
fn schema_name() -> String {
String::schema_name()
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
String::json_schema(gen)
}
}

impl<T: Clone> Clone for Stringify<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}

macro_rules! lotus_json_with_self {
($($domain_ty:ty),* $(,)?) => {
$(
Expand Down
1 change: 1 addition & 0 deletions src/lotus_json/po_st_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::*;

#[derive(Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "PoStProof")]
pub struct PoStProofLotusJson {
#[schemars(with = "LotusJson<RegisteredPoStProof>")]
#[serde(with = "crate::lotus_json")]
Expand Down
1 change: 1 addition & 0 deletions src/lotus_json/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::shim::executor::Receipt;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "Receipt")]
pub struct ReceiptLotusJson {
exit_code: u32,
#[schemars(with = "LotusJson<RawBytes>")]
Expand Down
7 changes: 2 additions & 5 deletions src/lotus_json/sector_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ::cid::Cid;

#[derive(Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "SectorInfo")]
pub struct SectorInfoLotusJson {
#[schemars(with = "LotusJson<RegisteredSealProof>")]
#[serde(with = "crate::lotus_json")]
Expand Down Expand Up @@ -57,10 +58,6 @@ impl HasLotusJson for SectorInfo {
sector_number,
sealed_c_i_d,
} = lotus_json;
Self::new(
seal_proof.into(),
sector_number,
sealed_c_i_d,
)
Self::new(seal_proof.into(), sector_number, sealed_c_i_d)
}
}
1 change: 1 addition & 0 deletions src/lotus_json/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::shim::crypto::{Signature, SignatureType};

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "Signature")]
pub struct SignatureLotusJson {
#[schemars(with = "LotusJson<SignatureType>")]
#[serde(with = "crate::lotus_json")]
Expand Down
Loading

0 comments on commit 6857cf1

Please sign in to comment.