Skip to content

Commit

Permalink
Merge branch 'main' into testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienFT committed Feb 10, 2023
2 parents 7c5c818 + fe43d5c commit 43dcb30
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 52 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ jobs:
cd gas-calibration &&
sed -i 's!main!${{ github.head_ref || github.ref_name }}!g' Cargo.toml &&
sed -i 's!massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", features = \["gas_calibration"\] }!'"$(cat ../massa-execution-worker/Cargo.toml | grep 'massalabs/massa-sc-runtime' | sed 's!/!\\/!g' | sed 's!}!, features = ["gas_calibration"]}!g' )"'!g' Cargo.toml
- name: "Launch gas-calibration with one SC per ABI in massa-as-sdk to see if there is an ABI missing"
run: >
cd gas-calibration &&
cargo run -r -- --nb-scs-by-abi=1 --as-sdk-env-path=../massa-as-sdk/assembly/env/env.ts --only-generate
#- name: "Launch gas-calibration with one SC per ABI in massa-as-sdk to see if there is an ABI missing"
# run: >
# cd gas-calibration &&
# cargo run -r -- --nb-scs-by-abi=1 --as-sdk-env-path=../massa-as-sdk/assembly/env/env.ts --only-generate


doc:
Expand Down
36 changes: 24 additions & 12 deletions massa-execution-worker/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,9 @@ impl ExecutionState {
bytecode = context.get_bytecode(&target_addr).unwrap_or_default();
}

