Sitelet https://github.com/dfinity/rosetta-node/commit/46fb0997101699fa53e8d4f1b32032e41ee7841c
Skip to content
This repository was archived by the owner on Feb 16, 2022. It is now read-only.

Commit 46fb099

Browse files
committed
Update to 98207d99651e8f20e82c0a86170f32855fb41444
1 parent ecf744b commit 46fb099

11 files changed

Lines changed: 239 additions & 208 deletions

File tree

‎canister_client/src/agent.rs‎

Lines changed: 11 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ const INGRESS_TIMEOUT: Duration = Duration::from_secs(60 * 6);
3030
/// from an 'execute_query' call.
3131
const QUERY_TIMEOUT: Duration = Duration::from_secs(30);
3232

33-
/// Maximum time in seconds to wait for a result (successful or otherwise)
34-
/// from an 'install_canister' call.
35-
const INSTALL_TIMEOUT: Duration = INGRESS_TIMEOUT;
36-
3733
/// The HTTP path for query calls on the replica.
3834
// TODO is this how v1 api works can we just change the URL?
3935
pub fn query_path(cid: CanisterId) -> String {
@@ -207,9 +203,6 @@ pub struct Agent {
207203
// How long to wait for queries.
208204
query_timeout: Duration,
209205

210-
// How long to wait for `install_canister` requests.
211-
pub(crate) install_timeout: Duration,
212-
213206
// Per reqwest document, cloning a client does not clone the actual connection pool inside.
214207
// Therefore directly owning a client as opposed to a reference is the standard way to go.
215208
http_client: Arc<HttpClient>,
@@ -227,7 +220,6 @@ impl fmt::Debug for Agent {
227220
.field("url", &self.url)
228221
.field("ingress_timeout", &self.ingress_timeout)
229222
.field("query_timeout", &self.query_timeout)
230-
.field("install_timeout", &self.install_timeout)
231223
.field("sender", &self.sender_field)
232224
.finish()
233225
}
@@ -267,7 +259,6 @@ impl Agent {
267259
url,
268260
ingress_timeout: INGRESS_TIMEOUT,
269261
query_timeout: QUERY_TIMEOUT,
270-
install_timeout: INSTALL_TIMEOUT,
271262
http_client,
272263
sender,
273264
sender_field,
@@ -286,12 +277,6 @@ impl Agent {
286277
self
287278
}
288279

289-
/// Sets the timeout for canister installation.
290-
pub fn with_install_timeout(mut self, install_timeout: Duration) -> Self {
291-
self.install_timeout = install_timeout;
292-
self
293-
}
294-
295280
/// Queries the cup endpoint given the provided CatchUpPackageParams.
296281
pub async fn query_cup_endpoint(
297282
&self,
@@ -367,26 +352,7 @@ impl Agent {
367352
arguments: Vec<u8>,
368353
nonce: Vec<u8>,
369354
) -> Result<Option<Vec<u8>>, String> {
370-
self.execute_update_with_deadline(
371-
canister_id,
372-
method,
373-
arguments,
374-
nonce,
375-
Instant::now() + self.ingress_timeout,
376-
)
377-
.await
378-
}
379-
380-
/// Calls the query method 'method' on the canister located at 'url',
381-
/// optionally with 'arguments'.
382-
pub(crate) async fn execute_update_with_deadline<S: ToString>(
383-
&self,
384-
canister_id: &CanisterId,
385-
method: S,
386-
arguments: Vec<u8>,
387-
nonce: Vec<u8>,
388-
deadline: Instant,
389-
) -> Result<Option<Vec<u8>>, String> {
355+
let deadline = Instant::now() + self.ingress_timeout;
390356
let (http_body, request_id) = self
391357
.prepare_update(canister_id, method, arguments, nonce)
392358
.map_err(|err| format!("{}", err))?;
@@ -487,9 +453,7 @@ impl Agent {
487453
parse_read_state_response(&request_id, cbor)
488454
}
489455

490-
/// Requests the version of the public spec supported by this node by
491-
/// querying /api/v1/status.
492-
pub async fn ic_api_version(&self) -> Result<String, String> {
456+
async fn get_status_with_response(&self) -> Result<HttpStatusResponse, String> {
493457
let bytes = self
494458
.http_client
495459
.get_with_response(
@@ -499,43 +463,27 @@ impl Agent {
499463
)
500464
.await?;
501465
let resp = bytes_to_cbor(bytes)?;
502-
let response = serde_cbor::value::from_value::<HttpStatusResponse>(resp)
503-
.map_err(|source| format!("decoding to HttpStatusResponse failed: {}", source))?;
466+
serde_cbor::value::from_value::<HttpStatusResponse>(resp)
467+
.map_err(|source| format!("decoding to HttpStatusResponse failed: {}", source))
468+
}
504469

470+
/// Requests the version of the public spec supported by this node by
471+
/// querying /api/v1/status.
472+
pub async fn ic_api_version(&self) -> Result<String, String> {
473+
let response = self.get_status_with_response().await?;
505474
Ok(response.ic_api_version)
506475
}
507476

508477
/// Requests the Replica impl version of this node by querying
509478
/// /api/v1/status
510479
pub async fn impl_version(&self) -> Result<Option<String>, String> {
511-
let bytes = self
512-
.http_client
513-
.get_with_response(
514-
&self.url,
515-
NODE_STATUS_PATH,
516-
tokio::time::Instant::now() + self.query_timeout,
517-
)
518-
.await?;
519-
let resp = bytes_to_cbor(bytes)?;
520-
let response = serde_cbor::value::from_value::<HttpStatusResponse>(resp)
521-
.map_err(|source| format!("decoding to HttpStatusResponse failed: {}", source))?;
522-
480+
let response = self.get_status_with_response().await?;
523481
Ok(response.impl_version)
524482
}
525483

526484
/// Requests the root key of this node by querying /api/v1/status
527485
pub async fn root_key(&self) -> Result<Option<Blob>, String> {
528-
let bytes = self
529-
.http_client
530-
.get_with_response(
531-
&self.url,
532-
NODE_STATUS_PATH,
533-
tokio::time::Instant::now() + self.query_timeout,
534-
)
535-
.await?;
536-
let resp = bytes_to_cbor(bytes)?;
537-
let response = serde_cbor::value::from_value::<HttpStatusResponse>(resp)
538-
.map_err(|source| format!("decoding to HttpStatusResponse failed: {}", source))?;
486+
let response = self.get_status_with_response().await?;
539487

540488
Ok(response.root_key)
541489
}

‎canister_client/src/canister_management.rs‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,8 @@ use ic_types::ic00::{InstallCodeArgs, Method, Payload, IC_00};
66
impl Agent {
77
// Ships a binary wasm module to a canister.
88
pub async fn install_canister(&self, install_args: InstallCodeArgs) -> Result<(), String> {
9-
self.execute_update_with_deadline(
10-
&IC_00,
11-
Method::InstallCode,
12-
install_args.encode(),
13-
vec![],
14-
std::time::Instant::now() + self.install_timeout,
15-
)
16-
.await
17-
.map(|_| ())
9+
self.execute_update(&IC_00, Method::InstallCode, install_args.encode(), vec![])
10+
.await
11+
.map(|_| ())
1812
}
1913
}

‎canister_client/src/cbor.rs‎

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ impl RequestStatus {
4343
}
4444

4545
#[derive(Debug)]
46-
pub struct CanisterCallResponse {
47-
pub status: String,
48-
pub arg: Option<Vec<u8>>,
49-
pub reject_message: Option<String>,
46+
struct CanisterCallResponse {
47+
status: String,
48+
arg: Option<Vec<u8>>,
49+
reject_message: Option<String>,
5050
}
5151

5252
/// Given a CBOR response from a `read_state` and a `request_id` extracts
@@ -179,12 +179,12 @@ impl Agent {
179179
}
180180

181181
/// Prepares and serializes a CBOR query request.
182-
pub(crate) fn prepare_query_raw(
182+
pub fn prepare_query(
183183
&self,
184184
canister_id: &CanisterId,
185185
method: &str,
186186
arguments: Vec<u8>,
187-
) -> Result<HttpRequestEnvelope<HttpReadContent>, Box<dyn Error>> {
187+
) -> Result<Vec<u8>, Box<dyn Error>> {
188188
let content = HttpReadContent::Query {
189189
query: HttpUserQuery {
190190
canister_id: to_blob(canister_id),
@@ -196,17 +196,7 @@ impl Agent {
196196
},
197197
};
198198

199-
sign_read(content, &self.sender)
200-
}
201-
202-
/// Prepares and serializes a CBOR query request.
203-
pub fn prepare_query(
204-
&self,
205-
canister_id: &CanisterId,
206-
method: &str,
207-
arguments: Vec<u8>,
208-
) -> Result<Vec<u8>, Box<dyn Error>> {
209-
let request = self.prepare_query_raw(canister_id, method, arguments)?;
199+
let request = sign_read(content, &self.sender)?;
210200
Ok(SignedRequestBytes::try_from(request)?.into())
211201
}
212202

‎canister_client/src/lib.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! A client to interface with canisters via HTTP.
2-
pub mod agent;
2+
mod agent;
33
mod canister_management;
44
/// Asynchronous method to interact with canisters.
5-
pub mod cbor;
5+
mod cbor;
66
mod http_client;
77

88
pub use agent::{

‎protobuf/def/state/canister_state_bits/v1/canister_state_bits.proto‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ message CanisterStatusStopping {
125125
message CanisterStatusStopped {}
126126

127127
message CanisterStateBits {
128+
// This field is now deprecated. Once all subnets in production contain the
129+
// new version of this field, we can remove it (and mark it as reserved).
128130
types.v1.PrincipalId controller = 1;
129131
uint64 last_full_execution_round = 2;
130132
CallContextManager call_context_manager = 3;
@@ -155,4 +157,5 @@ message CanisterStateBits {
155157
types.v1.NominalCycles consumed_cycles_since_replica_started = 22;
156158
uint64 freeze_threshold = 23;
157159
uint32 stable_memory_size = 24;
160+
repeated types.v1.PrincipalId controllers = 25;
158161
}

‎rosetta-api/Dockerfile‎

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
FROM debian:buster-slim
2-
3-
WORKDIR /root
4-
1+
FROM ubuntu:latest
2+
RUN apt-get update && \
3+
apt-get install -y --no-install-recommends \
4+
ca-certificates \
5+
libssl1.1
56
COPY target/release/ic-rosetta-api /usr/local/bin/ic-rosetta-api
6-
7-
COPY log_config.yml /root
8-
9-
RUN \
10-
apt update && \
11-
apt install -y \
12-
ca-certificates && \
13-
apt autoremove --purge -y && \
14-
rm -rf \
15-
/tmp/* \
16-
/var/lib/apt/lists/* \
17-
/var/tmp/*
18-
197
ENTRYPOINT ["/usr/local/bin/ic-rosetta-api", "--store-location", "/data"]

‎rosetta-api/export-source.sh‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,35 @@ set -euo pipefail
33

44
# We use this script to export new versions of our source to the coinbase guys
55

6-
ROSETTA_NODE_PATH=~/rosetta-node
6+
ROSETTA_NODE_PATH=${ROSETTA_NODE_PATH:-~/rosetta-node}
77

88
# Why try and pretend that bash scripts are anything but a nasty hack
9-
rsync -av --relative rosetta-api crypto/tree_hash crypto/internal crypto/sha256 types/error_types types/types types/base_types types/ic00_types canister_client phantom_newtype utils utils/actix-utils sys rust_canisters/dfn_candid rust_canisters/dfn_http rust_canisters/on_wire rust_canisters/dfn_json rust_canisters/dfn_core rust_canisters/dfn_macro registry/transport registry/routing_table registry/subnet_type protobuf interfaces tree_deserializer registry/provisional_whitelist $ROSETTA_NODE_PATH
9+
rsync \
10+
-av \
11+
--relative \
12+
canister_client \
13+
crypto/internal \
14+
crypto/sha256 \
15+
crypto/tree_hash \
16+
interfaces \
17+
phantom_newtype \
18+
protobuf \
19+
registry/provisional_whitelist \
20+
registry/routing_table \
21+
registry/subnet_type \
22+
registry/transport \
23+
rosetta-api \
24+
rust_canisters/dfn_candid \
25+
rust_canisters/dfn_core \
26+
rust_canisters/dfn_json \
27+
rust_canisters/dfn_macro \
28+
rust_canisters/on_wire \
29+
sys \
30+
tree_deserializer \
31+
types/base_types \
32+
types/error_types \
33+
types/ic00_types \
34+
types/types \
35+
utils \
36+
utils/actix-utils \
37+
"$ROSETTA_NODE_PATH"

0 commit comments

Comments
 (0)