Skip to content

Commit

Permalink
Sync with latest solidity (#415)
Browse files Browse the repository at this point in the history
* sync with latest solidity

* remove flaky tests and reload config

* format code

* fix latest changes

* format code
  • Loading branch information
cryptoAtwill authored Dec 21, 2023
1 parent 4f34e4b commit 0885603
Show file tree
Hide file tree
Showing 20 changed files with 397 additions and 533 deletions.
263 changes: 126 additions & 137 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions ipc/cli/src/commands/crossmsg/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ impl CommandLineHandler for Release {
Some(address) => Some(require_fil_addr_from_str(address)?),
None => None,
};
let fee = match &arguments.fee {
Some(f) => Some(f64_to_token_amount(*f)?),
None => None,
};

println!(
"release performed in epoch: {:?}",
Expand All @@ -50,7 +46,6 @@ impl CommandLineHandler for Release {
from,
to,
f64_to_token_amount(arguments.amount)?,
fee,
)
.await?,
);
Expand All @@ -74,8 +69,6 @@ pub(crate) struct ReleaseArgs {
pub to: Option<String>,
#[arg(long, short, help = "The subnet to release funds from")]
pub subnet: String,
#[arg(long, help = "The fee to pay for the cross-net message, in whole FIL")]
pub fee: Option<f64>,
#[arg(help = "The amount to release in FIL, in whole FIL")]
pub amount: f64,
}
Expand Down
29 changes: 26 additions & 3 deletions ipc/cli/src/commands/subnet/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
use async_trait::async_trait;
use clap::Args;
use fvm_shared::address::Address;
use fvm_shared::clock::ChainEpoch;
use ipc_sdk::subnet::{PermissionMode, SupplyKind, SupplySource};
use ipc_sdk::subnet_id::SubnetID;
use std::fmt::Debug;
use std::str::FromStr;
Expand All @@ -30,6 +32,16 @@ impl CreateSubnet {
None => None,
};

let permission_mode = PermissionMode::try_from(arguments.permission_mode)?;
let token_address = if let Some(addr) = &arguments.supply_source_address {
Some(Address::from_str(addr)?)
} else {
None
};
let supply_source = SupplySource {
kind: SupplyKind::try_from(arguments.supply_source_kind)?,
token_address,
};
let addr = provider
.create_subnet(
from,
Expand All @@ -41,7 +53,8 @@ impl CreateSubnet {
.active_validators_limit
.unwrap_or(DEFAULT_ACTIVE_VALIDATORS),
f64_to_token_amount(arguments.min_cross_msg_fee)?,
arguments.permissioned,
permission_mode,
supply_source,
)
.await?;

Expand Down Expand Up @@ -99,7 +112,17 @@ pub struct CreateSubnetArgs {
pub min_cross_msg_fee: f64,
#[arg(
long,
help = "Deploy static network where validators can't join in a permissionless manner"
help = "The permission mode for the subnet, collateral(0), federated(1) and static(2)"
)]
pub permission_mode: u8,
#[arg(
long,
help = "The kind of supply source of a subnet on its parent subnet, native(0), erc20(1)"
)]
pub supply_source_kind: u8,
#[arg(
long,
help = "The address of supply source of a subnet on its parent subnet. None if kind is native"
)]
pub permissioned: bool,
pub supply_source_address: Option<String>,
}
4 changes: 2 additions & 2 deletions ipc/cli/src/commands/subnet/list_subnets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl CommandLineHandler for ListSubnets {

for (_, s) in ls.iter() {
println!(
"{} - status: {:?}, collateral: {} FIL, circ.supply: {} FIL, genesis: {}",
s.id, s.status, s.stake, s.circ_supply, s.genesis_epoch
"{} - collateral: {} FIL, circ.supply: {} FIL, genesis: {}",
s.id, s.stake, s.circ_supply, s.genesis_epoch
);
}

Expand Down
51 changes: 27 additions & 24 deletions ipc/provider/src/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,24 @@ impl<T: BottomUpCheckpointRelayer + Send + Sync + 'static> BottomUpCheckpointMan
let bundle = self.child_handler.checkpoint_bundle_at(height).await?;
log::debug!("bottom up bundle: {bundle:?}");

let epoch = self
.parent_handler
.submit_checkpoint(submitter, bundle)
.await
.map_err(|e| anyhow!("cannot submit bottom up checkpoint due to: {e:}"))?;
log::info!(
"submitted bottom up checkpoint({}) in parent at height {}",
height,
epoch
);

Ok(())
todo!("implement submit checkpoint")

// let epoch = self
// .parent_handler
// .submit_checkpoint(submitter, bundle)
// .await
// .map_err(|e| anyhow!("cannot submit bottom up checkpoint due to: {e:}"))?;
// log::info!(
// "submitted bottom up checkpoint({}) in parent at height {}",
// height,
// epoch
// );
//
// Ok(())
}