// run the VM on the bytecode loaded from the target address
let mut module_lock = self.module_cache.write();
let module = module_lock.get_module(&bytecode, max_gas)?;
// Execute bytecode
// IMPORTANT: do not keep a lock here as `run_function` uses the `get_module` interface
let module = self.module_cache.write().get_module(&bytecode, max_gas)?;
match massa_sc_runtime::run_function(
&*self.execution_interface,
module.clone(),
Expand All @@ -625,7 +625,9 @@ impl ExecutionState {
self.config.gas_costs.clone(),
) {
Ok(Response { init_cost, .. }) => {
module_lock.save_module(&bytecode, module, init_cost);
self.module_cache
.write()
.save_module(&bytecode, module, init_cost);
Ok(())
}
Err(err) => Err(ExecutionError::RuntimeError(format!(
Expand Down Expand Up @@ -703,9 +705,12 @@ impl ExecutionState {
bytecode
};

// run the VM on the bytecode contained in the operation
let mut module_lock = self.module_cache.write();
let module = module_lock.get_module(&bytecode, message.max_gas)?;
// Execute bytecode
// IMPORTANT: do not keep a lock here as `run_function` uses the `get_module` interface
let module = self
.module_cache
.write()
.get_module(&bytecode, message.max_gas)?;
match massa_sc_runtime::run_function(
&*self.execution_interface,
module.clone(),
Expand All @@ -715,7 +720,9 @@ impl ExecutionState {
self.config.gas_costs.clone(),
) {
Ok(Response { init_cost, .. }) => {
module_lock.save_module(&bytecode, module, init_cost);
self.module_cache
.write()
.save_module(&bytecode, module, init_cost);
Ok(())
}
Err(err) => {
Expand Down Expand Up @@ -1110,9 +1117,12 @@ impl ExecutionState {
// set the execution context for execution
*context_guard!(self) = execution_context;

// run the target function in the bytecode
let mut module_lock = self.module_cache.write();
let module = module_lock.get_module(&bytecode, req.max_gas)?;
// Execute bytecode
// IMPORTANT: do not keep a lock here as `run_function` uses the `get_module` interface
let module = self
.module_cache
.write()
.get_module(&bytecode, req.max_gas)?;
let response = massa_sc_runtime::run_function(
&*self.execution_interface,
module.clone(),
Expand All @@ -1127,7 +1137,9 @@ impl ExecutionState {
err,
))
})?;
module_lock.save_module(&bytecode, module, response.init_cost);
self.module_cache
.write()
.save_module(&bytecode, module, response.init_cost);
response
}
};
Expand Down
60 changes: 30 additions & 30 deletions massa-execution-worker/src/tests/scenarios_mandatories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ fn init_execution_worker(
/// This test can fail if the gas is going up in the execution
#[test]
#[serial]
#[ignore]
fn test_nested_call_gas_usage() {
// setup the period duration
let exec_cfg = ExecutionConfig {
Expand Down Expand Up @@ -188,32 +187,32 @@ fn test_nested_call_gas_usage() {
block_storage.clone(),
);

std::thread::sleep(Duration::from_millis(10));
std::thread::sleep(Duration::from_millis(100));

// length of the sub contract test.wasm
let bytecode_sub_contract_len = 4374;

let balance = sample_state
.read()
.ledger
.get_balance(&Address::from_public_key(&keypair.get_public_key()))
.unwrap();

let exec_cost = exec_cfg
.storage_costs_constants
.ledger_cost_per_byte
.saturating_mul_u64(bytecode_sub_contract_len);

let balance_expected = Amount::from_str("300000")
.unwrap()
// Gas fee
.saturating_sub(Amount::from_str("10").unwrap())
// Storage cost base
.saturating_sub(exec_cfg.storage_costs_constants.ledger_entry_base_cost)
// Storage cost bytecode
.saturating_sub(exec_cost);

assert_eq!(balance, balance_expected);
// let bytecode_sub_contract_len = 4374;

// let balance = sample_state
// .read()
// .ledger
// .get_balance(&Address::from_public_key(&keypair.get_public_key()))
// .unwrap();

// let exec_cost = exec_cfg
// .storage_costs_constants
// .ledger_cost_per_byte
// .saturating_mul_u64(bytecode_sub_contract_len);

// let balance_expected = Amount::from_str("300000")
// .unwrap()
// // Gas fee
// .saturating_sub(Amount::from_str("10").unwrap())
// // Storage cost base
// .saturating_sub(exec_cfg.storage_costs_constants.ledger_entry_base_cost)
// // Storage cost bytecode
// .saturating_sub(exec_cost);

// assert_eq!(balance, balance_expected);
// retrieve events emitted by smart contracts
let events = controller.get_filtered_sc_output_event(EventFilter {
start: Some(Slot::new(0, 1)),
Expand All @@ -229,14 +228,14 @@ fn test_nested_call_gas_usage() {
10000000,
Amount::from_str("0").unwrap(),
Address::from_str(&address).unwrap(),
address,
b"test".to_vec(),
String::from("test"),
address.as_bytes().to_vec(),
)
.unwrap();
// Init new storage for this block
let mut storage = Storage::create_root();
storage.store_operations(vec![operation.clone()]);
let block = create_block(KeyPair::generate(), vec![operation], Slot::new(1, 1)).unwrap();
let block = create_block(KeyPair::generate(), vec![operation], Slot::new(2, 0)).unwrap();
// store the block in storage
storage.store_block(block.clone());
// set our block as a final block so the message is sent
Expand All @@ -249,12 +248,13 @@ fn test_nested_call_gas_usage() {
Default::default(),
block_storage.clone(),
);
std::thread::sleep(Duration::from_millis(10));
std::thread::sleep(Duration::from_millis(100));
// Get the events that give us the gas usage (refer to source in ts) without fetching the first slot because it emit a event with an address.
let events = controller.get_filtered_sc_output_event(EventFilter {
start: Some(Slot::new(1, 1)),
start: Some(Slot::new(2, 0)),
..Default::default()
});
assert!(events.len() > 0);
// Check that we always subtract gas through the execution (even in sub calls)
assert!(
events.is_sorted_by_key(|event| Reverse(event.data.parse::<u64>().unwrap())),
Expand Down
Binary file modified massa-execution-worker/src/tests/wasm/test.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions massa-models/src/config/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ lazy_static::lazy_static! {
.saturating_add(MassaTime::from_millis(1000 * 10))
)
} else {
1675951200000.into() // Thursday, February 09, 2022 02:00:00 PM UTC
1676034000000.into() // Thursday, February 10, 2023 01:00:00 PM UTC
};

/// TESTNET: time when the blockclique is ended.
pub static ref END_TIMESTAMP: Option<MassaTime> = if cfg!(feature = "sandbox") {
None
} else {
Some(1677596400000.into()) // Tuesday, February 28, 2022 15:00:00 PM UTC
Some(1677596400000.into()) // Tuesday, February 28, 2023 15:00:00 PM UTC
};
/// `KeyPair` to sign genesis blocks.
pub static ref GENESIS_KEY: KeyPair = KeyPair::from_str("S1UxdCJv5ckDK8z87E5Jq5fEfSVLi2cTHgtpfZy7iURs3KpPns8")
Expand All @@ -64,7 +64,7 @@ lazy_static::lazy_static! {
if cfg!(feature = "sandbox") {
"SAND.0.0"
} else {
"TEST.19.2"
"TEST.19.3"
}
.parse()
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion massa-models/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl Deserializer<Version> for VersionDeserializer {
impl Version {
/// true if instance and major are the same
pub fn is_compatible(&self, other: &Version) -> bool {
self.instance == other.instance && self.major == other.major && other.minor >= 2
self.instance == other.instance && self.major == other.major && other.minor >= 3
}
}

Expand Down
2 changes: 1 addition & 1 deletion massa-node/base_config/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openrpc": "1.2.4",
"info": {
"title": "Massa OpenRPC Specification",
"version": "TEST.19.2",
"version": "TEST.19.3",
"description": "Massa OpenRPC Specification document. Find more information on https://docs.massa.net/en/latest/technical-doc/api.html",
"termsOfService": "https://open-rpc.org",
"contact": {
Expand Down
2 changes: 1 addition & 1 deletion tools/setup_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use glob::glob;
use tar::Archive;

// git tag
const TAG: &str = "TEST.19.1";
const TAG: &str = "TEST.19.2";

// Maximum archive file size to download in bytes (here: 1Mb)
// const ARCHIVE_MAX_SIZE: u64 = 2; // Maximum archive file size to download in bytes (DEBUG)
Expand Down

0 comments on commit 43dcb30

Please sign in to comment.