Skip to content

Commit

Permalink
Merge branch 'mirroring' into marko-runs-on-change
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-k0 authored Jul 1, 2024
2 parents edff0d8 + f4ad279 commit 2dca190
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 44 deletions.
8 changes: 1 addition & 7 deletions Cargo.Bazel.Fuzzing.json.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "1fad9b01754dfc8ab5ab938fd7be19e742886c39dc6ca6831e681dd9402ab23c",
"checksum": "d3868993e9229f3511e484bd4c963de0f56ce3d7e0b84714e53f16117cdc2e0e",
"crates": {
"abnf 0.12.0": {
"name": "abnf",
Expand Down Expand Up @@ -17174,10 +17174,6 @@
"id": "escargot 0.5.8",
"target": "escargot"
},
{
"id": "ethabi 18.0.0",
"target": "ethabi"
},
{
"id": "ethers-core 2.0.10",
"target": "ethers_core"
Expand Down Expand Up @@ -20467,7 +20463,6 @@
],
"crate_features": {
"common": [
"default",
"full-serde",
"once_cell",
"regex",
Expand Down Expand Up @@ -77129,7 +77124,6 @@
"either 1.9.0",
"erased-serde 0.3.31",
"escargot 0.5.8",
"ethabi 18.0.0",
"ethers-core 2.0.10",
"ethnum 1.4.0",
"exec 0.3.1",
Expand Down
1 change: 0 additions & 1 deletion Cargo.Bazel.Fuzzing.toml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2939,7 +2939,6 @@ dependencies = [
"either",
"erased-serde",
"escargot",
"ethabi",
"ethers-core",
"ethnum",
"exec",
Expand Down
8 changes: 1 addition & 7 deletions Cargo.Bazel.json.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "26f9d3c20340bdce0d732a7492a82ee00e59e45663d0c847dcb88caab0e3a92f",
"checksum": "74c8f9b45c9788e4a08a17fa88e5161de167b65c0f5122773922852e3c55abbd",
"crates": {
"abnf 0.12.0": {
"name": "abnf",
Expand Down Expand Up @@ -17007,10 +17007,6 @@
"id": "escargot 0.5.7",
"target": "escargot"
},
{
"id": "ethabi 18.0.0",
"target": "ethabi"
},
{
"id": "ethers-core 2.0.8",
"target": "ethers_core"
Expand Down Expand Up @@ -20321,7 +20317,6 @@
],
"crate_features": {
"common": [
"default",
"full-serde",
"once_cell",
"regex",
Expand Down Expand Up @@ -77280,7 +77275,6 @@
"either 1.8.1",
"erased-serde 0.3.28",
"escargot 0.5.7",
"ethabi 18.0.0",
"ethers-core 2.0.8",
"ethnum 1.3.2",
"exec 0.3.1",
Expand Down
1 change: 0 additions & 1 deletion Cargo.Bazel.toml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2929,7 +2929,6 @@ dependencies = [
"either",
"erased-serde",
"escargot",
"ethabi",
"ethers-core",
"ethnum",
"exec",
Expand Down
3 changes: 0 additions & 3 deletions bazel/external_crates.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,6 @@ def external_crates_repository(name, cargo_lockfile, lockfile, sanitizers_enable
version = "^0.5.7",
features = ["print"],
),
"ethabi": crate.spec(
version = "^18.0.0",
),
"ethers-core": crate.spec(
version = "^2.0.7",
),
Expand Down
20 changes: 12 additions & 8 deletions packages/pocket-ic/src/common/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use reqwest::Response;
use schemars::JsonSchema;
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::path::PathBuf;

pub type InstanceId = usize;
Expand Down Expand Up @@ -218,7 +218,7 @@ pub struct RawCycles {
pub cycles: u128,
}

#[derive(Clone, Serialize, Eq, PartialEq, Deserialize, Debug, JsonSchema)]
#[derive(Clone, Serialize, Eq, PartialEq, Ord, PartialOrd, Deserialize, Debug, JsonSchema)]
pub struct RawCanisterId {
// raw bytes of the principal
#[serde(deserialize_with = "base64::deserialize")]
Expand Down Expand Up @@ -318,7 +318,9 @@ pub mod base64 {

// ================================================================================================================= //

#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema)]
#[derive(
Debug, Clone, Copy, Eq, Hash, PartialEq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema,
)]
pub enum SubnetKind {
Application,
Bitcoin,
Expand Down Expand Up @@ -482,7 +484,9 @@ impl Default for SubnetSpec {
}

/// Specifies instruction limits for canister execution on this subnet.
#[derive(Debug, Clone, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema)]
#[derive(
Debug, Clone, Eq, Hash, PartialEq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema,
)]
pub enum SubnetInstructionConfig {
/// Use default instruction limits as in production.
Production,
Expand Down Expand Up @@ -597,7 +601,7 @@ impl ExtendedSubnetConfigSet {
}

/// Configuration details for a subnet, returned by PocketIc server
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema)]
pub struct SubnetConfig {
pub subnet_kind: SubnetKind,
/// Instruction limits for canister execution on this subnet.
Expand All @@ -608,14 +612,14 @@ pub struct SubnetConfig {
pub canister_ranges: Vec<CanisterIdRange>,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema)]
pub struct CanisterIdRange {
pub start: RawCanisterId,
pub end: RawCanisterId,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct Topology(pub HashMap<SubnetId, SubnetConfig>);
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema)]
pub struct Topology(pub BTreeMap<SubnetId, SubnetConfig>);

impl Topology {
pub fn get_app_subnets(&self) -> Vec<SubnetId> {
Expand Down
14 changes: 5 additions & 9 deletions packages/pocket-ic/src/nonblocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ pub struct PocketIc {
// how long a get/post request may retry or poll
max_request_time_ms: Option<u64>,
http_gateway: Option<HttpGatewayInfo>,
topology: Topology,
server_url: Url,
reqwest_client: reqwest::Client,
_log_guard: Option<WorkerGuard>,
Expand Down Expand Up @@ -113,7 +112,7 @@ impl PocketIc {
let log_guard = setup_tracing(parent_pid);

let reqwest_client = reqwest::Client::new();
let (instance_id, topology) = match reqwest_client
let instance_id = match reqwest_client
.post(server_url.join("instances").unwrap())
.json(&config)
.send()
Expand All @@ -123,10 +122,7 @@ impl PocketIc {
.await
.expect("Could not parse response for create instance request")
{
CreateInstanceResponse::Created {
instance_id,
topology,
} => (instance_id, topology),
CreateInstanceResponse::Created { instance_id, .. } => instance_id,
CreateInstanceResponse::Error { message } => panic!("{}", message),
};
debug!("instance_id={} New instance created.", instance_id);
Expand All @@ -135,7 +131,6 @@ impl PocketIc {
instance_id,
max_request_time_ms,
http_gateway: None,
topology,
server_url,
reqwest_client,
_log_guard: log_guard,
Expand All @@ -144,7 +139,8 @@ impl PocketIc {

/// Returns the topology of the different subnets of this PocketIC instance.
pub async fn topology(&self) -> Topology {
self.topology.clone()
let endpoint = "read/topology";
self.get(endpoint).await
}

/// Upload and store a binary blob to the PocketIC server.
Expand Down Expand Up @@ -373,7 +369,7 @@ impl PocketIc {
/// Get the root key of this IC instance. Returns `None` if the IC has no NNS subnet.
#[instrument(skip(self), fields(instance_id=self.instance_id))]
pub async fn root_key(&self) -> Option<Vec<u8>> {
let subnet_id = self.topology.get_nns()?;
let subnet_id = self.topology().await.get_nns()?;
let subnet_id: RawSubnetId = subnet_id.into();
let endpoint = "read/pub_key";
let res = self.post::<Vec<u8>, _>(endpoint, subnet_id).await;
Expand Down
2 changes: 0 additions & 2 deletions rs/ethereum/cketh/minter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ rust_test(
"//rs/rust_canisters/http_types",
"@crate_index//:askama",
"@crate_index//:candid",
"@crate_index//:ethabi",
"@crate_index//:futures",
"@crate_index//:hex",
"@crate_index//:ic-canister-log",
Expand All @@ -154,7 +153,6 @@ rust_test(
"@crate_index//:ic-metrics-encoder",
"@crate_index//:num-traits",
"@crate_index//:serde_bytes",
"@crate_index//:serde_json",
"@crate_index//:time",
],
) for (target_suffix, features) in [
Expand Down
17 changes: 15 additions & 2 deletions rs/pocket_ic_server/src/pocket_ic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use serde::{Deserialize, Serialize};
use std::hash::Hash;
use std::str::FromStr;
use std::{
collections::{BTreeMap, HashMap},
collections::BTreeMap,
sync::{Arc, Mutex, RwLock},
time::{Duration, SystemTime},
};
Expand Down Expand Up @@ -141,7 +141,7 @@ impl PocketIc {
let registry_data_provider = Arc::new(ProtoRegistryDataProvider::new());
let subnets: Arc<RwLock<BTreeMap<SubnetId, Arc<StateMachine>>>> =
Arc::new(RwLock::new(BTreeMap::new()));
let mut topology = Topology(HashMap::new());
let mut topology = Topology(BTreeMap::new());

// Create all StateMachines and the topology from the subnet config infos.
for (
Expand Down Expand Up @@ -542,6 +542,19 @@ impl Operation for SetTime {
}
}

#[derive(Clone, Copy, Debug)]
pub struct GetTopology;

impl Operation for GetTopology {
fn compute(&self, pic: &mut PocketIc) -> OpOut {
OpOut::Topology(pic.topology.clone())
}

fn id(&self) -> OpId {
OpId("get_topology".into())
}
}

#[derive(Clone, Copy, Debug)]
pub struct GetTime;

Expand Down
31 changes: 28 additions & 3 deletions rs/pocket_ic_server/src/state_api/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use super::state::{ApiState, OpOut, PocketIcError, StateLabel, UpdateReply};
use crate::pocket_ic::{
AddCycles, AwaitIngressMessage, CallRequest, ExecuteIngressMessage, GetCyclesBalance,
GetStableMemory, GetSubnet, GetTime, PubKey, Query, QueryRequest, ReadStateRequest,
SetStableMemory, SetTime, StatusRequest, SubmitIngressMessage, Tick,
GetStableMemory, GetSubnet, GetTime, GetTopology, PubKey, Query, QueryRequest,
ReadStateRequest, SetStableMemory, SetTime, StatusRequest, SubmitIngressMessage, Tick,
};
use crate::OpId;
use crate::{pocket_ic::PocketIc, BlobStore, InstanceId, Operation};
Expand Down Expand Up @@ -36,7 +36,7 @@ use ic_types::CanisterId;
use pocket_ic::common::rest::{
self, ApiResponse, ExtendedSubnetConfigSet, HttpGatewayConfig, HttpGatewayInfo, RawAddCycles,
RawCanisterCall, RawCanisterId, RawCanisterResult, RawCycles, RawMessageId, RawSetStableMemory,
RawStableMemory, RawSubmitIngressResult, RawSubnetId, RawTime, RawWasmResult,
RawStableMemory, RawSubmitIngressResult, RawSubnetId, RawTime, RawWasmResult, Topology,
};
use pocket_ic::WasmResult;
use serde::Serialize;
Expand Down Expand Up @@ -66,6 +66,7 @@ where
{
ApiRouter::new()
.directory_route("/query", post(handler_json_query))
.directory_route("/topology", get(handler_topology))
.directory_route("/get_time", get(handler_get_time))
.directory_route("/get_cycles", post(handler_get_cycles))
.directory_route("/get_stable_memory", post(handler_get_stable_memory))
Expand Down Expand Up @@ -299,6 +300,16 @@ impl TryFrom<OpOut> for RawTime {
}
}

impl TryFrom<OpOut> for Topology {
type Error = OpConversionError;
fn try_from(value: OpOut) -> Result<Self, Self::Error> {
match value {
OpOut::Topology(topology) => Ok(topology),
_ => Err(OpConversionError),
}
}
}

impl TryFrom<OpOut> for () {
type Error = OpConversionError;
fn try_from(value: OpOut) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -461,6 +472,17 @@ pub async fn handler_json_query(
}
}

pub async fn handler_topology(
State(AppState { api_state, .. }): State<AppState>,
headers: HeaderMap,
Path(instance_id): Path<InstanceId>,
) -> (StatusCode, Json<ApiResponse<Topology>>) {
let timeout = timeout_or_default(headers);
let op = GetTopology {};
let (code, response) = run_operation(api_state, instance_id, timeout, op).await;
(code, Json(response))
}

pub async fn handler_get_time(
State(AppState { api_state, .. }): State<AppState>,
headers: HeaderMap,
Expand Down Expand Up @@ -656,6 +678,9 @@ fn op_out_to_response(op_out: OpOut) -> Response {
Json(ApiResponse::Success(())).into_response(),
)
.into_response(),
OpOut::Topology(topology) => {
(StatusCode::OK, Json(ApiResponse::Success(topology))).into_response()
}
opout @ OpOut::Time(_) => (
StatusCode::OK,
Json(ApiResponse::Success(RawTime::try_from(opout).unwrap())),
Expand Down
4 changes: 3 additions & 1 deletion rs/pocket_ic_server/src/state_api/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{OpId, Operation};
use base64;
use ic_http_endpoints_public::cors_layer;
use ic_types::{CanisterId, SubnetId};
use pocket_ic::common::rest::{HttpGatewayBackend, HttpGatewayConfig};
use pocket_ic::common::rest::{HttpGatewayBackend, HttpGatewayConfig, Topology};
use pocket_ic::{ErrorCode, UserError, WasmResult};
use serde::{Deserialize, Serialize};
use std::{
Expand Down Expand Up @@ -161,6 +161,7 @@ pub enum OpOut {
ApiV2Response((u16, BTreeMap<String, Vec<u8>>, Vec<u8>)),
Pruned,
MessageId((EffectivePrincipal, Vec<u8>)),
Topology(Topology),
}

#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
Expand Down Expand Up @@ -210,6 +211,7 @@ impl std::fmt::Debug for OpOut {
match self {
OpOut::NoOutput => write!(f, "NoOutput"),
OpOut::Time(x) => write!(f, "Time({})", x),
OpOut::Topology(t) => write!(f, "Topology({:?})", t),
OpOut::CanisterId(cid) => write!(f, "CanisterId({})", cid),
OpOut::Cycles(x) => write!(f, "Cycles({})", x),
OpOut::CanisterResult(Ok(x)) => write!(f, "CanisterResult: Ok({:?})", x),
Expand Down

0 comments on commit 2dca190

Please sign in to comment.