Skip to content

Commit

Permalink
Merge branch 'BOUN-1091-add-api-v3-endpoint' into 'master'
Browse files Browse the repository at this point in the history
feat(BOUN-1091): Add `/api/v3/canister/canister_id/call` in Boundary Node

 

See merge request dfinity-lab/public/ic!19640
  • Loading branch information
nikolay-komarevskiy committed Jul 1, 2024
2 parents 7ff6ac4 + e08223b commit 1be34eb
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
10 changes: 7 additions & 3 deletions rs/boundary_node/ic_boundary/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,13 @@ pub fn setup_router(
})));

let call_route = {
let mut route = Router::new().route(routes::PATH_CALL, {
post(routes::handle_canister).with_state(proxy.clone())
});
let mut route = Router::new()
.route(routes::PATH_CALL, {
post(routes::handle_canister).with_state(proxy.clone())
})
.route(routes::PATH_CALL_V3, {
post(routes::handle_canister).with_state(proxy.clone())
});

// will panic if ip_rate_limit is Some(0)
if let Some(rl) = cli.rate_limiting.rate_limit_per_second_per_ip {
Expand Down
3 changes: 3 additions & 0 deletions rs/boundary_node/ic_boundary/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const HEADERS_HIDE_HTTP_REQUEST: [&str; 4] =
pub const PATH_STATUS: &str = "/api/v2/status";
pub const PATH_QUERY: &str = "/api/v2/canister/:canister_id/query";
pub const PATH_CALL: &str = "/api/v2/canister/:canister_id/call";
pub const PATH_CALL_V3: &str = "/api/v3/canister/:canister_id/call";
pub const PATH_READ_STATE: &str = "/api/v2/canister/:canister_id/read_state";
pub const PATH_SUBNET_READ_STATE: &str = "/api/v2/subnet/:subnet_id/read_state";
pub const PATH_HEALTH: &str = "/health";
Expand All @@ -112,6 +113,7 @@ pub enum RequestType {
Status,
Query,
Call,
CallV3,
ReadState,
ReadStateSubnet,
}
Expand Down Expand Up @@ -520,6 +522,7 @@ pub async fn validate_canister_request(
let request_type = match matched_path.as_str() {
PATH_QUERY => RequestType::Query,
PATH_CALL => RequestType::Call,
PATH_CALL_V3 => RequestType::CallV3,
PATH_READ_STATE => RequestType::ReadState,
_ => panic!("unknown path, should never happen"),
};
Expand Down
37 changes: 37 additions & 0 deletions rs/boundary_node/ic_boundary/src/routes/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,43 @@ async fn test_all_call_types() -> Result<(), Error> {
let body = String::from_utf8_lossy(&body);
assert_eq!(body, "a".repeat(1024));

// Test call v3
let content = HttpCallContent::Call {
update: HttpCanisterUpdate {
canister_id: Blob(canister_id.get().as_slice().to_vec()),
method_name: "foobar".to_string(),
arg: Blob(vec![]),
sender: Blob(sender.as_slice().to_vec()),
nonce: None,
ingress_expiry: 1234,
},
};

let envelope = HttpRequestEnvelope::<HttpCallContent> {
content,
sender_delegation: None,
sender_pubkey: None,
sender_sig: None,
};

let body = serde_cbor::to_vec(&envelope).unwrap();

let request = Request::builder()
.method("POST")
.uri(format!(
"http://localhost/api/v3/canister/{canister_id}/call"
))
.body(Body::from(body))
.unwrap();

let resp = app.call(request).await.unwrap();
assert_eq!(resp.status(), StatusCode::ACCEPTED);

let (_parts, body) = resp.into_parts();
let body = hyper::body::to_bytes(body).await.unwrap().to_vec();
let body = String::from_utf8_lossy(&body);
assert_eq!(body, "a".repeat(1024));

// Test canister read_state
let content = HttpReadStateContent::ReadState {
read_state: HttpReadState {
Expand Down
3 changes: 3 additions & 0 deletions rs/boundary_node/ic_boundary/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ impl Node {
RequestType::Unknown => {
panic!("can't construct url for unknown request type")
}
RequestType::CallV3 => Url::from_str(&format!(
"https://{node_id}:{node_port}/api/v3/canister/{principal}/call",
)),
RequestType::ReadStateSubnet => Url::from_str(&format!(
"https://{node_id}:{node_port}/api/v2/subnet/{principal}/read_state",
)),
Expand Down

0 comments on commit 1be34eb

Please sign in to comment.