Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aleph-client: Custom gas limit #880

Merged
merged 6 commits into from
Jan 23, 2023
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 aleph-client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aleph-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aleph_client"
version = "2.11.0"
version = "2.12.0"
edition = "2021"
license = "Apache 2.0"

Expand Down
30 changes: 26 additions & 4 deletions aleph-client/src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,43 @@ use crate::{
AccountId, Balance, ConnectionApi, SignedConnectionApi, TxStatus,
};

/// 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 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.
pub struct ContractInstance {
address: AccountId,
transcoder: ContractMessageTranscoder,
max_gas_override: Option<u64>,
krzysztofziobro marked this conversation as resolved.
Show resolved Hide resolved
max_proof_size_override: Option<u64>,
}

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<Self> {
Ok(Self {
address,
transcoder: ContractMessageTranscoder::load(metadata_path)?,
max_gas_override: None,
max_proof_size_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<u64>) {
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<u64>) {
self.max_proof_size_override = limit_override;
}

/// The address of this contract instance.
pub fn address(&self) -> &AccountId {
&self.address
Expand Down Expand Up @@ -168,8 +188,10 @@ 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_proof_size_override
.unwrap_or(DEFAULT_MAX_PROOF_SIZE),
},
None,
data,
Expand Down
2 changes: 1 addition & 1 deletion benches/payout-stakers/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/cliain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flooder/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.