/// Checks if the relayer has already submitted at the next submission epoch, if not it submits it.
async fn submit_next_epoch(&self, submitter: &Address) -> Result<()> {
async fn submit_next_epoch(&self, _submitter: &Address) -> Result<()> {
let next_submission_height = self.next_submission_height().await?;
let current_height = self.child_handler.current_epoch().await?;
let finalized_height = max(1, current_height - self.finalization_blocks);
Expand Down Expand Up @@ -201,17 +203,18 @@ impl<T: BottomUpCheckpointRelayer + Send + Sync + 'static> BottomUpCheckpointMan
.await?;
log::debug!("bottom up bundle: {bundle:?}");

let epoch = self
.parent_handler
.submit_checkpoint(submitter, bundle)
.await
.map_err(|e| anyhow!("cannot submit bottom up checkpoint due to: {e:}"))?;

log::info!(
"submitted bottom up checkpoint({}) in parent at height {}",
event.height,
epoch
);
todo!("implement submiet checkpoint")
// let epoch = self
// .parent_handler
// .submit_checkpoint(submitter, bundle)
// .await
// .map_err(|e| anyhow!("cannot submit bottom up checkpoint due to: {e:}"))?;
//
// log::info!(
// "submitted bottom up checkpoint({}) in parent at height {}",
// event.height,
// epoch
// );
}
}

Expand Down
2 changes: 0 additions & 2 deletions ipc/provider/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//! [`Config`] struct.
pub mod deserialize;
mod reload;
pub mod subnet;

pub mod serialize;
Expand All @@ -20,7 +19,6 @@ use std::path::Path;
use anyhow::Result;
use deserialize::deserialize_subnets_from_vec;
use ipc_sdk::subnet_id::SubnetID;
pub use reload::ReloadableConfig;
use serde::{Deserialize, Serialize};
use serialize::serialize_subnets_to_str;
pub use subnet::Subnet;
Expand Down
77 changes: 0 additions & 77 deletions ipc/provider/src/config/reload.rs

This file was deleted.

78 changes: 1 addition & 77 deletions ipc/provider/src/config/tests.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// Copyright 2022-2023 Protocol Labs
// SPDX-License-Identifier: MIT
use std::io::Write;
use std::str::FromStr;
use std::sync::{Arc, Condvar, Mutex};

use fvm_shared::address::Address;
use indoc::formatdoc;
use ipc_sdk::subnet_id::SubnetID;
use primitives::EthAddress;
use tempfile::NamedTempFile;
use url::Url;

use crate::config::{Config, ReloadableConfig};
use crate::config::Config;

// Arguments for the config's fields
const REPO_PATH: &str = "~/.ipc";
Expand All @@ -20,61 +17,6 @@ const CHILD_AUTH_TOKEN: &str = "CHILD_AUTH_TOKEN";
const PROVIDER_HTTP: &str = "http://127.0.0.1:3030/rpc/v1";
const ETH_ADDRESS: &str = "0x6be1ccf648c74800380d0520d797a170c808b624";

#[tokio::test]
async fn reload_works() {
let config_str = config_str();

let mut file = NamedTempFile::new().unwrap();
let path = file
.path()
.as_os_str()
.to_os_string()
.into_string()
.unwrap();

file.write_all(config_str.as_bytes()).unwrap();

let h = Arc::new(ReloadableConfig::new(path.clone()).unwrap());
let original_config = h.get_config();

// A simple barrier implementation for testing.
// Refer to: https://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/std/sync/struct.Condvar.html#examples
// Only when the main thread has created a new subscriber then we trigger then update the config file.
// This way, we dont miss the update and stuck the main thread.
let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair2 = pair.clone();
let h_cloned = h.clone();
tokio::spawn(async move {
{
let (lock, cvar) = &*pair;
let mut started = lock.lock().unwrap();
while !*started {
started = cvar.wait(started).unwrap();
}
};

let config_str = config_str_diff_addr();

let mut file = file.reopen().unwrap();
file.write_all(config_str.as_bytes()).unwrap();

h_cloned.set_path(path);
h_cloned.reload().await.unwrap();
});

let mut rx = h.new_subscriber();
{
let (lock, cvar) = &*pair2;
let mut started = lock.lock().unwrap();
*started = true;
cvar.notify_one();
}
rx.recv().await.unwrap();

let updated_config = h.get_config();
assert_ne!(updated_config.keystore_path, original_config.keystore_path,);
}

#[test]
fn check_keystore_config() {
let config = read_config();
Expand Down Expand Up @@ -118,24 +60,6 @@ fn config_str() -> String {
)
}

fn config_str_diff_addr() -> String {
formatdoc!(
r#"
repo_path = "~/.ipc2"
[[subnets]]
id = "{CHILD_ID}"
[subnets.config]
network_type = "fevm"
auth_token = "{CHILD_AUTH_TOKEN}"
provider_http = "{PROVIDER_HTTP}"
registry_addr = "{ETH_ADDRESS}"
gateway_addr = "{ETH_ADDRESS}"
"#
)
}

fn read_config() -> Config {
Config::from_toml_str(config_str().as_str()).unwrap()
}
12 changes: 0 additions & 12 deletions ipc/provider/src/jsonrpc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ use crate::jsonrpc::{JsonRpcClient, JsonRpcClientImpl, NO_PARAMS};
const HTTP_ENDPOINT: &str = "https://api.node.glif.io/rpc/v0";
const WS_ENDPOINT: &str = "wss://wss.node.glif.io/apigw/lotus/rpc/v0";

#[tokio::test]
async fn test_request() {
let url = Url::parse(HTTP_ENDPOINT).unwrap();
let client = JsonRpcClientImpl::new(url, None);
let response = client
.request::<serde_json::Value>("Filecoin.ChainHead", NO_PARAMS)
.await
.unwrap();
assert!(response.get("Blocks").is_some());
assert!(response.get("Height").is_some());
}

#[tokio::test]
async fn test_request_error() {
let url = Url::parse(HTTP_ENDPOINT).unwrap();
Expand Down
Loading

0 comments on commit 0885603

Please sign in to comment.