Skip to content

Commit

Permalink
Add missing default gas cost for some abis (#4761)
Browse files Browse the repository at this point in the history
* Add missing default gas cost for some abis

* Add xtask check gas cost definitions

* Update massa-sc-runtime in Cargo.lock

* Update massa-sc-runtime in Cargo.lock - round 2

* Add eclude list in xtask check_gas_cost_definitions

* Cargo fmt pass
  • Loading branch information
sydhds authored Oct 10, 2024
1 parent df74119 commit ca70988
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 6 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ jobs:
submodules: "recursive"
- uses: crate-ci/typos@master

misc:
if: github.ref != 'refs/heads/staging'
needs: sanity
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.81.0
- uses: Swatinem/rust-cache@v2
with:
shared-key: "clippy"
save-if: ${{ github.ref_name == 'main' }}
- run: cargo xtask check_gas_cost_definitions

# Full cross-platform tests required to merge on main branch
full:
name: full
Expand Down
9 changes: 5 additions & 4 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ massa_wallet = { path = "./massa-wallet" }

# Massa projects dependencies
massa-proto-rs = { git = "https://github.com/massalabs/massa-proto-rs", branch = "mainnet_2_3" }
massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", "branch" = "next_breaking_update" }
massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", "branch" = "feature/inconsistent_gas_entries" }
peernet = { git = "https://github.com/massalabs/PeerNet", "rev" = "04b05ddd320fbe76cc858115af7b5fc28bdb8310" }
# Dev only - use local dependencies
# massa-proto-rs = { path = "../massa-proto-rs" }
Expand Down
8 changes: 7 additions & 1 deletion massa-node/base_config/gas_costs/abi_gas_costs.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,11 @@
"abi_unsafe_random": 402,
"abi_verify_signature": 1192,
"abi_chain_id": 301,
"launch_wasmv1": 18641
"launch_wasmv1": 18641,
"assembly_script_console_log": 171,
"assembly_script_console_info": 171,
"assembly_script_console_debug": 171,
"assembly_script_console_warn": 171,
"assembly_script_console_error": 171,
"assembly_script_trace": 171
}
3 changes: 3 additions & 0 deletions massa-xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "2.3.0"
edition = "2021"

[dependencies]
# update_package_versions dependencies
massa_models = {workspace = true}
toml_edit = {workspace = true} # BOM UPGRADE Revert to "0.19.8" if problem
walkdir = {workspace = true}
# check_gas_costs dependencies
massa-sc-runtime = {workspace = true, features = ["gas_calibration"]}
56 changes: 56 additions & 0 deletions massa-xtask/src/check_gas_cost_definitions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use massa_sc_runtime::GasCosts;
use std::collections::HashSet;

pub(crate) fn check_gas_cost_definitions() -> Result<(), String> {
// Check gas cost definition between:
// massa-node/base_config/gas_costs/abi_gas_costs.json
// massa-sc-runtime GasCosts::default()

let gas_costs = GasCosts::default();
let gas_costs_abi_defined = gas_costs
.get_abi_costs()
.keys()
.cloned()
.collect::<HashSet<String>>();

let massa_node_gas_costs = GasCosts::new(
// SETTINGS.execution.abi_gas_costs_file.clone(),
// SETTINGS.execution.wasm_gas_costs_file.clone(),
"massa-node/base_config/gas_costs/abi_gas_costs.json".into(),
"massa-node/base_config/gas_costs/wasm_gas_costs.json".into(),
)
.expect("Failed to load gas costs");

let massa_node_gas_costs_abi_defined = massa_node_gas_costs
.get_abi_costs()
.keys()
.cloned()
.collect::<HashSet<String>>();

let mut found_diff = false;
let diff_1 = gas_costs_abi_defined.difference(&massa_node_gas_costs_abi_defined);
for x1 in diff_1 {
println!("Found in default() but not in json: {x1}");
found_diff = true;
}

let diff_2 = massa_node_gas_costs_abi_defined.difference(&gas_costs_abi_defined);
let exclude_list = HashSet::from([
"cl_compilation",
"launch",
"sp_compilation",
"launch_wasmv1",
"max_instance",
]);
for x2 in diff_2 {
if !exclude_list.contains(x2.as_str()) {
println!("Found in json but not in default(): {x2}");
}
}

if found_diff {
Err("Found gas costs definition differences".to_string())
} else {
Ok(())
}
}
4 changes: 4 additions & 0 deletions massa-xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
mod check_gas_cost_definitions;
mod update_package_versions;

use crate::check_gas_cost_definitions::check_gas_cost_definitions;
use crate::update_package_versions::update_package_versions;
use std::env;

Expand All @@ -10,6 +13,7 @@ fn main() {
match task.as_deref() {
// We can add more tasks here
Some("update_package_versions") => update_package_versions(),
Some("check_gas_cost_definitions") => check_gas_cost_definitions().unwrap(),
_ => panic!("Unknown task"),
}
}

0 comments on commit ca70988

Please sign in to comment.