Skip to content

Commit

Permalink
block limit multiplier instead of exact value
Browse files Browse the repository at this point in the history
  • Loading branch information
ukint-vs committed Sep 17, 2023
1 parent 528cdff commit 2103648
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 67 deletions.
4 changes: 2 additions & 2 deletions node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub struct RunCmd {
pub max_gas: Option<u64>,

/// The upper limit for the amount of gas a runtime api can burn in one call.
#[arg(long, default_value_t = 600_000_000)]
pub rpc_max_gas_allowance: u64,
#[arg(long, default_value_t = 64)]
pub rpc_gas_allowance_multiplier: u64,
}

#[derive(Debug, Parser)]
Expand Down
20 changes: 10 additions & 10 deletions node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,31 +155,31 @@ pub fn run() -> sc_cli::Result<()> {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let (client, _, import_queue, task_manager) =
service::new_chain_ops(&config, cli.run.rpc_max_gas_allowance)?;
service::new_chain_ops(&config, cli.run.rpc_gas_allowance_multiplier)?;
Ok((cmd.run(client, import_queue), task_manager))
})
}
Some(Subcommand::ExportBlocks(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let (client, _, _, task_manager) =
service::new_chain_ops(&config, cli.run.rpc_max_gas_allowance)?;
service::new_chain_ops(&config, cli.run.rpc_gas_allowance_multiplier)?;
Ok((cmd.run(client, config.database), task_manager))
})
}
Some(Subcommand::ExportState(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let (client, _, _, task_manager) =
service::new_chain_ops(&config, cli.run.rpc_max_gas_allowance)?;
service::new_chain_ops(&config, cli.run.rpc_gas_allowance_multiplier)?;
Ok((cmd.run(client, config.chain_spec), task_manager))
})
}
Some(Subcommand::ImportBlocks(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let (client, _, import_queue, task_manager) =
service::new_chain_ops(&config, cli.run.rpc_max_gas_allowance)?;
service::new_chain_ops(&config, cli.run.rpc_gas_allowance_multiplier)?;
Ok((cmd.run(client, import_queue), task_manager))
})
}
Expand All @@ -191,7 +191,7 @@ pub fn run() -> sc_cli::Result<()> {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let (client, backend, _, task_manager) =
service::new_chain_ops(&config, cli.run.rpc_max_gas_allowance)?;
service::new_chain_ops(&config, cli.run.rpc_gas_allowance_multiplier)?;
let aux_revert = Box::new(|client, backend, blocks| {
service::revert_backend(client, backend, blocks, config)
.map_err(|err| sc_cli::Error::Application(err.into()))
Expand Down Expand Up @@ -236,7 +236,7 @@ pub fn run() -> sc_cli::Result<()> {
}
}
BenchmarkCmd::Block(cmd) => {
let (client, _, _, _) = service::new_chain_ops(&config)?;
let (client, _, _, _) = service::new_chain_ops(&config, cli.run.rpc_gas_allowance_multiplier)?;

unwrap_client!(client, cmd.run(client.clone()))
}
Expand All @@ -247,7 +247,7 @@ pub fn run() -> sc_cli::Result<()> {
),
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(cmd) => {
let (client, backend, _, _) = service::new_chain_ops(&config)?;
let (client, backend, _, _) = service::new_chain_ops(&config, cli.run.rpc_gas_allowance_multiplier)?;
let db = backend.expose_db();
let storage = backend.expose_storage();

Expand All @@ -258,7 +258,7 @@ pub fn run() -> sc_cli::Result<()> {
sc_cli::Error::from(format!("generating inherent data: {e:?}"))
})?;

let (client, _, _, _) = service::new_chain_ops(&config)?;
let (client, _, _, _) = service::new_chain_ops(&config, cli.run.rpc_gas_allowance_multiplier)?;
let ext_builder = RemarkBuilder::new(client.clone());

unwrap_client!(
Expand All @@ -276,7 +276,7 @@ pub fn run() -> sc_cli::Result<()> {
let inherent_data = inherent_benchmark_data().map_err(|e| {
sc_cli::Error::from(format!("generating inherent data: {e:?}"))
})?;
let (client, _, _, _) = service::new_chain_ops(&config)?;
let (client, _, _, _) = service::new_chain_ops(&config, cli.run.rpc_gas_allowance_multiplier)?;
// Register the *Remark* and *TKA* builders.
let ext_factory = ExtrinsicFactory(vec![
Box::new(RemarkBuilder::new(client.clone())),
Expand Down Expand Up @@ -371,7 +371,7 @@ pub fn run() -> sc_cli::Result<()> {
config,
cli.no_hardware_benchmarks,
cli.run.max_gas,
cli.run.rpc_max_gas_allowance,
cli.run.rpc_gas_allowance_multiplier,
)
.map_err(sc_cli::Error::Service)
})
Expand Down
24 changes: 12 additions & 12 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ type TransactionPool<RuntimeApi, ExecutorDispatch> =
sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>;

macro_rules! chain_ops {
($config:expr, $rpc_max_gas_allowance:expr, $scope:ident, $executor:ident, $variant:ident) => {{
($config:expr, $rpc_gas_allowance_multiplier:expr, $scope:ident, $executor:ident, $variant:ident) => {{
let PartialComponents {
client,
backend,
import_queue,
task_manager,
..
} = new_partial::<$scope::RuntimeApi, $executor>($config, $rpc_max_gas_allowance)?;
} = new_partial::<$scope::RuntimeApi, $executor>($config, $rpc_gas_allowance_multiplier)?;

Ok((
Arc::new(Client::$variant(client)),
Expand All @@ -112,7 +112,7 @@ macro_rules! chain_ops {
#[allow(clippy::type_complexity)]
pub fn new_chain_ops(
config: &Configuration,
rpc_max_gas_allowance: u64,
rpc_gas_allowance_multiplier: u64,
) -> Result<
(
Arc<Client>,
Expand All @@ -127,7 +127,7 @@ pub fn new_chain_ops(
spec if spec.is_gear() => {
chain_ops!(
config,
rpc_max_gas_allowance,
rpc_gas_allowance_multiplier,
gear_runtime,
GearExecutorDispatch,
Gear
Expand All @@ -137,7 +137,7 @@ pub fn new_chain_ops(
spec if spec.is_vara() => {
chain_ops!(
config,
rpc_max_gas_allowance,
rpc_gas_allowance_multiplier,
vara_runtime,
VaraExecutorDispatch,
Vara
Expand All @@ -152,7 +152,7 @@ pub fn new_chain_ops(
#[allow(clippy::type_complexity)]
pub fn new_partial<RuntimeApi, ExecutorDispatch>(
config: &Configuration,
rpc_max_gas_allowance: u64,
rpc_gas_allowance_multiplier: u64,
) -> Result<
PartialComponents<
FullClient<RuntimeApi, ExecutorDispatch>,
Expand Down Expand Up @@ -324,7 +324,7 @@ where
finality_provider: finality_proof_provider.clone(),
},
gear: crate::rpc::GearDeps {
gas_allowance: rpc_max_gas_allowance.clone(),
allowance_multiplier: rpc_gas_allowance_multiplier,
},
};

Expand Down Expand Up @@ -386,7 +386,7 @@ pub fn new_full_base<RuntimeApi, ExecutorDispatch>(
&sc_consensus_babe::BabeLink<Block>,
),
max_gas: Option<u64>,
rpc_max_gas_allowance: u64,
rpc_gas_allowance_multiplier: u64,
) -> Result<NewFullBase<RuntimeApi, ExecutorDispatch>, ServiceError>
where
RuntimeApi: ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>
Expand All @@ -413,7 +413,7 @@ where
select_chain,
transaction_pool,
other: (rpc_builder, import_setup, rpc_setup, mut telemetry),
} = new_partial(&config, rpc_max_gas_allowance)?;
} = new_partial(&config, rpc_gas_allowance_multiplier)?;

let shared_voter_state = rpc_setup;
let grandpa_protocol_name = sc_consensus_grandpa::protocol_standard_name(
Expand Down Expand Up @@ -661,7 +661,7 @@ pub fn new_full(
config: Configuration,
disable_hardware_benchmarks: bool,
max_gas: Option<u64>,
rpc_max_gas_allowance: u64,
rpc_gas_allowance_multiplier: u64,
) -> Result<TaskManager, ServiceError> {
match &config.chain_spec {
#[cfg(feature = "gear-native")]
Expand All @@ -670,7 +670,7 @@ pub fn new_full(
disable_hardware_benchmarks,
|_, _| (),
max_gas,
rpc_max_gas_allowance,
rpc_gas_allowance_multiplier,
)
.map(|NewFullBase { task_manager, .. }| task_manager),
#[cfg(feature = "vara-native")]
Expand All @@ -679,7 +679,7 @@ pub fn new_full(
disable_hardware_benchmarks,
|_, _| (),
max_gas,
rpc_max_gas_allowance,
rpc_gas_allowance_multiplier,
)
.map(|NewFullBase { task_manager, .. }| task_manager),
_ => Err(ServiceError::Other("Invalid chain spec".into())),
Expand Down
8 changes: 4 additions & 4 deletions node/service/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ pub struct GrandpaDeps<B> {

/// Extra dependencies for GEAR.
pub struct GearDeps {
/// gas allowance limit.
pub gas_allowance: u64,
/// gas allowance block limit multiplier.
pub allowance_multiplier: u64,
}

/// Full client dependencies.
Expand Down Expand Up @@ -153,7 +153,7 @@ where
finality_provider,
} = grandpa;

let GearDeps { gas_allowance } = gear;
let GearDeps { allowance_multiplier } = gear;

let chain_name = chain_spec.name().to_string();
let genesis_hash = client
Expand Down Expand Up @@ -201,7 +201,7 @@ where
io.merge(StateMigration::new(client.clone(), backend, deny_unsafe).into_rpc())?;
io.merge(Dev::new(client.clone(), deny_unsafe).into_rpc())?;

io.merge(Gear::new(client.clone(), gas_allowance).into_rpc())?;
io.merge(Gear::new(client.clone(), allowance_multiplier).into_rpc())?;

io.merge(RuntimeInfoApi::<C, Block, B>::new(client).into_rpc())?;

Expand Down
9 changes: 5 additions & 4 deletions pallets/gear/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@ sp_api::decl_runtime_apis! {
#[api_version(2)]
pub trait GearApi {
#[allow(clippy::too_many_arguments)]
fn calculate_gas_info(source: H256, kind: HandleKind, payload: Vec<u8>, value: u128, allow_other_panics: bool, initial_gas: Option<u64>, gas_allowance: Option<u64>) -> Result<GasInfo, Vec<u8>>;
fn calculate_gas_info(source: H256, kind: HandleKind, payload: Vec<u8>, value: u128, allow_other_panics: bool, initial_gas: Option<u64>, allowance_multiplier: Option<u64>) -> Result<GasInfo, Vec<u8>>;

/// Generate inherent-like extrinsic that runs message queue processing.
fn gear_run_extrinsic(max_gas: Option<u64>) -> <Block as BlockT>::Extrinsic;

fn read_state(program_id: H256, payload: Vec<u8>, gas_allowance: Option<u64>) -> Result<Vec<u8>, Vec<u8>>;
fn read_state(program_id: H256, payload: Vec<u8>, allowance_multiplier: Option<u64>) -> Result<Vec<u8>, Vec<u8>>;

#[allow(clippy::too_many_arguments)]
fn read_state_using_wasm(program_id: H256, payload: Vec<u8>, fn_name: Vec<u8>, wasm: Vec<u8>, argument: Option<Vec<u8>>, gas_allowance: Option<u64>) -> Result<Vec<u8>, Vec<u8>>;
fn read_state_using_wasm(program_id: H256, payload: Vec<u8>, fn_name: Vec<u8>, wasm: Vec<u8>, argument: Option<Vec<u8>>, allowance_multiplier: Option<u64>) -> Result<Vec<u8>, Vec<u8>>;

fn read_metahash(program_id: H256, gas_allowance: Option<u64>) -> Result<H256, Vec<u8>>;
fn read_metahash(program_id: H256, allowance_multiplier: Option<u64>) -> Result<H256, Vec<u8>>;

// DEPRECATED APIS

#[allow(clippy::too_many_arguments)]
#[changed_in(2)]
fn calculate_gas_info(source: H256, kind: HandleKind, payload: Vec<u8>, value: u128, allow_other_panics: bool, initial_gas: Option<u64>) -> Result<GasInfo, Vec<u8>>;

Expand Down
Loading

0 comments on commit 2103648

Please sign in to comment.