Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion linera-chain/src/unit_tests/chain_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async fn test_block_size_limit() {
let mut chain = ChainStateView::new(chain_id).await;

// The size of the executed valid block below.
let maximum_executed_block_size = 725;
let maximum_executed_block_size = 733;

// Initialize the chain.
let mut config = make_open_chain_config();
Expand Down
18 changes: 14 additions & 4 deletions linera-execution/src/execution_state_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#[cfg(with_metrics)]
use std::sync::LazyLock;
#[cfg(not(web))]
use std::time::Duration;

use custom_debug_derive::Debug;
use futures::channel::mpsc;
Expand Down Expand Up @@ -395,12 +397,20 @@ where
ExecutionError::UnauthorizedHttpRequest(url)
);

let response = Client::new()
#[cfg_attr(web, allow(unused_mut))]
let mut request = Client::new()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So on a web client there won't be any timeouts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the default browser timeouts. Unfortunately we can't add timeouts with reqwest for Wasm, we'd need to use Javascript APIs directly :(

.request(request.method.into(), url)
.body(request.body)
.headers(headers)
.send()
.await?;
.headers(headers);
#[cfg(not(web))]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…or use the same timeout in either case? Might be less surprising, too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't, reqwest doesn't support timeouts on Wasm :/

{
request = request.timeout(Duration::from_millis(
committee.policy().http_request_timeout_ms,
));
}

let response = request.send().await?;

callback.respond(http::Response::from_reqwest(response).await?);
}

Expand Down
6 changes: 6 additions & 0 deletions linera-execution/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub struct ResourceControlPolicy {
pub maximum_bytes_read_per_block: u64,
/// The maximum data to write per block
pub maximum_bytes_written_per_block: u64,
/// The maximum amount of time allowed to wait for an HTTP response.
pub http_request_timeout_ms: u64,
/// The list of hosts that contracts and services can send HTTP requests to.
pub http_request_allow_list: BTreeSet<String>,
}
Expand Down Expand Up @@ -88,6 +90,7 @@ impl fmt::Display for ResourceControlPolicy {
maximum_bytes_read_per_block,
maximum_bytes_written_per_block,
http_request_allow_list,
http_request_timeout_ms,
} = self;
write!(
f,
Expand All @@ -111,6 +114,7 @@ impl fmt::Display for ResourceControlPolicy {
{maximum_block_proposal_size} maximum size of a block proposal\n\
{maximum_bytes_read_per_block} maximum number bytes read per block\n\
{maximum_bytes_written_per_block} maximum number bytes written per block\n\
{http_request_timeout_ms} ms timeout for HTTP requests\n\
HTTP hosts allowed for contracts and services: {http_request_allow_list:#?}\n",
)?;
Ok(())
Expand Down Expand Up @@ -148,6 +152,7 @@ impl ResourceControlPolicy {
maximum_block_proposal_size: u64::MAX,
maximum_bytes_read_per_block: u64::MAX,
maximum_bytes_written_per_block: u64::MAX,
http_request_timeout_ms: u64::MAX,
http_request_allow_list: BTreeSet::new(),
}
}
Expand Down Expand Up @@ -213,6 +218,7 @@ impl ResourceControlPolicy {
maximum_block_proposal_size: 13_000_000,
maximum_bytes_read_per_block: 100_000_000,
maximum_bytes_written_per_block: 10_000_000,
http_request_timeout_ms: 20_000,
http_request_allow_list: BTreeSet::new(),
}
}
Expand Down
13 changes: 7 additions & 6 deletions linera-execution/src/test_utils/mock_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct MockApplication {
///
/// Will expect certain calls previously configured through [`MockApplication`].
pub struct MockApplicationInstance<Runtime> {
expected_calls: VecDeque<ExpectedCall>,
expected_calls: Arc<Mutex<VecDeque<ExpectedCall>>>,
runtime: Runtime,
active_instances: Arc<AtomicUsize>,
}
Expand All @@ -61,7 +61,7 @@ impl MockApplication {
self.active_instances.fetch_add(1, Ordering::AcqRel);

MockApplicationInstance {
expected_calls: mem::take(&mut self.expected_calls.lock().expect("Mutex is poisoned")),
expected_calls: self.expected_calls.clone(),
runtime,
active_instances: self.active_instances.clone(),
}
Expand Down Expand Up @@ -115,9 +115,7 @@ impl Eq for MockApplication {}

impl<Runtime> Drop for MockApplicationInstance<Runtime> {
fn drop(&mut self) {
if self.expected_calls.is_empty() {
self.active_instances.fetch_sub(1, Ordering::AcqRel);
}
self.active_instances.fetch_sub(1, Ordering::AcqRel);
}
}

Expand Down Expand Up @@ -294,7 +292,10 @@ impl UserServiceModule for MockApplication {
impl<Runtime> MockApplicationInstance<Runtime> {
/// Retrieves the next [`ExpectedCall`] in the queue.
fn next_expected_call(&mut self) -> Option<ExpectedCall> {
self.expected_calls.pop_front()
self.expected_calls
.lock()
.expect("Queue of expected calls was poisoned")
.pop_front()
}
}

Expand Down
1 change: 1 addition & 0 deletions linera-execution/tests/fee_consumption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ async fn test_fee_consumption(
maximum_block_proposal_size: 53,
maximum_bytes_read_per_block: 59,
maximum_bytes_written_per_block: 61,
http_request_timeout_ms: 67,
http_request_allow_list: BTreeSet::new(),
};

Expand Down
1 change: 1 addition & 0 deletions linera-rpc/tests/snapshots/format__format.yaml.snap
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ ResourceControlPolicy:
- maximum_block_proposal_size: U64
- maximum_bytes_read_per_block: U64
- maximum_bytes_written_per_block: U64
- http_request_timeout_ms: U64
- http_request_allow_list:
SEQ: STR
Response:
Expand Down
4 changes: 4 additions & 0 deletions linera-service-graphql-client/gql/service_schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,10 @@ input ResourceControlPolicy {
"""
maximumBytesWrittenPerBlock: Int!
"""
The maximum amount of time allowed to wait for an HTTP response.
"""
httpRequestTimeoutMs: Int!
"""
The list of hosts that contracts and services can send HTTP requests to.
"""
httpRequestAllowList: [String!]!
Expand Down