From 4830ed0b0ab2b523b2344bf2439dbd94c14fea57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Mon, 23 Jan 2023 10:06:14 +0100 Subject: [PATCH 1/5] Custom gas limit --- aleph-client/src/contract/mod.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/aleph-client/src/contract/mod.rs b/aleph-client/src/contract/mod.rs index 077fa4eaf9..ca9c11ccce 100644 --- a/aleph-client/src/contract/mod.rs +++ b/aleph-client/src/contract/mod.rs @@ -59,23 +59,32 @@ use crate::{ AccountId, Balance, ConnectionApi, SignedConnectionApi, TxStatus, }; +/// Default gas limit, which allows up to 25% of block execution time. +pub const DEFAULT_MAX_GAS: u64 = 250_000_000_000u64; + /// Represents a contract instantiated on the chain. pub struct ContractInstance { address: AccountId, transcoder: ContractMessageTranscoder, + max_gas_override: Option, } impl ContractInstance { - const MAX_GAS: u64 = 10000000000u64; - /// Creates a new contract instance under `address` with metadata read from `metadata_path`. pub fn new(address: AccountId, metadata_path: &str) -> Result { Ok(Self { address, transcoder: ContractMessageTranscoder::load(metadata_path)?, + max_gas_override: None, }) } + /// From now on, the contract instance will use `limit_override` as the gas limit for all + /// contract calls. If `limit_override` is `None`, then [DEFAULT_MAX_GAS] will be used. + pub fn override_gas_limit(&mut self, limit_override: Option) { + self.max_gas_override = limit_override; + } + /// The address of this contract instance. pub fn address(&self) -> &AccountId { &self.address @@ -168,8 +177,8 @@ impl ContractInstance { self.address.clone(), value, Weight { - ref_time: Self::MAX_GAS, - proof_size: Self::MAX_GAS, + ref_time: self.max_gas_override.unwrap_or(DEFAULT_MAX_GAS), + proof_size: self.max_gas_override.unwrap_or(DEFAULT_MAX_GAS), }, None, data, From 54413336468eb1b130d185db48070a9bd06103da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Mon, 23 Jan 2023 10:12:41 +0100 Subject: [PATCH 2/5] Bump --- aleph-client/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aleph-client/Cargo.toml b/aleph-client/Cargo.toml index 841c78085e..3618cc072c 100644 --- a/aleph-client/Cargo.toml +++ b/aleph-client/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "aleph_client" # TODO bump major version when API stablize -version = "2.10.0" +version = "2.11.0" edition = "2021" license = "Apache 2.0" From 60cb7631d67adbcc22163a5ecf888898a182870f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Mon, 23 Jan 2023 10:14:01 +0100 Subject: [PATCH 3/5] locks --- aleph-client/Cargo.lock | 2 +- benches/payout-stakers/Cargo.lock | 2 +- bin/cliain/Cargo.lock | 2 +- e2e-tests/Cargo.lock | 2 +- flooder/Cargo.lock | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/aleph-client/Cargo.lock b/aleph-client/Cargo.lock index 52ef28bbd8..00f797f222 100644 --- a/aleph-client/Cargo.lock +++ b/aleph-client/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.10.0" +version = "2.11.0" dependencies = [ "anyhow", "async-trait", diff --git a/benches/payout-stakers/Cargo.lock b/benches/payout-stakers/Cargo.lock index d548ecc86d..36830d44dd 100644 --- a/benches/payout-stakers/Cargo.lock +++ b/benches/payout-stakers/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.10.0" +version = "2.11.0" dependencies = [ "anyhow", "async-trait", diff --git a/bin/cliain/Cargo.lock b/bin/cliain/Cargo.lock index 42df8358a5..96cf6d9048 100644 --- a/bin/cliain/Cargo.lock +++ b/bin/cliain/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.10.0" +version = "2.11.0" dependencies = [ "anyhow", "async-trait", diff --git a/e2e-tests/Cargo.lock b/e2e-tests/Cargo.lock index b60ada34de..205cc8f2ff 100644 --- a/e2e-tests/Cargo.lock +++ b/e2e-tests/Cargo.lock @@ -78,7 +78,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.10.0" +version = "2.11.0" dependencies = [ "anyhow", "async-trait", diff --git a/flooder/Cargo.lock b/flooder/Cargo.lock index e8604a36fa..c796321972 100644 --- a/flooder/Cargo.lock +++ b/flooder/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.10.0" +version = "2.11.0" dependencies = [ "anyhow", "async-trait", From 0ac719f6000384f52a41defa845d2a6465f11b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Mon, 23 Jan 2023 12:08:02 +0100 Subject: [PATCH 4/5] Custom proof size limit --- aleph-client/Cargo.lock | 2 +- aleph-client/src/contract/mod.rs | 14 +++++++++++++- benches/payout-stakers/Cargo.lock | 2 +- bin/cliain/Cargo.lock | 2 +- e2e-tests/Cargo.lock | 2 +- flooder/Cargo.lock | 2 +- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/aleph-client/Cargo.lock b/aleph-client/Cargo.lock index 9d18828332..34b679cfc2 100644 --- a/aleph-client/Cargo.lock +++ b/aleph-client/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.11.0" +version = "2.12.0" dependencies = [ "anyhow", "async-trait", diff --git a/aleph-client/src/contract/mod.rs b/aleph-client/src/contract/mod.rs index ca9c11ccce..9608d2ed90 100644 --- a/aleph-client/src/contract/mod.rs +++ b/aleph-client/src/contract/mod.rs @@ -61,12 +61,15 @@ use crate::{ /// Default gas limit, which allows up to 25% of block execution time. pub const DEFAULT_MAX_GAS: u64 = 250_000_000_000u64; +/// Default proof size limit, which allows up to 25% of block execution time. +pub const DEFAULT_MAX_PROOF_SIZE: u64 = 250_000_000_000u64; /// Represents a contract instantiated on the chain. pub struct ContractInstance { address: AccountId, transcoder: ContractMessageTranscoder, max_gas_override: Option, + max_proof_size_override: Option, } impl ContractInstance { @@ -76,6 +79,7 @@ impl ContractInstance { address, transcoder: ContractMessageTranscoder::load(metadata_path)?, max_gas_override: None, + max_proof_size_override: None, }) } @@ -85,6 +89,12 @@ impl ContractInstance { self.max_gas_override = limit_override; } + /// From now on, the contract instance will use `limit_override` as the proof size limit for all + /// contract calls. If `limit_override` is `None`, then [DEFAULT_MAX_PROOF_SIZE] will be used. + pub fn override_proof_size_limit(&mut self, limit_override: Option) { + self.max_proof_size_override = limit_override; + } + /// The address of this contract instance. pub fn address(&self) -> &AccountId { &self.address @@ -178,7 +188,9 @@ impl ContractInstance { value, Weight { ref_time: self.max_gas_override.unwrap_or(DEFAULT_MAX_GAS), - proof_size: self.max_gas_override.unwrap_or(DEFAULT_MAX_GAS), + proof_size: self + .max_proof_size_override + .unwrap_or(DEFAULT_MAX_PROOF_SIZE), }, None, data, diff --git a/benches/payout-stakers/Cargo.lock b/benches/payout-stakers/Cargo.lock index c989b6e7f8..ff4de412e7 100644 --- a/benches/payout-stakers/Cargo.lock +++ b/benches/payout-stakers/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.11.0" +version = "2.12.0" dependencies = [ "anyhow", "async-trait", diff --git a/bin/cliain/Cargo.lock b/bin/cliain/Cargo.lock index 2b31f33e68..36f550dc83 100644 --- a/bin/cliain/Cargo.lock +++ b/bin/cliain/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.11.0" +version = "2.12.0" dependencies = [ "anyhow", "async-trait", diff --git a/e2e-tests/Cargo.lock b/e2e-tests/Cargo.lock index 8c7d5f5cb3..65e4f412e7 100644 --- a/e2e-tests/Cargo.lock +++ b/e2e-tests/Cargo.lock @@ -78,7 +78,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.11.0" +version = "2.12.0" dependencies = [ "anyhow", "async-trait", diff --git a/flooder/Cargo.lock b/flooder/Cargo.lock index 305eb625fa..1a7a86ab31 100644 --- a/flooder/Cargo.lock +++ b/flooder/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.11.0" +version = "2.12.0" dependencies = [ "anyhow", "async-trait", From 9ff850a4e4a14975c81d8c5ac1c68507ab391ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Mon, 23 Jan 2023 13:04:23 +0100 Subject: [PATCH 5/5] Precise estimate --- aleph-client/src/contract/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/aleph-client/src/contract/mod.rs b/aleph-client/src/contract/mod.rs index 9608d2ed90..242f49f7db 100644 --- a/aleph-client/src/contract/mod.rs +++ b/aleph-client/src/contract/mod.rs @@ -59,9 +59,10 @@ use crate::{ AccountId, Balance, ConnectionApi, SignedConnectionApi, TxStatus, }; -/// Default gas limit, which allows up to 25% of block execution time. +/// Default gas limit, which allows up to 25% of block time (62.5% of the actual block capacity). pub const DEFAULT_MAX_GAS: u64 = 250_000_000_000u64; -/// Default proof size limit, which allows up to 25% of block execution time. +/// Default proof size limit, which allows up to 25% of block time (62.5% of the actual block +/// capacity). pub const DEFAULT_MAX_PROOF_SIZE: u64 = 250_000_000_000u64; /// Represents a contract instantiated on the chain.