From 676799a6a7d9c3fc692a98b9192a3eb9b1aad310 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Mon, 2 Jan 2023 08:57:46 +0100 Subject: [PATCH 01/80] Add version 19. --- massa-models/src/config/constants.rs | 2 +- massa-node/base_config/openrpc.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/massa-models/src/config/constants.rs b/massa-models/src/config/constants.rs index 993711af466..39d8203a0a7 100644 --- a/massa-models/src/config/constants.rs +++ b/massa-models/src/config/constants.rs @@ -64,7 +64,7 @@ lazy_static::lazy_static! { if cfg!(feature = "sandbox") { "SAND.0.0" } else { - "TEST.18.0" + "TEST.19.0" } .parse() .unwrap() diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index c68fd0b7daf..aa9b57b730f 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -2,7 +2,7 @@ "openrpc": "1.2.4", "info": { "title": "Massa OpenRPC Specification", - "version": "TEST.18.0", + "version": "TEST.19.0", "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": { From 9fa854ac3568502e9ebc696a4cb35e0a18337d77 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Mon, 2 Jan 2023 09:03:08 +0100 Subject: [PATCH 02/80] Update workflow. --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3686136dc3..cc67129037e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "sanity" - save-if: ${{ github.ref == 'refs/pull/3280/merge' }} + save-if: ${{ github.ref == 'refs/pull/3358/merge' }} - uses: actions-rs/cargo@v1 with: command: fmt @@ -55,7 +55,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "check" - save-if: ${{ github.ref == 'refs/pull/3280/merge' }} + save-if: ${{ github.ref == 'refs/pull/3358/merge' }} - uses: actions-rs/cargo@v1 with: command: check @@ -78,7 +78,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "clippy" - save-if: ${{ github.ref == 'refs/pull/3280/merge' }} + save-if: ${{ github.ref == 'refs/pull/3358/merge' }} - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} @@ -108,7 +108,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "massa" - save-if: ${{ github.ref == 'refs/pull/3280/merge' }} + save-if: ${{ github.ref == 'refs/pull/3358/merge' }} - uses: actions-rs/cargo@v1 with: command: install @@ -139,7 +139,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "doc" - save-if: ${{ github.ref == 'refs/pull/3280/merge' }} + save-if: ${{ github.ref == 'refs/pull/3358/merge' }} - uses: actions-rs/cargo@v1 with: command: doc From 3751e18022f7c29f7ce6b292e4d146921ecd563d Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Wed, 4 Jan 2023 20:17:42 +0100 Subject: [PATCH 03/80] fix: missing operation in OpenRPC --- massa-node/base_config/openrpc.json | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index c68fd0b7daf..2b217c3d74d 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -2393,6 +2393,31 @@ }, "additionalProperties": false }, + "Operation": { + "title": "Operation", + "description": "Operation", + "required": [ + "fee", + "expire_period", + "op" + ], + "type": "object", + "properties": { + "fee": { + "description": "the fee they have decided for this operation", + "type": "string" + }, + "expire_period": { + "description": "after `expire_period` slot the operation won't be included in a block", + "type": "number" + }, + "op": { + "$ref": "#/components/schemas/OperationType", + "description": "the type specific operation part" + } + }, + "additionalProperties": false + }, "OperationId": { "description": "Operation id", "type": "string" @@ -2973,6 +2998,14 @@ "$ref": "#/components/schemas/NodeStatus" } }, + "Operation": { + "name": "Operation", + "summary": "Operation", + "description": "A Operation object", + "schema": { + "$ref": "#/components/schemas/Operation" + } + }, "OperationId": { "name": "OperationId", "summary": "OperationId", From e3c37c82217d3c37509c56aa5fa23803a0524acd Mon Sep 17 00:00:00 2001 From: AurelienFT <32803821+AurelienFT@users.noreply.github.com> Date: Thu, 5 Jan 2023 15:47:32 +0100 Subject: [PATCH 04/80] Add gas calibration check to the CI. (#3367) * Update CI files. * Test replace some dependencies branches. * Try new command. * Try to fix usage of ref name. * Fix sed command. * Add clone of massa-as-sdk * Add more replacing in cargo toml * Try new sed command. * Add launch of GC. * debug ci * Remove debug. * Try to have dependencies that build for gas-calibration * Use only generate flag for gas calibration. * try glob pattern in save * Change back save to testnet 19 * Add some documentation --- .github/workflows/cd.yml | 2 +- .github/workflows/ci.yml | 57 +++++++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 9baef8ad1ee..9f7d7ed512f 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -41,7 +41,7 @@ jobs: platform: arm64 runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: "recursive" - uses: actions-rs/toolchain@v1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc67129037e..a37d75a943b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: sanity: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: "recursive" - uses: actions-rs/toolchain@v1 @@ -33,7 +33,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "sanity" - save-if: ${{ github.ref == 'refs/pull/3358/merge' }} + save-if: ${{ github.ref_name == 'testnet_19' }} - uses: actions-rs/cargo@v1 with: command: fmt @@ -45,7 +45,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: "recursive" - uses: actions-rs/toolchain@v1 @@ -55,7 +55,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "check" - save-if: ${{ github.ref == 'refs/pull/3358/merge' }} + save-if: ${{ github.ref_name == 'testnet_19' }} - uses: actions-rs/cargo@v1 with: command: check @@ -66,7 +66,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: "recursive" - uses: actions-rs/toolchain@v1 @@ -78,7 +78,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "clippy" - save-if: ${{ github.ref == 'refs/pull/3358/merge' }} + save-if: ${{ github.ref_name == 'testnet_19' }} - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} @@ -97,7 +97,7 @@ jobs: - macOS-latest - windows-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: "recursive" - uses: actions-rs/toolchain@v1 @@ -108,7 +108,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "massa" - save-if: ${{ github.ref == 'refs/pull/3358/merge' }} + save-if: ${{ github.ref_name == 'testnet_19' }} - uses: actions-rs/cargo@v1 with: command: install @@ -124,10 +124,47 @@ jobs: steps: - run: exit 0 + # Maybe launch it only in testnet branches + gas-costs-check: + if: github.ref != 'refs/heads/staging' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: "recursive" + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly-2022-12-24 + components: rustfmt + override: true + - uses: actions/checkout@v3 + with: + repository: massalabs/gas-calibration + path: gas-calibration + ref: main + - uses: actions/checkout@v3 + with: + repository: massalabs/massa-as-sdk + path: massa-as-sdk + ref: main + # Replace the branch in the dependencies in gas-calibration project by the current branch + # Special case for massa-sc-runtime: we use the branch referenced in the Cargo.toml of massa-execution-worker. + - name: "Use the current branch as dependency for gas-calibration" + run: > + 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 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 + + doc: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: "recursive" - uses: actions-rs/toolchain@v1 @@ -139,7 +176,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "doc" - save-if: ${{ github.ref == 'refs/pull/3358/merge' }} + save-if: ${{ github.ref_name == 'testnet_19' }} - uses: actions-rs/cargo@v1 with: command: doc From 99e4220705d859f29b20d7d1ec6a9ad80d912023 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Fri, 6 Jan 2023 09:57:41 +0100 Subject: [PATCH 05/80] improve get_boot_state --- massa-bootstrap/src/tests/tools.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/massa-bootstrap/src/tests/tools.rs b/massa-bootstrap/src/tests/tools.rs index 08486ce29d5..b4d0602932d 100644 --- a/massa-bootstrap/src/tests/tools.rs +++ b/massa-bootstrap/src/tests/tools.rs @@ -372,7 +372,9 @@ pub fn get_boot_state() -> BootstrapableGraph { Block { header: BlockHeader::new_wrapped( BlockHeader { - slot: Slot::new(1, 1), + // associated slot + // all header endorsements are supposed to point towards this one + slot: Slot::new(1, 0), parents: vec![get_dummy_block_id("p1"); THREAD_COUNT as usize], operation_merkle_root: Hash::compute_from("op_hash".as_bytes()), endorsements: vec![ @@ -388,7 +390,7 @@ pub fn get_boot_state() -> BootstrapableGraph { .unwrap(), Endorsement::new_wrapped( Endorsement { - slot: Slot::new(4, 1), + slot: Slot::new(1, 0), index: 3, endorsed_block: get_dummy_block_id("p1"), }, @@ -437,6 +439,11 @@ pub fn get_boot_state() -> BootstrapableGraph { .unwrap(); assert_eq_bootstrap_graph(&bootstrapable_graph_deserialized, &boot_graph); + for blk in bootstrapable_graph_deserialized.final_blocks.iter() { + for endo in blk.block.content.header.content.endorsements.iter() { + endo.verify_signature().unwrap(); + } + } boot_graph } From 60cd51dc83d114a5d55299de550dbb86fd2d8214 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Fri, 6 Jan 2023 12:30:53 +0100 Subject: [PATCH 06/80] remove endorsement sig verification check --- massa-bootstrap/src/tests/tools.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/massa-bootstrap/src/tests/tools.rs b/massa-bootstrap/src/tests/tools.rs index b4d0602932d..2f209318971 100644 --- a/massa-bootstrap/src/tests/tools.rs +++ b/massa-bootstrap/src/tests/tools.rs @@ -439,11 +439,6 @@ pub fn get_boot_state() -> BootstrapableGraph { .unwrap(); assert_eq_bootstrap_graph(&bootstrapable_graph_deserialized, &boot_graph); - for blk in bootstrapable_graph_deserialized.final_blocks.iter() { - for endo in blk.block.content.header.content.endorsements.iter() { - endo.verify_signature().unwrap(); - } - } boot_graph } From 678b52672a5327fb367a0948731dee17223d3b2d Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Fri, 6 Jan 2023 15:29:04 +0100 Subject: [PATCH 07/80] Fix spelling of bootstrap and hot reloading on whitelist and blacklist files --- massa-api/src/lib.rs | 16 ++-- massa-api/src/private.rs | 28 +++---- massa-bootstrap/src/server.rs | 116 ++++++++++++++-------------- massa-client/src/cmds.rs | 24 +++--- massa-models/src/api.rs | 2 +- massa-node/base_config/openrpc.json | 28 +++---- massa-sdk/src/lib.rs | 16 ++-- 7 files changed, 117 insertions(+), 113 deletions(-) diff --git a/massa-api/src/lib.rs b/massa-api/src/lib.rs index b6b72e5333e..60a1596f754 100644 --- a/massa-api/src/lib.rs +++ b/massa-api/src/lib.rs @@ -267,32 +267,32 @@ pub trait MassaRpc { #[method(name = "node_remove_from_peers_whitelist")] async fn node_remove_from_peers_whitelist(&self, arg: Vec) -> RpcResult<()>; - /// Returns node bootsrap whitelist IP address(es). + /// Returns node bootstrap whitelist IP address(es). #[method(name = "node_bootstrap_whitelist")] async fn node_bootstrap_whitelist(&self) -> RpcResult>; - /// Allow everyone to bootsrap from the node. - /// remove bootsrap whitelist configuration file. + /// Allow everyone to bootstrap from the node. + /// remove bootstrap whitelist configuration file. #[method(name = "node_bootstrap_whitelist_allow_all")] async fn node_bootstrap_whitelist_allow_all(&self) -> RpcResult<()>; - /// Add IP address(es) to node bootsrap whitelist. + /// Add IP address(es) to node bootstrap whitelist. #[method(name = "node_add_to_bootstrap_whitelist")] async fn node_add_to_bootstrap_whitelist(&self, arg: Vec) -> RpcResult<()>; - /// Remove IP address(es) to bootsrap whitelist. + /// Remove IP address(es) to bootstrap whitelist. #[method(name = "node_remove_from_bootstrap_whitelist")] async fn node_remove_from_bootstrap_whitelist(&self, arg: Vec) -> RpcResult<()>; - /// Returns node bootsrap blacklist IP address(es). + /// Returns node bootstrap blacklist IP address(es). #[method(name = "node_bootstrap_blacklist")] async fn node_bootstrap_blacklist(&self) -> RpcResult>; - /// Add IP address(es) to node bootsrap blacklist. + /// Add IP address(es) to node bootstrap blacklist. #[method(name = "node_add_to_bootstrap_blacklist")] async fn node_add_to_bootstrap_blacklist(&self, arg: Vec) -> RpcResult<()>; - /// Remove IP address(es) to bootsrap blacklist. + /// Remove IP address(es) to bootstrap blacklist. #[method(name = "node_remove_from_bootstrap_blacklist")] async fn node_remove_from_bootstrap_blacklist(&self, arg: Vec) -> RpcResult<()>; diff --git a/massa-api/src/private.rs b/massa-api/src/private.rs index c1048cac6a6..23631b84141 100644 --- a/massa-api/src/private.rs +++ b/massa-api/src/private.rs @@ -250,7 +250,7 @@ impl MassaRpcServer for API { async fn node_bootstrap_whitelist_allow_all(&self) -> RpcResult<()> { remove_file(self.0.api_settings.bootstrap_whitelist_path.clone()).map_err(|e| { ApiError::InternalServerError(format!( - "failed to delete bootsrap whitelist configuration file: {}", + "failed to delete bootstrap whitelist configuration file: {}", e )) .into() @@ -305,7 +305,7 @@ impl MassaRpcServer for API { } } -/// Run Search, Create, Read, Update, Delete operation on bootsrap list of IP(s) +/// Run Search, Create, Read, Update, Delete operation on bootstrap list of IP(s) fn run_scrud_operation( bootstrap_list_file: PathBuf, ips: Vec, @@ -330,7 +330,7 @@ fn run_scrud_operation( .and_then(|length| { if length == 0 { Err(ApiError::InternalServerError(format!( - "failed, bootsrap {} configuration file is empty", + "failed, bootstrap {} configuration file is empty", list_type )) .into()) @@ -340,7 +340,7 @@ fn run_scrud_operation( .and_then(|mut list_ips: BTreeSet| { if list_ips.is_empty() { return Err(ApiError::InternalServerError(format!( - "failed to execute delete operation, bootsrap {} is empty", + "failed to execute delete operation, bootstrap {} is empty", list_type )) .into()); @@ -373,7 +373,7 @@ fn get_file_len( .open(bootstrap_list_file) .map_err(|e| { ApiError::InternalServerError(format!( - "failed to read bootsrap {} configuration file: {}", + "failed to read bootstrap {} configuration file: {}", list_type, e )) .into() @@ -381,14 +381,14 @@ fn get_file_len( .and_then(|file| match file.metadata() { Ok(metadata) => Ok(metadata.len()), Err(e) => Err(ApiError::InternalServerError(format!( - "failed to read bootsrap {} configuration file metadata: {}", + "failed to read bootstrap {} configuration file metadata: {}", list_type, e )) .into()), }) } -/// Read bootsrap list IP(s) from json file +/// Read bootstrap list IP(s) from json file fn read_ips_from_jsonfile( bootstrap_list_file: PathBuf, list_type: &ListType, @@ -396,15 +396,15 @@ fn read_ips_from_jsonfile( std::fs::read_to_string(bootstrap_list_file) .map_err(|e| { ApiError::InternalServerError(format!( - "failed to read bootsrap {} configuration file: {}", + "failed to read bootstrap {} configuration file: {}", list_type, e )) .into() }) - .and_then(|bootsrap_list_str| { - serde_json::from_str(&bootsrap_list_str).map_err(|e| { + .and_then(|bootstrap_list_str| { + serde_json::from_str(&bootstrap_list_str).map_err(|e| { ApiError::InternalServerError(format!( - "failed to parse bootsrap {} configuration file: {}", + "failed to parse bootstrap {} configuration file: {}", list_type, e )) .into() @@ -412,7 +412,7 @@ fn read_ips_from_jsonfile( }) } -/// Write bootsrap list IP(s) from json file +/// Write bootstrap list IP(s) from json file fn write_ips_to_jsonfile( bootstrap_list_file: PathBuf, ips: BTreeSet, @@ -425,7 +425,7 @@ fn write_ips_to_jsonfile( .open(bootstrap_list_file) .map_err(|e| { ApiError::InternalServerError(format!( - "failed to create bootsrap {} configuration file: {}", + "failed to create bootstrap {} configuration file: {}", list_type, e )) .into() @@ -433,7 +433,7 @@ fn write_ips_to_jsonfile( .and_then(|file| { serde_json::to_writer_pretty(file, &ips).map_err(|e| { ApiError::InternalServerError(format!( - "failed to write bootsrap {} configuration file: {}", + "failed to write bootstrap {} configuration file: {}", list_type, e )) .into() diff --git a/massa-bootstrap/src/server.rs b/massa-bootstrap/src/server.rs index 7fa3160738b..33cf744dc96 100644 --- a/massa-bootstrap/src/server.rs +++ b/massa-bootstrap/src/server.rs @@ -17,9 +17,9 @@ use std::{ collections::{hash_map, HashMap, HashSet}, net::{IpAddr, SocketAddr}, sync::Arc, - time::{Duration, Instant}, + time::{Duration, Instant}, path::PathBuf, }; -use tokio::{sync::mpsc, task::JoinHandle}; +use tokio::{sync::mpsc, task::JoinHandle, time::{sleep, sleep_until}}; use tracing::{debug, info, warn}; use crate::{ @@ -66,42 +66,6 @@ pub async fn start_bootstrap_server( if let Some(bind) = bootstrap_config.bind { let (manager_tx, manager_rx) = mpsc::channel::<()>(1); - let whitelist = if let Ok(whitelist) = - std::fs::read_to_string(&bootstrap_config.bootstrap_whitelist_path) - { - Some( - serde_json::from_str::>(whitelist.as_str()) - .map_err(|_| { - BootstrapError::GeneralError(String::from( - "Failed to parse bootstrap whitelist", - )) - })? - .into_iter() - .map(normalize_ip) - .collect(), - ) - } else { - None - }; - - let blacklist = if let Ok(blacklist) = - std::fs::read_to_string(&bootstrap_config.bootstrap_blacklist_path) - { - Some( - serde_json::from_str::>(blacklist.as_str()) - .map_err(|_| { - BootstrapError::GeneralError(String::from( - "Failed to parse bootstrap blacklist", - )) - })? - .into_iter() - .map(normalize_ip) - .collect(), - ) - } else { - None - }; - let join_handle = tokio::spawn(async move { BootstrapServer { consensus_controller, @@ -112,8 +76,6 @@ pub async fn start_bootstrap_server( bind, keypair, version, - whitelist, - blacklist, ip_hist_map: HashMap::with_capacity(bootstrap_config.ip_list_max_size), bootstrap_config, } @@ -139,26 +101,67 @@ struct BootstrapServer { keypair: KeyPair, bootstrap_config: BootstrapConfig, version: Version, - blacklist: Option>, - whitelist: Option>, ip_hist_map: HashMap, } +#[allow(clippy::result_large_err)] +#[allow(clippy::type_complexity)] +fn reload_whitelist_blacklist( + whitelist_path: &PathBuf, + blacklist_path: &PathBuf, +) -> Result<(Option>, Option>), BootstrapError> { + let whitelist = if let Ok(whitelist) = + std::fs::read_to_string(whitelist_path) + { + Some( + serde_json::from_str::>(whitelist.as_str()) + .map_err(|_| { + BootstrapError::GeneralError(String::from( + "Failed to parse bootstrap whitelist", + )) + })? + .into_iter() + .map(normalize_ip) + .collect(), + ) + } else { + None + }; + + let blacklist = if let Ok(blacklist) = + std::fs::read_to_string(blacklist_path) + { + Some( + serde_json::from_str::>(blacklist.as_str()) + .map_err(|_| { + BootstrapError::GeneralError(String::from( + "Failed to parse bootstrap blacklist", + )) + })? + .into_iter() + .map(normalize_ip) + .collect(), + ) + } else { + None + }; + Ok((whitelist, blacklist)) +} + impl BootstrapServer { pub async fn run(mut self) -> Result<(), BootstrapError> { debug!("starting bootstrap server"); massa_trace!("bootstrap.lib.run", {}); let mut listener = self.establisher.get_listener(self.bind).await?; let mut bootstrap_sessions = FuturesUnordered::new(); - // let cache_timeout = self.bootstrap_config.cache_duration.to_duration(); - // let mut bootstrap_data: Option<( - // BootstrapableGraph, - // BootstrapPeers, - // Arc>, - // )> = None; - // let cache_timer = sleep(cache_timeout); + let cache_timeout = self.bootstrap_config.cache_duration.to_duration(); + let (mut whitelist, mut blacklist) = reload_whitelist_blacklist( + &self.bootstrap_config.bootstrap_whitelist_path, + &self.bootstrap_config.bootstrap_blacklist_path, + )?; + let cache_timer = sleep(cache_timeout); let per_ip_min_interval = self.bootstrap_config.per_ip_min_interval.to_duration(); - // tokio::pin!(cache_timer); + tokio::pin!(cache_timer); /* select! without the "biased" modifier will randomly select the 1st branch to check, then will check the next ones in the order they are written. @@ -177,11 +180,12 @@ impl BootstrapServer { break }, - // cache cleanup timeout - // _ = &mut cache_timer, if bootstrap_data.is_some() => { - // massa_trace!("bootstrap.lib.run.cache_unload", {}); - // bootstrap_data = None; - // } + // Whitelist cache timeout + _ = &mut cache_timer => { + (whitelist, blacklist) = reload_whitelist_blacklist(&self.bootstrap_config.bootstrap_whitelist_path, &self.bootstrap_config.bootstrap_blacklist_path)?; + let instant = tokio::time::Instant::now().checked_add(self.bootstrap_config.per_ip_min_interval.to_duration()).ok_or(BootstrapError::GeneralError("Fail to setup cache timeout".to_string()))?; + cache_timer.set(sleep_until(instant)); + } // bootstrap session finished Some(_) = bootstrap_sessions.next() => { @@ -189,7 +193,7 @@ impl BootstrapServer { } // listener - res_connection = listener.accept(&self.whitelist, &self.blacklist) => { + res_connection = listener.accept(&whitelist, &blacklist) => { let (dplx, remote_addr) = if res_connection.is_ok() { res_connection.unwrap() } else { diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index b05f3e6336b..9a0966402ad 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -103,14 +103,14 @@ pub enum Command { props(args = "(add, remove or allow-all) [IpAddr]"), message = "Manage boostrap whitelist IP address(es).No args returns the whitelist blacklist" )] - node_bootsrap_whitelist, + node_bootstrap_whitelist, #[strum( ascii_case_insensitive, props(args = "(add or remove) [IpAddr]"), message = "Manage boostrap blacklist IP address(es). No args returns the boostrap blacklist" )] - node_bootsrap_blacklist, + node_bootstrap_blacklist, #[strum( ascii_case_insensitive, @@ -1022,10 +1022,10 @@ impl Command { Err(e) => rpc_error!(e), } } - Command::node_bootsrap_blacklist => { + Command::node_bootstrap_blacklist => { if parameters.is_empty() { match client.private.node_bootstrap_blacklist().await { - Ok(bootsraplist_ips) => Ok(Box::new(bootsraplist_ips)), + Ok(bootstraplist_ips) => Ok(Box::new(bootstraplist_ips)), Err(e) => rpc_error!(e), } } else { @@ -1046,7 +1046,7 @@ impl Command { Ok(()) => { if !json { println!( - "Request of bootsrap blacklisting successfully sent!" + "Request of bootstrap blacklisting successfully sent!" ) } Ok(Box::new(())) @@ -1062,7 +1062,7 @@ impl Command { { Ok(()) => { if !json { - println!("Request of remove from bootsrap blacklist successfully sent!") + println!("Request of remove from bootstrap blacklist successfully sent!") } Ok(Box::new(())) } @@ -1076,12 +1076,12 @@ impl Command { res } } - Command::node_bootsrap_whitelist => { + Command::node_bootstrap_whitelist => { if parameters.is_empty() { match client.private.node_bootstrap_whitelist().await { - Ok(bootsraplist_ips) => Ok(Box::new(bootsraplist_ips)), + Ok(bootstraplist_ips) => Ok(Box::new(bootstraplist_ips)), Err(e) => { - client_warning!("if bootsrap whitelist configuration file does't exists, bootsrap is allowed for everyone !!!"); + client_warning!("if bootstrap whitelist configuration file does't exists, bootstrap is allowed for everyone !!!"); rpc_error!(e) } } @@ -1106,7 +1106,7 @@ impl Command { Ok(()) => { if !json { println!( - "Request of bootsrap whitelisting successfully sent!" + "Request of bootstrap whitelisting successfully sent!" ) } Ok(Box::new(())) @@ -1125,7 +1125,7 @@ impl Command { { Ok(()) => { if !json { - println!("Request of remove from bootsrap whitelist successfully sent!") + println!("Request of remove from bootstrap whitelist successfully sent!") } Ok(Box::new(())) } @@ -1137,7 +1137,7 @@ impl Command { Ok(()) => { if !json { println!( - "Request of bootsrap whitelisting everyone successfully sent!" + "Request of bootstrap whitelisting everyone successfully sent!" ) } Ok(Box::new(())) diff --git a/massa-models/src/api.rs b/massa-models/src/api.rs index 931ab7f48ab..b084ed1a99e 100644 --- a/massa-models/src/api.rs +++ b/massa-models/src/api.rs @@ -608,7 +608,7 @@ pub enum ScrudOperation { Delete, } -/// Bootsrap lists types +/// bootstrap lists types #[derive(Display)] #[strum(serialize_all = "snake_case")] pub enum ListType { diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index 2b217c3d74d..5968ad7cc57 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -503,8 +503,8 @@ "schema": false }, "name": "node_add_to_bootstrap_blacklist", - "summary": "Add to bootsrap blacklist given IP address(es)", - "description": "Add to bootsrap blacklist given IP address(es)." + "summary": "Add to bootstrap blacklist given IP address(es)", + "description": "Add to bootstrap blacklist given IP address(es)." }, { "tags": [ @@ -533,8 +533,8 @@ "schema": false }, "name": "node_add_to_bootstrap_whitelist", - "summary": "Add to bootsrap whitelist given IP address(es)", - "description": "Add to bootsrap whitelist given IP address(es)." + "summary": "Add to bootstrap whitelist given IP address(es)", + "description": "Add to bootstrap whitelist given IP address(es)." }, { "tags": [ @@ -644,8 +644,8 @@ } }, "name": "node_bootstrap_blacklist", - "summary": "Returns bootsrap blacklist IP address(es)", - "description": "Returns bootsrap blacklist IP address(es)." + "summary": "Returns bootstrap blacklist IP address(es)", + "description": "Returns bootstrap blacklist IP address(es)." }, { "tags": [ @@ -667,8 +667,8 @@ } }, "name": "node_bootstrap_whitelist", - "summary": "Returns bootsrap whitelist IP address(es)", - "description": "Returns bootsrap whitelist IP address(es)." + "summary": "Returns bootstrap whitelist IP address(es)", + "description": "Returns bootstrap whitelist IP address(es)." }, { "tags": [ @@ -684,8 +684,8 @@ "schema": false }, "name": "node_bootstrap_whitelist_allow_all", - "summary": "Allow everyone to bootsrap from the node", - "description": "Allow everyone to bootsrap from the node. Remove bootsrap whitelist configuration file." + "summary": "Allow everyone to bootstrap from the node", + "description": "Allow everyone to bootstrap from the node. Remove bootstrap whitelist configuration file." }, { "tags": [ @@ -737,8 +737,8 @@ "schema": false }, "name": "node_remove_from_bootstrap_blacklist", - "summary": "Remove from bootsrap blacklist given IP address(es)", - "description": "Remove from bootsrap blacklist given IP address(es)." + "summary": "Remove from bootstrap blacklist given IP address(es)", + "description": "Remove from bootstrap blacklist given IP address(es)." }, { "tags": [ @@ -767,8 +767,8 @@ "schema": false }, "name": "node_remove_from_bootstrap_whitelist", - "summary": "Remove from bootsrap whitelist given IP address(es)", - "description": "Remove from bootsrap whitelist given IP address(es)." + "summary": "Remove from bootstrap whitelist given IP address(es)", + "description": "Remove from bootstrap whitelist given IP address(es)." }, { "tags": [ diff --git a/massa-sdk/src/lib.rs b/massa-sdk/src/lib.rs index 60278ecf266..e06d9b23061 100644 --- a/massa-sdk/src/lib.rs +++ b/massa-sdk/src/lib.rs @@ -193,50 +193,50 @@ impl RpcClient { .await } - /// Returns node bootsrap whitelist IP address(es). + /// Returns node bootstrap whitelist IP address(es). pub async fn node_bootstrap_whitelist(&self) -> RpcResult> { self.http_client .request("node_bootstrap_whitelist", rpc_params![]) .await } - /// Allow everyone to bootsrap from the node. - /// remove bootsrap whitelist configuration file. + /// Allow everyone to bootstrap from the node. + /// remove bootstrap whitelist configuration file. pub async fn node_bootstrap_whitelist_allow_all(&self) -> RpcResult<()> { self.http_client .request("node_bootstrap_whitelist_allow_all", rpc_params![]) .await } - /// Add IP address(es) to node bootsrap whitelist. + /// Add IP address(es) to node bootstrap whitelist. pub async fn node_add_to_bootstrap_whitelist(&self, ips: Vec) -> RpcResult<()> { self.http_client .request("node_add_to_bootstrap_whitelist", rpc_params![ips]) .await } - /// Remove IP address(es) to bootsrap whitelist. + /// Remove IP address(es) to bootstrap whitelist. pub async fn node_remove_from_bootstrap_whitelist(&self, ips: Vec) -> RpcResult<()> { self.http_client .request("node_remove_from_bootstrap_whitelist", rpc_params![ips]) .await } - /// Returns node bootsrap blacklist IP address(es). + /// Returns node bootstrap blacklist IP address(es). pub async fn node_bootstrap_blacklist(&self) -> RpcResult> { self.http_client .request("node_bootstrap_blacklist", rpc_params![]) .await } - /// Add IP address(es) to node bootsrap blacklist. + /// Add IP address(es) to node bootstrap blacklist. pub async fn node_add_to_bootstrap_blacklist(&self, ips: Vec) -> RpcResult<()> { self.http_client .request("node_add_to_bootstrap_blacklist", rpc_params![ips]) .await } - /// Remove IP address(es) to bootsrap blacklist. + /// Remove IP address(es) to bootstrap blacklist. pub async fn node_remove_from_bootstrap_blacklist(&self, ips: Vec) -> RpcResult<()> { self.http_client .request("node_remove_from_bootstrap_blacklist", rpc_params![ips]) From e3d254428a5d79288bb3d158ae3678892992e045 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Fri, 6 Jan 2023 16:02:13 +0100 Subject: [PATCH 08/80] Format. --- massa-bootstrap/src/server.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/massa-bootstrap/src/server.rs b/massa-bootstrap/src/server.rs index 33cf744dc96..6284e6ef3aa 100644 --- a/massa-bootstrap/src/server.rs +++ b/massa-bootstrap/src/server.rs @@ -16,10 +16,15 @@ use parking_lot::RwLock; use std::{ collections::{hash_map, HashMap, HashSet}, net::{IpAddr, SocketAddr}, + path::PathBuf, sync::Arc, - time::{Duration, Instant}, path::PathBuf, + time::{Duration, Instant}, +}; +use tokio::{ + sync::mpsc, + task::JoinHandle, + time::{sleep, sleep_until}, }; -use tokio::{sync::mpsc, task::JoinHandle, time::{sleep, sleep_until}}; use tracing::{debug, info, warn}; use crate::{ @@ -110,9 +115,7 @@ fn reload_whitelist_blacklist( whitelist_path: &PathBuf, blacklist_path: &PathBuf, ) -> Result<(Option>, Option>), BootstrapError> { - let whitelist = if let Ok(whitelist) = - std::fs::read_to_string(whitelist_path) - { + let whitelist = if let Ok(whitelist) = std::fs::read_to_string(whitelist_path) { Some( serde_json::from_str::>(whitelist.as_str()) .map_err(|_| { @@ -128,9 +131,7 @@ fn reload_whitelist_blacklist( None }; - let blacklist = if let Ok(blacklist) = - std::fs::read_to_string(blacklist_path) - { + let blacklist = if let Ok(blacklist) = std::fs::read_to_string(blacklist_path) { Some( serde_json::from_str::>(blacklist.as_str()) .map_err(|_| { From 4a2f79a124c70f1cad4dfe4204c2734968b94c8d Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Fri, 6 Jan 2023 17:26:04 +0100 Subject: [PATCH 09/80] Change pinned variable with sleep with a tokio interval. --- massa-bootstrap/src/server.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/massa-bootstrap/src/server.rs b/massa-bootstrap/src/server.rs index 6284e6ef3aa..5da0968a97d 100644 --- a/massa-bootstrap/src/server.rs +++ b/massa-bootstrap/src/server.rs @@ -20,11 +20,7 @@ use std::{ sync::Arc, time::{Duration, Instant}, }; -use tokio::{ - sync::mpsc, - task::JoinHandle, - time::{sleep, sleep_until}, -}; +use tokio::{sync::mpsc, task::JoinHandle}; use tracing::{debug, info, warn}; use crate::{ @@ -160,9 +156,8 @@ impl BootstrapServer { &self.bootstrap_config.bootstrap_whitelist_path, &self.bootstrap_config.bootstrap_blacklist_path, )?; - let cache_timer = sleep(cache_timeout); + let mut cache_interval = tokio::time::interval(cache_timeout); let per_ip_min_interval = self.bootstrap_config.per_ip_min_interval.to_duration(); - tokio::pin!(cache_timer); /* select! without the "biased" modifier will randomly select the 1st branch to check, then will check the next ones in the order they are written. @@ -182,10 +177,8 @@ impl BootstrapServer { }, // Whitelist cache timeout - _ = &mut cache_timer => { + _ = cache_interval.tick() => { (whitelist, blacklist) = reload_whitelist_blacklist(&self.bootstrap_config.bootstrap_whitelist_path, &self.bootstrap_config.bootstrap_blacklist_path)?; - let instant = tokio::time::Instant::now().checked_add(self.bootstrap_config.per_ip_min_interval.to_duration()).ok_or(BootstrapError::GeneralError("Fail to setup cache timeout".to_string()))?; - cache_timer.set(sleep_until(instant)); } // bootstrap session finished From 94297f5822cbcfdfd883ae9798dcd23c3252fa8f Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 9 Jan 2023 12:26:07 +0100 Subject: [PATCH 10/80] Testnet 19 bph wrapper rename (#3384) Rename `Wrapper` (and friends) to `SecureSend` (and friends) Also expanded on some doc-comments. --- massa-api/src/public.rs | 22 +- massa-bootstrap/src/tests/tools.rs | 12 +- massa-client/src/cmds.rs | 2 +- massa-consensus-exports/src/block_status.rs | 6 +- .../src/controller_trait.rs | 6 +- .../src/export_active_block.rs | 30 +-- .../src/test_exports/mock.rs | 10 +- massa-consensus-worker/src/commands.rs | 6 +- massa-consensus-worker/src/controller.rs | 20 +- massa-consensus-worker/src/state/mod.rs | 8 +- massa-consensus-worker/src/state/process.rs | 18 +- .../src/state/process_commands.rs | 8 +- massa-consensus-worker/src/state/prune.rs | 10 +- .../src/state/verifications.rs | 11 +- massa-consensus-worker/src/worker/init.rs | 14 +- massa-executed-ops/src/executed_ops.rs | 4 +- massa-execution-worker/src/execution.rs | 14 +- massa-execution-worker/src/tests/mock.rs | 14 +- .../src/tests/scenarios_mandatories.rs | 20 +- .../src/test_exports/tools.rs | 10 +- massa-factory-worker/src/block_factory.rs | 12 +- .../src/endorsement_factory.rs | 11 +- massa-factory-worker/src/tests/scenarios.rs | 8 +- massa-factory-worker/src/tests/tools.rs | 10 +- massa-models/src/api.rs | 8 +- massa-models/src/block.rs | 153 +++++++------- massa-models/src/composite.rs | 4 +- massa-models/src/endorsement.rs | 33 +-- massa-models/src/lib.rs | 4 +- massa-models/src/operation.rs | 70 +++---- .../src/{wrapped.rs => secure_share.rs} | 192 ++++++++++-------- massa-network-exports/src/commands.rs | 34 ++-- .../src/network_controller.rs | 12 +- massa-network-worker/src/messages.rs | 32 +-- massa-network-worker/src/network_cmd_impl.rs | 12 +- massa-network-worker/src/network_event.rs | 14 +- massa-network-worker/src/node_worker.rs | 2 +- massa-network-worker/src/tests/scenarios.rs | 6 +- massa-network-worker/src/tests/tools.rs | 8 +- .../src/tests/operation_pool_tests.rs | 16 +- massa-pool-worker/src/tests/tools.rs | 26 +-- massa-pool-worker/src/types.rs | 10 +- .../src/protocol_controller.rs | 6 +- .../src/tests/mock_network_controller.rs | 12 +- massa-protocol-exports/src/tests/tools.rs | 40 ++-- massa-protocol-worker/src/protocol_network.rs | 28 +-- massa-protocol-worker/src/protocol_worker.rs | 26 +-- .../src/tests/ask_block_scenarios.rs | 2 +- .../src/tests/ban_nodes_scenarios.rs | 2 +- .../tests/in_block_operations_scenarios.rs | 22 +- .../src/tests/operations_scenarios.rs | 2 +- massa-protocol-worker/src/tests/tools.rs | 8 +- .../src/worker_operations_impl.rs | 6 +- massa-storage/src/block_indexes.rs | 14 +- massa-storage/src/endorsement_indexes.rs | 17 +- massa-storage/src/lib.rs | 14 +- massa-storage/src/operation_indexes.rs | 14 +- massa-wallet/src/lib.rs | 8 +- 58 files changed, 598 insertions(+), 545 deletions(-) rename massa-models/src/{wrapped.rs => secure_share.rs} (61%) diff --git a/massa-api/src/public.rs b/massa-api/src/public.rs index 58b82824d8d..a05f6e140cf 100644 --- a/massa-api/src/public.rs +++ b/massa-api/src/public.rs @@ -17,10 +17,10 @@ use massa_models::api::{ }; use massa_models::execution::ReadOnlyResult; use massa_models::operation::OperationDeserializer; -use massa_models::wrapped::WrappedDeserializer; +use massa_models::secure_share::SecureShareDeserializer; use massa_models::{ - block::Block, endorsement::WrappedEndorsement, error::ModelsError, operation::WrappedOperation, - timeslots, + block::Block, endorsement::SecureShareEndorsement, error::ModelsError, + operation::SecureShareOperation, timeslots, }; use massa_pos_exports::SelectorController; use massa_protocol_exports::ProtocolCommandSender; @@ -425,7 +425,7 @@ impl MassaRpcServer for API { async fn get_operations(&self, ops: Vec) -> RpcResult> { // get the operations and the list of blocks that contain them from storage - let storage_info: Vec<(WrappedOperation, PreHashSet)> = { + let storage_info: Vec<(SecureShareOperation, PreHashSet)> = { let read_blocks = self.0.storage.read_blocks(); let read_ops = self.0.storage.read_operations(); ops.iter() @@ -503,7 +503,7 @@ impl MassaRpcServer for API { async fn get_endorsements(&self, eds: Vec) -> RpcResult> { // get the endorsements and the list of blocks that contain them from storage - let storage_info: Vec<(WrappedEndorsement, PreHashSet)> = { + let storage_info: Vec<(SecureShareEndorsement, PreHashSet)> = { let read_blocks = self.0.storage.read_blocks(); let read_endos = self.0.storage.read_endorsements(); eds.iter() @@ -588,7 +588,7 @@ impl MassaRpcServer for API { let blocks = ids .into_iter() .filter_map(|id| { - if let Some(wrapped_block) = storage.read_blocks().get(&id).cloned() { + if let Some(verifiable_block) = storage.read_blocks().get(&id).cloned() { if let Some(graph_status) = consensus_controller .get_block_statuses(&[id]) .into_iter() @@ -608,7 +608,7 @@ impl MassaRpcServer for API { is_in_blockclique, is_candidate, is_discarded, - block: wrapped_block.content, + block: verifiable_block.content, }), }); } @@ -677,7 +677,7 @@ impl MassaRpcServer for API { is_stale: false, is_in_blockclique: blockclique.block_ids.contains(&id), slot: exported_block.header.content.slot, - creator: exported_block.header.creator_address, + creator: exported_block.header.content_creator_address, parents: exported_block.header.content.parents, }); } @@ -859,7 +859,7 @@ impl MassaRpcServer for API { if ops.len() as u64 > api_cfg.max_arguments { return Err(ApiError::BadRequest("too many arguments".into()).into()); } - let operation_deserializer = WrappedDeserializer::new(OperationDeserializer::new( + let operation_deserializer = SecureShareDeserializer::new(OperationDeserializer::new( api_cfg.max_datastore_value_length, api_cfg.max_function_name_length, api_cfg.max_parameter_size, @@ -874,7 +874,7 @@ impl MassaRpcServer for API { op_serialized.extend(op_input.signature.to_bytes()); op_serialized.extend(op_input.creator_public_key.to_bytes()); op_serialized.extend(op_input.serialized_content); - let (rest, op): (&[u8], WrappedOperation) = operation_deserializer + let (rest, op): (&[u8], SecureShareOperation) = operation_deserializer .deserialize::(&op_serialized) .map_err(|err| { ApiError::ModelsError(ModelsError::DeserializeError(err.to_string())) @@ -898,7 +898,7 @@ impl MassaRpcServer for API { } Err(e) => Err(e), }) - .collect::>>()?; + .collect::>>()?; to_send.store_operations(verified_ops.clone()); let ids: Vec = verified_ops.iter().map(|op| op.id).collect(); cmd_sender.add_operations(to_send.clone()); diff --git a/massa-bootstrap/src/tests/tools.rs b/massa-bootstrap/src/tests/tools.rs index 2f209318971..1681441bb6f 100644 --- a/massa-bootstrap/src/tests/tools.rs +++ b/massa-bootstrap/src/tests/tools.rs @@ -37,9 +37,9 @@ use massa_models::{ endorsement::EndorsementSerializer, operation::OperationId, prehash::PreHashMap, + secure_share::Id, + secure_share::SecureShareContent, slot::Slot, - wrapped::Id, - wrapped::WrappedContent, }; use massa_network_exports::{BootstrapPeers, NetworkCommand}; use massa_pos_exports::{CycleInfo, DeferredCredits, PoSChanges, PoSFinalState, ProductionStats}; @@ -368,9 +368,9 @@ pub fn assert_eq_bootstrap_graph(v1: &BootstrapableGraph, v2: &BootstrapableGrap pub fn get_boot_state() -> BootstrapableGraph { let keypair = KeyPair::generate(); - let block = Block::new_wrapped( + let block = Block::new_verifiable( Block { - header: BlockHeader::new_wrapped( + header: BlockHeader::new_verifiable( BlockHeader { // associated slot // all header endorsements are supposed to point towards this one @@ -378,7 +378,7 @@ pub fn get_boot_state() -> BootstrapableGraph { parents: vec![get_dummy_block_id("p1"); THREAD_COUNT as usize], operation_merkle_root: Hash::compute_from("op_hash".as_bytes()), endorsements: vec![ - Endorsement::new_wrapped( + Endorsement::new_verifiable( Endorsement { slot: Slot::new(1, 0), index: 1, @@ -388,7 +388,7 @@ pub fn get_boot_state() -> BootstrapableGraph { &keypair, ) .unwrap(), - Endorsement::new_wrapped( + Endorsement::new_verifiable( Endorsement { slot: Slot::new(1, 0), index: 3, diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index b05f3e6336b..90072c168fd 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -1238,7 +1238,7 @@ async fn send_operation( match client .public .send_operations(vec![OperationInput { - creator_public_key: op.creator_public_key, + creator_public_key: op.content_creator_pub_key, serialized_content: op.serialized_data, signature: op.signature, }]) diff --git a/massa-consensus-exports/src/block_status.rs b/massa-consensus-exports/src/block_status.rs index 2138a969489..9ad461f5906 100644 --- a/massa-consensus-exports/src/block_status.rs +++ b/massa-consensus-exports/src/block_status.rs @@ -1,7 +1,7 @@ use massa_models::{ active_block::ActiveBlock, address::Address, - block::{Block, BlockId, WrappedHeader}, + block::{Block, BlockId, SecuredHeader}, prehash::PreHashSet, slot::Slot, }; @@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone)] #[allow(clippy::large_enum_variant)] pub enum HeaderOrBlock { - Header(WrappedHeader), + Header(SecuredHeader), Block { id: BlockId, slot: Slot, @@ -100,7 +100,7 @@ pub enum ExportBlockStatus { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ExportCompiledBlock { /// Header of the corresponding block. - pub header: WrappedHeader, + pub header: SecuredHeader, /// For (i, set) in children, /// set contains the headers' hashes /// of blocks referencing exported block as a parent, diff --git a/massa-consensus-exports/src/controller_trait.rs b/massa-consensus-exports/src/controller_trait.rs index b46baf1764d..eb76e3bb7ef 100644 --- a/massa-consensus-exports/src/controller_trait.rs +++ b/massa-consensus-exports/src/controller_trait.rs @@ -6,9 +6,9 @@ use massa_models::{ api::BlockGraphStatus, block::{BlockHeader, BlockId}, clique::Clique, + secure_share::SecureShare, slot::Slot, stats::ConsensusStats, - wrapped::Wrapped, }; use massa_storage::Storage; @@ -107,14 +107,14 @@ pub trait ConsensusController: Send + Sync { /// # Arguments /// * `block_id`: the id of the block to register /// * `header`: the header of the block to register - fn register_block_header(&self, block_id: BlockId, header: Wrapped); + fn register_block_header(&self, block_id: BlockId, header: SecureShare); /// Mark a block as invalid in the graph /// /// # Arguments /// * `block_id`: the id of the block to mark as invalid /// * `header`: the header of the block to mark as invalid - fn mark_invalid_block(&self, block_id: BlockId, header: Wrapped); + fn mark_invalid_block(&self, block_id: BlockId, header: SecureShare); /// Returns a boxed clone of self. /// Useful to allow cloning `Box`. diff --git a/massa-consensus-exports/src/export_active_block.rs b/massa-consensus-exports/src/export_active_block.rs index 7f594f549ed..6e707de1085 100644 --- a/massa-consensus-exports/src/export_active_block.rs +++ b/massa-consensus-exports/src/export_active_block.rs @@ -2,9 +2,9 @@ use crate::error::ConsensusError; use massa_hash::HashDeserializer; use massa_models::{ active_block::ActiveBlock, - block::{Block, BlockDeserializer, BlockId, WrappedBlock}, + block::{Block, BlockDeserializer, BlockId, SecureShareBlock}, prehash::PreHashMap, - wrapped::{WrappedDeserializer, WrappedSerializer}, + secure_share::{SecureShareDeserializer, SecureShareSerializer}, }; use massa_serialization::{ Deserializer, SerializeError, Serializer, U64VarIntDeserializer, U64VarIntSerializer, @@ -27,7 +27,7 @@ use std::ops::Bound::Included; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ExportActiveBlock { /// The block. - pub block: WrappedBlock, + pub block: SecureShareBlock, /// one `(block id, period)` per thread ( if not genesis ) pub parents: Vec<(BlockId, u64)>, /// for example has its fitness reached the given threshold @@ -69,7 +69,7 @@ impl ExportActiveBlock { // create ActiveBlock let active_block = ActiveBlock { - creator_address: self.block.creator_address, + creator_address: self.block.content_creator_address, block_id: self.block.id, parents: self.parents.clone(), children: vec![PreHashMap::default(); thread_count as usize], // will be computed once the full graph is available @@ -89,7 +89,7 @@ impl ExportActiveBlock { /// Basic serializer of `ExportActiveBlock` #[derive(Default)] pub struct ExportActiveBlockSerializer { - wrapped_serializer: WrappedSerializer, + sec_share_serializer: SecureShareSerializer, period_serializer: U64VarIntSerializer, } @@ -97,7 +97,7 @@ impl ExportActiveBlockSerializer { /// Create a new `ExportActiveBlockSerializer` pub fn new() -> Self { ExportActiveBlockSerializer { - wrapped_serializer: WrappedSerializer::new(), + sec_share_serializer: SecureShareSerializer::new(), period_serializer: U64VarIntSerializer::new(), } } @@ -110,7 +110,7 @@ impl Serializer for ExportActiveBlockSerializer { buffer: &mut Vec, ) -> Result<(), SerializeError> { // block - self.wrapped_serializer.serialize(&value.block, buffer)?; + self.sec_share_serializer.serialize(&value.block, buffer)?; // parents with periods // note: there should be no parents for genesis blocks @@ -129,7 +129,7 @@ impl Serializer for ExportActiveBlockSerializer { /// Basic deserializer of `ExportActiveBlock` pub struct ExportActiveBlockDeserializer { - wrapped_block_deserializer: WrappedDeserializer, + sec_share_block_deserializer: SecureShareDeserializer, hash_deserializer: HashDeserializer, period_deserializer: U64VarIntDeserializer, thread_count: u8, @@ -140,7 +140,7 @@ impl ExportActiveBlockDeserializer { #[allow(clippy::too_many_arguments)] pub fn new(thread_count: u8, endorsement_count: u32, max_operations_per_block: u32) -> Self { ExportActiveBlockDeserializer { - wrapped_block_deserializer: WrappedDeserializer::new(BlockDeserializer::new( + sec_share_block_deserializer: SecureShareDeserializer::new(BlockDeserializer::new( thread_count, max_operations_per_block, endorsement_count, @@ -156,7 +156,7 @@ impl Deserializer for ExportActiveBlockDeserializer { /// ## Example: /// ```rust /// use massa_consensus_exports::export_active_block::{ExportActiveBlock, ExportActiveBlockDeserializer, ExportActiveBlockSerializer}; - /// use massa_models::{ledger_models::LedgerChanges, config::THREAD_COUNT, rolls::RollUpdates, block::{BlockId, Block, BlockSerializer, BlockHeader, BlockHeaderSerializer}, prehash::PreHashSet, endorsement::{Endorsement, EndorsementSerializerLW}, slot::Slot, wrapped::WrappedContent}; + /// use massa_models::{ledger_models::LedgerChanges, config::THREAD_COUNT, rolls::RollUpdates, block::{BlockId, Block, BlockSerializer, BlockHeader, BlockHeaderSerializer}, prehash::PreHashSet, endorsement::{Endorsement, EndorsementSerializerLW}, slot::Slot, secure_share::SecureShareContent}; /// use massa_hash::Hash; /// use std::collections::HashSet; /// use massa_signature::KeyPair; @@ -168,13 +168,13 @@ impl Deserializer for ExportActiveBlockDeserializer { /// .collect(); /// /// // create block header - /// let orig_header = BlockHeader::new_wrapped( + /// let orig_header = BlockHeader::new_verifiable( /// BlockHeader { /// slot: Slot::new(1, 1), /// parents, /// operation_merkle_root: Hash::compute_from("mno".as_bytes()), /// endorsements: vec![ - /// Endorsement::new_wrapped( + /// Endorsement::new_verifiable( /// Endorsement { /// slot: Slot::new(1, 1), /// index: 1, @@ -184,7 +184,7 @@ impl Deserializer for ExportActiveBlockDeserializer { /// &keypair, /// ) /// .unwrap(), - /// Endorsement::new_wrapped( + /// Endorsement::new_verifiable( /// Endorsement { /// slot: Slot::new(4, 0), /// index: 3, @@ -207,7 +207,7 @@ impl Deserializer for ExportActiveBlockDeserializer { /// operations: Vec::new(), /// }; /// - /// let full_block = Block::new_wrapped(orig_block, BlockSerializer::new(), &keypair).unwrap(); + /// let full_block = Block::new_verifiable(orig_block, BlockSerializer::new(), &keypair).unwrap(); /// let export_active_block = ExportActiveBlock { /// block: full_block.clone(), /// parents: vec![], @@ -230,7 +230,7 @@ impl Deserializer for ExportActiveBlockDeserializer { tuple(( // block context("Failed block deserialization", |input| { - self.wrapped_block_deserializer.deserialize(input) + self.sec_share_block_deserializer.deserialize(input) }), // parents context( diff --git a/massa-consensus-exports/src/test_exports/mock.rs b/massa-consensus-exports/src/test_exports/mock.rs index f4603b16bf4..8ceb43fb103 100644 --- a/massa-consensus-exports/src/test_exports/mock.rs +++ b/massa-consensus-exports/src/test_exports/mock.rs @@ -10,10 +10,10 @@ use massa_models::{ block::{BlockHeader, BlockId}, clique::Clique, prehash::PreHashSet, + secure_share::SecureShare, slot::Slot, stats::ConsensusStats, streaming_step::StreamingStep, - wrapped::Wrapped, }; use massa_storage::Storage; use massa_time::MassaTime; @@ -74,7 +74,7 @@ pub enum MockConsensusControllerMessage { }, MarkInvalidBlock { block_id: BlockId, - header: Wrapped, + header: SecureShare, }, RegisterBlock { block_id: BlockId, @@ -84,7 +84,7 @@ pub enum MockConsensusControllerMessage { }, RegisterBlockHeader { block_id: BlockId, - header: Wrapped, + header: SecureShare, }, } @@ -237,7 +237,7 @@ impl ConsensusController for MockConsensusController { response_rx.recv().unwrap() } - fn mark_invalid_block(&self, block_id: BlockId, header: Wrapped) { + fn mark_invalid_block(&self, block_id: BlockId, header: SecureShare) { self.0 .lock() .unwrap() @@ -258,7 +258,7 @@ impl ConsensusController for MockConsensusController { .unwrap(); } - fn register_block_header(&self, block_id: BlockId, header: Wrapped) { + fn register_block_header(&self, block_id: BlockId, header: SecureShare) { self.0 .lock() .unwrap() diff --git a/massa-consensus-worker/src/commands.rs b/massa-consensus-worker/src/commands.rs index 4ca74d79f94..e9852478491 100644 --- a/massa-consensus-worker/src/commands.rs +++ b/massa-consensus-worker/src/commands.rs @@ -1,13 +1,13 @@ use massa_models::{ block::{BlockHeader, BlockId}, + secure_share::SecureShare, slot::Slot, - wrapped::Wrapped, }; use massa_storage::Storage; #[allow(clippy::large_enum_variant)] pub enum ConsensusCommand { RegisterBlock(BlockId, Slot, Storage, bool), - RegisterBlockHeader(BlockId, Wrapped), - MarkInvalidBlock(BlockId, Wrapped), + RegisterBlockHeader(BlockId, SecureShare), + MarkInvalidBlock(BlockId, SecureShare), } diff --git a/massa-consensus-worker/src/controller.rs b/massa-consensus-worker/src/controller.rs index d0f1928fd40..3234b5003ae 100644 --- a/massa-consensus-worker/src/controller.rs +++ b/massa-consensus-worker/src/controller.rs @@ -9,10 +9,10 @@ use massa_models::{ clique::Clique, operation::{Operation, OperationId}, prehash::PreHashSet, + secure_share::SecureShare, slot::Slot, stats::ConsensusStats, streaming_step::StreamingStep, - wrapped::Wrapped, }; use massa_storage::Storage; use parking_lot::RwLock; @@ -227,15 +227,17 @@ impl ConsensusController for ConsensusControllerImpl { fn register_block(&self, block_id: BlockId, slot: Slot, block_storage: Storage, created: bool) { if self.broadcast_enabled { - if let Some(wrapped_block) = block_storage.read_blocks().get(&block_id) { - let operations: Vec<(OperationId, Option>)> = - wrapped_block + if let Some(verifiable_block) = block_storage.read_blocks().get(&block_id) { + let operations: Vec<(OperationId, Option>)> = + verifiable_block .content .operations .iter() .map(|operation_id| { match block_storage.read_operations().get(operation_id).cloned() { - Some(wrapped_operation) => (*operation_id, Some(wrapped_operation)), + Some(verifiable_operation) => { + (*operation_id, Some(verifiable_operation)) + } None => (*operation_id, None), } }) @@ -244,10 +246,10 @@ impl ConsensusController for ConsensusControllerImpl { let _block_receivers_count = self .channels .block_sender - .send(wrapped_block.content.clone()); + .send(verifiable_block.content.clone()); let _filled_block_receivers_count = self.channels.filled_block_sender.send(FilledBlock { - header: wrapped_block.content.header.clone(), + header: verifiable_block.content.header.clone(), operations, }); } else { @@ -271,7 +273,7 @@ impl ConsensusController for ConsensusControllerImpl { } } - fn register_block_header(&self, block_id: BlockId, header: Wrapped) { + fn register_block_header(&self, block_id: BlockId, header: SecureShare) { if self.broadcast_enabled { let _ = self .channels @@ -286,7 +288,7 @@ impl ConsensusController for ConsensusControllerImpl { } } - fn mark_invalid_block(&self, block_id: BlockId, header: Wrapped) { + fn mark_invalid_block(&self, block_id: BlockId, header: SecureShare) { if let Err(err) = self .command_sender .try_send(ConsensusCommand::MarkInvalidBlock(block_id, header)) diff --git a/massa-consensus-worker/src/state/mod.rs b/massa-consensus-worker/src/state/mod.rs index 41beb4edf0f..aa370247eb3 100644 --- a/massa-consensus-worker/src/state/mod.rs +++ b/massa-consensus-worker/src/state/mod.rs @@ -13,7 +13,7 @@ use massa_models::{ active_block::ActiveBlock, address::Address, api::BlockGraphStatus, - block::{BlockId, WrappedHeader}, + block::{BlockId, SecuredHeader}, clique::Clique, prehash::{CapacityAllocator, PreHashMap, PreHashSet}, slot::Slot, @@ -86,7 +86,7 @@ pub struct ConsensusState { /// the time span considered for desynchronization detection pub stats_desync_detection_timespan: MassaTime, /// blocks we want - pub wishlist: PreHashMap>, + pub wishlist: PreHashMap>, /// previous blockclique notified to Execution pub prev_blockclique: PreHashMap, } @@ -466,8 +466,8 @@ impl ConsensusState { /// get the current block wish list, including the operations hash. pub fn get_block_wishlist( &self, - ) -> Result>, ConsensusError> { - let mut wishlist = PreHashMap::>::default(); + ) -> Result>, ConsensusError> { + let mut wishlist = PreHashMap::>::default(); for block_id in self.waiting_for_dependencies_index.iter() { if let Some(BlockStatus::WaitingForDependencies { unsatisfied_dependencies, diff --git a/massa-consensus-worker/src/state/process.rs b/massa-consensus-worker/src/state/process.rs index 04ddeb1fb66..270d075fbfa 100644 --- a/massa-consensus-worker/src/state/process.rs +++ b/massa-consensus-worker/src/state/process.rs @@ -11,7 +11,7 @@ use massa_logging::massa_trace; use massa_models::{ active_block::ActiveBlock, address::Address, - block::{BlockId, WrappedHeader}, + block::{BlockId, SecuredHeader}, clique::Clique, prehash::{PreHashMap, PreHashSet}, slot::Slot, @@ -173,15 +173,17 @@ impl ConsensusState { massa_trace!("consensus.block_graph.process.incoming_header.discarded", {"block_id": block_id, "reason": reason}); // count stales if reason == DiscardReason::Stale { - self.new_stale_blocks - .insert(block_id, (header.creator_address, header.content.slot)); + self.new_stale_blocks.insert( + block_id, + (header.content_creator_address, header.content.slot), + ); } // discard self.block_statuses.insert( block_id, BlockStatus::Discarded { slot: header.content.slot, - creator: header.creator_address, + creator: header.content_creator_address, parents: header.content.parents, reason, sequence_number: { @@ -239,7 +241,7 @@ impl ConsensusState { "block_id": block_id }); ( - stored_block.content.header.creator_public_key, + stored_block.content.header.content_creator_pub_key, slot, parents_hash_period, incompatibilities, @@ -299,7 +301,7 @@ impl ConsensusState { self.new_stale_blocks.insert( block_id, ( - stored_block.content.header.creator_address, + stored_block.content.header.content_creator_address, stored_block.content.header.content.slot, ), ); @@ -309,7 +311,7 @@ impl ConsensusState { block_id, BlockStatus::Discarded { slot: stored_block.content.header.content.slot, - creator: stored_block.creator_address, + creator: stored_block.content_creator_address, parents: stored_block.content.header.content.parents.clone(), reason, sequence_number: { @@ -822,7 +824,7 @@ impl ConsensusState { // notify protocol of block wishlist let new_wishlist = self.get_block_wishlist()?; - let new_blocks: PreHashMap> = new_wishlist + let new_blocks: PreHashMap> = new_wishlist .iter() .filter_map(|(id, header)| { if !self.wishlist.contains_key(id) { diff --git a/massa-consensus-worker/src/state/process_commands.rs b/massa-consensus-worker/src/state/process_commands.rs index 3677ed3aa1c..196377353fc 100644 --- a/massa-consensus-worker/src/state/process_commands.rs +++ b/massa-consensus-worker/src/state/process_commands.rs @@ -6,7 +6,7 @@ use massa_consensus_exports::{ }; use massa_logging::massa_trace; use massa_models::{ - block::{BlockId, WrappedHeader}, + block::{BlockId, SecuredHeader}, slot::Slot, }; use massa_storage::Storage; @@ -28,7 +28,7 @@ impl ConsensusState { pub fn register_block_header( &mut self, block_id: BlockId, - header: WrappedHeader, + header: SecuredHeader, current_slot: Option, ) -> Result<(), ConsensusError> { // ignore genesis blocks @@ -164,7 +164,7 @@ impl ConsensusState { /// # Arguments: /// * `block_id`: Block id of the block to mark as invalid /// * `header`: Header of the block to mark as invalid - pub fn mark_invalid_block(&mut self, block_id: &BlockId, header: WrappedHeader) { + pub fn mark_invalid_block(&mut self, block_id: &BlockId, header: SecuredHeader) { let reason = DiscardReason::Invalid("invalid".to_string()); self.maybe_note_attack_attempt(&reason, block_id); massa_trace!("consensus.block_graph.process.invalid_block", {"block_id": block_id, "reason": reason}); @@ -174,7 +174,7 @@ impl ConsensusState { *block_id, BlockStatus::Discarded { slot: header.content.slot, - creator: header.creator_address, + creator: header.content_creator_address, parents: header.content.parents, reason, sequence_number: { diff --git a/massa-consensus-worker/src/state/prune.rs b/massa-consensus-worker/src/state/prune.rs index d1387b25004..beda15cdb14 100644 --- a/massa-consensus-worker/src/state/prune.rs +++ b/massa-consensus-worker/src/state/prune.rs @@ -57,7 +57,7 @@ impl ConsensusState { )) })?; block_slot = block.content.header.content.slot; - block_creator = block.creator_address; + block_creator = block.content_creator_address; block_parents = block.content.header.content.parents.clone(); }; @@ -301,15 +301,17 @@ impl ConsensusState { if let Some(reason) = reason_opt { // add to stats if reason is Stale if reason == DiscardReason::Stale { - self.new_stale_blocks - .insert(block_id, (header.creator_address, header.content.slot)); + self.new_stale_blocks.insert( + block_id, + (header.content_creator_address, header.content.slot), + ); } // transition to Discarded only if there is a reason self.block_statuses.insert( block_id, BlockStatus::Discarded { slot: header.content.slot, - creator: header.creator_address, + creator: header.content_creator_address, parents: header.content.parents.clone(), reason, sequence_number: { diff --git a/massa-consensus-worker/src/state/verifications.rs b/massa-consensus-worker/src/state/verifications.rs index 9fc6dc11be8..86835c421bd 100644 --- a/massa-consensus-worker/src/state/verifications.rs +++ b/massa-consensus-worker/src/state/verifications.rs @@ -6,7 +6,7 @@ use massa_consensus_exports::{ }; use massa_logging::massa_trace; use massa_models::{ - block::{BlockId, WrappedHeader}, + block::{BlockId, SecuredHeader}, prehash::PreHashSet, slot::Slot, }; @@ -66,7 +66,7 @@ impl ConsensusState { pub fn check_header( &self, block_id: &BlockId, - header: &WrappedHeader, + header: &SecuredHeader, current_slot: Option, read_shared_state: &ConsensusState, ) -> Result { @@ -77,7 +77,7 @@ impl ConsensusState { Vec::with_capacity(self.config.thread_count as usize); let mut incomp = PreHashSet::::default(); let mut missing_deps = PreHashSet::::default(); - let creator_addr = header.creator_address; + let creator_addr = header.content_creator_address; // check that is older than the latest final block in that thread // Note: this excludes genesis blocks @@ -376,7 +376,7 @@ impl ConsensusState { /// * endorsed slot is `parent_in_own_thread` slot pub fn check_endorsements( &self, - header: &WrappedHeader, + header: &SecuredHeader, ) -> Result { // check endorsements let endorsement_draws = match self @@ -389,7 +389,8 @@ impl ConsensusState { }; for endorsement in header.content.endorsements.iter() { // check that the draw is correct - if endorsement.creator_address != endorsement_draws[endorsement.content.index as usize] + if endorsement.content_creator_address + != endorsement_draws[endorsement.content.index as usize] { return Ok(EndorsementsCheckOutcome::Discard(DiscardReason::Invalid( format!( diff --git a/massa-consensus-worker/src/worker/init.rs b/massa-consensus-worker/src/worker/init.rs index f2adeee6d5d..9b2d5be07ff 100644 --- a/massa-consensus-worker/src/worker/init.rs +++ b/massa-consensus-worker/src/worker/init.rs @@ -6,11 +6,13 @@ use massa_hash::Hash; use massa_models::{ active_block::ActiveBlock, address::Address, - block::{Block, BlockHeader, BlockHeaderSerializer, BlockId, BlockSerializer, WrappedBlock}, + block::{ + Block, BlockHeader, BlockHeaderSerializer, BlockId, BlockSerializer, SecureShareBlock, + }, prehash::PreHashMap, + secure_share::SecureShareContent, slot::Slot, timeslots::{get_block_slot_timestamp, get_latest_block_slot_at_timestamp}, - wrapped::WrappedContent, }; use massa_storage::Storage; use massa_time::MassaTime; @@ -36,9 +38,9 @@ use super::ConsensusWorker; pub fn create_genesis_block( cfg: &ConsensusConfig, thread_number: u8, -) -> Result { +) -> Result { let keypair = &cfg.genesis_key; - let header = BlockHeader::new_wrapped( + let header = BlockHeader::new_verifiable( BlockHeader { slot: Slot::new(0, thread_number), parents: Vec::new(), @@ -49,7 +51,7 @@ pub fn create_genesis_block( keypair, )?; - Ok(Block::new_wrapped( + Ok(Block::new_verifiable( Block { header, operations: Default::default(), @@ -102,7 +104,7 @@ impl ConsensusWorker { block.id, BlockStatus::Active { a_block: Box::new(ActiveBlock { - creator_address: block.creator_address, + creator_address: block.content_creator_address, parents: Vec::new(), children: vec![PreHashMap::default(); config.thread_count as usize], descendants: Default::default(), diff --git a/massa-executed-ops/src/executed_ops.rs b/massa-executed-ops/src/executed_ops.rs index c0265778e2c..b0c3d50ea8b 100644 --- a/massa-executed-ops/src/executed_ops.rs +++ b/massa-executed-ops/src/executed_ops.rs @@ -8,9 +8,9 @@ use massa_hash::{Hash, HASH_SIZE_BYTES}; use massa_models::{ operation::{OperationId, OperationIdDeserializer}, prehash::PreHashSet, + secure_share::Id, slot::{Slot, SlotDeserializer, SlotSerializer}, streaming_step::StreamingStep, - wrapped::Id, }; use massa_serialization::{ Deserializer, SerializeError, Serializer, U64VarIntDeserializer, U64VarIntSerializer, @@ -164,7 +164,7 @@ impl ExecutedOps { #[test] fn test_executed_ops_xor_computing() { use massa_models::prehash::PreHashMap; - use massa_models::wrapped::Id; + use massa_models::secure_share::Id; // initialize the executed ops config let config = ExecutedOpsConfig { diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 4e14a67b5fa..31351111ca1 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -27,7 +27,7 @@ use massa_models::stats::ExecutionStats; use massa_models::{ address::Address, block::BlockId, - operation::{OperationId, OperationType, WrappedOperation}, + operation::{OperationId, OperationType, SecureShareOperation}, }; use massa_models::{amount::Amount, slot::Slot}; use massa_pos_exports::SelectorController; @@ -192,7 +192,7 @@ impl ExecutionState { /// * `block_credits`: mutable reference towards the total block reward/fee credits pub fn execute_operation( &self, - operation: &WrappedOperation, + operation: &SecureShareOperation, block_slot: Slot, remaining_block_gas: &mut u64, block_credits: &mut Amount, @@ -214,7 +214,7 @@ impl ExecutionState { })?; // get the operation's sender address - let sender_addr = operation.creator_address; + let sender_addr = operation.content_creator_address; // get the thread to which the operation belongs let op_thread = sender_addr.get_thread(self.config.thread_count); @@ -270,7 +270,7 @@ impl ExecutionState { context.max_gas = operation.get_gas_usage(); // set the creator address - context.creator_address = Some(operation.creator_address); + context.creator_address = Some(operation.content_creator_address); // set the context origin operation ID context.origin_operation_id = Some(operation_id); @@ -780,7 +780,7 @@ impl ExecutionState { .content .endorsements .iter() - .map(|endo| (endo.creator_address, endo.content.endorsed_block)) + .map(|endo| (endo.content_creator_address, endo.content.endorsed_block)) .unzip(); // deduce endorsement target block creators @@ -792,7 +792,7 @@ impl ExecutionState { blocks .get(b_id) .expect("endorsed block absent from storage") - .creator_address + .content_creator_address }) .collect::>() }; @@ -820,7 +820,7 @@ impl ExecutionState { } // Get block creator address - let block_creator_addr = stored_block.creator_address; + let block_creator_addr = stored_block.content_creator_address; // acquire lock on execution context let mut context = context_guard!(self); diff --git a/massa-execution-worker/src/tests/mock.rs b/massa-execution-worker/src/tests/mock.rs index 119ae0226fa..99c473ff393 100644 --- a/massa-execution-worker/src/tests/mock.rs +++ b/massa-execution-worker/src/tests/mock.rs @@ -19,10 +19,10 @@ use tempfile::TempDir; #[cfg(feature = "testing")] use massa_models::{ - block::{Block, BlockHeader, BlockHeaderSerializer, BlockSerializer, WrappedBlock}, - operation::WrappedOperation, + block::{Block, BlockHeader, BlockHeaderSerializer, BlockSerializer, SecureShareBlock}, + operation::SecureShareOperation, + secure_share::SecureShareContent, slot::Slot, - wrapped::WrappedContent, }; #[cfg(feature = "testing")] @@ -139,16 +139,16 @@ pub fn get_sample_state() -> Result<(Arc>, NamedTempFile, Tem #[cfg(feature = "testing")] pub fn create_block( creator_keypair: KeyPair, - operations: Vec, + operations: Vec, slot: Slot, -) -> Result { +) -> Result { let operation_merkle_root = Hash::compute_from( &operations.iter().fold(Vec::new(), |acc, v| { [acc, v.serialized_data.clone()].concat() })[..], ); - let header = BlockHeader::new_wrapped( + let header = BlockHeader::new_verifiable( BlockHeader { slot, parents: vec![], @@ -159,7 +159,7 @@ pub fn create_block( &creator_keypair, )?; - Ok(Block::new_wrapped( + Ok(Block::new_verifiable( Block { header, operations: operations.into_iter().map(|op| op.id).collect(), diff --git a/massa-execution-worker/src/tests/scenarios_mandatories.rs b/massa-execution-worker/src/tests/scenarios_mandatories.rs index 2ca0e35490f..8d58fbc7ac8 100644 --- a/massa-execution-worker/src/tests/scenarios_mandatories.rs +++ b/massa-execution-worker/src/tests/scenarios_mandatories.rs @@ -13,8 +13,8 @@ use massa_models::{ api::EventFilter, block::BlockId, datastore::Datastore, - operation::{Operation, OperationSerializer, OperationType, WrappedOperation}, - wrapped::WrappedContent, + operation::{Operation, OperationSerializer, OperationType, SecureShareOperation}, + secure_share::SecureShareContent, }; use massa_signature::KeyPair; use massa_storage::Storage; @@ -684,7 +684,7 @@ pub fn send_and_receive_transaction() { KeyPair::from_str("S1JJeHiZv1C1zZN5GLFcbz6EXYiccmUPLkYuDFA3kayjxP39kFQ").unwrap(); let (recipient_address, _keypair) = get_random_address_full(); // create the operation - let operation = Operation::new_wrapped( + let operation = Operation::new_verifiable( Operation { fee: Amount::zero(), expire_period: 10, @@ -761,7 +761,7 @@ pub fn roll_buy() { let keypair = KeyPair::from_str("S1JJeHiZv1C1zZN5GLFcbz6EXYiccmUPLkYuDFA3kayjxP39kFQ").unwrap(); let address = Address::from_public_key(&keypair.get_public_key()); // create the operation - let operation = Operation::new_wrapped( + let operation = Operation::new_verifiable( Operation { fee: Amount::zero(), expire_period: 10, @@ -840,7 +840,7 @@ pub fn roll_sell() { let roll_sell_2 = 1; // create operation 1 - let operation1 = Operation::new_wrapped( + let operation1 = Operation::new_verifiable( Operation { fee: Amount::zero(), expire_period: 10, @@ -852,7 +852,7 @@ pub fn roll_sell() { &keypair, ) .unwrap(); - let operation2 = Operation::new_wrapped( + let operation2 = Operation::new_verifiable( Operation { fee: Amount::zero(), expire_period: 10, @@ -1283,13 +1283,13 @@ fn create_execute_sc_operation( sender_keypair: &KeyPair, data: &[u8], datastore: Datastore, -) -> Result { +) -> Result { let op = OperationType::ExecuteSC { data: data.to_vec(), max_gas: 1_000_000, datastore, }; - let op = Operation::new_wrapped( + let op = Operation::new_verifiable( Operation { fee: Amount::from_mantissa_scale(10, 0), expire_period: 10, @@ -1310,7 +1310,7 @@ fn create_call_sc_operation( target_addr: Address, target_func: String, param: Vec, -) -> Result { +) -> Result { let op = OperationType::CallSC { max_gas, target_addr, @@ -1318,7 +1318,7 @@ fn create_call_sc_operation( target_func, param, }; - let op = Operation::new_wrapped( + let op = Operation::new_verifiable( Operation { fee, expire_period: 10, diff --git a/massa-factory-exports/src/test_exports/tools.rs b/massa-factory-exports/src/test_exports/tools.rs index 6634f703e7b..b3b51365bce 100644 --- a/massa-factory-exports/src/test_exports/tools.rs +++ b/massa-factory-exports/src/test_exports/tools.rs @@ -1,14 +1,14 @@ use massa_hash::Hash; use massa_models::{ - block::{Block, BlockHeader, BlockHeaderSerializer, BlockSerializer, WrappedBlock}, + block::{Block, BlockHeader, BlockHeaderSerializer, BlockSerializer, SecureShareBlock}, + secure_share::SecureShareContent, slot::Slot, - wrapped::WrappedContent, }; use massa_signature::KeyPair; /// Create an empty block for testing. Can be used to generate genesis blocks. -pub fn create_empty_block(keypair: &KeyPair, slot: &Slot) -> WrappedBlock { - let header = BlockHeader::new_wrapped( +pub fn create_empty_block(keypair: &KeyPair, slot: &Slot) -> SecureShareBlock { + let header = BlockHeader::new_verifiable( BlockHeader { slot: *slot, parents: Vec::new(), @@ -20,7 +20,7 @@ pub fn create_empty_block(keypair: &KeyPair, slot: &Slot) -> WrappedBlock { ) .unwrap(); - Block::new_wrapped( + Block::new_verifiable( Block { header, operations: Default::default(), diff --git a/massa-factory-worker/src/block_factory.rs b/massa-factory-worker/src/block_factory.rs index 39cf3c9f9c6..4fd187d988a 100644 --- a/massa-factory-worker/src/block_factory.rs +++ b/massa-factory-worker/src/block_factory.rs @@ -3,12 +3,12 @@ use massa_factory_exports::{FactoryChannels, FactoryConfig}; use massa_hash::Hash; use massa_models::{ - block::{Block, BlockHeader, BlockHeaderSerializer, BlockId, BlockSerializer, WrappedHeader}, - endorsement::WrappedEndorsement, + block::{Block, BlockHeader, BlockHeaderSerializer, BlockId, BlockSerializer, SecuredHeader}, + endorsement::SecureShareEndorsement, prehash::PreHashSet, + secure_share::SecureShareContent, slot::Slot, timeslots::{get_block_slot_timestamp, get_closest_slot_to_timestamp}, - wrapped::WrappedContent, }; use massa_time::MassaTime; use massa_wallet::Wallet; @@ -171,7 +171,7 @@ impl BlockFactoryWorker { .get_block_endorsements(&same_thread_parent_id, &slot); //TODO: Do we want ot populate only with endorsement id in the future ? - let endorsements: Vec = { + let endorsements: Vec = { let endo_read = endo_storage.read_endorsements(); endorsements_ids .into_iter() @@ -197,7 +197,7 @@ impl BlockFactoryWorker { ); // create header - let header: WrappedHeader = BlockHeader::new_wrapped::( + let header: SecuredHeader = BlockHeader::new_verifiable::( BlockHeader { slot, parents: parents.into_iter().map(|(id, _period)| id).collect(), @@ -210,7 +210,7 @@ impl BlockFactoryWorker { .expect("error while producing block header"); // create block - let block = Block::new_wrapped( + let block = Block::new_verifiable( Block { header, operations: op_ids.into_iter().collect(), diff --git a/massa-factory-worker/src/endorsement_factory.rs b/massa-factory-worker/src/endorsement_factory.rs index 797c10b797d..d5c7812a516 100644 --- a/massa-factory-worker/src/endorsement_factory.rs +++ b/massa-factory-worker/src/endorsement_factory.rs @@ -3,10 +3,10 @@ use massa_factory_exports::{FactoryChannels, FactoryConfig}; use massa_models::{ block::BlockId, - endorsement::{Endorsement, EndorsementSerializer, WrappedEndorsement}, + endorsement::{Endorsement, EndorsementSerializer, SecureShareEndorsement}, + secure_share::SecureShareContent, slot::Slot, timeslots::{get_block_slot_timestamp, get_closest_slot_to_timestamp}, - wrapped::WrappedContent, }; use massa_signature::KeyPair; use massa_time::MassaTime; @@ -167,9 +167,10 @@ impl EndorsementFactoryWorker { .get_latest_blockclique_block_at_slot(slot); // produce endorsements - let mut endorsements: Vec = Vec::with_capacity(producers_indices.len()); + let mut endorsements: Vec = + Vec::with_capacity(producers_indices.len()); for (keypair, index) in producers_indices { - let endorsement = Endorsement::new_wrapped( + let endorsement = Endorsement::new_verifiable( Endorsement { slot, index: index as u32, @@ -183,7 +184,7 @@ impl EndorsementFactoryWorker { // log endorsement creation debug!( "endorsement {} created at slot {} by address {}", - endorsement.id, endorsement.content.slot, endorsement.creator_address + endorsement.id, endorsement.content.slot, endorsement.content_creator_address ); endorsements.push(endorsement); diff --git a/massa-factory-worker/src/tests/scenarios.rs b/massa-factory-worker/src/tests/scenarios.rs index fc3fef81c19..45267a5150e 100644 --- a/massa-factory-worker/src/tests/scenarios.rs +++ b/massa-factory-worker/src/tests/scenarios.rs @@ -2,7 +2,7 @@ use super::TestFactory; use massa_models::{ amount::Amount, operation::{Operation, OperationSerializer, OperationType}, - wrapped::WrappedContent, + secure_share::SecureShareContent, }; use massa_signature::KeyPair; use std::str::FromStr; @@ -29,7 +29,8 @@ fn basic_creation_with_operation() { expire_period: 2, op: OperationType::RollBuy { roll_count: 1 }, }; - let operation = Operation::new_wrapped(content, OperationSerializer::new(), &keypair).unwrap(); + let operation = + Operation::new_verifiable(content, OperationSerializer::new(), &keypair).unwrap(); let (block_id, storage) = test_factory.get_next_created_block(Some(vec![operation]), None); let block = storage.read_blocks().get(&block_id).unwrap().clone(); @@ -51,7 +52,8 @@ fn basic_creation_with_multiple_operations() { expire_period: 2, op: OperationType::RollBuy { roll_count: 1 }, }; - let operation = Operation::new_wrapped(content, OperationSerializer::new(), &keypair).unwrap(); + let operation = + Operation::new_verifiable(content, OperationSerializer::new(), &keypair).unwrap(); let (block_id, storage) = test_factory.get_next_created_block(Some(vec![operation.clone(), operation]), None); diff --git a/massa-factory-worker/src/tests/tools.rs b/massa-factory-worker/src/tests/tools.rs index c0f8acb0ca8..f5b2f5596ac 100644 --- a/massa-factory-worker/src/tests/tools.rs +++ b/massa-factory-worker/src/tests/tools.rs @@ -12,9 +12,9 @@ use massa_factory_exports::{ test_exports::create_empty_block, FactoryChannels, FactoryConfig, FactoryManager, }; use massa_models::{ - address::Address, block::BlockId, config::ENDORSEMENT_COUNT, endorsement::WrappedEndorsement, - operation::WrappedOperation, prehash::PreHashMap, slot::Slot, - test_exports::get_next_slot_instant, + address::Address, block::BlockId, config::ENDORSEMENT_COUNT, + endorsement::SecureShareEndorsement, operation::SecureShareOperation, prehash::PreHashMap, + slot::Slot, test_exports::get_next_slot_instant, }; use massa_pool_exports::test_exports::{ MockPoolController, MockPoolControllerMessage, PoolEventReceiver, @@ -110,8 +110,8 @@ impl TestFactory { /// - `endorsements`: Optional list of endorsements to include in the block pub fn get_next_created_block( &mut self, - operations: Option>, - endorsements: Option>, + operations: Option>, + endorsements: Option>, ) -> (BlockId, Storage) { let now = MassaTime::now().expect("could not get current time"); let next_slot_instant = get_next_slot_instant( diff --git a/massa-models/src/api.rs b/massa-models/src/api.rs index 931ab7f48ab..d2b50c4bee7 100644 --- a/massa-models/src/api.rs +++ b/massa-models/src/api.rs @@ -1,10 +1,10 @@ // Copyright (c) 2022 MASSA LABS use crate::address::ExecutionAddressCycleInfo; -use crate::endorsement::{EndorsementId, WrappedEndorsement}; +use crate::endorsement::{EndorsementId, SecureShareEndorsement}; use crate::ledger_models::LedgerData; use crate::node::NodeId; -use crate::operation::{OperationId, WrappedOperation}; +use crate::operation::{OperationId, SecureShareOperation}; use crate::stats::{ConsensusStats, ExecutionStats, NetworkStats}; use crate::{ address::Address, amount::Amount, block::Block, block::BlockId, config::CompactConfig, @@ -119,7 +119,7 @@ pub struct OperationInfo { /// true if the operation is final (for example in a final block) pub is_final: bool, /// the operation itself - pub operation: WrappedOperation, + pub operation: SecureShareOperation, } impl std::fmt::Display for OperationInfo { @@ -380,7 +380,7 @@ pub struct EndorsementInfo { /// true if the endorsement is final (for example in a final block) pub is_final: bool, /// the endorsement itself - pub endorsement: WrappedEndorsement, + pub endorsement: SecureShareEndorsement, } impl std::fmt::Display for EndorsementInfo { diff --git a/massa-models/src/block.rs b/massa-models/src/block.rs index f0e5bae6b1f..3486c13a5b7 100644 --- a/massa-models/src/block.rs +++ b/massa-models/src/block.rs @@ -2,11 +2,15 @@ use crate::endorsement::{EndorsementId, EndorsementSerializer, EndorsementSerializerLW}; use crate::prehash::PreHashed; -use crate::wrapped::{Id, Wrapped, WrappedContent, WrappedDeserializer, WrappedSerializer}; +use crate::secure_share::{ + Id, SecureShare, SecureShareContent, SecureShareDeserializer, SecureShareSerializer, +}; use crate::{ - endorsement::{Endorsement, EndorsementDeserializerLW, WrappedEndorsement}, + endorsement::{Endorsement, EndorsementDeserializerLW, SecureShareEndorsement}, error::ModelsError, - operation::{OperationId, OperationIdsDeserializer, OperationIdsSerializer, WrappedOperation}, + operation::{ + OperationId, OperationIdsDeserializer, OperationIdsSerializer, SecureShareOperation, + }, slot::{Slot, SlotDeserializer, SlotSerializer}, }; use massa_hash::{Hash, HashDeserializer}; @@ -187,7 +191,7 @@ impl Deserializer for BlockIdDeserializer { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Block { /// signed header - pub header: WrappedHeader, + pub header: SecuredHeader, /// operations ids pub operations: Vec, } @@ -196,26 +200,26 @@ pub struct Block { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct FilledBlock { /// signed header - pub header: WrappedHeader, + pub header: SecuredHeader, /// operations - pub operations: Vec<(OperationId, Option)>, + pub operations: Vec<(OperationId, Option)>, } -/// Wrapped Block -pub type WrappedBlock = Wrapped; +/// Block with assosciated meta-data and interfaces allowing trust of data in untrusted network +pub type SecureShareBlock = SecureShare; -impl WrappedContent for Block { - fn new_wrapped, U: Id>( +impl SecureShareContent for Block { + fn new_verifiable, U: Id>( content: Self, content_serializer: SC, _keypair: &KeyPair, - ) -> Result, ModelsError> { + ) -> Result, ModelsError> { let mut content_serialized = Vec::new(); content_serializer.serialize(&content, &mut content_serialized)?; - Ok(Wrapped { + Ok(SecureShare { signature: content.header.signature, - creator_public_key: content.header.creator_public_key, - creator_address: content.header.creator_address, + content_creator_pub_key: content.header.content_creator_pub_key, + content_creator_address: content.header.content_creator_address, id: U::new(*content.header.id.get_hash()), content, serialized_data: content_serialized, @@ -243,14 +247,14 @@ impl WrappedContent for Block { _creator_public_key_deserializer: &massa_signature::PublicKeyDeserializer, content_deserializer: &DC, buffer: &'a [u8], - ) -> IResult<&'a [u8], Wrapped, E> { + ) -> IResult<&'a [u8], SecureShare, E> { let (rest, content) = content_deserializer.deserialize(buffer)?; Ok(( rest, - Wrapped { + SecureShare { signature: content.header.signature, - creator_public_key: content.header.creator_public_key, - creator_address: content.header.creator_address, + content_creator_pub_key: content.header.content_creator_pub_key, + content_creator_address: content.header.content_creator_address, id: U::new(*content.header.id.get_hash()), content, serialized_data: buffer[..buffer.len() - rest.len()].to_vec(), @@ -260,7 +264,7 @@ impl WrappedContent for Block { } /// Serializer for `Block` pub struct BlockSerializer { - header_serializer: WrappedSerializer, + header_serializer: SecureShareSerializer, op_ids_serializer: OperationIdsSerializer, } @@ -268,7 +272,7 @@ impl BlockSerializer { /// Creates a new `BlockSerializer` pub fn new() -> Self { BlockSerializer { - header_serializer: WrappedSerializer::new(), + header_serializer: SecureShareSerializer::new(), op_ids_serializer: OperationIdsSerializer::new(), } } @@ -283,7 +287,7 @@ impl Default for BlockSerializer { impl Serializer for BlockSerializer { /// ## Example: /// ```rust - /// use massa_models::{block::{Block, BlockSerializer, BlockId, BlockHeader, BlockHeaderSerializer}, config::THREAD_COUNT, slot::Slot, endorsement::{Endorsement, EndorsementSerializer}, wrapped::WrappedContent, prehash::PreHashSet}; + /// use massa_models::{block::{Block, BlockSerializer, BlockId, BlockHeader, BlockHeaderSerializer}, config::THREAD_COUNT, slot::Slot, endorsement::{Endorsement, EndorsementSerializer}, secure_share::SecureShareContent, prehash::PreHashSet}; /// use massa_hash::Hash; /// use massa_signature::KeyPair; /// use massa_serialization::{Serializer, Deserializer, DeserializeError}; @@ -293,13 +297,13 @@ impl Serializer for BlockSerializer { /// .collect(); /// /// // create block header - /// let orig_header = BlockHeader::new_wrapped( + /// let orig_header = BlockHeader::new_verifiable( /// BlockHeader { /// slot: Slot::new(1, 1), /// parents, /// operation_merkle_root: Hash::compute_from("mno".as_bytes()), /// endorsements: vec![ - /// Endorsement::new_wrapped( + /// Endorsement::new_verifiable( /// Endorsement { /// slot: Slot::new(1, 1), /// index: 1, @@ -309,7 +313,7 @@ impl Serializer for BlockSerializer { /// &keypair, /// ) /// .unwrap(), - /// Endorsement::new_wrapped( + /// Endorsement::new_verifiable( /// Endorsement { /// slot: Slot::new(4, 0), /// index: 3, @@ -345,7 +349,7 @@ impl Serializer for BlockSerializer { /// Deserializer for `Block` pub struct BlockDeserializer { - header_deserializer: WrappedDeserializer, + header_deserializer: SecureShareDeserializer, op_ids_deserializer: OperationIdsDeserializer, } @@ -353,7 +357,7 @@ impl BlockDeserializer { /// Creates a new `BlockDeserializer` pub fn new(thread_count: u8, max_operations_per_block: u32, endorsement_count: u32) -> Self { BlockDeserializer { - header_deserializer: WrappedDeserializer::new(BlockHeaderDeserializer::new( + header_deserializer: SecureShareDeserializer::new(BlockHeaderDeserializer::new( thread_count, endorsement_count, )), @@ -365,7 +369,7 @@ impl BlockDeserializer { impl Deserializer for BlockDeserializer { /// ## Example: /// ```rust - /// use massa_models::{block::{Block, BlockSerializer, BlockDeserializer, BlockId,BlockHeader, BlockHeaderSerializer}, config::THREAD_COUNT, slot::Slot, endorsement::{Endorsement, EndorsementSerializer}, wrapped::WrappedContent, prehash::PreHashSet}; + /// use massa_models::{block::{Block, BlockSerializer, BlockDeserializer, BlockId,BlockHeader, BlockHeaderSerializer}, config::THREAD_COUNT, slot::Slot, endorsement::{Endorsement, EndorsementSerializer}, secure_share::SecureShareContent, prehash::PreHashSet}; /// use massa_hash::Hash; /// use massa_signature::KeyPair; /// use massa_serialization::{Serializer, Deserializer, DeserializeError}; @@ -375,13 +379,13 @@ impl Deserializer for BlockDeserializer { /// .collect(); /// /// // create block header - /// let orig_header = BlockHeader::new_wrapped( + /// let orig_header = BlockHeader::new_verifiable( /// BlockHeader { /// slot: Slot::new(1, 1), /// parents, /// operation_merkle_root: Hash::compute_from("mno".as_bytes()), /// endorsements: vec![ - /// Endorsement::new_wrapped( + /// Endorsement::new_verifiable( /// Endorsement { /// slot: Slot::new(1, 1), /// index: 1, @@ -391,7 +395,7 @@ impl Deserializer for BlockDeserializer { /// &keypair, /// ) /// .unwrap(), - /// Endorsement::new_wrapped( + /// Endorsement::new_verifiable( /// Endorsement { /// slot: Slot::new(4, 0), /// index: 3, @@ -454,14 +458,14 @@ impl Deserializer for BlockDeserializer { } } -impl WrappedBlock { +impl SecureShareBlock { /// size in bytes of the whole block pub fn bytes_count(&self) -> u64 { self.serialized_data.len() as u64 } /// true if given operation is included in the block - pub fn contains_operation(&self, op: WrappedOperation) -> bool { + pub fn contains_operation(&self, op: SecureShareOperation) -> bool { self.content.operations.contains(&op.id) } @@ -497,7 +501,7 @@ pub struct BlockHeader { /// all operations hash pub operation_merkle_root: Hash, /// endorsements - pub endorsements: Vec, + pub endorsements: Vec, } // NOTE: TODO @@ -512,22 +516,22 @@ pub struct BlockHeader { // } // } -/// wrapped header -pub type WrappedHeader = Wrapped; +/// BlockHeader wrapped up alongside verification data +pub type SecuredHeader = SecureShare; -impl WrappedHeader { +impl SecuredHeader { /// gets the header fitness pub fn get_fitness(&self) -> u64 { (self.content.endorsements.len() as u64) + 1 } } -impl WrappedContent for BlockHeader {} +impl SecureShareContent for BlockHeader {} /// Serializer for `BlockHeader` pub struct BlockHeaderSerializer { slot_serializer: SlotSerializer, - endorsement_serializer: WrappedSerializer, + endorsement_serializer: SecureShareSerializer, endorsement_content_serializer: EndorsementSerializerLW, u32_serializer: U32VarIntSerializer, } @@ -537,7 +541,7 @@ impl BlockHeaderSerializer { pub fn new() -> Self { Self { slot_serializer: SlotSerializer::new(), - endorsement_serializer: WrappedSerializer::new(), + endorsement_serializer: SecureShareSerializer::new(), u32_serializer: U32VarIntSerializer::new(), endorsement_content_serializer: EndorsementSerializerLW::new(), } @@ -555,7 +559,7 @@ impl Serializer for BlockHeaderSerializer { /// ```rust /// use massa_models::block::{BlockId, BlockHeader, BlockHeaderSerializer}; /// use massa_models::endorsement::{Endorsement, EndorsementSerializer}; - /// use massa_models::wrapped::WrappedContent; + /// use massa_models::secure_share::SecureShareContent; /// use massa_models::{config::THREAD_COUNT, slot::Slot}; /// use massa_hash::Hash; /// use massa_signature::KeyPair; @@ -570,7 +574,7 @@ impl Serializer for BlockHeaderSerializer { /// parents, /// operation_merkle_root: Hash::compute_from("mno".as_bytes()), /// endorsements: vec![ - /// Endorsement::new_wrapped( + /// Endorsement::new_verifiable( /// Endorsement { /// slot: Slot::new(1, 1), /// index: 1, @@ -580,7 +584,7 @@ impl Serializer for BlockHeaderSerializer { /// &keypair, /// ) /// .unwrap(), - /// Endorsement::new_wrapped( + /// Endorsement::new_verifiable( /// Endorsement { /// slot: Slot::new(4, 0), /// index: 3, @@ -661,7 +665,7 @@ impl Deserializer for BlockHeaderDeserializer { /// ## Example: /// ```rust /// use massa_models::block::{BlockId, BlockHeader, BlockHeaderDeserializer, BlockHeaderSerializer}; - /// use massa_models::{config::THREAD_COUNT, slot::Slot, wrapped::WrappedContent}; + /// use massa_models::{config::THREAD_COUNT, slot::Slot, secure_share::SecureShareContent}; /// use massa_models::endorsement::{Endorsement, EndorsementSerializerLW}; /// use massa_hash::Hash; /// use massa_signature::KeyPair; @@ -676,7 +680,7 @@ impl Deserializer for BlockHeaderDeserializer { /// parents, /// operation_merkle_root: Hash::compute_from("mno".as_bytes()), /// endorsements: vec![ - /// Endorsement::new_wrapped( + /// Endorsement::new_verifiable( /// Endorsement { /// slot: Slot::new(1, 1), /// index: 1, @@ -686,7 +690,7 @@ impl Deserializer for BlockHeaderDeserializer { /// &keypair, /// ) /// .unwrap(), - /// Endorsement::new_wrapped( + /// Endorsement::new_verifiable( /// Endorsement { /// slot: Slot::new(4, 0), /// index: 3, @@ -753,15 +757,16 @@ impl Deserializer for BlockHeaderDeserializer { )); } // Now deser the endorsements (which were: lw serialized) - let endorsement_deserializer = WrappedDeserializer::new(EndorsementDeserializerLW::new( - self.endorsement_count, - slot, - parents[slot.thread as usize], - )); + let endorsement_deserializer = + SecureShareDeserializer::new(EndorsementDeserializerLW::new( + self.endorsement_count, + slot, + parents[slot.thread as usize], + )); let (rest, endorsements) = context( "Failed endorsements deserialization", - length_count::<&[u8], Wrapped, u32, E, _, _>( + length_count::<&[u8], SecureShare, u32, E, _, _>( context("Failed length deserialization", |input| { self.length_endorsements_deserializer.deserialize(input) }), @@ -806,7 +811,11 @@ impl std::fmt::Display for BlockHeader { writeln!(f, "\t\tId: {}", ed.id)?; writeln!(f, "\t\tIndex: {}", ed.content.index)?; writeln!(f, "\t\tEndorsed slot: {}", ed.content.slot)?; - writeln!(f, "\t\tEndorser's public key: {}", ed.creator_public_key)?; + writeln!( + f, + "\t\tEndorser's public key: {}", + ed.content_creator_pub_key + )?; writeln!(f, "\t\tEndorsed block: {}", ed.content.endorsed_block)?; writeln!(f, "\t\tSignature: {}", ed.signature)?; } @@ -843,7 +852,7 @@ mod test { }) .collect(); - let endo = Endorsement::new_wrapped( + let endo = Endorsement::new_verifiable( Endorsement { slot: Slot::new(1, 0), index: 1, @@ -858,7 +867,7 @@ mod test { .unwrap(); // create block header - let orig_header = BlockHeader::new_wrapped( + let orig_header = BlockHeader::new_verifiable( BlockHeader { slot: Slot::new(1, 0), parents, @@ -877,15 +886,15 @@ mod test { }; // serialize block - let wrapped_block: WrappedBlock = - Block::new_wrapped(orig_block.clone(), BlockSerializer::new(), &keypair).unwrap(); + let secured_block: SecureShareBlock = + Block::new_verifiable(orig_block.clone(), BlockSerializer::new(), &keypair).unwrap(); let mut ser_block = Vec::new(); - WrappedSerializer::new() - .serialize(&wrapped_block, &mut ser_block) + SecureShareSerializer::new() + .serialize(&secured_block, &mut ser_block) .unwrap(); // deserialize - let (rest, res_block): (&[u8], WrappedBlock) = WrappedDeserializer::new( + let (rest, res_block): (&[u8], SecureShareBlock) = SecureShareDeserializer::new( BlockDeserializer::new(THREAD_COUNT, MAX_OPERATIONS_PER_BLOCK, ENDORSEMENT_COUNT), ) .deserialize::(&ser_block) @@ -931,7 +940,7 @@ mod test { let parents: Vec = vec![]; // create block header - let orig_header = BlockHeader::new_wrapped( + let orig_header = BlockHeader::new_verifiable( BlockHeader { slot: Slot::new(1, 1), parents, @@ -950,15 +959,15 @@ mod test { }; // serialize block - let wrapped_block: WrappedBlock = - Block::new_wrapped(orig_block.clone(), BlockSerializer::new(), &keypair).unwrap(); + let secured_block: SecureShareBlock = + Block::new_verifiable(orig_block.clone(), BlockSerializer::new(), &keypair).unwrap(); let mut ser_block = Vec::new(); - WrappedSerializer::new() - .serialize(&wrapped_block, &mut ser_block) + SecureShareSerializer::new() + .serialize(&secured_block, &mut ser_block) .unwrap(); // deserialize - let (rest, res_block): (&[u8], WrappedBlock) = WrappedDeserializer::new( + let (rest, res_block): (&[u8], SecureShareBlock) = SecureShareDeserializer::new( BlockDeserializer::new(THREAD_COUNT, MAX_OPERATIONS_PER_BLOCK, ENDORSEMENT_COUNT), ) .deserialize::(&ser_block) @@ -1004,12 +1013,12 @@ mod test { }; // create block header - let orig_header = BlockHeader::new_wrapped( + let orig_header = BlockHeader::new_verifiable( BlockHeader { slot: Slot::new(1, 1), parents, operation_merkle_root: Hash::compute_from("mno".as_bytes()), - endorsements: vec![Endorsement::new_wrapped( + endorsements: vec![Endorsement::new_verifiable( endorsement, EndorsementSerializer::new(), &keypair, @@ -1028,15 +1037,15 @@ mod test { }; // serialize block - let wrapped_block: WrappedBlock = - Block::new_wrapped(orig_block, BlockSerializer::new(), &keypair).unwrap(); + let secured_block: SecureShareBlock = + Block::new_verifiable(orig_block, BlockSerializer::new(), &keypair).unwrap(); let mut ser_block = Vec::new(); - WrappedSerializer::new() - .serialize(&wrapped_block, &mut ser_block) + SecureShareSerializer::new() + .serialize(&secured_block, &mut ser_block) .unwrap(); // deserialize - let res: Result<(&[u8], WrappedBlock), _> = WrappedDeserializer::new( + let res: Result<(&[u8], SecureShareBlock), _> = SecureShareDeserializer::new( BlockDeserializer::new(THREAD_COUNT, MAX_OPERATIONS_PER_BLOCK, ENDORSEMENT_COUNT), ) .deserialize::(&ser_block); diff --git a/massa-models/src/composite.rs b/massa-models/src/composite.rs index 618911a65b3..fd6131ae10e 100644 --- a/massa-models/src/composite.rs +++ b/massa-models/src/composite.rs @@ -1,7 +1,7 @@ // Copyright (c) 2022 MASSA LABS use crate::prehash::PreHashMap; -use crate::{address::Address, block::BlockId, operation::WrappedOperation}; +use crate::{address::Address, block::BlockId, operation::SecureShareOperation}; use massa_signature::{PublicKey, Signature}; use serde::{Deserialize, Serialize}; use std::fmt::Display; @@ -36,7 +36,7 @@ pub enum OperationSearchResultStatus { #[derive(Clone, Debug, Serialize, Deserialize)] pub struct OperationSearchResult { /// the operation - pub op: WrappedOperation, + pub op: SecureShareOperation, /// true if in pool pub in_pool: bool, /// maps block id to index on the operation in the block and if it's final diff --git a/massa-models/src/endorsement.rs b/massa-models/src/endorsement.rs index 52692d067c2..8be2658805d 100644 --- a/massa-models/src/endorsement.rs +++ b/massa-models/src/endorsement.rs @@ -1,8 +1,8 @@ // Copyright (c) 2022 MASSA LABS use crate::prehash::PreHashed; +use crate::secure_share::{Id, SecureShare, SecureShareContent}; use crate::slot::{Slot, SlotDeserializer, SlotSerializer}; -use crate::wrapped::{Id, Wrapped, WrappedContent}; use crate::{block::BlockId, error::ModelsError}; use massa_hash::{Hash, HashDeserializer}; use massa_serialization::{ @@ -146,9 +146,9 @@ pub struct Endorsement { } /// Wrapped endorsement -pub type WrappedEndorsement = Wrapped; +pub type SecureShareEndorsement = SecureShare; -impl WrappedContent for Endorsement {} +impl SecureShareContent for Endorsement {} /// Serializer for `Endorsement` #[derive(Clone)] @@ -369,7 +369,7 @@ impl Deserializer for EndorsementDeserializerLW { #[cfg(test)] mod tests { - use crate::wrapped::{WrappedDeserializer, WrappedSerializer}; + use crate::secure_share::{SecureShareDeserializer, SecureShareSerializer}; use super::*; use massa_serialization::DeserializeError; @@ -385,17 +385,17 @@ mod tests { index: 0, endorsed_block: BlockId(Hash::compute_from("blk".as_bytes())), }; - let endorsement: WrappedEndorsement = - Endorsement::new_wrapped(content, EndorsementSerializer::new(), &sender_keypair) + let endorsement: SecureShareEndorsement = + Endorsement::new_verifiable(content, EndorsementSerializer::new(), &sender_keypair) .unwrap(); let mut ser_endorsement: Vec = Vec::new(); - let serializer = WrappedSerializer::new(); + let serializer = SecureShareSerializer::new(); serializer .serialize(&endorsement, &mut ser_endorsement) .unwrap(); - let (_, res_endorsement): (&[u8], WrappedEndorsement) = - WrappedDeserializer::new(EndorsementDeserializer::new(32, 1)) + let (_, res_endorsement): (&[u8], SecureShareEndorsement) = + SecureShareDeserializer::new(EndorsementDeserializer::new(32, 1)) .deserialize::(&ser_endorsement) .unwrap(); assert_eq!(res_endorsement, endorsement); @@ -410,22 +410,23 @@ mod tests { index: 0, endorsed_block: BlockId(Hash::compute_from("blk".as_bytes())), }; - let endorsement: WrappedEndorsement = - Endorsement::new_wrapped(content, EndorsementSerializerLW::new(), &sender_keypair) + let endorsement: SecureShareEndorsement = + Endorsement::new_verifiable(content, EndorsementSerializerLW::new(), &sender_keypair) .unwrap(); let mut ser_endorsement: Vec = Vec::new(); - let serializer = WrappedSerializer::new(); + let serializer = SecureShareSerializer::new(); serializer .serialize(&endorsement, &mut ser_endorsement) .unwrap(); let parent = BlockId(Hash::compute_from("blk".as_bytes())); - let (_, res_endorsement): (&[u8], WrappedEndorsement) = - WrappedDeserializer::new(EndorsementDeserializerLW::new(1, Slot::new(10, 1), parent)) - .deserialize::(&ser_endorsement) - .unwrap(); + let (_, res_endorsement): (&[u8], SecureShareEndorsement) = SecureShareDeserializer::new( + EndorsementDeserializerLW::new(1, Slot::new(10, 1), parent), + ) + .deserialize::(&ser_endorsement) + .unwrap(); // Test only endorsement index as with the lw ser. we only process this field assert_eq!(res_endorsement.content.index, endorsement.content.index); } diff --git a/massa-models/src/lib.rs b/massa-models/src/lib.rs index 30cd8478710..ae569ce12d6 100644 --- a/massa-models/src/lib.rs +++ b/massa-models/src/lib.rs @@ -45,6 +45,8 @@ pub mod output_event; pub mod prehash; /// rolls pub mod rolls; +/// trait for [Signature] secured data-structs +pub mod secure_share; /// serialization pub mod serialization; /// slots @@ -57,8 +59,6 @@ pub mod streaming_step; pub mod timeslots; /// versions pub mod version; -/// trait for signed structure -pub mod wrapped; /// Test utils #[cfg(feature = "testing")] diff --git a/massa-models/src/operation.rs b/massa-models/src/operation.rs index 5f960f51a5e..74c15ad7bb5 100644 --- a/massa-models/src/operation.rs +++ b/massa-models/src/operation.rs @@ -2,7 +2,9 @@ use crate::datastore::{Datastore, DatastoreDeserializer, DatastoreSerializer}; use crate::prehash::{PreHashSet, PreHashed}; -use crate::wrapped::{Id, Wrapped, WrappedContent, WrappedDeserializer, WrappedSerializer}; +use crate::secure_share::{ + Id, SecureShare, SecureShareContent, SecureShareDeserializer, SecureShareSerializer, +}; use crate::{ address::{Address, AddressDeserializer}, amount::{Amount, AmountDeserializer, AmountSerializer}, @@ -262,9 +264,9 @@ impl std::fmt::Display for Operation { } /// signed operation -pub type WrappedOperation = Wrapped; +pub type SecureShareOperation = SecureShare; -impl WrappedContent for Operation {} +impl SecureShareContent for Operation {} /// Serializer for `Operation` pub struct OperationSerializer { @@ -790,7 +792,7 @@ impl Deserializer for OperationTypeDeserializer { } } -impl WrappedOperation { +impl SecureShareOperation { /// get the range of periods during which an operation is valid /// Range: `(op.expire_period - cfg.operation_validity_period) -> op.expire_period` (included) pub fn get_validity_range(&self, operation_validity_period: u64) -> RangeInclusive { @@ -815,7 +817,7 @@ impl WrappedOperation { /// get the addresses that are involved in this operation from a ledger point of view pub fn get_ledger_involved_addresses(&self) -> PreHashSet
{ let mut res = PreHashSet::
::default(); - let emitter_address = Address::from_public_key(&self.creator_public_key); + let emitter_address = Address::from_public_key(&self.content_creator_pub_key); res.insert(emitter_address); match &self.content.op { OperationType::Transaction { @@ -854,10 +856,10 @@ impl WrappedOperation { match self.content.op { OperationType::Transaction { .. } => {} OperationType::RollBuy { .. } => { - res.insert(Address::from_public_key(&self.creator_public_key)); + res.insert(Address::from_public_key(&self.content_creator_pub_key)); } OperationType::RollSell { .. } => { - res.insert(Address::from_public_key(&self.creator_public_key)); + res.insert(Address::from_public_key(&self.content_creator_pub_key)); } OperationType::ExecuteSC { .. } => {} OperationType::CallSC { .. } => {} @@ -1125,7 +1127,7 @@ impl Serializer for OperationPrefixIdsSerializer { /// Serializer for `Operations` pub struct OperationsSerializer { u32_serializer: U32VarIntSerializer, - signed_op_serializer: WrappedSerializer, + signed_op_serializer: SecureShareSerializer, } impl OperationsSerializer { @@ -1133,7 +1135,7 @@ impl OperationsSerializer { pub const fn new() -> Self { Self { u32_serializer: U32VarIntSerializer::new(), - signed_op_serializer: WrappedSerializer::new(), + signed_op_serializer: SecureShareSerializer::new(), } } } @@ -1144,10 +1146,10 @@ impl Default for OperationsSerializer { } } -impl Serializer> for OperationsSerializer { +impl Serializer> for OperationsSerializer { /// ## Example: /// ```rust - /// use massa_models::{operation::{WrappedOperation, Operation, OperationType, OperationsSerializer, OperationSerializer}, wrapped::WrappedContent, address::Address, amount::Amount}; + /// use massa_models::{operation::{SecureShareOperation, Operation, OperationType, OperationsSerializer, OperationSerializer}, secure_share::SecureShareContent, address::Address, amount::Amount}; /// use massa_signature::KeyPair; /// use massa_serialization::Serializer; /// use std::str::FromStr; @@ -1162,14 +1164,14 @@ impl Serializer> for OperationsSerializer { /// op, /// expire_period: 50, /// }; - /// let op_wrapped = Operation::new_wrapped(content, OperationSerializer::new(), &keypair).unwrap(); - /// let operations = vec![op_wrapped.clone(), op_wrapped.clone()]; + /// let op_secured = Operation::new_verifiable(content, OperationSerializer::new(), &keypair).unwrap(); + /// let operations = vec![op_secured.clone(), op_secured.clone()]; /// let mut buffer = Vec::new(); /// OperationsSerializer::new().serialize(&operations, &mut buffer).unwrap(); /// ``` fn serialize( &self, - value: &Vec, + value: &Vec, buffer: &mut Vec, ) -> Result<(), SerializeError> { let list_len: u32 = value.len().try_into().map_err(|_| { @@ -1186,7 +1188,7 @@ impl Serializer> for OperationsSerializer { /// Deserializer for `Operations` pub struct OperationsDeserializer { length_deserializer: U32VarIntDeserializer, - signed_op_deserializer: WrappedDeserializer, + signed_op_deserializer: SecureShareDeserializer, } impl OperationsDeserializer { @@ -1205,7 +1207,7 @@ impl OperationsDeserializer { Included(0), Included(max_operations_per_message), ), - signed_op_deserializer: WrappedDeserializer::new(OperationDeserializer::new( + signed_op_deserializer: SecureShareDeserializer::new(OperationDeserializer::new( max_datastore_value_length, max_function_name_length, max_parameters_size, @@ -1217,10 +1219,10 @@ impl OperationsDeserializer { } } -impl Deserializer> for OperationsDeserializer { +impl Deserializer> for OperationsDeserializer { /// ## Example: /// ```rust - /// use massa_models::{operation::{WrappedOperation, Operation, OperationType, OperationsSerializer, OperationsDeserializer, OperationSerializer}, wrapped::WrappedContent, address::Address, amount::Amount}; + /// use massa_models::{operation::{SecureShareOperation, Operation, OperationType, OperationsSerializer, OperationsDeserializer, OperationSerializer}, secure_share::SecureShareContent, address::Address, amount::Amount}; /// use massa_signature::KeyPair; /// use massa_serialization::{Serializer, Deserializer, DeserializeError}; /// use std::str::FromStr; @@ -1235,22 +1237,22 @@ impl Deserializer> for OperationsDeserializer { /// op, /// expire_period: 50, /// }; - /// let op_wrapped = Operation::new_wrapped(content, OperationSerializer::new(), &keypair).unwrap(); - /// let operations = vec![op_wrapped.clone(), op_wrapped.clone()]; + /// let op_secured = Operation::new_verifiable(content, OperationSerializer::new(), &keypair).unwrap(); + /// let operations = vec![op_secured.clone(), op_secured.clone()]; /// let mut buffer = Vec::new(); /// OperationsSerializer::new().serialize(&operations, &mut buffer).unwrap(); /// let (rest, deserialized_operations) = OperationsDeserializer::new(10000, 10000, 10000, 10000, 10, 255, 10_000).deserialize::(&buffer).unwrap(); /// for (operation1, operation2) in deserialized_operations.iter().zip(operations.iter()) { /// assert_eq!(operation1.id, operation2.id); /// assert_eq!(operation1.signature, operation2.signature); - /// assert_eq!(operation1.creator_public_key, operation2.creator_public_key); + /// assert_eq!(operation1.content_creator_pub_key, operation2.content_creator_pub_key); /// assert_eq!(operation1.content.fee, operation2.content.fee); /// } /// ``` fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( &self, buffer: &'a [u8], - ) -> IResult<&'a [u8], Vec, E> { + ) -> IResult<&'a [u8], Vec, E> { context( "Failed Operations deserialization", length_count( @@ -1331,14 +1333,14 @@ mod tests { let op_serializer = OperationSerializer::new(); - let op = Operation::new_wrapped(content, op_serializer, &sender_keypair).unwrap(); + let op = Operation::new_verifiable(content, op_serializer, &sender_keypair).unwrap(); let mut ser_op = Vec::new(); - WrappedSerializer::new() + SecureShareSerializer::new() .serialize(&op, &mut ser_op) .unwrap(); - let (_, res_op): (&[u8], WrappedOperation) = - WrappedDeserializer::new(OperationDeserializer::new( + let (_, res_op): (&[u8], SecureShareOperation) = + SecureShareDeserializer::new(OperationDeserializer::new( MAX_DATASTORE_VALUE_LENGTH, MAX_FUNCTION_NAME_LENGTH, MAX_PARAMETERS_SIZE, @@ -1405,14 +1407,14 @@ mod tests { assert_eq!(res_content, content); let op_serializer = OperationSerializer::new(); - let op = Operation::new_wrapped(content, op_serializer, &sender_keypair).unwrap(); + let op = Operation::new_verifiable(content, op_serializer, &sender_keypair).unwrap(); let mut ser_op = Vec::new(); - WrappedSerializer::new() + SecureShareSerializer::new() .serialize(&op, &mut ser_op) .unwrap(); - let (_, res_op): (&[u8], WrappedOperation) = - WrappedDeserializer::new(OperationDeserializer::new( + let (_, res_op): (&[u8], SecureShareOperation) = + SecureShareDeserializer::new(OperationDeserializer::new( MAX_DATASTORE_VALUE_LENGTH, MAX_FUNCTION_NAME_LENGTH, MAX_PARAMETERS_SIZE, @@ -1481,14 +1483,14 @@ mod tests { assert_eq!(res_content, content); let op_serializer = OperationSerializer::new(); - let op = Operation::new_wrapped(content, op_serializer, &sender_keypair).unwrap(); + let op = Operation::new_verifiable(content, op_serializer, &sender_keypair).unwrap(); let mut ser_op = Vec::new(); - WrappedSerializer::new() + SecureShareSerializer::new() .serialize(&op, &mut ser_op) .unwrap(); - let (_, res_op): (&[u8], WrappedOperation) = - WrappedDeserializer::new(OperationDeserializer::new( + let (_, res_op): (&[u8], SecureShareOperation) = + SecureShareDeserializer::new(OperationDeserializer::new( MAX_DATASTORE_VALUE_LENGTH, MAX_FUNCTION_NAME_LENGTH, MAX_PARAMETERS_SIZE, diff --git a/massa-models/src/wrapped.rs b/massa-models/src/secure_share.rs similarity index 61% rename from massa-models/src/wrapped.rs rename to massa-models/src/secure_share.rs index f5980aadc5d..995cfab3814 100644 --- a/massa-models/src/wrapped.rs +++ b/massa-models/src/secure_share.rs @@ -14,26 +14,33 @@ use nom::{ }; use serde::{Deserialize, Serialize}; -/// Wrapped structure T where U is the associated id +/// Packages type T such that it can be securely sent and received in a trust-free network +/// +/// If the internal content is mutated, then it must be re-wrapped, as the assosciated +/// signature, serialized data, etc. would no longer be in sync #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Wrapped +pub struct SecureShare where - T: Display + WrappedContent, - U: Id, + T: Display + SecureShareContent, + ID: Id, { - /// content + /// Reference contents. Not required for the the security protocols. + /// + /// Use the Lightweight equivilant structures when you need verifiable + /// serialized data, but do not need to read the values directly (such as when sending) pub content: T, - /// signature - pub signature: Signature, - /// the content creator public key - pub creator_public_key: PublicKey, - /// the content creator address - pub creator_address: Address, - /// Id - pub id: U, #[serde(skip)] - /// Content serialized + /// Content in sharable, deserializable form. Is used in the secure verification protocols. pub serialized_data: Vec, + + /// A cryptographically generated value using `serialized_data` and a public key. + pub signature: Signature, + /// The public-key component used in the generation of the signature + pub content_creator_pub_key: PublicKey, + /// Derived from the same public key used to generate the signature + pub content_creator_address: Address, + /// A secure hash of the data. See also [massa_hash::Hash] + pub id: ID, } /// Used by signed structure @@ -44,17 +51,18 @@ pub trait Id { fn get_hash(&self) -> &Hash; } -/// Trait that define a structure that can be wrapped. -pub trait WrappedContent +/// Trait that define a structure that can be signed for secure sharing. +pub trait SecureShareContent where Self: Sized + Display, { - /// Creates a wrapped version of the object - fn new_wrapped, U: Id>( + /// Using the provided key-pair, applies a cryptographic signature, and packages + /// the data required to share and verify the data in a trust-free network of peers. + fn new_verifiable, ID: Id>( content: Self, - content_serializer: SC, + content_serializer: Ser, keypair: &KeyPair, - ) -> Result, ModelsError> { + ) -> Result, ModelsError> { let mut content_serialized = Vec::new(); content_serializer.serialize(&content, &mut content_serialized)?; let mut hash_data = Vec::new(); @@ -63,17 +71,17 @@ where hash_data.extend(content_serialized.clone()); let hash = Hash::compute_from(&hash_data); let creator_address = Address::from_public_key(&public_key); - Ok(Wrapped { + Ok(SecureShare { signature: keypair.sign(&hash)?, - creator_public_key: public_key, - creator_address, + content_creator_pub_key: public_key, + content_creator_address: creator_address, content, serialized_data: content_serialized, - id: U::new(hash), + id: ID::new(hash), }) } - /// Serialize the wrapped structure + /// Serialize the secured structure fn serialize( signature: &Signature, creator_public_key: &PublicKey, @@ -86,21 +94,21 @@ where Ok(()) } - /// Deserialize the wrapped structure + /// Deserialize the secured structure fn deserialize< 'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>, - DC: Deserializer, - U: Id, + Deser: Deserializer, + ID: Id, >( content_serializer: Option<&dyn Serializer>, signature_deserializer: &SignatureDeserializer, creator_public_key_deserializer: &PublicKeyDeserializer, - content_deserializer: &DC, + content_deserializer: &Deser, buffer: &'a [u8], - ) -> IResult<&'a [u8], Wrapped, E> { + ) -> IResult<&'a [u8], SecureShare, E> { let (serialized_data, (signature, creator_public_key)) = context( - "Failed wrapped deserialization", + "Failed SecureShare deserialization", tuple(( context("Failed signature deserialization", |input| { signature_deserializer.deserialize(input) @@ -131,42 +139,42 @@ where serialized_full_data.extend(&content_serialized); Ok(( rest, - Wrapped { + SecureShare { content, signature, - creator_public_key, - creator_address, + content_creator_pub_key: creator_public_key, + content_creator_address: creator_address, serialized_data: content_serialized.to_vec(), - id: U::new(Hash::compute_from(&serialized_full_data)), + id: ID::new(Hash::compute_from(&serialized_full_data)), }, )) } } -impl Display for Wrapped +impl Display for SecureShare where - T: Display + WrappedContent, - U: Id, + T: Display + SecureShareContent, + ID: Id, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!(f, "Signature: {}", self.signature)?; - writeln!(f, "Creator pubkey: {}", self.creator_public_key)?; - writeln!(f, "Creator address: {}", self.creator_address)?; + writeln!(f, "Creator pubkey: {}", self.content_creator_pub_key)?; + writeln!(f, "Creator address: {}", self.content_creator_address)?; writeln!(f, "Id: {}", self.id.get_hash())?; writeln!(f, "{}", self.content)?; Ok(()) } } -impl Wrapped +impl SecureShare where - T: Display + WrappedContent, - U: Id, + T: Display + SecureShareContent, + ID: Id, { /// check if self has been signed by public key pub fn verify_signature(&self) -> Result<(), ModelsError> { Ok(self - .creator_public_key + .content_creator_pub_key .verify_signature(self.id.get_hash(), &self.signature)?) } @@ -180,83 +188,87 @@ where } // NOTE FOR EXPLICATION: No content serializer because serialized data is already here. -/// Serializer for `Wrapped` structure +/// Serializer for `SecureShare` structure #[derive(Default)] -pub struct WrappedSerializer; +pub struct SecureShareSerializer; -impl WrappedSerializer { - /// Creates a new `WrappedSerializer` +impl SecureShareSerializer { + /// Creates a new `SecureShareSerializer` pub const fn new() -> Self { Self } - /// This method is used to serialize a `Wrapped` structure and use a custom serializer instead of + /// This method is used to serialize a `SecureShare` structure and use a custom serializer instead of /// using the serialized form of the content stored in `serialized_data`. /// This is useful when the content need to be serialized in a lighter form in specific cases. /// /// # Arguments: - /// * `serializer_content`: Custom serializer to be used instead of the data in `serialized_data` - /// * `value`: Wrapped structure to be serialized + /// * `content_serializer`: Custom serializer to be used instead of the data in `serialized_data` + /// * `value`: SecureShare structure to be serialized /// * `buffer`: buffer of serialized data to be extend - pub fn serialize_with( + pub fn serialize_with( &self, - serializer_content: &SC, - value: &Wrapped, + content_serializer: &Ser, + value: &SecureShare, buffer: &mut Vec, ) -> Result<(), SerializeError> where - SC: Serializer, - T: Display + WrappedContent, - U: Id, + Ser: Serializer, + T: Display + SecureShareContent, + ID: Id, { let mut content_buffer = Vec::new(); - serializer_content.serialize(&value.content, &mut content_buffer)?; + content_serializer.serialize(&value.content, &mut content_buffer)?; T::serialize( &value.signature, - &value.creator_public_key, + &value.content_creator_pub_key, &content_buffer, buffer, ) } } -impl Serializer> for WrappedSerializer +impl Serializer> for SecureShareSerializer where - T: Display + WrappedContent, - U: Id, + T: Display + SecureShareContent, + ID: Id, { - fn serialize(&self, value: &Wrapped, buffer: &mut Vec) -> Result<(), SerializeError> { + fn serialize( + &self, + value: &SecureShare, + buffer: &mut Vec, + ) -> Result<(), SerializeError> { T::serialize( &value.signature, - &value.creator_public_key, + &value.content_creator_pub_key, &value.serialized_data, buffer, ) } } -/// Deserializer for Wrapped structure -pub struct WrappedDeserializer +/// Deserializer for SecureShare structure +pub struct SecureShareDeserializer where - T: Display + WrappedContent, - DT: Deserializer, + T: Display + SecureShareContent, + Deser: Deserializer, { signature_deserializer: SignatureDeserializer, public_key_deserializer: PublicKeyDeserializer, - content_deserializer: DT, + content_deserializer: Deser, marker_t: std::marker::PhantomData, } -impl WrappedDeserializer +impl SecureShareDeserializer where - T: Display + WrappedContent, - DT: Deserializer, + T: Display + SecureShareContent, + Deser: Deserializer, { - /// Creates a new `WrappedDeserializer` + /// Creates a new `SecureShareDeserializer` /// /// # Arguments /// * `content_deserializer` - Deserializer for the content - pub const fn new(content_deserializer: DT) -> Self { + pub const fn new(content_deserializer: Deser) -> Self { Self { signature_deserializer: SignatureDeserializer::new(), public_key_deserializer: PublicKeyDeserializer::new(), @@ -276,17 +288,17 @@ where /// * `buffer`: buffer of serialized data to be deserialized /// /// # Returns: - /// A rest and the wrapped structure with coherent fields. + /// A rest (data left over from deserialization) and structure wrapped up with signature verification data as coherent fields. pub fn deserialize_with< 'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>, - U: Id, - ST: Serializer, + ID: Id, + Ser: Serializer, >( &self, - content_serializer: &ST, + content_serializer: &Ser, buffer: &'a [u8], - ) -> IResult<&'a [u8], Wrapped, E> { + ) -> IResult<&'a [u8], SecureShare, E> { T::deserialize( Some(content_serializer), &self.signature_deserializer, @@ -297,14 +309,14 @@ where } } -impl Deserializer> for WrappedDeserializer +impl Deserializer> for SecureShareDeserializer where - T: Display + WrappedContent, - U: Id, - DT: Deserializer, + T: Display + SecureShareContent, + ID: Id, + Deser: Deserializer, { /// ``` - /// # use massa_models::{block::BlockId, endorsement::{Endorsement, EndorsementSerializer, EndorsementDeserializer}, slot::Slot, wrapped::{Wrapped, WrappedSerializer, WrappedDeserializer, WrappedContent}}; + /// # use massa_models::{block::BlockId, endorsement::{Endorsement, EndorsementSerializer, EndorsementDeserializer}, slot::Slot, secure_share::{SecureShare, SecureShareSerializer, SecureShareDeserializer, SecureShareContent}}; /// # use massa_serialization::{Deserializer, Serializer, DeserializeError, U16VarIntSerializer, U16VarIntDeserializer}; /// # use massa_signature::KeyPair; /// # use std::ops::Bound::Included; @@ -316,22 +328,22 @@ where /// endorsed_block: BlockId(Hash::compute_from("blk".as_bytes())), /// }; /// let keypair = KeyPair::generate(); - /// let wrapped: Wrapped = Endorsement::new_wrapped( + /// let secured: SecureShare = Endorsement::new_verifiable( /// content, /// EndorsementSerializer::new(), /// &keypair /// ).unwrap(); /// let mut serialized_data = Vec::new(); - /// let serialized = WrappedSerializer::new().serialize(&wrapped, &mut serialized_data).unwrap(); - /// let deserializer = WrappedDeserializer::new(EndorsementDeserializer::new(32, 1)); - /// let (rest, deserialized): (&[u8], Wrapped) = deserializer.deserialize::(&serialized_data).unwrap(); + /// let serialized = SecureShareSerializer::new().serialize(&secured, &mut serialized_data).unwrap(); + /// let deserializer = SecureShareDeserializer::new(EndorsementDeserializer::new(32, 1)); + /// let (rest, deserialized): (&[u8], SecureShare) = deserializer.deserialize::(&serialized_data).unwrap(); /// assert!(rest.is_empty()); - /// assert_eq!(wrapped.id, deserialized.id); + /// assert_eq!(secured.id, deserialized.id); /// ``` fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( &self, buffer: &'a [u8], - ) -> IResult<&'a [u8], Wrapped, E> { + ) -> IResult<&'a [u8], SecureShare, E> { T::deserialize( None, &self.signature_deserializer, diff --git a/massa-network-exports/src/commands.rs b/massa-network-exports/src/commands.rs index d2547f8b288..3062ed5c827 100644 --- a/massa-network-exports/src/commands.rs +++ b/massa-network-exports/src/commands.rs @@ -71,11 +71,11 @@ use crate::{BootstrapPeers, ConnectionClosureReason, Peers}; use massa_models::{ - block::{BlockId, WrappedHeader}, + block::{BlockId, SecuredHeader}, composite::PubkeySig, - endorsement::WrappedEndorsement, + endorsement::SecureShareEndorsement, node::NodeId, - operation::{OperationId, OperationPrefixIds, WrappedOperation}, + operation::{OperationId, OperationPrefixIds, SecureShareOperation}, stats::NetworkStats, }; use serde::{Deserialize, Serialize}; @@ -89,7 +89,7 @@ pub enum NodeCommand { /// Send given peer list to node. SendPeerList(Vec), /// Send the header of a block to a node. - SendBlockHeader(WrappedHeader), + SendBlockHeader(SecuredHeader), /// Ask for info on a list of blocks. AskForBlocks(Vec<(BlockId, AskForBlocksInfo)>), /// Reply with info on a list of blocks. @@ -97,13 +97,13 @@ pub enum NodeCommand { /// Close the node worker. Close(ConnectionClosureReason), /// Send full Operations (send to a node that previously asked for) - SendOperations(Vec), + SendOperations(Vec), /// Send a batch of operation ids SendOperationAnnouncements(OperationPrefixIds), /// Ask for a set of operations AskForOperations(OperationPrefixIds), /// Endorsements - SendEndorsements(Vec), + SendEndorsements(Vec), /// Ask peer list AskPeerList, } @@ -119,19 +119,19 @@ pub enum NodeEventType { /// Node we are connected to sent peer list ReceivedPeerList(Vec), /// Node we are connected to sent block header - ReceivedBlockHeader(WrappedHeader), + ReceivedBlockHeader(SecuredHeader), /// Node we are connected asked for info on a list of blocks. ReceivedAskForBlocks(Vec<(BlockId, AskForBlocksInfo)>), /// Node we are connected sent info on a list of blocks. ReceivedReplyForBlocks(Vec<(BlockId, BlockInfoReply)>), /// Received full operations. - ReceivedOperations(Vec), + ReceivedOperations(Vec), /// Received an operation id batch announcing new operations ReceivedOperationAnnouncements(OperationPrefixIds), /// Receive a list of wanted operations ReceivedAskForOperations(OperationPrefixIds), /// Receive a set of endorsement - ReceivedEndorsements(Vec), + ReceivedEndorsements(Vec), } /// Events node worker can emit. @@ -172,7 +172,7 @@ pub enum NetworkCommand { /// to node id node: NodeId, /// block id - header: WrappedHeader, + header: SecuredHeader, }, /// `(PeerInfo, Vec <(NodeId, bool)>) peer info + list` of associated Id nodes in connection out (true) GetPeers(oneshot::Sender), @@ -191,7 +191,7 @@ pub enum NetworkCommand { /// to node id node: NodeId, /// endorsements - endorsements: Vec, + endorsements: Vec, }, /// sign message with our node keypair (associated to node id) /// != staking key @@ -211,7 +211,7 @@ pub enum NetworkCommand { /// to node id node: NodeId, /// operations - operations: Vec, + operations: Vec, }, /// Send operation ids batch to a node SendOperationAnnouncements { @@ -238,11 +238,11 @@ pub enum NetworkCommand { #[allow(clippy::large_enum_variant)] pub enum BlockInfoReply { /// Header - Header(WrappedHeader), + Header(SecuredHeader), /// The info about the block is required(list of operations ids). Info(Vec), /// The actual operations required. - Operations(Vec), + Operations(Vec), /// Block not found NotFound, } @@ -267,7 +267,7 @@ pub enum NetworkEvent { /// from node id source_node_id: NodeId, /// header - header: WrappedHeader, + header: SecuredHeader, }, /// Someone ask for block with given header hash. AskedForBlocks { @@ -281,7 +281,7 @@ pub enum NetworkEvent { /// node id node: NodeId, /// operations - operations: Vec, + operations: Vec, }, /// Receive a list of `OperationId` ReceivedOperationAnnouncements { @@ -302,7 +302,7 @@ pub enum NetworkEvent { /// node id node: NodeId, /// Endorsements - endorsements: Vec, + endorsements: Vec, }, } diff --git a/massa-network-exports/src/network_controller.rs b/massa-network-exports/src/network_controller.rs index d8dca55d79a..c948e315134 100644 --- a/massa-network-exports/src/network_controller.rs +++ b/massa-network-exports/src/network_controller.rs @@ -6,11 +6,11 @@ use crate::{ BlockInfoReply, BootstrapPeers, NetworkCommand, NetworkEvent, Peers, }; use massa_models::{ - block::{BlockId, WrappedHeader}, + block::{BlockId, SecuredHeader}, composite::PubkeySig, - endorsement::WrappedEndorsement, + endorsement::SecureShareEndorsement, node::NodeId, - operation::{OperationPrefixIds, WrappedOperation}, + operation::{OperationPrefixIds, SecureShareOperation}, stats::NetworkStats, }; use std::{ @@ -123,7 +123,7 @@ impl NetworkCommandSender { pub async fn send_block_header( &self, node: NodeId, - header: WrappedHeader, + header: SecuredHeader, ) -> Result<(), NetworkError> { self.0 .send(NetworkCommand::SendBlockHeader { node, header }) @@ -178,7 +178,7 @@ impl NetworkCommandSender { pub async fn send_operations( &self, node: NodeId, - operations: Vec, + operations: Vec, ) -> Result<(), NetworkError> { self.0 .send(NetworkCommand::SendOperations { node, operations }) @@ -241,7 +241,7 @@ impl NetworkCommandSender { pub async fn send_endorsements( &self, node: NodeId, - endorsements: Vec, + endorsements: Vec, ) -> Result<(), NetworkError> { self.0 .send(NetworkCommand::SendEndorsements { node, endorsements }) diff --git a/massa-network-worker/src/messages.rs b/massa-network-worker/src/messages.rs index cc5ab4855a4..5485e6a6a4b 100644 --- a/massa-network-worker/src/messages.rs +++ b/massa-network-worker/src/messages.rs @@ -2,18 +2,18 @@ use massa_hash::HashDeserializer; use massa_models::{ - block::{BlockHeader, BlockHeaderDeserializer, BlockId, WrappedHeader}, + block::{BlockHeader, BlockHeaderDeserializer, BlockId, SecuredHeader}, config::HANDSHAKE_RANDOMNESS_SIZE_BYTES, - endorsement::{Endorsement, EndorsementDeserializer, WrappedEndorsement}, + endorsement::{Endorsement, EndorsementDeserializer, SecureShareEndorsement}, operation::{ OperationIdsDeserializer, OperationIdsSerializer, OperationPrefixIds, OperationPrefixIdsDeserializer, OperationPrefixIdsSerializer, OperationsDeserializer, - OperationsSerializer, WrappedOperation, + OperationsSerializer, SecureShareOperation, }, + secure_share::{SecureShareDeserializer, SecureShareSerializer}, serialization::array_from_slice, serialization::{IpAddrDeserializer, IpAddrSerializer}, version::{Version, VersionDeserializer, VersionSerializer}, - wrapped::{WrappedDeserializer, WrappedSerializer}, }; use massa_network_exports::{AskForBlocksInfo, BlockInfoReply}; use massa_serialization::{ @@ -52,7 +52,7 @@ pub enum Message { signature: Signature, }, /// Block header - BlockHeader(WrappedHeader), + BlockHeader(SecuredHeader), /// Message asking the peer for info on a list of blocks. AskForBlocks(Vec<(BlockId, AskForBlocksInfo)>), /// Message replying with info on a list of blocks. @@ -69,9 +69,9 @@ pub enum Message { /// Someone ask for operations. AskForOperations(OperationPrefixIds), /// A list of operations - Operations(Vec), + Operations(Vec), /// Endorsements - Endorsements(Vec), + Endorsements(Vec), } #[derive(IntoPrimitive, Debug, Eq, PartialEq, TryFromPrimitive)] @@ -103,7 +103,7 @@ pub(crate) enum BlockInfoType { pub struct MessageSerializer { version_serializer: VersionSerializer, u32_serializer: U32VarIntSerializer, - wrapped_serializer: WrappedSerializer, + secure_serializer: SecureShareSerializer, operation_prefix_ids_serializer: OperationPrefixIdsSerializer, operations_ids_serializer: OperationIdsSerializer, operations_serializer: OperationsSerializer, @@ -116,7 +116,7 @@ impl MessageSerializer { MessageSerializer { version_serializer: VersionSerializer::new(), u32_serializer: U32VarIntSerializer::new(), - wrapped_serializer: WrappedSerializer::new(), + secure_serializer: SecureShareSerializer::new(), operation_prefix_ids_serializer: OperationPrefixIdsSerializer::new(), operations_ids_serializer: OperationIdsSerializer::new(), operations_serializer: OperationsSerializer::new(), @@ -155,7 +155,7 @@ impl Serializer for MessageSerializer { Message::BlockHeader(header) => { self.u32_serializer .serialize(&(MessageTypeId::BlockHeader as u32), buffer)?; - self.wrapped_serializer.serialize(header, buffer)?; + self.secure_serializer.serialize(header, buffer)?; } Message::AskForBlocks(list) => { self.u32_serializer @@ -192,7 +192,7 @@ impl Serializer for MessageSerializer { self.u32_serializer .serialize(&u32::from(info_type), buffer)?; if let BlockInfoReply::Header(header) = info { - self.wrapped_serializer.serialize(header, buffer)?; + self.secure_serializer.serialize(header, buffer)?; } if let BlockInfoReply::Operations(ops) = info { self.operations_serializer.serialize(ops, buffer)?; @@ -238,7 +238,7 @@ impl Serializer for MessageSerializer { self.u32_serializer .serialize(&(endorsements.len() as u32), buffer)?; for endorsement in endorsements { - self.wrapped_serializer.serialize(endorsement, buffer)?; + self.secure_serializer.serialize(endorsement, buffer)?; } } } @@ -256,9 +256,9 @@ pub struct MessageDeserializer { peer_list_length_deserializer: U32VarIntDeserializer, operations_deserializer: OperationsDeserializer, hash_deserializer: HashDeserializer, - block_header_deserializer: WrappedDeserializer, + block_header_deserializer: SecureShareDeserializer, endorsements_length_deserializer: U32VarIntDeserializer, - endorsement_deserializer: WrappedDeserializer, + endorsement_deserializer: SecureShareDeserializer, operation_prefix_ids_deserializer: OperationPrefixIdsDeserializer, infos_deserializer: OperationIdsDeserializer, ip_addr_deserializer: IpAddrDeserializer, @@ -305,7 +305,7 @@ impl MessageDeserializer { max_op_datastore_value_length, ), hash_deserializer: HashDeserializer::new(), - block_header_deserializer: WrappedDeserializer::new(BlockHeaderDeserializer::new( + block_header_deserializer: SecureShareDeserializer::new(BlockHeaderDeserializer::new( thread_count, endorsement_count, )), @@ -313,7 +313,7 @@ impl MessageDeserializer { Included(0), Excluded(max_endorsements_per_message), ), - endorsement_deserializer: WrappedDeserializer::new(EndorsementDeserializer::new( + endorsement_deserializer: SecureShareDeserializer::new(EndorsementDeserializer::new( thread_count, endorsement_count, )), diff --git a/massa-network-worker/src/network_cmd_impl.rs b/massa-network-worker/src/network_cmd_impl.rs index 35d6fc05c5f..4e1752a5ca1 100644 --- a/massa-network-worker/src/network_cmd_impl.rs +++ b/massa-network-worker/src/network_cmd_impl.rs @@ -24,11 +24,11 @@ use futures::{stream::FuturesUnordered, StreamExt}; use massa_hash::Hash; use massa_logging::massa_trace; use massa_models::{ - block::{BlockId, WrappedHeader}, + block::{BlockId, SecuredHeader}, composite::PubkeySig, - endorsement::WrappedEndorsement, + endorsement::SecureShareEndorsement, node::NodeId, - operation::{OperationPrefixIds, WrappedOperation}, + operation::{OperationPrefixIds, SecureShareOperation}, stats::NetworkStats, }; use massa_network_exports::{ @@ -175,7 +175,7 @@ pub async fn on_node_ban_by_ids_cmd( pub async fn on_send_block_header_cmd( worker: &mut NetworkWorker, node: NodeId, - header: WrappedHeader, + header: SecuredHeader, ) -> Result<(), NetworkError> { massa_trace!("network_worker.manage_network_command send NodeCommand::SendBlockHeader", {"block_id": header.id, "node": node}); worker @@ -254,7 +254,7 @@ pub async fn on_get_bootstrap_peers_cmd( pub async fn on_send_endorsements_cmd( worker: &mut NetworkWorker, node: NodeId, - endorsements: Vec, + endorsements: Vec, ) { massa_trace!( "network_worker.manage_network_command receive NetworkCommand::SendEndorsements", @@ -355,7 +355,7 @@ pub async fn on_get_stats_cmd( pub async fn on_send_operations_cmd( worker: &mut NetworkWorker, to_node: NodeId, - operations: Vec, + operations: Vec, ) { massa_trace!( "network_worker.manage_network_command receive NetworkCommand::SendOperations", diff --git a/massa-network-worker/src/network_event.rs b/massa-network-worker/src/network_event.rs index a939301a1dc..1b936d3d073 100644 --- a/massa-network-worker/src/network_event.rs +++ b/massa-network-worker/src/network_event.rs @@ -80,11 +80,11 @@ pub mod event_impl { use crate::network_worker::NetworkWorker; use massa_logging::massa_trace; use massa_models::{ - block::{BlockId, WrappedHeader}, - endorsement::WrappedEndorsement, + block::{BlockId, SecuredHeader}, + endorsement::SecureShareEndorsement, node::NodeId, - operation::{OperationPrefixIds, WrappedOperation}, - wrapped::Id, + operation::{OperationPrefixIds, SecureShareOperation}, + secure_share::Id, }; use massa_network_exports::{AskForBlocksInfo, BlockInfoReply, NodeCommand}; use massa_network_exports::{NetworkError, NetworkEvent}; @@ -128,7 +128,7 @@ pub mod event_impl { pub async fn on_received_block_header( worker: &mut NetworkWorker, from: NodeId, - header: WrappedHeader, + header: SecuredHeader, ) -> Result<(), NetworkError> { massa_trace!( "network_worker.on_node_event receive NetworkEvent::ReceivedBlockHeader", @@ -195,7 +195,7 @@ pub mod event_impl { pub async fn on_received_operations( worker: &mut NetworkWorker, from: NodeId, - operations: Vec, + operations: Vec, ) { massa_trace!( "network_worker.on_node_event receive NetworkEvent::ReceivedOperations", @@ -262,7 +262,7 @@ pub mod event_impl { pub async fn on_received_endorsements( worker: &mut NetworkWorker, from: NodeId, - endorsements: Vec, + endorsements: Vec, ) { massa_trace!( "network_worker.on_node_event receive NetworkEvent::ReceivedEndorsements", diff --git a/massa-network-worker/src/node_worker.rs b/massa-network-worker/src/node_worker.rs index a93218c4ef7..1174a66471b 100644 --- a/massa-network-worker/src/node_worker.rs +++ b/massa-network-worker/src/node_worker.rs @@ -6,7 +6,7 @@ use super::{ }; use itertools::Itertools; use massa_logging::massa_trace; -use massa_models::{node::NodeId, wrapped::Id}; +use massa_models::{node::NodeId, secure_share::Id}; use massa_network_exports::{ ConnectionClosureReason, NetworkConfig, NetworkError, NodeCommand, NodeEvent, NodeEventType, }; diff --git a/massa-network-worker/src/tests/scenarios.rs b/massa-network-worker/src/tests/scenarios.rs index d0155abab7e..27fb42195a3 100644 --- a/massa-network-worker/src/tests/scenarios.rs +++ b/massa-network-worker/src/tests/scenarios.rs @@ -25,8 +25,8 @@ use massa_models::{ block::BlockId, endorsement::{Endorsement, EndorsementSerializer}, node::NodeId, + secure_share::SecureShareContent, slot::Slot, - wrapped::WrappedContent, }; use massa_network_exports::{settings::PeerTypeConnectionConfig, NodeCommand, NodeEvent}; use massa_network_exports::{ @@ -1197,7 +1197,7 @@ async fn test_endorsements_messages() { index: 0, endorsed_block: BlockId(Hash::compute_from(&[])), }; - let endorsement = Endorsement::new_wrapped( + let endorsement = Endorsement::new_verifiable( content.clone(), EndorsementSerializer::new(), &sender_keypair, @@ -1233,7 +1233,7 @@ async fn test_endorsements_messages() { index: 0, endorsed_block: BlockId(Hash::compute_from(&[])), }; - let endorsement = Endorsement::new_wrapped( + let endorsement = Endorsement::new_verifiable( content.clone(), EndorsementSerializer::new(), &sender_keypair, diff --git a/massa-network-worker/src/tests/tools.rs b/massa-network-worker/src/tests/tools.rs index 321e9bd4f97..7400fc0683a 100644 --- a/massa-network-worker/src/tests/tools.rs +++ b/massa-network-worker/src/tests/tools.rs @@ -11,12 +11,12 @@ use crate::NetworkEvent; use massa_hash::Hash; use massa_models::node::NodeId; -use massa_models::wrapped::WrappedContent; +use massa_models::secure_share::SecureShareContent; use massa_models::{ address::Address, amount::Amount, block::BlockId, - operation::{Operation, OperationSerializer, OperationType, WrappedOperation}, + operation::{Operation, OperationSerializer, OperationType, SecureShareOperation}, version::Version, }; use massa_network_exports::test_exports::mock_establisher::{self, MockEstablisherInterface}; @@ -324,7 +324,7 @@ pub async fn incoming_message_drain_stop( join_handle.await.expect("could not join message drain") } -pub fn get_transaction(expire_period: u64, fee: u64) -> WrappedOperation { +pub fn get_transaction(expire_period: u64, fee: u64) -> SecureShareOperation { let sender_keypair = KeyPair::generate(); let recv_keypair = KeyPair::generate(); @@ -339,7 +339,7 @@ pub fn get_transaction(expire_period: u64, fee: u64) -> WrappedOperation { expire_period, }; - Operation::new_wrapped(content, OperationSerializer::new(), &sender_keypair).unwrap() + Operation::new_verifiable(content, OperationSerializer::new(), &sender_keypair).unwrap() } /// Runs a consensus test, passing a mock pool controller to it. diff --git a/massa-pool-worker/src/tests/operation_pool_tests.rs b/massa-pool-worker/src/tests/operation_pool_tests.rs index a960e3eb4b1..044e00030f1 100644 --- a/massa-pool-worker/src/tests/operation_pool_tests.rs +++ b/massa-pool-worker/src/tests/operation_pool_tests.rs @@ -23,10 +23,10 @@ use massa_execution_exports::test_exports::MockExecutionController; use massa_models::{ address::Address, amount::Amount, - operation::{Operation, OperationSerializer, OperationType, WrappedOperation}, + operation::{Operation, OperationSerializer, OperationType, SecureShareOperation}, prehash::PreHashMap, + secure_share::SecureShareContent, slot::Slot, - wrapped::WrappedContent, }; use massa_pool_exports::PoolConfig; use massa_signature::KeyPair; @@ -56,7 +56,7 @@ fn test_add_irrelevant_operation() { }); } -fn get_transaction(expire_period: u64, fee: u64) -> WrappedOperation { +fn get_transaction(expire_period: u64, fee: u64) -> SecureShareOperation { let sender_keypair = KeyPair::generate(); let recv_keypair = KeyPair::generate(); @@ -70,7 +70,7 @@ fn get_transaction(expire_period: u64, fee: u64) -> WrappedOperation { op, expire_period, }; - Operation::new_wrapped(content, OperationSerializer::new(), &sender_keypair).unwrap() + Operation::new_verifiable(content, OperationSerializer::new(), &sender_keypair).unwrap() } /// TODO refactor old tests @@ -105,7 +105,9 @@ fn test_pool() { //TODO: compare //assert_eq!(storage.get_op_refs(), &ops.keys().copied().collect::>()); - let op_thread = op.creator_address.get_thread(pool_config.thread_count); + let op_thread = op + .content_creator_address + .get_thread(pool_config.thread_count); thread_tx_lists[op_thread as usize].push((op, start_period..=expire_period)); } @@ -185,7 +187,9 @@ fn test_pool() { pool.add_operations(storage); //TODO: compare //assert_eq!(storage.get_op_refs(), &Set::::default()); - let op_thread = op.creator_address.get_thread(pool_config.thread_count); + let op_thread = op + .content_creator_address + .get_thread(pool_config.thread_count); let (ids, _) = pool.get_block_operations(&Slot::new(expire_period - 1, op_thread)); assert!(ids.is_empty()); } diff --git a/massa-pool-worker/src/tests/tools.rs b/massa-pool-worker/src/tests/tools.rs index c7c8c0a0eb8..add5d139135 100644 --- a/massa-pool-worker/src/tests/tools.rs +++ b/massa-pool-worker/src/tests/tools.rs @@ -9,10 +9,10 @@ use massa_models::{ address::Address, amount::Amount, block::BlockId, - endorsement::{Endorsement, EndorsementSerializer, WrappedEndorsement}, - operation::{Operation, OperationSerializer, OperationType, WrappedOperation}, + endorsement::{Endorsement, EndorsementSerializer, SecureShareEndorsement}, + operation::{Operation, OperationSerializer, OperationType, SecureShareOperation}, + secure_share::SecureShareContent, slot::Slot, - wrapped::WrappedContent, }; use massa_pool_exports::{PoolConfig, PoolController, PoolManager}; use massa_signature::{KeyPair, PublicKey}; @@ -25,7 +25,7 @@ use std::sync::mpsc::Receiver; pub fn create_operation_with_expire_period( keypair: &KeyPair, expire_period: u64, -) -> WrappedOperation { +) -> SecureShareOperation { let recv_keypair = KeyPair::generate(); let op = OperationType::Transaction { @@ -37,15 +37,15 @@ pub fn create_operation_with_expire_period( op, expire_period, }; - Operation::new_wrapped(content, OperationSerializer::new(), keypair).unwrap() + Operation::new_verifiable(content, OperationSerializer::new(), keypair).unwrap() } -/// Return `n` wrapped operations +/// Return `n` signed operations pub fn create_some_operations( n: usize, keypair: &KeyPair, expire_period: u64, -) -> Vec { +) -> Vec { (0..n) .map(|_| create_operation_with_expire_period(keypair, expire_period)) .collect() @@ -81,7 +81,7 @@ where ) } -pub fn _get_transaction(expire_period: u64, fee: u64) -> WrappedOperation { +pub fn _get_transaction(expire_period: u64, fee: u64) -> SecureShareOperation { let sender_keypair = KeyPair::generate(); let op = OperationType::Transaction { @@ -93,11 +93,11 @@ pub fn _get_transaction(expire_period: u64, fee: u64) -> WrappedOperation { op, expire_period, }; - Operation::new_wrapped(content, OperationSerializer::new(), &sender_keypair).unwrap() + Operation::new_verifiable(content, OperationSerializer::new(), &sender_keypair).unwrap() } /// Creates an endorsement for use in pool tests. -pub fn _create_endorsement(slot: Slot) -> WrappedEndorsement { +pub fn _create_endorsement(slot: Slot) -> SecureShareEndorsement { let sender_keypair = KeyPair::generate(); let content = Endorsement { @@ -105,7 +105,7 @@ pub fn _create_endorsement(slot: Slot) -> WrappedEndorsement { index: 0, endorsed_block: BlockId(Hash::compute_from("blabla".as_bytes())), }; - Endorsement::new_wrapped(content, EndorsementSerializer::new(), &sender_keypair).unwrap() + Endorsement::new_verifiable(content, EndorsementSerializer::new(), &sender_keypair).unwrap() } pub fn _get_transaction_with_addresses( @@ -113,7 +113,7 @@ pub fn _get_transaction_with_addresses( fee: u64, sender_keypair: &KeyPair, recv_pub: PublicKey, -) -> WrappedOperation { +) -> SecureShareOperation { let op = OperationType::Transaction { recipient_address: Address::from_public_key(&recv_pub), amount: Amount::default(), @@ -123,5 +123,5 @@ pub fn _get_transaction_with_addresses( op, expire_period, }; - Operation::new_wrapped(content, OperationSerializer::new(), sender_keypair).unwrap() + Operation::new_verifiable(content, OperationSerializer::new(), sender_keypair).unwrap() } diff --git a/massa-pool-worker/src/types.rs b/massa-pool-worker/src/types.rs index 3ba6129a025..871f3c707e9 100644 --- a/massa-pool-worker/src/types.rs +++ b/massa-pool-worker/src/types.rs @@ -1,7 +1,7 @@ use massa_models::{ address::Address, amount::Amount, - operation::{OperationId, WrappedOperation}, + operation::{OperationId, SecureShareOperation}, }; use num::rational::Ratio; use std::cmp::Reverse; @@ -40,7 +40,7 @@ pub struct OperationInfo { impl OperationInfo { pub fn from_op( - op: &WrappedOperation, + op: &SecureShareOperation, operation_validity_periods: u64, roll_price: Amount, thread_count: u8, @@ -50,9 +50,9 @@ impl OperationInfo { cursor: build_operation_cursor(op), size: op.serialized_size(), max_gas: op.get_gas_usage(), - creator_address: op.creator_address, + creator_address: op.content_creator_address, fee: op.content.fee, - thread: op.creator_address.get_thread(thread_count), + thread: op.content_creator_address.get_thread(thread_count), validity_period_range: op.get_validity_range(operation_validity_periods), max_spending: op.get_max_spending(roll_price), } @@ -60,7 +60,7 @@ impl OperationInfo { } /// build a cursor from an operation -fn build_operation_cursor(op: &WrappedOperation) -> PoolOperationCursor { +fn build_operation_cursor(op: &SecureShareOperation) -> PoolOperationCursor { let quality = Ratio::new(op.content.fee.to_raw(), op.serialized_size() as u64); let inner = (Reverse(quality), op.id); // TODO take into account max_gas as well in the future (multi-dimensional packing) diff --git a/massa-protocol-exports/src/protocol_controller.rs b/massa-protocol-exports/src/protocol_controller.rs index 4f615dc194c..e6a52864b6c 100644 --- a/massa-protocol-exports/src/protocol_controller.rs +++ b/massa-protocol-exports/src/protocol_controller.rs @@ -5,7 +5,7 @@ use massa_logging::massa_trace; use massa_models::prehash::{PreHashMap, PreHashSet}; use massa_models::{ - block::{BlockId, WrappedHeader}, + block::{BlockId, SecuredHeader}, endorsement::EndorsementId, operation::OperationId, }; @@ -40,7 +40,7 @@ pub enum ProtocolCommand { /// Wish list delta WishlistDelta { /// add to wish list - new: PreHashMap>, + new: PreHashMap>, /// remove from wish list remove: PreHashSet, }, @@ -94,7 +94,7 @@ impl ProtocolCommandSender { /// update the block wish list pub fn send_wishlist_delta( &mut self, - new: PreHashMap>, + new: PreHashMap>, remove: PreHashSet, ) -> Result<(), ProtocolError> { massa_trace!("protocol.command_sender.send_wishlist_delta", { "new": new, "remove": remove }); diff --git a/massa-protocol-exports/src/tests/mock_network_controller.rs b/massa-protocol-exports/src/tests/mock_network_controller.rs index db9ae9b627b..498a87a0ae0 100644 --- a/massa-protocol-exports/src/tests/mock_network_controller.rs +++ b/massa-protocol-exports/src/tests/mock_network_controller.rs @@ -1,13 +1,13 @@ // Copyright (c) 2022 MASSA LABS use massa_models::{ - block::{BlockId, WrappedHeader}, - endorsement::WrappedEndorsement, + block::{BlockId, SecuredHeader}, + endorsement::SecureShareEndorsement, }; use massa_models::{ config::CHANNEL_SIZE, node::NodeId, - operation::{OperationId, WrappedOperation}, + operation::{OperationId, SecureShareOperation}, }; use massa_network_exports::{ AskForBlocksInfo, BlockInfoReply, NetworkCommand, NetworkCommandSender, NetworkEvent, @@ -74,7 +74,7 @@ impl MockNetworkController { /// send header /// todo inconsistency with names - pub async fn send_header(&mut self, source_node_id: NodeId, header: WrappedHeader) { + pub async fn send_header(&mut self, source_node_id: NodeId, header: SecuredHeader) { self.network_event_tx .send(NetworkEvent::ReceivedBlockHeader { source_node_id, @@ -89,7 +89,7 @@ impl MockNetworkController { pub async fn send_operations( &mut self, source_node_id: NodeId, - operations: Vec, + operations: Vec, ) { self.network_event_tx .send(NetworkEvent::ReceivedOperations { @@ -137,7 +137,7 @@ impl MockNetworkController { pub async fn send_endorsements( &mut self, source_node_id: NodeId, - endorsements: Vec, + endorsements: Vec, ) { self.network_event_tx .send(NetworkEvent::ReceivedEndorsements { diff --git a/massa-protocol-exports/src/tests/tools.rs b/massa-protocol-exports/src/tests/tools.rs index 2928ad7a206..ff558cf89ec 100644 --- a/massa-protocol-exports/src/tests/tools.rs +++ b/massa-protocol-exports/src/tests/tools.rs @@ -5,13 +5,15 @@ use crate::ProtocolConfig; use massa_hash::Hash; use massa_models::node::NodeId; use massa_models::operation::OperationSerializer; -use massa_models::wrapped::WrappedContent; +use massa_models::secure_share::SecureShareContent; use massa_models::{ address::Address, amount::Amount, - block::{Block, BlockHeader, BlockHeaderSerializer, BlockId, BlockSerializer, WrappedBlock}, - endorsement::{Endorsement, EndorsementSerializerLW, WrappedEndorsement}, - operation::{Operation, OperationType, WrappedOperation}, + block::{ + Block, BlockHeader, BlockHeaderSerializer, BlockId, BlockSerializer, SecureShareBlock, + }, + endorsement::{Endorsement, EndorsementSerializerLW, SecureShareEndorsement}, + operation::{Operation, OperationType, SecureShareOperation}, slot::Slot, }; use massa_network_exports::{AskForBlocksInfo, NetworkCommand}; @@ -55,8 +57,8 @@ pub async fn create_and_connect_nodes( /// Creates a block for use in protocol, /// without paying attention to consensus related things /// like slot, parents, and merkle root. -pub fn create_block(keypair: &KeyPair) -> WrappedBlock { - let header = BlockHeader::new_wrapped( +pub fn create_block(keypair: &KeyPair) -> SecureShareBlock { + let header = BlockHeader::new_verifiable( BlockHeader { slot: Slot::new(1, 0), parents: vec![ @@ -71,7 +73,7 @@ pub fn create_block(keypair: &KeyPair) -> WrappedBlock { ) .unwrap(); - Block::new_wrapped( + Block::new_verifiable( Block { header, operations: Default::default(), @@ -90,14 +92,14 @@ pub fn create_block(keypair: &KeyPair) -> WrappedBlock { pub fn create_block_with_operations( keypair: &KeyPair, slot: Slot, - operations: Vec, -) -> WrappedBlock { + operations: Vec, +) -> SecureShareBlock { let operation_merkle_root = Hash::compute_from( &operations.iter().fold(Vec::new(), |acc, v| { [acc, v.id.to_bytes().to_vec()].concat() })[..], ); - let header = BlockHeader::new_wrapped( + let header = BlockHeader::new_verifiable( BlockHeader { slot, parents: vec![ @@ -113,7 +115,7 @@ pub fn create_block_with_operations( .unwrap(); let op_ids = operations.into_iter().map(|op| op.id).collect(); - Block::new_wrapped( + Block::new_verifiable( Block { header, operations: op_ids, @@ -132,9 +134,9 @@ pub fn create_block_with_operations( pub fn create_block_with_endorsements( keypair: &KeyPair, slot: Slot, - endorsements: Vec, -) -> WrappedBlock { - let header = BlockHeader::new_wrapped( + endorsements: Vec, +) -> SecureShareBlock { + let header = BlockHeader::new_verifiable( BlockHeader { slot, parents: vec![ @@ -149,7 +151,7 @@ pub fn create_block_with_endorsements( ) .unwrap(); - Block::new_wrapped( + Block::new_verifiable( Block { header, operations: Default::default(), @@ -162,7 +164,7 @@ pub fn create_block_with_endorsements( /// Creates an endorsement for use in protocol tests, /// without paying attention to consensus related things. -pub fn create_endorsement() -> WrappedEndorsement { +pub fn create_endorsement() -> SecureShareEndorsement { let keypair = KeyPair::generate(); let content = Endorsement { @@ -170,14 +172,14 @@ pub fn create_endorsement() -> WrappedEndorsement { index: 0, endorsed_block: BlockId(Hash::compute_from(&[])), }; - Endorsement::new_wrapped(content, EndorsementSerializerLW::new(), &keypair).unwrap() + Endorsement::new_verifiable(content, EndorsementSerializerLW::new(), &keypair).unwrap() } /// Create an operation, from a specific sender, and with a specific expire period. pub fn create_operation_with_expire_period( keypair: &KeyPair, expire_period: u64, -) -> WrappedOperation { +) -> SecureShareOperation { let recv_keypair = KeyPair::generate(); let op = OperationType::Transaction { @@ -189,7 +191,7 @@ pub fn create_operation_with_expire_period( op, expire_period, }; - Operation::new_wrapped(content, OperationSerializer::new(), keypair).unwrap() + Operation::new_verifiable(content, OperationSerializer::new(), keypair).unwrap() } lazy_static::lazy_static! { diff --git a/massa-protocol-worker/src/protocol_network.rs b/massa-protocol-worker/src/protocol_network.rs index 2c34e74d402..011a9d68e80 100644 --- a/massa-protocol-worker/src/protocol_network.rs +++ b/massa-protocol-worker/src/protocol_network.rs @@ -10,11 +10,11 @@ use massa_hash::{Hash, HASH_SIZE_BYTES}; use massa_logging::massa_trace; use massa_models::{ block::Block, - block::{BlockId, BlockSerializer, WrappedHeader}, + block::{BlockId, BlockSerializer, SecuredHeader}, node::NodeId, - operation::{OperationId, WrappedOperation}, + operation::{OperationId, SecureShareOperation}, prehash::{CapacityAllocator, PreHashSet}, - wrapped::{Id, Wrapped}, + secure_share::{Id, SecureShare}, }; use massa_network_exports::{AskForBlocksInfo, BlockInfoReply, NetworkEvent}; use massa_protocol_exports::ProtocolError; @@ -171,9 +171,9 @@ impl ProtocolWorker { let mut all_blocks_info = vec![]; for (hash, info_wanted) in &list { let (header, operations_ids) = match self.storage.read_blocks().get(hash) { - Some(wrapped_block) => ( - wrapped_block.content.header.clone(), - wrapped_block.content.operations.clone(), + Some(signed_block) => ( + signed_block.content.header.clone(), + signed_block.content.operations.clone(), ), None => { // let the node know we don't have the block. @@ -238,7 +238,7 @@ impl ProtocolWorker { &mut self, from_node_id: NodeId, block_id: BlockId, - header: WrappedHeader, + header: SecuredHeader, ) -> Result<(), ProtocolError> { if let Some(info) = self.block_wishlist.get(&block_id) { if info.header.is_some() { @@ -410,7 +410,7 @@ impl ProtocolWorker { &mut self, from_node_id: NodeId, block_id: BlockId, - mut operations: Vec, + mut operations: Vec, op_timer: &mut Pin<&mut Sleep>, ) -> Result<(), ProtocolError> { if let Err(err) = self @@ -495,10 +495,10 @@ impl ProtocolWorker { .unwrap(); // wrap block - let wrapped_block = Wrapped { + let signed_block = SecureShare { signature: header.signature, - creator_public_key: header.creator_public_key, - creator_address: header.creator_address, + content_creator_pub_key: header.content_creator_pub_key, + content_creator_address: header.content_creator_address, id: block_id, content: block, serialized_data: content_serialized, @@ -509,11 +509,11 @@ impl ProtocolWorker { // add endorsements to local storage and claim ref // TODO change this if we make endorsements separate from block header block_storage.store_endorsements( - wrapped_block.content.header.content.endorsements.clone(), + signed_block.content.header.content.endorsements.clone(), ); - let slot = wrapped_block.content.header.content.slot; + let slot = signed_block.content.header.content.slot; // add block to local storage and claim ref - block_storage.store_block(wrapped_block); + block_storage.store_block(signed_block); // Send to consensus self.consensus_controller diff --git a/massa-protocol-worker/src/protocol_worker.rs b/massa-protocol-worker/src/protocol_worker.rs index 25b4875fd43..2f3ebcbdc8e 100644 --- a/massa-protocol-worker/src/protocol_worker.rs +++ b/massa-protocol-worker/src/protocol_worker.rs @@ -9,15 +9,15 @@ use massa_consensus_exports::ConsensusController; use massa_logging::massa_trace; use massa_models::operation::Operation; +use massa_models::secure_share::Id; use massa_models::slot::Slot; use massa_models::timeslots::get_block_slot_timestamp; -use massa_models::wrapped::Id; use massa_models::{ - block::{BlockId, WrappedHeader}, - endorsement::{EndorsementId, WrappedEndorsement}, + block::{BlockId, SecuredHeader}, + endorsement::{EndorsementId, SecureShareEndorsement}, node::NodeId, operation::OperationPrefixId, - operation::{OperationId, WrappedOperation}, + operation::{OperationId, SecureShareOperation}, prehash::{CapacityAllocator, PreHashMap, PreHashSet}, }; use massa_network_exports::{AskForBlocksInfo, NetworkCommandSender, NetworkEventReceiver}; @@ -96,7 +96,7 @@ pub async fn start_protocol_controller( #[derive(Debug, Clone)] pub(crate) struct BlockInfo { /// The header of the block. - pub(crate) header: Option, + pub(crate) header: Option, /// Operations ids. None if not received yet pub(crate) operation_ids: Option>, /// Operations and endorsements contained in the block, @@ -107,7 +107,7 @@ pub(crate) struct BlockInfo { } impl BlockInfo { - fn new(header: Option, storage: Storage) -> Self { + fn new(header: Option, storage: Storage) -> Self { BlockInfo { header, operation_ids: None, @@ -145,7 +145,7 @@ pub struct ProtocolWorker { /// Cache of processed operations pub(crate) checked_operations: CheckedOperations, /// List of processed headers - pub(crate) checked_headers: LinearHashCacheMap, + pub(crate) checked_headers: LinearHashCacheMap, /// List of ids of operations that we asked to the nodes pub(crate) asked_operations: PreHashMap)>, /// Buffer for operations that we want later @@ -378,7 +378,7 @@ impl ProtocolWorker { { "endorsements": storage.get_endorsement_refs() } ); for (node, node_info) in self.active_nodes.iter_mut() { - let new_endorsements: PreHashMap = { + let new_endorsements: PreHashMap = { let endorsements_reader = storage.read_endorsements(); storage .get_endorsement_refs() @@ -779,7 +779,7 @@ impl ProtocolWorker { /// - Block matches that of the block. pub(crate) async fn note_header_from_node( &mut self, - header: &WrappedHeader, + header: &SecuredHeader, source_node_id: &NodeId, ) -> Result, ProtocolError> { massa_trace!("protocol.protocol_worker.note_header_from_node", { "node": source_node_id, "header": header }); @@ -894,7 +894,7 @@ impl ProtocolWorker { /// - Valid signature pub(crate) async fn note_operations_from_node( &mut self, - operations: Vec, + operations: Vec, source_node_id: &NodeId, op_timer: &mut Pin<&mut Sleep>, ) -> Result<(), ProtocolError> { @@ -925,7 +925,7 @@ impl ProtocolWorker { verify_sigs_batch( &new_operations .iter() - .map(|(op_id, op)| (*op_id.get_hash(), op.signature, op.creator_public_key)) + .map(|(op_id, op)| (*op_id.get_hash(), op.signature, op.content_creator_pub_key)) .collect::>(), )?; @@ -1001,7 +1001,7 @@ impl ProtocolWorker { /// - Valid signature. pub(crate) async fn note_endorsements_from_node( &mut self, - endorsements: Vec, + endorsements: Vec, source_node_id: &NodeId, propagate: bool, ) -> Result<(), ProtocolError> { @@ -1028,7 +1028,7 @@ impl ProtocolWorker { ( *endorsement_id.get_hash(), endorsement.signature, - endorsement.creator_public_key, + endorsement.content_creator_pub_key, ) }) .collect::>(), diff --git a/massa-protocol-worker/src/tests/ask_block_scenarios.rs b/massa-protocol-worker/src/tests/ask_block_scenarios.rs index cad0469fe5d..d5ce19d7656 100644 --- a/massa-protocol-worker/src/tests/ask_block_scenarios.rs +++ b/massa-protocol-worker/src/tests/ask_block_scenarios.rs @@ -40,7 +40,7 @@ async fn test_full_ask_block_workflow() { let op_1 = tools::create_operation_with_expire_period(&node_a.keypair, 5); let op_2 = tools::create_operation_with_expire_period(&node_a.keypair, 5); let op_thread = op_1 - .creator_address + .content_creator_address .get_thread(protocol_config.thread_count); let block = tools::create_block_with_operations( &node_a.keypair, diff --git a/massa-protocol-worker/src/tests/ban_nodes_scenarios.rs b/massa-protocol-worker/src/tests/ban_nodes_scenarios.rs index 12e5c4a76c2..422794d2acd 100644 --- a/massa-protocol-worker/src/tests/ban_nodes_scenarios.rs +++ b/massa-protocol-worker/src/tests/ban_nodes_scenarios.rs @@ -5,7 +5,7 @@ use massa_consensus_exports::test_exports::MockConsensusControllerMessage; use massa_hash::Hash; use massa_models::operation::OperationId; use massa_models::prehash::PreHashSet; -use massa_models::wrapped::Id; +use massa_models::secure_share::Id; use massa_models::{block::BlockId, slot::Slot}; use massa_network_exports::{BlockInfoReply, NetworkCommand}; use massa_pool_exports::test_exports::MockPoolControllerMessage; diff --git a/massa-protocol-worker/src/tests/in_block_operations_scenarios.rs b/massa-protocol-worker/src/tests/in_block_operations_scenarios.rs index c891c9bbaf1..cd8ee0c31d3 100644 --- a/massa-protocol-worker/src/tests/in_block_operations_scenarios.rs +++ b/massa-protocol-worker/src/tests/in_block_operations_scenarios.rs @@ -4,7 +4,7 @@ use super::tools::{protocol_test, send_and_propagate_block}; use massa_consensus_exports::test_exports::MockConsensusControllerMessage; use massa_hash::Hash; use massa_models::operation::OperationId; -use massa_models::wrapped::{Id, WrappedContent}; +use massa_models::secure_share::{Id, SecureShareContent}; use massa_models::{ address::Address, block::{Block, BlockHeader, BlockHeaderSerializer, BlockSerializer}, @@ -47,7 +47,9 @@ async fn test_protocol_does_propagate_operations_received_in_blocks() { // block with ok operation let op = create_operation_with_expire_period(&keypair, 5); - let op_thread = op.creator_address.get_thread(protocol_config.thread_count); + let op_thread = op + .content_creator_address + .get_thread(protocol_config.thread_count); let block = create_block_with_operations( &creator_node.keypair, @@ -156,7 +158,9 @@ async fn test_protocol_sends_blocks_with_operations_to_consensus() { // block with ok operation { let op = create_operation_with_expire_period(&keypair, 5); - let op_thread = op.creator_address.get_thread(protocol_config.thread_count); + let op_thread = op + .content_creator_address + .get_thread(protocol_config.thread_count); let block = create_block_with_operations( &creator_node.keypair, @@ -208,11 +212,13 @@ async fn test_protocol_sends_blocks_with_operations_to_consensus() { // block with wrong merkle root { let op = create_operation_with_expire_period(&keypair, 5); - let op_thread = op.creator_address.get_thread(protocol_config.thread_count); + let op_thread = op + .content_creator_address + .get_thread(protocol_config.thread_count); let block = { let operation_merkle_root = Hash::compute_from("merkle root".as_bytes()); - let header = BlockHeader::new_wrapped( + let header = BlockHeader::new_verifiable( BlockHeader { slot: Slot::new(1, op_thread), parents: Vec::new(), @@ -224,7 +230,7 @@ async fn test_protocol_sends_blocks_with_operations_to_consensus() { ) .unwrap(); - Block::new_wrapped( + Block::new_verifiable( Block { header, operations: vec![op.clone()].into_iter().map(|op| op.id).collect(), @@ -271,7 +277,9 @@ async fn test_protocol_sends_blocks_with_operations_to_consensus() { // block with operation with wrong signature { let mut op = create_operation_with_expire_period(&keypair, 5); - let op_thread = op.creator_address.get_thread(protocol_config.thread_count); + let op_thread = op + .content_creator_address + .get_thread(protocol_config.thread_count); op.id = OperationId::new(Hash::compute_from("wrong signature".as_bytes())); let block = create_block_with_operations( &creator_node.keypair, diff --git a/massa-protocol-worker/src/tests/operations_scenarios.rs b/massa-protocol-worker/src/tests/operations_scenarios.rs index 3b7f73fa0a7..9de0f56b36c 100644 --- a/massa-protocol-worker/src/tests/operations_scenarios.rs +++ b/massa-protocol-worker/src/tests/operations_scenarios.rs @@ -574,7 +574,7 @@ async fn test_protocol_propagates_operations_only_to_nodes_that_dont_know_about_ let op_1 = tools::create_operation_with_expire_period(&node_a.keypair, 5); let op_2 = tools::create_operation_with_expire_period(&node_a.keypair, 5); let op_thread = op_1 - .creator_address + .content_creator_address .get_thread(protocol_config.thread_count); let mut block = tools::create_block_with_operations( &node_a.keypair, diff --git a/massa-protocol-worker/src/tests/tools.rs b/massa-protocol-worker/src/tests/tools.rs index 3a40123a544..9f56cda4155 100644 --- a/massa-protocol-worker/src/tests/tools.rs +++ b/massa-protocol-worker/src/tests/tools.rs @@ -2,9 +2,9 @@ use crate::start_protocol_controller; use futures::Future; use massa_consensus_exports::test_exports::{ConsensusEventReceiver, MockConsensusController}; use massa_models::{ - block::{BlockId, WrappedBlock}, + block::{BlockId, SecureShareBlock}, node::NodeId, - operation::WrappedOperation, + operation::SecureShareOperation, prehash::PreHashSet, }; use massa_network_exports::BlockInfoReply; @@ -164,10 +164,10 @@ where /// send a block and assert it has been propagate (or not) pub async fn send_and_propagate_block( network_controller: &mut MockNetworkController, - block: WrappedBlock, + block: SecureShareBlock, source_node_id: NodeId, protocol_command_sender: &mut ProtocolCommandSender, - operations: Vec, + operations: Vec, ) { network_controller .send_header(source_node_id, block.content.header.clone()) diff --git a/massa-protocol-worker/src/worker_operations_impl.rs b/massa-protocol-worker/src/worker_operations_impl.rs index 77d551467a4..e9c3dd74c41 100644 --- a/massa-protocol-worker/src/worker_operations_impl.rs +++ b/massa-protocol-worker/src/worker_operations_impl.rs @@ -14,7 +14,7 @@ use crate::protocol_worker::ProtocolWorker; use massa_logging::massa_trace; use massa_models::{ node::NodeId, - operation::{OperationPrefixIds, WrappedOperation}, + operation::{OperationPrefixIds, SecureShareOperation}, prehash::CapacityAllocator, }; use massa_protocol_exports::ProtocolError; @@ -141,7 +141,7 @@ impl ProtocolWorker { pub(crate) async fn on_operations_received( &mut self, node_id: NodeId, - operations: Vec, + operations: Vec, op_timer: &mut Pin<&mut Sleep>, ) { if let Err(err) = self @@ -209,7 +209,7 @@ impl ProtocolWorker { return Ok(()); } - let mut ops: Vec = Vec::with_capacity(op_pre_ids.len()); + let mut ops: Vec = Vec::with_capacity(op_pre_ids.len()); { // Scope the lock because of the async call to `send_operations` below. let stored_ops = self.storage.read_operations(); diff --git a/massa-storage/src/block_indexes.rs b/massa-storage/src/block_indexes.rs index 251cb23fd48..fa3e9c5d381 100644 --- a/massa-storage/src/block_indexes.rs +++ b/massa-storage/src/block_indexes.rs @@ -2,7 +2,7 @@ use std::{collections::hash_map, collections::HashMap}; use massa_models::{ address::Address, - block::{BlockId, WrappedBlock}, + block::{BlockId, SecureShareBlock}, endorsement::EndorsementId, operation::OperationId, prehash::{PreHashMap, PreHashSet}, @@ -14,7 +14,7 @@ use massa_models::{ #[derive(Default)] pub struct BlockIndexes { /// Blocks structure container - blocks: PreHashMap, + blocks: PreHashMap, /// Structure mapping creators with the created blocks index_by_creator: PreHashMap>, /// Structure mapping slot with their block id @@ -29,11 +29,11 @@ impl BlockIndexes { /// Insert a block and populate the indexes. /// Arguments: /// - block: the block to insert - pub(crate) fn insert(&mut self, block: WrappedBlock) { + pub(crate) fn insert(&mut self, block: SecureShareBlock) { if let Ok(b) = self.blocks.try_insert(block.id, block) { // update creator index self.index_by_creator - .entry(b.creator_address) + .entry(b.content_creator_address) .or_default() .insert(b.id); @@ -61,11 +61,11 @@ impl BlockIndexes { /// Remove a block, remove from the indexes and do some clean-up in indexes if necessary. /// Arguments: /// * `block_id`: the block id to remove - pub(crate) fn remove(&mut self, block_id: &BlockId) -> Option { + pub(crate) fn remove(&mut self, block_id: &BlockId) -> Option { if let Some(b) = self.blocks.remove(block_id) { // update creator index if let hash_map::Entry::Occupied(mut occ) = - self.index_by_creator.entry(b.creator_address) + self.index_by_creator.entry(b.content_creator_address) { occ.get_mut().remove(&b.id); if occ.get().is_empty() { @@ -113,7 +113,7 @@ impl BlockIndexes { /// /// Returns: /// - a reference to the block, or None if not found - pub fn get(&self, id: &BlockId) -> Option<&WrappedBlock> { + pub fn get(&self, id: &BlockId) -> Option<&SecureShareBlock> { self.blocks.get(id) } diff --git a/massa-storage/src/endorsement_indexes.rs b/massa-storage/src/endorsement_indexes.rs index f130cf909d2..92d165dd881 100644 --- a/massa-storage/src/endorsement_indexes.rs +++ b/massa-storage/src/endorsement_indexes.rs @@ -2,7 +2,7 @@ use std::collections::hash_map; use massa_models::{ address::Address, - endorsement::{EndorsementId, WrappedEndorsement}, + endorsement::{EndorsementId, SecureShareEndorsement}, prehash::{PreHashMap, PreHashSet}, }; @@ -11,7 +11,7 @@ use massa_models::{ #[derive(Default)] pub struct EndorsementIndexes { /// Endorsements structure container - endorsements: PreHashMap, + endorsements: PreHashMap, /// Structure mapping creators with the created endorsements index_by_creator: PreHashMap>, } @@ -20,11 +20,11 @@ impl EndorsementIndexes { /// Insert an endorsement and populate the indexes. /// Arguments: /// - endorsement: the endorsement to insert - pub(crate) fn insert(&mut self, endorsement: WrappedEndorsement) { + pub(crate) fn insert(&mut self, endorsement: SecureShareEndorsement) { if let Ok(e) = self.endorsements.try_insert(endorsement.id, endorsement) { // update creator index self.index_by_creator - .entry(e.creator_address) + .entry(e.content_creator_address) .or_default() .insert(e.id); } @@ -33,11 +33,14 @@ impl EndorsementIndexes { /// Remove a endorsement, remove from the indexes and made some clean-up in indexes if necessary. /// Arguments: /// * `endorsement_id`: the endorsement id to remove - pub(crate) fn remove(&mut self, endorsement_id: &EndorsementId) -> Option { + pub(crate) fn remove( + &mut self, + endorsement_id: &EndorsementId, + ) -> Option { if let Some(e) = self.endorsements.remove(endorsement_id) { // update creator index if let hash_map::Entry::Occupied(mut occ) = - self.index_by_creator.entry(e.creator_address) + self.index_by_creator.entry(e.content_creator_address) { occ.get_mut().remove(&e.id); if occ.get().is_empty() { @@ -50,7 +53,7 @@ impl EndorsementIndexes { } /// Gets a reference to a stored endorsement, if any. - pub fn get(&self, id: &EndorsementId) -> Option<&WrappedEndorsement> { + pub fn get(&self, id: &EndorsementId) -> Option<&SecureShareEndorsement> { self.endorsements.get(id) } diff --git a/massa-storage/src/lib.rs b/massa-storage/src/lib.rs index a52a2cf6b50..54c39fbed1c 100644 --- a/massa-storage/src/lib.rs +++ b/massa-storage/src/lib.rs @@ -20,11 +20,11 @@ mod tests; use block_indexes::BlockIndexes; use endorsement_indexes::EndorsementIndexes; use massa_models::prehash::{CapacityAllocator, PreHashMap, PreHashSet, PreHashed}; -use massa_models::wrapped::Id; +use massa_models::secure_share::Id; use massa_models::{ - block::{BlockId, WrappedBlock}, - endorsement::{EndorsementId, WrappedEndorsement}, - operation::{OperationId, WrappedOperation}, + block::{BlockId, SecureShareBlock}, + endorsement::{EndorsementId, SecureShareEndorsement}, + operation::{OperationId, SecureShareOperation}, }; use operation_indexes::OperationIndexes; use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; @@ -278,7 +278,7 @@ impl Storage { /// Store a block /// Note that this also claims a local reference to the block - pub fn store_block(&mut self, block: WrappedBlock) { + pub fn store_block(&mut self, block: SecureShareBlock) { let id = block.id; let mut owners = self.block_owners.write(); let mut blocks = self.blocks.write(); @@ -362,7 +362,7 @@ impl Storage { /// Store operations /// Claims a local reference to the added operation - pub fn store_operations(&mut self, operations: Vec) { + pub fn store_operations(&mut self, operations: Vec) { if operations.is_empty() { return; } @@ -460,7 +460,7 @@ impl Storage { /// Store endorsements /// Claims local references to the added endorsements - pub fn store_endorsements(&mut self, endorsements: Vec) { + pub fn store_endorsements(&mut self, endorsements: Vec) { if endorsements.is_empty() { return; } diff --git a/massa-storage/src/operation_indexes.rs b/massa-storage/src/operation_indexes.rs index 3fa4f1e3d02..30c42211840 100644 --- a/massa-storage/src/operation_indexes.rs +++ b/massa-storage/src/operation_indexes.rs @@ -2,7 +2,7 @@ use std::collections::hash_map; use massa_models::{ address::Address, - operation::{OperationId, OperationPrefixId, WrappedOperation}, + operation::{OperationId, OperationPrefixId, SecureShareOperation}, prehash::{PreHashMap, PreHashSet}, }; @@ -11,7 +11,7 @@ use massa_models::{ #[derive(Default)] pub struct OperationIndexes { /// Operations structure container - operations: PreHashMap, + operations: PreHashMap, /// Structure mapping creators with the created operations index_by_creator: PreHashMap>, /// Structure indexing operations by ID prefix @@ -22,11 +22,11 @@ impl OperationIndexes { /// Insert an operation and populate the indexes. /// Arguments: /// * `operation`: the operation to insert - pub(crate) fn insert(&mut self, operation: WrappedOperation) { + pub(crate) fn insert(&mut self, operation: SecureShareOperation) { if let Ok(o) = self.operations.try_insert(operation.id, operation) { // update creator index self.index_by_creator - .entry(o.creator_address) + .entry(o.content_creator_address) .or_default() .insert(o.id); // update prefix index @@ -40,11 +40,11 @@ impl OperationIndexes { /// Remove a operation, remove from the indexes and made some clean-up in indexes if necessary. /// Arguments: /// * `operation_id`: the operation id to remove - pub(crate) fn remove(&mut self, operation_id: &OperationId) -> Option { + pub(crate) fn remove(&mut self, operation_id: &OperationId) -> Option { if let Some(o) = self.operations.remove(operation_id) { // update creator index if let hash_map::Entry::Occupied(mut occ) = - self.index_by_creator.entry(o.creator_address) + self.index_by_creator.entry(o.content_creator_address) { occ.get_mut().remove(&o.id); if occ.get().is_empty() { @@ -64,7 +64,7 @@ impl OperationIndexes { } /// Gets a reference to a stored operation, if any. - pub fn get(&self, id: &OperationId) -> Option<&WrappedOperation> { + pub fn get(&self, id: &OperationId) -> Option<&SecureShareOperation> { self.operations.get(id) } diff --git a/massa-wallet/src/lib.rs b/massa-wallet/src/lib.rs index e27a7a2b5a0..5a84c05c8fe 100644 --- a/massa-wallet/src/lib.rs +++ b/massa-wallet/src/lib.rs @@ -11,9 +11,9 @@ use massa_cipher::{decrypt, encrypt}; use massa_hash::Hash; use massa_models::address::Address; use massa_models::composite::PubkeySig; -use massa_models::operation::{Operation, OperationSerializer, WrappedOperation}; +use massa_models::operation::{Operation, OperationSerializer, SecureShareOperation}; use massa_models::prehash::{PreHashMap, PreHashSet}; -use massa_models::wrapped::WrappedContent; +use massa_models::secure_share::SecureShareContent; use massa_signature::{KeyPair, PublicKey}; use serde::{Deserialize, Serialize}; use std::path::PathBuf; @@ -142,11 +142,11 @@ impl Wallet { &self, content: Operation, address: Address, - ) -> Result { + ) -> Result { let sender_keypair = self .find_associated_keypair(&address) .ok_or_else(|| WalletError::MissingKeyError(address))?; - Ok(Operation::new_wrapped(content, OperationSerializer::new(), sender_keypair).unwrap()) + Ok(Operation::new_verifiable(content, OperationSerializer::new(), sender_keypair).unwrap()) } } From 436cbf42d6c218af9807baee1a03ab6166dfd568 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Jan 2023 13:12:34 +0100 Subject: [PATCH 11/80] Bump tokio from 1.23.0 to 1.23.1 (#3385) * fix: missing operation in OpenRPC * Bump tokio from 1.23.0 to 1.23.1 Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.23.0 to 1.23.1. - [Release notes](https://github.com/tokio-rs/tokio/releases) - [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.23.0...tokio-1.23.1) --- updated-dependencies: - dependency-name: tokio dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- massa-api/Cargo.toml | 2 +- massa-bootstrap/Cargo.toml | 2 +- massa-client/Cargo.toml | 2 +- massa-consensus-exports/Cargo.toml | 2 +- massa-network-exports/Cargo.toml | 2 +- massa-network-worker/Cargo.toml | 2 +- massa-node/Cargo.toml | 2 +- massa-node/base_config/openrpc.json | 33 +++++++++++++++++++++++++++++ massa-pos-exports/Cargo.toml | 2 +- massa-protocol-exports/Cargo.toml | 2 +- massa-protocol-worker/Cargo.toml | 2 +- 12 files changed, 45 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd3e22a226a..d737c21c345 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4490,9 +4490,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.23.0" +version = "1.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" +checksum = "38a54aca0c15d014013256222ba0ebed095673f89345dd79119d912eb561b7a8" dependencies = [ "autocfg", "bytes", diff --git a/massa-api/Cargo.toml b/massa-api/Cargo.toml index 0a5190689fc..9312a478fd3 100644 --- a/massa-api/Cargo.toml +++ b/massa-api/Cargo.toml @@ -15,7 +15,7 @@ tower-http = { version = "0.3.4", features = ["full"] } tower = { version = "0.4.13", features = ["full"] } hyper = "0.14.20" thiserror = "1.0" -tokio = { version = "1.21", features = ["full"] } +tokio = { version = "1.23", features = ["full"] } tokio-stream = { version = "0.1", features = ["sync"] } tracing = "0.1" itertools = "0.10" diff --git a/massa-bootstrap/Cargo.toml b/massa-bootstrap/Cargo.toml index 4ebf71d2d0a..cb84c47e750 100644 --- a/massa-bootstrap/Cargo.toml +++ b/massa-bootstrap/Cargo.toml @@ -21,7 +21,7 @@ serde_json = "1.0" humantime = "2.1.0" thiserror = "1.0" parking_lot = { version = "0.12", features = ["deadlock_detection"] } -tokio = { version = "1.21", features = ["full"] } +tokio = { version = "1.23", features = ["full"] } tracing = "0.1" # custom modules diff --git a/massa-client/Cargo.toml b/massa-client/Cargo.toml index 7e389fc1317..3591fe60dcb 100644 --- a/massa-client/Cargo.toml +++ b/massa-client/Cargo.toml @@ -20,7 +20,7 @@ serde_json = "1.0" structopt = { version = "0.3", features = ["paw"] } strum = "0.24" strum_macros = "0.24" -tokio = { version = "1.21", features = ["full"] } +tokio = { version = "1.23", features = ["full"] } # custom modules massa_models = { path = "../massa-models" } massa_signature = { path = "../massa-signature" } diff --git a/massa-consensus-exports/Cargo.toml b/massa-consensus-exports/Cargo.toml index d37d46383cd..3996748a415 100644 --- a/massa-consensus-exports/Cargo.toml +++ b/massa-consensus-exports/Cargo.toml @@ -14,7 +14,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" jsonrpsee = { version = "0.16.2", features = ["server"] } -tokio = { version = "1.21", features = ["sync"] } +tokio = { version = "1.23", features = ["sync"] } #custom modules massa_hash = { path = "../massa-hash"} massa_execution_exports = { path = "../massa-execution-exports" } diff --git a/massa-network-exports/Cargo.toml b/massa-network-exports/Cargo.toml index 9009a3a1eb1..5b597f24253 100644 --- a/massa-network-exports/Cargo.toml +++ b/massa-network-exports/Cargo.toml @@ -10,7 +10,7 @@ displaydoc = "0.2" nom = "7.1" serde = { version = "1.0", features = ["derive"] } thiserror = "1.0" -tokio = { version = "1.21", features = ["full"] } +tokio = { version = "1.23", features = ["full"] } enum-map = { version = "2.4", features = ["serde"] } # custom modules massa_hash = { path = "../massa-hash" } diff --git a/massa-network-worker/Cargo.toml b/massa-network-worker/Cargo.toml index 617c744a724..836bf749293 100644 --- a/massa-network-worker/Cargo.toml +++ b/massa-network-worker/Cargo.toml @@ -15,7 +15,7 @@ nom = "7.1" rand = "0.8" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -tokio = { version = "1.21", features = ["full"] } +tokio = { version = "1.23", features = ["full"] } tracing = "0.1" # custom modules massa_hash = { path = "../massa-hash" } diff --git a/massa-node/Cargo.toml b/massa-node/Cargo.toml index 06f063d07bf..4f37ab7f7c9 100644 --- a/massa-node/Cargo.toml +++ b/massa-node/Cargo.toml @@ -14,7 +14,7 @@ lazy_static = "1.4" parking_lot = { version = "0.12", features = ["deadlock_detection"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -tokio = { version = "1.21", features = ["full"] } +tokio = { version = "1.23", features = ["full"] } tracing = { version = "0.1", features = [ "max_level_debug", "release_max_level_debug", diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index aa9b57b730f..a7e24025fe3 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -2393,6 +2393,31 @@ }, "additionalProperties": false }, + "Operation": { + "title": "Operation", + "description": "Operation", + "required": [ + "fee", + "expire_period", + "op" + ], + "type": "object", + "properties": { + "fee": { + "description": "the fee they have decided for this operation", + "type": "string" + }, + "expire_period": { + "description": "after `expire_period` slot the operation won't be included in a block", + "type": "number" + }, + "op": { + "$ref": "#/components/schemas/OperationType", + "description": "the type specific operation part" + } + }, + "additionalProperties": false + }, "OperationId": { "description": "Operation id", "type": "string" @@ -2973,6 +2998,14 @@ "$ref": "#/components/schemas/NodeStatus" } }, + "Operation": { + "name": "Operation", + "summary": "Operation", + "description": "A Operation object", + "schema": { + "$ref": "#/components/schemas/Operation" + } + }, "OperationId": { "name": "OperationId", "summary": "OperationId", diff --git a/massa-pos-exports/Cargo.toml b/massa-pos-exports/Cargo.toml index 78bb3be0f37..47e582ebdfa 100644 --- a/massa-pos-exports/Cargo.toml +++ b/massa-pos-exports/Cargo.toml @@ -13,7 +13,7 @@ nom = "7.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" -tokio = { version = "1.21", features = ["full"] } +tokio = { version = "1.23", features = ["full"] } tracing = "0.1" anyhow = "1.0" num = { version = "0.4", features = ["serde"] } diff --git a/massa-protocol-exports/Cargo.toml b/massa-protocol-exports/Cargo.toml index 2f9d48039a5..4f26346abc9 100644 --- a/massa-protocol-exports/Cargo.toml +++ b/massa-protocol-exports/Cargo.toml @@ -12,7 +12,7 @@ lazy_static = "1.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" -tokio = { version = "1.21", features = ["full"] } +tokio = { version = "1.23", features = ["full"] } tracing = "0.1" futures = {version = "0.3", optional = true } diff --git a/massa-protocol-worker/Cargo.toml b/massa-protocol-worker/Cargo.toml index 7d600ba7791..f81e8c3cb51 100644 --- a/massa-protocol-worker/Cargo.toml +++ b/massa-protocol-worker/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] serde_json = "1.0" -tokio = { version = "1.21", features = ["full"] } +tokio = { version = "1.23", features = ["full"] } tracing = "0.1" rayon = "1.5" # custom modules From a19786a5a08c072dedeb0049393fb0d88efcefa6 Mon Sep 17 00:00:00 2001 From: AurelienFT <32803821+AurelienFT@users.noreply.github.com> Date: Mon, 9 Jan 2023 15:09:49 +0100 Subject: [PATCH 12/80] Update bootstrap pubkeys to be nodeid. (#3389) * Update bootstrap keys to be nodeid. * Fix type incompatibility * Fix compile tests. --- Cargo.lock | 1 - massa-bootstrap/src/client.rs | 11 +++++++++-- massa-bootstrap/src/settings.rs | 4 ++-- massa-bootstrap/src/tests/binders.rs | 21 ++++++++++++++------- massa-bootstrap/src/tests/scenarios.rs | 6 ++++-- massa-bootstrap/src/tests/tools.rs | 3 ++- massa-node/Cargo.toml | 1 - massa-node/base_config/config.toml | 16 ++++++++-------- massa-node/src/settings.rs | 5 ++--- 9 files changed, 41 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d737c21c345..0babbb82eb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2216,7 +2216,6 @@ dependencies = [ "massa_pos_worker", "massa_protocol_exports", "massa_protocol_worker", - "massa_signature", "massa_storage", "massa_time", "massa_wallet", diff --git a/massa-bootstrap/src/client.rs b/massa-bootstrap/src/client.rs index 1768b67b0d2..1573666d5ca 100644 --- a/massa-bootstrap/src/client.rs +++ b/massa-bootstrap/src/client.rs @@ -458,14 +458,21 @@ pub async fn get_state( }; let mut global_bootstrap_state = GlobalBootstrapState::new(final_state.clone()); loop { - for (addr, pub_key) in shuffled_list.iter() { + for (addr, node_id) in shuffled_list.iter() { if let Some(end) = end_timestamp { if MassaTime::now().expect("could not get now time") > end { panic!("This episode has come to an end, please get the latest testnet node version to continue"); } } info!("Start bootstrapping from {}", addr); - match connect_to_server(&mut establisher, bootstrap_config, addr, pub_key).await { + match connect_to_server( + &mut establisher, + bootstrap_config, + addr, + &node_id.get_public_key(), + ) + .await + { Ok(mut client) => { match bootstrap_from_server(bootstrap_config, &mut client, &mut next_bootstrap_message, &mut global_bootstrap_state,version) .await // cancellable diff --git a/massa-bootstrap/src/settings.rs b/massa-bootstrap/src/settings.rs index 5024b5697d3..c6a0398ed99 100644 --- a/massa-bootstrap/src/settings.rs +++ b/massa-bootstrap/src/settings.rs @@ -1,6 +1,6 @@ // Copyright (c) 2022 MASSA LABS -use massa_signature::PublicKey; +use massa_models::node::NodeId; use massa_time::MassaTime; use serde::Deserialize; use std::{net::SocketAddr, path::PathBuf}; @@ -9,7 +9,7 @@ use std::{net::SocketAddr, path::PathBuf}; #[derive(Debug, Deserialize, Clone)] pub struct BootstrapConfig { /// Ip address of our bootstrap nodes and their public key. - pub bootstrap_list: Vec<(SocketAddr, PublicKey)>, + pub bootstrap_list: Vec<(SocketAddr, NodeId)>, /// Path to the bootstrap whitelist file. This whitelist define IPs that can bootstrap on your node. pub bootstrap_whitelist_path: PathBuf, /// Path to the bootstrap blacklist file. This whitelist define IPs that will not be able to bootstrap on your node. This list is optional. diff --git a/massa-bootstrap/src/tests/binders.rs b/massa-bootstrap/src/tests/binders.rs index 4e9eb610f1e..520b070695b 100644 --- a/massa-bootstrap/src/tests/binders.rs +++ b/massa-bootstrap/src/tests/binders.rs @@ -16,6 +16,7 @@ use massa_models::config::{ MAX_EXECUTED_OPS_CHANGES_LENGTH, MAX_EXECUTED_OPS_LENGTH, MAX_LEDGER_CHANGES_COUNT, MAX_OPERATIONS_PER_BLOCK, MAX_PRODUCTION_STATS_LENGTH, MAX_ROLLS_COUNT_LENGTH, THREAD_COUNT, }; +use massa_models::node::NodeId; use massa_models::version::Version; use massa_signature::{KeyPair, PublicKey}; use serial_test::serial; @@ -24,7 +25,7 @@ use tokio::io::duplex; lazy_static::lazy_static! { pub static ref BOOTSTRAP_CONFIG_KEYPAIR: (BootstrapConfig, KeyPair) = { let keypair = KeyPair::generate(); - (get_bootstrap_config(keypair.get_public_key()), keypair) + (get_bootstrap_config(NodeId::new(keypair.get_public_key())), keypair) }; } @@ -76,8 +77,10 @@ async fn test_binders() { BOOTSTRAP_RANDOMNESS_SIZE_BYTES, CONSENSUS_BOOTSTRAP_PART_SIZE, ); - let mut client = - BootstrapClientBinder::test_default(client, bootstrap_config.bootstrap_list[0].1); + let mut client = BootstrapClientBinder::test_default( + client, + bootstrap_config.bootstrap_list[0].1.get_public_key(), + ); let server_thread = tokio::spawn(async move { // Test message 1 @@ -170,8 +173,10 @@ async fn test_binders_double_send_server_works() { BOOTSTRAP_RANDOMNESS_SIZE_BYTES, CONSENSUS_BOOTSTRAP_PART_SIZE, ); - let mut client = - BootstrapClientBinder::test_default(client, bootstrap_config.bootstrap_list[0].1); + let mut client = BootstrapClientBinder::test_default( + client, + bootstrap_config.bootstrap_list[0].1.get_public_key(), + ); let server_thread = tokio::spawn(async move { // Test message 1 @@ -249,8 +254,10 @@ async fn test_binders_try_double_send_client_works() { BOOTSTRAP_RANDOMNESS_SIZE_BYTES, CONSENSUS_BOOTSTRAP_PART_SIZE, ); - let mut client = - BootstrapClientBinder::test_default(client, bootstrap_config.bootstrap_list[0].1); + let mut client = BootstrapClientBinder::test_default( + client, + bootstrap_config.bootstrap_list[0].1.get_public_key(), + ); let server_thread = tokio::spawn(async move { // Test message 1 diff --git a/massa-bootstrap/src/tests/scenarios.rs b/massa-bootstrap/src/tests/scenarios.rs index 69555aa173b..6c8a6953656 100644 --- a/massa-bootstrap/src/tests/scenarios.rs +++ b/massa-bootstrap/src/tests/scenarios.rs @@ -27,7 +27,9 @@ use massa_final_state::{ }; use massa_hash::{Hash, HASH_SIZE_BYTES}; use massa_ledger_exports::LedgerConfig; -use massa_models::{address::Address, slot::Slot, streaming_step::StreamingStep, version::Version}; +use massa_models::{ + address::Address, node::NodeId, slot::Slot, streaming_step::StreamingStep, version::Version, +}; use massa_models::{ config::{ MAX_ASYNC_MESSAGE_DATA, MAX_ASYNC_POOL_LENGTH, MAX_DATASTORE_KEY_LENGTH, POS_SAVED_CYCLES, @@ -50,7 +52,7 @@ use tokio::sync::mpsc; lazy_static::lazy_static! { pub static ref BOOTSTRAP_CONFIG_KEYPAIR: (BootstrapConfig, KeyPair) = { let keypair = KeyPair::generate(); - (get_bootstrap_config(keypair.get_public_key()), keypair) + (get_bootstrap_config(NodeId::new(keypair.get_public_key())), keypair) }; } diff --git a/massa-bootstrap/src/tests/tools.rs b/massa-bootstrap/src/tests/tools.rs index 1681441bb6f..571c3a98ded 100644 --- a/massa-bootstrap/src/tests/tools.rs +++ b/massa-bootstrap/src/tests/tools.rs @@ -28,6 +28,7 @@ use massa_models::config::{ MAX_OPERATION_DATASTORE_KEY_LENGTH, MAX_OPERATION_DATASTORE_VALUE_LENGTH, MAX_PARAMETERS_SIZE, MAX_PRODUCTION_STATS_LENGTH, MAX_ROLLS_COUNT_LENGTH, PERIODS_PER_CYCLE, THREAD_COUNT, }; +use massa_models::node::NodeId; use massa_models::{ address::Address, amount::Amount, @@ -272,7 +273,7 @@ pub fn get_dummy_signature(s: &str) -> Signature { priv_key.sign(&Hash::compute_from(s.as_bytes())).unwrap() } -pub fn get_bootstrap_config(bootstrap_public_key: PublicKey) -> BootstrapConfig { +pub fn get_bootstrap_config(bootstrap_public_key: NodeId) -> BootstrapConfig { BootstrapConfig { bind: Some("0.0.0.0:31244".parse().unwrap()), connect_timeout: 200.into(), diff --git a/massa-node/Cargo.toml b/massa-node/Cargo.toml index 4f37ab7f7c9..12dff740ac8 100644 --- a/massa-node/Cargo.toml +++ b/massa-node/Cargo.toml @@ -32,7 +32,6 @@ massa_consensus_worker = { path = "../massa-consensus-worker" } massa_executed_ops = { path = "../massa-executed-ops" } massa_execution_exports = { path = "../massa-execution-exports" } massa_execution_worker = { path = "../massa-execution-worker" } -massa_signature = { path = "../massa-signature" } massa_logging = { path = "../massa-logging" } massa_final_state = { path = "../massa-final-state" } massa_ledger_exports = { path = "../massa-ledger-exports" } diff --git a/massa-node/base_config/config.toml b/massa-node/base_config/config.toml index a0225ed2ce6..7a633fc5254 100644 --- a/massa-node/base_config/config.toml +++ b/massa-node/base_config/config.toml @@ -197,14 +197,14 @@ [bootstrap] # list of bootstrap (ip, node id) bootstrap_list = [ - ["149.202.86.103:31245", "P12UbyLJDS7zimGWf3LTHe8hYY67RdLke1iDRZqJbQQLHQSKPW8j"], - ["149.202.89.125:31245", "P12vxrYTQzS5TRzxLfFNYxn6PyEsphKWkdqx2mVfEuvJ9sPF43uq"], - ["158.69.120.215:31245", "P12rPDBmpnpnbECeAKDjbmeR19dYjAUwyLzsa8wmYJnkXLCNF28E"], - ["158.69.23.120:31245", "P1XxexKa3XNzvmakNmPawqFrE9Z2NFhfq1AhvV1Qx4zXq5p1Bp9"], - ["198.27.74.5:31245", "P1qxuqNnx9kyAMYxUfsYiv2gQd5viiBX126SzzexEdbbWd2vQKu"], - ["198.27.74.52:31245", "P1hdgsVsd4zkNp8cF1rdqqG6JPRQasAmx12QgJaJHBHFU1fRHEH"], - ["54.36.174.177:31245", "P1gEdBVEbRFbBxBtrjcTDDK9JPbJFDay27uiJRE3vmbFAFDKNh7"], - ["51.75.60.228:31245", "P13Ykon8Zo73PTKMruLViMMtE2rEG646JQ4sCcee2DnopmVM3P5"] + ["149.202.86.103:31245", "N12UbyLJDS7zimGWf3LTHe8hYY67RdLke1iDRZqJbQQLHQSKPW8j"], + ["149.202.89.125:31245", "N12vxrYTQzS5TRzxLfFNYxn6PyEsphKWkdqx2mVfEuvJ9sPF43uq"], + ["158.69.120.215:31245", "N12rPDBmpnpnbECeAKDjbmeR19dYjAUwyLzsa8wmYJnkXLCNF28E"], + ["158.69.23.120:31245", "N1XxexKa3XNzvmakNmPawqFrE9Z2NFhfq1AhvV1Qx4zXq5p1Bp9"], + ["198.27.74.5:31245", "N1qxuqNnx9kyAMYxUfsYiv2gQd5viiBX126SzzexEdbbWd2vQKu"], + ["198.27.74.52:31245", "N1hdgsVsd4zkNp8cF1rdqqG6JPRQasAmx12QgJaJHBHFU1fRHEH"], + ["54.36.174.177:31245", "N1gEdBVEbRFbBxBtrjcTDDK9JPbJFDay27uiJRE3vmbFAFDKNh7"], + ["51.75.60.228:31245", "N13Ykon8Zo73PTKMruLViMMtE2rEG646JQ4sCcee2DnopmVM3P5"] ] # path to the bootstrap whitelist file. This whitelist define IPs that can bootstrap on your node. bootstrap_whitelist_path = "base_config/bootstrap_whitelist.json" diff --git a/massa-node/src/settings.rs b/massa-node/src/settings.rs index 3511d2c7bf6..7185157df26 100644 --- a/massa-node/src/settings.rs +++ b/massa-node/src/settings.rs @@ -4,8 +4,7 @@ use std::path::PathBuf; use enum_map::EnumMap; -use massa_models::config::build_massa_settings; -use massa_signature::PublicKey; +use massa_models::{config::build_massa_settings, node::NodeId}; use massa_time::MassaTime; use serde::Deserialize; use std::net::{IpAddr, SocketAddr}; @@ -75,7 +74,7 @@ pub struct NetworkSettings { /// Bootstrap configuration. #[derive(Debug, Deserialize, Clone)] pub struct BootstrapSettings { - pub bootstrap_list: Vec<(SocketAddr, PublicKey)>, + pub bootstrap_list: Vec<(SocketAddr, NodeId)>, pub bootstrap_whitelist_path: PathBuf, pub bootstrap_blacklist_path: PathBuf, pub bind: Option, From c0d61fbcaf29e54fd8c540599d40f10dda875665 Mon Sep 17 00:00:00 2001 From: AurelienFT <32803821+AurelienFT@users.noreply.github.com> Date: Mon, 9 Jan 2023 15:12:17 +0100 Subject: [PATCH 13/80] Fix roll sell. (#3392) --- massa-execution-worker/src/context.rs | 6 +++--- .../src/tests/scenarios_mandatories.rs | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/massa-execution-worker/src/context.rs b/massa-execution-worker/src/context.rs index 2a39831ff2c..8b88ad2a14e 100644 --- a/massa-execution-worker/src/context.rs +++ b/massa-execution-worker/src/context.rs @@ -686,6 +686,9 @@ impl ExecutionContext { pub fn settle_slot(&mut self) -> ExecutionOutput { let slot = self.slot; + // execute the deferred credits coming from roll sells + self.execute_deferred_credits(&slot); + // settle emitted async messages and reimburse the senders of deleted messages let ledger_changes = self.speculative_ledger.take(); let deleted_messages = self @@ -695,9 +698,6 @@ impl ExecutionContext { self.cancel_async_message(&msg); } - // execute the deferred credits coming from roll sells - self.execute_deferred_credits(&slot); - // if the current slot is last in cycle check the production stats and act accordingly if self .slot diff --git a/massa-execution-worker/src/tests/scenarios_mandatories.rs b/massa-execution-worker/src/tests/scenarios_mandatories.rs index 8d58fbc7ac8..618fea40788 100644 --- a/massa-execution-worker/src/tests/scenarios_mandatories.rs +++ b/massa-execution-worker/src/tests/scenarios_mandatories.rs @@ -834,6 +834,9 @@ pub fn roll_sell() { let keypair = KeyPair::from_str("S1JJeHiZv1C1zZN5GLFcbz6EXYiccmUPLkYuDFA3kayjxP39kFQ").unwrap(); let address = Address::from_public_key(&keypair.get_public_key()); + // get initial balance + let balance_initial = sample_state.read().ledger.get_balance(&address).unwrap(); + // get initial roll count let roll_count_initial = sample_state.read().pos_state.get_rolls_for(&address); let roll_sell_1 = 10; @@ -915,6 +918,20 @@ pub fn roll_sell() { credits ); + // Now check balance + let balances = controller.get_final_and_candidate_balance(&[address]); + let candidate_balance = balances.get(0).unwrap().1.unwrap(); + + assert_eq!( + candidate_balance, + exec_cfg + .roll_price + .checked_mul_u64(roll_sell_1 + roll_sell_2) + .unwrap() + .checked_add(balance_initial) + .unwrap() + ); + // stop the execution controller manager.stop(); } From bb031fa509b8e0b639fc9c1527438c0c6d145259 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Mon, 9 Jan 2023 18:26:46 +0100 Subject: [PATCH 14/80] use runtime module separation to impl module caching in massa-execution --- Cargo.lock | 2 +- massa-execution-exports/Cargo.toml | 2 +- massa-execution-worker/Cargo.toml | 3 +- massa-execution-worker/src/execution.rs | 89 ++++++++++++++++++------- massa-execution-worker/src/worker.rs | 2 +- 5 files changed, 70 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0babbb82eb5..30330dd0357 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2232,7 +2232,6 @@ dependencies = [ [[package]] name = "massa-sc-runtime" version = "0.10.0" -source = "git+https://github.com/massalabs/massa-sc-runtime#04082b4986753160f9c3a075daf9f6f772d73c29" dependencies = [ "anyhow", "as-ffi-bindings", @@ -2464,6 +2463,7 @@ dependencies = [ "serial_test 0.10.0", "tempfile", "tracing", + "wasmer", ] [[package]] diff --git a/massa-execution-exports/Cargo.toml b/massa-execution-exports/Cargo.toml index 7086b5e7988..cb1c38025aa 100644 --- a/massa-execution-exports/Cargo.toml +++ b/massa-execution-exports/Cargo.toml @@ -18,7 +18,7 @@ massa_storage = { path = "../massa-storage" } massa_final_state = { path = "../massa-final-state" } massa_ledger_exports = { path = "../massa-ledger-exports", optional = true } parking_lot = { version = "0.12", features = ["deadlock_detection"], optional = true } -massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime" } +massa-sc-runtime = { path = "../../massa-sc-runtime" } # for more information on what are the following features used for, see the cargo.toml at workspace level [features] diff --git a/massa-execution-worker/Cargo.toml b/massa-execution-worker/Cargo.toml index 6d403163f69..def3ac0fe13 100644 --- a/massa-execution-worker/Cargo.toml +++ b/massa-execution-worker/Cargo.toml @@ -16,6 +16,7 @@ tracing = "0.1" serde_json = "1.0" num = { version = "0.4", features = ["serde"] } tempfile = { version = "3.3", optional = true } # use with gas_calibration feature +wasmer = { version = "3.0" } # custom modules massa_async_pool = { path = "../massa-async-pool" } massa_executed_ops = { path = "../massa-executed-ops" } @@ -23,7 +24,7 @@ massa_execution_exports = { path = "../massa-execution-exports" } massa_models = { path = "../massa-models" } massa_storage = { path = "../massa-storage" } massa_hash = { path = "../massa-hash" } -massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime" } +massa-sc-runtime = { path = "../../massa-sc-runtime" } massa_signature = { path = "../massa-signature" } massa_time = { path = "../massa-time" } massa_ledger_worker = { path = "../massa-ledger-worker", optional = true } diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 31351111ca1..8a8e347d288 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -18,11 +18,12 @@ use massa_execution_exports::{ ReadOnlyExecutionOutput, ReadOnlyExecutionRequest, ReadOnlyExecutionTarget, }; use massa_final_state::FinalState; +use massa_hash::Hash; use massa_ledger_exports::{SetOrDelete, SetUpdateOrDelete}; use massa_models::address::ExecutionAddressCycleInfo; use massa_models::api::EventFilter; use massa_models::output_event::SCOutputEvent; -use massa_models::prehash::PreHashSet; +use massa_models::prehash::{PreHashMap, PreHashSet}; use massa_models::stats::ExecutionStats; use massa_models::{ address::Address, @@ -31,12 +32,13 @@ use massa_models::{ }; use massa_models::{amount::Amount, slot::Slot}; use massa_pos_exports::SelectorController; -use massa_sc_runtime::Interface; +use massa_sc_runtime::{init_engine, Interface}; use massa_storage::Storage; use parking_lot::{Mutex, RwLock}; use std::collections::{BTreeMap, BTreeSet}; use std::sync::Arc; use tracing::{debug, info, warn}; +use wasmer::{Engine, Module}; /// Used to acquire a lock on the execution context macro_rules! context_guard { @@ -70,6 +72,8 @@ pub(crate) struct ExecutionState { execution_interface: Box, // execution statistics stats_counter: ExecutionStatsCounter, + // TODO + sc_cache: PreHashMap, } impl ExecutionState { @@ -116,9 +120,29 @@ impl ExecutionState { final_cursor: last_final_slot, stats_counter: ExecutionStatsCounter::new(config.stats_time_window_duration), config, + sc_cache: PreHashMap::default(), } } + /// Internal function that creates the engine and retrieves the bytcode for a runtime call + fn init_runtime_execution( + &mut self, + bytecode: &[u8], + max_gas: u64, + ) -> Result<(Engine, Module), ExecutionError> { + // IMPORTANT TODO: update error type to handle this + let engine = init_engine(self.config.gas_costs.clone(), max_gas).unwrap(); + let key = Hash::compute_from(bytecode); + let binary_module = if let Some(module) = self.sc_cache.get(&key) { + module.clone() + } else { + let module = Module::new(&engine, bytecode).unwrap(); + self.sc_cache.insert(key, module.clone()); + module + }; + Ok((engine, binary_module)) + } + /// Get execution statistics pub fn get_stats(&self) -> ExecutionStats { self.stats_counter.get_stats(self.active_cursor) @@ -191,7 +215,7 @@ impl ExecutionState { /// * `remaining_block_gas`: mutable reference towards the remaining gas in the block /// * `block_credits`: mutable reference towards the total block reward/fee credits pub fn execute_operation( - &self, + &mut self, operation: &SecureShareOperation, block_slot: Slot, remaining_block_gas: &mut u64, @@ -471,7 +495,7 @@ impl ExecutionState { /// * `operation`: the `WrappedOperation` to process, must be an `ExecuteSC` /// * `sender_addr`: address of the sender pub fn execute_executesc_op( - &self, + &mut self, operation: &OperationType, sender_addr: Address, ) -> Result<(), ExecutionError> { @@ -502,11 +526,14 @@ impl ExecutionState { }]; }; + // init runtime engine and retrieve the binary module + let (engine, binary_module) = self.init_runtime_execution(bytecode, *max_gas)?; + // run the VM on the bytecode contained in the operation match massa_sc_runtime::run_main( - bytecode, - *max_gas, &*self.execution_interface, + &engine, + binary_module, self.config.gas_costs.clone(), ) { Ok(_response) => {} @@ -531,7 +558,7 @@ impl ExecutionState { /// * `operation_id`: ID of the operation /// * `sender_addr`: address of the sender pub fn execute_callsc_op( - &self, + &mut self, operation: &OperationType, sender_addr: Address, ) -> Result<(), ExecutionError> { @@ -596,13 +623,16 @@ impl ExecutionState { bytecode = context.get_bytecode(&target_addr).unwrap_or_default(); } - // run the VM on the bytecode loaded from the target address + // init runtime engine and retrieve the binary module + let (engine, binary_module) = self.init_runtime_execution(&bytecode, max_gas)?; + + // run the VM on the bytecode contained in the operation match massa_sc_runtime::run_function( - &bytecode, - max_gas, - target_func, - param, &*self.execution_interface, + &engine, + binary_module, + &target_func, + ¶m, self.config.gas_costs.clone(), ) { Ok(_response) => {} @@ -625,7 +655,7 @@ impl ExecutionState { /// * message: message information /// * bytecode: executable target bytecode, or None if unavailable pub fn execute_async_message( - &self, + &mut self, message: AsyncMessage, bytecode: Option>, ) -> Result<(), ExecutionError> { @@ -686,13 +716,16 @@ impl ExecutionState { bytecode }; - // run the target function + // init runtime engine and retrieve the binary module + let (engine, binary_module) = self.init_runtime_execution(&bytecode, message.max_gas)?; + + // run the VM on the bytecode contained in the operation if let Err(err) = massa_sc_runtime::run_function( - &bytecode, - message.max_gas, + &*self.execution_interface, + &engine, + binary_module, &message.handler, &message.data, - &*self.execution_interface, self.config.gas_costs.clone(), ) { // execution failed: reset context to snapshot and reimburse sender @@ -720,7 +753,7 @@ impl ExecutionState { /// # Returns /// An `ExecutionOutput` structure summarizing the output of the executed slot pub fn execute_slot( - &self, + &mut self, slot: &Slot, exec_target: Option<&(BlockId, Storage)>, selector: Box, @@ -1009,7 +1042,7 @@ impl ExecutionState { /// # Returns /// `ExecutionOutput` describing the output of the execution, or an error pub(crate) fn execute_readonly_request( - &self, + &mut self, req: ReadOnlyExecutionRequest, ) -> Result { // TODO ensure that speculative things are reset after every execution ends (incl. on error and readonly) @@ -1045,11 +1078,15 @@ impl ExecutionState { // set the execution context for execution *context_guard!(self) = execution_context; + // init runtime engine and retrieve the binary module + let (engine, binary_module) = + self.init_runtime_execution(&bytecode, req.max_gas)?; + // run the bytecode's main function massa_sc_runtime::run_main( - &bytecode, - req.max_gas, &*self.execution_interface, + &engine, + binary_module, self.config.gas_costs.clone(), ) .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? @@ -1067,13 +1104,17 @@ impl ExecutionState { // set the execution context for execution *context_guard!(self) = execution_context; + // init runtime engine and retrieve the binary module + let (engine, binary_module) = + self.init_runtime_execution(&bytecode, req.max_gas)?; + // run the target function in the bytecode massa_sc_runtime::run_function( - &bytecode, - req.max_gas, + &*self.execution_interface, + &engine, + binary_module, &target_func, ¶meter, - &*self.execution_interface, self.config.gas_costs.clone(), ) .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? diff --git a/massa-execution-worker/src/worker.rs b/massa-execution-worker/src/worker.rs index 667d2feaee8..321b406968b 100644 --- a/massa-execution-worker/src/worker.rs +++ b/massa-execution-worker/src/worker.rs @@ -86,7 +86,7 @@ impl ExecutionThread { let (req, resp_tx) = req_resp.into_request_sender_pair(); // Acquire read access to the execution state and execute the read-only request - let outcome = self.execution_state.read().execute_readonly_request(req); + let outcome = self.execution_state.write().execute_readonly_request(req); // Send the execution output through resp_tx. // Ignore errors because they just mean that the request emitter dropped the received From 728b7e3a68d8cf83ce8c6e2adc9e5aadd9511576 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 9 Jan 2023 19:05:12 +0100 Subject: [PATCH 15/80] Bph time display (#3394) --- massa-models/src/config/compact_config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/massa-models/src/config/compact_config.rs b/massa-models/src/config/compact_config.rs index fb5c47de1e8..97ae34dbe44 100644 --- a/massa-models/src/config/compact_config.rs +++ b/massa-models/src/config/compact_config.rs @@ -50,11 +50,11 @@ impl Display for CompactConfig { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!( f, - " Genesis timestamp: {}", + " Genesis time: {}", self.genesis_timestamp.to_utc_string() )?; if let Some(end) = self.end_timestamp { - writeln!(f, " End timestamp: {}", end.to_utc_string())?; + writeln!(f, " End time: {}", end.to_utc_string())?; } writeln!(f, " Thread count: {}", self.thread_count)?; writeln!(f, " t0: {}", self.t0)?; From 1578485f9c4e747b553fd03095fedc085ab87778 Mon Sep 17 00:00:00 2001 From: AurelienFT <32803821+AurelienFT@users.noreply.github.com> Date: Mon, 9 Jan 2023 21:27:41 +0100 Subject: [PATCH 16/80] Fix gas calibration check when used on branches with / (#3390) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a37d75a943b..51cdaecffa7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -153,7 +153,7 @@ jobs: - name: "Use the current branch as dependency for gas-calibration" run: > cd gas-calibration && - sed -i 's/main/${{ github.head_ref || github.ref_name }}/g' Cargo.toml && + 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 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: > From 0a789e7260b48f82f7110e9c4893872b081392d5 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Tue, 10 Jan 2023 11:48:00 +0100 Subject: [PATCH 17/80] Fix get_blocks in client. --- massa-client/src/cmds.rs | 4 ++-- massa-client/src/repl.rs | 8 ++++++++ massa-sdk/src/lib.rs | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index 9a0966402ad..a8bbfbe2de3 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -583,8 +583,8 @@ impl Command { } Command::get_blocks => { - if parameters.len() != 1 { - bail!("wrong param numbers, expecting at least one IP address") + if parameters.is_empty() { + bail!("wrong param numbers, expecting at least one block id") } let block_ids = parse_vec::(parameters)?; match client.public.get_blocks(block_ids).await { diff --git a/massa-client/src/repl.rs b/massa-client/src/repl.rs index 0e1cc9fdea5..dbe65bf8bd2 100644 --- a/massa-client/src/repl.rs +++ b/massa-client/src/repl.rs @@ -297,6 +297,14 @@ impl Output for Vec { } } +impl Output for Vec { + fn pretty_print(&self) { + for block_info in self { + println!("{}", block_info); + } + } +} + impl Output for Vec { fn pretty_print(&self) { for operation_id in self { diff --git a/massa-sdk/src/lib.rs b/massa-sdk/src/lib.rs index e06d9b23061..b11793268ad 100644 --- a/massa-sdk/src/lib.rs +++ b/massa-sdk/src/lib.rs @@ -286,7 +286,7 @@ impl RpcClient { } /// Returns block(s) information associated to a given list of block(s) ID(s) - pub async fn get_blocks(&self, block_ids: Vec) -> RpcResult { + pub async fn get_blocks(&self, block_ids: Vec) -> RpcResult> { self.http_client .request("get_blocks", rpc_params![block_ids]) .await From 480d75e71833c43425d519e062c7585b24bb8a2d Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA <22281426+aoudiamoncef@users.noreply.github.com> Date: Tue, 10 Jan 2023 15:19:04 +0100 Subject: [PATCH 18/80] Add API V2 Http/WebSocket clients to Massa SDK (#3363) closes https://github.com/massalabs/massa/issues/3361 --- massa-api/src/api_trait.rs | 4 +- massa-client/base_config/config.toml | 8 +- massa-client/src/main.rs | 21 +- massa-client/src/settings.rs | 17 +- massa-node/base_config/openrpc.json | 4 +- massa-node/src/settings.rs | 2 +- massa-protocol-exports/src/settings.rs | 2 +- massa-protocol-exports/src/tests/tools.rs | 2 +- massa-sdk/src/config.rs | 30 ++- massa-sdk/src/lib.rs | 293 +++++++++++++++++++--- 10 files changed, 321 insertions(+), 62 deletions(-) diff --git a/massa-api/src/api_trait.rs b/massa-api/src/api_trait.rs index baf6f90e05b..73adcff90d5 100644 --- a/massa-api/src/api_trait.rs +++ b/massa-api/src/api_trait.rs @@ -27,7 +27,7 @@ pub trait MassaApi { )] fn subscribe_new_blocks_headers(&self); - /// New produced block with operations content. + /// New produced blocks with operations content. #[subscription( name = "subscribe_new_filled_blocks" => "new_filled_blocks", unsubscribe = "unsubscribe_new_filled_blocks", @@ -35,7 +35,7 @@ pub trait MassaApi { )] fn subscribe_new_filled_blocks(&self); - /// New produced operations. + /// New received only operations. #[subscription( name = "subscribe_new_operations" => "new_operations", unsubscribe = "unsubscribe_new_operations", diff --git a/massa-client/base_config/config.toml b/massa-client/base_config/config.toml index db17f5e366d..f3459f28729 100644 --- a/massa-client/base_config/config.toml +++ b/massa-client/base_config/config.toml @@ -6,8 +6,8 @@ timeout = 1000 ip = "127.0.0.1" private_port = 33034 public_port = 33035 -api_port = 33036 -[http] + +[client] # maximum size in bytes of a request max_request_body_size = 52428800 # request timeout @@ -22,3 +22,7 @@ api_port = 33036 max_log_length = 4096 # custom headers passed to the server with every request (default is empty). headers = [] + + [client.http] + # whether to enable HTTP. + enabled = true \ No newline at end of file diff --git a/massa-client/src/main.rs b/massa-client/src/main.rs index 5c7c1057167..acd5bcfad89 100644 --- a/massa-client/src/main.rs +++ b/massa-client/src/main.rs @@ -9,7 +9,7 @@ use atty::Stream; use cmds::Command; use console::style; use dialoguer::Password; -use massa_sdk::{Client, HttpConfig}; +use massa_sdk::{Client, ClientConfig, HttpConfig}; use massa_wallet::Wallet; use serde::Serialize; use std::net::IpAddr; @@ -95,14 +95,19 @@ fn main(args: Args) -> anyhow::Result<()> { } async fn run(args: Args) -> Result<()> { + let client_config = ClientConfig { + max_request_body_size: SETTINGS.client.max_request_body_size, + request_timeout: SETTINGS.client.request_timeout, + max_concurrent_requests: SETTINGS.client.max_concurrent_requests, + certificate_store: SETTINGS.client.certificate_store.clone(), + id_kind: SETTINGS.client.id_kind.clone(), + max_log_length: SETTINGS.client.max_log_length, + headers: SETTINGS.client.headers.clone(), + }; + let http_config = HttpConfig { - max_request_body_size: SETTINGS.http.max_request_body_size, - request_timeout: SETTINGS.http.request_timeout, - max_concurrent_requests: SETTINGS.http.max_concurrent_requests, - certificate_store: SETTINGS.http.certificate_store.clone(), - id_kind: SETTINGS.http.id_kind.clone(), - max_log_length: SETTINGS.http.max_log_length, - headers: SETTINGS.http.headers.clone(), + client_config, + enabled: SETTINGS.client.http.enabled, }; // TODO: move settings loading in another crate ... see #1277 diff --git a/massa-client/src/settings.rs b/massa-client/src/settings.rs index 0e7ad8e4be6..c35f7d9bc6f 100644 --- a/massa-client/src/settings.rs +++ b/massa-client/src/settings.rs @@ -16,7 +16,7 @@ pub struct Settings { pub history: usize, pub history_file_path: PathBuf, pub timeout: MassaTime, - pub http: HttpSettings, + pub client: ClientSettings, } #[derive(Debug, Deserialize, Clone)] @@ -26,10 +26,10 @@ pub struct DefaultNode { pub public_port: u16, } -/// Http Client settings. -/// the Http Client settings +/// Client settings +/// the client settings. #[derive(Debug, Deserialize, Clone)] -pub struct HttpSettings { +pub struct ClientSettings { pub max_request_body_size: u32, pub request_timeout: MassaTime, pub max_concurrent_requests: usize, @@ -37,6 +37,15 @@ pub struct HttpSettings { pub id_kind: String, pub max_log_length: u32, pub headers: Vec<(String, String)>, + pub http: HttpSettings, +} + +///TODO add WebSocket to CLI +/// Http client settings. +/// the Http client settings +#[derive(Debug, Deserialize, Clone)] +pub struct HttpSettings { + pub enabled: bool, } #[cfg(test)] diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index a7e24025fe3..da06327140f 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -1124,8 +1124,8 @@ "name": "FilledBlockInfo" }, "name": "subscribe_new_filled_blocks", - "summary": "New produced block with operations content", - "description": "New produced block with operations content." + "summary": "New produced blocks with operations content", + "description": "New produced blocks with operations content." }, { "tags": [ diff --git a/massa-node/src/settings.rs b/massa-node/src/settings.rs index 7185157df26..e0b0d504927 100644 --- a/massa-node/src/settings.rs +++ b/massa-node/src/settings.rs @@ -218,7 +218,7 @@ pub struct ProtocolSettings { pub max_operations_propagation_time: MassaTime, /// Time threshold after which operation are not propagated pub max_endorsements_propagation_time: MassaTime, - /// operations sender sender(channel) capacity + /// operations sender(channel) capacity pub broadcast_operations_capacity: usize, } diff --git a/massa-protocol-exports/src/settings.rs b/massa-protocol-exports/src/settings.rs index a86156ae7ee..d8b3ed0c7c2 100644 --- a/massa-protocol-exports/src/settings.rs +++ b/massa-protocol-exports/src/settings.rs @@ -57,6 +57,6 @@ pub struct ProtocolConfig { pub max_endorsements_propagation_time: MassaTime, /// Whether WebSockets are enabled pub broadcast_enabled: bool, - /// operation sender sender(channel) capacity + /// operations sender(channel) capacity pub broadcast_operations_capacity: usize, } diff --git a/massa-protocol-exports/src/tests/tools.rs b/massa-protocol-exports/src/tests/tools.rs index ff558cf89ec..dd46166c9b7 100644 --- a/massa-protocol-exports/src/tests/tools.rs +++ b/massa-protocol-exports/src/tests/tools.rs @@ -227,7 +227,7 @@ pub fn create_protocol_config() -> ProtocolConfig { max_operations_propagation_time: MassaTime::from_millis(30000), max_endorsements_propagation_time: MassaTime::from_millis(60000), broadcast_enabled: false, - broadcast_operations_capacity: 128, + broadcast_operations_capacity: 5000, } } diff --git a/massa-sdk/src/config.rs b/massa-sdk/src/config.rs index 0f28e771afb..5a376d40f77 100644 --- a/massa-sdk/src/config.rs +++ b/massa-sdk/src/config.rs @@ -2,10 +2,10 @@ use massa_time::MassaTime; -/// Http client settings. -/// the Http client settings +/// Client common settings. +/// the client common settings #[derive(Debug, Clone)] -pub struct HttpConfig { +pub struct ClientConfig { /// maximum size in bytes of a request. pub max_request_body_size: u32, /// maximum size in bytes of a response. @@ -21,3 +21,27 @@ pub struct HttpConfig { /// custom headers to pass with every request. pub headers: Vec<(String, String)>, } + +/// Http client settings. +/// the Http client settings +#[derive(Debug, Clone)] +pub struct HttpConfig { + /// common client configuration. + pub client_config: ClientConfig, + /// whether to enable HTTP. + pub enabled: bool, +} + +/// WebSocket client settings. +/// the WebSocket client settings +#[derive(Debug, Clone)] +pub struct WsConfig { + /// common client configuration. + pub client_config: ClientConfig, + /// whether to enable WS. + pub enabled: bool, + /// Max notifications per subscription. + pub max_notifs_per_subscription: usize, + /// Max number of redirections. + pub max_redirections: usize, +} diff --git a/massa-sdk/src/lib.rs b/massa-sdk/src/lib.rs index 60278ecf266..b423215362c 100644 --- a/massa-sdk/src/lib.rs +++ b/massa-sdk/src/lib.rs @@ -5,21 +5,28 @@ #![warn(unused_crate_dependencies)] use http::header::HeaderName; -use jsonrpsee::core::client::{CertificateStore, ClientT, IdKind}; +use jsonrpsee::core::client::{ + CertificateStore, ClientT, IdKind, Subscription, SubscriptionClientT, +}; use jsonrpsee::http_client::HttpClient; use jsonrpsee::rpc_params; -use jsonrpsee::ws_client::{HeaderMap, HeaderValue}; +use jsonrpsee::types::error::CallError; +use jsonrpsee::types::ErrorObject; +use jsonrpsee::ws_client::{HeaderMap, HeaderValue, WsClient, WsClientBuilder}; use massa_models::api::{ AddressInfo, BlockInfo, BlockSummary, DatastoreEntryInput, DatastoreEntryOutput, EndorsementInfo, EventFilter, NodeStatus, OperationInfo, OperationInput, ReadOnlyBytecodeExecution, ReadOnlyCall, TimeInterval, }; +use massa_models::block::{BlockHeader, FilledBlock}; use massa_models::clique::Clique; use massa_models::composite::PubkeySig; use massa_models::execution::ExecuteReadOnlyResponse; use massa_models::node::NodeId; +use massa_models::operation::Operation; use massa_models::output_event::SCOutputEvent; use massa_models::prehash::{PreHashMap, PreHashSet}; +use massa_models::version::Version; use massa_models::{ address::Address, block::BlockId, endorsement::EndorsementId, operation::OperationId, }; @@ -29,7 +36,9 @@ use std::net::{IpAddr, SocketAddr}; use std::str::FromStr; mod config; +pub use config::ClientConfig; pub use config::HttpConfig; +pub use config::WsConfig; /// Client pub struct Client { @@ -58,7 +67,7 @@ impl Client { } } -/// TODO add ws client +/// Rpc client pub struct RpcClient { http_client: HttpClient, } @@ -66,41 +75,8 @@ pub struct RpcClient { impl RpcClient { /// Default constructor pub async fn from_url(url: &str, http_config: &HttpConfig) -> RpcClient { - let certificate_store = match http_config.certificate_store.as_str() { - "Native" => CertificateStore::Native, - "WebPki" => CertificateStore::WebPki, - _ => CertificateStore::Native, - }; - let id_kind = match http_config.id_kind.as_str() { - "Number" => IdKind::Number, - "String" => IdKind::String, - _ => IdKind::Number, - }; - - let mut headers = HeaderMap::new(); - http_config.headers.iter().for_each(|(key, value)| { - let header_name = match HeaderName::from_str(key.as_str()) { - Ok(header_name) => header_name, - Err(_) => panic!("invalid header name: {:?}", key), - }; - let header_value = match HeaderValue::from_str(value.as_str()) { - Ok(header_name) => header_name, - Err(_) => panic!("invalid header value: {:?}", value), - }; - headers.insert(header_name, header_value); - }); - - match HttpClientBuilder::default() - .max_request_body_size(http_config.max_request_body_size) - .request_timeout(http_config.request_timeout.to_duration()) - .max_concurrent_requests(http_config.max_concurrent_requests) - .certificate_store(certificate_store) - .id_format(id_kind) - .set_headers(headers) - .build(url) - { - Ok(http_client) => RpcClient { http_client }, - Err(_) => panic!("unable to connect to Node."), + RpcClient { + http_client: http_client_from_url(url, http_config).await, } } @@ -376,3 +352,244 @@ impl RpcClient { }) } } + +/// Client V2 +pub struct ClientV2 { + /// API V2 component + pub api: RpcClientV2, +} + +impl ClientV2 { + /// creates a new client + pub async fn new( + ip: IpAddr, + api_port: u16, + http_config: &HttpConfig, + ws_config: &WsConfig, + ) -> ClientV2 { + let api_socket_addr = SocketAddr::new(ip, api_port); + ClientV2 { + api: RpcClientV2::from_url(api_socket_addr, http_config, ws_config).await, + } + } +} + +/// Rpc V2 client +pub struct RpcClientV2 { + http_client: Option, + ws_client: Option, +} + +impl RpcClientV2 { + /// Default constructor + pub async fn from_url( + socket_addr: SocketAddr, + http_config: &HttpConfig, + ws_config: &WsConfig, + ) -> RpcClientV2 { + let http_url = format!("http://{}", socket_addr); + let ws_url = format!("ws://{}", socket_addr); + + if http_config.enabled && !ws_config.enabled { + let http_client = http_client_from_url(&http_url, http_config).await; + return RpcClientV2 { + http_client: Some(http_client), + ws_client: None, + }; + } else if !http_config.enabled && ws_config.enabled { + let ws_client = ws_client_from_url(&ws_url, ws_config).await; + return RpcClientV2 { + http_client: None, + ws_client: Some(ws_client), + }; + } else if !http_config.enabled && !ws_config.enabled { + panic!("wrong client configuration, you can't disable both http and ws"); + } + + let http_client = http_client_from_url(&http_url, http_config).await; + let ws_client = ws_client_from_url(&ws_url, ws_config).await; + + RpcClientV2 { + http_client: Some(http_client), + ws_client: Some(ws_client), + } + } + + //////////////// + // API V2 // + //////////////// + // + // Experimental APIs. They might disappear, and they will change // + + /// Get Massa node version + pub async fn get_version(&self) -> RpcResult { + if let Some(client) = self.http_client.as_ref() { + client.request("get_version", rpc_params![]).await + } else { + Err(JsonRpseeError::Custom( + "error, no Http client instance found".to_owned(), + )) + } + } + + /// New produced blocks + pub async fn subscribe_new_blocks( + &self, + ) -> Result, jsonrpsee::core::Error> { + if let Some(client) = self.ws_client.as_ref() { + client + .subscribe( + "subscribe_new_blocks", + rpc_params![], + "unsubscribe_new_blocks", + ) + .await + } else { + Err(CallError::Custom(ErrorObject::owned( + -32080, + "error, no WebSocket client instance found".to_owned(), + None::<()>, + )) + .into()) + } + } + + /// New produced blocks headers + pub async fn subscribe_new_blocks_headers( + &self, + ) -> Result, jsonrpsee::core::Error> { + if let Some(client) = self.ws_client.as_ref() { + client + .subscribe( + "subscribe_new_blocks_headers", + rpc_params![], + "unsubscribe_new_blocks_headers", + ) + .await + } else { + Err(CallError::Custom(ErrorObject::owned( + -32080, + "error, no WebSocket client instance found".to_owned(), + None::<()>, + )) + .into()) + } + } + + /// New produced blocks with operations content. + pub async fn subscribe_new_filled_blocks( + &self, + ) -> Result, jsonrpsee::core::Error> { + if let Some(client) = self.ws_client.as_ref() { + client + .subscribe( + "subscribe_new_filled_blocks", + rpc_params![], + "unsubscribe_new_filled_blocks", + ) + .await + } else { + Err(CallError::Custom(ErrorObject::owned( + -32080, + "error, no WebSocket client instance found".to_owned(), + None::<()>, + )) + .into()) + } + } + + /// New received only operations. + pub async fn subscribe_new_operations( + &self, + ) -> Result, jsonrpsee::core::Error> { + if let Some(client) = self.ws_client.as_ref() { + client + .subscribe( + "subscribe_new_operations", + rpc_params![], + "unsubscribe_new_operations", + ) + .await + } else { + Err(CallError::Custom(ErrorObject::owned( + -32080, + "error, no WebSocket client instance found".to_owned(), + None::<()>, + )) + .into()) + } + } +} + +async fn http_client_from_url(url: &str, http_config: &HttpConfig) -> HttpClient { + match HttpClientBuilder::default() + .max_request_body_size(http_config.client_config.max_request_body_size) + .request_timeout(http_config.client_config.request_timeout.to_duration()) + .max_concurrent_requests(http_config.client_config.max_concurrent_requests) + .certificate_store(get_certificate_store( + http_config.client_config.certificate_store.as_str(), + )) + .id_format(get_id_kind(http_config.client_config.id_kind.as_str())) + .set_headers(get_headers(&http_config.client_config.headers)) + .build(url) + { + Ok(http_client) => http_client, + Err(_) => panic!("unable to create Http client."), + } +} + +async fn ws_client_from_url(url: &str, ws_config: &WsConfig) -> WsClient +where + WsClient: SubscriptionClientT, +{ + match WsClientBuilder::default() + .max_request_body_size(ws_config.client_config.max_request_body_size) + .request_timeout(ws_config.client_config.request_timeout.to_duration()) + .max_concurrent_requests(ws_config.client_config.max_concurrent_requests) + .certificate_store(get_certificate_store( + ws_config.client_config.certificate_store.as_str(), + )) + .id_format(get_id_kind(ws_config.client_config.id_kind.as_str())) + .set_headers(get_headers(&ws_config.client_config.headers)) + .max_notifs_per_subscription(ws_config.max_notifs_per_subscription) + .max_redirections(ws_config.max_redirections) + .build(url) + .await + { + Ok(ws_client) => ws_client, + Err(_) => panic!("unable to create WebSocket client"), + } +} + +fn get_certificate_store(certificate_store: &str) -> CertificateStore { + match certificate_store { + "Native" => CertificateStore::Native, + "WebPki" => CertificateStore::WebPki, + _ => CertificateStore::Native, + } +} + +fn get_id_kind(id_kind: &str) -> IdKind { + match id_kind { + "Number" => IdKind::Number, + "String" => IdKind::String, + _ => IdKind::Number, + } +} + +fn get_headers(headers: &[(String, String)]) -> HeaderMap { + let mut headers_map = HeaderMap::new(); + headers.iter().for_each(|(key, value)| { + let header_name = match HeaderName::from_str(key.as_str()) { + Ok(header_name) => header_name, + Err(_) => panic!("invalid header name: {:?}", key), + }; + let header_value = match HeaderValue::from_str(value.as_str()) { + Ok(header_name) => header_name, + Err(_) => panic!("invalid header value: {:?}", value), + }; + headers_map.insert(header_name, header_value); + }); + + headers_map +} From 98feda9227916756f87677386d2829676044dbda Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Wed, 11 Jan 2023 11:39:47 +0100 Subject: [PATCH 19/80] Added ipv6 bootstrap addresses (#3391) * Added IPv6 addresses in bootstrap list and bootstrap_protocol setting bootstrap_protocol may be "ipv4", "ipv6". Any other string defaults to both protocols. * Some optimisations and comments * Added setting documentation * Updated PublicKey -> NodeId (see merge commit) * Updated bootstrap test fake config * Added debug log to check the number of filtered out ips. * Refactoring + using IpType enum * Removed unnecessary .clone() * Dedup optimisation We don't need to shuffle twice the bootstrap list anymore --- massa-bootstrap/src/client.rs | 53 ++++++++++++++++++++++++++---- massa-bootstrap/src/lib.rs | 1 + massa-bootstrap/src/settings.rs | 13 ++++++++ massa-bootstrap/src/tests/tools.rs | 3 +- massa-node/base_config/config.toml | 10 ++++-- massa-node/src/main.rs | 1 + massa-node/src/settings.rs | 2 ++ massa-node/src/tests/config.toml | 4 ++- 8 files changed, 77 insertions(+), 10 deletions(-) diff --git a/massa-bootstrap/src/client.rs b/massa-bootstrap/src/client.rs index 1573666d5ca..1f2533b3317 100644 --- a/massa-bootstrap/src/client.rs +++ b/massa-bootstrap/src/client.rs @@ -1,9 +1,9 @@ use humantime::format_duration; -use std::{net::SocketAddr, sync::Arc, time::Duration}; +use std::{collections::HashSet, net::SocketAddr, sync::Arc, time::Duration}; use massa_final_state::FinalState; use massa_logging::massa_trace; -use massa_models::{streaming_step::StreamingStep, version::Version}; +use massa_models::{node::NodeId, streaming_step::StreamingStep, version::Version}; use massa_signature::PublicKey; use massa_time::MassaTime; use parking_lot::RwLock; @@ -18,6 +18,7 @@ use crate::{ client_binder::BootstrapClientBinder, error::BootstrapError, messages::{BootstrapClientMessage, BootstrapServerMessage}, + settings::IpType, BootstrapConfig, Establisher, GlobalBootstrapState, }; @@ -407,6 +408,32 @@ async fn connect_to_server( )) } +fn filter_bootstrap_list( + bootstrap_list: Vec<(SocketAddr, NodeId)>, + ip_type: IpType, +) -> Vec<(SocketAddr, NodeId)> { + let ip_filter: fn(&(SocketAddr, NodeId)) -> bool = match ip_type { + IpType::IPv4 => |&(addr, _)| addr.is_ipv4(), + IpType::IPv6 => |&(addr, _)| addr.is_ipv6(), + IpType::Both => |_| true, + }; + + let prev_bootstrap_list_len = bootstrap_list.len(); + + let filtered_bootstrap_list: Vec<_> = bootstrap_list.into_iter().filter(ip_filter).collect(); + + let new_bootstrap_list_len = filtered_bootstrap_list.len(); + + debug!( + "Keeping {:?} bootstrap ips. Filtered out {} bootstrap addresses out of a total of {} bootstrap servers.", + ip_type, + prev_bootstrap_list_len as i32 - new_bootstrap_list_len as i32, + prev_bootstrap_list_len + ); + + filtered_bootstrap_list +} + /// Gets the state from a bootstrap server /// needs to be CANCELLABLE pub async fn get_state( @@ -437,15 +464,28 @@ pub async fn get_state( } return Ok(GlobalBootstrapState::new(final_state)); } + + // we filter the bootstrap list to keep only the ip addresses we are compatible with + let mut filtered_bootstrap_list = filter_bootstrap_list( + bootstrap_config.bootstrap_list.clone(), + bootstrap_config.bootstrap_protocol, + ); + // we are after genesis => bootstrap massa_trace!("bootstrap.lib.get_state.init_from_others", {}); - if bootstrap_config.bootstrap_list.is_empty() { + if filtered_bootstrap_list.is_empty() { return Err(BootstrapError::GeneralError( "no bootstrap nodes found in list".into(), )); } - let mut shuffled_list = bootstrap_config.bootstrap_list.clone(); - shuffled_list.shuffle(&mut StdRng::from_entropy()); + + // we shuffle the list + filtered_bootstrap_list.shuffle(&mut StdRng::from_entropy()); + + // we remove the duplicated node ids (if a bootstrap server appears both with its IPv4 and IPv6 address) + let mut unique_node_ids: HashSet = HashSet::new(); + filtered_bootstrap_list.retain(|e| unique_node_ids.insert(e.1)); + let mut next_bootstrap_message: BootstrapClientMessage = BootstrapClientMessage::AskBootstrapPart { last_slot: None, @@ -457,8 +497,9 @@ pub async fn get_state( last_consensus_step: StreamingStep::Started, }; let mut global_bootstrap_state = GlobalBootstrapState::new(final_state.clone()); + loop { - for (addr, node_id) in shuffled_list.iter() { + for (addr, node_id) in filtered_bootstrap_list.iter() { if let Some(end) = end_timestamp { if MassaTime::now().expect("could not get now time") > end { panic!("This episode has come to an end, please get the latest testnet node version to continue"); diff --git a/massa-bootstrap/src/lib.rs b/massa-bootstrap/src/lib.rs index c9f3c934a4d..3f84a2e383f 100644 --- a/massa-bootstrap/src/lib.rs +++ b/massa-bootstrap/src/lib.rs @@ -37,6 +37,7 @@ pub use messages::{ }; pub use server::{start_bootstrap_server, BootstrapManager}; pub use settings::BootstrapConfig; +pub use settings::IpType; #[cfg(test)] pub mod tests; diff --git a/massa-bootstrap/src/settings.rs b/massa-bootstrap/src/settings.rs index c6a0398ed99..c49137977a8 100644 --- a/massa-bootstrap/src/settings.rs +++ b/massa-bootstrap/src/settings.rs @@ -5,11 +5,24 @@ use massa_time::MassaTime; use serde::Deserialize; use std::{net::SocketAddr, path::PathBuf}; +/// Bootstrap IP protocol version setting. +#[derive(Debug, Deserialize, Clone, Copy)] +pub enum IpType { + /// Bootstrap with both IPv4 and IPv6 protocols (default). + Both, + /// Bootstrap only with IPv4. + IPv4, + /// Bootstrap only with IPv6. + IPv6, +} + /// Bootstrap configuration. #[derive(Debug, Deserialize, Clone)] pub struct BootstrapConfig { /// Ip address of our bootstrap nodes and their public key. pub bootstrap_list: Vec<(SocketAddr, NodeId)>, + /// IP version filter for bootstrap list, targeting IpType::IPv4, IpType::IPv6 or IpType::Both. Defaults to IpType::Both. + pub bootstrap_protocol: IpType, /// Path to the bootstrap whitelist file. This whitelist define IPs that can bootstrap on your node. pub bootstrap_whitelist_path: PathBuf, /// Path to the bootstrap blacklist file. This whitelist define IPs that will not be able to bootstrap on your node. This list is optional. diff --git a/massa-bootstrap/src/tests/tools.rs b/massa-bootstrap/src/tests/tools.rs index 571c3a98ded..32719441ecb 100644 --- a/massa-bootstrap/src/tests/tools.rs +++ b/massa-bootstrap/src/tests/tools.rs @@ -1,7 +1,7 @@ // Copyright (c) 2022 MASSA LABS use super::mock_establisher::Duplex; -use crate::settings::BootstrapConfig; +use crate::settings::{BootstrapConfig, IpType}; use bitvec::vec::BitVec; use massa_async_pool::test_exports::{create_async_pool, get_random_message}; use massa_async_pool::{AsyncPoolChanges, Change}; @@ -276,6 +276,7 @@ pub fn get_dummy_signature(s: &str) -> Signature { pub fn get_bootstrap_config(bootstrap_public_key: NodeId) -> BootstrapConfig { BootstrapConfig { bind: Some("0.0.0.0:31244".parse().unwrap()), + bootstrap_protocol: IpType::Both, connect_timeout: 200.into(), retry_delay: 200.into(), max_ping: MassaTime::from_millis(500), diff --git a/massa-node/base_config/config.toml b/massa-node/base_config/config.toml index 7a633fc5254..d32b9280b51 100644 --- a/massa-node/base_config/config.toml +++ b/massa-node/base_config/config.toml @@ -204,13 +204,19 @@ ["198.27.74.5:31245", "N1qxuqNnx9kyAMYxUfsYiv2gQd5viiBX126SzzexEdbbWd2vQKu"], ["198.27.74.52:31245", "N1hdgsVsd4zkNp8cF1rdqqG6JPRQasAmx12QgJaJHBHFU1fRHEH"], ["54.36.174.177:31245", "N1gEdBVEbRFbBxBtrjcTDDK9JPbJFDay27uiJRE3vmbFAFDKNh7"], - ["51.75.60.228:31245", "N13Ykon8Zo73PTKMruLViMMtE2rEG646JQ4sCcee2DnopmVM3P5"] + ["51.75.60.228:31245", "N13Ykon8Zo73PTKMruLViMMtE2rEG646JQ4sCcee2DnopmVM3P5"], + ["[2001:41d0:1004:67::]:31245", "N12UbyLJDS7zimGWf3LTHe8hYY67RdLke1iDRZqJbQQLHQSKPW8j"], + ["[2001:41d0:a:7f7d::]:31245", "N12vxrYTQzS5TRzxLfFNYxn6PyEsphKWkdqx2mVfEuvJ9sPF43uq"], + ["[2001:41d0:602:db1::]:31245", "N1gEdBVEbRFbBxBtrjcTDDK9JPbJFDay27uiJRE3vmbFAFDKNh7"], + ["[2001:41d0:602:21e4::]:31245", "N13Ykon8Zo73PTKMruLViMMtE2rEG646JQ4sCcee2DnopmVM3P5"], ] + # force the bootstrap protocol to use: "IPv4", "IPv6", or "Both". Defaults to using both protocols. + bootstrap_protocol = "Both" # path to the bootstrap whitelist file. This whitelist define IPs that can bootstrap on your node. bootstrap_whitelist_path = "base_config/bootstrap_whitelist.json" # path to the bootstrap blacklist file. This whitelist define IPs that will not be able to bootstrap on your node. This list is optional. bootstrap_blacklist_path = "base_config/bootstrap_blacklist.json" - # [optionnal] port on which to listen for incoming bootstrap requests + # [optional] port on which to listen for incoming bootstrap requests bind = "[::]:31245" # timeout to establish a bootstrap connection connect_timeout = 15000 diff --git a/massa-node/src/main.rs b/massa-node/src/main.rs index bcc6098d21b..411025e8f23 100644 --- a/massa-node/src/main.rs +++ b/massa-node/src/main.rs @@ -172,6 +172,7 @@ async fn launch( let bootstrap_config: BootstrapConfig = BootstrapConfig { bootstrap_list: SETTINGS.bootstrap.bootstrap_list.clone(), + bootstrap_protocol: SETTINGS.bootstrap.bootstrap_protocol, bootstrap_whitelist_path: SETTINGS.bootstrap.bootstrap_whitelist_path.clone(), bootstrap_blacklist_path: SETTINGS.bootstrap.bootstrap_blacklist_path.clone(), bind: SETTINGS.bootstrap.bind, diff --git a/massa-node/src/settings.rs b/massa-node/src/settings.rs index e0b0d504927..695c0b78562 100644 --- a/massa-node/src/settings.rs +++ b/massa-node/src/settings.rs @@ -4,6 +4,7 @@ use std::path::PathBuf; use enum_map::EnumMap; +use massa_bootstrap::IpType; use massa_models::{config::build_massa_settings, node::NodeId}; use massa_time::MassaTime; use serde::Deserialize; @@ -75,6 +76,7 @@ pub struct NetworkSettings { #[derive(Debug, Deserialize, Clone)] pub struct BootstrapSettings { pub bootstrap_list: Vec<(SocketAddr, NodeId)>, + pub bootstrap_protocol: IpType, pub bootstrap_whitelist_path: PathBuf, pub bootstrap_blacklist_path: PathBuf, pub bind: Option, diff --git a/massa-node/src/tests/config.toml b/massa-node/src/tests/config.toml index 9f3ebfee3c0..442fc3cb9d4 100644 --- a/massa-node/src/tests/config.toml +++ b/massa-node/src/tests/config.toml @@ -70,8 +70,10 @@ ["149.202.86.103:31245", "5GcSNukkKePWpNSjx9STyoEZniJAN4U4EUzdsQyqhuP3WYf6nj"], ["149.202.89.125:31245", "5wDwi2GYPniGLzpDfKjXJrmHV3p1rLRmm4bQ9TUWNVkpYmd4Zm"], ["158.69.120.215:31245", "5QbsTjSoKzYc8uBbwPCap392CoMQfZ2jviyq492LZPpijctb9c"], - ["158.69.23.120:31245", "8139kbee951YJdwK99odM7e6V3eW7XShCfX5E2ovG3b9qxqqrq"] + ["158.69.23.120:31245", "8139kbee951YJdwK99odM7e6V3eW7XShCfX5E2ovG3b9qxqqrq"], + ["[dba7:c8ca:cfda:ffad:23ee:feb7:569e:a0bf]:31245", "6DbsTjSoKzYc8uBbwPCap392CoMQfZ2jviyq492LZPpijctb9c"] ] + bootstrap_protocol = "Both" bind = "[::]:31245" connect_timeout = 15000 retry_delay = 5000 From 5fb0c67651a272e7a1e4b332f3767c2205b17f85 Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA <22281426+aoudiamoncef@users.noreply.github.com> Date: Wed, 11 Jan 2023 14:08:36 +0100 Subject: [PATCH 20/80] Add execute from final state for read only SC calls (#3383) Co-authored-by: AurelienFT closes https://github.com/massalabs/massa/issues/2950 --- massa-api/src/public.rs | 4 +++ massa-client/src/cmds.rs | 24 ++++++++++---- massa-execution-exports/src/types.rs | 12 +++++++ massa-execution-worker/src/execution.rs | 15 ++++++--- .../src/tests/scenarios_mandatories.rs | 31 +++++++++++++++++-- massa-models/src/api.rs | 12 +++++++ 6 files changed, 85 insertions(+), 13 deletions(-) diff --git a/massa-api/src/public.rs b/massa-api/src/public.rs index a05f6e140cf..7bad5d3b67c 100644 --- a/massa-api/src/public.rs +++ b/massa-api/src/public.rs @@ -127,6 +127,7 @@ impl MassaRpcServer for API { address, bytecode, operation_datastore, + is_final, } in reqs { let address = address.unwrap_or_else(|| { @@ -170,6 +171,7 @@ impl MassaRpcServer for API { owned_addresses: vec![address], operation_datastore: op_datastore, }], + is_final, }; // run @@ -211,6 +213,7 @@ impl MassaRpcServer for API { target_function, parameter, caller_address, + is_final, } in reqs { let caller_address = caller_address.unwrap_or_else(|| { @@ -245,6 +248,7 @@ impl MassaRpcServer for API { operation_datastore: None, // should always be None }, ], + is_final, }; // run diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index 90072c168fd..3b8cea8316d 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -239,15 +239,15 @@ pub enum Command { #[strum( ascii_case_insensitive, - props(args = "PathToBytecode MaxGas Address",), - message = "execute byte code, address is optional. Nothing is really executed on chain" + props(args = "PathToBytecode MaxGas Address IsFinal",), + message = "execute byte code, address is optional, is_final is optional. Nothing is really executed on chain" )] read_only_execute_smart_contract, #[strum( ascii_case_insensitive, - props(args = "TargetAddress TargetFunction Parameter MaxGas SenderAddress",), - message = "call a smart contract function, sender address is optional. Nothing is really executed on chain" + props(args = "TargetAddress TargetFunction Parameter MaxGas SenderAddress IsFinal",), + message = "call a smart contract function, sender address is optional, is_final is optional. Nothing is really executed on chain" )] read_only_call, @@ -967,7 +967,7 @@ impl Command { } } Command::read_only_execute_smart_contract => { - if parameters.len() != 2 && parameters.len() != 3 { + if parameters.len() != 2 && parameters.len() <= 4 { bail!("wrong number of parameters"); } @@ -978,6 +978,11 @@ impl Command { } else { None }; + let is_final = if let Some(adr) = parameters.get(3) { + Some(adr.parse::()?) + } else { + None + }; let bytecode = get_file_as_byte_vec(&path).await?; match client .public @@ -986,6 +991,7 @@ impl Command { bytecode, address, operation_datastore: None, // TODO - #3072 + is_final, }) .await { @@ -994,7 +1000,7 @@ impl Command { } } Command::read_only_call => { - if parameters.len() != 4 && parameters.len() != 5 { + if parameters.len() != 4 && parameters.len() <= 6 { bail!("wrong number of parameters"); } @@ -1007,6 +1013,11 @@ impl Command { } else { None }; + let is_final = if let Some(adr) = parameters.get(5) { + Some(adr.parse::()?) + } else { + None + }; match client .public .execute_read_only_call(ReadOnlyCall { @@ -1015,6 +1026,7 @@ impl Command { target_function, parameter, max_gas, + is_final, }) .await { diff --git a/massa-execution-exports/src/types.rs b/massa-execution-exports/src/types.rs index 978270df5d8..5848cdec6e2 100644 --- a/massa-execution-exports/src/types.rs +++ b/massa-execution-exports/src/types.rs @@ -69,6 +69,12 @@ pub struct ReadOnlyExecutionRequest { pub call_stack: Vec, /// Target of the request pub target: ReadOnlyExecutionTarget, + /// optional event status + /// + /// Some(true) means final + /// Some(false) means candidate + /// None means final _and_ candidate + pub is_final: Option, } /// structure describing different possible targets of a read-only execution request @@ -101,6 +107,12 @@ pub struct ReadOnlyCallRequest { pub target_func: String, /// Parameter to pass to the target function pub parameter: String, + /// optional event status + /// + /// Some(true) means final + /// Some(false) means candidate + /// None means final _and_ candidate + pub is_final: Option, } /// Structure describing an element of the execution stack. diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 31351111ca1..6ce4301b90d 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -1023,11 +1023,16 @@ impl ExecutionState { ))); } - // set the execution slot to be the one after the latest executed active slot - let slot = self - .active_cursor - .get_next_slot(self.config.thread_count) - .expect("slot overflow in readonly execution"); + // set the execution slot to be the one after the latest executed active or final slot + let slot = if req.is_final.map_or(false, |is_final| is_final) { + self.final_cursor + .get_next_slot(self.config.thread_count) + .expect("slot overflow in readonly execution") + } else { + self.active_cursor + .get_next_slot(self.config.thread_count) + .expect("slot overflow in readonly execution") + }; // create a readonly execution context let execution_context = ExecutionContext::readonly( diff --git a/massa-execution-worker/src/tests/scenarios_mandatories.rs b/massa-execution-worker/src/tests/scenarios_mandatories.rs index 618fea40788..a503377fad7 100644 --- a/massa-execution-worker/src/tests/scenarios_mandatories.rs +++ b/massa-execution-worker/src/tests/scenarios_mandatories.rs @@ -57,12 +57,26 @@ fn test_sending_command() { #[test] #[serial] fn test_readonly_execution() { + // setup the period duration + let exec_cfg = ExecutionConfig { + t0: 100.into(), + cursor_delay: 0.into(), + ..ExecutionConfig::default() + }; + // get a sample final state let (sample_state, _keep_file, _keep_dir) = get_sample_state().unwrap(); + // init the storage + let storage = Storage::create_root(); + // start the execution worker let (mut manager, controller) = start_execution_worker( - ExecutionConfig::default(), + exec_cfg.clone(), sample_state.clone(), sample_state.read().pos_state.selector.clone(), ); + // initialize the execution system with genesis blocks + init_execution_worker(&exec_cfg, &storage, controller.clone()); + std::thread::sleep(Duration::from_millis(1000)); + let mut res = controller .execute_readonly_request(ReadOnlyExecutionRequest { max_gas: 1_000_000, @@ -70,12 +84,25 @@ fn test_readonly_execution() { target: ReadOnlyExecutionTarget::BytecodeExecution( include_bytes!("./wasm/event_test.wasm").to_vec(), ), + is_final: Some(true), }) .expect("readonly execution failed"); - + assert_eq!(res.out.slot, Slot::new(1, 0)); assert!(res.gas_cost > 0); assert_eq!(res.out.events.take().len(), 1, "wrong number of events"); + let res = controller + .execute_readonly_request(ReadOnlyExecutionRequest { + max_gas: 1_000_000, + call_stack: vec![], + target: ReadOnlyExecutionTarget::BytecodeExecution( + include_bytes!("./wasm/event_test.wasm").to_vec(), + ), + is_final: Some(false), + }) + .expect("readonly execution failed"); + assert!(res.out.slot.period > 8); + manager.stop(); } diff --git a/massa-models/src/api.rs b/massa-models/src/api.rs index d2b50c4bee7..70f61700578 100644 --- a/massa-models/src/api.rs +++ b/massa-models/src/api.rs @@ -575,6 +575,12 @@ pub struct ReadOnlyBytecodeExecution { pub address: Option
, /// Operation datastore, optional pub operation_datastore: Option>, + /// optional event status + /// + /// Some(true) means final + /// Some(false) means candidate + /// None means final _and_ candidate + pub is_final: Option, } /// read SC call request @@ -590,6 +596,12 @@ pub struct ReadOnlyCall { pub parameter: Vec, /// caller's address, optional pub caller_address: Option
, + /// optional event status + /// + /// Some(true) means final + /// Some(false) means candidate + /// None means final _and_ candidate + pub is_final: Option, } /// SCRUD operations From 4a3a576d92ad32d0831629c5a3e96a257ecf59cc Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Thu, 12 Jan 2023 18:55:40 +0100 Subject: [PATCH 21/80] Added new commands (e.g. node_start_staking with address) (#3365) * Added new commands (e.g. node_start_staking with address) node_start_staking, implemented renamed node_remove_staking_addresses to node_stop_staking for consistency get_public_key Address: get public key of an address, not yet implemented get_secret_key Address: get secret key of an address, not yet implemented * Removed node_remove_staking_addresses get_secret_key and get_public_key updated but still need their output defined * cargo fmt * Fixed unused var warning * Do not ask for password unless needed /!\ pwd_needed should be added to the command description when needed, check existing code! * Fix clippy warn * Fixed clippy warn * Idem * Implemented get_public_key and _get_secret_key * Updated wallet_info command to avoid leaking secret data * fix cargo fmt * Changed pwd_needed to pwd_not_needed * Changed massa-sc-runtime branch targeting to main * Added comments * Handle -p --pwd as well as env::var("MASSA_CLIENT_PASSWORD") * Better handling of address List in get_public_key and get_secret_key * Fix output * fix fmt * Updated warning messages * Changed get_public_key and get_secret_key names get_public_key -> wallet_get_public_key and get_secret_key -> wallet_get_secret_key --- massa-client/src/cmds.rs | 287 +++++++++++++++++++++++++++++---------- massa-client/src/main.rs | 26 +++- massa-client/src/repl.rs | 69 +++++++++- 3 files changed, 299 insertions(+), 83 deletions(-) diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index 3b8cea8316d..f988a73f8d9 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -23,7 +23,7 @@ use massa_signature::KeyPair; use massa_time::MassaTime; use massa_wallet::Wallet; use serde::Serialize; -use std::collections::{BTreeMap, HashMap}; +use std::collections::{BTreeMap, HashMap, HashSet}; use std::fmt::Write as _; use std::fmt::{Debug, Display}; use std::net::IpAddr; @@ -34,62 +34,80 @@ use strum_macros::{Display, EnumIter, EnumString}; /// All the client commands /// the order they are defined is the order they are displayed in so be careful /// Maybe it would be worth renaming some of them for consistency +/// Use props(pwd_not_needed = "true") if the command does not need an access to the wallet, to avoid unnecessary +/// prompting of the user. #[allow(non_camel_case_types)] #[derive(Debug, PartialEq, Eq, EnumIter, EnumMessage, EnumString, EnumProperty, Display)] pub enum Command { - #[strum(ascii_case_insensitive, message = "display this help")] + #[strum( + ascii_case_insensitive, + props(pwd_not_needed = "true"), + message = "display this help" + )] help, - #[strum(ascii_case_insensitive, message = "exit the prompt")] + #[strum( + ascii_case_insensitive, + props(pwd_not_needed = "true"), + message = "exit the prompt" + )] exit, #[strum( ascii_case_insensitive, - props(args = "IpAddr1 IpAddr2 ..."), + props(args = "IpAddr1 IpAddr2 ...", pwd_not_needed = "true"), message = "unban given IP address(es)" )] node_unban_by_ip, #[strum( ascii_case_insensitive, - props(args = "Id1 Id2 ..."), + props(args = "Id1 Id2 ...", pwd_not_needed = "true"), message = "unban given id(s)" )] node_unban_by_id, #[strum( ascii_case_insensitive, - props(args = "IpAddr1 IpAddr2 ..."), + props(args = "IpAddr1 IpAddr2 ...", pwd_not_needed = "true"), message = "ban given IP address(es)" )] node_ban_by_ip, #[strum( ascii_case_insensitive, - props(args = "Id1 Id2 ..."), + props(args = "Id1 Id2 ...", pwd_not_needed = "true"), message = "ban given id(s)" )] node_ban_by_id, - #[strum(ascii_case_insensitive, message = "stops the node")] + #[strum( + ascii_case_insensitive, + props(pwd_not_needed = "true"), + message = "stops the node" + )] node_stop, - #[strum(ascii_case_insensitive, message = "show staking addresses")] + #[strum( + ascii_case_insensitive, + props(pwd_not_needed = "true"), + message = "show staking addresses" + )] node_get_staking_addresses, #[strum( ascii_case_insensitive, props(args = "Address1 Address2 ..."), - message = "remove staking addresses" + message = "starts staking with the given addresses" )] - node_remove_staking_addresses, + node_start_staking, #[strum( ascii_case_insensitive, - props(args = "SecretKey1 SecretKey2 ..."), - message = "add staking secret keys" + props(args = "Address1 Address2 ..."), + message = "stops staking with the given addresses" )] - node_add_staking_secret_keys, + node_stop_staking, #[strum( ascii_case_insensitive, @@ -100,62 +118,63 @@ pub enum Command { #[strum( ascii_case_insensitive, - props(args = "(add, remove or allow-all) [IpAddr]"), - message = "Manage boostrap whitelist IP address(es).No args returns the whitelist blacklist" + props(args = "(add, remove or allow-all) [IpAddr]", pwd_not_needed = "true"), + message = "Manage boostrap whitelist IP address(es). No args returns the whitelist blacklist" )] node_bootsrap_whitelist, #[strum( ascii_case_insensitive, - props(args = "(add or remove) [IpAddr]"), + props(args = "(add or remove) [IpAddr]", pwd_not_needed = "true"), message = "Manage boostrap blacklist IP address(es). No args returns the boostrap blacklist" )] node_bootsrap_blacklist, #[strum( ascii_case_insensitive, - props(args = "(add or remove) [IpAddr]"), + props(args = "(add or remove) [IpAddr]", pwd_not_needed = "true"), message = "Manage peers whitelist IP address(es). No args returns the peers whitelist" )] node_peers_whitelist, #[strum( ascii_case_insensitive, + props(pwd_not_needed = "true"), message = "show the status of the node (reachable? number of peers connected, consensus, version, config parameter summary...)" )] get_status, #[strum( ascii_case_insensitive, - props(args = "Address1 Address2 ..."), + props(args = "Address1 Address2 ...", pwd_not_needed = "true"), message = "get info about a list of addresses (balances, block creation, ...)" )] get_addresses, #[strum( ascii_case_insensitive, - props(args = "Address Key"), + props(args = "Address Key", pwd_not_needed = "true"), message = "get a datastore entry (key must be UTF-8)" )] get_datastore_entry, #[strum( ascii_case_insensitive, - props(args = "BlockId"), + props(args = "BlockId", pwd_not_needed = "true"), message = "show info about a block (content, finality ...)" )] get_blocks, #[strum( ascii_case_insensitive, - props(args = "EndorsementId1 EndorsementId2 ..."), + props(args = "EndorsementId1 EndorsementId2 ...", pwd_not_needed = "true"), message = "show info about a list of endorsements (content, finality ...)" )] get_endorsements, #[strum( ascii_case_insensitive, - props(args = "OperationId1 OperationId2 ..."), + props(args = "OperationId1 OperationId2 ...", pwd_not_needed = "true"), message = "show info about a list of operations(content, finality ...) " )] get_operations, @@ -163,7 +182,8 @@ pub enum Command { #[strum( ascii_case_insensitive, props( - args = "start=Slot end=Slot emitter_address=Address caller_address=Address operation_id=OperationId is_final=bool is_error=bool" + args = "start=Slot end=Slot emitter_address=Address caller_address=Address operation_id=OperationId is_final=bool is_error=bool", + pwd_not_needed = "true" ), message = "show events emitted by smart contracts with various filters" )] @@ -171,10 +191,25 @@ pub enum Command { #[strum( ascii_case_insensitive, - message = "show wallet info (keys, addresses, balances ...)" + props(args = "show-all-keys"), + message = "show wallet info (addresses, balances ...)" )] wallet_info, + #[strum( + ascii_case_insensitive, + props(args = "Address1 Address2 .."), + message = "get public key of the given addresses" + )] + wallet_get_public_key, + + #[strum( + ascii_case_insensitive, + props(args = "Address1 Address2 ..."), + message = "get secret key of the given addresses" + )] + wallet_get_secret_key, + #[strum( ascii_case_insensitive, message = "generate a secret key and add it into the wallet" @@ -225,39 +260,50 @@ pub enum Command { #[strum( ascii_case_insensitive, - props(args = "SenderAddress PathToBytecode MaxGas Fee",), + props(args = "SenderAddress PathToBytecode MaxGas Fee"), message = "create and send an operation containing byte code" )] execute_smart_contract, #[strum( ascii_case_insensitive, - props(args = "SenderAddress TargetAddress FunctionName Parameter MaxGas Coins Fee",), + props(args = "SenderAddress TargetAddress FunctionName Parameter MaxGas Coins Fee"), message = "create and send an operation to call a function of a smart contract" )] call_smart_contract, #[strum( ascii_case_insensitive, - props(args = "PathToBytecode MaxGas Address IsFinal",), + props( + args = "PathToBytecode MaxGas Address IsFinal", + pwd_not_needed = "true" + ), message = "execute byte code, address is optional, is_final is optional. Nothing is really executed on chain" )] read_only_execute_smart_contract, #[strum( ascii_case_insensitive, - props(args = "TargetAddress TargetFunction Parameter MaxGas SenderAddress IsFinal",), + props( + args = "TargetAddress TargetFunction Parameter MaxGas SenderAddress IsFinal", + pwd_not_needed = "true" + ), message = "call a smart contract function, sender address is optional, is_final is optional. Nothing is really executed on chain" )] read_only_call, #[strum( ascii_case_insensitive, + props(pwd_not_needed = "true"), message = "show time remaining to end of current episode" )] when_episode_ends, - #[strum(ascii_case_insensitive, message = "tells you when moon")] + #[strum( + ascii_case_insensitive, + props(pwd_not_needed = "true"), + message = "tells you when moon" + )] when_moon, } @@ -313,12 +359,16 @@ struct ExtendedWalletEntry { pub keypair: KeyPair, /// address and balance information pub address_info: CompactAddressInfo, + /// whether to display the public/secret keys or just the address info + pub show_keys: bool, } impl Display for ExtendedWalletEntry { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!(f, "Secret key: {}", self.keypair)?; - writeln!(f, "Public key: {}", self.keypair.get_public_key())?; + if self.show_keys { + writeln!(f, "Secret key: {}", self.keypair)?; + writeln!(f, "Public key: {}", self.keypair.get_public_key())?; + } writeln!(f, "{}", self.address_info)?; writeln!(f, "\n=====\n")?; Ok(()) @@ -332,7 +382,7 @@ pub struct ExtendedWallet(PreHashMap); impl ExtendedWallet { /// Reorganize everything into an extended wallet - fn new(wallet: &Wallet, addresses_info: &[AddressInfo]) -> Result { + fn new(wallet: &Wallet, addresses_info: &[AddressInfo], show_keys: bool) -> Result { Ok(ExtendedWallet( addresses_info .iter() @@ -346,6 +396,7 @@ impl ExtendedWallet { ExtendedWalletEntry { keypair: keypair.clone(), address_info: x.compact(), + show_keys, }, )) }) @@ -388,18 +439,24 @@ impl Command { ) } + /// Returns true if the command needs wallet access + pub(crate) fn is_pwd_needed(&self) -> bool { + !(self.get_str("pwd_not_needed").is_some() + && self.get_str("pwd_not_needed").unwrap() == "true") + } + /// run a given command /// /// # parameters /// - client: the RPC client - /// - wallet: an access to the wallet + /// - wallet_opt: an optional access to the wallet /// - parameters: the parsed parameters /// - json: true if --json was passed as an option /// it means that we don't want to print anything we just want the json output pub(crate) async fn run( &self, client: &Client, - wallet: &mut Wallet, + wallet_opt: &mut Option, parameters: &[String], json: bool, ) -> Result> { @@ -493,36 +550,9 @@ impl Command { } } - Command::node_remove_staking_addresses => { - let addresses = parse_vec::
(parameters)?; - match client.private.remove_staking_addresses(addresses).await { - Ok(()) => { - if !json { - println!("Addresses successfully removed!") - } - } - Err(e) => rpc_error!(e), - } - Ok(Box::new(())) - } - - Command::node_add_staking_secret_keys => { - match client - .private - .add_staking_secret_keys(parameters.to_vec()) - .await - { - Ok(()) => { - if !json { - println!("Keys successfully added!") - } - } - Err(e) => rpc_error!(e), - }; - Ok(Box::new(())) - } - Command::node_testnet_rewards_program_ownership_proof => { + let wallet = wallet_opt.as_mut().unwrap(); + if parameters.len() != 2 { bail!("wrong number of parameters"); } @@ -644,34 +674,133 @@ impl Command { } Command::wallet_info => { - if !json { - client_warning!("do not share your key"); + let show_keys = parameters.len() == 1 && parameters[0] == "show-all-keys"; + + let wallet = wallet_opt.as_mut().unwrap(); + + if !json && show_keys { + client_warning!("do not share your secret key"); } match client .public .get_addresses(wallet.get_full_wallet().keys().copied().collect()) .await { - Ok(addresses_info) => { - Ok(Box::new(ExtendedWallet::new(wallet, &addresses_info)?)) + Ok(addresses_info) => Ok(Box::new(ExtendedWallet::new( + wallet, + &addresses_info, + show_keys, + )?)), + Err(_) => match show_keys { + true => Ok(Box::new(wallet.clone())), + false => Ok(Box::new(wallet.get_wallet_address_list())), + }, // FIXME + } + } + + Command::wallet_get_public_key => { + let wallet = wallet_opt.as_mut().unwrap(); + + let addresses = parse_vec::
(parameters)?; + + let hashset: HashSet<_> = addresses.into_iter().collect(); + + let keypair: Vec<(&Address, Option<&KeyPair>)> = hashset + .iter() + .map(|addr| (addr, wallet.get_full_wallet().get(addr))) + .filter(|kp| kp.1.is_some()) + .collect(); + + let addr_public_keys: Vec<_> = keypair + .iter() + .map(|kp| (*kp.0, kp.1.unwrap().get_public_key())) + .collect(); + + Ok(Box::new(addr_public_keys)) + } + + Command::wallet_get_secret_key => { + let wallet = wallet_opt.as_mut().unwrap(); + + if !json { + client_warning!("do not share your secret key"); + } + + let addresses = parse_vec::
(parameters)?; + + let hashset: HashSet<_> = addresses.into_iter().collect(); + + let keypair: Vec<(&Address, Option<&KeyPair>)> = hashset + .iter() + .map(|addr| (addr, wallet.get_full_wallet().get(addr))) + .filter(|kp| kp.1.is_some()) + .collect(); + + let addr_secret_keys: Vec<_> = keypair + .iter() + .map(|kp| (*kp.0, kp.1.unwrap().to_owned())) + .collect(); + + Ok(Box::new(addr_secret_keys)) + } + + Command::node_start_staking => { + let wallet = wallet_opt.as_mut().unwrap(); + + let addresses = parse_vec::
(parameters)?; + let secret: Vec> = addresses + .iter() + .map(|addr| wallet.get_full_wallet().get(addr)) + .collect(); + let secret_str = secret + .iter() + .filter(|a| a.is_some()) + .map(|s| format!("{}", s.unwrap())) + .collect(); + + match client.private.add_staking_secret_keys(secret_str).await { + Ok(()) => { + if !json { + println!("Keys successfully added!") + } + } + Err(e) => rpc_error!(e), + }; + Ok(Box::new(())) + } + + Command::node_stop_staking => { + let addresses = parse_vec::
(parameters)?; + match client.private.remove_staking_addresses(addresses).await { + Ok(()) => { + if !json { + println!("Addresses successfully removed!") + } } - Err(_) => Ok(Box::new(wallet.clone())), // FIXME + Err(e) => rpc_error!(e), } + Ok(Box::new(())) } Command::wallet_generate_secret_key => { + let wallet = wallet_opt.as_mut().unwrap(); + let key = KeyPair::generate(); let ad = wallet.add_keypairs(vec![key])?[0]; if json { Ok(Box::new(ad.to_string())) } else { println!("Generated {} address and added it to the wallet", ad); - println!("Type `node_add_staking_secret_keys ` to start staking with this key.\n"); + println!( + "Type `node_start_staking
` to start staking with this address.\n" + ); Ok(Box::new(())) } } Command::wallet_add_secret_keys => { + let wallet = wallet_opt.as_mut().unwrap(); + let keypairs = parse_vec::(parameters)?; let addresses = wallet.add_keypairs(keypairs)?; if json { @@ -680,12 +809,14 @@ impl Command { for address in addresses { println!("Derived and added address {} to the wallet.", address); } - println!("Type `node_add_staking_secret_keys ` to start staking with the corresponding key.\n"); + println!("Type `node_start_staking
` to start staking with the corresponding key.\n"); } Ok(Box::new(())) } Command::wallet_remove_addresses => { + let wallet = wallet_opt.as_mut().unwrap(); + let mut res = "".to_string(); let addresses = parse_vec::
(parameters)?; match wallet.remove_addresses(&addresses) { @@ -703,6 +834,8 @@ impl Command { } Command::buy_rolls => { + let wallet = wallet_opt.as_mut().unwrap(); + if parameters.len() != 3 { bail!("wrong number of parameters"); } @@ -741,7 +874,7 @@ impl Command { } if let Ok(staked_keys) = client.private.get_staking_addresses().await { if !staked_keys.contains(&addr) { - client_warning!("You are buying rolls with an address not registered for staking. Don't forget to run 'node_add_staking_secret_keys '"); } } } @@ -757,6 +890,8 @@ impl Command { } Command::sell_rolls => { + let wallet = wallet_opt.as_mut().unwrap(); + if parameters.len() != 3 { bail!("wrong number of parameters"); } @@ -791,6 +926,8 @@ impl Command { } Command::send_transaction => { + let wallet = wallet_opt.as_mut().unwrap(); + if parameters.len() != 4 { bail!("wrong number of parameters"); } @@ -854,6 +991,8 @@ impl Command { Ok(Box::new(())) } Command::execute_smart_contract => { + let wallet = wallet_opt.as_mut().unwrap(); + if parameters.len() != 4 { bail!("wrong number of parameters"); } @@ -902,6 +1041,8 @@ impl Command { .await } Command::call_smart_contract => { + let wallet = wallet_opt.as_mut().unwrap(); + if parameters.len() != 7 { bail!("wrong number of parameters"); } @@ -955,6 +1096,8 @@ impl Command { .await } Command::wallet_sign => { + let wallet = wallet_opt.as_mut().unwrap(); + if parameters.len() != 2 { bail!("wrong number of parameters"); } diff --git a/massa-client/src/main.rs b/massa-client/src/main.rs index acd5bcfad89..392ba57af00 100644 --- a/massa-client/src/main.rs +++ b/massa-client/src/main.rs @@ -12,6 +12,7 @@ use dialoguer::Password; use massa_sdk::{Client, ClientConfig, HttpConfig}; use massa_wallet::Wallet; use serde::Serialize; +use std::env; use std::net::IpAddr; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -64,7 +65,7 @@ struct JsonError { /// Ask for the wallet password /// If the wallet does not exist, it will require password confirmation -fn ask_password(wallet_path: &Path) -> String { +pub(crate) fn ask_password(wallet_path: &Path) -> String { if wallet_path.is_file() { Password::new() .with_prompt("Enter wallet password") @@ -136,18 +137,31 @@ async fn run(args: Args) -> Result<()> { std::process::exit(1); })); - // ... - let password = args.password.unwrap_or_else(|| ask_password(&args.wallet)); - let mut wallet = Wallet::new(args.wallet, password)?; let client = Client::new(address, public_port, private_port, &http_config).await; if atty::is(Stream::Stdout) && args.command == Command::help && !args.json { // Interactive mode - repl::run(&client, &mut wallet).await?; + repl::run(&client, &args.wallet, args.password).await?; } else { // Non-Interactive mode + + // Only prompt for password if the command needs wallet access. + let mut wallet_opt = match args.command.is_pwd_needed() { + true => { + let password = match (args.password, env::var("MASSA_CLIENT_PASSWORD")) { + (Some(pwd), _) => pwd, + (_, Ok(pwd)) => pwd, + _ => ask_password(&args.wallet), + }; + + let wallet = Wallet::new(args.wallet, password)?; + Some(wallet) + } + false => None, + }; + match args .command - .run(&client, &mut wallet, &args.parameters, args.json) + .run(&client, &mut wallet_opt, &args.parameters, args.json) .await { Ok(output) => { diff --git a/massa-client/src/repl.rs b/massa-client/src/repl.rs index 0e1cc9fdea5..88812f72659 100644 --- a/massa-client/src/repl.rs +++ b/massa-client/src/repl.rs @@ -1,5 +1,6 @@ // Copyright (c) 2022 MASSA LABS +use crate::ask_password; use crate::cmds::{Command, ExtendedWallet}; use crate::settings::SETTINGS; use anyhow::Result; @@ -14,13 +15,16 @@ use massa_models::output_event::SCOutputEvent; use massa_models::prehash::PreHashSet; use massa_models::{address::Address, operation::OperationId}; use massa_sdk::Client; +use massa_signature::{KeyPair, PublicKey}; use massa_wallet::Wallet; use rustyline::completion::{Completer, FilenameCompleter, Pair}; use rustyline::error::ReadlineError; use rustyline::validate::MatchingBracketValidator; use rustyline::{CompletionType, Config, Editor}; use rustyline_derive::{Completer, Helper, Highlighter, Hinter, Validator}; +use std::env; use std::net::IpAddr; +use std::path::Path; use std::str; use strum::IntoEnumIterator; use strum::ParseError; @@ -96,7 +100,11 @@ struct MyHelper { validator: MatchingBracketValidator, } -pub(crate) async fn run(client: &Client, wallet: &mut Wallet) -> Result<()> { +pub(crate) async fn run( + client: &Client, + wallet_path: &Path, + args_password: Option, +) -> Result<()> { massa_fancy_ascii_art_logo!(); println!("Use 'exit' or 'CTRL+D or CTRL+C' to quit the prompt"); println!("Use the Up/Down arrows to scroll through history"); @@ -118,6 +126,9 @@ pub(crate) async fn run(client: &Client, wallet: &mut Wallet) -> Result<()> { if rl.load_history(&SETTINGS.history_file_path).is_err() { println!("No previous history."); } + + let mut wallet_opt = None; + loop { let readline = rl.readline("command > "); match readline { @@ -132,10 +143,28 @@ pub(crate) async fn run(client: &Client, wallet: &mut Wallet) -> Result<()> { let parameters = input[1..].to_vec(); // Print result of evaluated command match cmd { - Ok(command) => match command.run(client, wallet, ¶meters, false).await { - Ok(output) => output.pretty_print(), - Err(e) => println!("{}", style(format!("Error: {}", e)).red()), - }, + Ok(command) => { + // Check if we need to prompt the user for their wallet password + if command.is_pwd_needed() && wallet_opt.is_none() { + let password = + match (args_password.clone(), env::var("MASSA_CLIENT_PASSWORD")) { + (Some(pwd), _) => pwd, + (_, Ok(pwd)) => pwd, + _ => ask_password(wallet_path), + }; + + let wallet = Wallet::new(wallet_path.to_path_buf(), password)?; + wallet_opt = Some(wallet); + } + + match command + .run(client, &mut wallet_opt, ¶meters, false) + .await + { + Ok(output) => output.pretty_print(), + Err(e) => println!("{}", style(format!("Error: {}", e)).red()), + } + } Err(_) => { println!("Command not found!\ntype \"help\" to get the list of commands") } @@ -219,6 +248,36 @@ impl Output for ExtendedWallet { } } +impl Output for Vec<(Address, PublicKey)> { + fn pretty_print(&self) { + match self.len() { + 1 => println!("{}", self[0].1), + _ => { + for address_pubkey in self { + println!("Address: {}", address_pubkey.0); + println!("Public key: {}", address_pubkey.1); + println!(); + } + } + } + } +} + +impl Output for Vec<(Address, KeyPair)> { + fn pretty_print(&self) { + match self.len() { + 1 => println!("{}", self[0].1), + _ => { + for address_seckey in self { + println!("Address: {}", address_seckey.0); + println!("Secret key: {}", address_seckey.1); + println!(); + } + } + } + } +} + impl Output for () { fn pretty_print(&self) {} } From a83fd232f5efc218fd11706f5d134e33718d8fc7 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Fri, 13 Jan 2023 15:41:55 +0100 Subject: [PATCH 22/80] use ModuleCache and remove wasmer dep --- Cargo.lock | 35 +++++++++++- massa-execution-exports/src/settings.rs | 2 + massa-execution-worker/Cargo.toml | 22 ++++++-- massa-execution-worker/src/execution.rs | 73 +++++++------------------ massa-node/src/main.rs | 1 + 5 files changed, 71 insertions(+), 62 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 30330dd0357..88697c6d741 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,6 +63,18 @@ dependencies = [ "version_check", ] +[[package]] +name = "ahash" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf6ccdb167abbf410dcb915cabd428929d7f6a04980b54a11f26a39f1c7f7107" +dependencies = [ + "cfg-if", + "getrandom 0.2.8", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "0.7.20" @@ -1573,7 +1585,7 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" dependencies = [ - "ahash", + "ahash 0.7.6", ] [[package]] @@ -1582,9 +1594,15 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ - "ahash", + "ahash 0.7.6", ] +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" + [[package]] name = "hdrhistogram" version = "7.5.2" @@ -2243,6 +2261,7 @@ dependencies = [ "parking_lot", "rand 0.8.5", "regex", + "schnellru", "serde", "serde_json", "serial_test 0.8.0", @@ -2463,7 +2482,6 @@ dependencies = [ "serial_test 0.10.0", "tempfile", "tracing", - "wasmer", ] [[package]] @@ -3930,6 +3948,17 @@ dependencies = [ "windows-sys 0.36.1", ] +[[package]] +name = "schnellru" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18b6778edaf75c32e4f919526092db16db6c49296e219005925ed9777e5b263d" +dependencies = [ + "ahash 0.8.2", + "cfg-if", + "hashbrown 0.13.2", +] + [[package]] name = "scopeguard" version = "1.1.0" diff --git a/massa-execution-exports/src/settings.rs b/massa-execution-exports/src/settings.rs index 7a140dd39cd..c85ace45eb8 100644 --- a/massa-execution-exports/src/settings.rs +++ b/massa-execution-exports/src/settings.rs @@ -57,6 +57,8 @@ pub struct ExecutionConfig { pub max_bytecode_size: u64, /// Max datastore value size pub max_datastore_value_size: u64, + /// Max size of the module cache + pub max_module_cache_size: u32, /// Storage cost constants pub storage_costs_constants: StorageCostsConstants, /// Max gas for read only executions diff --git a/massa-execution-worker/Cargo.toml b/massa-execution-worker/Cargo.toml index def3ac0fe13..20a2c7e5c71 100644 --- a/massa-execution-worker/Cargo.toml +++ b/massa-execution-worker/Cargo.toml @@ -10,13 +10,12 @@ edition = "2021" anyhow = "1.0" rand = "0.8" rand_xoshiro = "0.6" -criterion = {version = "0.4", optional = true} +criterion = { version = "0.4", optional = true } parking_lot = { version = "0.12", features = ["deadlock_detection"] } tracing = "0.1" serde_json = "1.0" num = { version = "0.4", features = ["serde"] } -tempfile = { version = "3.3", optional = true } # use with gas_calibration feature -wasmer = { version = "3.0" } +tempfile = { version = "3.3", optional = true } # use with gas_calibration feature # custom modules massa_async_pool = { path = "../massa-async-pool" } massa_executed_ops = { path = "../massa-executed-ops" } @@ -37,7 +36,7 @@ massa_final_state = { path = "../massa-final-state" } massa_pos_worker = { path = "../massa-pos-worker" } serial_test = "0.10" tempfile = "3.2" -massa_ledger_worker = { path = "../massa-ledger-worker"} +massa_ledger_worker = { path = "../massa-ledger-worker" } # custom modules with testing enabled massa_execution_exports = { path = "../massa-execution-exports", features = [ "testing", @@ -50,7 +49,13 @@ harness = false [features] sandbox = ["massa_async_pool/sandbox"] -gas_calibration = ["massa_execution_exports/gas_calibration", "massa_final_state/testing", "massa_pos_worker", "massa_ledger_worker", "tempfile"] +gas_calibration = [ + "massa_execution_exports/gas_calibration", + "massa_final_state/testing", + "massa_pos_worker", + "massa_ledger_worker", + "tempfile", +] testing = [ "massa_execution_exports/testing", "massa_ledger_exports/testing", @@ -59,4 +64,9 @@ testing = [ ] # This feature is useful as we want to have code that is compiled only when running benchmarks -benchmarking = ["criterion", "massa_pos_worker", "massa_ledger_worker", "tempfile"] \ No newline at end of file +benchmarking = [ + "criterion", + "massa_pos_worker", + "massa_ledger_worker", + "tempfile", +] diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 8a8e347d288..336d2010594 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -18,12 +18,11 @@ use massa_execution_exports::{ ReadOnlyExecutionOutput, ReadOnlyExecutionRequest, ReadOnlyExecutionTarget, }; use massa_final_state::FinalState; -use massa_hash::Hash; use massa_ledger_exports::{SetOrDelete, SetUpdateOrDelete}; use massa_models::address::ExecutionAddressCycleInfo; use massa_models::api::EventFilter; use massa_models::output_event::SCOutputEvent; -use massa_models::prehash::{PreHashMap, PreHashSet}; +use massa_models::prehash::{PreHashSet}; use massa_models::stats::ExecutionStats; use massa_models::{ address::Address, @@ -32,13 +31,12 @@ use massa_models::{ }; use massa_models::{amount::Amount, slot::Slot}; use massa_pos_exports::SelectorController; -use massa_sc_runtime::{init_engine, Interface}; +use massa_sc_runtime::{Interface, ModuleCache}; use massa_storage::Storage; use parking_lot::{Mutex, RwLock}; use std::collections::{BTreeMap, BTreeSet}; use std::sync::Arc; use tracing::{debug, info, warn}; -use wasmer::{Engine, Module}; /// Used to acquire a lock on the execution context macro_rules! context_guard { @@ -72,8 +70,8 @@ pub(crate) struct ExecutionState { execution_interface: Box, // execution statistics stats_counter: ExecutionStatsCounter, - // TODO - sc_cache: PreHashMap, + // cache of pre compiled sc modules + module_cache: Arc>, } impl ExecutionState { @@ -119,30 +117,11 @@ impl ExecutionState { active_cursor: last_final_slot, final_cursor: last_final_slot, stats_counter: ExecutionStatsCounter::new(config.stats_time_window_duration), + module_cache: Arc::new(RwLock::new(ModuleCache::new(config.max_module_cache_size))), config, - sc_cache: PreHashMap::default(), } } - /// Internal function that creates the engine and retrieves the bytcode for a runtime call - fn init_runtime_execution( - &mut self, - bytecode: &[u8], - max_gas: u64, - ) -> Result<(Engine, Module), ExecutionError> { - // IMPORTANT TODO: update error type to handle this - let engine = init_engine(self.config.gas_costs.clone(), max_gas).unwrap(); - let key = Hash::compute_from(bytecode); - let binary_module = if let Some(module) = self.sc_cache.get(&key) { - module.clone() - } else { - let module = Module::new(&engine, bytecode).unwrap(); - self.sc_cache.insert(key, module.clone()); - module - }; - Ok((engine, binary_module)) - } - /// Get execution statistics pub fn get_stats(&self) -> ExecutionStats { self.stats_counter.get_stats(self.active_cursor) @@ -526,14 +505,12 @@ impl ExecutionState { }]; }; - // init runtime engine and retrieve the binary module - let (engine, binary_module) = self.init_runtime_execution(bytecode, *max_gas)?; - // run the VM on the bytecode contained in the operation match massa_sc_runtime::run_main( &*self.execution_interface, - &engine, - binary_module, + &bytecode, + self.module_cache.clone(), + *max_gas, self.config.gas_costs.clone(), ) { Ok(_response) => {} @@ -623,16 +600,14 @@ impl ExecutionState { bytecode = context.get_bytecode(&target_addr).unwrap_or_default(); } - // init runtime engine and retrieve the binary module - let (engine, binary_module) = self.init_runtime_execution(&bytecode, max_gas)?; - // run the VM on the bytecode contained in the operation match massa_sc_runtime::run_function( &*self.execution_interface, - &engine, - binary_module, + &bytecode, &target_func, ¶m, + self.module_cache.clone(), + max_gas, self.config.gas_costs.clone(), ) { Ok(_response) => {} @@ -716,16 +691,14 @@ impl ExecutionState { bytecode }; - // init runtime engine and retrieve the binary module - let (engine, binary_module) = self.init_runtime_execution(&bytecode, message.max_gas)?; - // run the VM on the bytecode contained in the operation if let Err(err) = massa_sc_runtime::run_function( &*self.execution_interface, - &engine, - binary_module, + &bytecode, &message.handler, &message.data, + self.module_cache.clone(), + message.max_gas, self.config.gas_costs.clone(), ) { // execution failed: reset context to snapshot and reimburse sender @@ -1078,15 +1051,12 @@ impl ExecutionState { // set the execution context for execution *context_guard!(self) = execution_context; - // init runtime engine and retrieve the binary module - let (engine, binary_module) = - self.init_runtime_execution(&bytecode, req.max_gas)?; - // run the bytecode's main function massa_sc_runtime::run_main( &*self.execution_interface, - &engine, - binary_module, + &bytecode, + self.module_cache.clone(), + req.max_gas, self.config.gas_costs.clone(), ) .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? @@ -1104,17 +1074,14 @@ impl ExecutionState { // set the execution context for execution *context_guard!(self) = execution_context; - // init runtime engine and retrieve the binary module - let (engine, binary_module) = - self.init_runtime_execution(&bytecode, req.max_gas)?; - // run the target function in the bytecode massa_sc_runtime::run_function( &*self.execution_interface, - &engine, - binary_module, + &bytecode, &target_func, ¶meter, + self.module_cache.clone(), + req.max_gas, self.config.gas_costs.clone(), ) .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? diff --git a/massa-node/src/main.rs b/massa-node/src/main.rs index bcc6098d21b..7b56d08b27a 100644 --- a/massa-node/src/main.rs +++ b/massa-node/src/main.rs @@ -328,6 +328,7 @@ async fn launch( max_datastore_key_length: MAX_DATASTORE_KEY_LENGTH, max_bytecode_size: MAX_BYTECODE_LENGTH, max_datastore_value_size: MAX_DATASTORE_VALUE_LENGTH, + max_module_cache_size: 4242, storage_costs_constants, max_read_only_gas: SETTINGS.execution.max_read_only_gas, gas_costs: GasCosts::new( From c7cfe2996a580946f54f5ab26b9a00c9752256d4 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Fri, 13 Jan 2023 15:45:15 +0100 Subject: [PATCH 23/80] update settings --- massa-execution-worker/src/execution.rs | 6 +++--- massa-node/base_config/config.toml | 2 ++ massa-node/src/main.rs | 2 +- massa-node/src/settings.rs | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 336d2010594..c4357a157ec 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -22,7 +22,7 @@ use massa_ledger_exports::{SetOrDelete, SetUpdateOrDelete}; use massa_models::address::ExecutionAddressCycleInfo; use massa_models::api::EventFilter; use massa_models::output_event::SCOutputEvent; -use massa_models::prehash::{PreHashSet}; +use massa_models::prehash::PreHashSet; use massa_models::stats::ExecutionStats; use massa_models::{ address::Address, @@ -604,8 +604,8 @@ impl ExecutionState { match massa_sc_runtime::run_function( &*self.execution_interface, &bytecode, - &target_func, - ¶m, + target_func, + param, self.module_cache.clone(), max_gas, self.config.gas_costs.clone(), diff --git a/massa-node/base_config/config.toml b/massa-node/base_config/config.toml index 7a633fc5254..6ee27495983 100644 --- a/massa-node/base_config/config.toml +++ b/massa-node/base_config/config.toml @@ -54,6 +54,8 @@ abi_gas_costs_file = "base_config/gas_costs/abi_gas_costs.json" # gas cost for wasm operator wasm_gas_costs_file = "base_config/gas_costs/wasm_gas_costs.json" + # maximum size of the pre compiled module cache + max_module_cache_size = 100 [ledger] # path to the initial ledger diff --git a/massa-node/src/main.rs b/massa-node/src/main.rs index 7b56d08b27a..b91bbbe68da 100644 --- a/massa-node/src/main.rs +++ b/massa-node/src/main.rs @@ -328,7 +328,7 @@ async fn launch( max_datastore_key_length: MAX_DATASTORE_KEY_LENGTH, max_bytecode_size: MAX_BYTECODE_LENGTH, max_datastore_value_size: MAX_DATASTORE_VALUE_LENGTH, - max_module_cache_size: 4242, + max_module_cache_size: SETTINGS.execution.max_module_cache_size, storage_costs_constants, max_read_only_gas: SETTINGS.execution.max_read_only_gas, gas_costs: GasCosts::new( diff --git a/massa-node/src/settings.rs b/massa-node/src/settings.rs index 7185157df26..78767035c05 100644 --- a/massa-node/src/settings.rs +++ b/massa-node/src/settings.rs @@ -29,6 +29,7 @@ pub struct ExecutionSettings { pub max_read_only_gas: u64, pub abi_gas_costs_file: PathBuf, pub wasm_gas_costs_file: PathBuf, + pub max_module_cache_size: u32, } #[derive(Clone, Debug, Deserialize)] From c4db941eb6621a9036dba78eee017e862db0e3a9 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Fri, 13 Jan 2023 15:55:44 +0100 Subject: [PATCH 24/80] remove unused mutable refs --- massa-execution-worker/src/execution.rs | 14 +++++++------- massa-execution-worker/src/worker.rs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index c4357a157ec..83e59a1cf9b 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -194,7 +194,7 @@ impl ExecutionState { /// * `remaining_block_gas`: mutable reference towards the remaining gas in the block /// * `block_credits`: mutable reference towards the total block reward/fee credits pub fn execute_operation( - &mut self, + &self, operation: &SecureShareOperation, block_slot: Slot, remaining_block_gas: &mut u64, @@ -474,7 +474,7 @@ impl ExecutionState { /// * `operation`: the `WrappedOperation` to process, must be an `ExecuteSC` /// * `sender_addr`: address of the sender pub fn execute_executesc_op( - &mut self, + &self, operation: &OperationType, sender_addr: Address, ) -> Result<(), ExecutionError> { @@ -535,7 +535,7 @@ impl ExecutionState { /// * `operation_id`: ID of the operation /// * `sender_addr`: address of the sender pub fn execute_callsc_op( - &mut self, + &self, operation: &OperationType, sender_addr: Address, ) -> Result<(), ExecutionError> { @@ -600,7 +600,7 @@ impl ExecutionState { bytecode = context.get_bytecode(&target_addr).unwrap_or_default(); } - // run the VM on the bytecode contained in the operation + // run the VM on the bytecode loaded from the target address match massa_sc_runtime::run_function( &*self.execution_interface, &bytecode, @@ -630,7 +630,7 @@ impl ExecutionState { /// * message: message information /// * bytecode: executable target bytecode, or None if unavailable pub fn execute_async_message( - &mut self, + &self, message: AsyncMessage, bytecode: Option>, ) -> Result<(), ExecutionError> { @@ -726,7 +726,7 @@ impl ExecutionState { /// # Returns /// An `ExecutionOutput` structure summarizing the output of the executed slot pub fn execute_slot( - &mut self, + &self, slot: &Slot, exec_target: Option<&(BlockId, Storage)>, selector: Box, @@ -1015,7 +1015,7 @@ impl ExecutionState { /// # Returns /// `ExecutionOutput` describing the output of the execution, or an error pub(crate) fn execute_readonly_request( - &mut self, + &self, req: ReadOnlyExecutionRequest, ) -> Result { // TODO ensure that speculative things are reset after every execution ends (incl. on error and readonly) diff --git a/massa-execution-worker/src/worker.rs b/massa-execution-worker/src/worker.rs index 321b406968b..667d2feaee8 100644 --- a/massa-execution-worker/src/worker.rs +++ b/massa-execution-worker/src/worker.rs @@ -86,7 +86,7 @@ impl ExecutionThread { let (req, resp_tx) = req_resp.into_request_sender_pair(); // Acquire read access to the execution state and execute the read-only request - let outcome = self.execution_state.write().execute_readonly_request(req); + let outcome = self.execution_state.read().execute_readonly_request(req); // Send the execution output through resp_tx. // Ignore errors because they just mean that the request emitter dropped the received From 8424e660d7de9293811724edac6bdabcd8c6c48a Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA <22281426+aoudiamoncef@users.noreply.github.com> Date: Mon, 16 Jan 2023 14:50:53 +0100 Subject: [PATCH 25/80] Broadcast local operations (#3415) --- Cargo.lock | 2 ++ massa-api/src/api.rs | 8 +++---- massa-api/src/lib.rs | 8 +++---- massa-node/base_config/config.toml | 4 ++-- massa-node/src/main.rs | 22 +++++++++++++------ massa-node/src/settings.rs | 4 ++-- massa-pool-exports/Cargo.toml | 1 + massa-pool-exports/src/channels.rs | 8 +++++++ massa-pool-exports/src/config.rs | 4 ++++ massa-pool-exports/src/lib.rs | 2 ++ massa-pool-exports/src/test_exports/config.rs | 2 ++ massa-pool-worker/Cargo.toml | 1 + massa-pool-worker/src/operation_pool.rs | 18 +++++++++++---- .../src/tests/operation_pool_tests.rs | 11 ++++++++-- massa-pool-worker/src/tests/tools.rs | 21 +++++++++++++----- massa-pool-worker/src/worker.rs | 9 ++++---- massa-protocol-exports/src/channels.rs | 3 --- massa-protocol-exports/src/settings.rs | 4 ---- massa-protocol-exports/src/tests/tools.rs | 2 -- massa-protocol-worker/src/protocol_worker.rs | 13 ----------- massa-protocol-worker/src/tests/tools.rs | 5 +---- 21 files changed, 92 insertions(+), 60 deletions(-) create mode 100644 massa-pool-exports/src/channels.rs diff --git a/Cargo.lock b/Cargo.lock index 0babbb82eb5..689d0ea2ba3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2669,6 +2669,7 @@ dependencies = [ "massa_storage", "massa_time", "serde", + "tokio", ] [[package]] @@ -2683,6 +2684,7 @@ dependencies = [ "massa_storage", "num", "parking_lot", + "tokio", "tracing", ] diff --git a/massa-api/src/api.rs b/massa-api/src/api.rs index 5e9f2ea4d19..fff7592d83a 100644 --- a/massa-api/src/api.rs +++ b/massa-api/src/api.rs @@ -11,7 +11,7 @@ use jsonrpsee::types::SubscriptionResult; use jsonrpsee::SubscriptionSink; use massa_consensus_exports::ConsensusChannels; use massa_models::version::Version; -use massa_protocol_exports::ProtocolSenders; +use massa_pool_exports::PoolChannels; use serde::Serialize; use tokio_stream::wrappers::BroadcastStream; @@ -19,13 +19,13 @@ impl API { /// generate a new massa API pub fn new( consensus_channels: ConsensusChannels, - protocol_senders: ProtocolSenders, + pool_channels: PoolChannels, api_settings: APIConfig, version: Version, ) -> Self { API(ApiV2 { consensus_channels, - protocol_senders, + pool_channels, api_settings, version, }) @@ -66,7 +66,7 @@ impl MassaApiServer for API { } fn subscribe_new_operations(&self, sink: SubscriptionSink) -> SubscriptionResult { - broadcast_via_ws(self.0.protocol_senders.operation_sender.clone(), sink); + broadcast_via_ws(self.0.pool_channels.operation_sender.clone(), sink); Ok(()) } } diff --git a/massa-api/src/lib.rs b/massa-api/src/lib.rs index b6b72e5333e..f3c7e76649b 100644 --- a/massa-api/src/lib.rs +++ b/massa-api/src/lib.rs @@ -32,9 +32,9 @@ use massa_models::{ version::Version, }; use massa_network_exports::{NetworkCommandSender, NetworkConfig}; -use massa_pool_exports::PoolController; +use massa_pool_exports::{PoolChannels, PoolController}; use massa_pos_exports::SelectorController; -use massa_protocol_exports::{ProtocolCommandSender, ProtocolSenders}; +use massa_protocol_exports::ProtocolCommandSender; use massa_storage::Storage; use massa_wallet::Wallet; use parking_lot::RwLock; @@ -98,8 +98,8 @@ pub struct Private { pub struct ApiV2 { /// link(channels) to the consensus component pub consensus_channels: ConsensusChannels, - /// link(channels) to the protocol component - pub protocol_senders: ProtocolSenders, + /// link(channels) to the pool component + pub pool_channels: PoolChannels, /// API settings pub api_settings: APIConfig, /// node version diff --git a/massa-node/base_config/config.toml b/massa-node/base_config/config.toml index d32b9280b51..0e576e2cc74 100644 --- a/massa-node/base_config/config.toml +++ b/massa-node/base_config/config.toml @@ -132,8 +132,6 @@ max_operations_propagation_time = 32000 # time threshold after which endorsement are not propagated max_endorsements_propagation_time = 48000 - # operations sender(channel) capacity - broadcast_operations_capacity = 5000 [network] # port on which to listen for protocol communication @@ -254,6 +252,8 @@ max_endorsement_count = 10000 # max number of items returned per query max_item_return_count = 100 + # operations sender(channel) capacity + broadcast_operations_capacity = 5000 [selector] # maximum number of computed cycle's draws we keep in cache diff --git a/massa-node/src/main.rs b/massa-node/src/main.rs index 411025e8f23..7c675741975 100644 --- a/massa-node/src/main.rs +++ b/massa-node/src/main.rs @@ -47,7 +47,7 @@ use massa_models::config::constants::{ use massa_models::config::CONSENSUS_BOOTSTRAP_PART_SIZE; use massa_network_exports::{Establisher, NetworkConfig, NetworkManager}; use massa_network_worker::start_network_controller; -use massa_pool_exports::{PoolConfig, PoolManager}; +use massa_pool_exports::{PoolChannels, PoolConfig, PoolManager}; use massa_pool_worker::start_pool_controller; use massa_pos_exports::{PoSConfig, SelectorConfig, SelectorManager}; use massa_pos_worker::start_selector_worker; @@ -354,9 +354,20 @@ async fn launch( max_operation_pool_size_per_thread: SETTINGS.pool.max_pool_size_per_thread, max_endorsements_pool_size_per_thread: SETTINGS.pool.max_pool_size_per_thread, channels_size: POOL_CONTROLLER_CHANNEL_SIZE, + broadcast_enabled: SETTINGS.api.enable_ws, + broadcast_operations_capacity: SETTINGS.pool.broadcast_operations_capacity, + }; + + let pool_channels = PoolChannels { + operation_sender: broadcast::channel(pool_config.broadcast_operations_capacity).0, }; - let (pool_manager, pool_controller) = - start_pool_controller(pool_config, &shared_storage, execution_controller.clone()); + + let (pool_manager, pool_controller) = start_pool_controller( + pool_config, + &shared_storage, + execution_controller.clone(), + pool_channels.clone(), + ); let (protocol_command_sender, protocol_command_receiver) = mpsc::channel::(PROTOCOL_CONTROLLER_CHANNEL_SIZE); @@ -441,13 +452,10 @@ async fn launch( t0: T0, max_operations_propagation_time: SETTINGS.protocol.max_operations_propagation_time, max_endorsements_propagation_time: SETTINGS.protocol.max_endorsements_propagation_time, - broadcast_enabled: SETTINGS.api.enable_ws, - broadcast_operations_capacity: SETTINGS.protocol.broadcast_operations_capacity, }; let protocol_senders = ProtocolSenders { network_command_sender: network_command_sender.clone(), - operation_sender: broadcast::channel(protocol_config.broadcast_operations_capacity).0, }; let protocol_receivers = ProtocolReceivers { @@ -531,7 +539,7 @@ async fn launch( // spawn Massa API let api = API::::new( consensus_channels, - protocol_senders, + pool_channels, api_config.clone(), *VERSION, ); diff --git a/massa-node/src/settings.rs b/massa-node/src/settings.rs index 695c0b78562..7d8b85df7a5 100644 --- a/massa-node/src/settings.rs +++ b/massa-node/src/settings.rs @@ -111,6 +111,8 @@ pub struct PoolSettings { pub max_operation_future_validity_start_periods: u64, pub max_endorsement_count: u64, pub max_item_return_count: usize, + /// operations sender(channel) capacity + pub broadcast_operations_capacity: usize, } /// API and server configuration, read from a file configuration. @@ -220,8 +222,6 @@ pub struct ProtocolSettings { pub max_operations_propagation_time: MassaTime, /// Time threshold after which operation are not propagated pub max_endorsements_propagation_time: MassaTime, - /// operations sender(channel) capacity - pub broadcast_operations_capacity: usize, } #[cfg(test)] diff --git a/massa-pool-exports/Cargo.toml b/massa-pool-exports/Cargo.toml index 6eaab6f8577..a30134f2a5e 100644 --- a/massa-pool-exports/Cargo.toml +++ b/massa-pool-exports/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] serde = { version = "1.0", features = ["derive"] } +tokio = { version = "1.23", features = ["sync"] } # custom modules massa_models = { path = "../massa-models" } massa_storage = { path = "../massa-storage" } diff --git a/massa-pool-exports/src/channels.rs b/massa-pool-exports/src/channels.rs new file mode 100644 index 00000000000..b44ec4da659 --- /dev/null +++ b/massa-pool-exports/src/channels.rs @@ -0,0 +1,8 @@ +use massa_models::operation::Operation; + +/// channels used by the pool worker +#[derive(Clone)] +pub struct PoolChannels { + /// Broadcast sender(channel) for new operations + pub operation_sender: tokio::sync::broadcast::Sender, +} diff --git a/massa-pool-exports/src/config.rs b/massa-pool-exports/src/config.rs index af41e3bddbe..80f3636baa1 100644 --- a/massa-pool-exports/src/config.rs +++ b/massa-pool-exports/src/config.rs @@ -24,4 +24,8 @@ pub struct PoolConfig { pub max_block_endorsement_count: u32, /// operations and endorsements communication channels size pub channels_size: usize, + /// Whether WebSockets are enabled + pub broadcast_enabled: bool, + /// operations sender(channel) capacity + pub broadcast_operations_capacity: usize, } diff --git a/massa-pool-exports/src/lib.rs b/massa-pool-exports/src/lib.rs index 93e7cd7d3f3..7a30ca80bef 100644 --- a/massa-pool-exports/src/lib.rs +++ b/massa-pool-exports/src/lib.rs @@ -5,9 +5,11 @@ #![warn(missing_docs)] #![warn(unused_crate_dependencies)] +mod channels; mod config; mod controller_traits; +pub use channels::PoolChannels; pub use config::PoolConfig; pub use controller_traits::{PoolController, PoolManager}; diff --git a/massa-pool-exports/src/test_exports/config.rs b/massa-pool-exports/src/test_exports/config.rs index 5f40d6972b5..077117bc225 100644 --- a/massa-pool-exports/src/test_exports/config.rs +++ b/massa-pool-exports/src/test_exports/config.rs @@ -19,6 +19,8 @@ impl Default for PoolConfig { max_endorsements_pool_size_per_thread: 1000, max_block_endorsement_count: ENDORSEMENT_COUNT, channels_size: 1024, + broadcast_enabled: false, + broadcast_operations_capacity: 5000, } } } diff --git a/massa-pool-worker/Cargo.toml b/massa-pool-worker/Cargo.toml index dcbd3334ad2..be4a15529a4 100644 --- a/massa-pool-worker/Cargo.toml +++ b/massa-pool-worker/Cargo.toml @@ -15,6 +15,7 @@ massa_pool_exports = { path = "../massa-pool-exports" } massa_execution_exports = { path = "../massa-execution-exports" } [dev-dependencies] +tokio = { version = "1.23", features = ["sync"] } massa_signature = { path = "../massa-signature" } massa_hash = { path = "../massa-hash" } massa_pool_exports = { path = "../massa-pool-exports", features = [ "testing" ] } diff --git a/massa-pool-worker/src/operation_pool.rs b/massa-pool-worker/src/operation_pool.rs index 661873c7a1a..9ddbacef6d1 100644 --- a/massa-pool-worker/src/operation_pool.rs +++ b/massa-pool-worker/src/operation_pool.rs @@ -8,7 +8,7 @@ use massa_models::{ prehash::{CapacityAllocator, PreHashMap, PreHashSet}, slot::Slot, }; -use massa_pool_exports::PoolConfig; +use massa_pool_exports::{PoolChannels, PoolConfig}; use massa_storage::Storage; use std::collections::BTreeSet; @@ -35,6 +35,9 @@ pub struct OperationPool { /// last consensus final periods, per thread last_cs_final_periods: Vec, + + /// channels used by the pool worker + channels: PoolChannels, } impl OperationPool { @@ -42,6 +45,7 @@ impl OperationPool { config: PoolConfig, storage: &Storage, execution_controller: Box, + channels: PoolChannels, ) -> Self { OperationPool { operations: Default::default(), @@ -51,6 +55,7 @@ impl OperationPool { config, storage: storage.clone_without_refs(), execution_controller, + channels, } } @@ -112,10 +117,15 @@ impl OperationPool { { let ops = ops_storage.read_operations(); for op_id in items { + let op = ops + .get(&op_id) + .expect("attempting to add operation to pool, but it is absent from storage"); + // Broadcast operation to active sender(channel) subscribers. + if self.config.broadcast_enabled { + let _ = self.channels.operation_sender.send(op.content.clone()); + } let op_info = OperationInfo::from_op( - ops.get(&op_id).expect( - "attempting to add operation to pool, but it is absent from storage", - ), + op, self.config.operation_validity_periods, self.config.roll_price, self.config.thread_count, diff --git a/massa-pool-worker/src/tests/operation_pool_tests.rs b/massa-pool-worker/src/tests/operation_pool_tests.rs index 044e00030f1..07823d8fb6a 100644 --- a/massa-pool-worker/src/tests/operation_pool_tests.rs +++ b/massa-pool-worker/src/tests/operation_pool_tests.rs @@ -28,10 +28,11 @@ use massa_models::{ secure_share::SecureShareContent, slot::Slot, }; -use massa_pool_exports::PoolConfig; +use massa_pool_exports::{PoolChannels, PoolConfig}; use massa_signature::KeyPair; use massa_storage::Storage; use std::str::FromStr; +use tokio::sync::broadcast; #[test] fn test_add_operation() { @@ -80,7 +81,13 @@ fn test_pool() { let (execution_controller, _execution_receiver) = MockExecutionController::new_with_receiver(); let pool_config = PoolConfig::default(); let storage_base = Storage::create_root(); - let mut pool = OperationPool::init(pool_config, &storage_base, execution_controller); + let operation_sender = broadcast::channel(pool_config.broadcast_operations_capacity).0; + let mut pool = OperationPool::init( + pool_config, + &storage_base, + execution_controller, + PoolChannels { operation_sender }, + ); // generate (id, transactions, range of validity) by threads let mut thread_tx_lists = vec![Vec::new(); pool_config.thread_count as usize]; for i in 0..18 { diff --git a/massa-pool-worker/src/tests/tools.rs b/massa-pool-worker/src/tests/tools.rs index add5d139135..5289ba491c3 100644 --- a/massa-pool-worker/src/tests/tools.rs +++ b/massa-pool-worker/src/tests/tools.rs @@ -14,11 +14,12 @@ use massa_models::{ secure_share::SecureShareContent, slot::Slot, }; -use massa_pool_exports::{PoolConfig, PoolController, PoolManager}; +use massa_pool_exports::{PoolChannels, PoolConfig, PoolController, PoolManager}; use massa_signature::{KeyPair, PublicKey}; use massa_storage::Storage; use std::str::FromStr; use std::sync::mpsc::Receiver; +use tokio::sync::broadcast; /// Tooling to create a transaction with an expire periods /// TODO move tooling in a dedicated module @@ -61,10 +62,14 @@ where ), { let storage: Storage = Storage::create_root(); - + let operation_sender = broadcast::channel(5000).0; let (execution_controller, execution_receiver) = MockExecutionController::new_with_receiver(); - let (pool_manager, pool_controller) = - start_pool_controller(cfg, &storage, execution_controller); + let (pool_manager, pool_controller) = start_pool_controller( + cfg, + &storage, + execution_controller, + PoolChannels { operation_sender }, + ); test(pool_manager, pool_controller, execution_receiver, storage) } @@ -73,10 +78,16 @@ pub fn operation_pool_test(cfg: PoolConfig, test: F) where F: FnOnce(OperationPool, Storage), { + let operation_sender = broadcast::channel(5000).0; let (execution_controller, _) = MockExecutionController::new_with_receiver(); let storage = Storage::create_root(); test( - OperationPool::init(cfg, &storage.clone_without_refs(), execution_controller), + OperationPool::init( + cfg, + &storage.clone_without_refs(), + execution_controller, + PoolChannels { operation_sender }, + ), storage, ) } diff --git a/massa-pool-worker/src/worker.rs b/massa-pool-worker/src/worker.rs index 23bf89dbfe2..918f0ed4468 100644 --- a/massa-pool-worker/src/worker.rs +++ b/massa-pool-worker/src/worker.rs @@ -7,14 +7,13 @@ use crate::operation_pool::OperationPool; use crate::{controller_impl::PoolControllerImpl, endorsement_pool::EndorsementPool}; use massa_execution_exports::ExecutionController; use massa_pool_exports::PoolConfig; -use massa_pool_exports::{PoolController, PoolManager}; +use massa_pool_exports::{PoolChannels, PoolController, PoolManager}; use massa_storage::Storage; use parking_lot::RwLock; -use std::sync::mpsc::RecvError; -use std::thread; use std::{ - sync::mpsc::{sync_channel, Receiver}, + sync::mpsc::{sync_channel, Receiver, RecvError}, sync::Arc, + thread, thread::JoinHandle, }; @@ -112,6 +111,7 @@ pub fn start_pool_controller( config: PoolConfig, storage: &Storage, execution_controller: Box, + channels: PoolChannels, ) -> (Box, Box) { let (operations_input_sender, operations_input_receiver) = sync_channel(config.channels_size); let (endorsements_input_sender, endorsements_input_receiver) = @@ -120,6 +120,7 @@ pub fn start_pool_controller( config, storage, execution_controller, + channels, ))); let endorsement_pool = Arc::new(RwLock::new(EndorsementPool::init(config, storage))); let controller = PoolControllerImpl { diff --git a/massa-protocol-exports/src/channels.rs b/massa-protocol-exports/src/channels.rs index 57b29d61f16..4189843c3c9 100644 --- a/massa-protocol-exports/src/channels.rs +++ b/massa-protocol-exports/src/channels.rs @@ -1,4 +1,3 @@ -use massa_models::operation::Operation; use massa_network_exports::{NetworkCommandSender, NetworkEventReceiver}; use tokio::sync::mpsc; @@ -10,8 +9,6 @@ use crate::ProtocolCommand; pub struct ProtocolSenders { /// network command sender pub network_command_sender: NetworkCommandSender, - /// Broadcast sender(channel) for new operations - pub operation_sender: tokio::sync::broadcast::Sender, } /// Contains channels(receivers) used by the protocol worker diff --git a/massa-protocol-exports/src/settings.rs b/massa-protocol-exports/src/settings.rs index d8b3ed0c7c2..6c2ad08291a 100644 --- a/massa-protocol-exports/src/settings.rs +++ b/massa-protocol-exports/src/settings.rs @@ -55,8 +55,4 @@ pub struct ProtocolConfig { pub max_operations_propagation_time: MassaTime, /// max time we propagate endorsements pub max_endorsements_propagation_time: MassaTime, - /// Whether WebSockets are enabled - pub broadcast_enabled: bool, - /// operations sender(channel) capacity - pub broadcast_operations_capacity: usize, } diff --git a/massa-protocol-exports/src/tests/tools.rs b/massa-protocol-exports/src/tests/tools.rs index dd46166c9b7..04f2f2b16a5 100644 --- a/massa-protocol-exports/src/tests/tools.rs +++ b/massa-protocol-exports/src/tests/tools.rs @@ -226,8 +226,6 @@ pub fn create_protocol_config() -> ProtocolConfig { t0: MassaTime::from_millis(16000), max_operations_propagation_time: MassaTime::from_millis(30000), max_endorsements_propagation_time: MassaTime::from_millis(60000), - broadcast_enabled: false, - broadcast_operations_capacity: 5000, } } diff --git a/massa-protocol-worker/src/protocol_worker.rs b/massa-protocol-worker/src/protocol_worker.rs index 2f3ebcbdc8e..77ebe195eee 100644 --- a/massa-protocol-worker/src/protocol_worker.rs +++ b/massa-protocol-worker/src/protocol_worker.rs @@ -8,7 +8,6 @@ use crate::{node_info::NodeInfo, worker_operations_impl::OperationBatchBuffer}; use massa_consensus_exports::ConsensusController; use massa_logging::massa_trace; -use massa_models::operation::Operation; use massa_models::secure_share::Id; use massa_models::slot::Slot; use massa_models::timeslots::get_block_slot_timestamp; @@ -69,7 +68,6 @@ pub async fn start_protocol_controller( network_event_receiver: receivers.network_event_receiver, controller_command_rx: receivers.protocol_command_receiver, controller_manager_rx, - operation_sender: senders.operation_sender, }, consensus_controller, pool_controller, @@ -133,8 +131,6 @@ pub struct ProtocolWorker { controller_command_rx: mpsc::Receiver, /// Channel to send management commands to the controller. controller_manager_rx: mpsc::Receiver, - /// Broadcast sender(channel) for new operations - operation_sender: tokio::sync::broadcast::Sender, /// Ids of active nodes mapped to node info. pub(crate) active_nodes: HashMap, /// List of wanted blocks, @@ -166,8 +162,6 @@ pub struct ProtocolWorkerChannels { pub controller_command_rx: mpsc::Receiver, /// protocol management command receiver pub controller_manager_rx: mpsc::Receiver, - /// Broadcast sender(channel) for new operations - pub operation_sender: tokio::sync::broadcast::Sender, } impl ProtocolWorker { @@ -186,7 +180,6 @@ impl ProtocolWorker { network_event_receiver, controller_command_rx, controller_manager_rx, - operation_sender, }: ProtocolWorkerChannels, consensus_controller: Box, pool_controller: Box, @@ -200,7 +193,6 @@ impl ProtocolWorker { pool_controller, controller_command_rx, controller_manager_rx, - operation_sender, active_nodes: Default::default(), block_wishlist: Default::default(), checked_endorsements: LinearHashCacheSet::new(config.max_known_endorsements_size), @@ -939,11 +931,6 @@ impl ProtocolWorker { } if !new_operations.is_empty() { - if self.config.broadcast_enabled { - for op in new_operations.clone() { - let _ = self.operation_sender.send(op.1.content); - } - } // Store operation, claim locally let mut ops = self.storage.clone_without_refs(); ops.store_operations(new_operations.into_values().collect()); diff --git a/massa-protocol-worker/src/tests/tools.rs b/massa-protocol-worker/src/tests/tools.rs index 9f56cda4155..87a7d027ef0 100644 --- a/massa-protocol-worker/src/tests/tools.rs +++ b/massa-protocol-worker/src/tests/tools.rs @@ -14,7 +14,7 @@ use massa_protocol_exports::{ ProtocolManager, ProtocolReceivers, ProtocolSenders, }; use massa_storage::Storage; -use tokio::sync::{broadcast, mpsc}; +use tokio::sync::mpsc; pub async fn protocol_test(protocol_config: &ProtocolConfig, test: F) where @@ -44,14 +44,12 @@ where // start protocol controller let (protocol_command_sender, protocol_command_receiver) = mpsc::channel(protocol_config.controller_channel_size); - let operation_sender = broadcast::channel(protocol_config.broadcast_operations_capacity).0; let protocol_receivers = ProtocolReceivers { network_event_receiver, protocol_command_receiver, }; let protocol_senders = ProtocolSenders { network_command_sender, - operation_sender, }; // start protocol controller let protocol_manager: ProtocolManager = start_protocol_controller( @@ -119,7 +117,6 @@ where let protocol_senders = ProtocolSenders { network_command_sender: network_command_sender.clone(), - operation_sender: broadcast::channel(protocol_config.broadcast_operations_capacity).0, }; let protocol_receivers = ProtocolReceivers { From 82045c92e2052ff208c38e06bcbe8d8b4f1ffa0e Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Mon, 16 Jan 2023 17:12:40 +0100 Subject: [PATCH 26/80] lru cache move to execution --- Cargo.lock | 2 +- massa-execution-worker/Cargo.toml | 4 +++- massa-execution-worker/src/execution.rs | 28 +++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 88697c6d741..53971bcd21c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2261,7 +2261,6 @@ dependencies = [ "parking_lot", "rand 0.8.5", "regex", - "schnellru", "serde", "serde_json", "serial_test 0.8.0", @@ -2478,6 +2477,7 @@ dependencies = [ "parking_lot", "rand 0.8.5", "rand_xoshiro", + "schnellru", "serde_json", "serial_test 0.10.0", "tempfile", diff --git a/massa-execution-worker/Cargo.toml b/massa-execution-worker/Cargo.toml index 20a2c7e5c71..fc856acc531 100644 --- a/massa-execution-worker/Cargo.toml +++ b/massa-execution-worker/Cargo.toml @@ -15,7 +15,9 @@ parking_lot = { version = "0.12", features = ["deadlock_detection"] } tracing = "0.1" serde_json = "1.0" num = { version = "0.4", features = ["serde"] } -tempfile = { version = "3.3", optional = true } # use with gas_calibration feature +schnellru = "0.2.0" +# use with gas_calibration feature +tempfile = { version = "3.3", optional = true } # custom modules massa_async_pool = { path = "../massa-async-pool" } massa_executed_ops = { path = "../massa-executed-ops" } diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 83e59a1cf9b..4c982d7d20f 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -31,7 +31,7 @@ use massa_models::{ }; use massa_models::{amount::Amount, slot::Slot}; use massa_pos_exports::SelectorController; -use massa_sc_runtime::{Interface, ModuleCache}; +use massa_sc_runtime::{Interface, RuntimeModule}; use massa_storage::Storage; use parking_lot::{Mutex, RwLock}; use std::collections::{BTreeMap, BTreeSet}; @@ -71,7 +71,7 @@ pub(crate) struct ExecutionState { // execution statistics stats_counter: ExecutionStatsCounter, // cache of pre compiled sc modules - module_cache: Arc>, + module_cache: LruMap, RuntimeModule>, } impl ExecutionState { @@ -122,6 +122,30 @@ impl ExecutionState { } } + // /// If the module is contained in the cache: + // /// * retrieve a copy of it + // /// * move it up in the LRU cache + // /// + // /// If the module is not contained in the cache: + // /// * create the module + // /// * save the module in the cache + // /// * retrieve a copy of it + // pub(crate) fn get_module( + // &mut self, + // bytecode: &[u8], + // limit: u64, + // gas_costs: GasCosts, + // ) -> Result { + // let module = if let Some(cached_module) = self.module_cache.get(bytecode) { + // cached_module.clone() + // } else { + // let new_module = Module::new(engine, bytecode)?; + // self.module_cache.insert(bytecode.to_vec(), new_module.clone()); + // new_module + // }; + // Ok(module) + // } + /// Get execution statistics pub fn get_stats(&self) -> ExecutionStats { self.stats_counter.get_stats(self.active_cursor) From f2a392f8a1984a686e45a5b56ffdb04af5d3ebd5 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Mon, 16 Jan 2023 17:35:07 +0100 Subject: [PATCH 27/80] start using LRU in exec --- massa-execution-worker/src/execution.rs | 73 +++++++++++-------------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 4c982d7d20f..3473d4cd384 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -31,9 +31,10 @@ use massa_models::{ }; use massa_models::{amount::Amount, slot::Slot}; use massa_pos_exports::SelectorController; -use massa_sc_runtime::{Interface, RuntimeModule}; +use massa_sc_runtime::{GasCosts, Interface, RuntimeModule}; use massa_storage::Storage; use parking_lot::{Mutex, RwLock}; +use schnellru::{ByLength, LruMap}; use std::collections::{BTreeMap, BTreeSet}; use std::sync::Arc; use tracing::{debug, info, warn}; @@ -117,34 +118,36 @@ impl ExecutionState { active_cursor: last_final_slot, final_cursor: last_final_slot, stats_counter: ExecutionStatsCounter::new(config.stats_time_window_duration), - module_cache: Arc::new(RwLock::new(ModuleCache::new(config.max_module_cache_size))), + module_cache: LruMap::new(ByLength::new(config.max_module_cache_size)), config, } } - // /// If the module is contained in the cache: - // /// * retrieve a copy of it - // /// * move it up in the LRU cache - // /// - // /// If the module is not contained in the cache: - // /// * create the module - // /// * save the module in the cache - // /// * retrieve a copy of it - // pub(crate) fn get_module( - // &mut self, - // bytecode: &[u8], - // limit: u64, - // gas_costs: GasCosts, - // ) -> Result { - // let module = if let Some(cached_module) = self.module_cache.get(bytecode) { - // cached_module.clone() - // } else { - // let new_module = Module::new(engine, bytecode)?; - // self.module_cache.insert(bytecode.to_vec(), new_module.clone()); - // new_module - // }; - // Ok(module) - // } + /// If the module is contained in the cache: + /// * retrieve a copy of it + /// * move it up in the LRU cache + /// + /// If the module is not contained in the cache: + /// * create the module + /// * save the module in the cache + /// * retrieve a copy of it + pub(crate) fn get_module( + &mut self, + bytecode: &[u8], + limit: u64, + gas_costs: GasCosts, + ) -> Result<(), ExecutionError> { + let module = if let Some(cached_module) = self.module_cache.get_mut(bytecode) { + cached_module.reinitialize_metadata(limit, gas_costs); + cached_module.clone() + } else { + let new_module = RuntimeModule::new(bytecode, limit, gas_costs)?; + self.module_cache + .insert(bytecode.to_vec(), new_module.clone()); + new_module + }; + Ok(module) + } /// Get execution statistics pub fn get_stats(&self) -> ExecutionStats { @@ -532,9 +535,7 @@ impl ExecutionState { // run the VM on the bytecode contained in the operation match massa_sc_runtime::run_main( &*self.execution_interface, - &bytecode, - self.module_cache.clone(), - *max_gas, + module, self.config.gas_costs.clone(), ) { Ok(_response) => {} @@ -627,11 +628,9 @@ impl ExecutionState { // run the VM on the bytecode loaded from the target address match massa_sc_runtime::run_function( &*self.execution_interface, - &bytecode, + module, target_func, param, - self.module_cache.clone(), - max_gas, self.config.gas_costs.clone(), ) { Ok(_response) => {} @@ -718,11 +717,9 @@ impl ExecutionState { // run the VM on the bytecode contained in the operation if let Err(err) = massa_sc_runtime::run_function( &*self.execution_interface, - &bytecode, + module, &message.handler, &message.data, - self.module_cache.clone(), - message.max_gas, self.config.gas_costs.clone(), ) { // execution failed: reset context to snapshot and reimburse sender @@ -1078,9 +1075,7 @@ impl ExecutionState { // run the bytecode's main function massa_sc_runtime::run_main( &*self.execution_interface, - &bytecode, - self.module_cache.clone(), - req.max_gas, + module, self.config.gas_costs.clone(), ) .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? @@ -1101,11 +1096,9 @@ impl ExecutionState { // run the target function in the bytecode massa_sc_runtime::run_function( &*self.execution_interface, - &bytecode, + module, &target_func, ¶meter, - self.module_cache.clone(), - req.max_gas, self.config.gas_costs.clone(), ) .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? From 2923f99e411b2f32564d9f2ff29b42fcd44fe09a Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA <22281426+aoudiamoncef@users.noreply.github.com> Date: Tue, 17 Jan 2023 11:41:54 +0100 Subject: [PATCH 28/80] Return state changes in read only calls (#3405) --- Cargo.lock | 31 +- Cargo.toml | 1 + massa-api-exports/Cargo.toml | 31 + massa-api-exports/src/address.rs | 157 +++++ massa-api-exports/src/block.rs | 90 +++ .../src/config.rs | 0 massa-api-exports/src/datastore.rs | 30 + massa-api-exports/src/endorsement.rs | 43 ++ {massa-api => massa-api-exports}/src/error.rs | 7 +- massa-api-exports/src/execution.rs | 89 +++ massa-api-exports/src/ledger.rs | 30 + massa-api-exports/src/lib.rs | 80 +++ massa-api-exports/src/node.rs | 87 +++ massa-api-exports/src/operation.rs | 56 ++ massa-api-exports/src/rolls.rs | 23 + massa-api-exports/src/slot.rs | 14 + massa-api/Cargo.toml | 4 +- massa-api/src/api.rs | 3 +- massa-api/src/api_trait.rs | 2 +- massa-api/src/lib.rs | 25 +- massa-api/src/private.rs | 21 +- massa-api/src/public.rs | 41 +- massa-async-pool/src/changes.rs | 5 +- massa-client/Cargo.toml | 1 + massa-client/src/cmds.rs | 17 +- massa-client/src/repl.rs | 7 +- .../src/controller_trait.rs | 3 +- .../src/test_exports/mock.rs | 3 +- massa-consensus-worker/src/controller.rs | 3 +- massa-consensus-worker/src/state/mod.rs | 3 +- .../src/controller_traits.rs | 2 +- massa-execution-exports/src/event_store.rs | 2 +- .../src/test_exports/mock.rs | 2 +- massa-execution-exports/src/types.rs | 16 +- massa-execution-worker/src/controller.rs | 2 +- massa-execution-worker/src/execution.rs | 8 +- .../src/tests/scenarios_mandatories.rs | 6 +- massa-final-state/Cargo.toml | 1 + massa-final-state/src/state_changes.rs | 3 +- massa-ledger-exports/src/ledger_changes.rs | 5 +- massa-ledger-exports/src/types.rs | 7 +- massa-models/Cargo.toml | 1 - massa-models/src/api.rs | 631 ------------------ massa-models/src/block.rs | 21 + massa-models/src/execution.rs | 71 +- .../src/{ledger_models.rs => ledger.rs} | 0 massa-models/src/lib.rs | 4 +- massa-models/src/slot.rs | 15 + massa-node/Cargo.toml | 1 + massa-node/base_config/openrpc.json | 39 +- massa-node/src/main.rs | 3 +- massa-pos-exports/src/controller_traits.rs | 7 +- massa-pos-exports/src/cycle_info.rs | 3 +- massa-pos-exports/src/deferred_credits.rs | 3 +- massa-pos-exports/src/pos_changes.rs | 3 +- massa-pos-exports/src/test_exports/mock.rs | 5 +- massa-pos-worker/src/controller.rs | 5 +- massa-sdk/Cargo.toml | 1 + massa-sdk/src/lib.rs | 36 +- 59 files changed, 1009 insertions(+), 801 deletions(-) create mode 100644 massa-api-exports/Cargo.toml create mode 100644 massa-api-exports/src/address.rs create mode 100644 massa-api-exports/src/block.rs rename {massa-api => massa-api-exports}/src/config.rs (100%) create mode 100644 massa-api-exports/src/datastore.rs create mode 100644 massa-api-exports/src/endorsement.rs rename {massa-api => massa-api-exports}/src/error.rs (95%) create mode 100644 massa-api-exports/src/execution.rs create mode 100644 massa-api-exports/src/ledger.rs create mode 100644 massa-api-exports/src/lib.rs create mode 100644 massa-api-exports/src/node.rs create mode 100644 massa-api-exports/src/operation.rs create mode 100644 massa-api-exports/src/rolls.rs create mode 100644 massa-api-exports/src/slot.rs delete mode 100644 massa-models/src/api.rs rename massa-models/src/{ledger_models.rs => ledger.rs} (100%) diff --git a/Cargo.lock b/Cargo.lock index 689d0ea2ba3..b8c59e2c9f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2167,6 +2167,7 @@ dependencies = [ "dialoguer", "erased-serde", "lazy_static", + "massa_api_exports", "massa_models", "massa_sdk", "massa_signature", @@ -2194,6 +2195,7 @@ dependencies = [ "enum-map", "lazy_static", "massa_api", + "massa_api_exports", "massa_async_pool", "massa_bootstrap", "massa_consensus_exports", @@ -2259,13 +2261,12 @@ name = "massa_api" version = "0.1.0" dependencies = [ "async-trait", - "displaydoc", "hyper", "itertools", "jsonrpsee", + "massa_api_exports", "massa_consensus_exports", "massa_execution_exports", - "massa_hash", "massa_models", "massa_network_exports", "massa_pool_exports", @@ -2279,7 +2280,6 @@ dependencies = [ "parking_lot", "serde", "serde_json", - "thiserror", "tokio", "tokio-stream", "tower", @@ -2287,6 +2287,28 @@ dependencies = [ "tracing", ] +[[package]] +name = "massa_api_exports" +version = "0.1.0" +dependencies = [ + "displaydoc", + "jsonrpsee-core", + "jsonrpsee-types", + "massa_consensus_exports", + "massa_execution_exports", + "massa_final_state", + "massa_hash", + "massa_models", + "massa_network_exports", + "massa_protocol_exports", + "massa_signature", + "massa_time", + "massa_wallet", + "serde", + "strum", + "thiserror", +] + [[package]] name = "massa_async_pool" version = "0.1.0" @@ -2531,6 +2553,7 @@ dependencies = [ "massa_serialization", "massa_signature", "nom", + "serde", "thiserror", "tracing", ] @@ -2612,7 +2635,6 @@ dependencies = [ "serde", "serde_with", "serial_test 0.10.0", - "strum", "thiserror", ] @@ -2782,6 +2804,7 @@ version = "0.1.0" dependencies = [ "http", "jsonrpsee", + "massa_api_exports", "massa_models", "massa_time", ] diff --git a/Cargo.toml b/Cargo.toml index 6eb3224f43e..27c70714b81 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ "massa-api", + "massa-api-exports", "massa-async-pool", "massa-bootstrap", "massa-client", diff --git a/massa-api-exports/Cargo.toml b/massa-api-exports/Cargo.toml new file mode 100644 index 00000000000..1cf05d0a049 --- /dev/null +++ b/massa-api-exports/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "massa_api_exports" +version = "0.1.0" +authors = ["Massa Labs "] +edition = "2021" + +[dependencies] +displaydoc = "0.2" +thiserror = "1.0" +jsonrpsee-core = { version = "0.16.2" } +jsonrpsee-types = { version = "0.16.2" } +serde = { version = "1.0", features = ["derive"] } +strum = { version = "0.24", features = ["derive"] } + +# custom modules +massa_signature = { path = "../massa-signature" } +massa_time = { path = "../massa-time" } +massa_models = { path = "../massa-models" } +massa_final_state = { path = "../massa-final-state" } + +massa_consensus_exports = { path = "../massa-consensus-exports" } +massa_hash = { path = "../massa-hash" } +massa_network_exports = { path = "../massa-network-exports" } +massa_protocol_exports = { path = "../massa-protocol-exports" } +massa_execution_exports = { path = "../massa-execution-exports" } +massa_wallet = { path = "../massa-wallet" } + +# for more information on what are the following features used for, see the cargo.toml at workspace level +[features] +sandbox = [] +testing = [] diff --git a/massa-api-exports/src/address.rs b/massa-api-exports/src/address.rs new file mode 100644 index 00000000000..724c71f17a0 --- /dev/null +++ b/massa-api-exports/src/address.rs @@ -0,0 +1,157 @@ +// Copyright (c) 2022 MASSA LABS + +use massa_models::address::ExecutionAddressCycleInfo; +use massa_models::endorsement::EndorsementId; +use massa_models::operation::OperationId; +use massa_models::slot::{IndexedSlot, Slot}; +use massa_models::{address::Address, amount::Amount, block::BlockId}; +use serde::{Deserialize, Serialize}; + +use crate::slot::SlotAmount; + +/// All you ever dream to know about an address +#[derive(Debug, Deserialize, Serialize)] +pub struct AddressInfo { + /// the address + pub address: Address, + /// the thread the address belongs to + pub thread: u8, + + /// final balance + pub final_balance: Amount, + /// final roll count + pub final_roll_count: u64, + /// final datastore keys + pub final_datastore_keys: Vec>, + + /// candidate balance + pub candidate_balance: Amount, + /// candidate roll count + pub candidate_roll_count: u64, + /// candidate datastore keys + pub candidate_datastore_keys: Vec>, + + /// deferred credits + pub deferred_credits: Vec, + + /// next block draws + pub next_block_draws: Vec, + /// next endorsement draws + pub next_endorsement_draws: Vec, + + /// created blocks + pub created_blocks: Vec, + /// created operations + pub created_operations: Vec, + /// created endorsements + pub created_endorsements: Vec, + + /// cycle information + pub cycle_infos: Vec, +} + +impl std::fmt::Display for AddressInfo { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + writeln!(f, "Address {} (thread {}):", self.address, self.thread)?; + writeln!( + f, + "\tBalance: final={}, candidate={}", + self.final_balance, self.candidate_balance + )?; + writeln!( + f, + "\tRolls: final={}, candidate={}", + self.final_roll_count, self.candidate_roll_count + )?; + write!(f, "\tLocked coins:")?; + if self.deferred_credits.is_empty() { + writeln!(f, "0")?; + } else { + for slot_amount in &self.deferred_credits { + writeln!( + f, + "\t\t{} locked coins will be unlocked at slot {}", + slot_amount.amount, slot_amount.slot + )?; + } + } + writeln!(f, "\tCycle infos:")?; + for cycle_info in &self.cycle_infos { + writeln!( + f, + "\t\tCycle {} ({}): produced {} and missed {} blocks{}", + cycle_info.cycle, + if cycle_info.is_final { + "final" + } else { + "candidate" + }, + cycle_info.ok_count, + cycle_info.nok_count, + match cycle_info.active_rolls { + Some(rolls) => format!(" with {} active rolls", rolls), + None => "".into(), + }, + )?; + } + //writeln!(f, "\tProduced blocks: {}", self.created_blocks.iter().map(|id| id.to_string()).intersperse(", ".into()).collect())?; + //writeln!(f, "\tProduced operations: {}", self.created_operations.iter().map(|id| id.to_string()).intersperse(", ".into()).collect())?; + //writeln!(f, "\tProduced endorsements: {}", self.created_endorsements.iter().map(|id| id.to_string()).intersperse(", ".into()).collect())?; + Ok(()) + } +} + +impl AddressInfo { + /// Only essential info about an address + pub fn compact(&self) -> CompactAddressInfo { + CompactAddressInfo { + address: self.address, + thread: self.thread, + active_rolls: self + .cycle_infos + .last() + .and_then(|c| c.active_rolls) + .unwrap_or_default(), + final_rolls: self.final_roll_count, + candidate_rolls: self.candidate_roll_count, + final_balance: self.final_balance, + candidate_balance: self.candidate_balance, + } + } +} + +/// Less information about an address +#[derive(Debug, Serialize, Deserialize)] +pub struct CompactAddressInfo { + /// the address + pub address: Address, + /// the thread it is + pub thread: u8, + /// candidate rolls + pub candidate_rolls: u64, + /// final rolls + pub final_rolls: u64, + /// active rolls + pub active_rolls: u64, + /// final balance + pub final_balance: Amount, + /// candidate balance + pub candidate_balance: Amount, +} + +impl std::fmt::Display for CompactAddressInfo { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + writeln!(f, "Address: {} (thread {}):", self.address, self.thread)?; + writeln!( + f, + "\tBalance: final={}, candidate={}", + self.final_balance, self.candidate_balance + )?; + writeln!( + f, + "\tRolls: active={}, final={}, candidate={}", + self.active_rolls, self.final_rolls, self.candidate_rolls + )?; + Ok(()) + } +} diff --git a/massa-api-exports/src/block.rs b/massa-api-exports/src/block.rs new file mode 100644 index 00000000000..64b2ed6e19c --- /dev/null +++ b/massa-api-exports/src/block.rs @@ -0,0 +1,90 @@ +// Copyright (c) 2022 MASSA LABS + +use massa_models::{address::Address, block::Block, block::BlockId, slot::Slot}; + +use serde::{Deserialize, Serialize}; + +use crate::display_if_true; + +/// refactor to delete +#[derive(Debug, Deserialize, Serialize)] +pub struct BlockInfo { + /// block id + pub id: BlockId, + /// optional block info content + pub content: Option, +} + +/// Block content +#[derive(Debug, Deserialize, Serialize)] +pub struct BlockInfoContent { + /// true if final + pub is_final: bool, + /// true if in the greatest clique (and not final) + pub is_in_blockclique: bool, + /// true if candidate (active any clique but not final) + pub is_candidate: bool, + /// true if discarded + pub is_discarded: bool, + /// block + pub block: Block, +} + +impl std::fmt::Display for BlockInfo { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + if let Some(content) = &self.content { + writeln!( + f, + "Block ID: {}{}{}{}{}", + self.id, + display_if_true(content.is_final, " (final)"), + display_if_true(content.is_candidate, " (candidate)"), + display_if_true(content.is_in_blockclique, " (blockclique)"), + display_if_true(content.is_discarded, " (discarded)"), + )?; + writeln!(f, "Block: {}", content.block)?; + } else { + writeln!(f, "Block {} not found", self.id)?; + } + Ok(()) + } +} + +/// A block resume (without the block itself) +#[derive(Debug, Deserialize, Serialize)] +pub struct BlockSummary { + /// id + pub id: BlockId, + /// true if in a final block + pub is_final: bool, + /// true if incompatible with a final block + pub is_stale: bool, + /// true if in the greatest block clique + pub is_in_blockclique: bool, + /// the slot the block is in + pub slot: Slot, + /// the block creator + pub creator: Address, + /// the block parents + pub parents: Vec, +} + +impl std::fmt::Display for BlockSummary { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + writeln!( + f, + "Block's ID: {}{}{}{}", + self.id, + display_if_true(self.is_final, "final"), + display_if_true(self.is_stale, "stale"), + display_if_true(self.is_in_blockclique, "in blockclique"), + )?; + writeln!(f, "Slot: {}", self.slot)?; + writeln!(f, "Creator: {}", self.creator)?; + writeln!(f, "Parents' IDs:")?; + for parent in &self.parents { + writeln!(f, "\t- {}", parent)?; + } + Ok(()) + } +} diff --git a/massa-api/src/config.rs b/massa-api-exports/src/config.rs similarity index 100% rename from massa-api/src/config.rs rename to massa-api-exports/src/config.rs diff --git a/massa-api-exports/src/datastore.rs b/massa-api-exports/src/datastore.rs new file mode 100644 index 00000000000..83cfb1a8f6f --- /dev/null +++ b/massa-api-exports/src/datastore.rs @@ -0,0 +1,30 @@ +// Copyright (c) 2022 MASSA LABS + +use massa_models::address::Address; +use serde::{Deserialize, Serialize}; + +/// Datastore entry query input structure +#[derive(Debug, Deserialize, Clone, Serialize)] +pub struct DatastoreEntryInput { + /// associated address of the entry + pub address: Address, + /// datastore key + pub key: Vec, +} + +/// Datastore entry query output structure +#[derive(Debug, Deserialize, Clone, Serialize)] +pub struct DatastoreEntryOutput { + /// final datastore entry value + pub final_value: Option>, + /// candidate datastore entry value + pub candidate_value: Option>, +} + +impl std::fmt::Display for DatastoreEntryOutput { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + writeln!(f, "final value: {:?}", self.final_value)?; + writeln!(f, "candidate value: {:?}", self.candidate_value)?; + Ok(()) + } +} diff --git a/massa-api-exports/src/endorsement.rs b/massa-api-exports/src/endorsement.rs new file mode 100644 index 00000000000..ed77ce100c3 --- /dev/null +++ b/massa-api-exports/src/endorsement.rs @@ -0,0 +1,43 @@ +// Copyright (c) 2022 MASSA LABS + +use massa_models::{ + block::BlockId, + endorsement::{EndorsementId, SecureShareEndorsement}, +}; +use serde::{Deserialize, Serialize}; + +use crate::display_if_true; + +/// All you wanna know about an endorsement +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct EndorsementInfo { + /// id + pub id: EndorsementId, + /// true if endorsement is still in pool + pub in_pool: bool, + /// the endorsement appears in `in_blocks` + /// if it appears in multiple blocks, these blocks are in different cliques + pub in_blocks: Vec, + /// true if the endorsement is final (for example in a final block) + pub is_final: bool, + /// the endorsement itself + pub endorsement: SecureShareEndorsement, +} + +impl std::fmt::Display for EndorsementInfo { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + writeln!( + f, + "Endorsement {}{}{}", + self.id, + display_if_true(self.in_pool, " (in pool)"), + display_if_true(self.is_final, " (final)") + )?; + writeln!(f, "In blocks:")?; + for block_id in &self.in_blocks { + writeln!(f, "\t- {}", block_id)?; + } + writeln!(f, "{}", self.endorsement)?; + Ok(()) + } +} diff --git a/massa-api/src/error.rs b/massa-api-exports/src/error.rs similarity index 95% rename from massa-api/src/error.rs rename to massa-api-exports/src/error.rs index 2ce7d9efd54..f1e6330b6c1 100644 --- a/massa-api/src/error.rs +++ b/massa-api-exports/src/error.rs @@ -1,10 +1,8 @@ // Copyright (c) 2022 MASSA LABS use displaydoc::Display; -use jsonrpsee::{ - core::Error as JsonRpseeError, - types::error::{CallError, ErrorObject}, -}; +use jsonrpsee_core::Error as JsonRpseeError; +use jsonrpsee_types::{error::CallError, ErrorObject}; use massa_consensus_exports::error::ConsensusError; use massa_execution_exports::ExecutionError; @@ -15,6 +13,7 @@ use massa_protocol_exports::ProtocolError; use massa_time::TimeError; use massa_wallet::WalletError; +/// Errors of the api component. #[non_exhaustive] #[derive(Display, thiserror::Error, Debug)] pub enum ApiError { diff --git a/massa-api-exports/src/execution.rs b/massa-api-exports/src/execution.rs new file mode 100644 index 00000000000..19da251f290 --- /dev/null +++ b/massa-api-exports/src/execution.rs @@ -0,0 +1,89 @@ +// Copyright (c) 2022 MASSA LABS + +use massa_final_state::StateChanges; +use massa_models::{address::Address, output_event::SCOutputEvent, slot::Slot}; +use serde::{Deserialize, Serialize}; +use std::{collections::VecDeque, fmt::Display}; + +/// The result of the read-only execution. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum ReadOnlyResult { + /// An error occurred during execution. + Error(String), + /// The result of a successful execution. + Ok(Vec), +} + +/// The response to a request for a read-only execution. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct ExecuteReadOnlyResponse { + /// The slot at which the read-only execution occurred. + pub executed_at: Slot, + /// The result of the read-only execution. + pub result: ReadOnlyResult, + /// The output events generated by the read-only execution. + pub output_events: VecDeque, + /// The gas cost for the execution + pub gas_cost: u64, + /// state changes caused by the execution step + pub state_changes: StateChanges, +} + +impl Display for ExecuteReadOnlyResponse { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + writeln!(f, "Executed at slot: {}", self.executed_at)?; + writeln!( + f, + "Result: {}", + match &self.result { + ReadOnlyResult::Error(e) => + format!("an error occurred during the execution: {}", e), + ReadOnlyResult::Ok(ret) => format!("success, returned value: {:?}", ret), + } + )?; + writeln!(f, "Gas cost: {}", self.gas_cost)?; + if !self.output_events.is_empty() { + writeln!(f, "Generated events:",)?; + for event in self.output_events.iter() { + writeln!(f, "{}", event)?; // id already displayed in event + } + } + Ok(()) + } +} + +/// read only bytecode execution request +#[derive(Debug, Deserialize, Clone, Serialize)] +pub struct ReadOnlyBytecodeExecution { + /// max available gas + pub max_gas: u64, + /// byte code + pub bytecode: Vec, + /// caller's address, optional + pub address: Option
, + /// Operation datastore, optional + pub operation_datastore: Option>, + /// execution start state + /// + /// Whether to start execution from final or active state + pub is_final: bool, +} + +/// read SC call request +#[derive(Debug, Deserialize, Clone, Serialize)] +pub struct ReadOnlyCall { + /// max available gas + pub max_gas: u64, + /// target address + pub target_address: Address, + /// target function + pub target_function: String, + /// function parameter + pub parameter: Vec, + /// caller's address, optional + pub caller_address: Option
, + /// execution start state + /// + /// Whether to start execution from final or active state + pub is_final: bool, +} diff --git a/massa-api-exports/src/ledger.rs b/massa-api-exports/src/ledger.rs new file mode 100644 index 00000000000..b9e83094976 --- /dev/null +++ b/massa-api-exports/src/ledger.rs @@ -0,0 +1,30 @@ +// Copyright (c) 2022 MASSA LABS + +use massa_models::amount::Amount; +use massa_models::ledger::LedgerData; + +use serde::{Deserialize, Serialize}; + +/// Current balance ledger info +#[derive(Debug, Deserialize, Serialize, Clone, Copy)] +pub struct LedgerInfo { + /// final data + pub final_ledger_info: LedgerData, + /// latest data + pub candidate_ledger_info: LedgerData, + /// locked balance, for example balance due to a roll sell + pub locked_balance: Amount, +} + +impl std::fmt::Display for LedgerInfo { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + writeln!(f, "\tFinal balance: {}", self.final_ledger_info.balance)?; + writeln!( + f, + "\tCandidate balance: {}", + self.candidate_ledger_info.balance + )?; + writeln!(f, "\tLocked balance: {}", self.locked_balance)?; + Ok(()) + } +} diff --git a/massa-api-exports/src/lib.rs b/massa-api-exports/src/lib.rs new file mode 100644 index 00000000000..c356e20accb --- /dev/null +++ b/massa-api-exports/src/lib.rs @@ -0,0 +1,80 @@ +//! Copyright (c) 2022 MASSA LABS +//! All the structures that are used everywhere +//! +#![warn(missing_docs)] +#![warn(unused_crate_dependencies)] +#![feature(bound_map)] +#![feature(int_roundings)] +#![feature(iter_intersperse)] + +use massa_time::MassaTime; +use serde::{Deserialize, Serialize}; + +/// address related structures +pub mod address; +/// block-related structures +pub mod block; +/// node configuration +pub mod config; +/// datastore serialization / deserialization +pub mod datastore; +/// endorsements +pub mod endorsement; +/// models error +pub mod error; +/// execution +pub mod execution; +/// ledger structures +pub mod ledger; +/// node related structure +pub mod node; +/// operations +pub mod operation; +/// rolls +pub mod rolls; +/// slots +pub mod slot; + +/// Dumb utils function to display nicely boolean value +fn display_if_true(value: bool, text: &str) -> String { + if value { + format!("[{}]", text) + } else { + String::from("") + } +} + +/// Just a wrapper with a optional beginning and end +#[derive(Debug, Deserialize, Clone, Copy, Serialize)] +pub struct TimeInterval { + /// optional start slot + pub start: Option, + /// optional end slot + pub end: Option, +} + +/// SCRUD operations +#[derive(strum::Display)] +#[strum(serialize_all = "snake_case")] +pub enum ScrudOperation { + /// search operation + Search, + /// create operation + Create, + /// read operation + Read, + /// update operation + Update, + /// delete operation + Delete, +} + +/// Bootsrap lists types +#[derive(strum::Display)] +#[strum(serialize_all = "snake_case")] +pub enum ListType { + /// contains banned entry + Blacklist, + /// contains allowed entry + Whitelist, +} diff --git a/massa-api-exports/src/node.rs b/massa-api-exports/src/node.rs new file mode 100644 index 00000000000..4b44abc51f2 --- /dev/null +++ b/massa-api-exports/src/node.rs @@ -0,0 +1,87 @@ +// Copyright (c) 2022 MASSA LABS + +use massa_models::node::NodeId; +use massa_models::stats::{ConsensusStats, ExecutionStats, NetworkStats}; +use massa_models::{config::CompactConfig, slot::Slot, version::Version}; +use massa_time::MassaTime; +use serde::{Deserialize, Serialize}; +use std::collections::BTreeMap; +use std::net::IpAddr; + +/// node status +#[derive(Debug, Deserialize, Serialize)] +pub struct NodeStatus { + /// our node id + pub node_id: NodeId, + /// optional node ip + pub node_ip: Option, + /// node version + pub version: Version, + /// now + pub current_time: MassaTime, + /// current cycle + pub current_cycle: u64, + /// connected nodes (node id, ip address, true if the connection is outgoing, false if incoming) + pub connected_nodes: BTreeMap, + /// latest slot, none if now is before genesis timestamp + pub last_slot: Option, + /// next slot + pub next_slot: Slot, + /// consensus stats + pub consensus_stats: ConsensusStats, + /// pool stats (operation count and endorsement count) + pub pool_stats: (usize, usize), + /// network stats + pub network_stats: NetworkStats, + /// execution stats + pub execution_stats: ExecutionStats, + /// compact configuration + pub config: CompactConfig, +} + +impl std::fmt::Display for NodeStatus { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + writeln!(f, "Node's ID: {}", self.node_id)?; + if self.node_ip.is_some() { + writeln!(f, "Node's IP: {}", self.node_ip.unwrap())?; + } else { + writeln!(f, "No routable IP set")?; + } + writeln!(f)?; + + writeln!(f, "Version: {}", self.version)?; + writeln!(f, "Config:\n{}", self.config)?; + writeln!(f)?; + + writeln!(f, "Current time: {}", self.current_time.to_utc_string())?; + writeln!(f, "Current cycle: {}", self.current_cycle)?; + if self.last_slot.is_some() { + writeln!(f, "Last slot: {}", self.last_slot.unwrap())?; + } + writeln!(f, "Next slot: {}", self.next_slot)?; + writeln!(f)?; + + writeln!(f, "{}", self.consensus_stats)?; + + writeln!(f, "Pool stats:")?; + writeln!(f, "\tOperations count: {}", self.pool_stats.0)?; + writeln!(f, "\tEndorsements count: {}", self.pool_stats.1)?; + writeln!(f)?; + + writeln!(f, "{}", self.network_stats)?; + + writeln!(f, "{}", self.execution_stats)?; + + writeln!(f, "Connected nodes:")?; + for (node_id, (ip_addr, is_outgoing)) in &self.connected_nodes { + writeln!( + f, + "Node's ID: {} / IP address: {} / {} connection", + node_id, + ip_addr, + if *is_outgoing { "Out" } else { "In" } + )? + } + Ok(()) + } +} diff --git a/massa-api-exports/src/operation.rs b/massa-api-exports/src/operation.rs new file mode 100644 index 00000000000..f0784b89ccf --- /dev/null +++ b/massa-api-exports/src/operation.rs @@ -0,0 +1,56 @@ +// Copyright (c) 2022 MASSA LABS + +use massa_models::{ + block::BlockId, + operation::{OperationId, SecureShareOperation}, +}; + +use massa_signature::{PublicKey, Signature}; +use serde::{Deserialize, Serialize}; + +use crate::display_if_true; + +/// operation input +#[derive(Serialize, Deserialize, Debug)] +pub struct OperationInput { + /// The public key of the creator of the TX + pub creator_public_key: PublicKey, + /// The signature of the operation + pub signature: Signature, + /// The serialized version of the content `base58` encoded + pub serialized_content: Vec, +} + +/// Operation and contextual info about it +#[derive(Debug, Deserialize, Serialize)] +pub struct OperationInfo { + /// id + pub id: OperationId, + /// true if operation is still in pool + pub in_pool: bool, + /// the operation appears in `in_blocks` + /// if it appears in multiple blocks, these blocks are in different cliques + pub in_blocks: Vec, + /// true if the operation is final (for example in a final block) + pub is_final: bool, + /// the operation itself + pub operation: SecureShareOperation, +} + +impl std::fmt::Display for OperationInfo { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + writeln!( + f, + "Operation {}{}{}", + self.id, + display_if_true(self.in_pool, " (in pool)"), + display_if_true(self.is_final, " (final)") + )?; + writeln!(f, "In blocks:")?; + for block_id in &self.in_blocks { + writeln!(f, "\t- {}", block_id)?; + } + writeln!(f, "{}", self.operation)?; + Ok(()) + } +} diff --git a/massa-api-exports/src/rolls.rs b/massa-api-exports/src/rolls.rs new file mode 100644 index 00000000000..2802ee8451e --- /dev/null +++ b/massa-api-exports/src/rolls.rs @@ -0,0 +1,23 @@ +// Copyright (c) 2022 MASSA LABS + +use serde::{Deserialize, Serialize}; + +/// Roll counts +#[derive(Debug, Deserialize, Serialize, Clone, Copy)] +pub struct RollsInfo { + /// count taken into account for the current cycle + pub active_rolls: u64, + /// at final blocks + pub final_rolls: u64, + /// at latest blocks + pub candidate_rolls: u64, +} + +impl std::fmt::Display for RollsInfo { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + writeln!(f, "\tActive rolls: {}", self.active_rolls)?; + writeln!(f, "\tFinal rolls: {}", self.final_rolls)?; + writeln!(f, "\tCandidate rolls: {}", self.candidate_rolls)?; + Ok(()) + } +} diff --git a/massa-api-exports/src/slot.rs b/massa-api-exports/src/slot.rs new file mode 100644 index 00000000000..a62f505ae5f --- /dev/null +++ b/massa-api-exports/src/slot.rs @@ -0,0 +1,14 @@ +// Copyright (c) 2022 MASSA LABS + +use massa_models::{amount::Amount, slot::Slot}; + +use serde::{Deserialize, Serialize}; + +/// slot / amount pair +#[derive(Debug, Deserialize, Serialize)] +pub struct SlotAmount { + /// slot + pub slot: Slot, + /// amount + pub amount: Amount, +} diff --git a/massa-api/Cargo.toml b/massa-api/Cargo.toml index 9312a478fd3..cecf9f59514 100644 --- a/massa-api/Cargo.toml +++ b/massa-api/Cargo.toml @@ -6,7 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -displaydoc = "0.2" jsonrpsee = { version = "0.16.2", features = ["server", "macros"] } async-trait = "0.1.58" serde = { version = "1.0", features = ["derive"] } @@ -14,7 +13,6 @@ serde_json = "1.0.87" tower-http = { version = "0.3.4", features = ["full"] } tower = { version = "0.4.13", features = ["full"] } hyper = "0.14.20" -thiserror = "1.0" tokio = { version = "1.23", features = ["full"] } tokio-stream = { version = "0.1", features = ["sync"] } tracing = "0.1" @@ -22,7 +20,7 @@ itertools = "0.10" parking_lot = { version = "0.12", features = ["deadlock_detection"] } # custom modules massa_consensus_exports = { path = "../massa-consensus-exports" } -massa_hash = { path = "../massa-hash" } +massa_api_exports = { path = "../massa-api-exports" } massa_models = { path = "../massa-models" } massa_network_exports = { path = "../massa-network-exports" } massa_pool_exports = { path = "../massa-pool-exports" } diff --git a/massa-api/src/api.rs b/massa-api/src/api.rs index fff7592d83a..35b1458763f 100644 --- a/massa-api/src/api.rs +++ b/massa-api/src/api.rs @@ -3,12 +3,13 @@ use std::net::SocketAddr; use crate::api_trait::MassaApiServer; -use crate::{APIConfig, ApiServer, ApiV2, StopHandle, API}; +use crate::{ApiServer, ApiV2, StopHandle, API}; use async_trait::async_trait; use jsonrpsee::core::error::SubscriptionClosed; use jsonrpsee::core::{Error as JsonRpseeError, RpcResult}; use jsonrpsee::types::SubscriptionResult; use jsonrpsee::SubscriptionSink; +use massa_api_exports::config::APIConfig; use massa_consensus_exports::ConsensusChannels; use massa_models::version::Version; use massa_pool_exports::PoolChannels; diff --git a/massa-api/src/api_trait.rs b/massa-api/src/api_trait.rs index 73adcff90d5..da233c8c0ca 100644 --- a/massa-api/src/api_trait.rs +++ b/massa-api/src/api_trait.rs @@ -35,7 +35,7 @@ pub trait MassaApi { )] fn subscribe_new_filled_blocks(&self); - /// New received only operations. + /// New produced operations. #[subscription( name = "subscribe_new_operations" => "new_operations", unsubscribe = "unsubscribe_new_operations", diff --git a/massa-api/src/lib.rs b/massa-api/src/lib.rs index f3c7e76649b..513eaca7af5 100644 --- a/massa-api/src/lib.rs +++ b/massa-api/src/lib.rs @@ -3,23 +3,28 @@ #![feature(async_closure)] #![warn(missing_docs)] #![warn(unused_crate_dependencies)] -use crate::api_trait::MassaApiServer; -use crate::error::ApiError::WrongAPI; +use api_trait::MassaApiServer; use hyper::Method; use jsonrpsee::core::{Error as JsonRpseeError, RpcResult}; use jsonrpsee::proc_macros::rpc; use jsonrpsee::server::{AllowHosts, ServerBuilder, ServerHandle}; use jsonrpsee::RpcModule; +use massa_api_exports::{ + address::AddressInfo, + block::{BlockInfo, BlockSummary}, + config::APIConfig, + datastore::{DatastoreEntryInput, DatastoreEntryOutput}, + endorsement::EndorsementInfo, + error::ApiError::WrongAPI, + execution::{ExecuteReadOnlyResponse, ReadOnlyBytecodeExecution, ReadOnlyCall}, + node::NodeStatus, + operation::{OperationInfo, OperationInput}, + TimeInterval, +}; use massa_consensus_exports::{ConsensusChannels, ConsensusController}; use massa_execution_exports::ExecutionController; -use massa_models::api::{ - AddressInfo, BlockInfo, BlockSummary, DatastoreEntryInput, DatastoreEntryOutput, - EndorsementInfo, EventFilter, NodeStatus, OperationInfo, OperationInput, - ReadOnlyBytecodeExecution, ReadOnlyCall, TimeInterval, -}; use massa_models::clique::Clique; use massa_models::composite::PubkeySig; -use massa_models::execution::ExecuteReadOnlyResponse; use massa_models::node::NodeId; use massa_models::operation::OperationId; use massa_models::output_event::SCOutputEvent; @@ -28,6 +33,7 @@ use massa_models::{ address::Address, block::{Block, BlockId}, endorsement::EndorsementId, + execution::EventFilter, slot::Slot, version::Version, }; @@ -48,11 +54,8 @@ use tracing::{info, warn}; mod api; mod api_trait; -mod config; -mod error; mod private; mod public; -pub use config::APIConfig; /// Public API component pub struct Public { diff --git a/massa-api/src/private.rs b/massa-api/src/private.rs index c1048cac6a6..c7dbb9d2b5d 100644 --- a/massa-api/src/private.rs +++ b/massa-api/src/private.rs @@ -1,21 +1,25 @@ //! Copyright (c) 2022 MASSA LABS -use crate::config::APIConfig; -use crate::error::ApiError; use crate::{MassaRpcServer, Private, RpcServer, StopHandle, Value, API}; use async_trait::async_trait; use itertools::Itertools; use jsonrpsee::core::{Error as JsonRpseeError, RpcResult}; -use massa_execution_exports::ExecutionController; -use massa_models::api::{ - AddressInfo, BlockInfo, BlockSummary, DatastoreEntryInput, DatastoreEntryOutput, - EndorsementInfo, EventFilter, ListType, NodeStatus, OperationInfo, OperationInput, - ReadOnlyBytecodeExecution, ReadOnlyCall, ScrudOperation, TimeInterval, +use massa_api_exports::{ + address::AddressInfo, + block::{BlockInfo, BlockSummary}, + config::APIConfig, + datastore::{DatastoreEntryInput, DatastoreEntryOutput}, + endorsement::EndorsementInfo, + error::ApiError, + execution::{ExecuteReadOnlyResponse, ReadOnlyBytecodeExecution, ReadOnlyCall}, + node::NodeStatus, + operation::{OperationInfo, OperationInput}, + ListType, ScrudOperation, TimeInterval, }; +use massa_execution_exports::ExecutionController; use massa_models::clique::Clique; use massa_models::composite::PubkeySig; -use massa_models::execution::ExecuteReadOnlyResponse; use massa_models::node::NodeId; use massa_models::output_event::SCOutputEvent; use massa_models::prehash::PreHashSet; @@ -23,6 +27,7 @@ use massa_models::{ address::Address, block::{Block, BlockId}, endorsement::EndorsementId, + execution::EventFilter, operation::OperationId, slot::Slot, }; diff --git a/massa-api/src/public.rs b/massa-api/src/public.rs index 7bad5d3b67c..3ca99b3d03a 100644 --- a/massa-api/src/public.rs +++ b/massa-api/src/public.rs @@ -1,26 +1,35 @@ //! Copyright (c) 2022 MASSA LABS #![allow(clippy::too_many_arguments)] -use crate::config::APIConfig; -use crate::error::ApiError; use crate::{MassaRpcServer, Public, RpcServer, StopHandle, Value, API}; use async_trait::async_trait; use jsonrpsee::core::{Error as JsonRpseeError, RpcResult}; +use massa_api_exports::{ + address::AddressInfo, + block::{BlockInfo, BlockInfoContent, BlockSummary}, + config::APIConfig, + datastore::{DatastoreEntryInput, DatastoreEntryOutput}, + endorsement::EndorsementInfo, + error::ApiError, + execution::{ExecuteReadOnlyResponse, ReadOnlyBytecodeExecution, ReadOnlyCall, ReadOnlyResult}, + node::NodeStatus, + operation::{OperationInfo, OperationInput}, + slot::SlotAmount, + TimeInterval, +}; use massa_consensus_exports::block_status::DiscardReason; use massa_consensus_exports::ConsensusController; use massa_execution_exports::{ ExecutionController, ExecutionStackElement, ReadOnlyExecutionRequest, ReadOnlyExecutionTarget, }; -use massa_models::api::{ - BlockGraphStatus, DatastoreEntryInput, DatastoreEntryOutput, OperationInput, - ReadOnlyBytecodeExecution, ReadOnlyCall, SlotAmount, -}; -use massa_models::execution::ReadOnlyResult; use massa_models::operation::OperationDeserializer; use massa_models::secure_share::SecureShareDeserializer; use massa_models::{ - block::Block, endorsement::SecureShareEndorsement, error::ModelsError, - operation::SecureShareOperation, timeslots, + block::{Block, BlockGraphStatus}, + endorsement::SecureShareEndorsement, + error::ModelsError, + operation::SecureShareOperation, + timeslots, }; use massa_pos_exports::SelectorController; use massa_protocol_exports::ProtocolCommandSender; @@ -30,16 +39,12 @@ use itertools::{izip, Itertools}; use massa_models::datastore::DatastoreDeserializer; use massa_models::{ address::Address, - api::{ - AddressInfo, BlockInfo, BlockInfoContent, BlockSummary, EndorsementInfo, EventFilter, - NodeStatus, OperationInfo, TimeInterval, - }, block::BlockId, clique::Clique, composite::PubkeySig, config::CompactConfig, endorsement::EndorsementId, - execution::ExecuteReadOnlyResponse, + execution::EventFilter, node::NodeId, operation::OperationId, output_event::SCOutputEvent, @@ -188,7 +193,9 @@ impl MassaRpcServer for API { ), gas_cost: result.as_ref().map_or_else(|_| 0, |v| v.gas_cost), output_events: result - .map_or_else(|_| Default::default(), |mut v| v.out.events.take()), + .as_ref() + .map_or_else(|_| Default::default(), |v| v.out.events.clone().0), + state_changes: result.map_or_else(|_| Default::default(), |v| v.out.state_changes), }; res.push(result); @@ -265,7 +272,9 @@ impl MassaRpcServer for API { ), gas_cost: result.as_ref().map_or_else(|_| 0, |v| v.gas_cost), output_events: result - .map_or_else(|_| Default::default(), |mut v| v.out.events.take()), + .as_ref() + .map_or_else(|_| Default::default(), |v| v.out.events.clone().0), + state_changes: result.map_or_else(|_| Default::default(), |v| v.out.state_changes), }; res.push(result); diff --git a/massa-async-pool/src/changes.rs b/massa-async-pool/src/changes.rs index 13073dafdc1..86d3efa5c5d 100644 --- a/massa-async-pool/src/changes.rs +++ b/massa-async-pool/src/changes.rs @@ -9,6 +9,7 @@ use nom::{ sequence::tuple, IResult, Parser, }; +use serde::{Deserialize, Serialize}; ///! Copyright (c) 2022 MASSA LABS @@ -19,7 +20,7 @@ use crate::{ }; /// Enum representing a value U with identifier T being added or deleted -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum Change { /// an item with identifier T and value U is added Add(T, U), @@ -39,7 +40,7 @@ enum ChangeId { } /// represents a list of additions and deletions to the asynchronous message pool -#[derive(Default, Debug, Clone, PartialEq, Eq)] +#[derive(Default, Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct AsyncPoolChanges(pub Vec>); /// `AsyncPoolChanges` serializer diff --git a/massa-client/Cargo.toml b/massa-client/Cargo.toml index 3591fe60dcb..d065ef096de 100644 --- a/massa-client/Cargo.toml +++ b/massa-client/Cargo.toml @@ -22,6 +22,7 @@ strum = "0.24" strum_macros = "0.24" tokio = { version = "1.23", features = ["full"] } # custom modules +massa_api_exports = { path = "../massa-api-exports" } massa_models = { path = "../massa-models" } massa_signature = { path = "../massa-signature" } massa_time = { path = "../massa-time" } diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index f988a73f8d9..a6922aa8b7c 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -3,10 +3,12 @@ use crate::repl::Output; use anyhow::{anyhow, bail, Error, Result}; use console::style; -use massa_models::api::{ - AddressInfo, CompactAddressInfo, DatastoreEntryInput, EventFilter, OperationInput, +use massa_api_exports::{ + address::{AddressInfo, CompactAddressInfo}, + datastore::DatastoreEntryInput, + execution::{ReadOnlyBytecodeExecution, ReadOnlyCall}, + operation::OperationInput, }; -use massa_models::api::{ReadOnlyBytecodeExecution, ReadOnlyCall}; use massa_models::node::NodeId; use massa_models::prehash::PreHashMap; use massa_models::timeslots::get_current_latest_block_slot; @@ -15,6 +17,7 @@ use massa_models::{ amount::Amount, block::BlockId, endorsement::EndorsementId, + execution::EventFilter, operation::{Operation, OperationId, OperationType}, slot::Slot, }; @@ -1122,9 +1125,9 @@ impl Command { None }; let is_final = if let Some(adr) = parameters.get(3) { - Some(adr.parse::()?) + adr.parse::()? } else { - None + false }; let bytecode = get_file_as_byte_vec(&path).await?; match client @@ -1157,9 +1160,9 @@ impl Command { None }; let is_final = if let Some(adr) = parameters.get(5) { - Some(adr.parse::()?) + adr.parse::()? } else { - None + false }; match client .public diff --git a/massa-client/src/repl.rs b/massa-client/src/repl.rs index 88812f72659..a24ef14be7f 100644 --- a/massa-client/src/repl.rs +++ b/massa-client/src/repl.rs @@ -6,11 +6,12 @@ use crate::settings::SETTINGS; use anyhow::Result; use console::style; use erased_serde::{Serialize, Serializer}; -use massa_models::api::{ - AddressInfo, BlockInfo, DatastoreEntryOutput, EndorsementInfo, NodeStatus, OperationInfo, +use massa_api_exports::{ + address::AddressInfo, block::BlockInfo, datastore::DatastoreEntryOutput, + endorsement::EndorsementInfo, execution::ExecuteReadOnlyResponse, node::NodeStatus, + operation::OperationInfo, }; use massa_models::composite::PubkeySig; -use massa_models::execution::ExecuteReadOnlyResponse; use massa_models::output_event::SCOutputEvent; use massa_models::prehash::PreHashSet; use massa_models::{address::Address, operation::OperationId}; diff --git a/massa-consensus-exports/src/controller_trait.rs b/massa-consensus-exports/src/controller_trait.rs index eb76e3bb7ef..bff8eeb68bc 100644 --- a/massa-consensus-exports/src/controller_trait.rs +++ b/massa-consensus-exports/src/controller_trait.rs @@ -3,8 +3,7 @@ use crate::{bootstrapable_graph::BootstrapableGraph, error::ConsensusError}; use massa_models::prehash::PreHashSet; use massa_models::streaming_step::StreamingStep; use massa_models::{ - api::BlockGraphStatus, - block::{BlockHeader, BlockId}, + block::{BlockGraphStatus, BlockHeader, BlockId}, clique::Clique, secure_share::SecureShare, slot::Slot, diff --git a/massa-consensus-exports/src/test_exports/mock.rs b/massa-consensus-exports/src/test_exports/mock.rs index 8ceb43fb103..36ab094f675 100644 --- a/massa-consensus-exports/src/test_exports/mock.rs +++ b/massa-consensus-exports/src/test_exports/mock.rs @@ -6,8 +6,7 @@ use std::sync::{ }; use massa_models::{ - api::BlockGraphStatus, - block::{BlockHeader, BlockId}, + block::{BlockGraphStatus, BlockHeader, BlockId}, clique::Clique, prehash::PreHashSet, secure_share::SecureShare, diff --git a/massa-consensus-worker/src/controller.rs b/massa-consensus-worker/src/controller.rs index 3234b5003ae..4cf23476bc9 100644 --- a/massa-consensus-worker/src/controller.rs +++ b/massa-consensus-worker/src/controller.rs @@ -4,8 +4,7 @@ use massa_consensus_exports::{ export_active_block::ExportActiveBlock, ConsensusChannels, ConsensusController, }; use massa_models::{ - api::BlockGraphStatus, - block::{BlockHeader, BlockId, FilledBlock}, + block::{BlockGraphStatus, BlockHeader, BlockId, FilledBlock}, clique::Clique, operation::{Operation, OperationId}, prehash::PreHashSet, diff --git a/massa-consensus-worker/src/state/mod.rs b/massa-consensus-worker/src/state/mod.rs index aa370247eb3..00a655f934b 100644 --- a/massa-consensus-worker/src/state/mod.rs +++ b/massa-consensus-worker/src/state/mod.rs @@ -12,8 +12,7 @@ use massa_consensus_exports::{ use massa_models::{ active_block::ActiveBlock, address::Address, - api::BlockGraphStatus, - block::{BlockId, SecuredHeader}, + block::{BlockGraphStatus, BlockId, SecuredHeader}, clique::Clique, prehash::{CapacityAllocator, PreHashMap, PreHashSet}, slot::Slot, diff --git a/massa-execution-exports/src/controller_traits.rs b/massa-execution-exports/src/controller_traits.rs index c66c4063c41..198ea76e9b6 100644 --- a/massa-execution-exports/src/controller_traits.rs +++ b/massa-execution-exports/src/controller_traits.rs @@ -7,8 +7,8 @@ use crate::ExecutionError; use crate::{ExecutionAddressInfo, ReadOnlyExecutionOutput}; use massa_models::address::Address; use massa_models::amount::Amount; -use massa_models::api::EventFilter; use massa_models::block::BlockId; +use massa_models::execution::EventFilter; use massa_models::operation::OperationId; use massa_models::output_event::SCOutputEvent; use massa_models::prehash::PreHashMap; diff --git a/massa-execution-exports/src/event_store.rs b/massa-execution-exports/src/event_store.rs index 332ab49d631..295de896a2a 100644 --- a/massa-execution-exports/src/event_store.rs +++ b/massa-execution-exports/src/event_store.rs @@ -3,7 +3,7 @@ //! This module represents an event store allowing to store, search and retrieve //! a config-limited number of execution-generated events -use massa_models::api::EventFilter; +use massa_models::execution::EventFilter; use massa_models::output_event::SCOutputEvent; use std::collections::VecDeque; diff --git a/massa-execution-exports/src/test_exports/mock.rs b/massa-execution-exports/src/test_exports/mock.rs index ac98810ed59..701ba34d849 100644 --- a/massa-execution-exports/src/test_exports/mock.rs +++ b/massa-execution-exports/src/test_exports/mock.rs @@ -10,8 +10,8 @@ use massa_ledger_exports::LedgerEntry; use massa_models::{ address::Address, amount::Amount, - api::EventFilter, block::BlockId, + execution::EventFilter, operation::OperationId, output_event::SCOutputEvent, prehash::{PreHashMap, PreHashSet}, diff --git a/massa-execution-exports/src/types.rs b/massa-execution-exports/src/types.rs index 5848cdec6e2..3ebf802b6d5 100644 --- a/massa-execution-exports/src/types.rs +++ b/massa-execution-exports/src/types.rs @@ -69,12 +69,10 @@ pub struct ReadOnlyExecutionRequest { pub call_stack: Vec, /// Target of the request pub target: ReadOnlyExecutionTarget, - /// optional event status + /// execution start state /// - /// Some(true) means final - /// Some(false) means candidate - /// None means final _and_ candidate - pub is_final: Option, + /// Whether to start execution from final or active state + pub is_final: bool, } /// structure describing different possible targets of a read-only execution request @@ -107,12 +105,10 @@ pub struct ReadOnlyCallRequest { pub target_func: String, /// Parameter to pass to the target function pub parameter: String, - /// optional event status + /// execution start state /// - /// Some(true) means final - /// Some(false) means candidate - /// None means final _and_ candidate - pub is_final: Option, + /// Whether to start execution from final or active state + pub is_final: bool, } /// Structure describing an element of the execution stack. diff --git a/massa-execution-worker/src/controller.rs b/massa-execution-worker/src/controller.rs index 030106c9239..c1d4f79441b 100644 --- a/massa-execution-worker/src/controller.rs +++ b/massa-execution-worker/src/controller.rs @@ -9,7 +9,7 @@ use massa_execution_exports::{ ExecutionAddressInfo, ExecutionConfig, ExecutionController, ExecutionError, ExecutionManager, ReadOnlyExecutionOutput, ReadOnlyExecutionRequest, }; -use massa_models::api::EventFilter; +use massa_models::execution::EventFilter; use massa_models::output_event::SCOutputEvent; use massa_models::prehash::{PreHashMap, PreHashSet}; use massa_models::stats::ExecutionStats; diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 6ce4301b90d..f21acf9894f 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -20,7 +20,7 @@ use massa_execution_exports::{ use massa_final_state::FinalState; use massa_ledger_exports::{SetOrDelete, SetUpdateOrDelete}; use massa_models::address::ExecutionAddressCycleInfo; -use massa_models::api::EventFilter; +use massa_models::execution::EventFilter; use massa_models::output_event::SCOutputEvent; use massa_models::prehash::PreHashSet; use massa_models::stats::ExecutionStats; @@ -1024,14 +1024,14 @@ impl ExecutionState { } // set the execution slot to be the one after the latest executed active or final slot - let slot = if req.is_final.map_or(false, |is_final| is_final) { + let slot = if req.is_final { self.final_cursor .get_next_slot(self.config.thread_count) - .expect("slot overflow in readonly execution") + .expect("slot overflow in readonly execution from final slot") } else { self.active_cursor .get_next_slot(self.config.thread_count) - .expect("slot overflow in readonly execution") + .expect("slot overflow in readonly execution from active slot") }; // create a readonly execution context diff --git a/massa-execution-worker/src/tests/scenarios_mandatories.rs b/massa-execution-worker/src/tests/scenarios_mandatories.rs index a503377fad7..e129cc8ca05 100644 --- a/massa-execution-worker/src/tests/scenarios_mandatories.rs +++ b/massa-execution-worker/src/tests/scenarios_mandatories.rs @@ -10,9 +10,9 @@ use massa_models::config::{LEDGER_ENTRY_BASE_SIZE, LEDGER_ENTRY_DATASTORE_BASE_S use massa_models::prehash::PreHashMap; use massa_models::{address::Address, amount::Amount, slot::Slot}; use massa_models::{ - api::EventFilter, block::BlockId, datastore::Datastore, + execution::EventFilter, operation::{Operation, OperationSerializer, OperationType, SecureShareOperation}, secure_share::SecureShareContent, }; @@ -84,7 +84,7 @@ fn test_readonly_execution() { target: ReadOnlyExecutionTarget::BytecodeExecution( include_bytes!("./wasm/event_test.wasm").to_vec(), ), - is_final: Some(true), + is_final: true, }) .expect("readonly execution failed"); assert_eq!(res.out.slot, Slot::new(1, 0)); @@ -98,7 +98,7 @@ fn test_readonly_execution() { target: ReadOnlyExecutionTarget::BytecodeExecution( include_bytes!("./wasm/event_test.wasm").to_vec(), ), - is_final: Some(false), + is_final: false, }) .expect("readonly execution failed"); assert!(res.out.slot.period > 8); diff --git a/massa-final-state/Cargo.toml b/massa-final-state/Cargo.toml index 29ae05d130b..d5acaed693d 100644 --- a/massa-final-state/Cargo.toml +++ b/massa-final-state/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] displaydoc = "0.2" +serde = { version = "1.0", features = ["derive"] } nom = "7.1" thiserror = "1.0" tracing = "0.1" diff --git a/massa-final-state/src/state_changes.rs b/massa-final-state/src/state_changes.rs index 69142cc17fc..06a0dc705bc 100644 --- a/massa-final-state/src/state_changes.rs +++ b/massa-final-state/src/state_changes.rs @@ -16,9 +16,10 @@ use nom::{ sequence::tuple, IResult, Parser, }; +use serde::{Deserialize, Serialize}; /// represents changes that can be applied to the execution state -#[derive(Default, Debug, Clone)] +#[derive(Default, Debug, Clone, Deserialize, Serialize)] pub struct StateChanges { /// ledger changes pub ledger_changes: LedgerChanges, diff --git a/massa-ledger-exports/src/ledger_changes.rs b/massa-ledger-exports/src/ledger_changes.rs index 3b74466db01..4b7cd61cf1c 100644 --- a/massa-ledger-exports/src/ledger_changes.rs +++ b/massa-ledger-exports/src/ledger_changes.rs @@ -19,11 +19,12 @@ use nom::error::{context, ContextError, ParseError}; use nom::multi::length_count; use nom::sequence::tuple; use nom::{IResult, Parser}; +use serde::{Deserialize, Serialize}; use std::collections::{hash_map, BTreeMap}; use std::ops::Bound::Included; /// represents an update to one or more fields of a `LedgerEntry` -#[derive(Default, Debug, Clone, PartialEq, Eq)] +#[derive(Default, Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct LedgerEntryUpdate { /// change the balance pub balance: SetOrKeep, @@ -324,7 +325,7 @@ impl Applicable for LedgerEntryUpdate { } /// represents a list of changes to multiple ledger entries -#[derive(Default, Debug, Clone, PartialEq, Eq)] +#[derive(Default, Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct LedgerChanges( pub PreHashMap>, ); diff --git a/massa-ledger-exports/src/types.rs b/massa-ledger-exports/src/types.rs index bf1f11ed12e..9e595b51c4e 100644 --- a/massa-ledger-exports/src/types.rs +++ b/massa-ledger-exports/src/types.rs @@ -7,6 +7,7 @@ use nom::{ error::{ContextError, ParseError}, IResult, }; +use serde::{Deserialize, Serialize}; /// Trait marking a structure that supports another one (V) being applied to it pub trait Applicable { @@ -15,7 +16,7 @@ pub trait Applicable { } /// Enumeration representing set/update/delete change on a value T -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum SetUpdateOrDelete, V: Applicable + Clone> { /// Sets the value T a new absolute value T Set(T), @@ -184,7 +185,7 @@ where } /// `Enum` representing a set/delete change on a value T -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum SetOrDelete { /// sets a new absolute value T Set(T), @@ -270,7 +271,7 @@ impl Applicable> for SetOrDelete { } /// represents a set/keep change -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum SetOrKeep { /// sets a new absolute value T Set(T), diff --git a/massa-models/Cargo.toml b/massa-models/Cargo.toml index 98f934f2b68..a5c8b4a7e79 100644 --- a/massa-models/Cargo.toml +++ b/massa-models/Cargo.toml @@ -11,7 +11,6 @@ num_enum = "0.5" rust_decimal = "1.26" serde = { version = "1.0", features = ["derive"] } serde_with = "2.1.0" -strum = { version = "0.24", features = ["derive"] } thiserror = "1.0" num = { version = "0.4", features = ["serde"] } directories = "4.0" diff --git a/massa-models/src/api.rs b/massa-models/src/api.rs deleted file mode 100644 index 70f61700578..00000000000 --- a/massa-models/src/api.rs +++ /dev/null @@ -1,631 +0,0 @@ -// Copyright (c) 2022 MASSA LABS - -use crate::address::ExecutionAddressCycleInfo; -use crate::endorsement::{EndorsementId, SecureShareEndorsement}; -use crate::ledger_models::LedgerData; -use crate::node::NodeId; -use crate::operation::{OperationId, SecureShareOperation}; -use crate::stats::{ConsensusStats, ExecutionStats, NetworkStats}; -use crate::{ - address::Address, amount::Amount, block::Block, block::BlockId, config::CompactConfig, - slot::Slot, version::Version, -}; -use massa_signature::{PublicKey, Signature}; -use massa_time::MassaTime; -use serde::{Deserialize, Serialize}; -use std::collections::BTreeMap; -use std::net::IpAddr; -use strum::Display; - -/// operation input -#[derive(Serialize, Deserialize, Debug)] -pub struct OperationInput { - /// The public key of the creator of the TX - pub creator_public_key: PublicKey, - /// The signature of the operation - pub signature: Signature, - /// The serialized version of the content `base58` encoded - pub serialized_content: Vec, -} - -/// node status -#[derive(Debug, Deserialize, Serialize)] -pub struct NodeStatus { - /// our node id - pub node_id: NodeId, - /// optional node ip - pub node_ip: Option, - /// node version - pub version: Version, - /// now - pub current_time: MassaTime, - /// current cycle - pub current_cycle: u64, - /// connected nodes (node id, ip address, true if the connection is outgoing, false if incoming) - pub connected_nodes: BTreeMap, - /// latest slot, none if now is before genesis timestamp - pub last_slot: Option, - /// next slot - pub next_slot: Slot, - /// consensus stats - pub consensus_stats: ConsensusStats, - /// pool stats (operation count and endorsement count) - pub pool_stats: (usize, usize), - /// network stats - pub network_stats: NetworkStats, - /// execution stats - pub execution_stats: ExecutionStats, - /// compact configuration - pub config: CompactConfig, -} - -impl std::fmt::Display for NodeStatus { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!(f, "Node's ID: {}", self.node_id)?; - if self.node_ip.is_some() { - writeln!(f, "Node's IP: {}", self.node_ip.unwrap())?; - } else { - writeln!(f, "No routable IP set")?; - } - writeln!(f)?; - - writeln!(f, "Version: {}", self.version)?; - writeln!(f, "Config:\n{}", self.config)?; - writeln!(f)?; - - writeln!(f, "Current time: {}", self.current_time.to_utc_string())?; - writeln!(f, "Current cycle: {}", self.current_cycle)?; - if self.last_slot.is_some() { - writeln!(f, "Last slot: {}", self.last_slot.unwrap())?; - } - writeln!(f, "Next slot: {}", self.next_slot)?; - writeln!(f)?; - - writeln!(f, "{}", self.consensus_stats)?; - - writeln!(f, "Pool stats:")?; - writeln!(f, "\tOperations count: {}", self.pool_stats.0)?; - writeln!(f, "\tEndorsements count: {}", self.pool_stats.1)?; - writeln!(f)?; - - writeln!(f, "{}", self.network_stats)?; - - writeln!(f, "{}", self.execution_stats)?; - - writeln!(f, "Connected nodes:")?; - for (node_id, (ip_addr, is_outgoing)) in &self.connected_nodes { - writeln!( - f, - "Node's ID: {} / IP address: {} / {} connection", - node_id, - ip_addr, - if *is_outgoing { "Out" } else { "In" } - )? - } - Ok(()) - } -} - -/// Operation and contextual info about it -#[derive(Debug, Deserialize, Serialize)] -pub struct OperationInfo { - /// id - pub id: OperationId, - /// true if operation is still in pool - pub in_pool: bool, - /// the operation appears in `in_blocks` - /// if it appears in multiple blocks, these blocks are in different cliques - pub in_blocks: Vec, - /// true if the operation is final (for example in a final block) - pub is_final: bool, - /// the operation itself - pub operation: SecureShareOperation, -} - -impl std::fmt::Display for OperationInfo { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!( - f, - "Operation {}{}{}", - self.id, - display_if_true(self.in_pool, " (in pool)"), - display_if_true(self.is_final, " (final)") - )?; - writeln!(f, "In blocks:")?; - for block_id in &self.in_blocks { - writeln!(f, "\t- {}", block_id)?; - } - writeln!(f, "{}", self.operation)?; - Ok(()) - } -} - -/// Block status within the graph -#[derive(Eq, PartialEq, Debug, Deserialize, Serialize)] -pub enum BlockGraphStatus { - /// received but not yet graph-processed - Incoming, - /// waiting for its slot - WaitingForSlot, - /// waiting for a missing dependency - WaitingForDependencies, - /// active in alternative cliques - ActiveInAlternativeCliques, - /// active in blockclique - ActiveInBlockclique, - /// forever applies - Final, - /// discarded for any reason - Discarded, - /// not found in graph - NotFound, -} - -/// Current balance ledger info -#[derive(Debug, Deserialize, Serialize, Clone, Copy)] -pub struct LedgerInfo { - /// final data - pub final_ledger_info: LedgerData, - /// latest data - pub candidate_ledger_info: LedgerData, - /// locked balance, for example balance due to a roll sell - pub locked_balance: Amount, -} - -impl std::fmt::Display for LedgerInfo { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!(f, "\tFinal balance: {}", self.final_ledger_info.balance)?; - writeln!( - f, - "\tCandidate balance: {}", - self.candidate_ledger_info.balance - )?; - writeln!(f, "\tLocked balance: {}", self.locked_balance)?; - Ok(()) - } -} - -/// Roll counts -#[derive(Debug, Deserialize, Serialize, Clone, Copy)] -pub struct RollsInfo { - /// count taken into account for the current cycle - pub active_rolls: u64, - /// at final blocks - pub final_rolls: u64, - /// at latest blocks - pub candidate_rolls: u64, -} - -impl std::fmt::Display for RollsInfo { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!(f, "\tActive rolls: {}", self.active_rolls)?; - writeln!(f, "\tFinal rolls: {}", self.final_rolls)?; - writeln!(f, "\tCandidate rolls: {}", self.candidate_rolls)?; - Ok(()) - } -} - -/// All you ever dream to know about an address -#[derive(Debug, Deserialize, Serialize)] -pub struct AddressInfo { - /// the address - pub address: Address, - /// the thread the address belongs to - pub thread: u8, - - /// final balance - pub final_balance: Amount, - /// final roll count - pub final_roll_count: u64, - /// final datastore keys - pub final_datastore_keys: Vec>, - - /// candidate balance - pub candidate_balance: Amount, - /// candidate roll count - pub candidate_roll_count: u64, - /// candidate datastore keys - pub candidate_datastore_keys: Vec>, - - /// deferred credits - pub deferred_credits: Vec, - - /// next block draws - pub next_block_draws: Vec, - /// next endorsement draws - pub next_endorsement_draws: Vec, - - /// created blocks - pub created_blocks: Vec, - /// created operations - pub created_operations: Vec, - /// created endorsements - pub created_endorsements: Vec, - - /// cycle information - pub cycle_infos: Vec, -} - -impl std::fmt::Display for AddressInfo { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!(f, "Address {} (thread {}):", self.address, self.thread)?; - writeln!( - f, - "\tBalance: final={}, candidate={}", - self.final_balance, self.candidate_balance - )?; - writeln!( - f, - "\tRolls: final={}, candidate={}", - self.final_roll_count, self.candidate_roll_count - )?; - write!(f, "\tLocked coins:")?; - if self.deferred_credits.is_empty() { - writeln!(f, "0")?; - } else { - for slot_amount in &self.deferred_credits { - writeln!( - f, - "\t\t{} locked coins will be unlocked at slot {}", - slot_amount.amount, slot_amount.slot - )?; - } - } - writeln!(f, "\tCycle infos:")?; - for cycle_info in &self.cycle_infos { - writeln!( - f, - "\t\tCycle {} ({}): produced {} and missed {} blocks{}", - cycle_info.cycle, - if cycle_info.is_final { - "final" - } else { - "candidate" - }, - cycle_info.ok_count, - cycle_info.nok_count, - match cycle_info.active_rolls { - Some(rolls) => format!(" with {} active rolls", rolls), - None => "".into(), - }, - )?; - } - //writeln!(f, "\tProduced blocks: {}", self.created_blocks.iter().map(|id| id.to_string()).intersperse(", ".into()).collect())?; - //writeln!(f, "\tProduced operations: {}", self.created_operations.iter().map(|id| id.to_string()).intersperse(", ".into()).collect())?; - //writeln!(f, "\tProduced endorsements: {}", self.created_endorsements.iter().map(|id| id.to_string()).intersperse(", ".into()).collect())?; - Ok(()) - } -} - -impl AddressInfo { - /// Only essential info about an address - pub fn compact(&self) -> CompactAddressInfo { - CompactAddressInfo { - address: self.address, - thread: self.thread, - active_rolls: self - .cycle_infos - .last() - .and_then(|c| c.active_rolls) - .unwrap_or_default(), - final_rolls: self.final_roll_count, - candidate_rolls: self.candidate_roll_count, - final_balance: self.final_balance, - candidate_balance: self.candidate_balance, - } - } -} - -/// When an address is drawn to create an endorsement it is selected for a specific index -#[derive(Debug, Deserialize, Serialize, Hash, PartialEq, Eq)] -pub struct IndexedSlot { - /// slot - pub slot: Slot, - /// endorsement index in the slot - pub index: usize, -} - -impl std::fmt::Display for IndexedSlot { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!(f, "Slot: {}, Index: {}", self.slot, self.index) - } -} - -/// Less information about an address -#[derive(Debug, Serialize, Deserialize)] -pub struct CompactAddressInfo { - /// the address - pub address: Address, - /// the thread it is - pub thread: u8, - /// candidate rolls - pub candidate_rolls: u64, - /// final rolls - pub final_rolls: u64, - /// active rolls - pub active_rolls: u64, - /// final balance - pub final_balance: Amount, - /// candidate balance - pub candidate_balance: Amount, -} - -impl std::fmt::Display for CompactAddressInfo { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!(f, "Address: {} (thread {}):", self.address, self.thread)?; - writeln!( - f, - "\tBalance: final={}, candidate={}", - self.final_balance, self.candidate_balance - )?; - writeln!( - f, - "\tRolls: active={}, final={}, candidate={}", - self.active_rolls, self.final_rolls, self.candidate_rolls - )?; - Ok(()) - } -} - -/// All you wanna know about an endorsement -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct EndorsementInfo { - /// id - pub id: EndorsementId, - /// true if endorsement is still in pool - pub in_pool: bool, - /// the endorsement appears in `in_blocks` - /// if it appears in multiple blocks, these blocks are in different cliques - pub in_blocks: Vec, - /// true if the endorsement is final (for example in a final block) - pub is_final: bool, - /// the endorsement itself - pub endorsement: SecureShareEndorsement, -} - -impl std::fmt::Display for EndorsementInfo { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!( - f, - "Endorsement {}{}{}", - self.id, - display_if_true(self.in_pool, " (in pool)"), - display_if_true(self.is_final, " (final)") - )?; - writeln!(f, "In blocks:")?; - for block_id in &self.in_blocks { - writeln!(f, "\t- {}", block_id)?; - } - writeln!(f, "{}", self.endorsement)?; - Ok(()) - } -} - -/// slot / amount pair -#[derive(Debug, Deserialize, Serialize)] -pub struct SlotAmount { - /// slot - pub slot: Slot, - /// amount - pub amount: Amount, -} - -/// refactor to delete -#[derive(Debug, Deserialize, Serialize)] -pub struct BlockInfo { - /// block id - pub id: BlockId, - /// optional block info content - pub content: Option, -} - -/// Block content -#[derive(Debug, Deserialize, Serialize)] -pub struct BlockInfoContent { - /// true if final - pub is_final: bool, - /// true if in the greatest clique (and not final) - pub is_in_blockclique: bool, - /// true if candidate (active any clique but not final) - pub is_candidate: bool, - /// true if discarded - pub is_discarded: bool, - /// block - pub block: Block, -} - -impl std::fmt::Display for BlockInfo { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if let Some(content) = &self.content { - writeln!( - f, - "Block ID: {}{}{}{}{}", - self.id, - display_if_true(content.is_final, " (final)"), - display_if_true(content.is_candidate, " (candidate)"), - display_if_true(content.is_in_blockclique, " (blockclique)"), - display_if_true(content.is_discarded, " (discarded)"), - )?; - writeln!(f, "Block: {}", content.block)?; - } else { - writeln!(f, "Block {} not found", self.id)?; - } - Ok(()) - } -} - -/// A block resume (without the block itself) -#[derive(Debug, Deserialize, Serialize)] -pub struct BlockSummary { - /// id - pub id: BlockId, - /// true if in a final block - pub is_final: bool, - /// true if incompatible with a final block - pub is_stale: bool, - /// true if in the greatest block clique - pub is_in_blockclique: bool, - /// the slot the block is in - pub slot: Slot, - /// the block creator - pub creator: Address, - /// the block parents - pub parents: Vec, -} - -impl std::fmt::Display for BlockSummary { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!( - f, - "Block's ID: {}{}{}{}", - self.id, - display_if_true(self.is_final, "final"), - display_if_true(self.is_stale, "stale"), - display_if_true(self.is_in_blockclique, "in blockclique"), - )?; - writeln!(f, "Slot: {}", self.slot)?; - writeln!(f, "Creator: {}", self.creator)?; - writeln!(f, "Parents' IDs:")?; - for parent in &self.parents { - writeln!(f, "\t- {}", parent)?; - } - Ok(()) - } -} - -/// Dumb utils function to display nicely boolean value -fn display_if_true(value: bool, text: &str) -> String { - if value { - format!("[{}]", text) - } else { - String::from("") - } -} - -/// Just a wrapper with a optional beginning and end -#[derive(Debug, Deserialize, Clone, Copy, Serialize)] -pub struct TimeInterval { - /// optional start slot - pub start: Option, - /// optional end slot - pub end: Option, -} - -/// Datastore entry query input structure -#[derive(Debug, Deserialize, Clone, Serialize)] -pub struct DatastoreEntryInput { - /// associated address of the entry - pub address: Address, - /// datastore key - pub key: Vec, -} - -/// Datastore entry query output structure -#[derive(Debug, Deserialize, Clone, Serialize)] -pub struct DatastoreEntryOutput { - /// final datastore entry value - pub final_value: Option>, - /// candidate datastore entry value - pub candidate_value: Option>, -} - -impl std::fmt::Display for DatastoreEntryOutput { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!(f, "final value: {:?}", self.final_value)?; - writeln!(f, "candidate value: {:?}", self.candidate_value)?; - Ok(()) - } -} - -/// filter used when retrieving SC output events -#[derive(Default, Debug, Deserialize, Clone, Serialize)] -pub struct EventFilter { - /// optional start slot - pub start: Option, - /// optional end slot - pub end: Option, - /// optional emitter address - pub emitter_address: Option
, - /// optional caller address - pub original_caller_address: Option
, - /// optional operation id - pub original_operation_id: Option, - /// optional event status - /// - /// Some(true) means final - /// Some(false) means candidate - /// None means final _and_ candidate - pub is_final: Option, - /// optional execution status - /// - /// Some(true) means events coming from a failed sc execution - /// Some(false) means events coming from a succeeded sc execution - /// None means both - pub is_error: Option, -} - -/// read only bytecode execution request -#[derive(Debug, Deserialize, Clone, Serialize)] -pub struct ReadOnlyBytecodeExecution { - /// max available gas - pub max_gas: u64, - /// byte code - pub bytecode: Vec, - /// caller's address, optional - pub address: Option
, - /// Operation datastore, optional - pub operation_datastore: Option>, - /// optional event status - /// - /// Some(true) means final - /// Some(false) means candidate - /// None means final _and_ candidate - pub is_final: Option, -} - -/// read SC call request -#[derive(Debug, Deserialize, Clone, Serialize)] -pub struct ReadOnlyCall { - /// max available gas - pub max_gas: u64, - /// target address - pub target_address: Address, - /// target function - pub target_function: String, - /// function parameter - pub parameter: Vec, - /// caller's address, optional - pub caller_address: Option
, - /// optional event status - /// - /// Some(true) means final - /// Some(false) means candidate - /// None means final _and_ candidate - pub is_final: Option, -} - -/// SCRUD operations -#[derive(Display)] -#[strum(serialize_all = "snake_case")] -pub enum ScrudOperation { - /// search operation - Search, - /// create operation - Create, - /// read operation - Read, - /// update operation - Update, - /// delete operation - Delete, -} - -/// Bootsrap lists types -#[derive(Display)] -#[strum(serialize_all = "snake_case")] -pub enum ListType { - /// contains banned entry - Blacklist, - /// contains allowed entry - Whitelist, -} diff --git a/massa-models/src/block.rs b/massa-models/src/block.rs index 3486c13a5b7..5f03c056e6a 100644 --- a/massa-models/src/block.rs +++ b/massa-models/src/block.rs @@ -826,6 +826,27 @@ impl std::fmt::Display for BlockHeader { } } +/// Block status within the graph +#[derive(Eq, PartialEq, Debug, Deserialize, Serialize)] +pub enum BlockGraphStatus { + /// received but not yet graph-processed + Incoming, + /// waiting for its slot + WaitingForSlot, + /// waiting for a missing dependency + WaitingForDependencies, + /// active in alternative cliques + ActiveInAlternativeCliques, + /// active in blockclique + ActiveInBlockclique, + /// forever applies + Final, + /// discarded for any reason + Discarded, + /// not found in graph + NotFound, +} + #[cfg(test)] mod test { use super::*; diff --git a/massa-models/src/execution.rs b/massa-models/src/execution.rs index c49d87c3f49..2ca8ca807fe 100644 --- a/massa-models/src/execution.rs +++ b/massa-models/src/execution.rs @@ -1,48 +1,31 @@ -use std::{collections::VecDeque, fmt::Display}; +// Copyright (c) 2022 MASSA LABS -use crate::{output_event::SCOutputEvent, slot::Slot}; +use crate::{address::Address, operation::OperationId, slot::Slot}; use serde::{Deserialize, Serialize}; -/// The result of the read-only execution. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub enum ReadOnlyResult { - /// An error occurred during execution. - Error(String), - /// The result of a successful execution. - Ok(Vec), -} - -/// The response to a request for a read-only execution. -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct ExecuteReadOnlyResponse { - /// The slot at which the read-only execution occurred. - pub executed_at: Slot, - /// The result of the read-only execution. - pub result: ReadOnlyResult, - /// The output events generated by the read-only execution. - pub output_events: VecDeque, - /// The gas cost for the execution - pub gas_cost: u64, -} - -impl Display for ExecuteReadOnlyResponse { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!(f, "Executed at slot: {}", self.executed_at)?; - writeln!( - f, - "Result: {}", - match &self.result { - ReadOnlyResult::Error(e) => - format!("an error occurred during the execution: {}", e), - ReadOnlyResult::Ok(ret) => format!("success, returned value: {:?}", ret), - } - )?; - if !self.output_events.is_empty() { - writeln!(f, "Generated events:",)?; - for event in self.output_events.iter() { - writeln!(f, "{}", event)?; // id already displayed in event - } - } - Ok(()) - } +/// filter used when retrieving SC output events +#[derive(Default, Debug, Deserialize, Clone, Serialize)] +pub struct EventFilter { + /// optional start slot + pub start: Option, + /// optional end slot + pub end: Option, + /// optional emitter address + pub emitter_address: Option
, + /// optional caller address + pub original_caller_address: Option
, + /// optional operation id + pub original_operation_id: Option, + /// optional event status + /// + /// Some(true) means final + /// Some(false) means candidate + /// None means final _and_ candidate + pub is_final: Option, + /// optional execution status + /// + /// Some(true) means events coming from a failed sc execution + /// Some(false) means events coming from a succeeded sc execution + /// None means both + pub is_error: Option, } diff --git a/massa-models/src/ledger_models.rs b/massa-models/src/ledger.rs similarity index 100% rename from massa-models/src/ledger_models.rs rename to massa-models/src/ledger.rs diff --git a/massa-models/src/lib.rs b/massa-models/src/lib.rs index ae569ce12d6..117e812ce65 100644 --- a/massa-models/src/lib.rs +++ b/massa-models/src/lib.rs @@ -15,8 +15,6 @@ pub mod active_block; pub mod address; /// amount related structures pub mod amount; -/// structure use by the API -pub mod api; /// block-related structures pub mod block; /// clique @@ -34,7 +32,7 @@ pub mod error; /// execution related structures pub mod execution; /// ledger related structures -pub mod ledger_models; +pub mod ledger; /// node related structure pub mod node; /// operations diff --git a/massa-models/src/slot.rs b/massa-models/src/slot.rs index 86b8c7c177f..b4bd7b11784 100644 --- a/massa-models/src/slot.rs +++ b/massa-models/src/slot.rs @@ -329,3 +329,18 @@ impl Slot { .saturating_sub(s.thread as u64)) } } + +/// When an address is drawn to create an endorsement it is selected for a specific index +#[derive(Debug, Deserialize, Serialize, Hash, PartialEq, Eq)] +pub struct IndexedSlot { + /// slot + pub slot: Slot, + /// endorsement index in the slot + pub index: usize, +} + +impl std::fmt::Display for IndexedSlot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + writeln!(f, "Slot: {}, Index: {}", self.slot, self.index) + } +} diff --git a/massa-node/Cargo.toml b/massa-node/Cargo.toml index 12dff740ac8..a4466bab81f 100644 --- a/massa-node/Cargo.toml +++ b/massa-node/Cargo.toml @@ -24,6 +24,7 @@ paw = "1.0" structopt = { version = "0.3", features = ["paw"] } dialoguer = "0.10" # custom modules +massa_api_exports = { path = "../massa-api-exports" } massa_api = { path = "../massa-api" } massa_async_pool = { path = "../massa-async-pool" } massa_bootstrap = { path = "../massa-bootstrap" } diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index da06327140f..743d9b3211d 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -1150,8 +1150,8 @@ "name": "Operation" }, "name": "subscribe_new_operations", - "summary": "Subscribe to new received operations", - "description": "Subscribe to new received operations." + "summary": "Subscribe to new operations", + "description": "Subscribe to new operations." }, { "tags": [ @@ -1942,7 +1942,8 @@ "executed_at", "output_events", "result", - "gas_cost" + "gas_cost", + "state_changes" ], "type": "object", "properties": { @@ -1961,6 +1962,9 @@ "gas_cost": { "description": "The gas cost for the execution", "type": "number" + }, + "state_changes": { + "$ref": "#/components/schemas/StateChanges" } }, "additionalProperties": false @@ -2805,6 +2809,35 @@ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2": "Number" } }, + "StateChanges": { + "type": "object", + "additionalProperties": false, + "properties": { + "ledger_changes": { + "description": "ledger changes", + "type": "object" + }, + "async_pool_changes": { + "description": "async pool changes", + "type": "array" + }, + "pos_changes": { + "description": "pos changes", + "type": "object" + }, + "executed_ops_changes": { + "description": "executed operations changes", + "type": "object" + } + }, + "required": [ + "async_pool_changes", + "executed_ops_changes", + "ledger_changes", + "pos_changes" + ], + "title": "StateChanges" + }, "Transaction": { "title": "Transaction", "description": "Transation", diff --git a/massa-node/src/main.rs b/massa-node/src/main.rs index 7c675741975..b623046907d 100644 --- a/massa-node/src/main.rs +++ b/massa-node/src/main.rs @@ -8,7 +8,8 @@ use crate::settings::SETTINGS; use crossbeam_channel::{Receiver, TryRecvError}; use dialoguer::Password; -use massa_api::{APIConfig, ApiServer, ApiV2, Private, Public, RpcServer, StopHandle, API}; +use massa_api::{ApiServer, ApiV2, Private, Public, RpcServer, StopHandle, API}; +use massa_api_exports::config::APIConfig; use massa_async_pool::AsyncPoolConfig; use massa_bootstrap::{get_state, start_bootstrap_server, BootstrapConfig, BootstrapManager}; use massa_consensus_exports::events::ConsensusEvent; diff --git a/massa-pos-exports/src/controller_traits.rs b/massa-pos-exports/src/controller_traits.rs index 2bfb80b7da1..8b7af8a8b2b 100644 --- a/massa-pos-exports/src/controller_traits.rs +++ b/massa-pos-exports/src/controller_traits.rs @@ -7,9 +7,10 @@ use std::collections::BTreeMap; use crate::PosResult; use massa_hash::Hash; -use massa_models::address::Address; -use massa_models::api::IndexedSlot; -use massa_models::slot::Slot; +use massa_models::{ + address::Address, + slot::{IndexedSlot, Slot}, +}; #[cfg(feature = "testing")] use std::collections::{HashMap, VecDeque}; diff --git a/massa-pos-exports/src/cycle_info.rs b/massa-pos-exports/src/cycle_info.rs index e911c566591..ac1ab74a79b 100644 --- a/massa-pos-exports/src/cycle_info.rs +++ b/massa-pos-exports/src/cycle_info.rs @@ -20,6 +20,7 @@ use nom::{ IResult, Parser, }; use num::rational::Ratio; +use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::ops::Bound::Included; @@ -450,7 +451,7 @@ impl Deserializer for CycleInfoDeserializer { } /// Block production statistics -#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct ProductionStats { /// Number of successfully created blocks pub block_success_count: u64, diff --git a/massa-pos-exports/src/deferred_credits.rs b/massa-pos-exports/src/deferred_credits.rs index f5f72aa02af..0ff94a82017 100644 --- a/massa-pos-exports/src/deferred_credits.rs +++ b/massa-pos-exports/src/deferred_credits.rs @@ -14,12 +14,13 @@ use nom::{ sequence::tuple, IResult, Parser, }; +use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::ops::Bound::{Excluded, Included}; const DEFERRED_CREDITS_HASH_INITIAL_BYTES: &[u8; 32] = &[0; HASH_SIZE_BYTES]; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Deserialize, Serialize)] /// Structure containing all the PoS deferred credits information pub struct DeferredCredits { /// Deferred credits diff --git a/massa-pos-exports/src/pos_changes.rs b/massa-pos-exports/src/pos_changes.rs index 81143043053..bd189e8de66 100644 --- a/massa-pos-exports/src/pos_changes.rs +++ b/massa-pos-exports/src/pos_changes.rs @@ -14,9 +14,10 @@ use nom::{ sequence::tuple, IResult, Parser, }; +use serde::{Deserialize, Serialize}; /// Recap of all PoS changes -#[derive(Default, Debug, Clone)] +#[derive(Default, Debug, Clone, Deserialize, Serialize)] pub struct PoSChanges { /// extra block seed bits added pub seed_bits: BitVec, diff --git a/massa-pos-exports/src/test_exports/mock.rs b/massa-pos-exports/src/test_exports/mock.rs index 86d23a3717a..8b5dc5b86dd 100644 --- a/massa-pos-exports/src/test_exports/mock.rs +++ b/massa-pos-exports/src/test_exports/mock.rs @@ -10,7 +10,10 @@ use std::{ }; use massa_hash::Hash; -use massa_models::{address::Address, api::IndexedSlot, slot::Slot}; +use massa_models::{ + address::Address, + slot::{IndexedSlot, Slot}, +}; use crate::{PosResult, Selection, SelectorController}; diff --git a/massa-pos-worker/src/controller.rs b/massa-pos-worker/src/controller.rs index 4d6e19e08dd..79bd08b9d69 100644 --- a/massa-pos-worker/src/controller.rs +++ b/massa-pos-worker/src/controller.rs @@ -7,7 +7,10 @@ use std::collections::BTreeMap; use crate::{Command, DrawCachePtr}; use massa_hash::Hash; -use massa_models::{address::Address, api::IndexedSlot, slot::Slot}; +use massa_models::{ + address::Address, + slot::{IndexedSlot, Slot}, +}; use massa_pos_exports::{PosError, PosResult, Selection, SelectorController, SelectorManager}; #[cfg(feature = "testing")] use std::collections::{HashMap, VecDeque}; diff --git a/massa-sdk/Cargo.toml b/massa-sdk/Cargo.toml index ce8e1434561..759252af4f2 100644 --- a/massa-sdk/Cargo.toml +++ b/massa-sdk/Cargo.toml @@ -6,5 +6,6 @@ edition = "2021" [dependencies] jsonrpsee = { version = "0.16.2", features = ["client"] } http = "0.2.8" +massa_api_exports = { path = "../massa-api-exports" } massa_models = { path = "../massa-models" } massa_time = { path = "../massa-time" } diff --git a/massa-sdk/src/lib.rs b/massa-sdk/src/lib.rs index b423215362c..a5e5d062708 100644 --- a/massa-sdk/src/lib.rs +++ b/massa-sdk/src/lib.rs @@ -13,22 +13,28 @@ use jsonrpsee::rpc_params; use jsonrpsee::types::error::CallError; use jsonrpsee::types::ErrorObject; use jsonrpsee::ws_client::{HeaderMap, HeaderValue, WsClient, WsClientBuilder}; -use massa_models::api::{ - AddressInfo, BlockInfo, BlockSummary, DatastoreEntryInput, DatastoreEntryOutput, - EndorsementInfo, EventFilter, NodeStatus, OperationInfo, OperationInput, - ReadOnlyBytecodeExecution, ReadOnlyCall, TimeInterval, +use massa_api_exports::{ + address::AddressInfo, + block::{BlockInfo, BlockSummary}, + datastore::{DatastoreEntryInput, DatastoreEntryOutput}, + endorsement::EndorsementInfo, + execution::{ExecuteReadOnlyResponse, ReadOnlyBytecodeExecution, ReadOnlyCall}, + node::NodeStatus, + operation::{OperationInfo, OperationInput}, + TimeInterval, }; -use massa_models::block::{BlockHeader, FilledBlock}; -use massa_models::clique::Clique; -use massa_models::composite::PubkeySig; -use massa_models::execution::ExecuteReadOnlyResponse; -use massa_models::node::NodeId; -use massa_models::operation::Operation; -use massa_models::output_event::SCOutputEvent; -use massa_models::prehash::{PreHashMap, PreHashSet}; -use massa_models::version::Version; use massa_models::{ - address::Address, block::BlockId, endorsement::EndorsementId, operation::OperationId, + address::Address, + block::{BlockHeader, BlockId, FilledBlock}, + clique::Clique, + composite::PubkeySig, + endorsement::EndorsementId, + execution::EventFilter, + node::NodeId, + operation::{Operation, OperationId}, + output_event::SCOutputEvent, + prehash::{PreHashMap, PreHashSet}, + version::Version, }; use jsonrpsee::{core::Error as JsonRpseeError, core::RpcResult, http_client::HttpClientBuilder}; @@ -498,7 +504,7 @@ impl RpcClientV2 { } } - /// New received only operations. + /// New produced operations. pub async fn subscribe_new_operations( &self, ) -> Result, jsonrpsee::core::Error> { From 38139c4ebd6001185bf2a1e7bb634f65e1322f4e Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 17 Jan 2023 13:27:44 +0100 Subject: [PATCH 29/80] Add checks on object deserialisation (#3364) Co-authored-by: AurelienFT --- Cargo.lock | 21 + .../src/export_active_block.rs | 12 +- massa-models/Cargo.toml | 1 + massa-models/src/block.rs | 683 ++++++++++++++++-- massa-models/src/endorsement.rs | 18 + massa-models/src/secure_share.rs | 2 +- 6 files changed, 676 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8c59e2c9f1..827ed27ffdb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -623,6 +623,26 @@ dependencies = [ "winapi", ] +[[package]] +name = "const_format" +version = "0.2.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7309d9b4d3d2c0641e018d449232f2e28f1b22933c137f157d3dbc14228b8c0e" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f47bf7270cf70d370f8f98c1abb6d2d4cf60a6845d30e05bfb90c6568650" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + [[package]] name = "constant_time_eq" version = "0.2.4" @@ -2621,6 +2641,7 @@ dependencies = [ "bitvec", "bs58", "config", + "const_format", "directories", "displaydoc", "lazy_static", diff --git a/massa-consensus-exports/src/export_active_block.rs b/massa-consensus-exports/src/export_active_block.rs index 6e707de1085..3e374b4de7f 100644 --- a/massa-consensus-exports/src/export_active_block.rs +++ b/massa-consensus-exports/src/export_active_block.rs @@ -156,7 +156,7 @@ impl Deserializer for ExportActiveBlockDeserializer { /// ## Example: /// ```rust /// use massa_consensus_exports::export_active_block::{ExportActiveBlock, ExportActiveBlockDeserializer, ExportActiveBlockSerializer}; - /// use massa_models::{ledger_models::LedgerChanges, config::THREAD_COUNT, rolls::RollUpdates, block::{BlockId, Block, BlockSerializer, BlockHeader, BlockHeaderSerializer}, prehash::PreHashSet, endorsement::{Endorsement, EndorsementSerializerLW}, slot::Slot, secure_share::SecureShareContent}; + /// use massa_models::{ledger_models::LedgerChanges, config::THREAD_COUNT, rolls::RollUpdates, block::{BlockId, Block, BlockSerializer, BlockHeader, BlockHeaderSerializer}, prehash::PreHashSet, endorsement::{Endorsement, EndorsementSerializer}, slot::Slot, secure_share::SecureShareContent}; /// use massa_hash::Hash; /// use std::collections::HashSet; /// use massa_signature::KeyPair; @@ -178,19 +178,19 @@ impl Deserializer for ExportActiveBlockDeserializer { /// Endorsement { /// slot: Slot::new(1, 1), /// index: 1, - /// endorsed_block: BlockId(Hash::compute_from("blk1".as_bytes())), + /// endorsed_block: BlockId(Hash::compute_from(&[1])), /// }, - /// EndorsementSerializerLW::new(), + /// EndorsementSerializer::new(), /// &keypair, /// ) /// .unwrap(), /// Endorsement::new_verifiable( /// Endorsement { - /// slot: Slot::new(4, 0), + /// slot: Slot::new(1, 1), /// index: 3, - /// endorsed_block: BlockId(Hash::compute_from("blk2".as_bytes())), + /// endorsed_block: BlockId(Hash::compute_from(&[1])), /// }, - /// EndorsementSerializerLW::new(), + /// EndorsementSerializer::new(), /// &keypair, /// ) /// .unwrap(), diff --git a/massa-models/Cargo.toml b/massa-models/Cargo.toml index a5c8b4a7e79..b397edb7311 100644 --- a/massa-models/Cargo.toml +++ b/massa-models/Cargo.toml @@ -24,6 +24,7 @@ massa_hash = { path = "../massa-hash" } massa_serialization = { path = "../massa-serialization" } massa_signature = { path = "../massa-signature" } massa_time = { path = "../massa-time" } +const_format = "0.2.30" [dev-dependencies] serial_test = "0.10" diff --git a/massa-models/src/block.rs b/massa-models/src/block.rs index 5f03c056e6a..71a66f5eab1 100644 --- a/massa-models/src/block.rs +++ b/massa-models/src/block.rs @@ -1,5 +1,6 @@ //! Copyright (c) 2022 MASSA LABS +use crate::config::THREAD_COUNT; use crate::endorsement::{EndorsementId, EndorsementSerializer, EndorsementSerializerLW}; use crate::prehash::PreHashed; use crate::secure_share::{ @@ -31,6 +32,7 @@ use nom::{ }; use serde::{Deserialize, Serialize}; use serde_with::{DeserializeFromStr, SerializeDisplay}; +use std::collections::HashSet; use std::convert::TryInto; use std::fmt::Formatter; use std::ops::Bound::{Excluded, Included}; @@ -374,7 +376,7 @@ impl Deserializer for BlockDeserializer { /// use massa_signature::KeyPair; /// use massa_serialization::{Serializer, Deserializer, DeserializeError}; /// let keypair = KeyPair::generate(); - /// let parents = (0..THREAD_COUNT) + /// let parents: Vec = (0..THREAD_COUNT) /// .map(|i| BlockId(Hash::compute_from(&[i]))) /// .collect(); /// @@ -382,14 +384,14 @@ impl Deserializer for BlockDeserializer { /// let orig_header = BlockHeader::new_verifiable( /// BlockHeader { /// slot: Slot::new(1, 1), - /// parents, + /// parents: parents.clone(), /// operation_merkle_root: Hash::compute_from("mno".as_bytes()), /// endorsements: vec![ /// Endorsement::new_verifiable( /// Endorsement { /// slot: Slot::new(1, 1), - /// index: 1, - /// endorsed_block: BlockId(Hash::compute_from("blk1".as_bytes())), + /// index: 0, + /// endorsed_block: parents[1].clone(), /// }, /// EndorsementSerializer::new(), /// &keypair, @@ -397,9 +399,9 @@ impl Deserializer for BlockDeserializer { /// .unwrap(), /// Endorsement::new_verifiable( /// Endorsement { - /// slot: Slot::new(4, 0), - /// index: 3, - /// endorsed_block: BlockId(Hash::compute_from("blk2".as_bytes())), + /// slot: Slot::new(1, 1), + /// index: 1, + /// endorsed_block: parents[1].clone(), /// }, /// EndorsementSerializer::new(), /// &keypair, @@ -504,6 +506,49 @@ pub struct BlockHeader { pub endorsements: Vec, } +// TODO: gh-issue #3398 +#[cfg(any(test, feature = "testing"))] +impl BlockHeader { + fn assert_invariants(&self) -> Result<(), Box> { + if self.slot.period == 0 { + if !self.parents.is_empty() { + return Err("Invariant broken: genesis block with parent(s)".into()); + } + if !self.endorsements.is_empty() { + return Err("Invariant broken: genesis block with endorsement(s)".into()); + } + } else { + if self.parents.len() != crate::config::THREAD_COUNT as usize { + return Err( + "Invariant broken: non-genesis block with incorrect number of parents".into(), + ); + } + if self.endorsements.len() > crate::config::ENDORSEMENT_COUNT as usize { + return Err("Invariant broken: endorsement count too high".into()); + } + + let parent_id = self.parents[self.slot.thread as usize]; + for endo in self.endorsements.iter() { + if endo.content.endorsed_block != parent_id { + return Err("Invariant broken: endorsement doesn't match parent".into()); + } + } + } + + // assert that the endorsement indexes are all unique... + let mut set = HashSet::new(); + for endo in self.endorsements.iter() { + // ...and check signatures + invariants while at it + endo.check_invariants()?; + + if !set.insert(endo.content.index) { + return Err("Endorsement duplicate index found".into()); + } + } + Ok(()) + } +} + // NOTE: TODO // impl Signable for BlockHeader { // fn get_signature_message(&self) -> Result { @@ -524,6 +569,14 @@ impl SecuredHeader { pub fn get_fitness(&self) -> u64 { (self.content.endorsements.len() as u64) + 1 } + // TODO: gh-issue #3398 + #[allow(dead_code)] + #[cfg(any(test, feature = "testing"))] + fn assert_invariants(&self) -> Result<(), Box> { + self.content.assert_invariants()?; + self.verify_signature() + .map_err(|er| format!("{}", er).into()) + } } impl SecureShareContent for BlockHeader {} @@ -666,37 +719,37 @@ impl Deserializer for BlockHeaderDeserializer { /// ```rust /// use massa_models::block::{BlockId, BlockHeader, BlockHeaderDeserializer, BlockHeaderSerializer}; /// use massa_models::{config::THREAD_COUNT, slot::Slot, secure_share::SecureShareContent}; - /// use massa_models::endorsement::{Endorsement, EndorsementSerializerLW}; + /// use massa_models::endorsement::{Endorsement, EndorsementSerializer}; /// use massa_hash::Hash; /// use massa_signature::KeyPair; /// use massa_serialization::{Serializer, Deserializer, DeserializeError}; /// /// let keypair = KeyPair::generate(); - /// let parents = (0..THREAD_COUNT) + /// let parents: Vec = (0..THREAD_COUNT) /// .map(|i| BlockId(Hash::compute_from(&[i]))) /// .collect(); /// let header = BlockHeader { /// slot: Slot::new(1, 1), - /// parents, + /// parents: parents.clone(), /// operation_merkle_root: Hash::compute_from("mno".as_bytes()), /// endorsements: vec![ /// Endorsement::new_verifiable( /// Endorsement { /// slot: Slot::new(1, 1), - /// index: 1, - /// endorsed_block: BlockId(Hash::compute_from("blk1".as_bytes())), + /// index: 0, + /// endorsed_block: parents[1].clone(), /// }, - /// EndorsementSerializerLW::new(), + /// EndorsementSerializer::new(), /// &keypair, /// ) /// .unwrap(), /// Endorsement::new_verifiable( /// Endorsement { - /// slot: Slot::new(4, 0), - /// index: 3, - /// endorsed_block: BlockId(Hash::compute_from("blk2".as_bytes())), + /// slot: Slot::new(1, 1), + /// index: 1, + /// endorsed_block: parents[1].clone(), /// }, - /// EndorsementSerializerLW::new(), + /// EndorsementSerializer::new(), /// &keypair, /// ) /// .unwrap(), @@ -715,9 +768,8 @@ impl Deserializer for BlockHeaderDeserializer { buffer: &'a [u8], ) -> IResult<&'a [u8], BlockHeader, E> { let (rest, (slot, parents, operation_merkle_root)): (&[u8], (Slot, Vec, Hash)) = - context( - "Failed BlockHeader deserialization", - tuple(( + context("Failed BlockHeader deserialization", |input| { + let (rest, (slot, parents)) = tuple(( context("Failed slot deserialization", |input| { self.slot_deserializer.deserialize(input) }), @@ -738,25 +790,53 @@ impl Deserializer for BlockHeaderDeserializer { ), )), ), - context("Failed operation_merkle_root", |input| { - self.hash_deserializer.deserialize(input) - }), - )), - ) + )) + .parse(input)?; + + // validate the parent/slot invariats before moving on to other fields + if slot.period == 0 && !parents.is_empty() { + return Err(nom::Err::Failure(ContextError::add_context( + rest, + "Genesis block cannot contain parents", + ParseError::from_error_kind(rest, nom::error::ErrorKind::Fail), + ))); + } else if slot.period != 0 && parents.len() != THREAD_COUNT as usize { + return Err(nom::Err::Failure(ContextError::add_context( + rest, + const_format::formatcp!( + "Non-genesis block must have {} parents", + THREAD_COUNT + ), + ParseError::from_error_kind(rest, nom::error::ErrorKind::Fail), + ))); + } + + let (rest, merkle) = context("Failed operation_merkle_root", |input| { + self.hash_deserializer.deserialize(input) + }) + .parse(rest)?; + Ok((rest, (slot, parents, merkle))) + }) .parse(buffer)?; if parents.is_empty() { + let res = BlockHeader { + slot, + parents, + operation_merkle_root, + endorsements: Vec::new(), + }; + + // TODO: gh-issue #3398 + #[cfg(any(test, feature = "testing"))] + res.assert_invariants().unwrap(); + return Ok(( &rest[1..], // Because there is 0 endorsements, we have a remaining 0 in rest and we don't need it - BlockHeader { - slot, - parents, - operation_merkle_root, - endorsements: Vec::new(), - }, + res, )); } - // Now deser the endorsements (which were: lw serialized) + // Now deser the endorsements (which were light-weight serialized) let endorsement_deserializer = SecureShareDeserializer::new(EndorsementDeserializerLW::new( self.endorsement_count, @@ -764,28 +844,55 @@ impl Deserializer for BlockHeaderDeserializer { parents[slot.thread as usize], )); - let (rest, endorsements) = context( + let parent_id = parents[slot.thread as usize]; + let (rest, endorsements): (&[u8], Vec>) = context( "Failed endorsements deserialization", length_count::<&[u8], SecureShare, u32, E, _, _>( context("Failed length deserialization", |input| { self.length_endorsements_deserializer.deserialize(input) }), context("Failed endorsement deserialization", |input| { - endorsement_deserializer.deserialize_with(&self.endorsement_serializer, input) + let (rest, endo) = endorsement_deserializer + .deserialize_with(&self.endorsement_serializer, input)?; + + if endo.content.endorsed_block != parent_id { + return Err(nom::Err::Failure(ContextError::add_context( + rest, + "Endorsement does not match block parents", + ParseError::from_error_kind(rest, nom::error::ErrorKind::Fail), + ))); + } + + Ok((rest, endo)) }), ), ) .parse(rest)?; - Ok(( - rest, - BlockHeader { - slot, - parents, - operation_merkle_root, - endorsements, - }, - )) + let mut set = HashSet::new(); + + for end in endorsements.iter() { + if !set.insert(end.content.index) { + return Err(nom::Err::Failure(ContextError::add_context( + rest, + "Duplicate endorsement index found", + ParseError::from_error_kind(rest, nom::error::ErrorKind::Fail), + ))); + } + } + + let header = BlockHeader { + slot, + parents, + operation_merkle_root, + endorsements, + }; + + // TODO: gh-issue #3398 + #[cfg(any(test, feature = "testing"))] + header.assert_invariants().unwrap(); + + Ok((rest, header)) } } @@ -849,6 +956,7 @@ pub enum BlockGraphStatus { #[cfg(test)] mod test { + use super::*; use crate::{ config::{ENDORSEMENT_COUNT, MAX_OPERATIONS_PER_BLOCK, THREAD_COUNT}, @@ -873,10 +981,23 @@ mod test { }) .collect(); - let endo = Endorsement::new_verifiable( + let endo1 = Endorsement::new_verifiable( + Endorsement { + slot: Slot::new(1, 0), + index: 0, + endorsed_block: BlockId( + Hash::from_bs58_check("bq1NsaCBAfseMKSjNBYLhpK7M5eeef2m277MYS2P2k424GaDf") + .unwrap(), + ), + }, + EndorsementSerializer::new(), + &keypair, + ) + .unwrap(); + let endo2 = Endorsement::new_verifiable( Endorsement { slot: Slot::new(1, 0), - index: 1, + index: ENDORSEMENT_COUNT - 1, endorsed_block: BlockId( Hash::from_bs58_check("bq1NsaCBAfseMKSjNBYLhpK7M5eeef2m277MYS2P2k424GaDf") .unwrap(), @@ -893,7 +1014,7 @@ mod test { slot: Slot::new(1, 0), parents, operation_merkle_root: Hash::compute_from("mno".as_bytes()), - endorsements: vec![endo], + endorsements: vec![endo1, endo2], }, BlockHeaderSerializer::new(), &keypair, @@ -948,10 +1069,8 @@ mod test { for ed in orig_block.header.content.endorsements.iter() { ed.verify_signature().unwrap(); } - res_block.content.header.verify_signature().unwrap(); - for ed in res_block.content.header.content.endorsements.iter() { - ed.verify_signature().unwrap(); - } + + res_block.content.header.assert_invariants().unwrap(); } #[test] @@ -963,7 +1082,7 @@ mod test { // create block header let orig_header = BlockHeader::new_verifiable( BlockHeader { - slot: Slot::new(1, 1), + slot: Slot::new(0, 1), parents, operation_merkle_root: Hash::compute_from("mno".as_bytes()), endorsements: vec![], @@ -994,6 +1113,8 @@ mod test { .deserialize::(&ser_block) .unwrap(); + res_block.content.header.assert_invariants().unwrap(); + // check equality assert!(rest.is_empty()); @@ -1022,13 +1143,13 @@ mod test { #[test] #[serial] - fn test_invalid_genesis_block_serialization() { + fn test_invalid_genesis_block_serialization_with_endorsements() { let keypair = KeyPair::generate(); let parents: Vec = vec![]; // Genesis block do not have any parents and thus cannot embed endorsements let endorsement = Endorsement { - slot: Slot::new(1, 1), + slot: Slot::new(0, 1), index: 1, endorsed_block: BlockId(Hash::compute_from(&[1])), }; @@ -1036,7 +1157,7 @@ mod test { // create block header let orig_header = BlockHeader::new_verifiable( BlockHeader { - slot: Slot::new(1, 1), + slot: Slot::new(0, 1), parents, operation_merkle_root: Hash::compute_from("mno".as_bytes()), endorsements: vec![Endorsement::new_verifiable( @@ -1071,6 +1192,460 @@ mod test { ) .deserialize::(&ser_block); + // TODO: Catch an failed deser being a fail, instead of a recoverable error + // TODO: assert that the error variant/context/etc. matches the expected failure + assert!(res.is_err()); + // let nom::Err::Failure(_) = res.unwrap_err() else { + // panic!("Deserialisation with invalid endorsements should be total fail"); + // }; + } + #[test] + #[serial] + fn test_invalid_genesis_block_serialization_with_parents() { + let keypair = KeyPair::generate(); + let parents = (0..THREAD_COUNT) + .map(|i| BlockId(Hash::compute_from(&[i]))) + .collect(); + + // create block header + let orig_header = BlockHeader::new_verifiable( + BlockHeader { + slot: Slot::new(0, 1), + parents, + operation_merkle_root: Hash::compute_from("mno".as_bytes()), + endorsements: vec![], + }, + BlockHeaderSerializer::new(), + &keypair, + ) + .unwrap(); + + // create block + let orig_block = Block { + header: orig_header, + operations: Default::default(), + }; + + // serialize block + let secured_block: SecureShareBlock = + Block::new_verifiable(orig_block, BlockSerializer::new(), &keypair).unwrap(); + let mut ser_block = Vec::new(); + SecureShareSerializer::new() + .serialize(&secured_block, &mut ser_block) + .unwrap(); + + // deserialize + let res: Result<(&[u8], SecureShareBlock), _> = SecureShareDeserializer::new( + BlockDeserializer::new(THREAD_COUNT, MAX_OPERATIONS_PER_BLOCK, ENDORSEMENT_COUNT), + ) + .deserialize::(&ser_block); + + // TODO: Catch an failed deser being a fail, instead of a recoverable error + // TODO: assert that the error variant/context/etc. matches the expected failure + assert!(res.is_err()); + } + #[test] + #[serial] + fn test_invalid_block_serialization_no_parents() { + let keypair = KeyPair::generate(); + // Non genesis block must have THREAD_COUNT parents + + // create block header + let orig_header = BlockHeader::new_verifiable( + BlockHeader { + slot: Slot::new(1, 1), + parents: vec![], + operation_merkle_root: Hash::compute_from("mno".as_bytes()), + endorsements: vec![], + }, + BlockHeaderSerializer::new(), + &keypair, + ) + .unwrap(); + + // create block + let orig_block = Block { + header: orig_header, + operations: Default::default(), + }; + + // serialize block + let secured_block: SecureShareBlock = + Block::new_verifiable(orig_block, BlockSerializer::new(), &keypair).unwrap(); + let mut ser_block = Vec::new(); + SecureShareSerializer::new() + .serialize(&secured_block, &mut ser_block) + .unwrap(); + + // deserialize + let res: Result<(&[u8], SecureShareBlock), _> = SecureShareDeserializer::new( + BlockDeserializer::new(THREAD_COUNT, MAX_OPERATIONS_PER_BLOCK, ENDORSEMENT_COUNT), + ) + .deserialize::(&ser_block); + + // TODO: Catch an failed deser being a fail, instead of a recoverable error + // TODO: assert that the error variant/context/etc. matches the expected failure + assert!(res.is_err()); + } + #[test] + #[serial] + fn test_invalid_block_serialization_obo_high_parent_count() { + let keypair = KeyPair::generate(); + // Non genesis block must have THREAD_COUNT parents + let parents = (0..=THREAD_COUNT) + .map(|i| BlockId(Hash::compute_from(&[i]))) + .collect(); + + // create block header + let orig_header = BlockHeader::new_verifiable( + BlockHeader { + slot: Slot::new(1, 1), + parents, + operation_merkle_root: Hash::compute_from("mno".as_bytes()), + endorsements: vec![], + }, + BlockHeaderSerializer::new(), + &keypair, + ) + .unwrap(); + + // create block + let orig_block = Block { + header: orig_header, + operations: Default::default(), + }; + + // serialize block + let secured_block: SecureShareBlock = + Block::new_verifiable(orig_block, BlockSerializer::new(), &keypair).unwrap(); + let mut ser_block = Vec::new(); + SecureShareSerializer::new() + .serialize(&secured_block, &mut ser_block) + .unwrap(); + + // deserialize + let res: Result<(&[u8], SecureShareBlock), _> = SecureShareDeserializer::new( + BlockDeserializer::new(THREAD_COUNT, MAX_OPERATIONS_PER_BLOCK, ENDORSEMENT_COUNT), + ) + .deserialize::(&ser_block); + + // TODO: Catch an failed deser being a fail, instead of a recoverable error + // TODO: assert that the error variant/context/etc. matches the expected failure + assert!(res.is_err()); + } + + #[test] + #[serial] + fn test_block_serialization_max_endo_count() { + let keypair = + KeyPair::from_str("S1bXjyPwrssNmG4oUG5SEqaUhQkVArQi7rzQDWpCprTSmEgZDGG").unwrap(); + let endorsed = BlockId( + Hash::from_bs58_check("bq1NsaCBAfseMKSjNBYLhpK7M5eeef2m277MYS2P2k424GaDf").unwrap(), + ); + let fillers = (1..THREAD_COUNT).map(|i| BlockId(Hash::compute_from(&[i]))); + let parents = std::iter::once(endorsed).chain(fillers).collect(); + + let endorsements = (0..ENDORSEMENT_COUNT) + .map(|i| { + Endorsement::new_verifiable( + Endorsement { + slot: Slot::new(1, 0), + index: i, + endorsed_block: BlockId( + Hash::from_bs58_check( + "bq1NsaCBAfseMKSjNBYLhpK7M5eeef2m277MYS2P2k424GaDf", + ) + .unwrap(), + ), + }, + EndorsementSerializer::new(), + &keypair, + ) + .unwrap() + }) + .collect(); + // create block header + let orig_header = BlockHeader::new_verifiable( + BlockHeader { + slot: Slot::new(1, 0), + parents, + operation_merkle_root: Hash::compute_from("mno".as_bytes()), + endorsements, + }, + BlockHeaderSerializer::new(), + &keypair, + ) + .unwrap(); + + // create block + let orig_block = Block { + header: orig_header, + operations: Default::default(), + }; + + // serialize block + let secured_block: SecureShareBlock = + Block::new_verifiable(orig_block, BlockSerializer::new(), &keypair).unwrap(); + let mut ser_block = Vec::new(); + SecureShareSerializer::new() + .serialize(&secured_block, &mut ser_block) + .unwrap(); + + // deserialize + let (_, res): (&[u8], SecureShareBlock) = SecureShareDeserializer::new( + BlockDeserializer::new(THREAD_COUNT, MAX_OPERATIONS_PER_BLOCK, ENDORSEMENT_COUNT), + ) + .deserialize::(&ser_block) + .unwrap(); + + res.content.header.assert_invariants().unwrap(); + } + #[test] + #[serial] + fn test_invalid_block_serialization_obo_low_parent_count() { + let keypair = KeyPair::generate(); + // Non genesis block must have THREAD_COUNT parents + let parents = (1..THREAD_COUNT) + .map(|i| BlockId(Hash::compute_from(&[i]))) + .collect(); + + // create block header + let orig_header = BlockHeader::new_verifiable( + BlockHeader { + slot: Slot::new(1, 1), + parents, + operation_merkle_root: Hash::compute_from("mno".as_bytes()), + endorsements: vec![], + }, + BlockHeaderSerializer::new(), + &keypair, + ) + .unwrap(); + + // create block + let orig_block = Block { + header: orig_header, + operations: Default::default(), + }; + + // serialize block + let secured_block: SecureShareBlock = + Block::new_verifiable(orig_block, BlockSerializer::new(), &keypair).unwrap(); + let mut ser_block = Vec::new(); + SecureShareSerializer::new() + .serialize(&secured_block, &mut ser_block) + .unwrap(); + + // deserialize + let res: Result<(&[u8], SecureShareBlock), _> = SecureShareDeserializer::new( + BlockDeserializer::new(THREAD_COUNT, MAX_OPERATIONS_PER_BLOCK, ENDORSEMENT_COUNT), + ) + .deserialize::(&ser_block); + + // TODO: Catch an failed deser being a fail, instead of a recoverable error + // TODO: assert that the error variant/context/etc. matches the expected failure + assert!(res.is_err()); + } + #[test] + #[serial] + fn test_invalid_block_serialization_obo_high_endo_count() { + let keypair = KeyPair::generate(); + // Non genesis block must have THREAD_COUNT parents + let parents = (0..THREAD_COUNT) + .map(|i| BlockId(Hash::compute_from(&[i]))) + .collect(); + + let endorsements = (0..=ENDORSEMENT_COUNT) + .map(|i| { + Endorsement::new_verifiable( + Endorsement { + slot: Slot::new(0, 1), + index: i, + endorsed_block: BlockId(Hash::compute_from(&[i as u8])), + }, + EndorsementSerializer::new(), + &keypair, + ) + .unwrap() + }) + .collect(); + // create block header + let orig_header = BlockHeader::new_verifiable( + BlockHeader { + slot: Slot::new(1, 1), + parents, + operation_merkle_root: Hash::compute_from("mno".as_bytes()), + endorsements, + }, + BlockHeaderSerializer::new(), + &keypair, + ) + .unwrap(); + + // create block + let orig_block = Block { + header: orig_header, + operations: Default::default(), + }; + + // serialize block + let secured_block: SecureShareBlock = + Block::new_verifiable(orig_block, BlockSerializer::new(), &keypair).unwrap(); + let mut ser_block = Vec::new(); + SecureShareSerializer::new() + .serialize(&secured_block, &mut ser_block) + .unwrap(); + + // deserialize + let res: Result<(&[u8], SecureShareBlock), _> = SecureShareDeserializer::new( + BlockDeserializer::new(THREAD_COUNT, MAX_OPERATIONS_PER_BLOCK, ENDORSEMENT_COUNT), + ) + .deserialize::(&ser_block); + + // TODO: Catch an failed deser being a fail, instead of a recoverable error + // TODO: see issue #3400 + assert!(res.is_err()); + } + #[test] + #[serial] + fn test_invalid_endorsement_idx() { + let keypair = + KeyPair::from_str("S1bXjyPwrssNmG4oUG5SEqaUhQkVArQi7rzQDWpCprTSmEgZDGG").unwrap(); + let parents = (0..THREAD_COUNT) + .map(|_i| { + BlockId( + Hash::from_bs58_check("bq1NsaCBAfseMKSjNBYLhpK7M5eeef2m277MYS2P2k424GaDf") + .unwrap(), + ) + }) + .collect(); + + let endo1 = Endorsement::new_verifiable( + Endorsement { + slot: Slot::new(1, 0), + index: ENDORSEMENT_COUNT, + endorsed_block: BlockId( + Hash::from_bs58_check("bq1NsaCBAfseMKSjNBYLhpK7M5eeef2m277MYS2P2k424GaDf") + .unwrap(), + ), + }, + EndorsementSerializer::new(), + &keypair, + ) + .unwrap(); + + // create block header + let orig_header = BlockHeader::new_verifiable( + BlockHeader { + slot: Slot::new(1, 0), + parents, + operation_merkle_root: Hash::compute_from("mno".as_bytes()), + endorsements: vec![endo1], + }, + BlockHeaderSerializer::new(), + &keypair, + ) + .unwrap(); + + // create block + let orig_block = Block { + header: orig_header.clone(), + operations: Default::default(), + }; + + // serialize block + let secured_block: SecureShareBlock = + Block::new_verifiable(orig_block.clone(), BlockSerializer::new(), &keypair).unwrap(); + let mut ser_block = Vec::new(); + SecureShareSerializer::new() + .serialize(&secured_block, &mut ser_block) + .unwrap(); + + // deserialize + let res: Result<(&[u8], SecureShareBlock), _> = SecureShareDeserializer::new( + BlockDeserializer::new(THREAD_COUNT, MAX_OPERATIONS_PER_BLOCK, ENDORSEMENT_COUNT), + ) + .deserialize::(&ser_block); + // TODO: Catch an failed deser being a fail, instead of a recoverable error + // TODO: assert that the error variant/context/etc. matches the expected failure + assert!(res.is_err()); + } + #[test] + #[serial] + fn test_invalid_dupe_endo_idx() { + let keypair = + KeyPair::from_str("S1bXjyPwrssNmG4oUG5SEqaUhQkVArQi7rzQDWpCprTSmEgZDGG").unwrap(); + let parents = (0..THREAD_COUNT) + .map(|_i| { + BlockId( + Hash::from_bs58_check("bq1NsaCBAfseMKSjNBYLhpK7M5eeef2m277MYS2P2k424GaDf") + .unwrap(), + ) + }) + .collect(); + + let endo1 = Endorsement::new_verifiable( + Endorsement { + slot: Slot::new(1, 0), + index: 0, + endorsed_block: BlockId( + Hash::from_bs58_check("bq1NsaCBAfseMKSjNBYLhpK7M5eeef2m277MYS2P2k424GaDf") + .unwrap(), + ), + }, + EndorsementSerializer::new(), + &keypair, + ) + .unwrap(); + let endo2 = Endorsement::new_verifiable( + Endorsement { + slot: Slot::new(1, 0), + index: 0, + endorsed_block: BlockId( + Hash::from_bs58_check("bq1NsaCBAfseMKSjNBYLhpK7M5eeef2m277MYS2P2k424GaDf") + .unwrap(), + ), + }, + EndorsementSerializer::new(), + &keypair, + ) + .unwrap(); + + // create block header + let orig_header = BlockHeader::new_verifiable( + BlockHeader { + slot: Slot::new(1, 0), + parents, + operation_merkle_root: Hash::compute_from("mno".as_bytes()), + endorsements: vec![endo1, endo2], + }, + BlockHeaderSerializer::new(), + &keypair, + ) + .unwrap(); + + // create block + let orig_block = Block { + header: orig_header.clone(), + operations: Default::default(), + }; + + // serialize block + let secured_block: SecureShareBlock = + Block::new_verifiable(orig_block.clone(), BlockSerializer::new(), &keypair).unwrap(); + let mut ser_block = Vec::new(); + SecureShareSerializer::new() + .serialize(&secured_block, &mut ser_block) + .unwrap(); + + // deserialize + let res: Result<(&[u8], SecureShareBlock), _> = SecureShareDeserializer::new( + BlockDeserializer::new(THREAD_COUNT, MAX_OPERATIONS_PER_BLOCK, ENDORSEMENT_COUNT), + ) + .deserialize::(&ser_block); + + // TODO: Catch an failed deser being a fail, instead of a recoverable error + // TODO: assert that the error variant/context/etc. matches the expected failure assert!(res.is_err()); } } diff --git a/massa-models/src/endorsement.rs b/massa-models/src/endorsement.rs index 8be2658805d..0bc554e1b19 100644 --- a/massa-models/src/endorsement.rs +++ b/massa-models/src/endorsement.rs @@ -145,6 +145,24 @@ pub struct Endorsement { pub endorsed_block: BlockId, } +#[cfg(any(test, feature = "testing"))] +impl SecureShareEndorsement { + // TODO: gh-issue #3398 + /// Used under testing conditions to validate an instance of Self + pub fn check_invariants(&self) -> Result<(), Box> { + if let Err(e) = self.verify_signature() { + return Err(e.into()); + } + if self.content.slot.thread >= crate::config::THREAD_COUNT { + Err("Endorsement slot on non-existant thread".into()) + } else if self.content.index >= crate::config::ENDORSEMENT_COUNT { + Err("Endorsement index out of range".into()) + } else { + Ok(()) + } + } +} + /// Wrapped endorsement pub type SecureShareEndorsement = SecureShare; diff --git a/massa-models/src/secure_share.rs b/massa-models/src/secure_share.rs index 995cfab3814..50fc393bf6c 100644 --- a/massa-models/src/secure_share.rs +++ b/massa-models/src/secure_share.rs @@ -288,7 +288,7 @@ where /// * `buffer`: buffer of serialized data to be deserialized /// /// # Returns: - /// A rest (data left over from deserialization) and structure wrapped up with signature verification data as coherent fields. + /// A rest (data left over from deserialization), an instance of `T`, and the data enabling signature verification pub fn deserialize_with< 'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>, From f8c6c87f6c5ce784e66abf0a41e378f4fe7581cb Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Tue, 17 Jan 2023 16:03:26 +0100 Subject: [PATCH 30/80] use the update runtime module --- massa-execution-worker/src/execution.rs | 36 ++++++++++++++++--------- massa-execution-worker/src/worker.rs | 2 +- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 3473d4cd384..bb48d1fd676 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -31,7 +31,7 @@ use massa_models::{ }; use massa_models::{amount::Amount, slot::Slot}; use massa_pos_exports::SelectorController; -use massa_sc_runtime::{GasCosts, Interface, RuntimeModule}; +use massa_sc_runtime::{Interface, RuntimeModule}; use massa_storage::Storage; use parking_lot::{Mutex, RwLock}; use schnellru::{ByLength, LruMap}; @@ -135,13 +135,12 @@ impl ExecutionState { &mut self, bytecode: &[u8], limit: u64, - gas_costs: GasCosts, - ) -> Result<(), ExecutionError> { - let module = if let Some(cached_module) = self.module_cache.get_mut(bytecode) { - cached_module.reinitialize_metadata(limit, gas_costs); + ) -> Result { + let module = if let Some(cached_module) = self.module_cache.get(bytecode) { cached_module.clone() } else { - let new_module = RuntimeModule::new(bytecode, limit, gas_costs)?; + let new_module = RuntimeModule::new(bytecode, limit, self.config.gas_costs.clone()) + .expect("BIG TODO"); self.module_cache .insert(bytecode.to_vec(), new_module.clone()); new_module @@ -221,7 +220,7 @@ impl ExecutionState { /// * `remaining_block_gas`: mutable reference towards the remaining gas in the block /// * `block_credits`: mutable reference towards the total block reward/fee credits pub fn execute_operation( - &self, + &mut self, operation: &SecureShareOperation, block_slot: Slot, remaining_block_gas: &mut u64, @@ -501,7 +500,7 @@ impl ExecutionState { /// * `operation`: the `WrappedOperation` to process, must be an `ExecuteSC` /// * `sender_addr`: address of the sender pub fn execute_executesc_op( - &self, + &mut self, operation: &OperationType, sender_addr: Address, ) -> Result<(), ExecutionError> { @@ -533,9 +532,12 @@ impl ExecutionState { }; // run the VM on the bytecode contained in the operation + let module = RuntimeModule::new(bytecode, *max_gas, self.config.gas_costs.clone()) + .expect("BIG TODO"); match massa_sc_runtime::run_main( &*self.execution_interface, module, + *max_gas, self.config.gas_costs.clone(), ) { Ok(_response) => {} @@ -560,7 +562,7 @@ impl ExecutionState { /// * `operation_id`: ID of the operation /// * `sender_addr`: address of the sender pub fn execute_callsc_op( - &self, + &mut self, operation: &OperationType, sender_addr: Address, ) -> Result<(), ExecutionError> { @@ -626,11 +628,13 @@ impl ExecutionState { } // run the VM on the bytecode loaded from the target address + let module = self.get_module(&bytecode, max_gas)?; match massa_sc_runtime::run_function( &*self.execution_interface, module, target_func, param, + max_gas, self.config.gas_costs.clone(), ) { Ok(_response) => {} @@ -653,7 +657,7 @@ impl ExecutionState { /// * message: message information /// * bytecode: executable target bytecode, or None if unavailable pub fn execute_async_message( - &self, + &mut self, message: AsyncMessage, bytecode: Option>, ) -> Result<(), ExecutionError> { @@ -715,11 +719,13 @@ impl ExecutionState { }; // run the VM on the bytecode contained in the operation + let module = self.get_module(&bytecode, message.max_gas)?; if let Err(err) = massa_sc_runtime::run_function( &*self.execution_interface, module, &message.handler, &message.data, + message.max_gas, self.config.gas_costs.clone(), ) { // execution failed: reset context to snapshot and reimburse sender @@ -747,7 +753,7 @@ impl ExecutionState { /// # Returns /// An `ExecutionOutput` structure summarizing the output of the executed slot pub fn execute_slot( - &self, + &mut self, slot: &Slot, exec_target: Option<&(BlockId, Storage)>, selector: Box, @@ -1036,7 +1042,7 @@ impl ExecutionState { /// # Returns /// `ExecutionOutput` describing the output of the execution, or an error pub(crate) fn execute_readonly_request( - &self, + &mut self, req: ReadOnlyExecutionRequest, ) -> Result { // TODO ensure that speculative things are reset after every execution ends (incl. on error and readonly) @@ -1073,9 +1079,13 @@ impl ExecutionState { *context_guard!(self) = execution_context; // run the bytecode's main function + let module = + RuntimeModule::new(&bytecode, req.max_gas, self.config.gas_costs.clone()) + .expect("BIG TODO"); massa_sc_runtime::run_main( &*self.execution_interface, module, + req.max_gas, self.config.gas_costs.clone(), ) .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? @@ -1094,11 +1104,13 @@ impl ExecutionState { *context_guard!(self) = execution_context; // run the target function in the bytecode + let module = self.get_module(&bytecode, req.max_gas)?; massa_sc_runtime::run_function( &*self.execution_interface, module, &target_func, ¶meter, + req.max_gas, self.config.gas_costs.clone(), ) .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? diff --git a/massa-execution-worker/src/worker.rs b/massa-execution-worker/src/worker.rs index 667d2feaee8..321b406968b 100644 --- a/massa-execution-worker/src/worker.rs +++ b/massa-execution-worker/src/worker.rs @@ -86,7 +86,7 @@ impl ExecutionThread { let (req, resp_tx) = req_resp.into_request_sender_pair(); // Acquire read access to the execution state and execute the read-only request - let outcome = self.execution_state.read().execute_readonly_request(req); + let outcome = self.execution_state.write().execute_readonly_request(req); // Send the execution output through resp_tx. // Ignore errors because they just mean that the request emitter dropped the received From dc06b517db38b777ec64877a8eb613581c3c1ff3 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Tue, 17 Jan 2023 16:04:14 +0100 Subject: [PATCH 31/80] Fix deadlock in get_blocks --- massa-api/src/public.rs | 51 ++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/massa-api/src/public.rs b/massa-api/src/public.rs index 58b82824d8d..f1ce0eabd02 100644 --- a/massa-api/src/public.rs +++ b/massa-api/src/public.rs @@ -588,30 +588,33 @@ impl MassaRpcServer for API { let blocks = ids .into_iter() .filter_map(|id| { - if let Some(wrapped_block) = storage.read_blocks().get(&id).cloned() { - if let Some(graph_status) = consensus_controller - .get_block_statuses(&[id]) - .into_iter() - .next() - { - let is_final = graph_status == BlockGraphStatus::Final; - let is_in_blockclique = - graph_status == BlockGraphStatus::ActiveInBlockclique; - let is_candidate = graph_status == BlockGraphStatus::ActiveInBlockclique - || graph_status == BlockGraphStatus::ActiveInAlternativeCliques; - let is_discarded = graph_status == BlockGraphStatus::Discarded; - - return Some(BlockInfo { - id, - content: Some(BlockInfoContent { - is_final, - is_in_blockclique, - is_candidate, - is_discarded, - block: wrapped_block.content, - }), - }); - } + let content = if let Some(wrapped_block) = storage.read_blocks().get(&id) { + wrapped_block.content.clone() + } else { + return None; + }; + + if let Some(graph_status) = consensus_controller + .get_block_statuses(&[id]) + .into_iter() + .next() + { + let is_final = graph_status == BlockGraphStatus::Final; + let is_in_blockclique = graph_status == BlockGraphStatus::ActiveInBlockclique; + let is_candidate = graph_status == BlockGraphStatus::ActiveInBlockclique + || graph_status == BlockGraphStatus::ActiveInAlternativeCliques; + let is_discarded = graph_status == BlockGraphStatus::Discarded; + + return Some(BlockInfo { + id, + content: Some(BlockInfoContent { + is_final, + is_in_blockclique, + is_candidate, + is_discarded, + block: content, + }), + }); } None From 93953fed3eb6470d31b71330bbb0c11232c61c05 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 17 Jan 2023 17:18:39 +0100 Subject: [PATCH 32/80] Testnet 19 bootstrap timeout (#3431) * Provide a bootstrap timeout consistent with other config vals --- massa-bootstrap/src/server.rs | 26 +++++++++++++++++--------- massa-bootstrap/src/settings.rs | 3 +++ massa-bootstrap/src/tests/tools.rs | 1 + massa-node/base_config/config.toml | 2 ++ massa-node/src/main.rs | 1 + massa-node/src/settings.rs | 2 ++ 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/massa-bootstrap/src/server.rs b/massa-bootstrap/src/server.rs index 7fa3160738b..dc399465b05 100644 --- a/massa-bootstrap/src/server.rs +++ b/massa-bootstrap/src/server.rs @@ -260,16 +260,24 @@ impl BootstrapServer { bootstrap_sessions.push(async move { let mut server = BootstrapServerBinder::new(dplx, keypair, config.max_bytes_read_write, config.max_bootstrap_message_size, config.thread_count, config.max_datastore_key_length, config.randomness_size_bytes, config.consensus_bootstrap_part_size); - match manage_bootstrap(&config, &mut server, data_execution, version, consensus_command_sender, network_command_sender).await { - Ok(_) => { - info!("bootstrapped peer {}", remote_addr) - }, - Err(BootstrapError::ReceivedError(error)) => debug!("bootstrap serving error received from peer {}: {}", remote_addr, error), - Err(err) => { - debug!("bootstrap serving error for peer {}: {}", remote_addr, err); + debug!("awaiting on bootstrap of peer {}", remote_addr); + match tokio::time::timeout(config.bootstrap_timeout.into(), manage_bootstrap(&config, &mut server, data_execution, version, consensus_command_sender, network_command_sender)).await { + Ok(mgmt) => match mgmt { + Ok(_) => { + info!("bootstrapped peer {}", remote_addr) + }, + Err(BootstrapError::ReceivedError(error)) => debug!("bootstrap serving error received from peer {}: {}", remote_addr, error), + Err(err) => { + debug!("bootstrap serving error for peer {}: {}", remote_addr, err); + // We allow unused result because we don't care if an error is thrown when sending the error message to the server we will close the socket anyway. + let _ = tokio::time::timeout(config.write_error_timeout.into(), server.send(BootstrapServerMessage::BootstrapError { error: err.to_string() })).await; + }, + } + Err(_timeout) => { + debug!("bootstrap timeout for peer {}", remote_addr); // We allow unused result because we don't care if an error is thrown when sending the error message to the server we will close the socket anyway. - let _ = tokio::time::timeout(config.write_error_timeout.into(), server.send(BootstrapServerMessage::BootstrapError { error: err.to_string() })).await; - }, + let _ = tokio::time::timeout(config.write_error_timeout.into(), server.send(BootstrapServerMessage::BootstrapError { error: format!("Bootstrap process timedout ({})", format_duration(config.bootstrap_timeout.to_duration())) })).await; + } } }); diff --git a/massa-bootstrap/src/settings.rs b/massa-bootstrap/src/settings.rs index c49137977a8..afba6c982e5 100644 --- a/massa-bootstrap/src/settings.rs +++ b/massa-bootstrap/src/settings.rs @@ -31,6 +31,9 @@ pub struct BootstrapConfig { pub bind: Option, /// connection timeout pub connect_timeout: MassaTime, + /// Time allocated to managing the bootstrapping process, + /// i.e. providing the ledger and consensus + pub bootstrap_timeout: MassaTime, /// readout timeout pub read_timeout: MassaTime, /// write timeout diff --git a/massa-bootstrap/src/tests/tools.rs b/massa-bootstrap/src/tests/tools.rs index 32719441ecb..2b349ac184d 100644 --- a/massa-bootstrap/src/tests/tools.rs +++ b/massa-bootstrap/src/tests/tools.rs @@ -277,6 +277,7 @@ pub fn get_bootstrap_config(bootstrap_public_key: NodeId) -> BootstrapConfig { BootstrapConfig { bind: Some("0.0.0.0:31244".parse().unwrap()), bootstrap_protocol: IpType::Both, + bootstrap_timeout: 120000.into(), connect_timeout: 200.into(), retry_delay: 200.into(), max_ping: MassaTime::from_millis(500), diff --git a/massa-node/base_config/config.toml b/massa-node/base_config/config.toml index 0e576e2cc74..1780fad84e5 100644 --- a/massa-node/base_config/config.toml +++ b/massa-node/base_config/config.toml @@ -218,6 +218,8 @@ bind = "[::]:31245" # timeout to establish a bootstrap connection connect_timeout = 15000 + # timeout for providing the bootstrap to a connection + bootstrap_timeout = 1200000 # delay in milliseconds to wait between consecutive bootstrap attempts retry_delay = 60000 # if ping is too high bootstrap will be interrupted after max_ping milliseconds diff --git a/massa-node/src/main.rs b/massa-node/src/main.rs index b623046907d..c7d3ad12c25 100644 --- a/massa-node/src/main.rs +++ b/massa-node/src/main.rs @@ -178,6 +178,7 @@ async fn launch( bootstrap_blacklist_path: SETTINGS.bootstrap.bootstrap_blacklist_path.clone(), bind: SETTINGS.bootstrap.bind, connect_timeout: SETTINGS.bootstrap.connect_timeout, + bootstrap_timeout: SETTINGS.bootstrap.bootstrap_timeout, read_timeout: SETTINGS.bootstrap.read_timeout, write_timeout: SETTINGS.bootstrap.write_timeout, read_error_timeout: SETTINGS.bootstrap.read_error_timeout, diff --git a/massa-node/src/settings.rs b/massa-node/src/settings.rs index 7d8b85df7a5..5d45b43f0e6 100644 --- a/massa-node/src/settings.rs +++ b/massa-node/src/settings.rs @@ -93,6 +93,8 @@ pub struct BootstrapSettings { pub per_ip_min_interval: MassaTime, pub ip_list_max_size: usize, pub max_bytes_read_write: f64, + /// Allocated time with which to manage the bootstrap process + pub bootstrap_timeout: MassaTime, } /// Factory settings From aba89bdbd1fc5050fbc3acd522f202355553c900 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 18 Jan 2023 13:44:50 +0100 Subject: [PATCH 33/80] Update doctest import (#3440) --- massa-consensus-exports/src/export_active_block.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/massa-consensus-exports/src/export_active_block.rs b/massa-consensus-exports/src/export_active_block.rs index 3e374b4de7f..bd8332937d4 100644 --- a/massa-consensus-exports/src/export_active_block.rs +++ b/massa-consensus-exports/src/export_active_block.rs @@ -156,7 +156,7 @@ impl Deserializer for ExportActiveBlockDeserializer { /// ## Example: /// ```rust /// use massa_consensus_exports::export_active_block::{ExportActiveBlock, ExportActiveBlockDeserializer, ExportActiveBlockSerializer}; - /// use massa_models::{ledger_models::LedgerChanges, config::THREAD_COUNT, rolls::RollUpdates, block::{BlockId, Block, BlockSerializer, BlockHeader, BlockHeaderSerializer}, prehash::PreHashSet, endorsement::{Endorsement, EndorsementSerializer}, slot::Slot, secure_share::SecureShareContent}; + /// use massa_models::{ledger::LedgerChanges, config::THREAD_COUNT, rolls::RollUpdates, block::{BlockId, Block, BlockSerializer, BlockHeader, BlockHeaderSerializer}, prehash::PreHashSet, endorsement::{Endorsement, EndorsementSerializer}, slot::Slot, secure_share::SecureShareContent}; /// use massa_hash::Hash; /// use std::collections::HashSet; /// use massa_signature::KeyPair; From cb47fc810a204c17adbeea912e90808b8765463e Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Wed, 18 Jan 2023 14:58:15 +0100 Subject: [PATCH 34/80] use module cache in context and implement new interface func --- massa-execution-worker/src/context.rs | 13 ++++- massa-execution-worker/src/execution.rs | 52 ++++++++------------ massa-execution-worker/src/interface_impl.rs | 11 +++++ massa-execution-worker/src/lib.rs | 1 + massa-execution-worker/src/module_cache.rs | 41 +++++++++++++++ 5 files changed, 85 insertions(+), 33 deletions(-) create mode 100644 massa-execution-worker/src/module_cache.rs diff --git a/massa-execution-worker/src/context.rs b/massa-execution-worker/src/context.rs index 8b88ad2a14e..efe2324756e 100644 --- a/massa-execution-worker/src/context.rs +++ b/massa-execution-worker/src/context.rs @@ -7,6 +7,7 @@ //! More generally, the context acts only on its own state //! and does not write anything persistent to the consensus state. +use crate::module_cache::ModuleCache; use crate::speculative_async_pool::SpeculativeAsyncPool; use crate::speculative_executed_ops::SpeculativeExecutedOps; use crate::speculative_ledger::SpeculativeLedger; @@ -126,6 +127,9 @@ pub struct ExecutionContext { /// operation id that originally caused this execution (if any) pub origin_operation_id: Option, + + // cache of pre compiled sc modules + pub module_cache: Arc>, } impl ExecutionContext { @@ -143,6 +147,7 @@ impl ExecutionContext { config: ExecutionConfig, final_state: Arc>, active_history: Arc>, + module_cache: Arc>, ) -> Self { ExecutionContext { speculative_ledger: SpeculativeLedger::new( @@ -174,6 +179,7 @@ impl ExecutionContext { unsafe_rng: Xoshiro256PlusPlus::from_seed([0u8; 32]), creator_address: Default::default(), origin_operation_id: Default::default(), + module_cache, config, } } @@ -247,6 +253,8 @@ impl ExecutionContext { call_stack: Vec, final_state: Arc>, active_history: Arc>, + + module_cache: Arc>, ) -> Self { // Deterministically seed the unsafe RNG to allow the bytecode to use it. // Note that consecutive read-only calls for the same slot will get the same random seed. @@ -270,7 +278,7 @@ impl ExecutionContext { stack: call_stack, read_only: true, unsafe_rng, - ..ExecutionContext::new(config, final_state, active_history) + ..ExecutionContext::new(config, final_state, active_history, module_cache) } } @@ -310,6 +318,7 @@ impl ExecutionContext { opt_block_id: Option, final_state: Arc>, active_history: Arc>, + module_cache: Arc>, ) -> Self { // Deterministically seed the unsafe RNG to allow the bytecode to use it. @@ -331,7 +340,7 @@ impl ExecutionContext { slot, opt_block_id, unsafe_rng, - ..ExecutionContext::new(config, final_state, active_history) + ..ExecutionContext::new(config, final_state, active_history, module_cache) } } diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index bb48d1fd676..6df4299c62f 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -11,6 +11,7 @@ use crate::active_history::{ActiveHistory, HistorySearchResult}; use crate::context::ExecutionContext; use crate::interface_impl::InterfaceImpl; +use crate::module_cache::ModuleCache; use crate::stats::ExecutionStatsCounter; use massa_async_pool::AsyncMessage; use massa_execution_exports::{ @@ -34,7 +35,6 @@ use massa_pos_exports::SelectorController; use massa_sc_runtime::{Interface, RuntimeModule}; use massa_storage::Storage; use parking_lot::{Mutex, RwLock}; -use schnellru::{ByLength, LruMap}; use std::collections::{BTreeMap, BTreeSet}; use std::sync::Arc; use tracing::{debug, info, warn}; @@ -72,7 +72,7 @@ pub(crate) struct ExecutionState { // execution statistics stats_counter: ExecutionStatsCounter, // cache of pre compiled sc modules - module_cache: LruMap, RuntimeModule>, + module_cache: Arc>, } impl ExecutionState { @@ -92,11 +92,18 @@ impl ExecutionState { // Create default active history let active_history: Arc> = Default::default(); + // Initialize the SC module cache + let module_cache = Arc::new(RwLock::new(ModuleCache::new( + config.gas_costs.clone(), + config.max_module_cache_size, + ))); + // Create an empty placeholder execution context, with shared atomic access let execution_context = Arc::new(Mutex::new(ExecutionContext::new( config.clone(), final_state.clone(), active_history.clone(), + module_cache.clone(), ))); // Instantiate the interface providing ABI access to the VM, share the execution context with it @@ -118,36 +125,11 @@ impl ExecutionState { active_cursor: last_final_slot, final_cursor: last_final_slot, stats_counter: ExecutionStatsCounter::new(config.stats_time_window_duration), - module_cache: LruMap::new(ByLength::new(config.max_module_cache_size)), + module_cache, config, } } - /// If the module is contained in the cache: - /// * retrieve a copy of it - /// * move it up in the LRU cache - /// - /// If the module is not contained in the cache: - /// * create the module - /// * save the module in the cache - /// * retrieve a copy of it - pub(crate) fn get_module( - &mut self, - bytecode: &[u8], - limit: u64, - ) -> Result { - let module = if let Some(cached_module) = self.module_cache.get(bytecode) { - cached_module.clone() - } else { - let new_module = RuntimeModule::new(bytecode, limit, self.config.gas_costs.clone()) - .expect("BIG TODO"); - self.module_cache - .insert(bytecode.to_vec(), new_module.clone()); - new_module - }; - Ok(module) - } - /// Get execution statistics pub fn get_stats(&self) -> ExecutionStats { self.stats_counter.get_stats(self.active_cursor) @@ -628,7 +610,7 @@ impl ExecutionState { } // run the VM on the bytecode loaded from the target address - let module = self.get_module(&bytecode, max_gas)?; + let module = self.module_cache.write().get_module(&bytecode, max_gas)?; match massa_sc_runtime::run_function( &*self.execution_interface, module, @@ -719,7 +701,10 @@ impl ExecutionState { }; // run the VM on the bytecode contained in the operation - let module = self.get_module(&bytecode, message.max_gas)?; + let module = self + .module_cache + .write() + .get_module(&bytecode, message.max_gas)?; if let Err(err) = massa_sc_runtime::run_function( &*self.execution_interface, module, @@ -765,6 +750,7 @@ impl ExecutionState { exec_target.as_ref().map(|(b_id, _)| *b_id), self.final_state.clone(), self.active_history.clone(), + self.module_cache.clone(), ); // Get asynchronous messages to execute @@ -1070,6 +1056,7 @@ impl ExecutionState { req.call_stack, self.final_state.clone(), self.active_history.clone(), + self.module_cache.clone(), ); // run the interpreter according to the target type @@ -1104,7 +1091,10 @@ impl ExecutionState { *context_guard!(self) = execution_context; // run the target function in the bytecode - let module = self.get_module(&bytecode, req.max_gas)?; + let module = self + .module_cache + .write() + .get_module(&bytecode, req.max_gas)?; massa_sc_runtime::run_function( &*self.execution_interface, module, diff --git a/massa-execution-worker/src/interface_impl.rs b/massa-execution-worker/src/interface_impl.rs index e13c3b71f40..168e2cdf060 100644 --- a/massa-execution-worker/src/interface_impl.rs +++ b/massa-execution-worker/src/interface_impl.rs @@ -14,6 +14,7 @@ use massa_models::config::MAX_DATASTORE_KEY_LENGTH; use massa_models::{ address::Address, amount::Amount, slot::Slot, timeslots::get_block_slot_timestamp, }; +use massa_sc_runtime::RuntimeModule; use massa_sc_runtime::{Interface, InterfaceClone}; use parking_lot::Mutex; use rand::Rng; @@ -170,6 +171,16 @@ impl Interface for InterfaceImpl { Ok(()) } + /// Get the module from cache if possible, compile it if not + /// + /// # Returns + /// A `massa-sc-runtime` compiled module + fn get_module(&self, bytecode: &[u8], limit: u64) -> Result { + let context = context_guard!(self); + let module = context.module_cache.write().get_module(bytecode, limit)?; + Ok(module) + } + /// Gets the balance of the current address address (top of the stack). /// /// # Returns diff --git a/massa-execution-worker/src/lib.rs b/massa-execution-worker/src/lib.rs index 2c89fa46d72..cd937a9778f 100644 --- a/massa-execution-worker/src/lib.rs +++ b/massa-execution-worker/src/lib.rs @@ -88,6 +88,7 @@ mod context; mod controller; mod execution; mod interface_impl; +mod module_cache; mod request_queue; mod slot_sequencer; mod speculative_async_pool; diff --git a/massa-execution-worker/src/module_cache.rs b/massa-execution-worker/src/module_cache.rs new file mode 100644 index 00000000000..7279a9cc808 --- /dev/null +++ b/massa-execution-worker/src/module_cache.rs @@ -0,0 +1,41 @@ +use massa_execution_exports::ExecutionError; +use massa_sc_runtime::{GasCosts, RuntimeModule}; +use schnellru::{ByLength, LruMap}; + +pub struct ModuleCache { + gas_costs: GasCosts, + cache: LruMap, RuntimeModule>, +} + +impl ModuleCache { + pub fn new(gas_costs: GasCosts, cache_size: u32) -> Self { + Self { + gas_costs, + cache: LruMap::new(ByLength::new(cache_size)), + } + } + + /// If the module is contained in the cache: + /// * retrieve a copy of it + /// * move it up in the LRU cache + /// + /// If the module is not contained in the cache: + /// * create the module + /// * save the module in the cache + /// * retrieve a copy of it + pub fn get_module( + &mut self, + bytecode: &[u8], + limit: u64, + ) -> Result { + let module = if let Some(cached_module) = self.cache.get(bytecode) { + cached_module.clone() + } else { + let new_module = + RuntimeModule::new(bytecode, limit, self.gas_costs.clone()).expect("BIG TODO"); + self.cache.insert(bytecode.to_vec(), new_module.clone()); + new_module + }; + Ok(module) + } +} From 9c271a4e4f4f17f919cabf6adea46c42aa719ae0 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Wed, 18 Jan 2023 15:00:45 +0100 Subject: [PATCH 35/80] remove unused mutable refs --- massa-execution-worker/src/execution.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 6df4299c62f..2cff7e75c52 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -202,7 +202,7 @@ impl ExecutionState { /// * `remaining_block_gas`: mutable reference towards the remaining gas in the block /// * `block_credits`: mutable reference towards the total block reward/fee credits pub fn execute_operation( - &mut self, + &self, operation: &SecureShareOperation, block_slot: Slot, remaining_block_gas: &mut u64, @@ -482,7 +482,7 @@ impl ExecutionState { /// * `operation`: the `WrappedOperation` to process, must be an `ExecuteSC` /// * `sender_addr`: address of the sender pub fn execute_executesc_op( - &mut self, + &self, operation: &OperationType, sender_addr: Address, ) -> Result<(), ExecutionError> { @@ -544,7 +544,7 @@ impl ExecutionState { /// * `operation_id`: ID of the operation /// * `sender_addr`: address of the sender pub fn execute_callsc_op( - &mut self, + &self, operation: &OperationType, sender_addr: Address, ) -> Result<(), ExecutionError> { @@ -639,7 +639,7 @@ impl ExecutionState { /// * message: message information /// * bytecode: executable target bytecode, or None if unavailable pub fn execute_async_message( - &mut self, + &self, message: AsyncMessage, bytecode: Option>, ) -> Result<(), ExecutionError> { @@ -738,7 +738,7 @@ impl ExecutionState { /// # Returns /// An `ExecutionOutput` structure summarizing the output of the executed slot pub fn execute_slot( - &mut self, + &self, slot: &Slot, exec_target: Option<&(BlockId, Storage)>, selector: Box, @@ -1028,7 +1028,7 @@ impl ExecutionState { /// # Returns /// `ExecutionOutput` describing the output of the execution, or an error pub(crate) fn execute_readonly_request( - &mut self, + &self, req: ReadOnlyExecutionRequest, ) -> Result { // TODO ensure that speculative things are reset after every execution ends (incl. on error and readonly) From c12624713317eec05c2634206365990c1adde001 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Wed, 18 Jan 2023 15:51:33 +0100 Subject: [PATCH 36/80] handle errors --- Cargo.lock | 1 + massa-execution-exports/Cargo.toml | 1 + massa-execution-exports/src/error.rs | 5 +++ massa-execution-exports/src/lib.rs | 2 +- massa-execution-worker/src/execution.rs | 41 +++++++--------------- massa-execution-worker/src/module_cache.rs | 6 ++-- 6 files changed, 24 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53971bcd21c..6e402c1175a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2440,6 +2440,7 @@ dependencies = [ name = "massa_execution_exports" version = "0.1.0" dependencies = [ + "anyhow", "displaydoc", "massa-sc-runtime", "massa_final_state", diff --git a/massa-execution-exports/Cargo.toml b/massa-execution-exports/Cargo.toml index cb1c38025aa..4bb74869323 100644 --- a/massa-execution-exports/Cargo.toml +++ b/massa-execution-exports/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" [dependencies] displaydoc = "0.2" thiserror = "1.0" +anyhow = "1.0" num = { version = "0.4", features = ["serde"] } # custom modules massa_hash = { path = "../massa-hash" } diff --git a/massa-execution-exports/src/error.rs b/massa-execution-exports/src/error.rs index 4edf88b0246..f61a8e2b3d1 100644 --- a/massa-execution-exports/src/error.rs +++ b/massa-execution-exports/src/error.rs @@ -45,3 +45,8 @@ pub enum ExecutionError { /// Include operation error: {0} IncludeOperationError(String), } + +/// Creates an `ExecutionError::RuntimeError` from a `massa-sc-runtime` anyhow error +pub fn runtime_error(error: anyhow::Error) -> ExecutionError { + ExecutionError::RuntimeError(error.to_string()) +} diff --git a/massa-execution-exports/src/lib.rs b/massa-execution-exports/src/lib.rs index 9aae9563e51..168ed969de9 100644 --- a/massa-execution-exports/src/lib.rs +++ b/massa-execution-exports/src/lib.rs @@ -51,7 +51,7 @@ mod settings; mod types; pub use controller_traits::{ExecutionController, ExecutionManager}; -pub use error::ExecutionError; +pub use error::{runtime_error, ExecutionError}; pub use event_store::EventStore; pub use massa_sc_runtime::GasCosts; pub use settings::{ExecutionConfig, StorageCostsConstants}; diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 2cff7e75c52..ae87836c4de 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -15,8 +15,9 @@ use crate::module_cache::ModuleCache; use crate::stats::ExecutionStatsCounter; use massa_async_pool::AsyncMessage; use massa_execution_exports::{ - EventStore, ExecutionConfig, ExecutionError, ExecutionOutput, ExecutionStackElement, - ReadOnlyExecutionOutput, ReadOnlyExecutionRequest, ReadOnlyExecutionTarget, + runtime_error, EventStore, ExecutionConfig, ExecutionError, ExecutionOutput, + ExecutionStackElement, ReadOnlyExecutionOutput, ReadOnlyExecutionRequest, + ReadOnlyExecutionTarget, }; use massa_final_state::FinalState; use massa_ledger_exports::{SetOrDelete, SetUpdateOrDelete}; @@ -515,22 +516,14 @@ impl ExecutionState { // run the VM on the bytecode contained in the operation let module = RuntimeModule::new(bytecode, *max_gas, self.config.gas_costs.clone()) - .expect("BIG TODO"); - match massa_sc_runtime::run_main( + .map_err(runtime_error)?; + massa_sc_runtime::run_main( &*self.execution_interface, module, *max_gas, self.config.gas_costs.clone(), - ) { - Ok(_response) => {} - Err(err) => { - // there was an error during bytecode execution - return Err(ExecutionError::RuntimeError(format!( - "bytecode execution error: {}", - err - ))); - } - } + ) + .map_err(runtime_error)?; Ok(()) } @@ -611,23 +604,15 @@ impl ExecutionState { // run the VM on the bytecode loaded from the target address let module = self.module_cache.write().get_module(&bytecode, max_gas)?; - match massa_sc_runtime::run_function( + massa_sc_runtime::run_function( &*self.execution_interface, module, target_func, param, max_gas, self.config.gas_costs.clone(), - ) { - Ok(_response) => {} - Err(err) => { - // there was an error during bytecode execution - return Err(ExecutionError::RuntimeError(format!( - "bytecode execution error: {}", - err - ))); - } - } + ) + .map_err(runtime_error)?; Ok(()) } @@ -1068,14 +1053,14 @@ impl ExecutionState { // run the bytecode's main function let module = RuntimeModule::new(&bytecode, req.max_gas, self.config.gas_costs.clone()) - .expect("BIG TODO"); + .map_err(runtime_error)?; massa_sc_runtime::run_main( &*self.execution_interface, module, req.max_gas, self.config.gas_costs.clone(), ) - .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? + .map_err(runtime_error)? } ReadOnlyExecutionTarget::FunctionCall { target_addr, @@ -1103,7 +1088,7 @@ impl ExecutionState { req.max_gas, self.config.gas_costs.clone(), ) - .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? + .map_err(runtime_error)? } }; diff --git a/massa-execution-worker/src/module_cache.rs b/massa-execution-worker/src/module_cache.rs index 7279a9cc808..503e4551628 100644 --- a/massa-execution-worker/src/module_cache.rs +++ b/massa-execution-worker/src/module_cache.rs @@ -1,4 +1,4 @@ -use massa_execution_exports::ExecutionError; +use massa_execution_exports::{runtime_error, ExecutionError}; use massa_sc_runtime::{GasCosts, RuntimeModule}; use schnellru::{ByLength, LruMap}; @@ -31,8 +31,8 @@ impl ModuleCache { let module = if let Some(cached_module) = self.cache.get(bytecode) { cached_module.clone() } else { - let new_module = - RuntimeModule::new(bytecode, limit, self.gas_costs.clone()).expect("BIG TODO"); + let new_module = RuntimeModule::new(bytecode, limit, self.gas_costs.clone()) + .map_err(runtime_error)?; self.cache.insert(bytecode.to_vec(), new_module.clone()); new_module }; From 9d04fef8a66f83ef995ef62ed8e4b18b8407bb0f Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Wed, 18 Jan 2023 16:38:11 +0100 Subject: [PATCH 37/80] roll back error handling and improve it --- Cargo.lock | 1 - massa-execution-exports/Cargo.toml | 1 - massa-execution-exports/src/error.rs | 5 --- massa-execution-exports/src/lib.rs | 2 +- massa-execution-worker/src/execution.rs | 49 ++++++++++++++++------ massa-execution-worker/src/module_cache.rs | 11 +++-- 6 files changed, 45 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6e402c1175a..53971bcd21c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2440,7 +2440,6 @@ dependencies = [ name = "massa_execution_exports" version = "0.1.0" dependencies = [ - "anyhow", "displaydoc", "massa-sc-runtime", "massa_final_state", diff --git a/massa-execution-exports/Cargo.toml b/massa-execution-exports/Cargo.toml index 4bb74869323..cb1c38025aa 100644 --- a/massa-execution-exports/Cargo.toml +++ b/massa-execution-exports/Cargo.toml @@ -9,7 +9,6 @@ edition = "2021" [dependencies] displaydoc = "0.2" thiserror = "1.0" -anyhow = "1.0" num = { version = "0.4", features = ["serde"] } # custom modules massa_hash = { path = "../massa-hash" } diff --git a/massa-execution-exports/src/error.rs b/massa-execution-exports/src/error.rs index f61a8e2b3d1..4edf88b0246 100644 --- a/massa-execution-exports/src/error.rs +++ b/massa-execution-exports/src/error.rs @@ -45,8 +45,3 @@ pub enum ExecutionError { /// Include operation error: {0} IncludeOperationError(String), } - -/// Creates an `ExecutionError::RuntimeError` from a `massa-sc-runtime` anyhow error -pub fn runtime_error(error: anyhow::Error) -> ExecutionError { - ExecutionError::RuntimeError(error.to_string()) -} diff --git a/massa-execution-exports/src/lib.rs b/massa-execution-exports/src/lib.rs index 168ed969de9..9aae9563e51 100644 --- a/massa-execution-exports/src/lib.rs +++ b/massa-execution-exports/src/lib.rs @@ -51,7 +51,7 @@ mod settings; mod types; pub use controller_traits::{ExecutionController, ExecutionManager}; -pub use error::{runtime_error, ExecutionError}; +pub use error::ExecutionError; pub use event_store::EventStore; pub use massa_sc_runtime::GasCosts; pub use settings::{ExecutionConfig, StorageCostsConstants}; diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index ae87836c4de..37195cc9b27 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -15,9 +15,8 @@ use crate::module_cache::ModuleCache; use crate::stats::ExecutionStatsCounter; use massa_async_pool::AsyncMessage; use massa_execution_exports::{ - runtime_error, EventStore, ExecutionConfig, ExecutionError, ExecutionOutput, - ExecutionStackElement, ReadOnlyExecutionOutput, ReadOnlyExecutionRequest, - ReadOnlyExecutionTarget, + EventStore, ExecutionConfig, ExecutionError, ExecutionOutput, ExecutionStackElement, + ReadOnlyExecutionOutput, ReadOnlyExecutionRequest, ReadOnlyExecutionTarget, }; use massa_final_state::FinalState; use massa_ledger_exports::{SetOrDelete, SetUpdateOrDelete}; @@ -516,14 +515,26 @@ impl ExecutionState { // run the VM on the bytecode contained in the operation let module = RuntimeModule::new(bytecode, *max_gas, self.config.gas_costs.clone()) - .map_err(runtime_error)?; - massa_sc_runtime::run_main( + .map_err(|err| { + Err(ExecutionError::RuntimeError(format!( + "compilation error in execute_executesc_op: {}", + err + ))) + })?; + match massa_sc_runtime::run_main( &*self.execution_interface, module, *max_gas, self.config.gas_costs.clone(), - ) - .map_err(runtime_error)?; + ) { + Ok(_response) => {} + Err(err) => { + return Err(ExecutionError::RuntimeError(format!( + "module execution error in execute_executesc_op: {}", + err + ))); + } + } Ok(()) } @@ -604,15 +615,22 @@ impl ExecutionState { // run the VM on the bytecode loaded from the target address let module = self.module_cache.write().get_module(&bytecode, max_gas)?; - massa_sc_runtime::run_function( + match massa_sc_runtime::run_function( &*self.execution_interface, module, target_func, param, max_gas, self.config.gas_costs.clone(), - ) - .map_err(runtime_error)?; + ) { + Ok(_response) => {} + Err(err) => { + return Err(ExecutionError::RuntimeError(format!( + "module execution error in execute_callsc_op: {}", + err + ))); + } + } Ok(()) } @@ -1053,14 +1071,19 @@ impl ExecutionState { // run the bytecode's main function let module = RuntimeModule::new(&bytecode, req.max_gas, self.config.gas_costs.clone()) - .map_err(runtime_error)?; + .map_err(|err| { + Err(ExecutionError::RuntimeError(format!( + "compilation error in execute_readonly_request: {}", + err + ))) + })?; massa_sc_runtime::run_main( &*self.execution_interface, module, req.max_gas, self.config.gas_costs.clone(), ) - .map_err(runtime_error)? + .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? } ReadOnlyExecutionTarget::FunctionCall { target_addr, @@ -1088,7 +1111,7 @@ impl ExecutionState { req.max_gas, self.config.gas_costs.clone(), ) - .map_err(runtime_error)? + .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? } }; diff --git a/massa-execution-worker/src/module_cache.rs b/massa-execution-worker/src/module_cache.rs index 503e4551628..c90d5c1ce63 100644 --- a/massa-execution-worker/src/module_cache.rs +++ b/massa-execution-worker/src/module_cache.rs @@ -1,4 +1,4 @@ -use massa_execution_exports::{runtime_error, ExecutionError}; +use massa_execution_exports::ExecutionError; use massa_sc_runtime::{GasCosts, RuntimeModule}; use schnellru::{ByLength, LruMap}; @@ -31,8 +31,13 @@ impl ModuleCache { let module = if let Some(cached_module) = self.cache.get(bytecode) { cached_module.clone() } else { - let new_module = RuntimeModule::new(bytecode, limit, self.gas_costs.clone()) - .map_err(runtime_error)?; + let new_module = + RuntimeModule::new(bytecode, limit, self.gas_costs.clone()).map_err(|err| { + Err(ExecutionError::RuntimeError(format!( + "compilation of missing cache module failed: {}", + err + ))) + })?; self.cache.insert(bytecode.to_vec(), new_module.clone()); new_module }; From 4662da4433a4e24ede937effb88f5e7af46ffcfb Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Wed, 18 Jan 2023 16:39:48 +0100 Subject: [PATCH 38/80] fix compilation --- massa-execution-worker/src/execution.rs | 8 ++++---- massa-execution-worker/src/module_cache.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 37195cc9b27..ab71f300a13 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -516,10 +516,10 @@ impl ExecutionState { // run the VM on the bytecode contained in the operation let module = RuntimeModule::new(bytecode, *max_gas, self.config.gas_costs.clone()) .map_err(|err| { - Err(ExecutionError::RuntimeError(format!( + ExecutionError::RuntimeError(format!( "compilation error in execute_executesc_op: {}", err - ))) + )) })?; match massa_sc_runtime::run_main( &*self.execution_interface, @@ -1072,10 +1072,10 @@ impl ExecutionState { let module = RuntimeModule::new(&bytecode, req.max_gas, self.config.gas_costs.clone()) .map_err(|err| { - Err(ExecutionError::RuntimeError(format!( + ExecutionError::RuntimeError(format!( "compilation error in execute_readonly_request: {}", err - ))) + )) })?; massa_sc_runtime::run_main( &*self.execution_interface, diff --git a/massa-execution-worker/src/module_cache.rs b/massa-execution-worker/src/module_cache.rs index c90d5c1ce63..0fb19efe736 100644 --- a/massa-execution-worker/src/module_cache.rs +++ b/massa-execution-worker/src/module_cache.rs @@ -33,10 +33,10 @@ impl ModuleCache { } else { let new_module = RuntimeModule::new(bytecode, limit, self.gas_costs.clone()).map_err(|err| { - Err(ExecutionError::RuntimeError(format!( + ExecutionError::RuntimeError(format!( "compilation of missing cache module failed: {}", err - ))) + )) })?; self.cache.insert(bytecode.to_vec(), new_module.clone()); new_module From fcdc553a935788a66def9ae6c568e85e6835c247 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Wed, 18 Jan 2023 18:39:49 +0100 Subject: [PATCH 39/80] Save commit for bug fixing --- Cargo.lock | 1 + massa-execution-worker/Cargo.toml | 1 + massa-execution-worker/src/execution.rs | 22 +++++++---- massa-execution-worker/src/module_cache.rs | 3 ++ massa-node/base_config/initial_ledger.json | 44 +--------------------- massa-node/base_config/initial_rolls.json | 10 +---- 6 files changed, 22 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53971bcd21c..59ab51b7c63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2482,6 +2482,7 @@ dependencies = [ "serial_test 0.10.0", "tempfile", "tracing", + "wasmer", ] [[package]] diff --git a/massa-execution-worker/Cargo.toml b/massa-execution-worker/Cargo.toml index fc856acc531..49ec94fb235 100644 --- a/massa-execution-worker/Cargo.toml +++ b/massa-execution-worker/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +wasmer = { version = "3.0" } anyhow = "1.0" rand = "0.8" rand_xoshiro = "0.6" diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index ab71f300a13..bb4112f8e07 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -32,12 +32,13 @@ use massa_models::{ }; use massa_models::{amount::Amount, slot::Slot}; use massa_pos_exports::SelectorController; -use massa_sc_runtime::{Interface, RuntimeModule}; +use massa_sc_runtime::{init_engine, Interface, RuntimeModule, ASModule}; use massa_storage::Storage; use parking_lot::{Mutex, RwLock}; use std::collections::{BTreeMap, BTreeSet}; use std::sync::Arc; use tracing::{debug, info, warn}; +use wasmer::{Engine, Module}; /// Used to acquire a lock on the execution context macro_rules! context_guard { @@ -514,17 +515,21 @@ impl ExecutionState { }; // run the VM on the bytecode contained in the operation - let module = RuntimeModule::new(bytecode, *max_gas, self.config.gas_costs.clone()) - .map_err(|err| { - ExecutionError::RuntimeError(format!( - "compilation error in execute_executesc_op: {}", - err - )) - })?; + // let module = RuntimeModule::new(bytecode, *max_gas, self.config.gas_costs.clone()) + // .map_err(|err| { + // ExecutionError::RuntimeError(format!( + // "compilation error in execute_executesc_op: {}", + // err + // )) + // })?; + let engine = init_engine(*max_gas, self.config.gas_costs.clone()).unwrap(); + let binary_module = Module::new(&engine, bytecode).unwrap(); + let module = RuntimeModule::ASModule(ASModule { binary_module }); match massa_sc_runtime::run_main( &*self.execution_interface, module, *max_gas, + Some(engine), self.config.gas_costs.clone(), ) { Ok(_response) => {} @@ -1081,6 +1086,7 @@ impl ExecutionState { &*self.execution_interface, module, req.max_gas, + None, self.config.gas_costs.clone(), ) .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? diff --git a/massa-execution-worker/src/module_cache.rs b/massa-execution-worker/src/module_cache.rs index 0fb19efe736..0774002d604 100644 --- a/massa-execution-worker/src/module_cache.rs +++ b/massa-execution-worker/src/module_cache.rs @@ -1,6 +1,7 @@ use massa_execution_exports::ExecutionError; use massa_sc_runtime::{GasCosts, RuntimeModule}; use schnellru::{ByLength, LruMap}; +use tracing::warn; pub struct ModuleCache { gas_costs: GasCosts, @@ -29,8 +30,10 @@ impl ModuleCache { limit: u64, ) -> Result { let module = if let Some(cached_module) = self.cache.get(bytecode) { + warn!("(CACHE) module found"); cached_module.clone() } else { + warn!("(CACHE) module saved"); let new_module = RuntimeModule::new(bytecode, limit, self.gas_costs.clone()).map_err(|err| { ExecutionError::RuntimeError(format!( diff --git a/massa-node/base_config/initial_ledger.json b/massa-node/base_config/initial_ledger.json index 3d93a1a5fda..26a862f4637 100644 --- a/massa-node/base_config/initial_ledger.json +++ b/massa-node/base_config/initial_ledger.json @@ -1,46 +1,6 @@ { - "A1qDAxGJ387ETi9JRQzZWSPKYq4YPXrFvdiE4VoXUaiAt38JFEC": { - "balance": "1000000000", - "datastore": {}, - "bytecode": [] - }, - "A12M3AQqs7JH7mSe1UZyEA5NQ7nGQHXaqqxe1TGEpkimcRhsQ4eF": { - "balance": "1000000000", - "datastore": {}, - "bytecode": [] - }, - "A1nsqw9mCcYLyyMJx5f4in4NXDoe4B1LzV9pQdvX5Wrxq9ehf6h": { - "balance": "1000000000", - "datastore": {}, - "bytecode": [] - }, - "A1pdnk7gME8DSA6ueNZdCHqfSt9YfTwAJSgRCcB8g3z3kkapWtU": { - "balance": "1000000000", - "datastore": {}, - "bytecode": [] - }, - "A1H1Ze77ctAFi4FBc3nVe9AtWdtg7246V9pVXSeXqWaJFLPKfB1": { - "balance": "1000000000", - "datastore": {}, - "bytecode": [] - }, - "A12Dvay7jT1maaKpV9CHX6yMt3cS5ZEWy6Q67HV8twVGS3ihoq5x": { - "balance": "1000000000", - "datastore": {}, - "bytecode": [] - }, - "A13evhD7c9AXFc6CxWWjWWRT6bQnejYhq3MsNofJWJDe4UQStJE": { - "balance": "1000000000", - "datastore": {}, - "bytecode": [] - }, - "A1UpZLobUAWqj3M9DpBZNhh4GD4ZLvixKXQu2kt7ZDUiEepD89E": { - "balance": "1000000000", - "datastore": {}, - "bytecode": [] - }, - "A12p8v9V68SiehQb2Syzy6smfv9NTCJh2p6JPbsacy7PaGRw39uH": { - "balance": "1000000000", + "A12AXf3ngq3e5zPWikXu3QGR18JtX3wbRuduA3126joowvPwVWdk": { + "balance": "80000000", "datastore": {}, "bytecode": [] } diff --git a/massa-node/base_config/initial_rolls.json b/massa-node/base_config/initial_rolls.json index 19b631e303e..1dc8942a712 100644 --- a/massa-node/base_config/initial_rolls.json +++ b/massa-node/base_config/initial_rolls.json @@ -1,11 +1,3 @@ { - "A1qDAxGJ387ETi9JRQzZWSPKYq4YPXrFvdiE4VoXUaiAt38JFEC": 10, - "A12M3AQqs7JH7mSe1UZyEA5NQ7nGQHXaqqxe1TGEpkimcRhsQ4eF": 10, - "A1nsqw9mCcYLyyMJx5f4in4NXDoe4B1LzV9pQdvX5Wrxq9ehf6h": 10, - "A1pdnk7gME8DSA6ueNZdCHqfSt9YfTwAJSgRCcB8g3z3kkapWtU": 10, - "A1H1Ze77ctAFi4FBc3nVe9AtWdtg7246V9pVXSeXqWaJFLPKfB1": 10, - "A12Dvay7jT1maaKpV9CHX6yMt3cS5ZEWy6Q67HV8twVGS3ihoq5x": 10, - "A13evhD7c9AXFc6CxWWjWWRT6bQnejYhq3MsNofJWJDe4UQStJE": 10, - "A1UpZLobUAWqj3M9DpBZNhh4GD4ZLvixKXQu2kt7ZDUiEepD89E": 10, - "A12p8v9V68SiehQb2Syzy6smfv9NTCJh2p6JPbsacy7PaGRw39uH": 10 + "A12AXf3ngq3e5zPWikXu3QGR18JtX3wbRuduA3126joowvPwVWdk": 10 } From daade3fe6b6c83ef6a45b52b0323a0e6e6e08729 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Thu, 19 Jan 2023 13:30:12 +0100 Subject: [PATCH 40/80] revert bugfix changes --- Cargo.lock | 1 - massa-execution-worker/Cargo.toml | 1 - massa-execution-worker/src/execution.rs | 22 ++++------- massa-execution-worker/src/module_cache.rs | 3 -- massa-node/base_config/initial_ledger.json | 44 +++++++++++++++++++++- massa-node/base_config/initial_rolls.json | 10 ++++- 6 files changed, 59 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59ab51b7c63..53971bcd21c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2482,7 +2482,6 @@ dependencies = [ "serial_test 0.10.0", "tempfile", "tracing", - "wasmer", ] [[package]] diff --git a/massa-execution-worker/Cargo.toml b/massa-execution-worker/Cargo.toml index 49ec94fb235..fc856acc531 100644 --- a/massa-execution-worker/Cargo.toml +++ b/massa-execution-worker/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -wasmer = { version = "3.0" } anyhow = "1.0" rand = "0.8" rand_xoshiro = "0.6" diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index bb4112f8e07..ab71f300a13 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -32,13 +32,12 @@ use massa_models::{ }; use massa_models::{amount::Amount, slot::Slot}; use massa_pos_exports::SelectorController; -use massa_sc_runtime::{init_engine, Interface, RuntimeModule, ASModule}; +use massa_sc_runtime::{Interface, RuntimeModule}; use massa_storage::Storage; use parking_lot::{Mutex, RwLock}; use std::collections::{BTreeMap, BTreeSet}; use std::sync::Arc; use tracing::{debug, info, warn}; -use wasmer::{Engine, Module}; /// Used to acquire a lock on the execution context macro_rules! context_guard { @@ -515,21 +514,17 @@ impl ExecutionState { }; // run the VM on the bytecode contained in the operation - // let module = RuntimeModule::new(bytecode, *max_gas, self.config.gas_costs.clone()) - // .map_err(|err| { - // ExecutionError::RuntimeError(format!( - // "compilation error in execute_executesc_op: {}", - // err - // )) - // })?; - let engine = init_engine(*max_gas, self.config.gas_costs.clone()).unwrap(); - let binary_module = Module::new(&engine, bytecode).unwrap(); - let module = RuntimeModule::ASModule(ASModule { binary_module }); + let module = RuntimeModule::new(bytecode, *max_gas, self.config.gas_costs.clone()) + .map_err(|err| { + ExecutionError::RuntimeError(format!( + "compilation error in execute_executesc_op: {}", + err + )) + })?; match massa_sc_runtime::run_main( &*self.execution_interface, module, *max_gas, - Some(engine), self.config.gas_costs.clone(), ) { Ok(_response) => {} @@ -1086,7 +1081,6 @@ impl ExecutionState { &*self.execution_interface, module, req.max_gas, - None, self.config.gas_costs.clone(), ) .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? diff --git a/massa-execution-worker/src/module_cache.rs b/massa-execution-worker/src/module_cache.rs index 0774002d604..0fb19efe736 100644 --- a/massa-execution-worker/src/module_cache.rs +++ b/massa-execution-worker/src/module_cache.rs @@ -1,7 +1,6 @@ use massa_execution_exports::ExecutionError; use massa_sc_runtime::{GasCosts, RuntimeModule}; use schnellru::{ByLength, LruMap}; -use tracing::warn; pub struct ModuleCache { gas_costs: GasCosts, @@ -30,10 +29,8 @@ impl ModuleCache { limit: u64, ) -> Result { let module = if let Some(cached_module) = self.cache.get(bytecode) { - warn!("(CACHE) module found"); cached_module.clone() } else { - warn!("(CACHE) module saved"); let new_module = RuntimeModule::new(bytecode, limit, self.gas_costs.clone()).map_err(|err| { ExecutionError::RuntimeError(format!( diff --git a/massa-node/base_config/initial_ledger.json b/massa-node/base_config/initial_ledger.json index 26a862f4637..3d93a1a5fda 100644 --- a/massa-node/base_config/initial_ledger.json +++ b/massa-node/base_config/initial_ledger.json @@ -1,6 +1,46 @@ { - "A12AXf3ngq3e5zPWikXu3QGR18JtX3wbRuduA3126joowvPwVWdk": { - "balance": "80000000", + "A1qDAxGJ387ETi9JRQzZWSPKYq4YPXrFvdiE4VoXUaiAt38JFEC": { + "balance": "1000000000", + "datastore": {}, + "bytecode": [] + }, + "A12M3AQqs7JH7mSe1UZyEA5NQ7nGQHXaqqxe1TGEpkimcRhsQ4eF": { + "balance": "1000000000", + "datastore": {}, + "bytecode": [] + }, + "A1nsqw9mCcYLyyMJx5f4in4NXDoe4B1LzV9pQdvX5Wrxq9ehf6h": { + "balance": "1000000000", + "datastore": {}, + "bytecode": [] + }, + "A1pdnk7gME8DSA6ueNZdCHqfSt9YfTwAJSgRCcB8g3z3kkapWtU": { + "balance": "1000000000", + "datastore": {}, + "bytecode": [] + }, + "A1H1Ze77ctAFi4FBc3nVe9AtWdtg7246V9pVXSeXqWaJFLPKfB1": { + "balance": "1000000000", + "datastore": {}, + "bytecode": [] + }, + "A12Dvay7jT1maaKpV9CHX6yMt3cS5ZEWy6Q67HV8twVGS3ihoq5x": { + "balance": "1000000000", + "datastore": {}, + "bytecode": [] + }, + "A13evhD7c9AXFc6CxWWjWWRT6bQnejYhq3MsNofJWJDe4UQStJE": { + "balance": "1000000000", + "datastore": {}, + "bytecode": [] + }, + "A1UpZLobUAWqj3M9DpBZNhh4GD4ZLvixKXQu2kt7ZDUiEepD89E": { + "balance": "1000000000", + "datastore": {}, + "bytecode": [] + }, + "A12p8v9V68SiehQb2Syzy6smfv9NTCJh2p6JPbsacy7PaGRw39uH": { + "balance": "1000000000", "datastore": {}, "bytecode": [] } diff --git a/massa-node/base_config/initial_rolls.json b/massa-node/base_config/initial_rolls.json index 1dc8942a712..19b631e303e 100644 --- a/massa-node/base_config/initial_rolls.json +++ b/massa-node/base_config/initial_rolls.json @@ -1,3 +1,11 @@ { - "A12AXf3ngq3e5zPWikXu3QGR18JtX3wbRuduA3126joowvPwVWdk": 10 + "A1qDAxGJ387ETi9JRQzZWSPKYq4YPXrFvdiE4VoXUaiAt38JFEC": 10, + "A12M3AQqs7JH7mSe1UZyEA5NQ7nGQHXaqqxe1TGEpkimcRhsQ4eF": 10, + "A1nsqw9mCcYLyyMJx5f4in4NXDoe4B1LzV9pQdvX5Wrxq9ehf6h": 10, + "A1pdnk7gME8DSA6ueNZdCHqfSt9YfTwAJSgRCcB8g3z3kkapWtU": 10, + "A1H1Ze77ctAFi4FBc3nVe9AtWdtg7246V9pVXSeXqWaJFLPKfB1": 10, + "A12Dvay7jT1maaKpV9CHX6yMt3cS5ZEWy6Q67HV8twVGS3ihoq5x": 10, + "A13evhD7c9AXFc6CxWWjWWRT6bQnejYhq3MsNofJWJDe4UQStJE": 10, + "A1UpZLobUAWqj3M9DpBZNhh4GD4ZLvixKXQu2kt7ZDUiEepD89E": 10, + "A12p8v9V68SiehQb2Syzy6smfv9NTCJh2p6JPbsacy7PaGRw39uH": 10 } From d510cf49e4e5a9b05b679aec27a31f90e42a6b46 Mon Sep 17 00:00:00 2001 From: Sydhds Date: Thu, 19 Jan 2023 15:18:48 +0100 Subject: [PATCH 41/80] Move BlockId into block_id.rs & BlockHeader into block_header.rs (#3447) * Move BlockId into block_id.rs & BlockHeader into block_header.rs * Cargo fmt pass Co-authored-by: sydhds --- massa-api-exports/src/address.rs | 2 +- massa-api-exports/src/block.rs | 2 +- massa-api-exports/src/endorsement.rs | 2 +- massa-api-exports/src/operation.rs | 2 +- massa-api/src/lib.rs | 8 +- massa-api/src/private.rs | 8 +- massa-api/src/public.rs | 2 +- massa-bootstrap/src/messages.rs | 2 +- massa-bootstrap/src/server.rs | 2 +- massa-bootstrap/src/tests/tools.rs | 4 +- massa-client/src/cmds.rs | 2 +- .../src/block_graph_export.rs | 2 +- massa-consensus-exports/src/block_status.rs | 7 +- .../src/bootstrapable_graph.rs | 4 +- massa-consensus-exports/src/channels.rs | 3 +- .../src/controller_trait.rs | 7 +- .../src/export_active_block.rs | 7 +- .../src/test_exports/mock.rs | 8 +- massa-consensus-worker/src/commands.rs | 4 +- massa-consensus-worker/src/controller.rs | 4 +- massa-consensus-worker/src/state/graph.rs | 2 +- massa-consensus-worker/src/state/mod.rs | 4 +- massa-consensus-worker/src/state/process.rs | 3 +- .../src/state/process_commands.rs | 5 +- massa-consensus-worker/src/state/prune.rs | 2 +- massa-consensus-worker/src/state/tick.rs | 2 +- .../src/state/verifications.rs | 4 +- massa-consensus-worker/src/worker/init.rs | 6 +- massa-consensus-worker/src/worker/mod.rs | 2 +- .../src/controller_traits.rs | 2 +- .../src/test_exports/mock.rs | 2 +- massa-execution-exports/src/types.rs | 2 +- massa-execution-worker/src/context.rs | 2 +- massa-execution-worker/src/controller.rs | 2 +- massa-execution-worker/src/execution.rs | 2 +- massa-execution-worker/src/slot_sequencer.rs | 2 +- .../src/speculative_roll_state.rs | 2 +- massa-execution-worker/src/tests/mock.rs | 3 +- .../src/tests/scenarios_mandatories.rs | 2 +- massa-execution-worker/src/worker.rs | 2 +- .../src/test_exports/tools.rs | 3 +- massa-factory-worker/src/block_factory.rs | 4 +- .../src/endorsement_factory.rs | 2 +- massa-factory-worker/src/tests/tools.rs | 2 +- massa-models/src/active_block.rs | 2 +- massa-models/src/block.rs | 632 +----------------- massa-models/src/block_header.rs | 453 +++++++++++++ massa-models/src/block_id.rs | 165 +++++ massa-models/src/clique.rs | 6 +- massa-models/src/composite.rs | 2 +- massa-models/src/endorsement.rs | 10 +- massa-models/src/ledger.rs | 16 +- massa-models/src/lib.rs | 6 +- massa-models/src/output_event.rs | 2 +- massa-models/src/secure_share.rs | 3 +- massa-network-exports/src/commands.rs | 3 +- .../src/network_controller.rs | 3 +- massa-network-worker/src/messages.rs | 3 +- massa-network-worker/src/network_cmd_impl.rs | 3 +- massa-network-worker/src/network_event.rs | 3 +- massa-network-worker/src/tests/scenarios.rs | 2 +- massa-network-worker/src/tests/tools.rs | 2 +- massa-pool-exports/src/controller_traits.rs | 2 +- massa-pool-exports/src/test_exports/mock.rs | 2 +- massa-pool-worker/src/controller_impl.rs | 2 +- massa-pool-worker/src/endorsement_pool.rs | 2 +- massa-pool-worker/src/tests/tools.rs | 2 +- .../src/protocol_controller.rs | 3 +- .../src/test_exports/mock.rs | 2 +- .../src/tests/mock_network_controller.rs | 3 +- massa-protocol-exports/src/tests/tools.rs | 6 +- massa-protocol-worker/src/node_info.rs | 2 +- massa-protocol-worker/src/protocol_network.rs | 5 +- massa-protocol-worker/src/protocol_worker.rs | 3 +- .../src/tests/ask_block_scenarios.rs | 2 +- .../src/tests/ban_nodes_scenarios.rs | 2 +- .../tests/in_block_operations_scenarios.rs | 3 +- .../src/tests/operations_scenarios.rs | 2 +- massa-protocol-worker/src/tests/scenarios.rs | 2 +- massa-protocol-worker/src/tests/tools.rs | 4 +- massa-sdk/src/lib.rs | 4 +- massa-storage/src/block_indexes.rs | 3 +- massa-storage/src/lib.rs | 3 +- 83 files changed, 788 insertions(+), 733 deletions(-) create mode 100644 massa-models/src/block_header.rs create mode 100644 massa-models/src/block_id.rs diff --git a/massa-api-exports/src/address.rs b/massa-api-exports/src/address.rs index 724c71f17a0..7410f0df20e 100644 --- a/massa-api-exports/src/address.rs +++ b/massa-api-exports/src/address.rs @@ -4,7 +4,7 @@ use massa_models::address::ExecutionAddressCycleInfo; use massa_models::endorsement::EndorsementId; use massa_models::operation::OperationId; use massa_models::slot::{IndexedSlot, Slot}; -use massa_models::{address::Address, amount::Amount, block::BlockId}; +use massa_models::{address::Address, amount::Amount, block_id::BlockId}; use serde::{Deserialize, Serialize}; use crate::slot::SlotAmount; diff --git a/massa-api-exports/src/block.rs b/massa-api-exports/src/block.rs index 64b2ed6e19c..f10bcbd9633 100644 --- a/massa-api-exports/src/block.rs +++ b/massa-api-exports/src/block.rs @@ -1,6 +1,6 @@ // Copyright (c) 2022 MASSA LABS -use massa_models::{address::Address, block::Block, block::BlockId, slot::Slot}; +use massa_models::{address::Address, block::Block, block_id::BlockId, slot::Slot}; use serde::{Deserialize, Serialize}; diff --git a/massa-api-exports/src/endorsement.rs b/massa-api-exports/src/endorsement.rs index ed77ce100c3..1269dadc435 100644 --- a/massa-api-exports/src/endorsement.rs +++ b/massa-api-exports/src/endorsement.rs @@ -1,7 +1,7 @@ // Copyright (c) 2022 MASSA LABS use massa_models::{ - block::BlockId, + block_id::BlockId, endorsement::{EndorsementId, SecureShareEndorsement}, }; use serde::{Deserialize, Serialize}; diff --git a/massa-api-exports/src/operation.rs b/massa-api-exports/src/operation.rs index f0784b89ccf..9dd08545f9e 100644 --- a/massa-api-exports/src/operation.rs +++ b/massa-api-exports/src/operation.rs @@ -1,7 +1,7 @@ // Copyright (c) 2022 MASSA LABS use massa_models::{ - block::BlockId, + block_id::BlockId, operation::{OperationId, SecureShareOperation}, }; diff --git a/massa-api/src/lib.rs b/massa-api/src/lib.rs index 513eaca7af5..e3c63ac3a22 100644 --- a/massa-api/src/lib.rs +++ b/massa-api/src/lib.rs @@ -30,12 +30,8 @@ use massa_models::operation::OperationId; use massa_models::output_event::SCOutputEvent; use massa_models::prehash::PreHashSet; use massa_models::{ - address::Address, - block::{Block, BlockId}, - endorsement::EndorsementId, - execution::EventFilter, - slot::Slot, - version::Version, + address::Address, block::Block, block_id::BlockId, endorsement::EndorsementId, + execution::EventFilter, slot::Slot, version::Version, }; use massa_network_exports::{NetworkCommandSender, NetworkConfig}; use massa_pool_exports::{PoolChannels, PoolController}; diff --git a/massa-api/src/private.rs b/massa-api/src/private.rs index c7dbb9d2b5d..894e102bc75 100644 --- a/massa-api/src/private.rs +++ b/massa-api/src/private.rs @@ -24,12 +24,8 @@ use massa_models::node::NodeId; use massa_models::output_event::SCOutputEvent; use massa_models::prehash::PreHashSet; use massa_models::{ - address::Address, - block::{Block, BlockId}, - endorsement::EndorsementId, - execution::EventFilter, - operation::OperationId, - slot::Slot, + address::Address, block::Block, block_id::BlockId, endorsement::EndorsementId, + execution::EventFilter, operation::OperationId, slot::Slot, }; use massa_network_exports::NetworkCommandSender; use massa_signature::KeyPair; diff --git a/massa-api/src/public.rs b/massa-api/src/public.rs index 3ca99b3d03a..1a14c2b6f54 100644 --- a/massa-api/src/public.rs +++ b/massa-api/src/public.rs @@ -39,7 +39,7 @@ use itertools::{izip, Itertools}; use massa_models::datastore::DatastoreDeserializer; use massa_models::{ address::Address, - block::BlockId, + block_id::BlockId, clique::Clique, composite::PubkeySig, config::CompactConfig, diff --git a/massa-bootstrap/src/messages.rs b/massa-bootstrap/src/messages.rs index 44800e8917c..24c1a3b5cc8 100644 --- a/massa-bootstrap/src/messages.rs +++ b/massa-bootstrap/src/messages.rs @@ -10,7 +10,7 @@ use massa_consensus_exports::bootstrapable_graph::{ use massa_executed_ops::{ExecutedOpsDeserializer, ExecutedOpsSerializer}; use massa_final_state::{StateChanges, StateChangesDeserializer, StateChangesSerializer}; use massa_ledger_exports::{KeyDeserializer, KeySerializer}; -use massa_models::block::{BlockId, BlockIdDeserializer, BlockIdSerializer}; +use massa_models::block_id::{BlockId, BlockIdDeserializer, BlockIdSerializer}; use massa_models::operation::OperationId; use massa_models::prehash::PreHashSet; use massa_models::serialization::{ diff --git a/massa-bootstrap/src/server.rs b/massa-bootstrap/src/server.rs index dc399465b05..e7db4656df6 100644 --- a/massa-bootstrap/src/server.rs +++ b/massa-bootstrap/src/server.rs @@ -6,7 +6,7 @@ use massa_consensus_exports::{bootstrapable_graph::BootstrapableGraph, Consensus use massa_final_state::{FinalState, FinalStateError}; use massa_logging::massa_trace; use massa_models::{ - block::BlockId, prehash::PreHashSet, slot::Slot, streaming_step::StreamingStep, + block_id::BlockId, prehash::PreHashSet, slot::Slot, streaming_step::StreamingStep, version::Version, }; use massa_network_exports::NetworkCommandSender; diff --git a/massa-bootstrap/src/tests/tools.rs b/massa-bootstrap/src/tests/tools.rs index 2b349ac184d..92a6d9ec610 100644 --- a/massa-bootstrap/src/tests/tools.rs +++ b/massa-bootstrap/src/tests/tools.rs @@ -32,8 +32,10 @@ use massa_models::node::NodeId; use massa_models::{ address::Address, amount::Amount, + block::Block, block::BlockSerializer, - block::{Block, BlockHeader, BlockHeaderSerializer, BlockId}, + block_header::{BlockHeader, BlockHeaderSerializer}, + block_id::BlockId, endorsement::Endorsement, endorsement::EndorsementSerializer, operation::OperationId, diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index a6922aa8b7c..dc804e664da 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -15,7 +15,7 @@ use massa_models::timeslots::get_current_latest_block_slot; use massa_models::{ address::Address, amount::Amount, - block::BlockId, + block_id::BlockId, endorsement::EndorsementId, execution::EventFilter, operation::{Operation, OperationId, OperationType}, diff --git a/massa-consensus-exports/src/block_graph_export.rs b/massa-consensus-exports/src/block_graph_export.rs index bd8f5d27069..1221244b2cf 100644 --- a/massa-consensus-exports/src/block_graph_export.rs +++ b/massa-consensus-exports/src/block_graph_export.rs @@ -1,6 +1,6 @@ use massa_models::{ address::Address, - block::BlockId, + block_id::BlockId, clique::Clique, prehash::{PreHashMap, PreHashSet}, slot::Slot, diff --git a/massa-consensus-exports/src/block_status.rs b/massa-consensus-exports/src/block_status.rs index 9ad461f5906..89d393efab4 100644 --- a/massa-consensus-exports/src/block_status.rs +++ b/massa-consensus-exports/src/block_status.rs @@ -1,9 +1,6 @@ use massa_models::{ - active_block::ActiveBlock, - address::Address, - block::{Block, BlockId, SecuredHeader}, - prehash::PreHashSet, - slot::Slot, + active_block::ActiveBlock, address::Address, block::Block, block_header::SecuredHeader, + block_id::BlockId, prehash::PreHashSet, slot::Slot, }; use massa_storage::Storage; use serde::{Deserialize, Serialize}; diff --git a/massa-consensus-exports/src/bootstrapable_graph.rs b/massa-consensus-exports/src/bootstrapable_graph.rs index 4ee633653ff..b7988051b7d 100644 --- a/massa-consensus-exports/src/bootstrapable_graph.rs +++ b/massa-consensus-exports/src/bootstrapable_graph.rs @@ -39,7 +39,7 @@ impl Serializer for BootstrapableGraphSerializer { /// use massa_consensus_exports::bootstrapable_graph::{BootstrapableGraph, BootstrapableGraphSerializer}; /// use massa_serialization::Serializer; /// use massa_hash::Hash; - /// use massa_models::{prehash::PreHashMap, block::BlockId, config::THREAD_COUNT}; + /// use massa_models::{prehash::PreHashMap, block_id::BlockId, config::THREAD_COUNT}; /// let mut bootstrapable_graph = BootstrapableGraph { /// final_blocks: Vec::new(), /// }; @@ -106,7 +106,7 @@ impl Deserializer for BootstrapableGraphDeserializer { /// use massa_consensus_exports::bootstrapable_graph::{BootstrapableGraph, BootstrapableGraphDeserializer, BootstrapableGraphSerializer}; /// use massa_serialization::{Deserializer, Serializer, DeserializeError}; /// use massa_hash::Hash; - /// use massa_models::{prehash::PreHashMap, block::BlockId, config::THREAD_COUNT}; + /// use massa_models::{prehash::PreHashMap, block_id::BlockId, config::THREAD_COUNT}; /// let mut bootstrapable_graph = BootstrapableGraph { /// final_blocks: Vec::new(), /// }; diff --git a/massa-consensus-exports/src/channels.rs b/massa-consensus-exports/src/channels.rs index 2cc2a44bde6..d09fb6a515a 100644 --- a/massa-consensus-exports/src/channels.rs +++ b/massa-consensus-exports/src/channels.rs @@ -1,5 +1,6 @@ use massa_execution_exports::ExecutionController; -use massa_models::block::{Block, BlockHeader, FilledBlock}; +use massa_models::block::{Block, FilledBlock}; +use massa_models::block_header::BlockHeader; use massa_pool_exports::PoolController; use massa_pos_exports::SelectorController; use massa_protocol_exports::ProtocolCommandSender; diff --git a/massa-consensus-exports/src/controller_trait.rs b/massa-consensus-exports/src/controller_trait.rs index bff8eeb68bc..ecd9f22f1d4 100644 --- a/massa-consensus-exports/src/controller_trait.rs +++ b/massa-consensus-exports/src/controller_trait.rs @@ -3,11 +3,8 @@ use crate::{bootstrapable_graph::BootstrapableGraph, error::ConsensusError}; use massa_models::prehash::PreHashSet; use massa_models::streaming_step::StreamingStep; use massa_models::{ - block::{BlockGraphStatus, BlockHeader, BlockId}, - clique::Clique, - secure_share::SecureShare, - slot::Slot, - stats::ConsensusStats, + block::BlockGraphStatus, block_header::BlockHeader, block_id::BlockId, clique::Clique, + secure_share::SecureShare, slot::Slot, stats::ConsensusStats, }; use massa_storage::Storage; diff --git a/massa-consensus-exports/src/export_active_block.rs b/massa-consensus-exports/src/export_active_block.rs index bd8332937d4..c9cd601540f 100644 --- a/massa-consensus-exports/src/export_active_block.rs +++ b/massa-consensus-exports/src/export_active_block.rs @@ -2,7 +2,8 @@ use crate::error::ConsensusError; use massa_hash::HashDeserializer; use massa_models::{ active_block::ActiveBlock, - block::{Block, BlockDeserializer, BlockId, SecureShareBlock}, + block::{Block, BlockDeserializer, SecureShareBlock}, + block_id::BlockId, prehash::PreHashMap, secure_share::{SecureShareDeserializer, SecureShareSerializer}, }; @@ -156,7 +157,9 @@ impl Deserializer for ExportActiveBlockDeserializer { /// ## Example: /// ```rust /// use massa_consensus_exports::export_active_block::{ExportActiveBlock, ExportActiveBlockDeserializer, ExportActiveBlockSerializer}; - /// use massa_models::{ledger::LedgerChanges, config::THREAD_COUNT, rolls::RollUpdates, block::{BlockId, Block, BlockSerializer, BlockHeader, BlockHeaderSerializer}, prehash::PreHashSet, endorsement::{Endorsement, EndorsementSerializer}, slot::Slot, secure_share::SecureShareContent}; + /// use massa_models::{ledger::LedgerChanges, config::THREAD_COUNT, rolls::RollUpdates, block::{Block, BlockSerializer}, prehash::PreHashSet, endorsement::{Endorsement, EndorsementSerializer}, slot::Slot, secure_share::SecureShareContent}; + /// use massa_models::block_id::BlockId; + /// use massa_models::block_header::{BlockHeader, BlockHeaderSerializer}; /// use massa_hash::Hash; /// use std::collections::HashSet; /// use massa_signature::KeyPair; diff --git a/massa-consensus-exports/src/test_exports/mock.rs b/massa-consensus-exports/src/test_exports/mock.rs index 36ab094f675..70b1c256607 100644 --- a/massa-consensus-exports/src/test_exports/mock.rs +++ b/massa-consensus-exports/src/test_exports/mock.rs @@ -6,12 +6,8 @@ use std::sync::{ }; use massa_models::{ - block::{BlockGraphStatus, BlockHeader, BlockId}, - clique::Clique, - prehash::PreHashSet, - secure_share::SecureShare, - slot::Slot, - stats::ConsensusStats, + block::BlockGraphStatus, block_header::BlockHeader, block_id::BlockId, clique::Clique, + prehash::PreHashSet, secure_share::SecureShare, slot::Slot, stats::ConsensusStats, streaming_step::StreamingStep, }; use massa_storage::Storage; diff --git a/massa-consensus-worker/src/commands.rs b/massa-consensus-worker/src/commands.rs index e9852478491..5541cf8f296 100644 --- a/massa-consensus-worker/src/commands.rs +++ b/massa-consensus-worker/src/commands.rs @@ -1,7 +1,5 @@ use massa_models::{ - block::{BlockHeader, BlockId}, - secure_share::SecureShare, - slot::Slot, + block_header::BlockHeader, block_id::BlockId, secure_share::SecureShare, slot::Slot, }; use massa_storage::Storage; diff --git a/massa-consensus-worker/src/controller.rs b/massa-consensus-worker/src/controller.rs index 4cf23476bc9..42043454290 100644 --- a/massa-consensus-worker/src/controller.rs +++ b/massa-consensus-worker/src/controller.rs @@ -4,7 +4,9 @@ use massa_consensus_exports::{ export_active_block::ExportActiveBlock, ConsensusChannels, ConsensusController, }; use massa_models::{ - block::{BlockGraphStatus, BlockHeader, BlockId, FilledBlock}, + block::{BlockGraphStatus, FilledBlock}, + block_header::BlockHeader, + block_id::BlockId, clique::Clique, operation::{Operation, OperationId}, prehash::PreHashSet, diff --git a/massa-consensus-worker/src/state/graph.rs b/massa-consensus-worker/src/state/graph.rs index b2c08e5c6d9..11bce905b0d 100644 --- a/massa-consensus-worker/src/state/graph.rs +++ b/massa-consensus-worker/src/state/graph.rs @@ -5,7 +5,7 @@ use massa_consensus_exports::{ error::ConsensusError, }; use massa_logging::massa_trace; -use massa_models::{block::BlockId, clique::Clique, prehash::PreHashSet, slot::Slot}; +use massa_models::{block_id::BlockId, clique::Clique, prehash::PreHashSet, slot::Slot}; use super::ConsensusState; diff --git a/massa-consensus-worker/src/state/mod.rs b/massa-consensus-worker/src/state/mod.rs index 00a655f934b..7197110f1ac 100644 --- a/massa-consensus-worker/src/state/mod.rs +++ b/massa-consensus-worker/src/state/mod.rs @@ -12,7 +12,9 @@ use massa_consensus_exports::{ use massa_models::{ active_block::ActiveBlock, address::Address, - block::{BlockGraphStatus, BlockId, SecuredHeader}, + block::BlockGraphStatus, + block_header::SecuredHeader, + block_id::BlockId, clique::Clique, prehash::{CapacityAllocator, PreHashMap, PreHashSet}, slot::Slot, diff --git a/massa-consensus-worker/src/state/process.rs b/massa-consensus-worker/src/state/process.rs index 270d075fbfa..b7ab4c808fa 100644 --- a/massa-consensus-worker/src/state/process.rs +++ b/massa-consensus-worker/src/state/process.rs @@ -11,7 +11,8 @@ use massa_logging::massa_trace; use massa_models::{ active_block::ActiveBlock, address::Address, - block::{BlockId, SecuredHeader}, + block_header::SecuredHeader, + block_id::BlockId, clique::Clique, prehash::{PreHashMap, PreHashSet}, slot::Slot, diff --git a/massa-consensus-worker/src/state/process_commands.rs b/massa-consensus-worker/src/state/process_commands.rs index 196377353fc..5fec3eebfbc 100644 --- a/massa-consensus-worker/src/state/process_commands.rs +++ b/massa-consensus-worker/src/state/process_commands.rs @@ -5,10 +5,7 @@ use massa_consensus_exports::{ error::ConsensusError, }; use massa_logging::massa_trace; -use massa_models::{ - block::{BlockId, SecuredHeader}, - slot::Slot, -}; +use massa_models::{block_header::SecuredHeader, block_id::BlockId, slot::Slot}; use massa_storage::Storage; use massa_time::MassaTime; use tracing::debug; diff --git a/massa-consensus-worker/src/state/prune.rs b/massa-consensus-worker/src/state/prune.rs index beda15cdb14..e60fa1609c5 100644 --- a/massa-consensus-worker/src/state/prune.rs +++ b/massa-consensus-worker/src/state/prune.rs @@ -5,7 +5,7 @@ use massa_consensus_exports::{ use massa_logging::massa_trace; use massa_models::{ active_block::ActiveBlock, - block::BlockId, + block_id::BlockId, prehash::{PreHashMap, PreHashSet}, slot::Slot, }; diff --git a/massa-consensus-worker/src/state/tick.rs b/massa-consensus-worker/src/state/tick.rs index 3165bc82669..4e4ac156098 100644 --- a/massa-consensus-worker/src/state/tick.rs +++ b/massa-consensus-worker/src/state/tick.rs @@ -2,7 +2,7 @@ use std::collections::BTreeSet; use massa_consensus_exports::{block_status::BlockStatus, error::ConsensusError}; use massa_logging::massa_trace; -use massa_models::{block::BlockId, slot::Slot}; +use massa_models::{block_id::BlockId, slot::Slot}; use super::ConsensusState; diff --git a/massa-consensus-worker/src/state/verifications.rs b/massa-consensus-worker/src/state/verifications.rs index 86835c421bd..bb2eddce944 100644 --- a/massa-consensus-worker/src/state/verifications.rs +++ b/massa-consensus-worker/src/state/verifications.rs @@ -6,9 +6,7 @@ use massa_consensus_exports::{ }; use massa_logging::massa_trace; use massa_models::{ - block::{BlockId, SecuredHeader}, - prehash::PreHashSet, - slot::Slot, + block_header::SecuredHeader, block_id::BlockId, prehash::PreHashSet, slot::Slot, }; /// Possible output of a header check diff --git a/massa-consensus-worker/src/worker/init.rs b/massa-consensus-worker/src/worker/init.rs index 9b2d5be07ff..48e49e0cdd5 100644 --- a/massa-consensus-worker/src/worker/init.rs +++ b/massa-consensus-worker/src/worker/init.rs @@ -6,9 +6,9 @@ use massa_hash::Hash; use massa_models::{ active_block::ActiveBlock, address::Address, - block::{ - Block, BlockHeader, BlockHeaderSerializer, BlockId, BlockSerializer, SecureShareBlock, - }, + block::{Block, BlockSerializer, SecureShareBlock}, + block_header::{BlockHeader, BlockHeaderSerializer}, + block_id::BlockId, prehash::PreHashMap, secure_share::SecureShareContent, slot::Slot, diff --git a/massa-consensus-worker/src/worker/mod.rs b/massa-consensus-worker/src/worker/mod.rs index 298b2341d99..42793c21569 100644 --- a/massa-consensus-worker/src/worker/mod.rs +++ b/massa-consensus-worker/src/worker/mod.rs @@ -2,7 +2,7 @@ use massa_consensus_exports::{ bootstrapable_graph::BootstrapableGraph, ConsensusChannels, ConsensusConfig, ConsensusController, ConsensusManager, }; -use massa_models::block::BlockId; +use massa_models::block_id::BlockId; use massa_models::clique::Clique; use massa_models::config::CHANNEL_SIZE; use massa_models::prehash::PreHashSet; diff --git a/massa-execution-exports/src/controller_traits.rs b/massa-execution-exports/src/controller_traits.rs index 198ea76e9b6..74e72dbd49b 100644 --- a/massa-execution-exports/src/controller_traits.rs +++ b/massa-execution-exports/src/controller_traits.rs @@ -7,7 +7,7 @@ use crate::ExecutionError; use crate::{ExecutionAddressInfo, ReadOnlyExecutionOutput}; use massa_models::address::Address; use massa_models::amount::Amount; -use massa_models::block::BlockId; +use massa_models::block_id::BlockId; use massa_models::execution::EventFilter; use massa_models::operation::OperationId; use massa_models::output_event::SCOutputEvent; diff --git a/massa-execution-exports/src/test_exports/mock.rs b/massa-execution-exports/src/test_exports/mock.rs index 701ba34d849..ad4d775698a 100644 --- a/massa-execution-exports/src/test_exports/mock.rs +++ b/massa-execution-exports/src/test_exports/mock.rs @@ -10,7 +10,7 @@ use massa_ledger_exports::LedgerEntry; use massa_models::{ address::Address, amount::Amount, - block::BlockId, + block_id::BlockId, execution::EventFilter, operation::OperationId, output_event::SCOutputEvent, diff --git a/massa-execution-exports/src/types.rs b/massa-execution-exports/src/types.rs index 3ebf802b6d5..6fe1a9d3906 100644 --- a/massa-execution-exports/src/types.rs +++ b/massa-execution-exports/src/types.rs @@ -6,7 +6,7 @@ use crate::event_store::EventStore; use massa_final_state::StateChanges; use massa_models::datastore::Datastore; use massa_models::{ - address::Address, address::ExecutionAddressCycleInfo, amount::Amount, block::BlockId, + address::Address, address::ExecutionAddressCycleInfo, amount::Amount, block_id::BlockId, slot::Slot, }; use std::collections::{BTreeMap, BTreeSet}; diff --git a/massa-execution-worker/src/context.rs b/massa-execution-worker/src/context.rs index 8b88ad2a14e..ffde16c7ea2 100644 --- a/massa-execution-worker/src/context.rs +++ b/massa-execution-worker/src/context.rs @@ -22,7 +22,7 @@ use massa_models::address::ExecutionAddressCycleInfo; use massa_models::{ address::Address, amount::Amount, - block::BlockId, + block_id::BlockId, operation::OperationId, output_event::{EventExecutionContext, SCOutputEvent}, slot::Slot, diff --git a/massa-execution-worker/src/controller.rs b/massa-execution-worker/src/controller.rs index c1d4f79441b..2f6fc629a6a 100644 --- a/massa-execution-worker/src/controller.rs +++ b/massa-execution-worker/src/controller.rs @@ -14,7 +14,7 @@ use massa_models::output_event::SCOutputEvent; use massa_models::prehash::{PreHashMap, PreHashSet}; use massa_models::stats::ExecutionStats; use massa_models::{address::Address, amount::Amount, operation::OperationId}; -use massa_models::{block::BlockId, slot::Slot}; +use massa_models::{block_id::BlockId, slot::Slot}; use massa_storage::Storage; use parking_lot::{Condvar, Mutex, RwLock}; use std::collections::{BTreeMap, HashMap}; diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index f21acf9894f..40742d51d1d 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -26,7 +26,7 @@ use massa_models::prehash::PreHashSet; use massa_models::stats::ExecutionStats; use massa_models::{ address::Address, - block::BlockId, + block_id::BlockId, operation::{OperationId, OperationType, SecureShareOperation}, }; use massa_models::{amount::Amount, slot::Slot}; diff --git a/massa-execution-worker/src/slot_sequencer.rs b/massa-execution-worker/src/slot_sequencer.rs index 9274857c099..e26350125a1 100644 --- a/massa-execution-worker/src/slot_sequencer.rs +++ b/massa-execution-worker/src/slot_sequencer.rs @@ -6,7 +6,7 @@ use std::collections::{HashMap, VecDeque}; use massa_execution_exports::ExecutionConfig; use massa_models::{ - block::BlockId, + block_id::BlockId, prehash::PreHashMap, slot::Slot, timeslots::{get_block_slot_timestamp, get_latest_block_slot_at_timestamp}, diff --git a/massa-execution-worker/src/speculative_roll_state.rs b/massa-execution-worker/src/speculative_roll_state.rs index 7da56cb3035..7a2d0ad7a52 100644 --- a/massa-execution-worker/src/speculative_roll_state.rs +++ b/massa-execution-worker/src/speculative_roll_state.rs @@ -5,7 +5,7 @@ use massa_execution_exports::ExecutionError; use massa_final_state::FinalState; use massa_models::address::ExecutionAddressCycleInfo; use massa_models::{ - address::Address, amount::Amount, block::BlockId, prehash::PreHashMap, slot::Slot, + address::Address, amount::Amount, block_id::BlockId, prehash::PreHashMap, slot::Slot, }; use massa_pos_exports::{DeferredCredits, PoSChanges, ProductionStats}; use num::rational::Ratio; diff --git a/massa-execution-worker/src/tests/mock.rs b/massa-execution-worker/src/tests/mock.rs index 99c473ff393..9bb91de238e 100644 --- a/massa-execution-worker/src/tests/mock.rs +++ b/massa-execution-worker/src/tests/mock.rs @@ -19,7 +19,8 @@ use tempfile::TempDir; #[cfg(feature = "testing")] use massa_models::{ - block::{Block, BlockHeader, BlockHeaderSerializer, BlockSerializer, SecureShareBlock}, + block::{Block, BlockSerializer, SecureShareBlock}, + block_header::{BlockHeader, BlockHeaderSerializer}, operation::SecureShareOperation, secure_share::SecureShareContent, slot::Slot, diff --git a/massa-execution-worker/src/tests/scenarios_mandatories.rs b/massa-execution-worker/src/tests/scenarios_mandatories.rs index e129cc8ca05..0289a4f3693 100644 --- a/massa-execution-worker/src/tests/scenarios_mandatories.rs +++ b/massa-execution-worker/src/tests/scenarios_mandatories.rs @@ -10,7 +10,7 @@ use massa_models::config::{LEDGER_ENTRY_BASE_SIZE, LEDGER_ENTRY_DATASTORE_BASE_S use massa_models::prehash::PreHashMap; use massa_models::{address::Address, amount::Amount, slot::Slot}; use massa_models::{ - block::BlockId, + block_id::BlockId, datastore::Datastore, execution::EventFilter, operation::{Operation, OperationSerializer, OperationType, SecureShareOperation}, diff --git a/massa-execution-worker/src/worker.rs b/massa-execution-worker/src/worker.rs index 667d2feaee8..a8f14032ae5 100644 --- a/massa-execution-worker/src/worker.rs +++ b/massa-execution-worker/src/worker.rs @@ -14,7 +14,7 @@ use massa_execution_exports::{ ReadOnlyExecutionOutput, ReadOnlyExecutionRequest, }; use massa_final_state::FinalState; -use massa_models::block::BlockId; +use massa_models::block_id::BlockId; use massa_models::slot::Slot; use massa_pos_exports::SelectorController; use massa_storage::Storage; diff --git a/massa-factory-exports/src/test_exports/tools.rs b/massa-factory-exports/src/test_exports/tools.rs index b3b51365bce..1427748a508 100644 --- a/massa-factory-exports/src/test_exports/tools.rs +++ b/massa-factory-exports/src/test_exports/tools.rs @@ -1,6 +1,7 @@ use massa_hash::Hash; use massa_models::{ - block::{Block, BlockHeader, BlockHeaderSerializer, BlockSerializer, SecureShareBlock}, + block::{Block, BlockSerializer, SecureShareBlock}, + block_header::{BlockHeader, BlockHeaderSerializer}, secure_share::SecureShareContent, slot::Slot, }; diff --git a/massa-factory-worker/src/block_factory.rs b/massa-factory-worker/src/block_factory.rs index 4fd187d988a..8655aa7de7c 100644 --- a/massa-factory-worker/src/block_factory.rs +++ b/massa-factory-worker/src/block_factory.rs @@ -3,7 +3,9 @@ use massa_factory_exports::{FactoryChannels, FactoryConfig}; use massa_hash::Hash; use massa_models::{ - block::{Block, BlockHeader, BlockHeaderSerializer, BlockId, BlockSerializer, SecuredHeader}, + block::{Block, BlockSerializer}, + block_header::{BlockHeader, BlockHeaderSerializer, SecuredHeader}, + block_id::BlockId, endorsement::SecureShareEndorsement, prehash::PreHashSet, secure_share::SecureShareContent, diff --git a/massa-factory-worker/src/endorsement_factory.rs b/massa-factory-worker/src/endorsement_factory.rs index d5c7812a516..1e9f2dc8f0f 100644 --- a/massa-factory-worker/src/endorsement_factory.rs +++ b/massa-factory-worker/src/endorsement_factory.rs @@ -2,7 +2,7 @@ use massa_factory_exports::{FactoryChannels, FactoryConfig}; use massa_models::{ - block::BlockId, + block_id::BlockId, endorsement::{Endorsement, EndorsementSerializer, SecureShareEndorsement}, secure_share::SecureShareContent, slot::Slot, diff --git a/massa-factory-worker/src/tests/tools.rs b/massa-factory-worker/src/tests/tools.rs index f5b2f5596ac..afb1336d9de 100644 --- a/massa-factory-worker/src/tests/tools.rs +++ b/massa-factory-worker/src/tests/tools.rs @@ -12,7 +12,7 @@ use massa_factory_exports::{ test_exports::create_empty_block, FactoryChannels, FactoryConfig, FactoryManager, }; use massa_models::{ - address::Address, block::BlockId, config::ENDORSEMENT_COUNT, + address::Address, block_id::BlockId, config::ENDORSEMENT_COUNT, endorsement::SecureShareEndorsement, operation::SecureShareOperation, prehash::PreHashMap, slot::Slot, test_exports::get_next_slot_instant, }; diff --git a/massa-models/src/active_block.rs b/massa-models/src/active_block.rs index 9f79c2c58dc..50a5f7293bc 100644 --- a/massa-models/src/active_block.rs +++ b/massa-models/src/active_block.rs @@ -1,6 +1,6 @@ use crate::{ address::Address, - block::BlockId, + block_id::BlockId, prehash::{PreHashMap, PreHashSet}, slot::Slot, }; diff --git a/massa-models/src/block.rs b/massa-models/src/block.rs index 71a66f5eab1..152fe94645a 100644 --- a/massa-models/src/block.rs +++ b/massa-models/src/block.rs @@ -1,193 +1,48 @@ //! Copyright (c) 2022 MASSA LABS -use crate::config::THREAD_COUNT; -use crate::endorsement::{EndorsementId, EndorsementSerializer, EndorsementSerializerLW}; -use crate::prehash::PreHashed; +// use crate::config::THREAD_COUNT; +// use crate::endorsement::{EndorsementId, EndorsementSerializer, EndorsementSerializerLW}; +// use crate::prehash::PreHashed; use crate::secure_share::{ Id, SecureShare, SecureShareContent, SecureShareDeserializer, SecureShareSerializer, }; use crate::{ - endorsement::{Endorsement, EndorsementDeserializerLW, SecureShareEndorsement}, + // endorsement::{Endorsement, EndorsementDeserializerLW, SecureShareEndorsement}, error::ModelsError, operation::{ OperationId, OperationIdsDeserializer, OperationIdsSerializer, SecureShareOperation, }, - slot::{Slot, SlotDeserializer, SlotSerializer}, + // slot::{Slot, SlotDeserializer, SlotSerializer}, }; -use massa_hash::{Hash, HashDeserializer}; +// use massa_hash::{Hash, HashDeserializer}; use massa_serialization::{ - DeserializeError, Deserializer, SerializeError, Serializer, U32VarIntDeserializer, - U32VarIntSerializer, U64VarIntDeserializer, U64VarIntSerializer, + // DeserializeError, + Deserializer, + SerializeError, + Serializer, + // U32VarIntDeserializer, + // U32VarIntSerializer, U64VarIntDeserializer, U64VarIntSerializer, }; use massa_signature::{KeyPair, PublicKey, Signature}; -use nom::branch::alt; -use nom::bytes::complete::tag; +// use nom::branch::alt; +// use nom::bytes::complete::tag; use nom::error::context; -use nom::multi::{count, length_count}; -use nom::sequence::{preceded, tuple}; +// use nom::multi::{count, length_count}; +use nom::sequence::tuple; use nom::Parser; use nom::{ error::{ContextError, ParseError}, IResult, }; use serde::{Deserialize, Serialize}; -use serde_with::{DeserializeFromStr, SerializeDisplay}; -use std::collections::HashSet; -use std::convert::TryInto; +// use serde_with::{DeserializeFromStr, SerializeDisplay}; +// use std::collections::HashSet; +// use std::convert::TryInto; use std::fmt::Formatter; -use std::ops::Bound::{Excluded, Included}; -use std::str::FromStr; - -/// Size in bytes of a serialized block ID -const BLOCK_ID_SIZE_BYTES: usize = massa_hash::HASH_SIZE_BYTES; - -/// block id -#[derive( - Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, SerializeDisplay, DeserializeFromStr, -)] -pub struct BlockId(pub Hash); - -impl PreHashed for BlockId {} - -impl Id for BlockId { - fn new(hash: Hash) -> Self { - BlockId(hash) - } - - fn get_hash(&self) -> &Hash { - &self.0 - } -} - -const BLOCKID_PREFIX: char = 'B'; -const BLOCKID_VERSION: u64 = 0; - -impl std::fmt::Display for BlockId { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - let u64_serializer = U64VarIntSerializer::new(); - // might want to allocate the vector with capacity in order to avoid re-allocation - let mut bytes: Vec = Vec::new(); - u64_serializer - .serialize(&BLOCKID_VERSION, &mut bytes) - .map_err(|_| std::fmt::Error)?; - bytes.extend(self.0.to_bytes()); - write!( - f, - "{}{}", - BLOCKID_PREFIX, - bs58::encode(bytes).with_check().into_string() - ) - } -} - -impl std::fmt::Debug for BlockId { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", self) - } -} - -impl FromStr for BlockId { - type Err = ModelsError; - /// ## Example - /// ```rust - /// # use massa_hash::Hash; - /// # use std::str::FromStr; - /// # use massa_models::block::BlockId; - /// # let hash = Hash::compute_from(b"test"); - /// # let block_id = BlockId(hash); - /// let ser = block_id.to_string(); - /// let res_block_id = BlockId::from_str(&ser).unwrap(); - /// assert_eq!(block_id, res_block_id); - /// ``` - fn from_str(s: &str) -> Result { - let mut chars = s.chars(); - match chars.next() { - Some(prefix) if prefix == BLOCKID_PREFIX => { - let data = chars.collect::(); - let decoded_bs58_check = bs58::decode(data) - .with_check(None) - .into_vec() - .map_err(|_| ModelsError::BlockIdParseError)?; - let u64_deserializer = U64VarIntDeserializer::new(Included(0), Included(u64::MAX)); - let (rest, _version) = u64_deserializer - .deserialize::(&decoded_bs58_check[..]) - .map_err(|_| ModelsError::BlockIdParseError)?; - Ok(BlockId(Hash::from_bytes( - rest.try_into() - .map_err(|_| ModelsError::BlockIdParseError)?, - ))) - } - _ => Err(ModelsError::BlockIdParseError), - } - } -} - -impl BlockId { - /// block id to bytes - pub fn to_bytes(&self) -> &[u8; BLOCK_ID_SIZE_BYTES] { - self.0.to_bytes() - } - - /// block id into bytes - pub fn into_bytes(self) -> [u8; BLOCK_ID_SIZE_BYTES] { - self.0.into_bytes() - } - - /// block id from bytes - pub fn from_bytes(data: &[u8; BLOCK_ID_SIZE_BYTES]) -> BlockId { - BlockId(Hash::from_bytes(data)) - } - - /// first bit of the hashed block id - pub fn get_first_bit(&self) -> bool { - self.to_bytes()[0] >> 7 == 1 - } -} - -/// Serializer for `BlockId` -#[derive(Default, Clone)] -pub struct BlockIdSerializer; - -impl BlockIdSerializer { - /// Creates a new serializer for `BlockId` - pub fn new() -> Self { - Self - } -} - -impl Serializer for BlockIdSerializer { - fn serialize(&self, value: &BlockId, buffer: &mut Vec) -> Result<(), SerializeError> { - buffer.extend(value.to_bytes()); - Ok(()) - } -} - -/// Deserializer for `BlockId` -#[derive(Default, Clone)] -pub struct BlockIdDeserializer { - hash_deserializer: HashDeserializer, -} - -impl BlockIdDeserializer { - /// Creates a new deserializer for `BlockId` - pub fn new() -> Self { - Self { - hash_deserializer: HashDeserializer::new(), - } - } -} - -impl Deserializer for BlockIdDeserializer { - fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( - &self, - buffer: &'a [u8], - ) -> IResult<&'a [u8], BlockId, E> { - context("Failed BlockId deserialization", |input| { - let (rest, hash) = self.hash_deserializer.deserialize(input)?; - Ok((rest, BlockId(hash))) - })(buffer) - } -} +// use std::ops::Bound::{Excluded, Included}; +// use std::str::FromStr; +use crate::block_header::{BlockHeader, BlockHeaderDeserializer, SecuredHeader}; +use crate::block_id::BlockId; /// block #[derive(Debug, Clone, Serialize, Deserialize)] @@ -289,7 +144,9 @@ impl Default for BlockSerializer { impl Serializer for BlockSerializer { /// ## Example: /// ```rust - /// use massa_models::{block::{Block, BlockSerializer, BlockId, BlockHeader, BlockHeaderSerializer}, config::THREAD_COUNT, slot::Slot, endorsement::{Endorsement, EndorsementSerializer}, secure_share::SecureShareContent, prehash::PreHashSet}; + /// use massa_models::{block::{Block, BlockSerializer}, config::THREAD_COUNT, slot::Slot, endorsement::{Endorsement, EndorsementSerializer}, secure_share::SecureShareContent, prehash::PreHashSet}; + /// use massa_models::block_header::{BlockHeader, BlockHeaderSerializer}; + /// use massa_models::block_id::{BlockId}; /// use massa_hash::Hash; /// use massa_signature::KeyPair; /// use massa_serialization::{Serializer, Deserializer, DeserializeError}; @@ -371,7 +228,9 @@ impl BlockDeserializer { impl Deserializer for BlockDeserializer { /// ## Example: /// ```rust - /// use massa_models::{block::{Block, BlockSerializer, BlockDeserializer, BlockId,BlockHeader, BlockHeaderSerializer}, config::THREAD_COUNT, slot::Slot, endorsement::{Endorsement, EndorsementSerializer}, secure_share::SecureShareContent, prehash::PreHashSet}; + /// use massa_models::{block::{Block, BlockSerializer, BlockDeserializer}, config::THREAD_COUNT, slot::Slot, endorsement::{Endorsement, EndorsementSerializer}, secure_share::SecureShareContent, prehash::PreHashSet}; + /// use massa_models::block_id::BlockId; + /// use massa_models::block_header::{BlockHeader, BlockHeaderSerializer}; /// use massa_hash::Hash; /// use massa_signature::KeyPair; /// use massa_serialization::{Serializer, Deserializer, DeserializeError}; @@ -493,62 +352,6 @@ impl std::fmt::Display for Block { } } -/// block header -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct BlockHeader { - /// slot - pub slot: Slot, - /// parents - pub parents: Vec, - /// all operations hash - pub operation_merkle_root: Hash, - /// endorsements - pub endorsements: Vec, -} - -// TODO: gh-issue #3398 -#[cfg(any(test, feature = "testing"))] -impl BlockHeader { - fn assert_invariants(&self) -> Result<(), Box> { - if self.slot.period == 0 { - if !self.parents.is_empty() { - return Err("Invariant broken: genesis block with parent(s)".into()); - } - if !self.endorsements.is_empty() { - return Err("Invariant broken: genesis block with endorsement(s)".into()); - } - } else { - if self.parents.len() != crate::config::THREAD_COUNT as usize { - return Err( - "Invariant broken: non-genesis block with incorrect number of parents".into(), - ); - } - if self.endorsements.len() > crate::config::ENDORSEMENT_COUNT as usize { - return Err("Invariant broken: endorsement count too high".into()); - } - - let parent_id = self.parents[self.slot.thread as usize]; - for endo in self.endorsements.iter() { - if endo.content.endorsed_block != parent_id { - return Err("Invariant broken: endorsement doesn't match parent".into()); - } - } - } - - // assert that the endorsement indexes are all unique... - let mut set = HashSet::new(); - for endo in self.endorsements.iter() { - // ...and check signatures + invariants while at it - endo.check_invariants()?; - - if !set.insert(endo.content.index) { - return Err("Endorsement duplicate index found".into()); - } - } - Ok(()) - } -} - // NOTE: TODO // impl Signable for BlockHeader { // fn get_signature_message(&self) -> Result { @@ -561,378 +364,6 @@ impl BlockHeader { // } // } -/// BlockHeader wrapped up alongside verification data -pub type SecuredHeader = SecureShare; - -impl SecuredHeader { - /// gets the header fitness - pub fn get_fitness(&self) -> u64 { - (self.content.endorsements.len() as u64) + 1 - } - // TODO: gh-issue #3398 - #[allow(dead_code)] - #[cfg(any(test, feature = "testing"))] - fn assert_invariants(&self) -> Result<(), Box> { - self.content.assert_invariants()?; - self.verify_signature() - .map_err(|er| format!("{}", er).into()) - } -} - -impl SecureShareContent for BlockHeader {} - -/// Serializer for `BlockHeader` -pub struct BlockHeaderSerializer { - slot_serializer: SlotSerializer, - endorsement_serializer: SecureShareSerializer, - endorsement_content_serializer: EndorsementSerializerLW, - u32_serializer: U32VarIntSerializer, -} - -impl BlockHeaderSerializer { - /// Creates a new `BlockHeaderSerializer` - pub fn new() -> Self { - Self { - slot_serializer: SlotSerializer::new(), - endorsement_serializer: SecureShareSerializer::new(), - u32_serializer: U32VarIntSerializer::new(), - endorsement_content_serializer: EndorsementSerializerLW::new(), - } - } -} - -impl Default for BlockHeaderSerializer { - fn default() -> Self { - Self::new() - } -} - -impl Serializer for BlockHeaderSerializer { - /// ## Example: - /// ```rust - /// use massa_models::block::{BlockId, BlockHeader, BlockHeaderSerializer}; - /// use massa_models::endorsement::{Endorsement, EndorsementSerializer}; - /// use massa_models::secure_share::SecureShareContent; - /// use massa_models::{config::THREAD_COUNT, slot::Slot}; - /// use massa_hash::Hash; - /// use massa_signature::KeyPair; - /// use massa_serialization::Serializer; - /// - /// let keypair = KeyPair::generate(); - /// let parents = (0..THREAD_COUNT) - /// .map(|i| BlockId(Hash::compute_from(&[i]))) - /// .collect(); - /// let header = BlockHeader { - /// slot: Slot::new(1, 1), - /// parents, - /// operation_merkle_root: Hash::compute_from("mno".as_bytes()), - /// endorsements: vec![ - /// Endorsement::new_verifiable( - /// Endorsement { - /// slot: Slot::new(1, 1), - /// index: 1, - /// endorsed_block: BlockId(Hash::compute_from("blk1".as_bytes())), - /// }, - /// EndorsementSerializer::new(), - /// &keypair, - /// ) - /// .unwrap(), - /// Endorsement::new_verifiable( - /// Endorsement { - /// slot: Slot::new(4, 0), - /// index: 3, - /// endorsed_block: BlockId(Hash::compute_from("blk2".as_bytes())), - /// }, - /// EndorsementSerializer::new(), - /// &keypair, - /// ) - /// .unwrap(), - /// ], - /// }; - /// let mut buffer = vec![]; - /// BlockHeaderSerializer::new().serialize(&header, &mut buffer).unwrap(); - /// ``` - fn serialize(&self, value: &BlockHeader, buffer: &mut Vec) -> Result<(), SerializeError> { - self.slot_serializer.serialize(&value.slot, buffer)?; - // parents (note: there should be none if slot period=0) - if value.parents.is_empty() { - buffer.push(0); - } else { - buffer.push(1); - } - for parent_h in value.parents.iter() { - buffer.extend(parent_h.0.to_bytes()); - } - - // operations merkle root - buffer.extend(value.operation_merkle_root.to_bytes()); - - self.u32_serializer.serialize( - &value.endorsements.len().try_into().map_err(|err| { - SerializeError::GeneralError(format!("too many endorsements: {}", err)) - })?, - buffer, - )?; - for endorsement in value.endorsements.iter() { - self.endorsement_serializer.serialize_with( - &self.endorsement_content_serializer, - endorsement, - buffer, - )?; - } - Ok(()) - } -} - -/// Deserializer for `BlockHeader` -pub struct BlockHeaderDeserializer { - slot_deserializer: SlotDeserializer, - endorsement_serializer: EndorsementSerializer, - length_endorsements_deserializer: U32VarIntDeserializer, - hash_deserializer: HashDeserializer, - thread_count: u8, - endorsement_count: u32, -} - -impl BlockHeaderDeserializer { - /// Creates a new `BlockHeaderDeserializerLW` - pub const fn new(thread_count: u8, endorsement_count: u32) -> Self { - Self { - slot_deserializer: SlotDeserializer::new( - (Included(0), Included(u64::MAX)), - (Included(0), Excluded(thread_count)), - ), - endorsement_serializer: EndorsementSerializer::new(), - length_endorsements_deserializer: U32VarIntDeserializer::new( - Included(0), - Included(endorsement_count), - ), - hash_deserializer: HashDeserializer::new(), - thread_count, - endorsement_count, - } - } -} - -impl Deserializer for BlockHeaderDeserializer { - /// ## Example: - /// ```rust - /// use massa_models::block::{BlockId, BlockHeader, BlockHeaderDeserializer, BlockHeaderSerializer}; - /// use massa_models::{config::THREAD_COUNT, slot::Slot, secure_share::SecureShareContent}; - /// use massa_models::endorsement::{Endorsement, EndorsementSerializer}; - /// use massa_hash::Hash; - /// use massa_signature::KeyPair; - /// use massa_serialization::{Serializer, Deserializer, DeserializeError}; - /// - /// let keypair = KeyPair::generate(); - /// let parents: Vec = (0..THREAD_COUNT) - /// .map(|i| BlockId(Hash::compute_from(&[i]))) - /// .collect(); - /// let header = BlockHeader { - /// slot: Slot::new(1, 1), - /// parents: parents.clone(), - /// operation_merkle_root: Hash::compute_from("mno".as_bytes()), - /// endorsements: vec![ - /// Endorsement::new_verifiable( - /// Endorsement { - /// slot: Slot::new(1, 1), - /// index: 0, - /// endorsed_block: parents[1].clone(), - /// }, - /// EndorsementSerializer::new(), - /// &keypair, - /// ) - /// .unwrap(), - /// Endorsement::new_verifiable( - /// Endorsement { - /// slot: Slot::new(1, 1), - /// index: 1, - /// endorsed_block: parents[1].clone(), - /// }, - /// EndorsementSerializer::new(), - /// &keypair, - /// ) - /// .unwrap(), - /// ], - /// }; - /// let mut buffer = vec![]; - /// BlockHeaderSerializer::new().serialize(&header, &mut buffer).unwrap(); - /// let (rest, deserialized_header) = BlockHeaderDeserializer::new(32, 9).deserialize::(&buffer).unwrap(); - /// assert_eq!(rest.len(), 0); - /// let mut buffer2 = Vec::new(); - /// BlockHeaderSerializer::new().serialize(&deserialized_header, &mut buffer2).unwrap(); - /// assert_eq!(buffer, buffer2); - /// ``` - fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( - &self, - buffer: &'a [u8], - ) -> IResult<&'a [u8], BlockHeader, E> { - let (rest, (slot, parents, operation_merkle_root)): (&[u8], (Slot, Vec, Hash)) = - context("Failed BlockHeader deserialization", |input| { - let (rest, (slot, parents)) = tuple(( - context("Failed slot deserialization", |input| { - self.slot_deserializer.deserialize(input) - }), - context( - "Failed parents deserialization", - alt(( - preceded(tag(&[0]), |input| Ok((input, Vec::new()))), - preceded( - tag(&[1]), - count( - context("Failed block_id deserialization", |input| { - self.hash_deserializer - .deserialize(input) - .map(|(rest, hash)| (rest, BlockId(hash))) - }), - self.thread_count as usize, - ), - ), - )), - ), - )) - .parse(input)?; - - // validate the parent/slot invariats before moving on to other fields - if slot.period == 0 && !parents.is_empty() { - return Err(nom::Err::Failure(ContextError::add_context( - rest, - "Genesis block cannot contain parents", - ParseError::from_error_kind(rest, nom::error::ErrorKind::Fail), - ))); - } else if slot.period != 0 && parents.len() != THREAD_COUNT as usize { - return Err(nom::Err::Failure(ContextError::add_context( - rest, - const_format::formatcp!( - "Non-genesis block must have {} parents", - THREAD_COUNT - ), - ParseError::from_error_kind(rest, nom::error::ErrorKind::Fail), - ))); - } - - let (rest, merkle) = context("Failed operation_merkle_root", |input| { - self.hash_deserializer.deserialize(input) - }) - .parse(rest)?; - Ok((rest, (slot, parents, merkle))) - }) - .parse(buffer)?; - - if parents.is_empty() { - let res = BlockHeader { - slot, - parents, - operation_merkle_root, - endorsements: Vec::new(), - }; - - // TODO: gh-issue #3398 - #[cfg(any(test, feature = "testing"))] - res.assert_invariants().unwrap(); - - return Ok(( - &rest[1..], // Because there is 0 endorsements, we have a remaining 0 in rest and we don't need it - res, - )); - } - // Now deser the endorsements (which were light-weight serialized) - let endorsement_deserializer = - SecureShareDeserializer::new(EndorsementDeserializerLW::new( - self.endorsement_count, - slot, - parents[slot.thread as usize], - )); - - let parent_id = parents[slot.thread as usize]; - let (rest, endorsements): (&[u8], Vec>) = context( - "Failed endorsements deserialization", - length_count::<&[u8], SecureShare, u32, E, _, _>( - context("Failed length deserialization", |input| { - self.length_endorsements_deserializer.deserialize(input) - }), - context("Failed endorsement deserialization", |input| { - let (rest, endo) = endorsement_deserializer - .deserialize_with(&self.endorsement_serializer, input)?; - - if endo.content.endorsed_block != parent_id { - return Err(nom::Err::Failure(ContextError::add_context( - rest, - "Endorsement does not match block parents", - ParseError::from_error_kind(rest, nom::error::ErrorKind::Fail), - ))); - } - - Ok((rest, endo)) - }), - ), - ) - .parse(rest)?; - - let mut set = HashSet::new(); - - for end in endorsements.iter() { - if !set.insert(end.content.index) { - return Err(nom::Err::Failure(ContextError::add_context( - rest, - "Duplicate endorsement index found", - ParseError::from_error_kind(rest, nom::error::ErrorKind::Fail), - ))); - } - } - - let header = BlockHeader { - slot, - parents, - operation_merkle_root, - endorsements, - }; - - // TODO: gh-issue #3398 - #[cfg(any(test, feature = "testing"))] - header.assert_invariants().unwrap(); - - Ok((rest, header)) - } -} - -impl std::fmt::Display for BlockHeader { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - writeln!( - f, - "\t(period: {}, thread: {})", - self.slot.period, self.slot.thread, - )?; - writeln!(f, "\tMerkle root: {}", self.operation_merkle_root,)?; - writeln!(f, "\tParents: ")?; - for id in self.parents.iter() { - let str_id = id.to_string(); - writeln!(f, "\t\t{}", str_id)?; - } - if self.parents.is_empty() { - writeln!(f, "No parents found: This is a genesis header")?; - } - writeln!(f, "\tEndorsements:")?; - for ed in self.endorsements.iter() { - writeln!(f, "\t\t-----")?; - writeln!(f, "\t\tId: {}", ed.id)?; - writeln!(f, "\t\tIndex: {}", ed.content.index)?; - writeln!(f, "\t\tEndorsed slot: {}", ed.content.slot)?; - writeln!( - f, - "\t\tEndorser's public key: {}", - ed.content_creator_pub_key - )?; - writeln!(f, "\t\tEndorsed block: {}", ed.content.endorsed_block)?; - writeln!(f, "\t\tSignature: {}", ed.signature)?; - } - if self.endorsements.is_empty() { - writeln!(f, "\tNo endorsements found")?; - } - Ok(()) - } -} - /// Block status within the graph #[derive(Eq, PartialEq, Debug, Deserialize, Serialize)] pub enum BlockGraphStatus { @@ -956,16 +387,19 @@ pub enum BlockGraphStatus { #[cfg(test)] mod test { - use super::*; use crate::{ + block_header::BlockHeaderSerializer, config::{ENDORSEMENT_COUNT, MAX_OPERATIONS_PER_BLOCK, THREAD_COUNT}, endorsement::Endorsement, endorsement::EndorsementSerializer, + slot::Slot, }; + use massa_hash::Hash; use massa_serialization::DeserializeError; use massa_signature::KeyPair; use serial_test::serial; + use std::str::FromStr; #[test] #[serial] diff --git a/massa-models/src/block_header.rs b/massa-models/src/block_header.rs new file mode 100644 index 00000000000..58721fd2af3 --- /dev/null +++ b/massa-models/src/block_header.rs @@ -0,0 +1,453 @@ +use crate::block_id::BlockId; +use crate::config::THREAD_COUNT; +use crate::endorsement::{ + Endorsement, EndorsementDeserializerLW, EndorsementId, EndorsementSerializer, + EndorsementSerializerLW, SecureShareEndorsement, +}; +use crate::secure_share::{ + SecureShare, SecureShareContent, SecureShareDeserializer, SecureShareSerializer, +}; +use crate::slot::{Slot, SlotDeserializer, SlotSerializer}; +use massa_hash::{Hash, HashDeserializer}; +use massa_serialization::{ + Deserializer, SerializeError, Serializer, U32VarIntDeserializer, U32VarIntSerializer, +}; +use nom::branch::alt; +use nom::bytes::complete::tag; +use nom::error::{context, ContextError, ParseError}; +use nom::multi::{count, length_count}; +use nom::sequence::{preceded, tuple}; +use nom::{IResult, Parser}; +use serde::{Deserialize, Serialize}; +use std::collections::Bound::{Excluded, Included}; +use std::collections::HashSet; +use std::fmt::Formatter; + +/// block header +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BlockHeader { + /// slot + pub slot: Slot, + /// parents + pub parents: Vec, + /// all operations hash + pub operation_merkle_root: Hash, + /// endorsements + pub endorsements: Vec, +} + +// TODO: gh-issue #3398 +#[cfg(any(test, feature = "testing"))] +impl BlockHeader { + fn assert_invariants(&self) -> Result<(), Box> { + if self.slot.period == 0 { + if !self.parents.is_empty() { + return Err("Invariant broken: genesis block with parent(s)".into()); + } + if !self.endorsements.is_empty() { + return Err("Invariant broken: genesis block with endorsement(s)".into()); + } + } else { + if self.parents.len() != crate::config::THREAD_COUNT as usize { + return Err( + "Invariant broken: non-genesis block with incorrect number of parents".into(), + ); + } + if self.endorsements.len() > crate::config::ENDORSEMENT_COUNT as usize { + return Err("Invariant broken: endorsement count too high".into()); + } + + let parent_id = self.parents[self.slot.thread as usize]; + for endo in self.endorsements.iter() { + if endo.content.endorsed_block != parent_id { + return Err("Invariant broken: endorsement doesn't match parent".into()); + } + } + } + + // assert that the endorsement indexes are all unique... + let mut set = HashSet::new(); + for endo in self.endorsements.iter() { + // ...and check signatures + invariants while at it + endo.check_invariants()?; + + if !set.insert(endo.content.index) { + return Err("Endorsement duplicate index found".into()); + } + } + Ok(()) + } +} + +/// BlockHeader wrapped up alongside verification data +pub type SecuredHeader = SecureShare; + +impl SecuredHeader { + /// gets the header fitness + pub fn get_fitness(&self) -> u64 { + (self.content.endorsements.len() as u64) + 1 + } + // TODO: gh-issue #3398 + #[allow(dead_code)] + #[cfg(any(test, feature = "testing"))] + pub(crate) fn assert_invariants(&self) -> Result<(), Box> { + self.content.assert_invariants()?; + self.verify_signature() + .map_err(|er| format!("{}", er).into()) + } +} + +impl SecureShareContent for BlockHeader {} + +/// Serializer for `BlockHeader` +pub struct BlockHeaderSerializer { + slot_serializer: SlotSerializer, + endorsement_serializer: SecureShareSerializer, + endorsement_content_serializer: EndorsementSerializerLW, + u32_serializer: U32VarIntSerializer, +} + +impl BlockHeaderSerializer { + /// Creates a new `BlockHeaderSerializer` + pub fn new() -> Self { + Self { + slot_serializer: SlotSerializer::new(), + endorsement_serializer: SecureShareSerializer::new(), + u32_serializer: U32VarIntSerializer::new(), + endorsement_content_serializer: EndorsementSerializerLW::new(), + } + } +} + +impl Default for BlockHeaderSerializer { + fn default() -> Self { + Self::new() + } +} + +impl Serializer for BlockHeaderSerializer { + /// ## Example: + /// ```rust + /// use massa_models::{block_id::BlockId, block_header::BlockHeader, block_header::BlockHeaderSerializer}; + /// use massa_models::endorsement::{Endorsement, EndorsementSerializer}; + /// use massa_models::secure_share::SecureShareContent; + /// use massa_models::{config::THREAD_COUNT, slot::Slot}; + /// use massa_hash::Hash; + /// use massa_signature::KeyPair; + /// use massa_serialization::Serializer; + /// + /// let keypair = KeyPair::generate(); + /// let parents = (0..THREAD_COUNT) + /// .map(|i| BlockId(Hash::compute_from(&[i]))) + /// .collect(); + /// let header = BlockHeader { + /// slot: Slot::new(1, 1), + /// parents, + /// operation_merkle_root: Hash::compute_from("mno".as_bytes()), + /// endorsements: vec![ + /// Endorsement::new_verifiable( + /// Endorsement { + /// slot: Slot::new(1, 1), + /// index: 1, + /// endorsed_block: BlockId(Hash::compute_from("blk1".as_bytes())), + /// }, + /// EndorsementSerializer::new(), + /// &keypair, + /// ) + /// .unwrap(), + /// Endorsement::new_verifiable( + /// Endorsement { + /// slot: Slot::new(4, 0), + /// index: 3, + /// endorsed_block: BlockId(Hash::compute_from("blk2".as_bytes())), + /// }, + /// EndorsementSerializer::new(), + /// &keypair, + /// ) + /// .unwrap(), + /// ], + /// }; + /// let mut buffer = vec![]; + /// BlockHeaderSerializer::new().serialize(&header, &mut buffer).unwrap(); + /// ``` + fn serialize(&self, value: &BlockHeader, buffer: &mut Vec) -> Result<(), SerializeError> { + self.slot_serializer.serialize(&value.slot, buffer)?; + // parents (note: there should be none if slot period=0) + if value.parents.is_empty() { + buffer.push(0); + } else { + buffer.push(1); + } + for parent_h in value.parents.iter() { + buffer.extend(parent_h.0.to_bytes()); + } + + // operations merkle root + buffer.extend(value.operation_merkle_root.to_bytes()); + + self.u32_serializer.serialize( + &value.endorsements.len().try_into().map_err(|err| { + SerializeError::GeneralError(format!("too many endorsements: {}", err)) + })?, + buffer, + )?; + for endorsement in value.endorsements.iter() { + self.endorsement_serializer.serialize_with( + &self.endorsement_content_serializer, + endorsement, + buffer, + )?; + } + Ok(()) + } +} + +/// Deserializer for `BlockHeader` +pub struct BlockHeaderDeserializer { + slot_deserializer: SlotDeserializer, + endorsement_serializer: EndorsementSerializer, + length_endorsements_deserializer: U32VarIntDeserializer, + hash_deserializer: HashDeserializer, + thread_count: u8, + endorsement_count: u32, +} + +impl BlockHeaderDeserializer { + /// Creates a new `BlockHeaderDeserializerLW` + pub const fn new(thread_count: u8, endorsement_count: u32) -> Self { + Self { + slot_deserializer: SlotDeserializer::new( + (Included(0), Included(u64::MAX)), + (Included(0), Excluded(thread_count)), + ), + endorsement_serializer: EndorsementSerializer::new(), + length_endorsements_deserializer: U32VarIntDeserializer::new( + Included(0), + Included(endorsement_count), + ), + hash_deserializer: HashDeserializer::new(), + thread_count, + endorsement_count, + } + } +} + +impl Deserializer for BlockHeaderDeserializer { + /// ## Example: + /// ```rust + /// use massa_models::block_header::{BlockHeader, BlockHeaderDeserializer, BlockHeaderSerializer}; + /// use massa_models::block_id::{BlockId}; + /// use massa_models::{config::THREAD_COUNT, slot::Slot, secure_share::SecureShareContent}; + /// use massa_models::endorsement::{Endorsement, EndorsementSerializer}; + /// use massa_hash::Hash; + /// use massa_signature::KeyPair; + /// use massa_serialization::{Serializer, Deserializer, DeserializeError}; + /// + /// let keypair = KeyPair::generate(); + /// let parents: Vec = (0..THREAD_COUNT) + /// .map(|i| BlockId(Hash::compute_from(&[i]))) + /// .collect(); + /// let header = BlockHeader { + /// slot: Slot::new(1, 1), + /// parents: parents.clone(), + /// operation_merkle_root: Hash::compute_from("mno".as_bytes()), + /// endorsements: vec![ + /// Endorsement::new_verifiable( + /// Endorsement { + /// slot: Slot::new(1, 1), + /// index: 0, + /// endorsed_block: parents[1].clone(), + /// }, + /// EndorsementSerializer::new(), + /// &keypair, + /// ) + /// .unwrap(), + /// Endorsement::new_verifiable( + /// Endorsement { + /// slot: Slot::new(1, 1), + /// index: 1, + /// endorsed_block: parents[1].clone(), + /// }, + /// EndorsementSerializer::new(), + /// &keypair, + /// ) + /// .unwrap(), + /// ], + /// }; + /// let mut buffer = vec![]; + /// BlockHeaderSerializer::new().serialize(&header, &mut buffer).unwrap(); + /// let (rest, deserialized_header) = BlockHeaderDeserializer::new(32, 9).deserialize::(&buffer).unwrap(); + /// assert_eq!(rest.len(), 0); + /// let mut buffer2 = Vec::new(); + /// BlockHeaderSerializer::new().serialize(&deserialized_header, &mut buffer2).unwrap(); + /// assert_eq!(buffer, buffer2); + /// ``` + fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( + &self, + buffer: &'a [u8], + ) -> IResult<&'a [u8], BlockHeader, E> { + let (rest, (slot, parents, operation_merkle_root)): (&[u8], (Slot, Vec, Hash)) = + context("Failed BlockHeader deserialization", |input| { + let (rest, (slot, parents)) = tuple(( + context("Failed slot deserialization", |input| { + self.slot_deserializer.deserialize(input) + }), + context( + "Failed parents deserialization", + alt(( + preceded(tag(&[0]), |input| Ok((input, Vec::new()))), + preceded( + tag(&[1]), + count( + context("Failed block_id deserialization", |input| { + self.hash_deserializer + .deserialize(input) + .map(|(rest, hash)| (rest, BlockId(hash))) + }), + self.thread_count as usize, + ), + ), + )), + ), + )) + .parse(input)?; + + // validate the parent/slot invariats before moving on to other fields + if slot.period == 0 && !parents.is_empty() { + return Err(nom::Err::Failure(ContextError::add_context( + rest, + "Genesis block cannot contain parents", + ParseError::from_error_kind(rest, nom::error::ErrorKind::Fail), + ))); + } else if slot.period != 0 && parents.len() != THREAD_COUNT as usize { + return Err(nom::Err::Failure(ContextError::add_context( + rest, + const_format::formatcp!( + "Non-genesis block must have {} parents", + THREAD_COUNT + ), + ParseError::from_error_kind(rest, nom::error::ErrorKind::Fail), + ))); + } + + let (rest, merkle) = context("Failed operation_merkle_root", |input| { + self.hash_deserializer.deserialize(input) + }) + .parse(rest)?; + Ok((rest, (slot, parents, merkle))) + }) + .parse(buffer)?; + + if parents.is_empty() { + let res = BlockHeader { + slot, + parents, + operation_merkle_root, + endorsements: Vec::new(), + }; + + // TODO: gh-issue #3398 + #[cfg(any(test, feature = "testing"))] + res.assert_invariants().unwrap(); + + return Ok(( + &rest[1..], // Because there is 0 endorsements, we have a remaining 0 in rest and we don't need it + res, + )); + } + // Now deser the endorsements (which were light-weight serialized) + let endorsement_deserializer = + SecureShareDeserializer::new(EndorsementDeserializerLW::new( + self.endorsement_count, + slot, + parents[slot.thread as usize], + )); + + let parent_id = parents[slot.thread as usize]; + let (rest, endorsements): (&[u8], Vec>) = context( + "Failed endorsements deserialization", + length_count::<&[u8], SecureShare, u32, E, _, _>( + context("Failed length deserialization", |input| { + self.length_endorsements_deserializer.deserialize(input) + }), + context("Failed endorsement deserialization", |input| { + let (rest, endo) = endorsement_deserializer + .deserialize_with(&self.endorsement_serializer, input)?; + + if endo.content.endorsed_block != parent_id { + return Err(nom::Err::Failure(ContextError::add_context( + rest, + "Endorsement does not match block parents", + ParseError::from_error_kind(rest, nom::error::ErrorKind::Fail), + ))); + } + + Ok((rest, endo)) + }), + ), + ) + .parse(rest)?; + + let mut set = HashSet::new(); + + for end in endorsements.iter() { + if !set.insert(end.content.index) { + return Err(nom::Err::Failure(ContextError::add_context( + rest, + "Duplicate endorsement index found", + ParseError::from_error_kind(rest, nom::error::ErrorKind::Fail), + ))); + } + } + + let header = BlockHeader { + slot, + parents, + operation_merkle_root, + endorsements, + }; + + // TODO: gh-issue #3398 + #[cfg(any(test, feature = "testing"))] + header.assert_invariants().unwrap(); + + Ok((rest, header)) + } +} + +impl std::fmt::Display for BlockHeader { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + writeln!( + f, + "\t(period: {}, thread: {})", + self.slot.period, self.slot.thread, + )?; + writeln!(f, "\tMerkle root: {}", self.operation_merkle_root,)?; + writeln!(f, "\tParents: ")?; + for id in self.parents.iter() { + let str_id = id.to_string(); + writeln!(f, "\t\t{}", str_id)?; + } + if self.parents.is_empty() { + writeln!(f, "No parents found: This is a genesis header")?; + } + writeln!(f, "\tEndorsements:")?; + for ed in self.endorsements.iter() { + writeln!(f, "\t\t-----")?; + writeln!(f, "\t\tId: {}", ed.id)?; + writeln!(f, "\t\tIndex: {}", ed.content.index)?; + writeln!(f, "\t\tEndorsed slot: {}", ed.content.slot)?; + writeln!( + f, + "\t\tEndorser's public key: {}", + ed.content_creator_pub_key + )?; + writeln!(f, "\t\tEndorsed block: {}", ed.content.endorsed_block)?; + writeln!(f, "\t\tSignature: {}", ed.signature)?; + } + if self.endorsements.is_empty() { + writeln!(f, "\tNo endorsements found")?; + } + Ok(()) + } +} diff --git a/massa-models/src/block_id.rs b/massa-models/src/block_id.rs new file mode 100644 index 00000000000..77640407d4d --- /dev/null +++ b/massa-models/src/block_id.rs @@ -0,0 +1,165 @@ +use crate::error::ModelsError; +use crate::prehash::PreHashed; +use crate::secure_share::Id; +use massa_hash::{Hash, HashDeserializer}; +use massa_serialization::{ + DeserializeError, Deserializer, SerializeError, Serializer, U64VarIntDeserializer, + U64VarIntSerializer, +}; +use nom::error::{context, ContextError, ParseError}; +use nom::IResult; +use serde_with::{DeserializeFromStr, SerializeDisplay}; +use std::collections::Bound::Included; +use std::convert::TryInto; +use std::str::FromStr; + +/// Size in bytes of a serialized block ID +const BLOCK_ID_SIZE_BYTES: usize = massa_hash::HASH_SIZE_BYTES; + +/// block id +#[derive( + Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, SerializeDisplay, DeserializeFromStr, +)] +pub struct BlockId(pub Hash); + +impl PreHashed for BlockId {} + +impl Id for BlockId { + fn new(hash: Hash) -> Self { + BlockId(hash) + } + + fn get_hash(&self) -> &Hash { + &self.0 + } +} + +const BLOCKID_PREFIX: char = 'B'; +const BLOCKID_VERSION: u64 = 0; + +impl std::fmt::Display for BlockId { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + let u64_serializer = U64VarIntSerializer::new(); + // might want to allocate the vector with capacity in order to avoid re-allocation + let mut bytes: Vec = Vec::new(); + u64_serializer + .serialize(&BLOCKID_VERSION, &mut bytes) + .map_err(|_| std::fmt::Error)?; + bytes.extend(self.0.to_bytes()); + write!( + f, + "{}{}", + BLOCKID_PREFIX, + bs58::encode(bytes).with_check().into_string() + ) + } +} + +impl std::fmt::Debug for BlockId { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{}", self) + } +} + +impl FromStr for BlockId { + type Err = ModelsError; + /// ## Example + /// ```rust + /// # use massa_hash::Hash; + /// # use std::str::FromStr; + /// # use massa_models::block_id::BlockId; + /// # let hash = Hash::compute_from(b"test"); + /// # let block_id = BlockId(hash); + /// let ser = block_id.to_string(); + /// let res_block_id = BlockId::from_str(&ser).unwrap(); + /// assert_eq!(block_id, res_block_id); + /// ``` + fn from_str(s: &str) -> Result { + let mut chars = s.chars(); + match chars.next() { + Some(prefix) if prefix == BLOCKID_PREFIX => { + let data = chars.collect::(); + let decoded_bs58_check = bs58::decode(data) + .with_check(None) + .into_vec() + .map_err(|_| ModelsError::BlockIdParseError)?; + let u64_deserializer = U64VarIntDeserializer::new(Included(0), Included(u64::MAX)); + let (rest, _version) = u64_deserializer + .deserialize::(&decoded_bs58_check[..]) + .map_err(|_| ModelsError::BlockIdParseError)?; + Ok(BlockId(Hash::from_bytes( + rest.try_into() + .map_err(|_| ModelsError::BlockIdParseError)?, + ))) + } + _ => Err(ModelsError::BlockIdParseError), + } + } +} + +impl BlockId { + /// block id to bytes + pub fn to_bytes(&self) -> &[u8; BLOCK_ID_SIZE_BYTES] { + self.0.to_bytes() + } + + /// block id into bytes + pub fn into_bytes(self) -> [u8; BLOCK_ID_SIZE_BYTES] { + self.0.into_bytes() + } + + /// block id from bytes + pub fn from_bytes(data: &[u8; BLOCK_ID_SIZE_BYTES]) -> BlockId { + BlockId(Hash::from_bytes(data)) + } + + /// first bit of the hashed block id + pub fn get_first_bit(&self) -> bool { + self.to_bytes()[0] >> 7 == 1 + } +} + +/// Serializer for `BlockId` +#[derive(Default, Clone)] +pub struct BlockIdSerializer; + +impl BlockIdSerializer { + /// Creates a new serializer for `BlockId` + pub fn new() -> Self { + Self + } +} + +impl Serializer for BlockIdSerializer { + fn serialize(&self, value: &BlockId, buffer: &mut Vec) -> Result<(), SerializeError> { + buffer.extend(value.to_bytes()); + Ok(()) + } +} + +/// Deserializer for `BlockId` +#[derive(Default, Clone)] +pub struct BlockIdDeserializer { + hash_deserializer: HashDeserializer, +} + +impl BlockIdDeserializer { + /// Creates a new deserializer for `BlockId` + pub fn new() -> Self { + Self { + hash_deserializer: HashDeserializer::new(), + } + } +} + +impl Deserializer for BlockIdDeserializer { + fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>( + &self, + buffer: &'a [u8], + ) -> IResult<&'a [u8], BlockId, E> { + context("Failed BlockId deserialization", |input| { + let (rest, hash) = self.hash_deserializer.deserialize(input)?; + Ok((rest, BlockId(hash))) + })(buffer) + } +} diff --git a/massa-models/src/clique.rs b/massa-models/src/clique.rs index 0280827ca49..946084c766b 100644 --- a/massa-models/src/clique.rs +++ b/massa-models/src/clique.rs @@ -17,7 +17,7 @@ use nom::sequence::tuple; use nom::{IResult, Parser}; use serde::{Deserialize, Serialize}; -use crate::block::BlockId; +use crate::block_id::BlockId; use crate::prehash::PreHashSet; use std::ops::Bound::{Excluded, Included}; @@ -64,7 +64,7 @@ impl Serializer for CliqueSerializer { /// ## Example /// ```rust /// # use massa_models::clique::{Clique, CliqueSerializer}; - /// # use massa_models::block::BlockId; + /// # use massa_models::block_id::BlockId; /// # use massa_hash::Hash; /// # use std::str::FromStr; /// # use massa_serialization::Serializer; @@ -117,7 +117,7 @@ impl Deserializer for CliqueDeserializer { /// ## Example /// ```rust /// # use massa_models::clique::{Clique, CliqueDeserializer, CliqueSerializer}; - /// # use massa_models::block::BlockId; + /// # use massa_models::block_id::BlockId; /// # use massa_hash::Hash; /// # use std::str::FromStr; /// # use massa_serialization::{Serializer, Deserializer, DeserializeError}; diff --git a/massa-models/src/composite.rs b/massa-models/src/composite.rs index fd6131ae10e..c0497e79c17 100644 --- a/massa-models/src/composite.rs +++ b/massa-models/src/composite.rs @@ -1,7 +1,7 @@ // Copyright (c) 2022 MASSA LABS use crate::prehash::PreHashMap; -use crate::{address::Address, block::BlockId, operation::SecureShareOperation}; +use crate::{address::Address, block_id::BlockId, operation::SecureShareOperation}; use massa_signature::{PublicKey, Signature}; use serde::{Deserialize, Serialize}; use std::fmt::Display; diff --git a/massa-models/src/endorsement.rs b/massa-models/src/endorsement.rs index 0bc554e1b19..d64a248aeba 100644 --- a/massa-models/src/endorsement.rs +++ b/massa-models/src/endorsement.rs @@ -3,7 +3,7 @@ use crate::prehash::PreHashed; use crate::secure_share::{Id, SecureShare, SecureShareContent}; use crate::slot::{Slot, SlotDeserializer, SlotSerializer}; -use crate::{block::BlockId, error::ModelsError}; +use crate::{block_id::BlockId, error::ModelsError}; use massa_hash::{Hash, HashDeserializer}; use massa_serialization::{ DeserializeError, Deserializer, SerializeError, Serializer, U32VarIntDeserializer, @@ -194,7 +194,7 @@ impl Default for EndorsementSerializer { impl Serializer for EndorsementSerializer { /// ## Example: /// ```rust - /// use massa_models::{slot::Slot, block::BlockId, endorsement::{Endorsement, EndorsementSerializer}}; + /// use massa_models::{slot::Slot, block_id::BlockId, endorsement::{Endorsement, EndorsementSerializer}}; /// use massa_serialization::Serializer; /// use massa_hash::Hash; /// @@ -241,7 +241,7 @@ impl EndorsementDeserializer { impl Deserializer for EndorsementDeserializer { /// ## Example: /// ```rust - /// use massa_models::{slot::Slot, block::BlockId, endorsement::{Endorsement, EndorsementSerializer, EndorsementDeserializer}}; + /// use massa_models::{slot::Slot, block_id::BlockId, endorsement::{Endorsement, EndorsementSerializer, EndorsementDeserializer}}; /// use massa_serialization::{Serializer, Deserializer, DeserializeError}; /// use massa_hash::Hash; /// @@ -310,7 +310,7 @@ impl Default for EndorsementSerializerLW { impl Serializer for EndorsementSerializerLW { /// ## Example: /// ```rust - /// use massa_models::{slot::Slot, block::BlockId, endorsement::{Endorsement, EndorsementSerializerLW}}; + /// use massa_models::{slot::Slot, block_id::BlockId, endorsement::{Endorsement, EndorsementSerializerLW}}; /// use massa_serialization::Serializer; /// use massa_hash::Hash; /// @@ -352,7 +352,7 @@ impl EndorsementDeserializerLW { impl Deserializer for EndorsementDeserializerLW { /// ## Example: /// ```rust - /// use massa_models::{slot::Slot, block::BlockId, endorsement::{Endorsement, EndorsementSerializerLW, EndorsementDeserializerLW}}; + /// use massa_models::{slot::Slot, block_id::BlockId, endorsement::{Endorsement, EndorsementSerializerLW, EndorsementDeserializerLW}}; /// use massa_serialization::{Serializer, Deserializer, DeserializeError}; /// use massa_hash::Hash; /// diff --git a/massa-models/src/ledger.rs b/massa-models/src/ledger.rs index 1f93b7c93af..115abdbd856 100644 --- a/massa-models/src/ledger.rs +++ b/massa-models/src/ledger.rs @@ -49,10 +49,10 @@ impl LedgerDataSerializer { impl Serializer for LedgerDataSerializer { /// ## Example: /// ```rust - /// use massa_models::ledger_models::{LedgerData, LedgerDataSerializer}; /// use massa_models::amount::Amount; /// use massa_serialization::Serializer; /// use std::str::FromStr; + /// use massa_models::ledger::{LedgerData, LedgerDataSerializer}; /// /// let ledger_data = LedgerData { /// balance: Amount::from_str("1349").unwrap(), @@ -92,10 +92,10 @@ impl Default for LedgerDataDeserializer { impl Deserializer for LedgerDataDeserializer { /// ## Example: /// ```rust - /// use massa_models::ledger_models::{LedgerData, LedgerDataDeserializer, LedgerDataSerializer}; /// use massa_models::amount::Amount; /// use massa_serialization::{Serializer, Deserializer, DeserializeError}; /// use std::str::FromStr; + /// use massa_models::ledger::{LedgerData, LedgerDataDeserializer, LedgerDataSerializer}; /// /// let ledger_data = LedgerData { /// balance: Amount::from_str("1349").unwrap(), @@ -193,9 +193,9 @@ impl LedgerChangeSerializer { impl Serializer for LedgerChangeSerializer { /// ## Example /// ```rust - /// use massa_models::{address::Address, amount::Amount, ledger_models::LedgerChangeSerializer}; + /// use massa_models::{address::Address, amount::Amount}; /// use std::str::FromStr; - /// use massa_models::ledger_models::LedgerChange; + /// use massa_models::ledger::{LedgerChange, LedgerChangeSerializer}; /// use massa_serialization::Serializer; /// let ledger_change = LedgerChange { /// balance_delta: Amount::from_str("1149").unwrap(), @@ -238,9 +238,9 @@ impl Default for LedgerChangeDeserializer { impl Deserializer for LedgerChangeDeserializer { /// ## Example /// ```rust - /// use massa_models::{address::Address, amount::Amount, ledger_models::{LedgerChangeSerializer, LedgerChangeDeserializer}}; + /// use massa_models::{address::Address, amount::Amount}; /// use std::str::FromStr; - /// use massa_models::ledger_models::LedgerChange; + /// use massa_models::ledger::{LedgerChange, LedgerChangeDeserializer, LedgerChangeSerializer}; /// use massa_serialization::{Serializer, Deserializer, DeserializeError}; /// let ledger_change = LedgerChange { /// balance_delta: Amount::from_str("1149").unwrap(), @@ -377,9 +377,9 @@ impl LedgerChangesDeserializer { impl Deserializer for LedgerChangesDeserializer { /// ## Example /// ```rust - /// # use massa_models::{address::Address, amount::Amount, ledger_models::{LedgerChangesSerializer, LedgerChangesDeserializer, LedgerChangeSerializer, LedgerChangeDeserializer}}; + /// # use massa_models::{address::Address, amount::Amount}; /// # use std::str::FromStr; - /// # use massa_models::ledger_models::{LedgerChanges, LedgerChange}; + /// use massa_models::ledger::{LedgerChange, LedgerChanges, LedgerChangesDeserializer, LedgerChangeSerializer, LedgerChangesSerializer}; /// # use massa_serialization::{Serializer, Deserializer, DeserializeError}; /// # let ledger_changes = LedgerChanges(vec![ /// # ( diff --git a/massa-models/src/lib.rs b/massa-models/src/lib.rs index 117e812ce65..9298e92ba47 100644 --- a/massa-models/src/lib.rs +++ b/massa-models/src/lib.rs @@ -15,8 +15,12 @@ pub mod active_block; pub mod address; /// amount related structures pub mod amount; -/// block-related structures +/// block structure pub mod block; +/// block-related structure: block_header +pub mod block_header; +/// block-related structure: block_id +pub mod block_id; /// clique pub mod clique; /// various structures diff --git a/massa-models/src/output_event.rs b/massa-models/src/output_event.rs index 3a2dc851ee0..924b3927bdb 100644 --- a/massa-models/src/output_event.rs +++ b/massa-models/src/output_event.rs @@ -1,4 +1,4 @@ -use crate::{address::Address, block::BlockId, operation::OperationId, slot::Slot}; +use crate::{address::Address, block_id::BlockId, operation::OperationId, slot::Slot}; use serde::{Deserialize, Serialize}; use std::{collections::VecDeque, fmt::Display}; diff --git a/massa-models/src/secure_share.rs b/massa-models/src/secure_share.rs index 50fc393bf6c..40ca8475c37 100644 --- a/massa-models/src/secure_share.rs +++ b/massa-models/src/secure_share.rs @@ -316,7 +316,8 @@ where Deser: Deserializer, { /// ``` - /// # use massa_models::{block::BlockId, endorsement::{Endorsement, EndorsementSerializer, EndorsementDeserializer}, slot::Slot, secure_share::{SecureShare, SecureShareSerializer, SecureShareDeserializer, SecureShareContent}}; + /// # use massa_models::{endorsement::{Endorsement, EndorsementSerializer, EndorsementDeserializer}, slot::Slot, secure_share::{SecureShare, SecureShareSerializer, SecureShareDeserializer, SecureShareContent}}; + /// use massa_models::block_id::BlockId; /// # use massa_serialization::{Deserializer, Serializer, DeserializeError, U16VarIntSerializer, U16VarIntDeserializer}; /// # use massa_signature::KeyPair; /// # use std::ops::Bound::Included; diff --git a/massa-network-exports/src/commands.rs b/massa-network-exports/src/commands.rs index 3062ed5c827..7187fb4aad6 100644 --- a/massa-network-exports/src/commands.rs +++ b/massa-network-exports/src/commands.rs @@ -71,7 +71,8 @@ use crate::{BootstrapPeers, ConnectionClosureReason, Peers}; use massa_models::{ - block::{BlockId, SecuredHeader}, + block_header::SecuredHeader, + block_id::BlockId, composite::PubkeySig, endorsement::SecureShareEndorsement, node::NodeId, diff --git a/massa-network-exports/src/network_controller.rs b/massa-network-exports/src/network_controller.rs index c948e315134..188018df383 100644 --- a/massa-network-exports/src/network_controller.rs +++ b/massa-network-exports/src/network_controller.rs @@ -6,7 +6,8 @@ use crate::{ BlockInfoReply, BootstrapPeers, NetworkCommand, NetworkEvent, Peers, }; use massa_models::{ - block::{BlockId, SecuredHeader}, + block_header::SecuredHeader, + block_id::BlockId, composite::PubkeySig, endorsement::SecureShareEndorsement, node::NodeId, diff --git a/massa-network-worker/src/messages.rs b/massa-network-worker/src/messages.rs index 5485e6a6a4b..31fef1ddcfc 100644 --- a/massa-network-worker/src/messages.rs +++ b/massa-network-worker/src/messages.rs @@ -2,7 +2,8 @@ use massa_hash::HashDeserializer; use massa_models::{ - block::{BlockHeader, BlockHeaderDeserializer, BlockId, SecuredHeader}, + block_header::{BlockHeader, BlockHeaderDeserializer, SecuredHeader}, + block_id::BlockId, config::HANDSHAKE_RANDOMNESS_SIZE_BYTES, endorsement::{Endorsement, EndorsementDeserializer, SecureShareEndorsement}, operation::{ diff --git a/massa-network-worker/src/network_cmd_impl.rs b/massa-network-worker/src/network_cmd_impl.rs index 4e1752a5ca1..2c937f0a4ad 100644 --- a/massa-network-worker/src/network_cmd_impl.rs +++ b/massa-network-worker/src/network_cmd_impl.rs @@ -24,7 +24,8 @@ use futures::{stream::FuturesUnordered, StreamExt}; use massa_hash::Hash; use massa_logging::massa_trace; use massa_models::{ - block::{BlockId, SecuredHeader}, + block_header::SecuredHeader, + block_id::BlockId, composite::PubkeySig, endorsement::SecureShareEndorsement, node::NodeId, diff --git a/massa-network-worker/src/network_event.rs b/massa-network-worker/src/network_event.rs index 1b936d3d073..61e95d9dcff 100644 --- a/massa-network-worker/src/network_event.rs +++ b/massa-network-worker/src/network_event.rs @@ -80,7 +80,8 @@ pub mod event_impl { use crate::network_worker::NetworkWorker; use massa_logging::massa_trace; use massa_models::{ - block::{BlockId, SecuredHeader}, + block_header::SecuredHeader, + block_id::BlockId, endorsement::SecureShareEndorsement, node::NodeId, operation::{OperationPrefixIds, SecureShareOperation}, diff --git a/massa-network-worker/src/tests/scenarios.rs b/massa-network-worker/src/tests/scenarios.rs index 27fb42195a3..bf9f03b37e7 100644 --- a/massa-network-worker/src/tests/scenarios.rs +++ b/massa-network-worker/src/tests/scenarios.rs @@ -22,7 +22,7 @@ use massa_models::config::{ MAX_OPERATION_DATASTORE_VALUE_LENGTH, MAX_PARAMETERS_SIZE, THREAD_COUNT, }; use massa_models::{ - block::BlockId, + block_id::BlockId, endorsement::{Endorsement, EndorsementSerializer}, node::NodeId, secure_share::SecureShareContent, diff --git a/massa-network-worker/src/tests/tools.rs b/massa-network-worker/src/tests/tools.rs index 7400fc0683a..b8537922cca 100644 --- a/massa-network-worker/src/tests/tools.rs +++ b/massa-network-worker/src/tests/tools.rs @@ -15,7 +15,7 @@ use massa_models::secure_share::SecureShareContent; use massa_models::{ address::Address, amount::Amount, - block::BlockId, + block_id::BlockId, operation::{Operation, OperationSerializer, OperationType, SecureShareOperation}, version::Version, }; diff --git a/massa-pool-exports/src/controller_traits.rs b/massa-pool-exports/src/controller_traits.rs index bef47bf3022..b07711f67f9 100644 --- a/massa-pool-exports/src/controller_traits.rs +++ b/massa-pool-exports/src/controller_traits.rs @@ -1,7 +1,7 @@ // Copyright (c) 2022 MASSA LABS use massa_models::{ - block::BlockId, endorsement::EndorsementId, operation::OperationId, slot::Slot, + block_id::BlockId, endorsement::EndorsementId, operation::OperationId, slot::Slot, }; use massa_storage::Storage; diff --git a/massa-pool-exports/src/test_exports/mock.rs b/massa-pool-exports/src/test_exports/mock.rs index 8f55592e17e..c45d2d89a98 100644 --- a/massa-pool-exports/src/test_exports/mock.rs +++ b/massa-pool-exports/src/test_exports/mock.rs @@ -6,7 +6,7 @@ use std::sync::{ }; use massa_models::{ - block::BlockId, endorsement::EndorsementId, operation::OperationId, slot::Slot, + block_id::BlockId, endorsement::EndorsementId, operation::OperationId, slot::Slot, }; use massa_storage::Storage; use massa_time::MassaTime; diff --git a/massa-pool-worker/src/controller_impl.rs b/massa-pool-worker/src/controller_impl.rs index 67254720bc7..e09ce8862d0 100644 --- a/massa-pool-worker/src/controller_impl.rs +++ b/massa-pool-worker/src/controller_impl.rs @@ -3,7 +3,7 @@ //! Pool controller implementation use massa_models::{ - block::BlockId, endorsement::EndorsementId, operation::OperationId, slot::Slot, + block_id::BlockId, endorsement::EndorsementId, operation::OperationId, slot::Slot, }; use massa_pool_exports::{PoolConfig, PoolController, PoolManager}; use massa_storage::Storage; diff --git a/massa-pool-worker/src/endorsement_pool.rs b/massa-pool-worker/src/endorsement_pool.rs index 80f1e7a57ef..3aa6f40c400 100644 --- a/massa-pool-worker/src/endorsement_pool.rs +++ b/massa-pool-worker/src/endorsement_pool.rs @@ -1,7 +1,7 @@ //! Copyright (c) 2022 MASSA LABS use massa_models::{ - block::BlockId, + block_id::BlockId, endorsement::EndorsementId, prehash::{CapacityAllocator, PreHashSet}, slot::Slot, diff --git a/massa-pool-worker/src/tests/tools.rs b/massa-pool-worker/src/tests/tools.rs index 5289ba491c3..130d0f6beb5 100644 --- a/massa-pool-worker/src/tests/tools.rs +++ b/massa-pool-worker/src/tests/tools.rs @@ -8,7 +8,7 @@ use massa_hash::Hash; use massa_models::{ address::Address, amount::Amount, - block::BlockId, + block_id::BlockId, endorsement::{Endorsement, EndorsementSerializer, SecureShareEndorsement}, operation::{Operation, OperationSerializer, OperationType, SecureShareOperation}, secure_share::SecureShareContent, diff --git a/massa-protocol-exports/src/protocol_controller.rs b/massa-protocol-exports/src/protocol_controller.rs index e6a52864b6c..18e594c5905 100644 --- a/massa-protocol-exports/src/protocol_controller.rs +++ b/massa-protocol-exports/src/protocol_controller.rs @@ -5,8 +5,7 @@ use massa_logging::massa_trace; use massa_models::prehash::{PreHashMap, PreHashSet}; use massa_models::{ - block::{BlockId, SecuredHeader}, - endorsement::EndorsementId, + block_header::SecuredHeader, block_id::BlockId, endorsement::EndorsementId, operation::OperationId, }; use massa_network_exports::NetworkEventReceiver; diff --git a/massa-protocol-exports/src/test_exports/mock.rs b/massa-protocol-exports/src/test_exports/mock.rs index b38436b1606..8e159a73bf7 100644 --- a/massa-protocol-exports/src/test_exports/mock.rs +++ b/massa-protocol-exports/src/test_exports/mock.rs @@ -1,7 +1,7 @@ // Copyright (c) 2022 MASSA LABS use crate::{ProtocolCommand, ProtocolCommandSender}; -use massa_models::block::BlockId; +use massa_models::block_id::BlockId; use massa_time::MassaTime; use tokio::{sync::mpsc, time::sleep}; diff --git a/massa-protocol-exports/src/tests/mock_network_controller.rs b/massa-protocol-exports/src/tests/mock_network_controller.rs index 498a87a0ae0..da87b32cd48 100644 --- a/massa-protocol-exports/src/tests/mock_network_controller.rs +++ b/massa-protocol-exports/src/tests/mock_network_controller.rs @@ -1,8 +1,7 @@ // Copyright (c) 2022 MASSA LABS use massa_models::{ - block::{BlockId, SecuredHeader}, - endorsement::SecureShareEndorsement, + block_header::SecuredHeader, block_id::BlockId, endorsement::SecureShareEndorsement, }; use massa_models::{ config::CHANNEL_SIZE, diff --git a/massa-protocol-exports/src/tests/tools.rs b/massa-protocol-exports/src/tests/tools.rs index 04f2f2b16a5..bf463cb6fa2 100644 --- a/massa-protocol-exports/src/tests/tools.rs +++ b/massa-protocol-exports/src/tests/tools.rs @@ -9,9 +9,9 @@ use massa_models::secure_share::SecureShareContent; use massa_models::{ address::Address, amount::Amount, - block::{ - Block, BlockHeader, BlockHeaderSerializer, BlockId, BlockSerializer, SecureShareBlock, - }, + block::{Block, BlockSerializer, SecureShareBlock}, + block_header::{BlockHeader, BlockHeaderSerializer}, + block_id::BlockId, endorsement::{Endorsement, EndorsementSerializerLW, SecureShareEndorsement}, operation::{Operation, OperationType, SecureShareOperation}, slot::Slot, diff --git a/massa-protocol-worker/src/node_info.rs b/massa-protocol-worker/src/node_info.rs index a47c6812d3c..5abae7c746d 100644 --- a/massa-protocol-worker/src/node_info.rs +++ b/massa-protocol-worker/src/node_info.rs @@ -8,7 +8,7 @@ use massa_models::operation::OperationPrefixId; use massa_models::prehash::{CapacityAllocator, PreHashMap}; -use massa_models::{block::BlockId, endorsement::EndorsementId}; +use massa_models::{block_id::BlockId, endorsement::EndorsementId}; use massa_protocol_exports::ProtocolConfig; use tokio::time::Instant; diff --git a/massa-protocol-worker/src/protocol_network.rs b/massa-protocol-worker/src/protocol_network.rs index 011a9d68e80..52acc97cb07 100644 --- a/massa-protocol-worker/src/protocol_network.rs +++ b/massa-protocol-worker/src/protocol_network.rs @@ -9,8 +9,9 @@ use crate::protocol_worker::ProtocolWorker; use massa_hash::{Hash, HASH_SIZE_BYTES}; use massa_logging::massa_trace; use massa_models::{ - block::Block, - block::{BlockId, BlockSerializer, SecuredHeader}, + block::{Block, BlockSerializer}, + block_header::SecuredHeader, + block_id::BlockId, node::NodeId, operation::{OperationId, SecureShareOperation}, prehash::{CapacityAllocator, PreHashSet}, diff --git a/massa-protocol-worker/src/protocol_worker.rs b/massa-protocol-worker/src/protocol_worker.rs index 77ebe195eee..e63924a0df4 100644 --- a/massa-protocol-worker/src/protocol_worker.rs +++ b/massa-protocol-worker/src/protocol_worker.rs @@ -12,7 +12,8 @@ use massa_models::secure_share::Id; use massa_models::slot::Slot; use massa_models::timeslots::get_block_slot_timestamp; use massa_models::{ - block::{BlockId, SecuredHeader}, + block_header::SecuredHeader, + block_id::BlockId, endorsement::{EndorsementId, SecureShareEndorsement}, node::NodeId, operation::OperationPrefixId, diff --git a/massa-protocol-worker/src/tests/ask_block_scenarios.rs b/massa-protocol-worker/src/tests/ask_block_scenarios.rs index d5ce19d7656..8e40285da15 100644 --- a/massa-protocol-worker/src/tests/ask_block_scenarios.rs +++ b/massa-protocol-worker/src/tests/ask_block_scenarios.rs @@ -3,7 +3,7 @@ use super::tools::protocol_test; use massa_consensus_exports::test_exports::MockConsensusControllerMessage; use massa_models::prehash::PreHashSet; -use massa_models::{block::BlockId, slot::Slot}; +use massa_models::{block_id::BlockId, slot::Slot}; use massa_network_exports::{AskForBlocksInfo, BlockInfoReply, NetworkCommand}; use massa_protocol_exports::tests::tools; use massa_protocol_exports::tests::tools::{asked_list, assert_hash_asked_to_node}; diff --git a/massa-protocol-worker/src/tests/ban_nodes_scenarios.rs b/massa-protocol-worker/src/tests/ban_nodes_scenarios.rs index 422794d2acd..b3a15230cc6 100644 --- a/massa-protocol-worker/src/tests/ban_nodes_scenarios.rs +++ b/massa-protocol-worker/src/tests/ban_nodes_scenarios.rs @@ -6,7 +6,7 @@ use massa_hash::Hash; use massa_models::operation::OperationId; use massa_models::prehash::PreHashSet; use massa_models::secure_share::Id; -use massa_models::{block::BlockId, slot::Slot}; +use massa_models::{block_id::BlockId, slot::Slot}; use massa_network_exports::{BlockInfoReply, NetworkCommand}; use massa_pool_exports::test_exports::MockPoolControllerMessage; use massa_protocol_exports::tests::tools; diff --git a/massa-protocol-worker/src/tests/in_block_operations_scenarios.rs b/massa-protocol-worker/src/tests/in_block_operations_scenarios.rs index cd8ee0c31d3..087100797c5 100644 --- a/massa-protocol-worker/src/tests/in_block_operations_scenarios.rs +++ b/massa-protocol-worker/src/tests/in_block_operations_scenarios.rs @@ -7,7 +7,8 @@ use massa_models::operation::OperationId; use massa_models::secure_share::{Id, SecureShareContent}; use massa_models::{ address::Address, - block::{Block, BlockHeader, BlockHeaderSerializer, BlockSerializer}, + block::{Block, BlockSerializer}, + block_header::{BlockHeader, BlockHeaderSerializer}, slot::Slot, }; use massa_network_exports::NetworkCommand; diff --git a/massa-protocol-worker/src/tests/operations_scenarios.rs b/massa-protocol-worker/src/tests/operations_scenarios.rs index 9de0f56b36c..7c600367844 100644 --- a/massa-protocol-worker/src/tests/operations_scenarios.rs +++ b/massa-protocol-worker/src/tests/operations_scenarios.rs @@ -5,7 +5,7 @@ use super::tools::{protocol_test, protocol_test_with_storage}; use massa_consensus_exports::test_exports::MockConsensusControllerMessage; use massa_models::prehash::PreHashSet; -use massa_models::{self, address::Address, amount::Amount, block::BlockId, slot::Slot}; +use massa_models::{self, address::Address, amount::Amount, block_id::BlockId, slot::Slot}; use massa_network_exports::{BlockInfoReply, NetworkCommand}; use massa_pool_exports::test_exports::MockPoolControllerMessage; use massa_protocol_exports::tests::tools::{self, assert_hash_asked_to_node}; diff --git a/massa-protocol-worker/src/tests/scenarios.rs b/massa-protocol-worker/src/tests/scenarios.rs index 143ca55aa42..9d93c04c562 100644 --- a/massa-protocol-worker/src/tests/scenarios.rs +++ b/massa-protocol-worker/src/tests/scenarios.rs @@ -4,7 +4,7 @@ use super::tools::{protocol_test, protocol_test_with_storage}; use massa_consensus_exports::test_exports::MockConsensusControllerMessage; -use massa_models::block::BlockId; +use massa_models::block_id::BlockId; use massa_models::prehash::{PreHashMap, PreHashSet}; use massa_network_exports::{AskForBlocksInfo, NetworkCommand}; use massa_protocol_exports::tests::tools; diff --git a/massa-protocol-worker/src/tests/tools.rs b/massa-protocol-worker/src/tests/tools.rs index 87a7d027ef0..47491208e5d 100644 --- a/massa-protocol-worker/src/tests/tools.rs +++ b/massa-protocol-worker/src/tests/tools.rs @@ -2,9 +2,7 @@ use crate::start_protocol_controller; use futures::Future; use massa_consensus_exports::test_exports::{ConsensusEventReceiver, MockConsensusController}; use massa_models::{ - block::{BlockId, SecureShareBlock}, - node::NodeId, - operation::SecureShareOperation, + block::SecureShareBlock, block_id::BlockId, node::NodeId, operation::SecureShareOperation, prehash::PreHashSet, }; use massa_network_exports::BlockInfoReply; diff --git a/massa-sdk/src/lib.rs b/massa-sdk/src/lib.rs index a5e5d062708..b28ae3e8dad 100644 --- a/massa-sdk/src/lib.rs +++ b/massa-sdk/src/lib.rs @@ -25,7 +25,9 @@ use massa_api_exports::{ }; use massa_models::{ address::Address, - block::{BlockHeader, BlockId, FilledBlock}, + block::FilledBlock, + block_header::BlockHeader, + block_id::BlockId, clique::Clique, composite::PubkeySig, endorsement::EndorsementId, diff --git a/massa-storage/src/block_indexes.rs b/massa-storage/src/block_indexes.rs index fa3e9c5d381..97a6b163c95 100644 --- a/massa-storage/src/block_indexes.rs +++ b/massa-storage/src/block_indexes.rs @@ -2,7 +2,8 @@ use std::{collections::hash_map, collections::HashMap}; use massa_models::{ address::Address, - block::{BlockId, SecureShareBlock}, + block::SecureShareBlock, + block_id::BlockId, endorsement::EndorsementId, operation::OperationId, prehash::{PreHashMap, PreHashSet}, diff --git a/massa-storage/src/lib.rs b/massa-storage/src/lib.rs index 54c39fbed1c..14c2b786be7 100644 --- a/massa-storage/src/lib.rs +++ b/massa-storage/src/lib.rs @@ -22,7 +22,8 @@ use endorsement_indexes::EndorsementIndexes; use massa_models::prehash::{CapacityAllocator, PreHashMap, PreHashSet, PreHashed}; use massa_models::secure_share::Id; use massa_models::{ - block::{BlockId, SecureShareBlock}, + block::SecureShareBlock, + block_id::BlockId, endorsement::{EndorsementId, SecureShareEndorsement}, operation::{OperationId, SecureShareOperation}, }; From 95ed2a9a8066e70305abfbe423cbbbc134495b17 Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA <22281426+aoudiamoncef@users.noreply.github.com> Date: Mon, 23 Jan 2023 02:06:18 +0100 Subject: [PATCH 42/80] refactor: improve is_final state exec param (#3451) --- massa-api-exports/src/execution.rs | 10 ++++------ massa-node/base_config/openrpc.json | 4 ++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/massa-api-exports/src/execution.rs b/massa-api-exports/src/execution.rs index 19da251f290..826f1bba31e 100644 --- a/massa-api-exports/src/execution.rs +++ b/massa-api-exports/src/execution.rs @@ -63,9 +63,8 @@ pub struct ReadOnlyBytecodeExecution { pub address: Option
, /// Operation datastore, optional pub operation_datastore: Option>, - /// execution start state - /// - /// Whether to start execution from final or active state + /// whether to start execution from final or active state. Default false + #[serde(default)] pub is_final: bool, } @@ -82,8 +81,7 @@ pub struct ReadOnlyCall { pub parameter: Vec, /// caller's address, optional pub caller_address: Option
, - /// execution start state - /// - /// Whether to start execution from final or active state + /// whether to start execution from final or active state. Default false + #[serde(default)] pub is_final: bool, } diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index 743d9b3211d..1ae55f278e5 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -2611,6 +2611,10 @@ "operation_datastore": { "description": "An operation datastore", "type": "array" + }, + "is_final": { + "description": "Whether to start execution from final or active state", + "type": "boolean" } }, "additionalProperties": false From b8ef6c4b7efbe8bdc8852e51da4c8857225a0857 Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA <22281426+aoudiamoncef@users.noreply.github.com> Date: Mon, 23 Jan 2023 14:08:23 +0100 Subject: [PATCH 43/80] Datastore serde support (#3450) --- Cargo.lock | 26 +++++++++++++++++ massa-api-exports/Cargo.toml | 3 ++ massa-api-exports/src/operation.rs | 43 +++++++++++++++++++++++++++++ massa-models/src/operation.rs | 5 ++-- massa-node/base_config/openrpc.json | 26 +++++++++-------- 5 files changed, 90 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 827ed27ffdb..6142b748c51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2325,6 +2325,7 @@ dependencies = [ "massa_time", "massa_wallet", "serde", + "serial_test 1.0.0", "strum", "thiserror", ] @@ -4141,6 +4142,20 @@ dependencies = [ "serial_test_derive 0.10.0", ] +[[package]] +name = "serial_test" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "538c30747ae860d6fb88330addbbd3e0ddbe46d662d032855596d8a8ca260611" +dependencies = [ + "dashmap", + "futures", + "lazy_static", + "log", + "parking_lot", + "serial_test_derive 1.0.0", +] + [[package]] name = "serial_test_derive" version = "0.8.0" @@ -4165,6 +4180,17 @@ dependencies = [ "syn", ] +[[package]] +name = "serial_test_derive" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "079a83df15f85d89a68d64ae1238f142f172b1fa915d0d76b26a7cba1b659a69" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "sha-1" version = "0.9.8" diff --git a/massa-api-exports/Cargo.toml b/massa-api-exports/Cargo.toml index 1cf05d0a049..0664498284f 100644 --- a/massa-api-exports/Cargo.toml +++ b/massa-api-exports/Cargo.toml @@ -25,6 +25,9 @@ massa_protocol_exports = { path = "../massa-protocol-exports" } massa_execution_exports = { path = "../massa-execution-exports" } massa_wallet = { path = "../massa-wallet" } +[dev-dependencies] +serial_test = "1.0.0" + # for more information on what are the following features used for, see the cargo.toml at workspace level [features] sandbox = [] diff --git a/massa-api-exports/src/operation.rs b/massa-api-exports/src/operation.rs index 9dd08545f9e..8cd261889ca 100644 --- a/massa-api-exports/src/operation.rs +++ b/massa-api-exports/src/operation.rs @@ -54,3 +54,46 @@ impl std::fmt::Display for OperationInfo { Ok(()) } } + +#[cfg(test)] +mod tests { + use jsonrpsee_core::__reexports::serde_json::{self, Value}; + use massa_models::operation::OperationType; + use serial_test::serial; + use std::collections::BTreeMap; + + #[test] + #[serial] + fn test_execute_sc_with_datastore() { + let given_op = OperationType::ExecuteSC { + max_gas: 123, + data: vec![23u8, 123u8, 44u8], + datastore: BTreeMap::from([ + (vec![1, 2, 3], vec![4, 5, 6, 7, 8, 9]), + (vec![22, 33, 44, 55, 66, 77], vec![11]), + (vec![2, 3, 4, 5, 6, 7], vec![1]), + ]), + }; + + let op_json_str = serde_json::to_string(&given_op).unwrap(); + + let op_json_value: Value = serde_json::from_str(&op_json_str).unwrap(); + let datastore = op_json_value["ExecuteSC"] + .as_object() + .unwrap() + .get("datastore") + .unwrap() + .as_array() + .unwrap(); + assert_eq!(datastore.len(), 3); + let first_entry = datastore[0].as_array().unwrap(); + assert_eq!(first_entry.len(), 2); + let first_key = first_entry[0].as_array().unwrap(); + let first_value = first_entry[1].as_array().unwrap(); + assert_eq!(first_key.len(), 3); + assert_eq!(first_value.len(), 6); + + let expected_op = serde_json::from_str(&op_json_str).unwrap(); + assert_eq!(given_op, expected_op); + } +} diff --git a/massa-models/src/operation.rs b/massa-models/src/operation.rs index 74c15ad7bb5..3fa874074b1 100644 --- a/massa-models/src/operation.rs +++ b/massa-models/src/operation.rs @@ -28,7 +28,7 @@ use nom::{ }; use num_enum::{IntoPrimitive, TryFromPrimitive}; use serde::{Deserialize, Serialize}; -use serde_with::{DeserializeFromStr, SerializeDisplay}; +use serde_with::{serde_as, DeserializeFromStr, SerializeDisplay}; use std::convert::TryInto; use std::fmt::Formatter; use std::{ops::Bound::Included, ops::RangeInclusive, str::FromStr}; @@ -421,6 +421,7 @@ impl Deserializer for OperationDeserializer { } /// Type specific operation content +#[serde_as] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub enum OperationType { /// transfer coins from sender to recipient @@ -447,7 +448,7 @@ pub enum OperationType { /// The maximum amount of gas that the execution of the contract is allowed to cost. max_gas: u64, /// A key-value store associating a hash to arbitrary bytes - #[serde(skip)] + #[serde_as(as = "Vec<(_, _)>")] datastore: Datastore, }, /// Calls an exported function from a stored smart contract diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index 1ae55f278e5..5bec77f8b85 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -1719,13 +1719,16 @@ }, "DataStore": { "title": "Datastore", - "description": "Datastore", + "description": "A tuple which contains (entry, bytes)", "type": "object", "additionalProperties": { "type": "object", "properties": { - "enrtry": { - "type": "string" + "entry": { + "type": "array", + "items": { + "type": "integer" + } }, "bytes": { "type": "array", @@ -1735,14 +1738,10 @@ } } }, - "example": { - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1": [ - "Number" - ], - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2": [ - "Number" + "example": [ + [1, 2, 3, 4], + [5, 6, 7, 9, 10] ] - } }, "DataStoreEntry": { "description": "Datastore entry", @@ -1974,7 +1973,8 @@ "description": "Execute Smart Contract", "required": [ "data", - "max_gas" + "max_gas", + "datastore" ], "type": "object", "properties": { @@ -1988,6 +1988,10 @@ "max_gas": { "description": "Maximum amount of gas that the execution of the contract is allowed to cost.", "type": "number" + }, + "datastore": { + "description": "A tuple which contains (key, value)", + "$ref": "#/components/schemas/DataStore" } }, "additionalProperties": false From 7872333603f4f6681e87971afe459d1c24cb5fc1 Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA <22281426+aoudiamoncef@users.noreply.github.com> Date: Mon, 23 Jan 2023 15:28:16 +0100 Subject: [PATCH 44/80] Add some missing types to OpenRPC (#3460) --- massa-node/base_config/openrpc.json | 148 ++++++++++++++++------------ 1 file changed, 86 insertions(+), 62 deletions(-) diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index 5bec77f8b85..13b77c5ed9a 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -1376,8 +1376,8 @@ "type": "object", "properties": { "slot": { - "type": "object", - "$ref": "#/components/schemas/Slot" + "$ref": "#/components/schemas/Slot", + "type": "object" }, "amount": { "type": "number" @@ -1389,8 +1389,8 @@ "description": "The next block draws", "type": "array", "items": { - "type": "object", - "$ref": "#/components/schemas/Slot" + "$ref": "#/components/schemas/Slot", + "type": "object" } }, "next_endorsement_draws": { @@ -1400,8 +1400,8 @@ "type": "object", "properties": { "slot": { - "type": "object", - "$ref": "#/components/schemas/Slot" + "$ref": "#/components/schemas/Slot", + "type": "object" }, "index": { "type": "number" @@ -1425,8 +1425,8 @@ "description": "Cycle infos", "type": "array", "items": { - "type": "object", - "$ref": "#/components/schemas/ExecutionAddressCycleInfo" + "$ref": "#/components/schemas/ExecutionAddressCycleInfo", + "type": "object" } } }, @@ -1540,8 +1540,8 @@ "type": "object", "properties": { "target_addr": { - "description": "Address", - "$ref": "#/components/schemas/Address" + "$ref": "#/components/schemas/Address", + "description": "Address" }, "target_func": { "description": "Function name", @@ -1574,9 +1574,7 @@ "description": "The block ids of the blocks in that clique", "type": "array", "items": { - "schema": { - "$ref": "#/components/schemas/BlockId" - } + "$ref": "#/components/schemas/BlockId" } }, "fitness": { @@ -1615,16 +1613,16 @@ "type": "number" }, "end_timestamp": { - "type": "number", - "description": "(Only in tesnets)\nTime in milliseconds when the blockclique started." + "description": "(Only in tesnets)\nTime in milliseconds when the blockclique started.", + "type": "number" }, "genesis_timestamp": { - "type": "number", - "description": "Time in milliseconds when the blockclique started." + "description": "Time in milliseconds when the blockclique started.", + "type": "number" }, "max_block_size": { - "type": "number", - "description": "Maximum size (in bytes) of a block" + "description": "Maximum size (in bytes) of a block", + "type": "number" }, "operation_validity_periods": { "description": "Maximum operation validity period count", @@ -1647,8 +1645,8 @@ "type": "string" }, "t0": { - "type": "number", - "description": "Time between the periods in the same thread." + "description": "Time between the periods in the same thread.", + "type": "number" }, "thread_count": { "description": "Number of threads", @@ -1739,9 +1737,20 @@ } }, "example": [ - [1, 2, 3, 4], - [5, 6, 7, 9, 10] + [ + 1, + 2, + 3, + 4 + ], + [ + 5, + 6, + 7, + 9, + 10 ] + ] }, "DataStoreEntry": { "description": "Datastore entry", @@ -1920,21 +1929,6 @@ }, "additionalProperties": false }, - "ReadOnlyResult": { - "title": "ReadOnlyResult", - "type": "object", - "description": "The result of a read-only execution", - "properties": { - "Ok": { - "type": "array", - "description": "Included in case of success. The result of the execution" - }, - "Error": { - "type": "string", - "description": "Included in case of error. The error message" - } - } - }, "ExecuteReadOnlyResponse": { "title": "ExecuteReadOnlyResponse", "required": [ @@ -1990,8 +1984,8 @@ "type": "number" }, "datastore": { - "description": "A tuple which contains (key, value)", - "$ref": "#/components/schemas/DataStore" + "$ref": "#/components/schemas/DataStore", + "description": "A tuple which contains (key, value)" } }, "additionalProperties": false @@ -2038,12 +2032,12 @@ "description": "Optional end slot\nWill use by default Slot(0,0)" }, "emitter_address": { - "type": "string", - "description": "Optional emitter address" + "description": "Optional emitter address", + "type": "string" }, "original_caller_address": { - "type": "string", - "description": "Optional caller address" + "description": "Optional caller address", + "type": "string" }, "original_operation_id": { "description": "Optional operation id", @@ -2078,7 +2072,7 @@ } } }, - "EventExecutionContext" : { + "EventExecutionContext": { "title": "EventExecutionContext", "description": "Context of the event (not generated by the user)", "required": [ @@ -2367,8 +2361,8 @@ "type": "number" }, "current_time": { - "type": "number", - "description": "Time in milliseconds since 1970-01-01" + "description": "Time in milliseconds since 1970-01-01", + "type": "number" }, "last_slot": { "$ref": "#/components/schemas/Slot", @@ -2606,15 +2600,23 @@ }, "bytecode": { "description": "Bytecode to execute", - "type": "array" + "type": "array", + "items": { + "format": "byte", + "type": "string" + } }, "address": { - "description": "caller's address", - "$ref": "#/components/schemas/Address" + "$ref": "#/components/schemas/Address", + "description": "caller's address" }, "operation_datastore": { "description": "An operation datastore", - "type": "array" + "type": "array", + "items": { + "format": "byte", + "type": "string" + } }, "is_final": { "description": "Whether to start execution from final or active state", @@ -2651,12 +2653,31 @@ "type": "string" }, "caller_address": { - "type": "string", - "description": "Caller's address, optional" + "description": "Caller's address, optional", + "type": "string" } }, "additionalProperties": false }, + "ReadOnlyResult": { + "title": "ReadOnlyResult", + "description": "The result of a read-only execution", + "type": "object", + "properties": { + "Ok": { + "description": "Included in case of success. The result of the execution", + "type": "array", + "items": { + "format": "byte", + "type": "string" + } + }, + "Error": { + "description": "Included in case of error. The error message", + "type": "string" + } + } + }, "Roll": { "title": "Roll", "description": "Roll", @@ -2818,8 +2839,14 @@ } }, "StateChanges": { + "title": "StateChanges", + "required": [ + "async_pool_changes", + "executed_ops_changes", + "ledger_changes", + "pos_changes" + ], "type": "object", - "additionalProperties": false, "properties": { "ledger_changes": { "description": "ledger changes", @@ -2827,7 +2854,10 @@ }, "async_pool_changes": { "description": "async pool changes", - "type": "array" + "type": "array", + "items": { + "type": "object" + } }, "pos_changes": { "description": "pos changes", @@ -2838,13 +2868,7 @@ "type": "object" } }, - "required": [ - "async_pool_changes", - "executed_ops_changes", - "ledger_changes", - "pos_changes" - ], - "title": "StateChanges" + "additionalProperties": false }, "Transaction": { "title": "Transaction", From 6e2128383c4e859d02009dff7a951bdf96d0db64 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Mon, 23 Jan 2023 15:16:53 +0000 Subject: [PATCH 45/80] use latest runtime updates --- massa-execution-worker/src/execution.rs | 15 ++++++++++++--- massa-execution-worker/src/module_cache.rs | 13 ++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index ab71f300a13..45bf83fefe7 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -614,17 +614,24 @@ impl ExecutionState { } // run the VM on the bytecode loaded from the target address - let module = self.module_cache.write().get_module(&bytecode, max_gas)?; + let mut module_lock = self.module_cache.write(); + let module = module_lock.get_module(&bytecode, max_gas)?; match massa_sc_runtime::run_function( &*self.execution_interface, - module, + module.clone(), target_func, param, max_gas, + None, self.config.gas_costs.clone(), ) { - Ok(_response) => {} + Ok(_response) => module_lock.save_module(&bytecode, module), Err(err) => { + if err.to_string() != "limit reached at initialization" { + module_lock.save_module(&bytecode, module); + } else { + warn!("(EXEC) init error"); + } return Err(ExecutionError::RuntimeError(format!( "module execution error in execute_callsc_op: {}", err @@ -714,6 +721,7 @@ impl ExecutionState { &message.handler, &message.data, message.max_gas, + None, self.config.gas_costs.clone(), ) { // execution failed: reset context to snapshot and reimburse sender @@ -1109,6 +1117,7 @@ impl ExecutionState { &target_func, ¶meter, req.max_gas, + None, self.config.gas_costs.clone(), ) .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? diff --git a/massa-execution-worker/src/module_cache.rs b/massa-execution-worker/src/module_cache.rs index 0fb19efe736..0365b39a62d 100644 --- a/massa-execution-worker/src/module_cache.rs +++ b/massa-execution-worker/src/module_cache.rs @@ -1,6 +1,7 @@ use massa_execution_exports::ExecutionError; use massa_sc_runtime::{GasCosts, RuntimeModule}; use schnellru::{ByLength, LruMap}; +use tracing::log::warn; pub struct ModuleCache { gas_costs: GasCosts, @@ -21,16 +22,17 @@ impl ModuleCache { /// /// If the module is not contained in the cache: /// * create the module - /// * save the module in the cache - /// * retrieve a copy of it + /// * retrieve it pub fn get_module( &mut self, bytecode: &[u8], limit: u64, ) -> Result { let module = if let Some(cached_module) = self.cache.get(bytecode) { + warn!("(CACHE) found"); cached_module.clone() } else { + warn!("(CACHE) compiled"); let new_module = RuntimeModule::new(bytecode, limit, self.gas_costs.clone()).map_err(|err| { ExecutionError::RuntimeError(format!( @@ -38,9 +40,14 @@ impl ModuleCache { err )) })?; - self.cache.insert(bytecode.to_vec(), new_module.clone()); new_module }; Ok(module) } + + /// Save a module in the cache + pub fn save_module(&mut self, bytecode: &[u8], module: RuntimeModule) { + warn!("(CACHE) saved"); + self.cache.insert(bytecode.to_vec(), module); + } } From d0b63e4d7bea689edf79a459a619aa119f75342a Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Mon, 23 Jan 2023 15:54:40 +0000 Subject: [PATCH 46/80] use cached instance init costs --- massa-execution-worker/src/execution.rs | 22 ++++++++------------ massa-execution-worker/src/interface_impl.rs | 3 ++- massa-execution-worker/src/module_cache.rs | 16 +++++++------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 45bf83fefe7..39a42c4e7bd 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -32,7 +32,7 @@ use massa_models::{ }; use massa_models::{amount::Amount, slot::Slot}; use massa_pos_exports::SelectorController; -use massa_sc_runtime::{Interface, RuntimeModule}; +use massa_sc_runtime::{Interface, Response, RuntimeModule}; use massa_storage::Storage; use parking_lot::{Mutex, RwLock}; use std::collections::{BTreeMap, BTreeSet}; @@ -615,23 +615,19 @@ impl ExecutionState { // 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)?; + let (module, cached_cost) = module_lock.get_module(&bytecode, max_gas)?; match massa_sc_runtime::run_function( &*self.execution_interface, module.clone(), target_func, param, max_gas, - None, + cached_cost, self.config.gas_costs.clone(), ) { - Ok(_response) => module_lock.save_module(&bytecode, module), + // TODO: handle in other ones too + Ok(Response { init_cost, .. }) => module_lock.save_module(&bytecode, module, init_cost), Err(err) => { - if err.to_string() != "limit reached at initialization" { - module_lock.save_module(&bytecode, module); - } else { - warn!("(EXEC) init error"); - } return Err(ExecutionError::RuntimeError(format!( "module execution error in execute_callsc_op: {}", err @@ -711,7 +707,7 @@ impl ExecutionState { }; // run the VM on the bytecode contained in the operation - let module = self + let (module, cached_init_cost) = self .module_cache .write() .get_module(&bytecode, message.max_gas)?; @@ -721,7 +717,7 @@ impl ExecutionState { &message.handler, &message.data, message.max_gas, - None, + cached_init_cost, self.config.gas_costs.clone(), ) { // execution failed: reset context to snapshot and reimburse sender @@ -1107,7 +1103,7 @@ impl ExecutionState { *context_guard!(self) = execution_context; // run the target function in the bytecode - let module = self + let (module, cached_init_cost) = self .module_cache .write() .get_module(&bytecode, req.max_gas)?; @@ -1117,7 +1113,7 @@ impl ExecutionState { &target_func, ¶meter, req.max_gas, - None, + cached_init_cost, self.config.gas_costs.clone(), ) .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? diff --git a/massa-execution-worker/src/interface_impl.rs b/massa-execution-worker/src/interface_impl.rs index 168e2cdf060..5d25afecc7a 100644 --- a/massa-execution-worker/src/interface_impl.rs +++ b/massa-execution-worker/src/interface_impl.rs @@ -176,8 +176,9 @@ impl Interface for InterfaceImpl { /// # Returns /// A `massa-sc-runtime` compiled module fn get_module(&self, bytecode: &[u8], limit: u64) -> Result { + // TODO: use cache here as well let context = context_guard!(self); - let module = context.module_cache.write().get_module(bytecode, limit)?; + let module = context.module_cache.write().get_module(bytecode, limit)?.0; Ok(module) } diff --git a/massa-execution-worker/src/module_cache.rs b/massa-execution-worker/src/module_cache.rs index 0365b39a62d..68109ce8af8 100644 --- a/massa-execution-worker/src/module_cache.rs +++ b/massa-execution-worker/src/module_cache.rs @@ -5,7 +5,7 @@ use tracing::log::warn; pub struct ModuleCache { gas_costs: GasCosts, - cache: LruMap, RuntimeModule>, + cache: LruMap, (RuntimeModule, u64)>, } impl ModuleCache { @@ -27,10 +27,10 @@ impl ModuleCache { &mut self, bytecode: &[u8], limit: u64, - ) -> Result { - let module = if let Some(cached_module) = self.cache.get(bytecode) { + ) -> Result<(RuntimeModule, Option), ExecutionError> { + let tuple = if let Some((cached_module, init_cost)) = self.cache.get(bytecode) { warn!("(CACHE) found"); - cached_module.clone() + (cached_module.clone(), Some(*init_cost)) } else { warn!("(CACHE) compiled"); let new_module = @@ -40,14 +40,14 @@ impl ModuleCache { err )) })?; - new_module + (new_module, None) }; - Ok(module) + Ok(tuple) } /// Save a module in the cache - pub fn save_module(&mut self, bytecode: &[u8], module: RuntimeModule) { + pub fn save_module(&mut self, bytecode: &[u8], module: RuntimeModule, init_cost: u64) { warn!("(CACHE) saved"); - self.cache.insert(bytecode.to_vec(), module); + self.cache.insert(bytecode.to_vec(), (module, init_cost)); } } From 8192db2a9baf3c6adea3219b9c7dd4b0ae4000af Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Mon, 23 Jan 2023 22:15:46 +0000 Subject: [PATCH 47/80] init limit management and use last runtime updates --- massa-execution-worker/src/execution.rs | 81 +++++++++++--------- massa-execution-worker/src/interface_impl.rs | 3 +- massa-execution-worker/src/module_cache.rs | 21 +++-- 3 files changed, 57 insertions(+), 48 deletions(-) diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 39a42c4e7bd..99f82a283c0 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -615,27 +615,23 @@ impl ExecutionState { // run the VM on the bytecode loaded from the target address let mut module_lock = self.module_cache.write(); - let (module, cached_cost) = module_lock.get_module(&bytecode, max_gas)?; + let module = module_lock.get_module(&bytecode, max_gas)?; match massa_sc_runtime::run_function( &*self.execution_interface, module.clone(), target_func, param, max_gas, - cached_cost, self.config.gas_costs.clone(), ) { - // TODO: handle in other ones too - Ok(Response { init_cost, .. }) => module_lock.save_module(&bytecode, module, init_cost), - Err(err) => { - return Err(ExecutionError::RuntimeError(format!( - "module execution error in execute_callsc_op: {}", - err - ))); + Ok(Response { init_cost, .. }) => { + Ok(module_lock.save_module(&bytecode, module, init_cost)) } + Err(err) => Err(ExecutionError::RuntimeError(format!( + "module execution error in execute_callsc_op: {}", + err + ))), } - - Ok(()) } /// Tries to execute an asynchronous message @@ -707,30 +703,30 @@ impl ExecutionState { }; // run the VM on the bytecode contained in the operation - let (module, cached_init_cost) = self - .module_cache - .write() - .get_module(&bytecode, message.max_gas)?; - if let Err(err) = massa_sc_runtime::run_function( + let mut module_lock = self.module_cache.write(); + let module = module_lock.get_module(&bytecode, message.max_gas)?; + match massa_sc_runtime::run_function( &*self.execution_interface, - module, + module.clone(), &message.handler, &message.data, message.max_gas, - cached_init_cost, self.config.gas_costs.clone(), ) { - // execution failed: reset context to snapshot and reimburse sender - let err = ExecutionError::RuntimeError(format!( - "async message runtime execution error: {}", - err - )); - let mut context = context_guard!(self); - context.reset_to_snapshot(context_snapshot, err.clone()); - context.cancel_async_message(&message); - Err(err) - } else { - Ok(()) + Ok(Response { init_cost, .. }) => { + Ok(module_lock.save_module(&bytecode, module, init_cost)) + } + Err(err) => { + // execution failed: reset context to snapshot and reimburse sender + let err = ExecutionError::RuntimeError(format!( + "module execution error in execute_async_message: {}", + err + )); + let mut context = context_guard!(self); + context.reset_to_snapshot(context_snapshot, err.clone()); + context.cancel_async_message(&message); + Err(err) + } } } @@ -1087,7 +1083,12 @@ impl ExecutionState { req.max_gas, self.config.gas_costs.clone(), ) - .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? + .map_err(|err| { + ExecutionError::RuntimeError(format!( + "module execution error in execute_readonly_request BytecodeExecution: {}", + err, + )) + })? } ReadOnlyExecutionTarget::FunctionCall { target_addr, @@ -1103,20 +1104,24 @@ impl ExecutionState { *context_guard!(self) = execution_context; // run the target function in the bytecode - let (module, cached_init_cost) = self - .module_cache - .write() - .get_module(&bytecode, req.max_gas)?; - massa_sc_runtime::run_function( + let mut module_lock = self.module_cache.write(); + let module = module_lock.get_module(&bytecode, req.max_gas)?; + let response = massa_sc_runtime::run_function( &*self.execution_interface, - module, + module.clone(), &target_func, ¶meter, req.max_gas, - cached_init_cost, self.config.gas_costs.clone(), ) - .map_err(|err| ExecutionError::RuntimeError(err.to_string()))? + .map_err(|err| { + ExecutionError::RuntimeError(format!( + "module execution error in execute_readonly_request BytecodeExecution: {}", + err, + )) + })?; + module_lock.save_module(&bytecode, module, response.init_cost); + response } }; diff --git a/massa-execution-worker/src/interface_impl.rs b/massa-execution-worker/src/interface_impl.rs index 5d25afecc7a..168e2cdf060 100644 --- a/massa-execution-worker/src/interface_impl.rs +++ b/massa-execution-worker/src/interface_impl.rs @@ -176,9 +176,8 @@ impl Interface for InterfaceImpl { /// # Returns /// A `massa-sc-runtime` compiled module fn get_module(&self, bytecode: &[u8], limit: u64) -> Result { - // TODO: use cache here as well let context = context_guard!(self); - let module = context.module_cache.write().get_module(bytecode, limit)?.0; + let module = context.module_cache.write().get_module(bytecode, limit)?; Ok(module) } diff --git a/massa-execution-worker/src/module_cache.rs b/massa-execution-worker/src/module_cache.rs index 68109ce8af8..d023c6fd409 100644 --- a/massa-execution-worker/src/module_cache.rs +++ b/massa-execution-worker/src/module_cache.rs @@ -27,10 +27,15 @@ impl ModuleCache { &mut self, bytecode: &[u8], limit: u64, - ) -> Result<(RuntimeModule, Option), ExecutionError> { - let tuple = if let Some((cached_module, init_cost)) = self.cache.get(bytecode) { + ) -> Result { + if let Some((cached_module, init_cost)) = self.cache.get(bytecode) { warn!("(CACHE) found"); - (cached_module.clone(), Some(*init_cost)) + if limit < *init_cost { + return Err(ExecutionError::RuntimeError( + "given gas cannot cover the initialization costs".to_string(), + )); + } + Ok(cached_module.clone()) } else { warn!("(CACHE) compiled"); let new_module = @@ -40,14 +45,14 @@ impl ModuleCache { err )) })?; - (new_module, None) - }; - Ok(tuple) + Ok(new_module) + } } /// Save a module in the cache pub fn save_module(&mut self, bytecode: &[u8], module: RuntimeModule, init_cost: u64) { - warn!("(CACHE) saved"); - self.cache.insert(bytecode.to_vec(), (module, init_cost)); + if self.cache.insert(bytecode.to_vec(), (module, init_cost)) { + warn!("(CACHE) saved"); + } } } From 84994aedd68503327954c91ec6c6a47523c11a4a Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Tue, 24 Jan 2023 19:51:23 +0100 Subject: [PATCH 48/80] 3428 implement pagination in jsonrpc endpoints (#3461) * Fix spelling of bootstrap and hot reloading on whitelist and blacklist files * Format. * Change pinned variable with sleep with a tokio interval. * Fix get_blocks in client. * Fix deadlock in get_blocks * Introducing PagedVec struct * Fixed broken rebased + fmt + cargo check * Update lib.rs * Update openrpc.json * Refactoring + PageRequest struct * fmt * Update openrpc.json * Make PageRequest optional + Update openrpc * Serialize PagedVec as Vec + openrpc update * fmt * Removed PagedStakers from openrpc.json * Added PageRequest to components Co-authored-by: AurelienFT --- Cargo.lock | 7 ++ massa-api-exports/Cargo.toml | 1 + massa-api-exports/src/lib.rs | 2 + massa-api-exports/src/page.rs | 52 ++++++++++++++ massa-api/src/lib.rs | 25 ++++--- massa-api/src/private.rs | 33 ++++----- massa-api/src/public.rs | 63 ++++++++++------- massa-bootstrap/src/server.rs | 106 ++++++++++++++-------------- massa-client/src/cmds.rs | 28 ++++---- massa-client/src/repl.rs | 8 +++ massa-node/base_config/openrpc.json | 69 +++++++++++++----- massa-sdk/src/lib.rs | 18 ++--- 12 files changed, 265 insertions(+), 147 deletions(-) create mode 100644 massa-api-exports/src/page.rs diff --git a/Cargo.lock b/Cargo.lock index 6142b748c51..1ee30fb78e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2324,6 +2324,7 @@ dependencies = [ "massa_signature", "massa_time", "massa_wallet", + "paginate", "serde", "serial_test 1.0.0", "strum", @@ -3224,6 +3225,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "paginate" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ac1db209d9d6dc8e4435b744ed76198494406cd20eb8ca14baf9828664664c8" + [[package]] name = "parking" version = "2.0.0" diff --git a/massa-api-exports/Cargo.toml b/massa-api-exports/Cargo.toml index 0664498284f..518501adc11 100644 --- a/massa-api-exports/Cargo.toml +++ b/massa-api-exports/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Massa Labs "] edition = "2021" [dependencies] +paginate = "1.1.11" displaydoc = "0.2" thiserror = "1.0" jsonrpsee-core = { version = "0.16.2" } diff --git a/massa-api-exports/src/lib.rs b/massa-api-exports/src/lib.rs index c356e20accb..6b9d5de2344 100644 --- a/massa-api-exports/src/lib.rs +++ b/massa-api-exports/src/lib.rs @@ -30,6 +30,8 @@ pub mod ledger; pub mod node; /// operations pub mod operation; +/// page +pub mod page; /// rolls pub mod rolls; /// slots diff --git a/massa-api-exports/src/page.rs b/massa-api-exports/src/page.rs new file mode 100644 index 00000000000..d0ad5fa0295 --- /dev/null +++ b/massa-api-exports/src/page.rs @@ -0,0 +1,52 @@ +// Copyright (c) 2022 MASSA LABS + +use paginate::Pages; +use serde::{Deserialize, Serialize, Serializer}; + +/// Represents a Vec that can be split across Pages +/// Cf. https://docs.rs/paginate/latest/paginate/ +pub struct PagedVec { + res: Vec, + _total_count: usize, +} + +impl PagedVec { + /// Creates a new Paged Vec with optional limits of item per page and offset + pub fn new(elements: Vec, page_request: Option) -> Self { + let total_count = elements.len(); + + let (limit, offset) = match page_request { + Some(PageRequest { limit, offset }) => (limit, offset), + None => (total_count, 0), + }; + + let pages = Pages::new(total_count, limit); + let page = pages.with_offset(offset); + + let res: Vec<_> = elements + .into_iter() + .skip(page.start) + .take(page.length) + .collect(); + + PagedVec { + res, + _total_count: total_count, + } + } +} + +impl Serialize for PagedVec { + fn serialize(&self, s: S) -> Result { + self.res.serialize::(s) + } +} + +/// Represents the request inputs for a PagedVec +#[derive(Deserialize)] +pub struct PageRequest { + /// The limit of elements in a page + pub limit: usize, + /// The page offset + pub offset: usize, +} diff --git a/massa-api/src/lib.rs b/massa-api/src/lib.rs index e3c63ac3a22..798e255a4ab 100644 --- a/massa-api/src/lib.rs +++ b/massa-api/src/lib.rs @@ -19,6 +19,7 @@ use massa_api_exports::{ execution::{ExecuteReadOnlyResponse, ReadOnlyBytecodeExecution, ReadOnlyCall}, node::NodeStatus, operation::{OperationInfo, OperationInput}, + page::{PageRequest, PagedVec}, TimeInterval, }; use massa_consensus_exports::{ConsensusChannels, ConsensusController}; @@ -43,9 +44,8 @@ use parking_lot::RwLock; use serde_json::Value; use std::net::{IpAddr, SocketAddr}; use std::sync::Arc; -use tower_http::cors::{Any, CorsLayer}; - use tokio::sync::mpsc; +use tower_http::cors::{Any, CorsLayer}; use tracing::{info, warn}; mod api; @@ -266,32 +266,32 @@ pub trait MassaRpc { #[method(name = "node_remove_from_peers_whitelist")] async fn node_remove_from_peers_whitelist(&self, arg: Vec) -> RpcResult<()>; - /// Returns node bootsrap whitelist IP address(es). + /// Returns node bootstrap whitelist IP address(es). #[method(name = "node_bootstrap_whitelist")] async fn node_bootstrap_whitelist(&self) -> RpcResult>; - /// Allow everyone to bootsrap from the node. - /// remove bootsrap whitelist configuration file. + /// Allow everyone to bootstrap from the node. + /// remove bootstrap whitelist configuration file. #[method(name = "node_bootstrap_whitelist_allow_all")] async fn node_bootstrap_whitelist_allow_all(&self) -> RpcResult<()>; - /// Add IP address(es) to node bootsrap whitelist. + /// Add IP address(es) to node bootstrap whitelist. #[method(name = "node_add_to_bootstrap_whitelist")] async fn node_add_to_bootstrap_whitelist(&self, arg: Vec) -> RpcResult<()>; - /// Remove IP address(es) to bootsrap whitelist. + /// Remove IP address(es) to bootstrap whitelist. #[method(name = "node_remove_from_bootstrap_whitelist")] async fn node_remove_from_bootstrap_whitelist(&self, arg: Vec) -> RpcResult<()>; - /// Returns node bootsrap blacklist IP address(es). + /// Returns node bootstrap blacklist IP address(es). #[method(name = "node_bootstrap_blacklist")] async fn node_bootstrap_blacklist(&self) -> RpcResult>; - /// Add IP address(es) to node bootsrap blacklist. + /// Add IP address(es) to node bootstrap blacklist. #[method(name = "node_add_to_bootstrap_blacklist")] async fn node_add_to_bootstrap_blacklist(&self, arg: Vec) -> RpcResult<()>; - /// Remove IP address(es) to bootsrap blacklist. + /// Remove IP address(es) to bootstrap blacklist. #[method(name = "node_remove_from_bootstrap_blacklist")] async fn node_remove_from_bootstrap_blacklist(&self, arg: Vec) -> RpcResult<()>; @@ -315,7 +315,10 @@ pub trait MassaRpc { /// Returns the active stakers and their active roll counts for the current cycle. #[method(name = "get_stakers")] - async fn get_stakers(&self) -> RpcResult>; + async fn get_stakers( + &self, + page_request: Option, + ) -> RpcResult>; /// Returns operation(s) information associated to a given list of operation(s) ID(s). #[method(name = "get_operations")] diff --git a/massa-api/src/private.rs b/massa-api/src/private.rs index 894e102bc75..7eafb34d80b 100644 --- a/massa-api/src/private.rs +++ b/massa-api/src/private.rs @@ -15,6 +15,7 @@ use massa_api_exports::{ execution::{ExecuteReadOnlyResponse, ReadOnlyBytecodeExecution, ReadOnlyCall}, node::NodeStatus, operation::{OperationInfo, OperationInput}, + page::{PageRequest, PagedVec}, ListType, ScrudOperation, TimeInterval, }; use massa_execution_exports::ExecutionController; @@ -174,8 +175,8 @@ impl MassaRpcServer for API { crate::wrong_api::>() } - async fn get_stakers(&self) -> RpcResult> { - crate::wrong_api::>() + async fn get_stakers(&self, _: Option) -> RpcResult> { + crate::wrong_api::>() } async fn get_operations(&self, _: Vec) -> RpcResult> { @@ -251,7 +252,7 @@ impl MassaRpcServer for API { async fn node_bootstrap_whitelist_allow_all(&self) -> RpcResult<()> { remove_file(self.0.api_settings.bootstrap_whitelist_path.clone()).map_err(|e| { ApiError::InternalServerError(format!( - "failed to delete bootsrap whitelist configuration file: {}", + "failed to delete bootstrap whitelist configuration file: {}", e )) .into() @@ -306,7 +307,7 @@ impl MassaRpcServer for API { } } -/// Run Search, Create, Read, Update, Delete operation on bootsrap list of IP(s) +/// Run Search, Create, Read, Update, Delete operation on bootstrap list of IP(s) fn run_scrud_operation( bootstrap_list_file: PathBuf, ips: Vec, @@ -331,7 +332,7 @@ fn run_scrud_operation( .and_then(|length| { if length == 0 { Err(ApiError::InternalServerError(format!( - "failed, bootsrap {} configuration file is empty", + "failed, bootstrap {} configuration file is empty", list_type )) .into()) @@ -341,7 +342,7 @@ fn run_scrud_operation( .and_then(|mut list_ips: BTreeSet| { if list_ips.is_empty() { return Err(ApiError::InternalServerError(format!( - "failed to execute delete operation, bootsrap {} is empty", + "failed to execute delete operation, bootstrap {} is empty", list_type )) .into()); @@ -374,7 +375,7 @@ fn get_file_len( .open(bootstrap_list_file) .map_err(|e| { ApiError::InternalServerError(format!( - "failed to read bootsrap {} configuration file: {}", + "failed to read bootstrap {} configuration file: {}", list_type, e )) .into() @@ -382,14 +383,14 @@ fn get_file_len( .and_then(|file| match file.metadata() { Ok(metadata) => Ok(metadata.len()), Err(e) => Err(ApiError::InternalServerError(format!( - "failed to read bootsrap {} configuration file metadata: {}", + "failed to read bootstrap {} configuration file metadata: {}", list_type, e )) .into()), }) } -/// Read bootsrap list IP(s) from json file +/// Read bootstrap list IP(s) from json file fn read_ips_from_jsonfile( bootstrap_list_file: PathBuf, list_type: &ListType, @@ -397,15 +398,15 @@ fn read_ips_from_jsonfile( std::fs::read_to_string(bootstrap_list_file) .map_err(|e| { ApiError::InternalServerError(format!( - "failed to read bootsrap {} configuration file: {}", + "failed to read bootstrap {} configuration file: {}", list_type, e )) .into() }) - .and_then(|bootsrap_list_str| { - serde_json::from_str(&bootsrap_list_str).map_err(|e| { + .and_then(|bootstrap_list_str| { + serde_json::from_str(&bootstrap_list_str).map_err(|e| { ApiError::InternalServerError(format!( - "failed to parse bootsrap {} configuration file: {}", + "failed to parse bootstrap {} configuration file: {}", list_type, e )) .into() @@ -413,7 +414,7 @@ fn read_ips_from_jsonfile( }) } -/// Write bootsrap list IP(s) from json file +/// Write bootstrap list IP(s) from json file fn write_ips_to_jsonfile( bootstrap_list_file: PathBuf, ips: BTreeSet, @@ -426,7 +427,7 @@ fn write_ips_to_jsonfile( .open(bootstrap_list_file) .map_err(|e| { ApiError::InternalServerError(format!( - "failed to create bootsrap {} configuration file: {}", + "failed to create bootstrap {} configuration file: {}", list_type, e )) .into() @@ -434,7 +435,7 @@ fn write_ips_to_jsonfile( .and_then(|file| { serde_json::to_writer_pretty(file, &ips).map_err(|e| { ApiError::InternalServerError(format!( - "failed to write bootsrap {} configuration file: {}", + "failed to write bootstrap {} configuration file: {}", list_type, e )) .into() diff --git a/massa-api/src/public.rs b/massa-api/src/public.rs index 1a14c2b6f54..3d06e86ae6d 100644 --- a/massa-api/src/public.rs +++ b/massa-api/src/public.rs @@ -14,6 +14,7 @@ use massa_api_exports::{ execution::{ExecuteReadOnlyResponse, ReadOnlyBytecodeExecution, ReadOnlyCall, ReadOnlyResult}, node::NodeStatus, operation::{OperationInfo, OperationInput}, + page::{PageRequest, PagedVec}, slot::SlotAmount, TimeInterval, }; @@ -404,7 +405,10 @@ impl MassaRpcServer for API { Ok(consensus_controller.get_cliques()) } - async fn get_stakers(&self) -> RpcResult> { + async fn get_stakers( + &self, + page_request: Option, + ) -> RpcResult> { let execution_controller = self.0.execution_controller.clone(); let cfg = self.0.api_settings.clone(); @@ -431,9 +435,13 @@ impl MassaRpcServer for API { .get_cycle_active_rolls(curr_cycle) .into_iter() .collect::>(); + staker_vec .sort_by(|&(_, roll_counts_a), &(_, roll_counts_b)| roll_counts_b.cmp(&roll_counts_a)); - Ok(staker_vec) + + let paged_vec = PagedVec::new(staker_vec, page_request); + + Ok(paged_vec) } async fn get_operations(&self, ops: Vec) -> RpcResult> { @@ -601,30 +609,33 @@ impl MassaRpcServer for API { let blocks = ids .into_iter() .filter_map(|id| { - if let Some(verifiable_block) = storage.read_blocks().get(&id).cloned() { - if let Some(graph_status) = consensus_controller - .get_block_statuses(&[id]) - .into_iter() - .next() - { - let is_final = graph_status == BlockGraphStatus::Final; - let is_in_blockclique = - graph_status == BlockGraphStatus::ActiveInBlockclique; - let is_candidate = graph_status == BlockGraphStatus::ActiveInBlockclique - || graph_status == BlockGraphStatus::ActiveInAlternativeCliques; - let is_discarded = graph_status == BlockGraphStatus::Discarded; - - return Some(BlockInfo { - id, - content: Some(BlockInfoContent { - is_final, - is_in_blockclique, - is_candidate, - is_discarded, - block: verifiable_block.content, - }), - }); - } + let content = if let Some(wrapped_block) = storage.read_blocks().get(&id) { + wrapped_block.content.clone() + } else { + return None; + }; + + if let Some(graph_status) = consensus_controller + .get_block_statuses(&[id]) + .into_iter() + .next() + { + let is_final = graph_status == BlockGraphStatus::Final; + let is_in_blockclique = graph_status == BlockGraphStatus::ActiveInBlockclique; + let is_candidate = graph_status == BlockGraphStatus::ActiveInBlockclique + || graph_status == BlockGraphStatus::ActiveInAlternativeCliques; + let is_discarded = graph_status == BlockGraphStatus::Discarded; + + return Some(BlockInfo { + id, + content: Some(BlockInfoContent { + is_final, + is_in_blockclique, + is_candidate, + is_discarded, + block: content, + }), + }); } None diff --git a/massa-bootstrap/src/server.rs b/massa-bootstrap/src/server.rs index e7db4656df6..21c2f5c3b01 100644 --- a/massa-bootstrap/src/server.rs +++ b/massa-bootstrap/src/server.rs @@ -16,6 +16,7 @@ use parking_lot::RwLock; use std::{ collections::{hash_map, HashMap, HashSet}, net::{IpAddr, SocketAddr}, + path::PathBuf, sync::Arc, time::{Duration, Instant}, }; @@ -66,42 +67,6 @@ pub async fn start_bootstrap_server( if let Some(bind) = bootstrap_config.bind { let (manager_tx, manager_rx) = mpsc::channel::<()>(1); - let whitelist = if let Ok(whitelist) = - std::fs::read_to_string(&bootstrap_config.bootstrap_whitelist_path) - { - Some( - serde_json::from_str::>(whitelist.as_str()) - .map_err(|_| { - BootstrapError::GeneralError(String::from( - "Failed to parse bootstrap whitelist", - )) - })? - .into_iter() - .map(normalize_ip) - .collect(), - ) - } else { - None - }; - - let blacklist = if let Ok(blacklist) = - std::fs::read_to_string(&bootstrap_config.bootstrap_blacklist_path) - { - Some( - serde_json::from_str::>(blacklist.as_str()) - .map_err(|_| { - BootstrapError::GeneralError(String::from( - "Failed to parse bootstrap blacklist", - )) - })? - .into_iter() - .map(normalize_ip) - .collect(), - ) - } else { - None - }; - let join_handle = tokio::spawn(async move { BootstrapServer { consensus_controller, @@ -112,8 +77,6 @@ pub async fn start_bootstrap_server( bind, keypair, version, - whitelist, - blacklist, ip_hist_map: HashMap::with_capacity(bootstrap_config.ip_list_max_size), bootstrap_config, } @@ -139,26 +102,62 @@ struct BootstrapServer { keypair: KeyPair, bootstrap_config: BootstrapConfig, version: Version, - blacklist: Option>, - whitelist: Option>, ip_hist_map: HashMap, } +#[allow(clippy::result_large_err)] +#[allow(clippy::type_complexity)] +fn reload_whitelist_blacklist( + whitelist_path: &PathBuf, + blacklist_path: &PathBuf, +) -> Result<(Option>, Option>), BootstrapError> { + let whitelist = if let Ok(whitelist) = std::fs::read_to_string(whitelist_path) { + Some( + serde_json::from_str::>(whitelist.as_str()) + .map_err(|_| { + BootstrapError::GeneralError(String::from( + "Failed to parse bootstrap whitelist", + )) + })? + .into_iter() + .map(normalize_ip) + .collect(), + ) + } else { + None + }; + + let blacklist = if let Ok(blacklist) = std::fs::read_to_string(blacklist_path) { + Some( + serde_json::from_str::>(blacklist.as_str()) + .map_err(|_| { + BootstrapError::GeneralError(String::from( + "Failed to parse bootstrap blacklist", + )) + })? + .into_iter() + .map(normalize_ip) + .collect(), + ) + } else { + None + }; + Ok((whitelist, blacklist)) +} + impl BootstrapServer { pub async fn run(mut self) -> Result<(), BootstrapError> { debug!("starting bootstrap server"); massa_trace!("bootstrap.lib.run", {}); let mut listener = self.establisher.get_listener(self.bind).await?; let mut bootstrap_sessions = FuturesUnordered::new(); - // let cache_timeout = self.bootstrap_config.cache_duration.to_duration(); - // let mut bootstrap_data: Option<( - // BootstrapableGraph, - // BootstrapPeers, - // Arc>, - // )> = None; - // let cache_timer = sleep(cache_timeout); + let cache_timeout = self.bootstrap_config.cache_duration.to_duration(); + let (mut whitelist, mut blacklist) = reload_whitelist_blacklist( + &self.bootstrap_config.bootstrap_whitelist_path, + &self.bootstrap_config.bootstrap_blacklist_path, + )?; + let mut cache_interval = tokio::time::interval(cache_timeout); let per_ip_min_interval = self.bootstrap_config.per_ip_min_interval.to_duration(); - // tokio::pin!(cache_timer); /* select! without the "biased" modifier will randomly select the 1st branch to check, then will check the next ones in the order they are written. @@ -177,11 +176,10 @@ impl BootstrapServer { break }, - // cache cleanup timeout - // _ = &mut cache_timer, if bootstrap_data.is_some() => { - // massa_trace!("bootstrap.lib.run.cache_unload", {}); - // bootstrap_data = None; - // } + // Whitelist cache timeout + _ = cache_interval.tick() => { + (whitelist, blacklist) = reload_whitelist_blacklist(&self.bootstrap_config.bootstrap_whitelist_path, &self.bootstrap_config.bootstrap_blacklist_path)?; + } // bootstrap session finished Some(_) = bootstrap_sessions.next() => { @@ -189,7 +187,7 @@ impl BootstrapServer { } // listener - res_connection = listener.accept(&self.whitelist, &self.blacklist) => { + res_connection = listener.accept(&whitelist, &blacklist) => { let (dplx, remote_addr) = if res_connection.is_ok() { res_connection.unwrap() } else { diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index dc804e664da..450fe0b8b4e 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -124,14 +124,14 @@ pub enum Command { props(args = "(add, remove or allow-all) [IpAddr]", pwd_not_needed = "true"), message = "Manage boostrap whitelist IP address(es). No args returns the whitelist blacklist" )] - node_bootsrap_whitelist, + node_bootstrap_whitelist, #[strum( ascii_case_insensitive, props(args = "(add or remove) [IpAddr]", pwd_not_needed = "true"), message = "Manage boostrap blacklist IP address(es). No args returns the boostrap blacklist" )] - node_bootsrap_blacklist, + node_bootstrap_blacklist, #[strum( ascii_case_insensitive, @@ -616,8 +616,8 @@ impl Command { } Command::get_blocks => { - if parameters.len() != 1 { - bail!("wrong param numbers, expecting at least one IP address") + if parameters.is_empty() { + bail!("wrong param numbers, expecting at least one block id") } let block_ids = parse_vec::(parameters)?; match client.public.get_blocks(block_ids).await { @@ -1180,10 +1180,10 @@ impl Command { Err(e) => rpc_error!(e), } } - Command::node_bootsrap_blacklist => { + Command::node_bootstrap_blacklist => { if parameters.is_empty() { match client.private.node_bootstrap_blacklist().await { - Ok(bootsraplist_ips) => Ok(Box::new(bootsraplist_ips)), + Ok(bootstraplist_ips) => Ok(Box::new(bootstraplist_ips)), Err(e) => rpc_error!(e), } } else { @@ -1204,7 +1204,7 @@ impl Command { Ok(()) => { if !json { println!( - "Request of bootsrap blacklisting successfully sent!" + "Request of bootstrap blacklisting successfully sent!" ) } Ok(Box::new(())) @@ -1220,7 +1220,7 @@ impl Command { { Ok(()) => { if !json { - println!("Request of remove from bootsrap blacklist successfully sent!") + println!("Request of remove from bootstrap blacklist successfully sent!") } Ok(Box::new(())) } @@ -1234,12 +1234,12 @@ impl Command { res } } - Command::node_bootsrap_whitelist => { + Command::node_bootstrap_whitelist => { if parameters.is_empty() { match client.private.node_bootstrap_whitelist().await { - Ok(bootsraplist_ips) => Ok(Box::new(bootsraplist_ips)), + Ok(bootstraplist_ips) => Ok(Box::new(bootstraplist_ips)), Err(e) => { - client_warning!("if bootsrap whitelist configuration file does't exists, bootsrap is allowed for everyone !!!"); + client_warning!("if bootstrap whitelist configuration file does't exists, bootstrap is allowed for everyone !!!"); rpc_error!(e) } } @@ -1264,7 +1264,7 @@ impl Command { Ok(()) => { if !json { println!( - "Request of bootsrap whitelisting successfully sent!" + "Request of bootstrap whitelisting successfully sent!" ) } Ok(Box::new(())) @@ -1283,7 +1283,7 @@ impl Command { { Ok(()) => { if !json { - println!("Request of remove from bootsrap whitelist successfully sent!") + println!("Request of remove from bootstrap whitelist successfully sent!") } Ok(Box::new(())) } @@ -1295,7 +1295,7 @@ impl Command { Ok(()) => { if !json { println!( - "Request of bootsrap whitelisting everyone successfully sent!" + "Request of bootstrap whitelisting everyone successfully sent!" ) } Ok(Box::new(())) diff --git a/massa-client/src/repl.rs b/massa-client/src/repl.rs index a24ef14be7f..929ab2d3320 100644 --- a/massa-client/src/repl.rs +++ b/massa-client/src/repl.rs @@ -357,6 +357,14 @@ impl Output for Vec { } } +impl Output for Vec { + fn pretty_print(&self) { + for block_info in self { + println!("{}", block_info); + } + } +} + impl Output for Vec { fn pretty_print(&self) { for operation_id in self { diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index 13b77c5ed9a..652ecaf69ef 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -394,12 +394,22 @@ "description": "Massa public api" } ], - "params": [], + "params": [ + { + "schema": { + "$ref": "#/components/schemas/PageRequest" + }, + "name": "PageRequest" + } + ], "result": { "schema": { - "$ref": "#/components/schemas/Staker" + "type": "array", + "items": { + "$ref": "#/components/schemas/Staker" + } }, - "name": "Staker" + "name": "PagedStakers" }, "name": "get_stakers", "summary": "Get stakers", @@ -503,8 +513,8 @@ "schema": false }, "name": "node_add_to_bootstrap_blacklist", - "summary": "Add to bootsrap blacklist given IP address(es)", - "description": "Add to bootsrap blacklist given IP address(es)." + "summary": "Add to bootstrap blacklist given IP address(es)", + "description": "Add to bootstrap blacklist given IP address(es)." }, { "tags": [ @@ -533,8 +543,8 @@ "schema": false }, "name": "node_add_to_bootstrap_whitelist", - "summary": "Add to bootsrap whitelist given IP address(es)", - "description": "Add to bootsrap whitelist given IP address(es)." + "summary": "Add to bootstrap whitelist given IP address(es)", + "description": "Add to bootstrap whitelist given IP address(es)." }, { "tags": [ @@ -644,8 +654,8 @@ } }, "name": "node_bootstrap_blacklist", - "summary": "Returns bootsrap blacklist IP address(es)", - "description": "Returns bootsrap blacklist IP address(es)." + "summary": "Returns bootstrap blacklist IP address(es)", + "description": "Returns bootstrap blacklist IP address(es)." }, { "tags": [ @@ -667,8 +677,8 @@ } }, "name": "node_bootstrap_whitelist", - "summary": "Returns bootsrap whitelist IP address(es)", - "description": "Returns bootsrap whitelist IP address(es)." + "summary": "Returns bootstrap whitelist IP address(es)", + "description": "Returns bootstrap whitelist IP address(es)." }, { "tags": [ @@ -684,8 +694,8 @@ "schema": false }, "name": "node_bootstrap_whitelist_allow_all", - "summary": "Allow everyone to bootsrap from the node", - "description": "Allow everyone to bootsrap from the node. Remove bootsrap whitelist configuration file." + "summary": "Allow everyone to bootstrap from the node", + "description": "Allow everyone to bootstrap from the node. Remove bootstrap whitelist configuration file." }, { "tags": [ @@ -737,8 +747,8 @@ "schema": false }, "name": "node_remove_from_bootstrap_blacklist", - "summary": "Remove from bootsrap blacklist given IP address(es)", - "description": "Remove from bootsrap blacklist given IP address(es)." + "summary": "Remove from bootstrap blacklist given IP address(es)", + "description": "Remove from bootstrap blacklist given IP address(es)." }, { "tags": [ @@ -767,8 +777,8 @@ "schema": false }, "name": "node_remove_from_bootstrap_whitelist", - "summary": "Remove from bootsrap whitelist given IP address(es)", - "description": "Remove from bootsrap whitelist given IP address(es)." + "summary": "Remove from bootstrap whitelist given IP address(es)", + "description": "Remove from bootstrap whitelist given IP address(es)." }, { "tags": [ @@ -2516,6 +2526,23 @@ } } }, + "PageRequest": { + "title": "PageRequest", + "description": "An PageRequest object, which contains limit (max elements par page) and a page offset.", + "type": "object", + "required": [ + "limit", + "offset" + ], + "properties": { + "limit": { + "type": "number" + }, + "offset": { + "type": "number" + } + } + }, "PoolStats": { "title": "PoolStats", "description": "Pool stats", @@ -3103,6 +3130,14 @@ "$ref": "#/components/schemas/OperationType" } }, + "PageRequest": { + "name": "PageRequest", + "summary": "PageRequest", + "description": "An Page request parameter, which contains limit and offset properties.", + "schema": { + "$ref": "#/components/schemas/PageRequest" + } + }, "PubkeySig": { "name": "PubkeySig", "summary": "PubkeySig", diff --git a/massa-sdk/src/lib.rs b/massa-sdk/src/lib.rs index b28ae3e8dad..0edcf622c12 100644 --- a/massa-sdk/src/lib.rs +++ b/massa-sdk/src/lib.rs @@ -177,50 +177,50 @@ impl RpcClient { .await } - /// Returns node bootsrap whitelist IP address(es). + /// Returns node bootstrap whitelist IP address(es). pub async fn node_bootstrap_whitelist(&self) -> RpcResult> { self.http_client .request("node_bootstrap_whitelist", rpc_params![]) .await } - /// Allow everyone to bootsrap from the node. - /// remove bootsrap whitelist configuration file. + /// Allow everyone to bootstrap from the node. + /// remove bootstrap whitelist configuration file. pub async fn node_bootstrap_whitelist_allow_all(&self) -> RpcResult<()> { self.http_client .request("node_bootstrap_whitelist_allow_all", rpc_params![]) .await } - /// Add IP address(es) to node bootsrap whitelist. + /// Add IP address(es) to node bootstrap whitelist. pub async fn node_add_to_bootstrap_whitelist(&self, ips: Vec) -> RpcResult<()> { self.http_client .request("node_add_to_bootstrap_whitelist", rpc_params![ips]) .await } - /// Remove IP address(es) to bootsrap whitelist. + /// Remove IP address(es) to bootstrap whitelist. pub async fn node_remove_from_bootstrap_whitelist(&self, ips: Vec) -> RpcResult<()> { self.http_client .request("node_remove_from_bootstrap_whitelist", rpc_params![ips]) .await } - /// Returns node bootsrap blacklist IP address(es). + /// Returns node bootstrap blacklist IP address(es). pub async fn node_bootstrap_blacklist(&self) -> RpcResult> { self.http_client .request("node_bootstrap_blacklist", rpc_params![]) .await } - /// Add IP address(es) to node bootsrap blacklist. + /// Add IP address(es) to node bootstrap blacklist. pub async fn node_add_to_bootstrap_blacklist(&self, ips: Vec) -> RpcResult<()> { self.http_client .request("node_add_to_bootstrap_blacklist", rpc_params![ips]) .await } - /// Remove IP address(es) to bootsrap blacklist. + /// Remove IP address(es) to bootstrap blacklist. pub async fn node_remove_from_bootstrap_blacklist(&self, ips: Vec) -> RpcResult<()> { self.http_client .request("node_remove_from_bootstrap_blacklist", rpc_params![ips]) @@ -270,7 +270,7 @@ impl RpcClient { } /// Returns block(s) information associated to a given list of block(s) ID(s) - pub async fn get_blocks(&self, block_ids: Vec) -> RpcResult { + pub async fn get_blocks(&self, block_ids: Vec) -> RpcResult> { self.http_client .request("get_blocks", rpc_params![block_ids]) .await From 2e53c42543a5318d8b4944cdcedf1edd84311dd7 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Tue, 24 Jan 2023 20:30:29 +0000 Subject: [PATCH 49/80] review updates --- Cargo.lock | 1 + massa-execution-exports/src/settings.rs | 2 +- massa-execution-exports/src/test_exports/config.rs | 1 + massa-execution-worker/src/context.rs | 2 +- massa-execution-worker/src/module_cache.rs | 13 +++++++------ massa-execution-worker/src/worker.rs | 2 +- massa-node/base_config/config.toml | 4 ++-- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53971bcd21c..5f85e9d432e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2265,6 +2265,7 @@ dependencies = [ "serde_json", "serial_test 0.8.0", "thiserror", + "tracing", "wasmer", "wasmer-compiler-singlepass", "wasmer-middlewares", diff --git a/massa-execution-exports/src/settings.rs b/massa-execution-exports/src/settings.rs index c85ace45eb8..a109cc85b23 100644 --- a/massa-execution-exports/src/settings.rs +++ b/massa-execution-exports/src/settings.rs @@ -57,7 +57,7 @@ pub struct ExecutionConfig { pub max_bytecode_size: u64, /// Max datastore value size pub max_datastore_value_size: u64, - /// Max size of the module cache + /// Max number of compiled modules in the cache pub max_module_cache_size: u32, /// Storage cost constants pub storage_costs_constants: StorageCostsConstants, diff --git a/massa-execution-exports/src/test_exports/config.rs b/massa-execution-exports/src/test_exports/config.rs index 951a1fa60bd..761e6d0e8b4 100644 --- a/massa-execution-exports/src/test_exports/config.rs +++ b/massa-execution-exports/src/test_exports/config.rs @@ -55,6 +55,7 @@ impl Default for ExecutionConfig { .into(), ) .unwrap(), + max_module_cache_size: 1000, } } } diff --git a/massa-execution-worker/src/context.rs b/massa-execution-worker/src/context.rs index efe2324756e..f5f669788ee 100644 --- a/massa-execution-worker/src/context.rs +++ b/massa-execution-worker/src/context.rs @@ -128,7 +128,7 @@ pub struct ExecutionContext { /// operation id that originally caused this execution (if any) pub origin_operation_id: Option, - // cache of pre compiled sc modules + // cache of compiled runtime modules pub module_cache: Arc>, } diff --git a/massa-execution-worker/src/module_cache.rs b/massa-execution-worker/src/module_cache.rs index d023c6fd409..8e5567eb301 100644 --- a/massa-execution-worker/src/module_cache.rs +++ b/massa-execution-worker/src/module_cache.rs @@ -1,8 +1,13 @@ use massa_execution_exports::ExecutionError; use massa_sc_runtime::{GasCosts, RuntimeModule}; use schnellru::{ByLength, LruMap}; -use tracing::log::warn; +/// LRU cache of compiled runtime modules. +/// The LRU caching scheme is to remove the least recently used module when the cache is full. +/// +/// * key: raw bytecode +/// * value.0: corresponding compiled module +/// * value.1: instance initialization cost pub struct ModuleCache { gas_costs: GasCosts, cache: LruMap, (RuntimeModule, u64)>, @@ -29,7 +34,6 @@ impl ModuleCache { limit: u64, ) -> Result { if let Some((cached_module, init_cost)) = self.cache.get(bytecode) { - warn!("(CACHE) found"); if limit < *init_cost { return Err(ExecutionError::RuntimeError( "given gas cannot cover the initialization costs".to_string(), @@ -37,7 +41,6 @@ impl ModuleCache { } Ok(cached_module.clone()) } else { - warn!("(CACHE) compiled"); let new_module = RuntimeModule::new(bytecode, limit, self.gas_costs.clone()).map_err(|err| { ExecutionError::RuntimeError(format!( @@ -51,8 +54,6 @@ impl ModuleCache { /// Save a module in the cache pub fn save_module(&mut self, bytecode: &[u8], module: RuntimeModule, init_cost: u64) { - if self.cache.insert(bytecode.to_vec(), (module, init_cost)) { - warn!("(CACHE) saved"); - } + self.cache.insert(bytecode.to_vec(), (module, init_cost)); } } diff --git a/massa-execution-worker/src/worker.rs b/massa-execution-worker/src/worker.rs index 321b406968b..3af5c91a3e8 100644 --- a/massa-execution-worker/src/worker.rs +++ b/massa-execution-worker/src/worker.rs @@ -85,7 +85,7 @@ impl ExecutionThread { if let Some(req_resp) = self.readonly_requests.pop() { let (req, resp_tx) = req_resp.into_request_sender_pair(); - // Acquire read access to the execution state and execute the read-only request + // Acquire write access to the execution state (for cache updates) and execute the read-only request let outcome = self.execution_state.write().execute_readonly_request(req); // Send the execution output through resp_tx. diff --git a/massa-node/base_config/config.toml b/massa-node/base_config/config.toml index 6ee27495983..8c8887fcb58 100644 --- a/massa-node/base_config/config.toml +++ b/massa-node/base_config/config.toml @@ -54,8 +54,8 @@ abi_gas_costs_file = "base_config/gas_costs/abi_gas_costs.json" # gas cost for wasm operator wasm_gas_costs_file = "base_config/gas_costs/wasm_gas_costs.json" - # maximum size of the pre compiled module cache - max_module_cache_size = 100 + # max number of compiled modules in the cache + max_module_cache_size = 1000 [ledger] # path to the initial ledger From e1e165a39bd8c0fb25b3d645adf6c2d39f29cac2 Mon Sep 17 00:00:00 2001 From: sydhds Date: Wed, 25 Jan 2023 10:08:25 +0100 Subject: [PATCH 50/80] Add info about key in LruMap --- massa-execution-worker/src/module_cache.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/massa-execution-worker/src/module_cache.rs b/massa-execution-worker/src/module_cache.rs index 8e5567eb301..c5a001e3746 100644 --- a/massa-execution-worker/src/module_cache.rs +++ b/massa-execution-worker/src/module_cache.rs @@ -5,7 +5,7 @@ use schnellru::{ByLength, LruMap}; /// LRU cache of compiled runtime modules. /// The LRU caching scheme is to remove the least recently used module when the cache is full. /// -/// * key: raw bytecode +/// * key: raw bytecode (which is hashed on insertion in LruMap) /// * value.0: corresponding compiled module /// * value.1: instance initialization cost pub struct ModuleCache { From a83f4d82959eacd26b345734e929fc3148052777 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Wed, 25 Jan 2023 10:29:46 +0000 Subject: [PATCH 51/80] fix execution test compilation failure --- massa-execution-worker/src/tests/mock.rs | 36 +++++++++--------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/massa-execution-worker/src/tests/mock.rs b/massa-execution-worker/src/tests/mock.rs index 9bb91de238e..c068ea846f9 100644 --- a/massa-execution-worker/src/tests/mock.rs +++ b/massa-execution-worker/src/tests/mock.rs @@ -1,8 +1,18 @@ +use massa_execution_exports::ExecutionError; use massa_final_state::{FinalState, FinalStateConfig}; -use massa_ledger_exports::LedgerEntry; -use massa_ledger_exports::{LedgerConfig, LedgerController, LedgerError}; +use massa_hash::Hash; +use massa_ledger_exports::{LedgerConfig, LedgerController, LedgerEntry, LedgerError}; use massa_ledger_worker::FinalLedger; -use massa_models::{address::Address, amount::Amount, config::THREAD_COUNT}; +use massa_models::{ + address::Address, + amount::Amount, + block::{Block, BlockSerializer, SecureShareBlock}, + block_header::{BlockHeader, BlockHeaderSerializer}, + config::THREAD_COUNT, + operation::SecureShareOperation, + secure_share::SecureShareContent, + slot::Slot, +}; use massa_pos_exports::SelectorConfig; use massa_pos_worker::start_selector_worker; use massa_signature::KeyPair; @@ -14,23 +24,7 @@ use std::{ io::Seek, sync::Arc, }; -use tempfile::NamedTempFile; -use tempfile::TempDir; - -#[cfg(feature = "testing")] -use massa_models::{ - block::{Block, BlockSerializer, SecureShareBlock}, - block_header::{BlockHeader, BlockHeaderSerializer}, - operation::SecureShareOperation, - secure_share::SecureShareContent, - slot::Slot, -}; - -#[cfg(feature = "testing")] -use massa_execution_exports::ExecutionError; - -#[cfg(feature = "testing")] -use massa_hash::Hash; +use tempfile::{NamedTempFile, TempDir}; fn get_initials() -> (NamedTempFile, HashMap) { let file = NamedTempFile::new().unwrap(); @@ -101,7 +95,6 @@ fn get_initials() -> (NamedTempFile, HashMap) { /// Same as `get_random_address()` and return `keypair` associated /// to the address. -#[cfg(feature = "testing")] pub fn get_random_address_full() -> (Address, KeyPair) { let keypair = KeyPair::generate(); (Address::from_public_key(&keypair.get_public_key()), keypair) @@ -137,7 +130,6 @@ pub fn get_sample_state() -> Result<(Arc>, NamedTempFile, Tem /// creator. /// /// Return a result that should be unwrapped in the root `#[test]` routine. -#[cfg(feature = "testing")] pub fn create_block( creator_keypair: KeyPair, operations: Vec, From 1ffb0aa411a8ad527a5a9a2b579f31b9d85399d6 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Wed, 25 Jan 2023 10:29:46 +0000 Subject: [PATCH 52/80] fix execution test compilation failure --- massa-execution-worker/src/tests/mock.rs | 36 +++++++++--------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/massa-execution-worker/src/tests/mock.rs b/massa-execution-worker/src/tests/mock.rs index 9bb91de238e..c068ea846f9 100644 --- a/massa-execution-worker/src/tests/mock.rs +++ b/massa-execution-worker/src/tests/mock.rs @@ -1,8 +1,18 @@ +use massa_execution_exports::ExecutionError; use massa_final_state::{FinalState, FinalStateConfig}; -use massa_ledger_exports::LedgerEntry; -use massa_ledger_exports::{LedgerConfig, LedgerController, LedgerError}; +use massa_hash::Hash; +use massa_ledger_exports::{LedgerConfig, LedgerController, LedgerEntry, LedgerError}; use massa_ledger_worker::FinalLedger; -use massa_models::{address::Address, amount::Amount, config::THREAD_COUNT}; +use massa_models::{ + address::Address, + amount::Amount, + block::{Block, BlockSerializer, SecureShareBlock}, + block_header::{BlockHeader, BlockHeaderSerializer}, + config::THREAD_COUNT, + operation::SecureShareOperation, + secure_share::SecureShareContent, + slot::Slot, +}; use massa_pos_exports::SelectorConfig; use massa_pos_worker::start_selector_worker; use massa_signature::KeyPair; @@ -14,23 +24,7 @@ use std::{ io::Seek, sync::Arc, }; -use tempfile::NamedTempFile; -use tempfile::TempDir; - -#[cfg(feature = "testing")] -use massa_models::{ - block::{Block, BlockSerializer, SecureShareBlock}, - block_header::{BlockHeader, BlockHeaderSerializer}, - operation::SecureShareOperation, - secure_share::SecureShareContent, - slot::Slot, -}; - -#[cfg(feature = "testing")] -use massa_execution_exports::ExecutionError; - -#[cfg(feature = "testing")] -use massa_hash::Hash; +use tempfile::{NamedTempFile, TempDir}; fn get_initials() -> (NamedTempFile, HashMap) { let file = NamedTempFile::new().unwrap(); @@ -101,7 +95,6 @@ fn get_initials() -> (NamedTempFile, HashMap) { /// Same as `get_random_address()` and return `keypair` associated /// to the address. -#[cfg(feature = "testing")] pub fn get_random_address_full() -> (Address, KeyPair) { let keypair = KeyPair::generate(); (Address::from_public_key(&keypair.get_public_key()), keypair) @@ -137,7 +130,6 @@ pub fn get_sample_state() -> Result<(Arc>, NamedTempFile, Tem /// creator. /// /// Return a result that should be unwrapped in the root `#[test]` routine. -#[cfg(feature = "testing")] pub fn create_block( creator_keypair: KeyPair, operations: Vec, From a5ea9f465e5a7dd347df0d4d01241f80eda127cd Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Wed, 25 Jan 2023 14:38:41 +0000 Subject: [PATCH 53/80] fix SC deployment test --- .../src/tests/wasm/deploy_sc.wasm | Bin 3392 -> 2952 bytes .../src/tests/wasm/init_sc.wasm | Bin 1589 -> 1115 bytes .../base_config/gas_costs/abi_gas_costs.json | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/massa-execution-worker/src/tests/wasm/deploy_sc.wasm b/massa-execution-worker/src/tests/wasm/deploy_sc.wasm index 9c1d6b83aba2c8e95bd246a340431f3fc0d72753..d473742149e8607f110e7e9b52801e018b9ffa81 100644 GIT binary patch literal 2952 zcmaJ@J&YSg6n-*rNgzUi=s=Fow>i#tXFK-h zl1Kq)3sHBGU1_S)0opKespgW@f+l-uHfH zWa^AJ6%nbU(Rnpdlk<8aZ!?)p=se*c3x#Qbjj8xZP4rz=HF?{vP1y#b$&UoBu z;+1bMZ(MDUyQ8&X(O%7q_F&jv&##Ut_5lSFk;Cc?acD1MHSgym z!Q@+czo4)*^z>fXg-iWzu{P+p^DArPVoa*U9oUQOb~ZMsYLb{#pfqVip)o+p!DeTzPmQqM?&p^&f*fK!S8ca1^<|dU+U@ROVKss)|@ymBebk{$&z>qEt9>#1FT(x6SLp65ojUkBBoq zm=f7}YAFtSEe*u}9uF^au->9x%e+LbfYXBKWV01Q(FM-9aGhbM$JefXc#+esR*2p3 zY;%d2P6HB7CuFU4W`Ue?bW)Sk_I0I&#r@qZej`34H1H+urPY=Z_nM&-I4>fnojR#w z2yCX#0B7G;W}=tmnO6;s6kD=P9HbF~`Ml2bunwCXvB3_Qfx+}MY~rgW2TI}t1ii3F zJXJohzNphTk)&@e->UJ?#Lt%Woa!Be%|#De)X^04!18yBkCm837*su{PXYK#q#6>h zH~0z+!mp=yYf6t(t_V9JAaqI|!Zm^#MC@qJa?BA>S}eq@(5d+%->NV?x?D(pzxuqpnH)3fmhBnwXlG70<#xwMT$w^ry2h|sKtBMf z_>Ts5_JIxwXA;gfz{(m@el&3P&n-~N0S>>e%oBeWS@k0ESCKuTh-eXmX#>xIy40b9 z)-dbCOaVE7+`#ULRw*a`snoq4*~6lH2;(DsU!!F@0Zf7S81GA1ABP;nTg|GY@K&?) zqVW{Q8Cc(fP0?HN_H*p40{;Q=P2j=q$C^DR_#?YKi0zW0FdgCP(AAlzhtPbA_|v*o z0r7PRtiGvRD|P~mQ+W7hxqk-&Ztm6p&CQPKWrT78PYzepfUd(JG{3R-IWfF|Apxxb za|OW+piy{v0dFBFp&@m5O1*oJ={xh*}3G(cJA{{JW0e7)5hDXVkw8UlXNlQ93QjWKjTh^Y(PYqw% z+YMVwU^&82{^wlMz|>*L9}dMAbN28`xgxE~iRP)Sl~R^CvER>G^)m6V5RQ(dy&5TV0OF zBPnuql7PSz0t65Y7b;z(ND&|@Tm(Ui6e>~$E{s4`lEQ@nH!f@-g$u(FpnPwJyz`xv zG&y28v%~lE&G)`}ge?p}3wM$!Ma+3wXnqG0pv$vFLK z)vGH+U0R$uX|Yp{s;Ssi2i2&iI0X9Uq1laFqkg?R9(AibyR&*mIvA`S8Y~d^d&40m zX0=6{w2BldL$NVYtR_n9*kGe^%FGp$4R6GcS~ht#iS~QDBP!x z)<{<0$hzJBcsQ*3HJ!HI?zFCVyIZ|kWprb|+8jP{!DeueLXd=`u{>#e%H0&a9JDj$YE_w7sUZp!oDSihmHF5g7QS z7!*lqB)w+%M9xpC(@wplb4=JQoPnJkA{OTy6=|tn#ffs(McPr;fmF%nrzlJ*LLVOe zw<$kL`85Avk&_SsX&gPa0#$owncyt>Qm5=We+XXN+t9`9LSK^~HTmzv-w8pS8l1-o zHoVz}P8T*0EdNRI`Czjl0S8WBf?=)9TyM(jtZHec$&zK_7*IeW3lz&KHv%+I9#fHd zMsOC7!#|o$0U0)gd+oD0;3%4faG?erl`9lN+xLu0=3)+jrE&T|>Zt-T;faNt9Nc_w z37I<4!oaYqQRz55zTPfl1~c$aUu!#Emsq;^ifo@K@5jsXLP~oO+UiY)Z5u2?^ckOL zBgxJJvedn?p{Yzj)Q>tTk`;q8JJe)HyToNzfI7v>)|!LmzN1 zCvvfuEY>)S8bD~VGkZa6(T{-&2bTi-DZ(WXht%3nBB|D*v?6c-6Rq>Vp%lr>1t+4H zue!tDE7niBqg9IwlEDe_;l7Xr)=PQFmDh`XgSC-0M_^icB}p~ny$+NM(R2)MS>{1J z<%-2Yh3F5_;0o?&xNuV-hpHar{4C(2&?1v?#n3bc;g%VH%aDO1a4)wD_Wz`%1CRhm z2Ws#qj=}}^Q{?=VhAD?)&|996w78(g2gTo^`Ov269x8H3RL+^*ug!*hBT1N(H!D1evM7K+7{K|b7wBMZKnYRcpG)X z2G8I`Y+S?lz2JeBRNXT?vKjCzbSZL0sq=uTar=&e}IsG%r-q5@flD4R_%%mkuqe5cD1& zE^0lHdtlhCi)f@Ee{EsslmZb_QIecC!jmnHa z8sjB-CEgBV@WU)*&Fr_t_sp@ZQ+QlNh8j7y4zmT1`%U{@@mR-@b8REq9mF2Pw)XQ4 zybESIp=4@?OwFgAPjUpLf_Qn><@ti=eS4Jgh?yFkOb~zj>wXWdRnLP_C_<1%7?<$k z55xXrOd$MzZoe%bJB*{S5>6l;fV_%sFAx7P_eFg_w;l0$?wHTlfPWgSzsPM{tk*DR zD2c~Xx;@`U}RWwRATPBE1KUB1%7(qYISZrbOtU@SET z@V~Qan_8anr!(T;ty=X8@t-j{I#lRi2XK;fo@^Rk{1-P&uj&=>mx$-C zLl-*A1>lod*q{riL1(y2y5=A878q7)$*Q6$FUh19|Aq}Tt^Tyn~F5)8i zMdZkU-wKI(7dh9?GJ;#O`J?!I(h@aW-o0=t=}@M*rt*^Ag{XEy>{iEGL YS@Ff_3fd))_9=GJ!MTE>X4Sv+7b84!OaK4? literal 1589 zcmb7FzmMEh5T5sJuf6-cibW_QC7j-EmS_>&U3U^uByNO|_z{G}j|w55*X!)<-tKy1 zd+%6;aLOwvLPtSCNkM_AD6WV^lL}o$MM*(Hkw4(1<9qhrMp4pWYu-H1oB6((&-;U- zd@6`YblrVX(!MN9QDTRMXx}bz(Y{r!Bue>(WhJvCC+eqJLAEoE@;uU5l4*ak4C81r zNwV-D%ERMqR3u>($4Q=3qfXpdC+2ZBnit_PnI&0-yyPgE6-1V52`L;RNtWeUf<(iY zrC?Ge@uRkKKk-zY&hjE##6_BsYtKisA$d+1&XQxY;1Qsv8-|OS*|nNs7^i3|E=Z{` z%!*aTjV_B8aY z14e6U*p0#zI6(uWi18-*La7zFAz6VpUI@M#{t|qx#u^+EEh=zfz=Z)<>O1Ee@wc85 zZxDa)shj3|cmwtx&FF|Cn$U;_7<)nqB10IBBWZO+^=G<{AL)OJJwSEh>KxtLfQHXqZ|xQ|m?Z8IHPB)A8l3 zm-E$?C+aEVQ)LQhG6(+P`MOi3#0@BlH)1-qVYhMfUwFPt{Et#^oA@1ATq$I_$k2Zb zpJJyg{fv?ZUqgc>Rx|0mQg?}6M*Op{#Dw@aUwv-yKK-9~3n&y-svT6UBl>E^7lCU4 zh6L{b@A-#zHP26Nb;a;_uzA(@u=){gy9j8Qx$t5CyRDjxt%MDz8|3LCi<1wdx%qAV Y?BlyHZSRa`qaw`X?PL5|Y)_;4e;J)80ssI2 diff --git a/massa-node/base_config/gas_costs/abi_gas_costs.json b/massa-node/base_config/gas_costs/abi_gas_costs.json index 6abe6319cad..72871f441d4 100644 --- a/massa-node/base_config/gas_costs/abi_gas_costs.json +++ b/massa-node/base_config/gas_costs/abi_gas_costs.json @@ -1,6 +1,6 @@ { - "assembly_caller_has_write_access": 142, - "assembly_function_exists": 40653, + "assembly_script_caller_has_write_access": 142, + "assembly_script_function_exists": 40653, "assembly_script_abort": 0, "assembly_script_address_from_public_key": 317, "assembly_script_append_data": 314, From 0ab4acec3754c346fa4c836962bcb0b77078afac Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA <22281426+aoudiamoncef@users.noreply.github.com> Date: Wed, 25 Jan 2023 16:02:27 +0100 Subject: [PATCH 54/80] Update `get_filtered_sc_output_event` error handling in Massa client (#3466) --- massa-client/src/cmds.rs | 51 ++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index 450fe0b8b4e..734b72a0919 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -1,7 +1,7 @@ // Copyright (c) 2022 MASSA LABS use crate::repl::Output; -use anyhow::{anyhow, bail, Error, Result}; +use anyhow::{anyhow, bail, Result}; use console::style; use massa_api_exports::{ address::{AddressInfo, CompactAddressInfo}, @@ -185,7 +185,7 @@ pub enum Command { #[strum( ascii_case_insensitive, props( - args = "start=Slot end=Slot emitter_address=Address caller_address=Address operation_id=OperationId is_final=bool is_error=bool", + args = "start=slot_period,slot_thread end=slot_period,slot_thread emitter_address=Address caller_address=Address operation_id=OperationId is_final=bool is_error=bool", pwd_not_needed = "true" ), message = "show events emitted by smart contracts with various filters" @@ -658,17 +658,17 @@ impl Command { if s.len() == 2 && p_list.contains(&s[0]) { p.insert(s[0], s[1]); } else { - bail!("invalid parameter"); + bail!("invalid parameter: {}, type \"help get_filtered_sc_output_event\" to get the list of valid parameters", v); } } let filter = EventFilter { - start: parse_key_value(&p, p_list[0]), - end: parse_key_value(&p, p_list[1]), - emitter_address: parse_key_value(&p, p_list[2]), - original_caller_address: parse_key_value(&p, p_list[3]), - original_operation_id: parse_key_value(&p, p_list[4]), - is_final: parse_key_value(&p, p_list[5]), - is_error: parse_key_value(&p, p_list[6]), + start: parse_key_value(&p, p_list[0])?, + end: parse_key_value(&p, p_list[1])?, + emitter_address: parse_key_value(&p, p_list[2])?, + original_caller_address: parse_key_value(&p, p_list[3])?, + original_operation_id: parse_key_value(&p, p_list[4])?, + is_final: parse_key_value(&p, p_list[5])?, + is_error: parse_key_value(&p, p_list[6])?, }; match client.public.get_filtered_sc_output_event(filter).await { Ok(events) => Ok(Box::new(events)), @@ -1414,7 +1414,7 @@ async fn send_operation( /// TODO: ugly utilities functions /// takes a slice of string and makes it into a `Vec` -pub fn parse_vec(args: &[String]) -> anyhow::Result, Error> +pub fn parse_vec(args: &[String]) -> anyhow::Result, anyhow::Error> where T::Err: Display, { @@ -1431,16 +1431,21 @@ async fn get_file_as_byte_vec(filename: &std::path::Path) -> Result> { Ok(tokio::fs::read(filename).await?) } -// chains get_key_value with its parsing and displays a warning on parsing error -pub fn parse_key_value(p: &HashMap<&str, &str>, key: &str) -> Option { - p.get_key_value(key).and_then(|x| { - x.1.parse::() - .map_err(|_| { - client_warning!(format!( - "'{}' parameter was ignored because of wrong corresponding value", - key - )) - }) - .ok() - }) +// chains get_key_value with its parsing +pub fn parse_key_value( + p: &HashMap<&str, &str>, + key: &str, +) -> anyhow::Result, anyhow::Error> +where + T::Err: Display, +{ + if let Some(value) = p.get_key_value(key) { + value + .1 + .parse::() + .map(|op| Some(op)) + .map_err(|e| anyhow!("failed to parse \"{}\" due to: {}", value.1, e)) + } else { + Ok(None) + } } From cda2bbca566c48a4d7b06fc0e556b986a9424ab6 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Thu, 26 Jan 2023 10:29:14 +0100 Subject: [PATCH 55/80] use testnet_19 runtime --- Cargo.lock | 1 + massa-execution-exports/Cargo.toml | 2 +- massa-execution-worker/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 09a5095f025..16c200eb73a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2272,6 +2272,7 @@ dependencies = [ [[package]] name = "massa-sc-runtime" version = "0.10.0" +source = "git+https://github.com/massalabs/massa-sc-runtime?branch=testnet_19#d88552415603ef8d3144c7f2905cca64b462ab2d" dependencies = [ "anyhow", "as-ffi-bindings", diff --git a/massa-execution-exports/Cargo.toml b/massa-execution-exports/Cargo.toml index cb1c38025aa..cef2ca90c2d 100644 --- a/massa-execution-exports/Cargo.toml +++ b/massa-execution-exports/Cargo.toml @@ -18,7 +18,7 @@ massa_storage = { path = "../massa-storage" } massa_final_state = { path = "../massa-final-state" } massa_ledger_exports = { path = "../massa-ledger-exports", optional = true } parking_lot = { version = "0.12", features = ["deadlock_detection"], optional = true } -massa-sc-runtime = { path = "../../massa-sc-runtime" } +massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", branch = "testnet_19" } # for more information on what are the following features used for, see the cargo.toml at workspace level [features] diff --git a/massa-execution-worker/Cargo.toml b/massa-execution-worker/Cargo.toml index fc856acc531..7fedbdf97d9 100644 --- a/massa-execution-worker/Cargo.toml +++ b/massa-execution-worker/Cargo.toml @@ -25,7 +25,7 @@ massa_execution_exports = { path = "../massa-execution-exports" } massa_models = { path = "../massa-models" } massa_storage = { path = "../massa-storage" } massa_hash = { path = "../massa-hash" } -massa-sc-runtime = { path = "../../massa-sc-runtime" } +massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", branch = "testnet_19" } massa_signature = { path = "../massa-signature" } massa_time = { path = "../massa-time" } massa_ledger_worker = { path = "../massa-ledger-worker", optional = true } From b28bd1b84e4bc2d649435b746828eba5458a78bb Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Thu, 26 Jan 2023 11:34:54 +0100 Subject: [PATCH 56/80] Fix gas calibration and clippy issues --- massa-execution-worker/Cargo.toml | 2 ++ massa-execution-worker/src/execution.rs | 6 ++++-- massa-execution-worker/src/interface_impl.rs | 12 ++++++++++-- massa-execution-worker/src/tests/mock.rs | 2 ++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/massa-execution-worker/Cargo.toml b/massa-execution-worker/Cargo.toml index 7fedbdf97d9..4cdd92c9878 100644 --- a/massa-execution-worker/Cargo.toml +++ b/massa-execution-worker/Cargo.toml @@ -52,6 +52,7 @@ harness = false [features] sandbox = ["massa_async_pool/sandbox"] gas_calibration = [ + "massa-sc-runtime/gas_calibration", "massa_execution_exports/gas_calibration", "massa_final_state/testing", "massa_pos_worker", @@ -67,6 +68,7 @@ testing = [ # This feature is useful as we want to have code that is compiled only when running benchmarks benchmarking = [ + "massa-sc-runtime/gas_calibration", "criterion", "massa_pos_worker", "massa_ledger_worker", diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 6023b656daa..713e56a786d 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -625,7 +625,8 @@ impl ExecutionState { self.config.gas_costs.clone(), ) { Ok(Response { init_cost, .. }) => { - Ok(module_lock.save_module(&bytecode, module, init_cost)) + module_lock.save_module(&bytecode, module, init_cost); + Ok(()) } Err(err) => Err(ExecutionError::RuntimeError(format!( "module execution error in execute_callsc_op: {}", @@ -714,7 +715,8 @@ impl ExecutionState { self.config.gas_costs.clone(), ) { Ok(Response { init_cost, .. }) => { - Ok(module_lock.save_module(&bytecode, module, init_cost)) + module_lock.save_module(&bytecode, module, init_cost); + Ok(()) } Err(err) => { // execution failed: reset context to snapshot and reimburse sender diff --git a/massa-execution-worker/src/interface_impl.rs b/massa-execution-worker/src/interface_impl.rs index 168e2cdf060..c89437033f5 100644 --- a/massa-execution-worker/src/interface_impl.rs +++ b/massa-execution-worker/src/interface_impl.rs @@ -58,12 +58,20 @@ impl InterfaceImpl { sender_addr: Address, operation_datastore: Option, ) -> InterfaceImpl { + use crate::module_cache::ModuleCache; use massa_ledger_exports::{LedgerEntry, SetUpdateOrDelete}; + use massa_sc_runtime::GasCosts; + use parking_lot::RwLock; let config = ExecutionConfig::default(); let (final_state, _tempfile, _tempdir) = crate::tests::get_sample_state().unwrap(); - let mut execution_context = - ExecutionContext::new(config.clone(), final_state, Default::default()); + let module_cache = Arc::new(RwLock::new(ModuleCache::new(GasCosts::default(), 1000))); + let mut execution_context = ExecutionContext::new( + config.clone(), + final_state, + Default::default(), + module_cache, + ); execution_context.stack = vec![ExecutionStackElement { address: sender_addr, coins: Amount::zero(), diff --git a/massa-execution-worker/src/tests/mock.rs b/massa-execution-worker/src/tests/mock.rs index c068ea846f9..e5fff335d06 100644 --- a/massa-execution-worker/src/tests/mock.rs +++ b/massa-execution-worker/src/tests/mock.rs @@ -95,6 +95,7 @@ fn get_initials() -> (NamedTempFile, HashMap) { /// Same as `get_random_address()` and return `keypair` associated /// to the address. +#[allow(dead_code)] // to avoid warnings on gas_calibration feature pub fn get_random_address_full() -> (Address, KeyPair) { let keypair = KeyPair::generate(); (Address::from_public_key(&keypair.get_public_key()), keypair) @@ -130,6 +131,7 @@ pub fn get_sample_state() -> Result<(Arc>, NamedTempFile, Tem /// creator. /// /// Return a result that should be unwrapped in the root `#[test]` routine. +#[allow(dead_code)] // to avoid warnings on gas_calibration feature pub fn create_block( creator_keypair: KeyPair, operations: Vec, From 2322fd52aa18eb59643e6dfda510a053efdfe698 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Thu, 26 Jan 2023 12:36:16 +0100 Subject: [PATCH 57/80] update setup_test DL tag and commit new SCs --- .../src/tests/wasm/datastore.wasm | Bin 6283 -> 6142 bytes .../tests/wasm/datastore_manipulations.wasm | Bin 6840 -> 6699 bytes .../src/tests/wasm/execution_error.wasm | Bin 2796 -> 2230 bytes .../src/tests/wasm/local_call.wasm | Bin 3429 -> 2982 bytes .../src/tests/wasm/local_execution.wasm | Bin 3367 -> 2918 bytes .../src/tests/wasm/local_function.wasm | Bin 3749 -> 3274 bytes .../src/tests/wasm/nested_call.wasm | Bin 2911 -> 2770 bytes .../src/tests/wasm/receive_message.wasm | Bin 3958 -> 3483 bytes .../src/tests/wasm/send_message.wasm | Bin 3087 -> 2951 bytes .../tests/wasm/send_message_condition.wasm | Bin 3996 -> 3272 bytes .../wasm/send_message_condition_deployer.wasm | Bin 2547 -> 1306 bytes .../src/tests/wasm/send_message_trigger.wasm | Bin 3436 -> 3016 bytes .../wasm/send_message_wrong_trigger.wasm | Bin 3405 -> 2985 bytes .../src/tests/wasm/set_bytecode_fail.wasm | Bin 2680 -> 2539 bytes .../src/tests/wasm/test.wasm | Bin 5376 -> 4817 bytes tools/setup_test.rs | 2 +- 16 files changed, 1 insertion(+), 1 deletion(-) diff --git a/massa-execution-worker/src/tests/wasm/datastore.wasm b/massa-execution-worker/src/tests/wasm/datastore.wasm index 699ded6b4226024d5c5ed7658a770338591174db..6f6917aff5976855a7fed2d315ebef27ece4cf33 100644 GIT binary patch delta 2435 zcmZuzO^97Z7Cu$?-uLRhx__Ncy5rn_-F2T)o*|m}*MW>+jx&ylA;iTf!p!hYGCfRQ zCoyST#UHrsFoIx%!Ezx(FM2>QgIP4_B1#rnh(u^GE@ZNZ5Kx9NG&5Od5zKs5w_8Ex zHTBLcL=ce*W0t$l(`e0?|4#bK?2A zS0pL1IT76Xax8ySh^RKiw{9o5ZwCj$y}YdWnzFBnH=>3Ua`%?I$p{#2p6$!x5NuX7 zUyki(aw-IO!+tBb)?X=+xj^3Lao7-3(e4Sp++n)aA>x8tP$1H@B;!d4dzzN2A&H?} zbHWN%(nUyE7VS!EBb^mBBy5P{a6LXv6SnFmtaQYggf1-nT@e>C}26}m4xr$c0q(H zOysLDp^1h*OB47k`x4dcgFV26{Xc2L0jVI7Dqe>!ZI1UOG@hu2B&LoT$KEF2!I*C( z`~~qN?p#(THZiM%CCm9<;8AnH1h+Jq)JT_;CkWXjl$v;2Cc$3#Wr%0ct3nwuWHGE9 zaK6RBMnHiE)4s4awLtYwfR>&tBg_j7Ot`PqRp1)ojO5R3AUhpwOfdVCGq@0FV;)Q} zG{Oy!$xPap31-h^E|$j%MgB$bm(i(sp0YlUq40&PU_0wFu)C=55?ko4=3IH(^tTUvwHqkaRZPP;YBh$hR0|IB> z+FuqeaKc0$_Mj3vG9kR((LeeifGf##rey&Rr93N)8lw9hqh{S;38SBYSK3@lPeKh5 z9?DVIE({r1ci%FM=FlYmdf*Pa%_>U-j!Eqgtv#C-^Wno7(}2IHQ!wSl+&y{MU!Wm~FOagL05A=h|d&e^}K-J265-7q(m;cb{7@`_zk zyF_BU@ouqfpN>!B`}6o7eE%ojf$y@jS1zUY51k_rE_R+8xm?P+5Jjg)sG*X)Y%9IJ zNF!cOHIfIZ2*>?S-#3yLS%oJc03^gKWs%vx>FqVNkwH6(tdNX1%RP^LqufdKOTr`I z6@t%9aN9S7ioiW)IO$@SuXS-Ny^ zOueha$7pt?`!R4+frr{Xd^izA>kr3R6E7+)9wB~T+12#Hc(swPD66u2;>B2t9oUQQ zk+iQM!0=LR=duSLf-ph+R!55v1%p63+tFGOQHZq%e|(|QUj>2Zb$dG7Vh`jUyONH^ zOR$CVthRfyo$6{MUAG@)yVO$BY+0G_P*))!hwFAazk6&k^#{EVBG6or*NM;Dx%`wm zmwBi2_TTvfS zu21oNSLe=CVa?MVy@-T(wb{GU)gx{XPdNRF4%2ZYirqErqMDob=y-o}X|kzwQpYYi zXC9+cXkl{6{$qTbT7!UA-L&6~Zx`p@-8z2YsT^kbEad+GqSPT_oB|)<@K>Yn`eP%J WbP@59yiVhWIuT?3iG614!~X+yTCL6i delta 2572 zcmZuzONbps6s@Z6eqG(w-LEH~nP|_a`WfORjLF1LqH(}?1vT-5ih>*A8RH0flYd6V zp!6sR14bC^EFvmo;UbGH1UG^M21JdLMRqE<5Om=pU=~3|9>#O4Ukr$E=)QHU?&sW3 z-JZX^^qWXk`7gY+*`UX*ThRpmht=Du0~u#2#IW z>qpg;zY^0*eOPU%mbJ_nwG(1QjcGww42eN31mzSmS~lwJITwr;E|?@%whbcE4IUti z^4Kb3*K)X4SgYaM!`kCD`K7F^ng(RNM8{hw177J;Aukb}wwk0k;#)_w^%|^J*`U7% zewq{=19aqQC83*umvhvz9wP>UAcJmkdbDl91NpmMKB$7icjCGRpa4i24Py=(_m241 z5#5l)Muf^-6I^C4O+sG@nq$ADZG=<(SV3x$Q-U}=6iRWSf(DZ#uxM4qhyoiSjb7LK zHrnHNEz+DvR`yBuOU|6DP3a-svfn|@cl#9z>$x@8;Nc=*o}b-?DbWp$jA9w~jfZ8x z^8*ofNz2!$lW22nn<4a3PE_ z)@(!-Y=(vmEPM}BV6$pZk++ZyX^l&}hglFfOziq!C0O8?tlpt=tPqQ|aUYe{HeP5Z zK==@Rq7S&|9q|n)6f{#V7kUg!zHUBRvu|4v9kB}i!l$L5NVo~=?^?UoT+aG;!H!42 zh$E1t%UOL(xK)8X6;3mGJ$!Bq7vG%nc<7-q7dp5f+$T%*)$l};SQXGunZaZ@S)b55 z*QHi*Gy4F^{V5mw7(id@S((z#6`-Wnak`@?86-d{&EcwddWYLL`B;^)D<7e6ub zaiOYQ=B6VMM5$=0{wv;+X8|px2H-(T0e5$rts`09E-?cqx3EWD@7p0`DCoKD%Y=%dNpp&>d({l^}%#9 zZ20ARdp3LPsxfjLM&VHkA$&Z$@JBy3`vVa8T(0+LGkP^~XfD(rW}8MYgMs3oAQC`R zBVPm1`iJa@KAAbC)Af_>+c#VU1G(=r6R`t@XI9|eeDZ$#l#B)=MveP$@X6gHsjok{ z*~n)Fovj~R|McVl3^bRE8=A<)2Zh@`TYtWO!@a8wbD=PCFf>m01AMdnYhl{F9pVu} zBCY$-kvM~y<$BF%N1q#a%%}C-==98w<7RROf}Rt{zy!sx6M5EbbTh;`;k=)&S4P)u zI@d6tPM8r64POWGqSz}Ah~r{j&_$fW(f9SYqtlavMs#`7M2v{VBg8W4M9$Xv*hYO3 z%pA+ljcs}6;@6i$(dNDj`tU6W)_v$ONf zo0;#;%so8(*`c{U53qj5s@LmqXP}PGo#rWiJ@56~3xF18Y{=+-+*xmyWOgKLUl^O5 zhHXx*Ha+nkxU4U+-I1-;u1=e;POnxQzj*%q#P|$sm$lmEnVHGj*|94Voaw^Eg^QQ3 z32?E?%OVg;Y!7hA|Dvn#5u#I%fi^ZbH?3FgVOntMiA!bbRseDbR8W71SDggauZg32 z*cvJHLW~^KcCISaX^v?IwBl*U>gnRI^?*J{+Hb;Rs0usAsaOmF=$lr>@@QS(w@z;5 zduDZuC$8RRk8A;B_P0GZ9LyRgd6MEo$Fk#slRvj6`58uq@RGY2`yw=RRLv(6lHW*W^cl4H1h~;?PklJ<`yA+ zfYhEGx8p3~R7I#jpU95q8*1t>m$T>>xI|)x8cKheeMzwTHCr_*=bphxUv|&pg8tDx z$ZyZP6-F^QbX~~+B`xVsyrXR`+?q1R8GAUkm^RK#G2N%$K+ZTSaMG@G5r{!4z2D!< zY2Ne)`Q7jdj)$YuQK2Ht<&Z+dUVj`N!*%^l)MuN4 z>c65=eXiR~_D`UynJmqfOglhjUL=w>H%MB5iM)(fotArc0@F{~&G`fg8JDbtKk(*l zd3hVzDLH}JN1GM0lJa(82&myoJPsD!bM=Snp!aoR($B8`O6~RO`p#9wl|`r#ywWZd&KH}pojWa{*t@Yk_0`}R_kELQ#P2(vli)@ z+X@yY(ohdhwcbTo5|BK}6%PIO;zth># zvzi)fe58dFyDUs*gHa|k+pQNnCnq<$6V|gOSug}5mUA!x*Wd~aa@)qev khJGl?U2kuh!i4c7XiIykHYTsl%^ry-fbRC_>Fp=~0WZKUng9R* delta 1768 zcmZWqTWB0r82-g4!TOurH!)FGfhx8|_x9 z2onQB(1KgfgMG+@Z&s8d)CZ9uf(Usiy1uAjz*hQDBtoe5@~|}iXJ(rgoaM~f|NGDR z{`>AHPkyndxydooG=-zU(#yjsD_s8UIeOh65`DeEfLVqKmfFEKrp-Z794nfqj!mA1 zbymH8dg67kX+KMHf3aS_a9V#`@6_uj&YV0saiReOqFz7OXiV0RA3Hx`u)?W{Q)kXy z14F<^Ujb=4R*N3rQ(%fTvEB!GAf5~hA&7px3b<9x4u zlJOKhG}SHh@gt93{Lsdhjor9UUnB)cJK+d1v<1X0<|DkbnIypow__%TGz3_lu5o!- z8+WngswKX`qHj&{zR{;<`Izc6ss^#E1ID3_C+`>)-g4B(##jgV)A&CA(qu&)OGYS%$sYaWgI=n@YI!)j;t?*K#y2_AZHW@$pKtz12T$in&M0SokuO| zA;1+;0~i576E(oF>2&}j12}%>q0x5fL=G6(>HriRmyDXs&~Hg6BWcJ$mSwlpVFbb9 zpf}+ zn67$4=o<#D9(V$9A;%XV!MDILSc6xxN=_iyo0J@Nw{+II6lNS(!YnyyS7qP^A$0iXP&k^1(;}P8p?J?wFPCfA zf9;xNPPpD+8SJwG7WOMq9^tLt7k(k6ij=AwrLREzm2L$5}nThn^9reOju zl7IVws=biw7wJ|=I-3^xx~2$zr@yQE&D4AE3V;pE{c^=MRy5J}4X{ eNjv=t;Eh4yaxK%t9l+azf;|OzZ&2OpKlC3+zfb`H diff --git a/massa-execution-worker/src/tests/wasm/execution_error.wasm b/massa-execution-worker/src/tests/wasm/execution_error.wasm index 12fd84d7d03bdd493515cd133a240a8ca1af7e4f..494313affe78cda18cf446f033aa957d3c338bdc 100644 GIT binary patch literal 2230 zcmai0J!}+56n-l@Be#m-t3u@ zL01uxI$ge@Ms!1uMrwo|UL=cdcq9B32#=MY@oC;iZpqi52{MX%t$fW;zhhWZOa$R zUN>p=sN%EO_nSZ7gmn~ro8|aa)k~208oH{gh1p)2;hkQ!=Qcq(k^IXHN1fS z6(NWp)rt@i%~)3Rig#_DCYHOlUDsw6Ve}g6rX?kf9IG{N6e(71A7zfig3|@}+HCXq zdvg&ObQ^Blg`eiJ(>yj8Ay7Dsx`GJ^)qHeOv1wcDWLjj($tW~+2gpnS-QNa0V2V_o zfJ;X*3Xu_9-UJs#-U<<73p@xNJP5foii$CSE)8h06eA68=OE1LT~rVJ@j_fAPo;{*58OQdw4=n|e!u3!5(LYo4&t6kTM(z0R1s!7e)nsRm-V`@~KPWD{ z0rcEx$>?aAEc6(~smM6Svp>o`WS>izHeE~`$O?HF?&m>q3lvzUc@_GYq_GWESgIr7 zg7)gtX$PlXLLRSfaEh1)xmCzfsIJKEo{~%P3-Nmn6m)IeK}<XKhUi1Y6u%7@KZRry_P2l+_CWWvYCjbF(?>E$>;j=6&G002 z?;z72JWmoo2(0pmzXk#KU0|)m@vv6#@Ds>^=V@Ty5%~$M))720Vs7Bc@G*w%=ftlA zdsS>NW2HbYXmg5OM|$7{MGh*ptb^V}*D_G);4Mc7=xhXef?OSRN3{G5$bjU9d>0UT z_8*XJ!9${V@jZpLR97pi138Q8YW4&1oyWQkRAS$9(FM!EWy*kN6LLYwFX4xrzts*; ztX3G58GGzN&5&!X v^K>R0^mnpm`dPAtAM?%Y*FK$HTuSez&7Hi}@5O1B^|Qr0_-|#gn{53Fvm&FA literal 2796 zcmb_ePiP!f82{dzncdlav&le8i#`^z!nrK(sG)w(^OEjX&{*pAGYW!EV=!o( z#4G76wQtu4&3Aq~FMrda{*tGt#-(@uOnRM!QW#Z+wgtDX&1DBCUNtz^n?9 z9x5g?Bz`<*ikFLir_t(CC8*cC$xZSxuVY^-*6W*HS&fzI^=7Z#PMR5wn|i&UWv%*B zV~}{N&`CPI{%uX6iX(NZe6KS0iBiGP67TNq?RnSyIlf=wMPP8>}(Rq{pes2%~s&lb=r^OdnEz5b~ptkMW!PJ_#1!#?r14sM;yZ1ZD9TT4l~U z5`27ZO2-QlzA`^5^AE(Y&#iB0KnU*^8yZxm1GGE-tOwfX`Co5~w9aRAo{ z8jEWVxsW4qv0{n?7XUzaZr#?K6HNJmgjzeJ7H;E0Tm)H_R#l`BcWr!7GMAMaS_MQ^ zPhvUm4_O74aDZTX>AcCw0O;>yfa9_tHgzgmNcL_SXJ^HVQxa2Y9Jo@UxGafrA7p7B z1}buLzBp7Ia|w*RJRfd?LD_}*6anzx)AG2&-x6OG6pX0jYj}N9asw+qqktqsp7kX_ zZjxd|qF~O|hc{0)FA{B|QMB{^e}k(I zGjOD}GP>Q2x;+w>M%0gVdxXKD;=-Cjnw7hDSkD2=kP$JQ3EO`@-*R?1RO zR-;b?2T431>Y!|ekt8_A3QUv@QzYKE;ac9E#dm>Jd^{K@!d)~tI#aDbsVMDVBb0#Be#xzApW|78zQ>&YOE*t{#dMx zNBL;UMYJ=123(KcMjj%8-upjpqd1%}=3(I!@u#6t=ZHTG&1pqMCory1m$s-uZEDdn zqTZ$iC##gv4dNZhUnKr6G}9t~7UPbST%uX%^zk(4HZ9R6t>8(ppMmB8_kFIpT`~v} z(G&(lvrRo}LMMZ_9{gCWdU(XI*jt4S-YMl?OXg+KJ^7T^J~U?GA%oAQLvOjpcG)AM#+~Uj*8c*Nt>BOV diff --git a/massa-execution-worker/src/tests/wasm/local_call.wasm b/massa-execution-worker/src/tests/wasm/local_call.wasm index e7cbd30347c663b40a13cd70665355c1503f0463..0762260d49f3aaad366f0c3d20a30e4ca76c6c16 100644 GIT binary patch literal 2982 zcmai0J&YSg6n->#2-M8l4X?HCs_r{e^0na<~)rR!8HC8sS!NGU*+| ztK3>0Tjvm$+jMjRCF4};aCQZl$Mw3=R76zf(R$7M!qs9?4RZO;i5#L;}&1ajz zR&QfSY1r)!%PZ7`+{QR-cDt8{(p!kT-L=tRP_9*!+irJURU6&a-lR0Tu~lx3##c2( z>PXyF#LB89Q72m0(&SyG!l@&^v$wZrUJRD`dc;3RT<`-qkv&cw#X-NLp>bEAw=Z$9 z*`a>NJWZW|^NJT_vJ=A4118y|52@sC@V4lFnZNNxKPu7xOp7 z57+RV>Ys$qC9k%mqnXalgg;e$vesFGL)CZsEEKgu$*uNEiE1r)_Jqgwk8G}_&ZG;%>2_C!cy(k3n4NPuh19Id7QV< zM`Bpb`jUJ->l^fq^f@S$)3PVLs1t4$z84h+NMZryi9HCzh4qe6DM5b)*{Z8<4EWb$ z-c9*FZhEq`3w>Qk`Sg9Zo$(;SEe9wi$pG|!pt%8%07nteh)e6}UIfmIs1}KfQKNf% z{$i-NVUT(9lP;8PCp~Xl^q*4+y0gpAF)Wt}JS%zIEX8?)HV`Q0C zzYyAde!+~w1d0!bVCoe1E`3bW3++(G($2MQVT3Nx(T8*}mO1D+v$=1Ko>Vnz!I{2O zQaCPi>5@)RfG+cgPME?T-%)(8r#2HP*Z`R9M67rG(LKz_UHq6=h87jJPLqpRRUHM` zK5MVE!B7NT!JIHGIkVF4v<@HRU*^ZyaxUl>E}_0u8(Ac|Yfhq~!2WSz1n0Zy>j@-2 z2jW^d(1Smoi4R=^)e8bdy|L1k+X(v&J?ExS7FQhtNaVk4aLLJzTuZJdB|A|r z>Lc?l7i~&SDQBODQCgozF9M4p3?h+|E7TXda?mnVW#1+KVBqk{Vv!{ZQBu1?j&hR+ z1#!q0HG$$1MToN`^)(wQjF=Wx9u-&w)BH#32;TGXD8HZO%D#@|`15=b zbPJxN*8bi&L3}N;>M7z6BYRpA(GnWd0MCfls7DoTpf`k@3UUNF!0ebVQc3)EZTn+n zPl)X?w70RoL928cIu+g%yf0&X3UY#Iu~m;ET5OMt#rX9pmZI)p?{lu)Lr6y_Qu0@kbCCebTa4`~+xc@$l!Ee+m9u zmSrCQ71-Af+7P~--{lY^@mxU)zE#KzU}6j@ti0jn1Z?p&ct?~Q5CHv|{WsA2KvzM` z1w7(@M$fI<^0u{)2%JSUp=TXBZz9+T76NMoE9XH8QAos%q>h;E+wCW!0x8?jTK^|W zw`#lFiG4`oIkbH{(HDYukeHIL%rV|beF{HIZ6P*C57_MQZnmSJpbbiXOYMSaM`#zY zi=ohU2Wuezz05u#YmcExsR^y~@*AKp$(4eX-iWramjQI@bnw@i_y1#N<8U|bW5hX-RD2Gm85}q?`Qf5MuKkf6~NqE7kZZEJWpMQcAKNb@EkN_LoLPEL_jc0e;#zVfYES(sHKypApNI>9>#1RpJ15P?20(5e40s;agB;h&!3r(24M)Y0^UnyJ|ZGn>r_OS+(EvL_jIA;K}v%HmvH0$A(0+;Gc)dUDVGJoT-3}QtDpI60VvD0#Z7Z!~gM-EaGgC}9 zd=cO5+T`UV+Uj2(Q8(`OM%6V+FmGd@C%xX)k*p46z25qGIIPxd`h)HDCUt$ex7MFl zMmM&qt?}f#rc@ow5=E@6>a^5y^M}0izEbhb5#PIi|GqgJt@4K%-^sY(CvqZtgi6KH zpwy5!IN_iQ=cdQG88&Si-=Qe2_OvBknarCvtvDop$OO-NJ;!+!@H( zA#8DrqdY0q%gCt3I!_8^9Y7Uteu~1B!t{gGZ>D@F<%9hE+$Yc#Z;tL+2~~S#nV>BG zQm5=wJ_-Kg=8Dc=7xtY|0cz&P*%q1fid&**sT+{$Wi=EjFT#H^sR7hM3 z?57BqKonAI??zIsd1-~<2u!%npSQpd_~o1v;mfbpA@3RMr<&k`MJT`$eJS{tvr*Y8u4ZU=7KbZ!7a;t5RbTGabO|(Lo_&pI~p$B1d)SP-?#WN zgo{E8O~MsJ(-?$XX8bLK2abTf+%Cv}Lkk5&f;bAW!Dk$W3+|`L`6&%k3yeW;xlhvK z0++uaenH%VtU_Lpl|fcB$C8|pN+3N6$xpE8d^`vbJqH&oc8RbDh0Ze+*k36?${5o?4gZ>q!NJ6TSx;vtYt+-&UHPIyg(PZMv_G0`$A-YL<0iT za+5~|dJx+^6+T6PMfxB#Sz*Vtta6LQK?&U8wllsyX#s|FQy3ZQUcJs*k zC^$fU5WWx{evmbagSv=wKf#=2g?{c|2uy`Wfq-xb0g%i$rSNsP3xBfc!k*PynstH8 zDy`7NsUHa^dFuse#Eh z>~B1*ciUR^I1t5eFNrk5IE4>?hy6L?yVkOtgS^n+!5I0-CE5{ m{TO08kOh}Rwq>6dqYh&?NC{37+(9WSy0(DwgLa@u+ZLj8XphcAFx-Z; zq|>%tkxnr#0_>3l@g1H?N^SeBJUfXYC6{0qG#Fwn;0iHhHKr{9Clm}x@~w`y|5?Xo z?YVtL{1r}N`P+_tQ7k`)@q1wP5trDUz|S72@VmaiAZF`+o#* BMJNCO diff --git a/massa-execution-worker/src/tests/wasm/local_execution.wasm b/massa-execution-worker/src/tests/wasm/local_execution.wasm index d0bd976d3af4bedac56a79aa0cde3890776760c9..daa0293a636f886abd9e1ab5507b5a408d8e2507 100644 GIT binary patch literal 2918 zcmai0J&YSg6n-T;_E*xS?ADNi|JGS(=WU`w=Z)=t zy8ZcfH_dKl^Vjpmevitg7Ly5#Can-W3_`V{vVN!8yn_qFw6HM{w3ljzn&1;z0^`1bXpo3J3G8`jf15Ybz0^G zwE|9Zo|45@2tyY*&!Gc<>;s;r|ns# z1;w+iD1Ic~BQUU&bds=TB)n$W1kQ`dX{V0r7y^rlGtjdal^N+-`R!G8tu$G(OdKR7 zBy+dQv|fczj@V!Y$bewH4WHPxx5P;zNbb3>>PC)5oCrL!|1GuXlJ74iVSGy9cBKj}tBlIsqVX3LJtp zf*C~YP-Tuef|eE!G3%t%)V3f73H*~L4#xiJC}FGc>V*&)h*#)~=Ojuh7^5((#$zeI z9*+&iM#da8mD7?FUepSgntl{D4Ukj>lqYs83>Ov|qf>&;X;iD|x`DJ^h1Y8Q8kap; z+J(L^qm1D{B@tSTv_wr>Vl3dXz*BP-l)}uyt}bT)g-Rk+nN_DLwE6mi z8HEKj9}dCDDda9=EYg`qD06vEHEh!eU81A6>0mBv&~avI(-`Ewn=t}5b5FqNM(+#g9Kry6ocV=n!QP*Qut1`Z`t zl&X%E9a_qS$Vwvf+7!G82yP82|I~@^C(|BCQr>0lUnNZLL{=Rq{vxtR6cNqfVd~=7 zr+I2qPKy}z;3kLcLw2z`pevLSKQ3&aMs}ar?!og3_7`c6jzA~Jdx-aS%nw5j5v^j? zK}4(Ay<)K&&uMsHg-@|t@cuKbT!H>o;)l=&y6-CXkm&E<5hZKBske9*4 z08&`F>g5n@@f~{lNYk=uMz=Am%cD;(koev%>PZwFd;wG#;U60XjDktPcx; z)rXbypoAzC;(lC2j5qBz3z37A6=*HIOwzN$?s;tAlz0x$rk&^u!K)}tMmHuH@7H_@ zAJlA9Y<6w2+01U7(a+EZC4bcHlxRnIE+dPc(6x>|kbk?rNxrn2&^l?qF2<6327SqW z(v0)qU>R9;u~QU=AJ=`Pr*&Jg<46jhEm%d2=XHBR;=haM{|ej&Lh(63>@DTR*B(9% z3z{IX&A(6CeG4+ipOye3c`Pf1lqtSrK2NNAj}9io{`J9pcD}uWPs1x8UOcz!@R4nw OpoeeZ>-z9=d*yEksr_;Q literal 3367 zcmbtXO^6)F6@FFKJ>5MuKP@{1thJTuUd35sOUfab#2CEK;6$=)41pX&Yj(FK@9gZ% zYNoZaz+_Aypo0!R=BPs;7oB`EMg|{3@WBL~Vjp}k zzT3CS8%eZ3*d0?ZuBvf;6Ny#T0iOFwRoxiND$lBFdomi;+YOzvRW)sz-D+zvtBr2$ z*ZY&{ElsI+MhS-k+3;=Z^T{qeqX-x%vN5fLX z;^`qDT<2)7q+w}ZqcY;W;l6B^F&tgwjEnae#|-&{58l7d`C%DjH-2+%lb9~TBwj4Y zTI~)mnw++ml@=8LK91s_#AgHsKFNo9Tp9_l89tHoQ|h!+FY68_Z063u&W>;v zcR0#hrFsJyby(-ELRkk=C7Pe2Fr_&9aq4$devtCh{HsMw!U+iD=%E#;+B?exXNi|O zWuNy+@Q?O3bpDRe*X9Rp{s-|3;Si^W=a9jMH`~zZ!sbKEA1OW;Y&PV;q0_Ixuu*2N zH|4didK%)eWSKYy6p+XQ#d6B60L_!flqa4M-<><`aoRHIT5`ab%(uIte-lL`W6=?ffLS$`$7^}FXbUu zUN80y)<)JGfobKHB-M!b3Mdz%DGY8|=0SYV6^nxk(I2AWCEU?);if%L7{VWqM^T1pvqsu0`~|T z(m*aobBM$EH8$zZHBk*dcjn@nEm}~3w^1i-@C;7G#HX^8_7 z9W)n+QB*2S;lBP+@sB;Vk%&|P=-eU=^so+QDP)4IhmsfMBG*WgNPJ(2?5AizP+D#Z zXymLyY7e@3yF{CSYg$0K+y)Y)B<_A%HD=lDAho0I6_Ae5uJ9>nUvQ3c1rXkuGp65iXM!D;1(`e@{B*h5`qXzKmwLL46qa$ zCn!RD_Mb1?CXPZ+mQwh0BYaQDrB``$n!oGj%Kjd`oWHZV%5@G?*caNP$K4X=g#siA z$p?p{6ryLt25bvn;?H{6Ii-$<=5Km9J;KekhLj)ICDfh#tgjOq!qM*wd|jAhRr{6&5`UiB zb7KEI#vi=p7F~eP6t4l@qAj{XSMjRxd>)=Nd`kz<+nK!}o*Nhp&k;>%8$J!9O%TUn zHNi{b%6Zpt2H(#@)Xe@=e9s(v6Q;al36_6pynQlGhGSdk<$%VB7fl zD&7UNWGIo^AyWJM@{lLQY@ikfaNsl3w-66xAPd`=(pd4h)fu$FYXwlCHx##N9#77$>|cjJ^Px(|0Tx% zqHO?#a^@7VkCBES?%fU!a2WE3+x)k_%@|9Kv4f2IwyotEe>x-nPv5H7>7{%&xiQ_Y f-yR&`m;JTh{r0WX=P#W2AL9H?{CjkMe{k?$(=Iw+ diff --git a/massa-execution-worker/src/tests/wasm/local_function.wasm b/massa-execution-worker/src/tests/wasm/local_function.wasm index 51ccf225167aea9d7bf6be7eeb7129d66e10acfa..7dab755e1c0e7fabcecee1e98537dc4efbc3d935 100644 GIT binary patch delta 661 zcmZWn&ubGw6n<}Jc4ua1ZGs+}XoXcPq@ckcSWzrEq9>0cco25eG(x0FN}Bous_Q|- zL&1hY@DQOF(Srve7Z3RZiuNQPa`fP_2l3*ef%vwiAozyI_rCYu_swDE-O(?_IjAf* z5CCvmCYVA3kcgB55|*ZzCV)>9zRQs)yTf^{`M|5px7roJm=x@%f{{0*xVO@*g6G9?v-S`;;ZnT`zKr9QW>!fZ$JN&2Vy)T%W#YKq>D1%- z%5sgP->5ZO?Z*rh>JW=TU&>8HKaId{kH=$vQ(UzhLfIe6{RvB!b!;zmUs;(E?66V>CwZBzhwe6CMd7~j;l4urqZo*p^natw_*(Sh`9%&P z8WXVy-$#%aS(#@>Km>*Z?&fvmsogG2g9R({{5ab6z``g1u*!03&|sGBPZ@2&$dEzA zW|<(sLxjfs&K1F~DT7zQzEQ5?pVwP^Y^dB@e@3rqgQsYw-5;-{h|uDuc2b@z6PW`0 zGB7B>_6Uf52#m>|UQk}9V+YhgrQ2;KHUK4Vefv-J**UC?V~^` zL4Z<@M8I4iVkFQp&~mHJ_vh8Tm01I^3<7NTzkB`%#9VBEzOApX%L^)BrUj3dy(GXkCyTmq zF`hsXQ$Q+|`>1BorfBXF#aa%T4%OK>PPu$ zE7agBpHb7#Sp4L&b8H|>=JX$uKdm*msVRnx{MF<}V@<7bH;=^g+Tx0>hZn7KejDhk zPTn|mZ#76ueGQUQ?&z+^g%tC$pgoHbY)81Af_@;AJ#KO7S#AvdPoWmO70^n!)Zzxp n`?gc#6`)@`ldj;B;m^E~XPjZPKYp!0TeU|VTDpA>v6n`_jd$)VDciAWqDO`wVFHSH5I}|8I6bU~>z)pxFAyHq>_Qv?^`|#by z!4k?vNJtbE6iB2<;W7n9L`9K;0wD?nDG;Pc5s4;6iu?hV%3Ag3Vcw1&f09iObT zxW3gKE)7=ud2=Ppo4tN>E!!GW>HlSxTX~D9kU4hH&e9-jeES2VX5Wo7cOtt3}P`Qg3}dTgvH>X*LIWzS>-D4Kq)bI$5VT*wPfLBq}RnWt53k zTKTqWzECO{S>m1D-CggJKgZi4KMpzNR}&(0k{XKrc0)trNSpf`?5{Pb-SFO_hR;dP zhvcvkK+*cvv%wm}Oq*}r`fP)f%|?LJ;9`A_nC2l8j5lPAvECF}W$COYtIZ{)C5or} zqxh5fgoJ^cq@9!+p19Wx9p5?Tqa|SQKAhJoyD9nQj(@upD9G7qa zdyRa)=4?lrpN*XcrhpT$M)$g;i|Ceh-B@HRmh9wBupag zQAJkcy>v>C_a641?AcG1)shoF)Cks6w+mAbkwg-d_&*Sa4T_A>R=>S~(iRXIApGr! z@5OwK%dS}322NRe-FB_9o(mGSWgmT)4nY1dnkXO=#F0kh!c`0Jj`-G*upqIG0I1zv za>$JMSBd}n- zwp9WgTeH<^9Rq;2=3a?MASFpvWW=IH7?12Z|?XoPR!0 zyg9rAAj}Pv00X6LOK5yxOF%CQAmXKkx{MCw8@QT#sWO;La3G$a>tG^DMz$hzL`f#f zhHZ4dV#77Tl(OanC{>I1=!kE?LLn3?y#l_lm4{XXD%&=84+D=+F4J19;H7FtZrCL{ z@lxV|4Nw7ii73c95`>L8Gmvx(sYw$|OT7a0Us*k0pS^!bnCW z85tj(@kqJ#o)~{xn znlp-srm>jT@$1nNwJ4`m?7Gm+L3^O*eQE$RqWKN34ajXSc--J!kTXyy{oUB0p6XN@jM|8hLW=7;s@ADwGiwGss z0e&sont0lQ=5gXLD@OTfDG0c`6=TGXk97_|zF(X_0)d++mH%?HXL=E-T*EJet8qei zU=W&jjd?>1Phm+y%aHjL$@HL+J9-UY2~bi)=^hn&PhQa5D_xE>`jA@wcUpJi!e4A& z6Mq(KPfz5fB%3H@MmHugK7tO4{vj_vx2xu`NCVK+fz4G!j)Hwx z-2MQf0DyvfST#`H@@xN5HhONbtKfw5#nmM&xaHPd7{xpwiR8V1o*`I1gy-WND th^6Ud*t*>}F% zI9Nit2npmOMaq;ZD5($yg^`euPzr=nK|@EIf`Wp=lKI~3ovk<#x0-$PX5a5O?>!y0 zM;nTW)NJ*p8mlp0bkiG;@z!JEiEjE}!IK*6Jyr4Y&F!GQ+#ePc1RL$qsNKLT-&pSL zv_>n#^+C~E%ZpZj(CX$pBdYwr%xb%66O}TjkK0)p=ItVf)v3hU;}UE6WyM8_f%yg-{=o_G==I!R8_>vs5n-( z_G3N%N~vIMiT4i<4!rCBWquIxlZZ2ZH6=3VsHxcRG&Lknc6hMGez!@TruQB-eNGFW zk;7&HMeAG723>}k4&S@?#TKXA%>bvtwZ>&)x(bnCvLR!P^=8Q`OBXa*ZLTXVQ9OM% zirmyfWF@LG}l!MlHp@>k} ztg+sfZdAt+ImvH3VMtL{Ew9PeSQSkVA-P+-(SUapHIyfSVQammMl(F#nSV_?v&v}~ zFwAVBzElJFV_ro(kBS2N=a7W7tS9w^JUbs`u?^9q&E#;LWOZw7B1p$r$x%0!gXkU3 zT-eIiJ57VJ6CaJ8L=uff{n*$^aGD&Ao#Zl_2o>hWj=|XRY#p^2Sh$`5VCzc_88FD# zILti^jKGB?o)2{}wu06>G5=bhB@~PlJh}q&%@Btu9XECz zC}>z9hlw zb&|`p2%RCGHtoisl>^L$gPHT7gahZ+-Z&*!A&kt}?@KC_#@}ajsWV4oDEj z{ltBJ2%?C;Ex8{O6D5!fv2cq2cu5^wizPqQ)jyD6Y&F&@tkg|S3y+_Uh`*^D^*-_U tAeQFRQUCUECI7fRz<T6n01V5+Ojln3$hM0KnKy zF^5#-Ip!%qs&ZbC%EJ@cDDFs^l^2|e$x5{ba%t!+!cuxN2dM*8h~R(_jzmB=6gd)@ z9Oz?Yyb;fZ;dAp_4zl5+MKB;#DE48E5nkIGFg2$E!~GBcA+)j*phsn%+xWO8CY zljzQ7vz6+i03S_=-MZliTZnER1MMChm;*VghH1s8AHLOi+-Yfj_}V@ZLr3d{>1zUF zNjoq{qDJ+C{UZ7W!=C7ELM&5M_PJ~qE5olDdG7eWM1OiQm+iaeI(fOb^huwpX3g;;XjzopbkYq0DJNIs*ixit-fF zOHHt^0mvuG26haHe_p{+ux}uSSPTfofDFd`EOrCceSh-Y*ic6oV#MV&YL#bew$OY{pH;}R%b6q zH5d?Rjo~TKhOwi5C0Gj&i*JPXvwx{$ml;R?4o%RkCs;1>O$+N`@Cx;E(TGm&x>{U+ yr$ZHNb{HJzE*=$P1pflz2 zQr*r%zg(Vb%*|D&nvh*<_Z`oLI1v01gijIOI0AaTy}d2Zs0q5^Q`@IMfez#WH1FhV z2Ni9-w`~UTW;}-?rjS%#9>kNJ7?Q}#BI<~>jS5JeN}b1?9mGA4+8%vCW1RxP1VIqN zmgcNTB+1rsa>OVvLOp1Afc9P~iTqbqWpJF@0X+jcoKhmJ4YA%*a;_x2^bp<9^efU( zdZuKFwMdKun1?vty`HOm&O#-FVw%BfPck;^iL$KJS2T3R=BC9@GIK={3w6ZG^ zw0=?3v$34-z9ww)LXNN!=?5+WA zhNj^*{EciPV>4_1aXMvX3pS39EQCx-QT4>$0W4Q57%mZ3XS6%|Ssy z&}|Qg?FL?XcWGn0HC!I7^^4YOUbHs*t@V6+NR|J`th9?ZQHgovu$|>W-Y#-jogj`M zMhx@bN~@d0iPfB{rI}-gLH)s6uORK!6Y|JI@Jf^ReLqlrrFDQERf+XTF_{tZow}*M zRQ0>cn*kK9Z#^5VGt6}O{rBIy!s%8sz;1A%F;7g3fCS?S8Dp$> zf~>N1R+H7{Ri(v?zYcow3-ROP2EL@7w9@qCc+Jr9trMZuR-M%`1U6Ia0cYlvIv7#J zKSz9qUl^P6(<-7OOS=Xhm{ZOTKDs`m(@RLemqy?}5!FuLqVdlY;NSu=M54mB3GGeg6@0>>^N=6Of{>_NLjQJ6+x@2h^IAx(m$5qmL z&Pn8!eb7WI0Q|2sQGh4#Ba6m~OUl!o@U0VJDPkLee|vl6h#c|Vn7^a4?i|_(U&D(H z)&+%LGNZ5|d|LEJ;4?0Z za0}x?BapR>#fHf|se)kiAq>{C2aNUB_mwddqJj(7>sTekv2~lw=okdFb$6j8Q;6{c z#SgjE*2NVBfJ`<+)?4mc9?r;v{Hy~5MVTqfWJ6X(Q^9RlwMz|TD1=}BBw_euz4MJ` z?eG=-V{%0er{ew874SxtA$}HiiS_=SY|}UMaUSTdwh? zI`z^xBhV*=f}^RUI{5dR6jtbl#&Dt0)Y6nu*bYC1Jx}~b^Gl!&Y>NAC2?gVu$pT2e zaFmZO-2Ak%pcejw3$8ab-l2FlbiVn;I zq4=(_@QA`fA|{ELKdYyK@v&t*Qf@qt{|IACiE`{RHCcQKS!O%;~yg;O(v=o?z zFy`-In)s8@s27Mo56x*sL^Bvn8+bNpnc7s)8fHD5S3qt;ZeVvntCSP}Q0o2`nvsFi<*bt5j%i_H^qp2gVL6TGBk3#rWM+Qi4(&_U97Vv~u^qX%^Mqnnf{DNB@? zV}h<@3}9^;V-1$!`z;`l%DP@V<`t_7i r3&h_-Sb8!YZeATM=NH?3{777V^Yzyro;!X2Z`8SK`1w88ZTJ5HYnuw& literal 3087 zcmaJ^J!~9B6n-y&i2Om?DJjj zHV%b3By8msYDZ#*6owscjGBumgn|uxzazWnpdo?2c7x;u%sa9 zbw;C33tvTVe)U#+v@l#Al<&cj_CkMkwOAr9TFX5#uNgAFbtJUfsyB2Dg3Hu;;4`bx#WDM7 zJy-7_qL_7B&y=yiQ>;1SS0se$-O#@Y`F_X;`OS$sxoh}G#iuHsX;Ij<`V1InlzJo`;!}fP zax5RZ|9Fg;l5!kJ1Lv z1uLt`Ued28dk=e0_UvcCM102=<=#pb$S%w@5RYK9R>AFvZygDdA?GR*7If!erUHKm z&k^a}n4g8alJT1L1a1&83gR^ZKD0GhU?0UKNQ3`(+7W;!@FR;R5eJoZM^J=v3M&%Z z2vxehO;YZHZ_K|?1u%y;!rSn2i*+f0APf&^YpH;sa>)^Bto#XVg!=QO{G&OPIP#oE z$R?|9Ca}3^GY{3Kx{|o_{@5z(xxJL&g;pSES?60u5UqH$@Q7(F;lWuJc&u94dx4!) zL{02=ttT0mmYdcw3eEbi?OaX9{Hfxn9kjl4MVP|8!FpYqSM5jSAiwIE!9`iUN|SA{ zDsvAmxvX7j!8&>X!V|!-wccDS5BE3npF53Q=X3=yOkGEPsTS}jnKq|TQAqkR1R)*n zNj)LX?zt?sAzC_5cBfC)w8kcabc~hkHE%VyUgylYt!%TK8%(KqZ%QQ+Xe{FUrc{F4 zWN%6(XVFBcFgK+Prj%!!sKvm-^aKFgoNLKELcGRd?qR+J&Ly$DD}ym75!q0Nlaff3 zZFG^<&^A`8sZxIzUZDo0+8yx?CGk}K2~w$f-ms#^B(9 zjWl~z`XFa$GO7ew;}Ui?+tzztGCHjBcq}eo0DD z{5Jf30%`E32E|QC7~e@|VPp0XADaEZwMuO%V7LUT64qn}xuf%8av{duK$DbLbMPU95-LGw?TI=koxY<}?X>=`PTa_7z-*OK zkSPhmm0OF=1%aNu}kW`7(*TW&pjgZnB#v}-2cYruy8lAhS0Wv zwG7PwMAhkDVxk1RAr@}`!0m^`ekU&ES*e8 i{TsuD;&Nwz->OR=ym#rDnbQydR-Uu_R=8)DJFN@0B`v=zEYpC8w%k7yt5^J}fUHfi0 z?zLuT78Y77y_wlAi9(3Rp1`Ta(J1Ix6AHl&GW9H3(1= zeFRaUmc6X_(>a*mb%ci8lu=e;(aF3_T1jOA%S&j&NJcxmRQ40_9nFJ0-mkAIDOLS$ zO~9g;ImYRWZ`Cu0m632(XX-W=SmT_mXD&Z@3Z0yPCmt!|DNeeXVEPBtQ zn-V?5a=V$2q*-WW=Xk1(%Sk7Tc(B74mT;LmCN$AW)U0u$|Igt?PRl$fq?3iOQ>HoT zoerjoL$IKbI6$Za8jX#CUl zqyjLc3GGCTlS=KCHQCfpd=NnL8MkZPqcSl81au=in73J8)sQ;yOS7kgnH z6lfD;tpMDP9W6#}yy9C{CVLan^jDmy14{g5#Zt+Esxe*q$xD)KlH!a7Hh?{oiObw9)HWSRNNj1e9 z#ulY3ONq)nei$2%pXoMbQVtAA5pPxv_RxsQk;_I-u72~IJ4utsXI$JGFY&Ys%r)Ma z^2EdsY7K0O%`}{7{cUB8_?pt<81Z#gOht!-yM5^wReTyf7hDUpIEcHT_*FL*1Q>1v z#b42(9Kv4WtDzPy<^lrgt59o!*U`m!1s~sr9{wAl9MlW8QtoeZo^bViFcF`U%c{M6-MdK>c z;xa0T3MZc5f4f@7-l*!Djba^os9^>Fc?);2+^!aD@ltCmE-klXJzy>I8+l@Rh!}5l lHG<0E*gtH*mo**E^(B(1;&x3Bo5wQu8Tpt7#o5}Ce*tr@Dpddg literal 3996 zcma)9Pi!1l8UNm!nVp$^v%8Z&6cLB$%_c-H5Qn5tXsCq0P^XQPG@?+I6PvX?Njz(> z?cK3Mq{tf~5IOXaV~{xHfJ6^PsyHE(Lr+x?70RjN&_e|m4jd2?oFbXu_h#325|Hrf z?VI<__viQheO~GgR}~Sd@0)9Cq(;~DNWKY6jp&*;8jZh&NY{LvK_Im)jC3s-jke{p zy)AV8sj7K-e=F!NtPM&EgVpYE*lpu0UtL(a-5D+pme`Dt2yA` z$f@ofI!KC?Pg?mgQQ(nRtNDRiS6T-i-qa3wBgJH@FXGQzCY%fXG9Q+7DCl(h`7MN_ z(^+5c)8Vkw+3d^H7vfH5acyNKUo7bb)9DP#a=Ek69p;{{t>&w1gWH-S^~E?;#LB3H zi8@*T)!~D`P%0Q%;wL*hJKiOKmhZ>>IOdGMoD!Mi)K=^lZ4Hh?1+QRw7&Ih&||16`0m|18=P*n15ktcsaaxr11!P#fs8TMJ3&@idRddz=91Ea z;_pwR_>}mVz`&cdNNa6R%xi{>Z`~GIZPm*-4IGug;I_ z{3qfUD<@l1=t!s>HioKfnjbO@$8zr?SOF$Ln)E+*4c z-bl~N=eTNWrOA+CN=>E>M_dClLNB4-> z3h5&Attv;lL>>^DOmhl0zrc|q|epXvqqG$P0f?(p%Zoo_;4XC)DHri5J{4jA=TY#R-H58`B&Q53( zn^aF1reIZ=Juqi}RhFRMhmw>bX6~dE#Zbw?brsg)q9y|V_Sc{ zfxNS>v|tOQ6PYs40FO7<&_@JGk%f*vGSEL7LYK1DoSerqB3DW(5k3#deL-%uE1{gW2Q0aIN(qQ$nIP|N8{1z(&!Y2 zDL}(Cc_>$eqs$8hazKv=BJseBBsw21YzP5K5m54?u%7cmne>49m#?Fd+D=s#r#jR8 z50iROoKflnz@!IoFX|rV5$eDJ!WAe8{puzZ+kO=^kYPq}>%#hC25p$8ZC`pX;22$i zvE*kV5>B3UEL6!mPcGW|DL1ZB{y2l|7wEbyV($dX$%X|6j3nZI1LOn2_zFO&kjo_$ zC%73Ta+bzd5=QVpiNETGnHUyerD$!FH1P)w8PfkIo)!+K6DkE1@L{eaz$rK24P2I1 zbQ^AdImtYASHXCs%l{bF!2gJeU9^0DCs=$U$oorBNYfhc@F?$dY zI9i#PNK^+2-o7jLx05SY0#x0^nG{$6_u(~iE>l?WEgI5qy}k!+=82~PFzu8AQFGjM5AjP zpFeiT>hpJh_ZR;>okvkvg}2sE1LKn=2!mFA4o1){kIw88`*$z-i-m6DR!un<9R{ zI{hIrvB+pFsQ3g_Y=2HrOQ0OV+C%odAC-=K4HGBejIf~j*A1iY5Wm+jx#;)_)*LdF z(<)Zq#d6}K1#Q#i!y+F!S-jtLneO5&G8SG)-1lq?WeCbmWJWk{!(!8U_FmJp)EGyJ zHgm*ymanrb;qu24C=?vQH$8-VJ^h5d%ZP43vi!Re8*j&WtETXnbSCEAP)*0{@ zc=H;)Mc<}*NG*Z(4kEk=*|VSutseRQ+k8<8OD5k*n0G^Yl_WT-zKh=2yDw_~m!w?YAyx cGpG0e$ixr9{?c-}yw;z&h2P{etKIeg08pE&EdT%j diff --git a/massa-execution-worker/src/tests/wasm/send_message_condition_deployer.wasm b/massa-execution-worker/src/tests/wasm/send_message_condition_deployer.wasm index 42e22ea9b50532ccc89970764aa6a040fc997e22..4adf0b4baa83cdf7da487f3a15a56d024c0d3513 100644 GIT binary patch delta 806 zcmYLHziSjh6n<}Jc4u~HB?~DciIKVW)Kesa30FwaJVo(WXJNUQ#4B>i<>#pg>ZY); zNMYDUBt=R^Q`+SZxFSU=u@TY=>9nv2#5Z?}yUcv^z3-d%W*+l%@O@l`>9sZj0G`tg zEU@4S8UPJd@COZ1aBTD92+GadGZ=1utQC<_5Fnrsfn*31Q6PaWfDWwHx3p?c&n~L6Tn`K@SQiNc2U9krEjxzjuk!z>5$#7bPLqExqS7GaRysJc;LuK>C?5)D<>+ zd7Zmg6Y2(}a+tPk`7*3N@R_%*6TTKF6)k@ePXgMv72oevS;dl-fV~j|eNL*7>S1el zIdAFGL%W#Y?P3#Z(@rIXp4c_ zhuB)=*Qt11<)3yr&ilJ@`Q4m9d)RmVj_rVV86F*I!Wz%C!8?5=TRw^^^<8G1ugieF dhkC-B9S{F;8($|je%xmu*s_&abmf=m+8^z4nHvBA literal 2547 zcmZuzJ!~9B6n?WmcY8Z~@uEbLh~sE>6Cwk#jRcBB6bZke03k$?kZ5SmXWz#7e1E>% zI9Nit2ni{Li*%$+hlD5)6+$Vf5EV*+sM67-ND(B;i157`+lOs@nw_1Q_w&7`ELvB+=}2sOr>D9Xwnudc{x- z6q`k_B;_BelSf`i6;fFFp^vGOcw@z+$Hd>)b@g&J=r-4SR1X`CUU7>mmC==e4%)c~iKA^EY;driQ#<$Hp*-NU_umCrPo@;^XS!J1^EdC;+^jRAOA6uXG((97Gm>wyq(4>um?@1jk0Y+&44D>~n9`~M zMRFZDyYv?&4!0o%A?sR_m_}(0DN*fAB?{Fc{ZptCK!F5cXNpsiONv^XHqW-LxAl0U38&9eNIA1D0ZqrypoVgOAD37Ff46AB4#g%*-{-qS%7NkmfM6mN(`nW&Az2PRr~ zjH%pVR`@#wJAZBwg5nbs;r?v@?=~rTT={{{%C{+mTl1i0?=Gv?8LD7+0uA zo7AKZtx*e*I#gh1l}h@I_#xyk68{?MIgvk$aob8R(*ksc_%&&Zmgy$lz^}l19-1Ru zu1@oAO)rS%ECxffLw#C-P6=;)_%V3v<0pQ_-YRVH!;w)>DR?R*1I!7LGqr`UOl|1UoA;gAaA-B@?ybDDSc#N#A0 zC2}%={nlZXQ;U8`Tx9C9YvDlPUE%)FggJNFYk zC3Yf=5*`IJe}^;J`Z3X&oSnd!U^^7aV<-J2(K8}_9OGU1DQxT#gRyVGxLtQXF)901 zQb$YU*!`j5ey?j>yhI*Gi}-IWjXR`EbTJ+EZw^ZS5`my_@me67e+;|)#w)Z g5L+$q_0nstm23T8qg4z#{jFj+e+!>_^WEm)U-#F~UjP6A diff --git a/massa-execution-worker/src/tests/wasm/send_message_trigger.wasm b/massa-execution-worker/src/tests/wasm/send_message_trigger.wasm index 54b73674343d1ef0a4e885615c86c46145247591..8cca53b6a30ae4af1dd8d3569cca09201adbef5a 100644 GIT binary patch delta 966 zcmY*YJ!lkB5T1Fvd;4~0cW(tH7!%z)Lb$|`XoLh}0(oEpB4}kH7JFyBA~BcWQxSyK zB9J0Q!YfRnkV3&iQm05^c}UR1DxyWeCdC!01The2?^N)Pc{ATPGvCa6+%?*3ZGBK$ zt{?zluPkDM2_H}tNgDA9MI&j(07Wy|7#u@;W1$;y<3&CRd=MZEFaZHA%d~I-g|G}p z8BZjrfD%y80`Nb z=lT)LameI%=JC*|^@-Y*gPtop0u)3LoT!$}TF5#5o=T>4eY5 z#GeTr=C2D4w;*`2M|s~IkGu&kLgj>Z9ty%#byp8rd4sXOYfS{~bAd4~5*BK>dfS>5 zN3Q;1eR8A~1za6U{V~&vQvb|cI{lBMD994Gq%vdnq+rz*`x<8S2m3Og$M)HjYLhoT zCyxc;@ye1*7v)v)p7gftwhk!0;TPF?X3OJ9{Qy-+Z^$Eapk8WndXgTtEh3(}t1n(g?bMw=+X4k80gjkTxo*3??`+B)CICm>Ci# zYa=_N9gF9#Ny1T3o00|)^rk!D?6sJEsq1c!v*r-?ao*9rZb35O;+msJXz&h$4p6Hu zp~?HRWAxS~LjF0MY$NfwPXE?#CC0%K delta 1317 zcmZuxU1%It6h7z9?9SY|v$GRZkVw_pX-qemF2U2dcej! zc63w+Ou~j6F&~M38%aNAt`!-{-v0i+_o6>98(OxteThG;Ri~f%WU<1kkXZb*mU9O- zv8c4xVw17ZlZvX%ueR`Bu&+Yd4rNrHN{I|E2nb3jqdfz!OqI@VgL4L`Fk>^}Zb%Nj z)mG_(ODO8fb|kk+CM%STd((hxmv(IxRz|X6%BJlQdzm@~!{f~NRp^q6WKK>G zld9P%^^PCP&DegaUKp1Bhk96nhuG^36|Z{#JbEo|E3o%o-tgzM*fGHprBO}@Cx05d z=I0({`kGci|t+ijM|9pOzkIaYFPs7)Yz~-#m3InXAT|cOqMhaTpY~h z`WXe(@9WQTVEy2U!#W2uptAsOq|?^ zP@VimGF8^>mGp?}_fSvO(yI+;@i$4^SpctvnXsL3Qe92#S~ynROwvTQ@k%}8ql3mH zF4worej&G-4wN0JF<;b=pe>={V2%w`mL?Mxv;~`T1C<@W`)~{w_8~ zQkAqG8||zV7D~MymlfZLO^a<3<&WHg0${(uEQU#l1?L@T-zV9%pG3WIr&0Rs+TAEW zdOa!aZzN{K!D0l#!7^Cr(=5qmb-R^VF{9)7k7_hvkYTwWy82PmXu;8?bB^TeroCbo F{so$V^d|rS diff --git a/massa-execution-worker/src/tests/wasm/send_message_wrong_trigger.wasm b/massa-execution-worker/src/tests/wasm/send_message_wrong_trigger.wasm index 0eb06a893b95df19e8c55ed59f732894f7547d28..037756ec7fbb7cfe4715313732c1f900f0aab33f 100644 GIT binary patch delta 902 zcmY*YO-L0{6h7z9-@S8Z<_(kuFYAqy%2OgELBR~X&=VqP5x6Rt%-%xt`Ck!4Ly+L& zEtCrxA>p#1TDNdfJBwFIE1?!fn-(ryNulsM^<6_;T8`7e2L{Xp%RoTeHZ7b&#u~_DDJqaDs4ZVQCC97` zk4}JRCCNnjE?DHJ2>VWw+@8pGfk={($?@^>$QPlsN_0IeK}7l)7wOY&{^VAD~VgqeOgiZ`aW~vQW_gJw(SYNeD0r{4|7+@(0ZM*ulHOO{cy=#3I+=>FK4!Qnh zcOuun?K6k}#bgxZBvCS%^Ufe6)p_Rv+WLdjo~!xU`46T;I|jAk>$=mF6&&H0JrQG( zc{Bhg;uJr}-b($7w_95>n|G5RZ(8+er*=UVvw5k37EmkN6&>lSAF+KGAcBaEMHm?w zpc@NWC}|neq?9xO53CnyrdrSn)TJ3(F{(vZK}Jzr85E#I4= z2t9YD%+yS>K3Zz65nm^VpuRQGPgjbpijk4{K1InbNc~;56<(48DZPc?Iz)(8-L-PiBDLv8dg_#O#FWZ6Sk@hFh)%?1KS L!YhIP zMJV1BTF4@cJcdFSLc6rZg}M&ZMHgN4Cv;J|a3Q5o7Yelt5gJL)+<6K5hI41mneTk( zZ+PFn{PXB2%q(6&0Kf?~jU|@TqI6#@p+7n*ri1>(G>U$|$c8dNKnWN^6bKOgyCai# zQyovm;f0xV^U#R8-TB!o5b?gidKP!Pm*?GSNOiksF3!!(o>_vItih4JyHt!osIhLa znfyMKeSsL2Ind_T)>iON*r7E=8_K?mpGE%k8y+m@P?TgS%%TFP7-L9eQ4@8J1aArO zTj)3WJlQvrHYDw$Lm7bP3t$F8ki({CuUu5lZe!=1sbr42zib#N`=I_Y1a z@v8cuY7~j39y9ylF4rC62~gW1n6JsN!yc1kVmY-JbhEL? zjaW4Uk`(w+y9x8evznW+$OAvuN)0+WY#UB+LxszQEjhp7%snIQHNl|fb}%O}XU%b* z@^9`r(!pcdCf#{GJEUyMu_8rBijGw4XAzUGN{w#-eI@Nl)t0Or1^Q9iWi{NIfsc93 zz*RU6m*FE`v#jrjC0OK+c<73ssS0oEfL>{6dz)yy%{{Ki~~HDX*;e5nCuUR8HPv}c7Dj#Pl2A=GU>^O^~&d|eVi1X>uH6*k?Mw{ mb@(MtbCJKqe?;{<8*&!+;m-nn-mo9&5B~>+yXltz diff --git a/massa-execution-worker/src/tests/wasm/set_bytecode_fail.wasm b/massa-execution-worker/src/tests/wasm/set_bytecode_fail.wasm index f425ff63861752ec585b58223f96fae51a77ccaf..aa7bcfe970fe68a04b0352eec261e30c17aa6753 100644 GIT binary patch literal 2539 zcmaJ@y>A>v6n`_jd$)VDcUcsK1ZSezixZ5%4h2dPMZymeuoI$4NYv}Iy)nM?`7U=G z2P4Eq2qX#$$`meAri`dlBMJm55KyE*qDcW#{s2qP@6F!Du|e!=_RYup{Jl3%OYKol z5s{j$uBfpZuXy9}m@uUkJ(e}mijOUBj{P(E%LSgdQRGl4SAj-rAhm~AE<%S zI*^S@tjCJUjEV2pP4!aM@3l9#sTO3}c76+PX4wF1Q_ZrQ+cJxzEL-buZRKkP)lHTS zi()fdZI5zKReE`^Kit(6szy{*#LB2BRx`D`vH4o5U~Gx^4-O8zEB+$i4f)TIQ+_oe zGN-Af*zdG7I8JtWaD)ABi#jdu9cuZU6nsK9TLA>EZ#^4y8EQIw`}XHIIN50h*bOc> z7l~;JEWu<##u)3(l2w+@YqHv0QChtC`=}Sc5uXw_aFTQqzvYQ}&5-e}Bcat+o!2o4 zHWTZC&zyC7`Ni&>POc%M`-UGz{4??Er7o*F^H4hH*yeON;dx^Cd&To5&m1hMj@1{y z_zPeY=bXYzP>5)f0Khz~G40m~&T$1B&?mt-;)5R^g(ZnCoiH482rexeV%ABJYEwo5 z0G^MD{fT}$PdF;IIwDc~q80q2IjJO7%z+}S$y_p}Cvy*TPv-2W%4&%TA8G~N)Xl=w zgC~(VCH9ZGVS_Saq}A^%1KP4ghEgLD-;eoat~#)^4Vo2v;OeDyM||r@Sd!RAD5!%2a+MkJlbC-Xz9?onv=L6jt4-DgDnn8tuz351 zY~5;c$q{HQ{i)jsrQ$6@t|0}BL?snunN=qh*j#>rjKT)8i;5kiKvDgeW0Nj716j*h zYMRuOEC`Q2#)Gx&fya8?Lt)H(_=sAtUdJja9NVz^LGP`7Or`E=o7U4b+!vB8w!AVICC)^iK;SxQta-PXO_K09V89gPm!kNGsA2oXZGsT0c@guEo5~ zsdHP|N~aYZZ79--q?`cY(T3tlH7-4CDBdD&0V>QjlmHE-YAZ;5U@NFz03hs@<)*X_ z#2Yxwy;K?WB^VIP&t%Y%BqCdrKB6QNWy20KU$bFXYD!u20fg%1eRRY(SVABaD!D>^ zVJa7`fvW7-*j)@Pqv4WMl3CU8T6VF^z-k2$+L?vNMp%PM!@^p6|3;3+9x73u* zi9=~A&7N@wcH-7m4qL=A0s;ISi&PynR}uHWjpq**0Vg&_3uEc89b>r^yBeJJ3zQFk=t}-Jl z6XFNphj%|lW?uNu9KCaPA%<265)MQGs-941HtNE%^1<+V_d+?56b;V zATaZ|_FrZWRj(qH>v(gRngp~5g^;{w%p0P37DEDB2hXPnrVok2(d+n%gAy8`dsNCj zeopQXx&mPgz_tGGu=e88UTj_ydlutRPWT0q9YC4Wt*MWXAOp}J$0ik-SB}UWMmJ4S z-9dGyZXyHD5JR~im3oY+#gGT3`D@*rSua{TA+udnu zMBE|>Ie5s?qkn^V%uOggh!h09c++DK9z6u&=lf=pwP`WK+wXgCzCSXdnZkas)#BdYyB&t|)96IDEO=k<)BXMMlyZ1gufq`hWL9(jtCChhxvpax3o zKrU*r9xEm@CO&MM`t`cM)85`C6Xf}B=RW+*^8wCrJui)XWAc1h zmfQJyd(`n%ZKt!-AMR@k)ofH(#LB2ftXhqS&G;Log0Uq&J~=t@Zuu*G81dtXQ+_oe zGM6Y*>=&5^$Ay9iciHb|RAklOR>b0#C8#h+mNqs?S3IKIF$CU*LBqHVGPF#?rA7SG5xs z0%5TiT4gS~Ao#`Zf=+G=d<}lw;9rQ}sFYY$EFyvh$F`uu3D2S79~3WEJPV?*u=*+( z4?;B~NH~S!J)nad#D5#6;|2idEGRSU6^V>7{O+(!p{-kIuZhM=PEJ~6ss^(p*e)-fb%fsm*K9Y zux35M4+M+?VNH+>Z4DOKM|B8v;QyUY1>gz%NTW%_L1o<$RF#~i6=)9B_1G%wxxLiX%~l|1SvOin5UqH$@Q7(F;lWuJc&zG9Utkvq)MB@=o@88l zXhFxQ9P7J2azz&N*NR_q(E835VG6Sb>pkg4bsmum{I+8T7p3(oO}4?R%sjZ{vUa-# z>nLgnPXNQ#daJE0Jl~mro_1!PlP+MGy^H!%E#OZwJ{D0?K>regke2nNo)Bm8K^of- zJ(@Mo#z{J3jcp3jF;;WhjnyD}hg0XavNJ_yFm~eU*l9|jv521=J5Ag+r(>tNf+j+R zxv^s~c04ZKGR_ ziTa1|3N;|r?uc(dArK0cT%o?Ol}7VXm4&Sdt468F%hZn*tOO<`ONmZAb6a_1rj!zu zM43V*q}p3SePHzA0H0kM$$Z7xm(DH=04^2851QD$pl}e?B&v;%lkrHo^^;Qmn2($D zgv?3hc`|Vj35Up`n}5zbbPn9aXgFCQEw4{7n)0oh~}_XX_xk>O+DJCO@!T}4sN!n zq|bLdiR{IvtPUZu3=1V}uAf<}Bn}$pO_7+#lDIaZ z?Q`hvgST|_4t~XFiBK#xDoc&$#V0l@PsQWYSWn}tBoEBg;uM(@m<*tQ^I5qgW7HfF zMUjc8KGsz{{6}?v35%FJ5qu!^bWYoVm+~|DV g9^eaW>(fs@np;}_?-yKtr@h@7h{A#JET{=Fe`% z6hWM&P{={3GKUsy!CQOiK`I3g9)wo{r`R6 z``)zQ`1Q3TG{3$qh)5hQ%!!!hWE_haJABA4n$s~J0(WIj+1>Rcr$p}hrG>cIBc#f^ zf|MXhT05X3*Q;W|WU>$O_Mpk1ar3SELVaA6 z>@M(XwT0CS7wQWU^_p6(6-A4+v-9h9C3DO5<<-_DNv_!Mi^Fl@-=3Z=A#!m@ytBKz zt4`|~zUlH4mmd%x3Wy9eL8Gd)qz?jN0E3`m#)YtzynyQQw#SovtXqf- z+4hr)Zh8*7B|;Ur$qoILaFR)9=DELq$^Q#y?78^mu=kt;!c87JV}*99XwY^MIEl#( z#oL8I1YS@GWJ=MOK=RGfUZMG0;k5Z`c~laMjgvU;tX|?<<*eS2iiX9A;A`aybuF)z z8x^T$P_vxHDba+m=iU~xIt~Skh7+oo+d;-k%X0gfYI6IQI)#qO2K<_tqwH$#s8bLK z3{OSC1cZDChb~w(j7eqE%0w!oz^SB&R2R{eCh!4NC@KVCGK}r)hRPz-U1SvMX(9x- z03l5ALCCocz9(AP90x?vVmE5NBdno?4#PWY78PWuE&sGziY);dWYyVIgbleH=bK!J zFxa{gI=q{2wt%A>|6l|QB<-?6WOMuf^GFYV{{}x5tyVT;wjF=~qSCI|6mWQwqJ9zS zIdEt{$%0RlL>*}hZ2+`TWi2!x3S}=x|I(-o>;!gqYVYMvZ_JN^^XZk*_AX$$%JBpH zm*6L_j1$v{2=Wyf_!S+>QK>7oe`$(J4!*gH!r|bM?cK)AXR0%px_blmYCa|&OA|rY zz@GqzA8pt(vqM!8DRPP5hAIX7>}8W_l2E4{JM01-7pk-E!BlaA0$t`?gRjiI#?cx@ zB3(ViKMalF7F*rzN=_>*1-+-3Nf%bPeO+R_t z^d}4Zh6e8XX_PJBcs7c}0=`GS`BEiZ9KHSXzC}^kDH=J5l+TK{r;5Jzt{ybvQ$ReJ zobLPRzz(=UC_w~DD`lmXlArn}y!+r#%)?UhSKsS#2OKOn%cj>R!_SVEX`a^c&ZD4m zRuBks-30;Et+IL3+Kym-Oe?eo%SCEYoz77Rzl+$nXqC=G9zn_-_#xxwfEl)agIHJS z0({QWp$RxdFkeKV^E8hAI!}1<`NK@OJK*5{ESc^vC!hD9sFcnjf_xPSORJPvsZ delta 2551 zcmbtVO>7la6h8OP&zqS$rPJ0w-Ya_FP_ZCCf{Kx7>_J747#5niF?p2wOgg1N=>tPF zPGi)tU;!D7ELfPhfCVu`HpH-SWmuWAamB`H6cb`x8qV9Q>4OFmx{@h#Ph?Zu_tOA?oMVde^nK-zAe|Mrs51LNraIZJn**8Ah^;9_Boj!Q@n5IZQl&XzM`T5Y`r%DB- zC0@97>z23MALElT&&S;6RT+_4O}S#f$Tc*E3O+Q${!~sy?!830&smTAQS62{HtVf;w^sKkLU zS&;>~C;m0#j&GfathQ>aP9boZSr2+I-GzYBY@03?yymiJxb1>Q zAVr>lxy&MSrIMzR>r0ud1a+l2P8X>w9m6D|;EuYI5wf9Ug8=YIB!6sexVr_861*e= zDyzXcfs098-@StYl$4~o8CFO|*{DGCeH%?VqA6|THN@pQE-*mjeGsPHh(t=KfCVfC z!Es>&@P<2W$8NTy(I5|@5Z6#23?>mN^RZT8$#bpcqm(7Nm}&=np@l+YgpRg-5NM+v z0&s{{pcW!AuoQc}qkK!vETHeRTA$CK*sflcw1r2dvv zpTt`__2#%SPm05lWe$6AbqG%0UE=z-yDP@1VFZd_X1V9%-G+y+V~+%G7=z9bjaDxX zw5l)}h|i`*eMo#ht!#2IKHKNi&i7SklFg4?#}3AB^qE*LX}nJ%qrOW&C8t$#V!-HO z9~Bz7RHmsPUs!3>JH(e)R;RN!A3o7^ch5j5;tLRPf4N!xlWmG`Vu#ZH)vUG-JhA3% z%W0l(nE~+veA6@%o5eFud<9>jd$rm;*j#_J-u%@vZBcFF{jWB-T2#9RUs(x;tmA%{ R`1C3RmaYG`S6>gV{ujr0yKevh diff --git a/tools/setup_test.rs b/tools/setup_test.rs index 790a6e86e65..cc84ccbdde1 100644 --- a/tools/setup_test.rs +++ b/tools/setup_test.rs @@ -26,7 +26,7 @@ use glob::glob; use tar::Archive; // git tag -const TAG: &str = "TEST.18.2"; +const TAG: &str = "TEST.19.0"; // 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) From ebd9db79c6a0ea221fe2eb090de75d5f8fc42d87 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Thu, 26 Jan 2023 13:53:50 +0100 Subject: [PATCH 58/80] Fix local_execution & sc_datastore tests after latest SC updates --- .../src/tests/scenarios_mandatories.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/massa-execution-worker/src/tests/scenarios_mandatories.rs b/massa-execution-worker/src/tests/scenarios_mandatories.rs index 0289a4f3693..758faf813f6 100644 --- a/massa-execution-worker/src/tests/scenarios_mandatories.rs +++ b/massa-execution-worker/src/tests/scenarios_mandatories.rs @@ -436,9 +436,11 @@ fn local_execution() { &Address::from_str("A12eS5qggxuvqviD5eQ72oM2QhGwnmNbT1BaxVXU4hqQ8rAYXFe").unwrap() ); assert_eq!(events[2].data, "one local execution completed"); - assert_eq!( - Amount::from_raw(events[5].data.parse().unwrap()), - Amount::from_str("299_979.05275").unwrap() // start (299_000) - fee (1000) - storage cost + let amount = Amount::from_raw(events[5].data.parse().unwrap()); + assert!( + // start (299_000) - fee (1000) - storage cost + Amount::from_str("299_979").unwrap() < amount + && amount < Amount::from_str("299_980").unwrap() ); assert_eq!(events[5].context.call_stack.len(), 1); assert_eq!( @@ -1068,7 +1070,7 @@ fn sc_datastore() { let mut block_storage: PreHashMap = Default::default(); block_storage.insert(block.id, storage.clone()); controller.update_blockclique_status(finalized_blocks, Some(Default::default()), block_storage); - std::thread::sleep(Duration::from_millis(10)); + std::thread::sleep(Duration::from_millis(100)); // retrieve the event emitted by the execution error let events = controller.get_filtered_sc_output_event(EventFilter::default()); From 99b24b74a0d00e02cc0b5e12bca2d9cfe3dd2a3d Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Thu, 26 Jan 2023 14:23:52 +0100 Subject: [PATCH 59/80] Fix gas costs verif job. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51cdaecffa7..7643818392a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -154,7 +154,7 @@ jobs: run: > 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 massa-sc-runtime | sed 's!/!\\/!g' | sed 's!}!, features = ["gas_calibration"]}!g' )"'!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 && From 1c138c1590c2b5c58e25f1cf557f4c4e4e02c452 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Thu, 26 Jan 2023 14:56:01 +0100 Subject: [PATCH 60/80] Add the thread of the operation in the API. --- massa-api/src/public.rs | 3 ++- massa-models/src/api.rs | 2 ++ massa-node/base_config/openrpc.json | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/massa-api/src/public.rs b/massa-api/src/public.rs index f1ce0eabd02..6d35760487a 100644 --- a/massa-api/src/public.rs +++ b/massa-api/src/public.rs @@ -490,9 +490,10 @@ impl MassaRpcServer for API { for (id, (operation, in_blocks), in_pool, is_final) in zipped_iterator { res.push(OperationInfo { id, - operation, in_pool, is_final, + thread: operation.creator_address.get_thread(api_cfg.thread_count), + operation, in_blocks: in_blocks.into_iter().collect(), }); } diff --git a/massa-models/src/api.rs b/massa-models/src/api.rs index b084ed1a99e..1b76ec6ddf1 100644 --- a/massa-models/src/api.rs +++ b/massa-models/src/api.rs @@ -118,6 +118,8 @@ pub struct OperationInfo { pub in_blocks: Vec, /// true if the operation is final (for example in a final block) pub is_final: bool, + /// Thread in which the operation can be included + pub thread: u8, /// the operation itself pub operation: WrappedOperation, } diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index 5968ad7cc57..e2610d0d777 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -2430,6 +2430,7 @@ "in_blocks", "in_pool", "is_final", + "thread", "operation" ], "type": "object", @@ -2453,6 +2454,10 @@ "description": "True if the operation is final (for example in a final block)", "type": "boolean" }, + "thread": { + "description": "Thread in which the operation can be included", + "type": "number" + }, "operation": { "$ref": "#/components/schemas/WrappedOperation", "description": "The operation itself" From 0fbf2b8f3dbdb2d88469384171e3173c701bf54e Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA <22281426+aoudiamoncef@users.noreply.github.com> Date: Fri, 27 Jan 2023 01:29:01 +0100 Subject: [PATCH 61/80] refactor: add lazy error handling in get_block_slot_timestamp (#3473) --- massa-models/src/timeslots.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/massa-models/src/timeslots.rs b/massa-models/src/timeslots.rs index 0a9883f1c06..c898de3b037 100644 --- a/massa-models/src/timeslots.rs +++ b/massa-models/src/timeslots.rs @@ -39,17 +39,17 @@ pub fn get_block_slot_timestamp( ) -> Result { let base: MassaTime = t0 .checked_div_u64(thread_count as u64) - .or(Err(ModelsError::TimeOverflowError))? + .map_err(|_| ModelsError::TimeOverflowError)? .checked_mul(slot.thread as u64) - .or(Err(ModelsError::TimeOverflowError))?; + .map_err(|_| ModelsError::TimeOverflowError)?; let shift: MassaTime = t0 .checked_mul(slot.period) - .or(Err(ModelsError::TimeOverflowError))?; + .map_err(|_| ModelsError::TimeOverflowError)?; genesis_timestamp .checked_add(base) - .or(Err(ModelsError::TimeOverflowError))? + .map_err(|_| ModelsError::TimeOverflowError)? .checked_add(shift) - .or(Err(ModelsError::TimeOverflowError)) + .map_err(|_| ModelsError::TimeOverflowError) } /// Returns the thread and block period index of the latest block slot at a given timestamp (inclusive), if any happened From c4c588c1ff0294c71a16fe8d991d995e96494c45 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Fri, 27 Jan 2023 11:50:28 +0100 Subject: [PATCH 62/80] used hashed bytecode as keys --- massa-execution-worker/src/module_cache.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/massa-execution-worker/src/module_cache.rs b/massa-execution-worker/src/module_cache.rs index c5a001e3746..ffff1be0d73 100644 --- a/massa-execution-worker/src/module_cache.rs +++ b/massa-execution-worker/src/module_cache.rs @@ -1,7 +1,12 @@ use massa_execution_exports::ExecutionError; +use massa_hash::Hash; +use massa_models::prehash::BuildHashMapper; use massa_sc_runtime::{GasCosts, RuntimeModule}; use schnellru::{ByLength, LruMap}; +/// `LruMap` specialization for `PreHashed` keys +pub type PreHashLruMap = LruMap>; + /// LRU cache of compiled runtime modules. /// The LRU caching scheme is to remove the least recently used module when the cache is full. /// @@ -10,14 +15,14 @@ use schnellru::{ByLength, LruMap}; /// * value.1: instance initialization cost pub struct ModuleCache { gas_costs: GasCosts, - cache: LruMap, (RuntimeModule, u64)>, + cache: PreHashLruMap, } impl ModuleCache { pub fn new(gas_costs: GasCosts, cache_size: u32) -> Self { Self { gas_costs, - cache: LruMap::new(ByLength::new(cache_size)), + cache: LruMap::with_hasher(ByLength::new(cache_size), BuildHashMapper::default()), } } @@ -33,7 +38,7 @@ impl ModuleCache { bytecode: &[u8], limit: u64, ) -> Result { - if let Some((cached_module, init_cost)) = self.cache.get(bytecode) { + if let Some((cached_module, init_cost)) = self.cache.get(&Hash::compute_from(bytecode)) { if limit < *init_cost { return Err(ExecutionError::RuntimeError( "given gas cannot cover the initialization costs".to_string(), @@ -54,6 +59,7 @@ impl ModuleCache { /// Save a module in the cache pub fn save_module(&mut self, bytecode: &[u8], module: RuntimeModule, init_cost: u64) { - self.cache.insert(bytecode.to_vec(), (module, init_cost)); + self.cache + .insert(Hash::compute_from(bytecode), (module, init_cost)); } } From d82fb66cca8b39d4ec41a0e4b4d7ab92a249a680 Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA Date: Fri, 27 Jan 2023 17:48:51 +0100 Subject: [PATCH 63/80] feat: add rusty-hooks support --- .rusty-hook.toml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .rusty-hook.toml diff --git a/.rusty-hook.toml b/.rusty-hook.toml new file mode 100644 index 00000000000..e51c329f52c --- /dev/null +++ b/.rusty-hook.toml @@ -0,0 +1,6 @@ +# Generate git hooks run: cargo install rusty-hook && rusty-hook +[hooks] +pre-commit= "cargo check && cargo fmt -- --check && cargo clippy -- -A clippy::uninlined-format-args" + +[logging] +verbose = true From b93069415fbdc8859394371b73022f466615453a Mon Sep 17 00:00:00 2001 From: AurelienFT <32803821+AurelienFT@users.noreply.github.com> Date: Mon, 30 Jan 2023 11:28:15 +0100 Subject: [PATCH 64/80] Update all dependencies include sc-runtime to round gas costs (#3476) * Update all dependencies include sc-runtime. * gas calibration test * gas calibration round_abi_costs * Downgrade gas cost from abi that compile --------- Co-authored-by: Massembler --- Cargo.lock | 433 ++++++++---------- .../base_config/gas_costs/abi_gas_costs.json | 92 ++-- .../base_config/gas_costs/wasm_gas_costs.json | 20 +- 3 files changed, 252 insertions(+), 293 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 16c200eb73a..291a3114018 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,7 +8,7 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" dependencies = [ - "gimli 0.27.0", + "gimli 0.27.1", ] [[package]] @@ -65,9 +65,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf6ccdb167abbf410dcb915cabd428929d7f6a04980b54a11f26a39f1c7f7107" +checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" dependencies = [ "cfg-if", "getrandom 0.2.8", @@ -188,9 +188,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.60" +version = "0.1.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3" +checksum = "eff18d764974428cf3a9328e23fc5c986f5fbed46e6cd4cdf42544df5d297ec1" dependencies = [ "proc-macro2", "quote", @@ -235,6 +235,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" + [[package]] name = "base64ct" version = "1.5.3" @@ -378,9 +384,9 @@ dependencies = [ [[package]] name = "brotli-decompressor" -version = "2.3.2" +version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ad2d4653bf5ca36ae797b1f4bb4dbddb60ce49ca4aed8a2ce4829f60425b80" +checksum = "4b6561fd3f895a11e8f72af2cb7d22e08366bebc2b6b57f7744c4bda27034744" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -397,18 +403,19 @@ dependencies = [ [[package]] name = "bstr" -version = "0.2.17" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +checksum = "b45ea9b00a7b3f2988e9a65ad3917e62123c38dba709b666506207be96d1790b" dependencies = [ "memchr", + "serde", ] [[package]] name = "bumpalo" -version = "3.11.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "bytecheck" @@ -583,9 +590,9 @@ dependencies = [ [[package]] name = "clipboard-win" -version = "4.4.2" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4ab1b92798304eedc095b53942963240037c0516452cb11aeba709d420b2219" +checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362" dependencies = [ "error-code", "str-buf", @@ -623,16 +630,15 @@ dependencies = [ [[package]] name = "console" -version = "0.15.2" +version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c" +checksum = "c3d79fbe8970a77e3e34151cc13d3b3e248aa0faaecb9f6091fa07ebefe5ad60" dependencies = [ "encode_unicode", "lazy_static", "libc", - "terminal_size", "unicode-width", - "winapi", + "windows-sys 0.42.0", ] [[package]] @@ -898,9 +904,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.85" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5add3fc1717409d029b20c5b6903fc0c0b02fa6741d820054f4a2efa5e5816fd" +checksum = "322296e2f2e5af4270b54df9e85a02ff037e271af20ba3e7fe1575515dc840b8" dependencies = [ "cc", "cxxbridge-flags", @@ -910,9 +916,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.85" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4c87959ba14bc6fbc61df77c3fcfe180fc32b93538c4f1031dd802ccb5f2ff0" +checksum = "017a1385b05d631e7875b1f151c9f012d37b53491e2a87f65bff5c262b2111d8" dependencies = [ "cc", "codespan-reporting", @@ -925,15 +931,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.85" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69a3e162fde4e594ed2b07d0f83c6c67b745e7f28ce58c6df5e6b6bef99dfb59" +checksum = "c26bbb078acf09bc1ecda02d4223f03bdd28bd4874edcb0379138efc499ce971" [[package]] name = "cxxbridge-macro" -version = "1.0.85" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6" +checksum = "357f40d1f06a24b60ae1fe122542c1fb05d28d32acb2aed064e84bc2ad1e252e" dependencies = [ "proc-macro2", "quote", @@ -990,11 +996,12 @@ dependencies = [ [[package]] name = "dialoguer" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92e7e37ecef6857fdc0c0c5d42fd5b0938e46590c2183cc92dd310a6d078eb1" +checksum = "af3c796f3b0b408d9fd581611b47fa850821fcb84aa640b83a3c1a5be2d691f2" dependencies = [ "console", + "shell-words", "tempfile", "zeroize", ] @@ -1111,9 +1118,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" dependencies = [ "signature", ] @@ -1135,9 +1142,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "encode_unicode" @@ -1276,9 +1283,9 @@ dependencies = [ [[package]] name = "fd-lock" -version = "3.0.8" +version = "3.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb21c69b9fea5e15dbc1049e4b77145dd0ba1c84019c488102de0dc4ea4b0a27" +checksum = "28c0190ff0bd3b28bfdd4d0cf9f92faa12880fb0b8ae2054723dd6c76a4efd42" dependencies = [ "cfg-if", "rustix", @@ -1506,21 +1513,21 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dec7af912d60cdbd3677c1af9352ebae6fb8394d165568a2234df0fa00f87793" +checksum = "221996f774192f0f718773def8201c4ae31f02616a54ccfc2d358bb0e5cefdec" [[package]] name = "glob" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "globset" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a" +checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" dependencies = [ "aho-corasick", "bstr", @@ -1531,9 +1538,9 @@ dependencies = [ [[package]] name = "gloo-net" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9050ff8617e950288d7bf7f300707639fdeda5ca0d0ecf380cff448cfd52f4a6" +checksum = "9902a044653b26b99f7e3693a42f171312d9be8b26b5697bd1e43ad1f8a35e10" dependencies = [ "futures-channel", "futures-core", @@ -1551,9 +1558,9 @@ dependencies = [ [[package]] name = "gloo-timers" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c4a8d6391675c6b2ee1a6c8d06e8e2d03605c44cec1270675985a4c2a5500b" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" dependencies = [ "futures-channel", "futures-core", @@ -1828,9 +1835,9 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e" dependencies = [ "libc", "windows-sys 0.42.0", @@ -1986,7 +1993,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baa6da1e4199c10d7b1d0a6e5e8bd8e55f351163b6f4b3cbb044672a69bd4c1c" dependencies = [ "heck 0.4.0", - "proc-macro-crate 1.2.1", + "proc-macro-crate 1.3.0", "proc-macro2", "quote", "syn", @@ -2220,7 +2227,7 @@ dependencies = [ "strum", "strum_macros", "tokio", - "toml_edit", + "toml_edit 0.16.2", ] [[package]] @@ -2272,11 +2279,11 @@ dependencies = [ [[package]] name = "massa-sc-runtime" version = "0.10.0" -source = "git+https://github.com/massalabs/massa-sc-runtime?branch=testnet_19#d88552415603ef8d3144c7f2905cca64b462ab2d" +source = "git+https://github.com/massalabs/massa-sc-runtime?branch=testnet_19#7182b80c4bcb74de61b8ce29eb2f64e7e57617c4" dependencies = [ "anyhow", "as-ffi-bindings", - "base64", + "base64 0.13.1", "displaydoc", "function_name", "loupe", @@ -3031,10 +3038,11 @@ dependencies = [ [[package]] name = "nix" -version = "0.24.3" +version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" +checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" dependencies = [ + "autocfg", "bitflags", "cfg-if", "libc", @@ -3042,9 +3050,9 @@ dependencies = [ [[package]] name = "nom" -version = "7.1.1" +version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ "memchr", "minimal-lexical", @@ -3052,12 +3060,11 @@ dependencies = [ [[package]] name = "nom8" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75d908f0297c3526d34e478d438b07eefe3d7b0416494d7ffccb17f1c7f7262c" +checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8" dependencies = [ "memchr", - "minimal-lexical", ] [[package]] @@ -3098,9 +3105,9 @@ dependencies = [ [[package]] name = "num-complex" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ae39348c8bc5fbd7f40c727a9925f03517afd2ab27d46702108b6a7e5414c19" +checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" dependencies = [ "num-traits", "serde", @@ -3162,20 +3169,20 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.5.7" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf5395665662ef45796a4ff5486c5d41d29e0c09640af4c5f17fd94ee2c119c9" +checksum = "8d829733185c1ca374f17e52b762f24f535ec625d2cc1f070e34c8a9068f341b" dependencies = [ "num_enum_derive", ] [[package]] name = "num_enum_derive" -version = "0.5.7" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b0498641e53dd6ac1a4f22547548caa6864cc4933784319cd1775271c5a46ce" +checksum = "2be1598bf1c313dcdd12092e3f1920f463462525a21b7b4e11b4168353d0123e" dependencies = [ - "proc-macro-crate 1.2.1", + "proc-macro-crate 1.3.0", "proc-macro2", "quote", "syn", @@ -3183,18 +3190,18 @@ dependencies = [ [[package]] name = "object" -version = "0.30.0" +version = "0.30.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "239da7f290cfa979f43f85a8efeee9a8a76d0827c356d37f9d3d7254d6b537fb" +checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] name = "oorandom" @@ -3269,9 +3276,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.5" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" +checksum = "ba1ef8814b5c993410bb3adfad7a5ed269563e4a2f90c41f5d85be7fb47133bf" dependencies = [ "backtrace", "cfg-if", @@ -3353,9 +3360,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.5.2" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f6e86fb9e7026527a0d46bc308b841d73170ef8f443e1807f6ef88526a816d4" +checksum = "4ab62d2fa33726dbe6321cc97ef96d8cde531e3eeaf858a058de53a8a6d40d8f" dependencies = [ "thiserror", "ucd-trie", @@ -3363,9 +3370,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.5.2" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96504449aa860c8dcde14f9fba5c58dc6658688ca1fe363589d6327b8662c603" +checksum = "8bf026e2d0581559db66d837fe5242320f525d85c76283c61f4d51a1238d65ea" dependencies = [ "pest", "pest_generator", @@ -3373,9 +3380,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.5.2" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "798e0220d1111ae63d66cb66a5dcb3fc2d986d520b98e49e1852bfdb11d7c5e7" +checksum = "2b27bd18aa01d91c8ed2b61ea23406a676b42d82609c6e2581fba42f0c15f17f" dependencies = [ "pest", "pest_meta", @@ -3386,13 +3393,13 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.5.2" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "984298b75898e30a843e278a9f2452c31e349a073a0ce6fd950a12a74464e065" +checksum = "9f02b677c1859756359fc9983c2e56a0237f18624a3789528804406b7e915e5d" dependencies = [ "once_cell", "pest", - "sha1", + "sha2 0.10.6", ] [[package]] @@ -3512,13 +3519,12 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" +checksum = "66618389e4ec1c7afe67d51a9bf34ff9236480f8d51e7489b7d5ab0303c13f34" dependencies = [ "once_cell", - "thiserror", - "toml", + "toml_edit 0.18.1", ] [[package]] @@ -3547,9 +3553,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" dependencies = [ "unicode-ident", ] @@ -3701,9 +3707,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.10.1" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3" +checksum = "356a0625f1954f730c0201cdab48611198dc6ce21f4acff55089b5a78e6e835b" dependencies = [ "crossbeam-channel", "crossbeam-deque", @@ -3745,9 +3751,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ "aho-corasick", "memchr", @@ -3847,7 +3853,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a" dependencies = [ - "base64", + "base64 0.13.1", "bitflags", "serde", ] @@ -3864,9 +3870,9 @@ dependencies = [ [[package]] name = "rust_decimal" -version = "1.27.0" +version = "1.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c321ee4e17d2b7abe12b5d20c1231db708dd36185c8a21e9de5fed6da4dbe9" +checksum = "7fe32e8c89834541077a5c5bbe5691aa69324361e27e6aeb3552a737db4a70c8" dependencies = [ "arrayvec", "borsh", @@ -3894,9 +3900,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.36.6" +version = "0.36.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" +checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03" dependencies = [ "bitflags", "errno", @@ -3908,9 +3914,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.7" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "539a2bfe908f471bfa933876bd1eb6a19cf2176d375f82ef7f99530a40e48c2c" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" dependencies = [ "log", "ring", @@ -3932,11 +3938,11 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" +checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" dependencies = [ - "base64", + "base64 0.21.0", ] [[package]] @@ -3947,9 +3953,9 @@ checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" [[package]] name = "rustyline" -version = "10.0.0" +version = "10.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1cd5ae51d3f7bf65d7969d579d502168ef578f289452bd8ccc91de28fda20e" +checksum = "c1e83c32c3f3c33b08496e0d1df9ea8c64d39adb8eb36a1ebb1440c690697aef" dependencies = [ "bitflags", "cfg-if", @@ -3996,21 +4002,20 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" dependencies = [ - "lazy_static", - "windows-sys 0.36.1", + "windows-sys 0.42.0", ] [[package]] name = "schnellru" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18b6778edaf75c32e4f919526092db16db6c49296e219005925ed9777e5b263d" +checksum = "772575a524feeb803e5b0fcbc6dd9f367e579488197c94c6e4023aad2305774d" dependencies = [ - "ahash 0.8.2", + "ahash 0.8.3", "cfg-if", "hashbrown 0.13.2", ] @@ -4045,9 +4050,9 @@ checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" [[package]] name = "security-framework" -version = "2.7.0" +version = "2.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" +checksum = "7c4437699b6d34972de58652c68b98cb5b53a4199ab126db8e20ec8ded29a721" dependencies = [ "bitflags", "core-foundation", @@ -4058,9 +4063,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.6.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" dependencies = [ "core-foundation-sys", "libc", @@ -4127,11 +4132,11 @@ dependencies = [ [[package]] name = "serde_with" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25bf4a5a814902cd1014dbccfa4d4560fb8432c779471e96e035602519f82eef" +checksum = "30d904179146de381af4c93d3af6ca4984b3152db687dacb9c3c35e86f39809c" dependencies = [ - "base64", + "base64 0.13.1", "chrono", "hex", "indexmap", @@ -4143,9 +4148,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3452b4c0f6c1e357f73fdb87cd1efabaa12acf328c7a528e252893baeb3f4aa" +checksum = "a1966009f3c05f095697c537312f5415d1e3ed31ce0a56942bac4c771c5c335e" dependencies = [ "darling", "proc-macro2", @@ -4242,17 +4247,6 @@ dependencies = [ "opaque-debug", ] -[[package]] -name = "sha1" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.6", -] - [[package]] name = "sha2" version = "0.9.9" @@ -4286,6 +4280,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shell-words" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" + [[package]] name = "shlex" version = "1.1.0" @@ -4344,7 +4344,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2" dependencies = [ - "base64", + "base64 0.13.1", "bytes", "futures", "http", @@ -4488,23 +4488,13 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] -[[package]] -name = "terminal_size" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "textwrap" version = "0.11.0" @@ -4599,9 +4589,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.23.1" +version = "1.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38a54aca0c15d014013256222ba0ebed095673f89345dd79119d912eb561b7a8" +checksum = "597a12a59981d9e3c38d216785b0c37399f6e415e8d0712047620f189371b0bb" dependencies = [ "autocfg", "bytes", @@ -4668,24 +4658,24 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.10" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" dependencies = [ "serde", ] [[package]] name = "toml_datetime" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808b51e57d0ef8f71115d8f3a01e7d3750d01c79cac4b3eda910f4389fdf92fd" +checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5" [[package]] name = "toml_edit" -version = "0.16.1" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c040d7eb2b695a2a39048f9d8e7ee865ef1c57cd9c44ba9b4a4d389095f7e6a" +checksum = "dd30deba9a1cd7153c22aecf93e86df639e7b81c622b0af8d9255e989991a7b7" dependencies = [ "indexmap", "itertools", @@ -4693,6 +4683,17 @@ dependencies = [ "toml_datetime", ] +[[package]] +name = "toml_edit" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c59d8dd7d0dcbc6428bf7aa2f0e823e26e43b3c9aca15bbc9475d23e5fa12b" +dependencies = [ + "indexmap", + "nom8", + "toml_datetime", +] + [[package]] name = "tower" version = "0.4.13" @@ -4721,7 +4722,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f873044bf02dd1e8239e9c1293ea39dad76dc594ec16185d0a1bf31d8dc8d858" dependencies = [ "async-compression", - "base64", + "base64 0.13.1", "bitflags", "bytes", "futures-core", @@ -4817,9 +4818,9 @@ dependencies = [ [[package]] name = "try-lock" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "typenum" @@ -5059,18 +5060,18 @@ checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "wasm-encoder" -version = "0.20.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05632e0a66a6ed8cca593c24223aabd6262f256c3693ad9822c315285f010614" +checksum = "ef126be0e14bdf355ac1a8b41afc89195289e5c7179f80118e3abddb472f0810" dependencies = [ "leb128", ] [[package]] name = "wasmer" -version = "3.1.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "740f96c9e5d49f0056d716977657f3f7f8eea9923b41f46d1046946707aa038f" +checksum = "840af6d21701220cb805dc7201af301cb99e9b4f646f48a41befbc1d949f0f90" dependencies = [ "bytes", "cfg-if", @@ -5094,9 +5095,9 @@ dependencies = [ [[package]] name = "wasmer-compiler" -version = "3.1.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "001d072dd9823e5a06052621eadb531627b4a508d74b67da4590a3d5d9332dc8" +checksum = "b86fab98beaaace77380cb04e681773739473860d1b8499ea6b14f920923e0c5" dependencies = [ "backtrace", "cfg-if", @@ -5118,9 +5119,9 @@ dependencies = [ [[package]] name = "wasmer-compiler-cranelift" -version = "3.1.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2974856a7ce40eb033efc9db3d480845385c27079b6e33ce51751f2f3c67e9bd" +checksum = "015eef629fc84889540dc1686bd7fa524b93da9fd2d275b16c49dbe96268e58f" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -5137,9 +5138,9 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" -version = "3.1.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c6baae9a0b87050564178fc34138411682aeb725b57255b9b03735d6620d065" +checksum = "07e235ccc192d5f39147e8a430f48040dcfeebc1f1b0d979d2232ec1618d255c" dependencies = [ "byteorder", "dynasm", @@ -5156,9 +5157,9 @@ dependencies = [ [[package]] name = "wasmer-derive" -version = "3.1.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36b23b52272494369a1f96428f0056425a85a66154610c988d971bbace8230f1" +checksum = "1ff577b7c1cfcd3d7c5b3a09fe1a499b73f7c17084845ff71225c8250a6a63a9" dependencies = [ "proc-macro-error", "proc-macro2", @@ -5168,9 +5169,9 @@ dependencies = [ [[package]] name = "wasmer-middlewares" -version = "3.1.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ebe29eb090b5212606a2f295ded55d44f38f65ff9cfa85795127f77e119a729" +checksum = "c3f7b2443d00487fcd63e0158ea2eb7a12253fcc99b1c73a7a89796f3cb5a10f" dependencies = [ "wasmer", "wasmer-types", @@ -5179,9 +5180,9 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "3.1.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bc6cd7a2d2d3bd901ff491f131188c1030694350685279e16e1233b9922846b" +checksum = "8b9600f9da966abae3be0b0a4560e7d1f2c88415a2d01ce362ac06063cb1c473" dependencies = [ "enum-iterator", "enumset", @@ -5194,9 +5195,9 @@ dependencies = [ [[package]] name = "wasmer-vm" -version = "3.1.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e67d0cd6c0ef4985d1ce9c7d7cccf34e910804417a230fa16ab7ee904efb4c34" +checksum = "9fc68a7f0a003e6cb63845b7510065097d289553201d64afb9a5e1744da3c6a0" dependencies = [ "backtrace", "cc", @@ -5224,9 +5225,9 @@ checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" [[package]] name = "wast" -version = "50.0.0" +version = "52.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2cbb59d4ac799842791fe7e806fa5dbbf6b5554d538e51cc8e176db6ff0ae34" +checksum = "707a9fd59b0144c530f0a31f21737036ffea6ece492918cae0843dd09b6f9bc9" dependencies = [ "leb128", "memchr", @@ -5236,9 +5237,9 @@ dependencies = [ [[package]] name = "wat" -version = "1.0.52" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "584aaf7a1ecf4d383bbe1a25eeab0cbb8ff96acc6796707ff65cde48f4632f15" +checksum = "91d73cbaa81acc2f8a3303e2289205c971d99c89245c2f56ab8765c4daabc2be" dependencies = [ "wast", ] @@ -5316,19 +5317,6 @@ dependencies = [ "windows_x86_64_msvc 0.33.0", ] -[[package]] -name = "windows-sys" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" -dependencies = [ - "windows_aarch64_msvc 0.36.1", - "windows_i686_gnu 0.36.1", - "windows_i686_msvc 0.36.1", - "windows_x86_64_gnu 0.36.1", - "windows_x86_64_msvc 0.36.1", -] - [[package]] name = "windows-sys" version = "0.42.0" @@ -5336,19 +5324,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.0", - "windows_i686_gnu 0.42.0", - "windows_i686_msvc 0.42.0", - "windows_x86_64_gnu 0.42.0", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.0", + "windows_x86_64_msvc 0.42.1", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" [[package]] name = "windows_aarch64_msvc" @@ -5358,15 +5346,9 @@ checksum = "cd761fd3eb9ab8cc1ed81e56e567f02dd82c4c837e48ac3b2181b9ffc5060807" [[package]] name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" [[package]] name = "windows_i686_gnu" @@ -5376,15 +5358,9 @@ checksum = "cab0cf703a96bab2dc0c02c0fa748491294bf9b7feb27e1f4f96340f208ada0e" [[package]] name = "windows_i686_gnu" -version = "0.36.1" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" [[package]] name = "windows_i686_msvc" @@ -5394,15 +5370,9 @@ checksum = "8cfdbe89cc9ad7ce618ba34abc34bbb6c36d99e96cae2245b7943cd75ee773d0" [[package]] name = "windows_i686_msvc" -version = "0.36.1" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - -[[package]] -name = "windows_i686_msvc" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" [[package]] name = "windows_x86_64_gnu" @@ -5412,21 +5382,15 @@ checksum = "b4dd9b0c0e9ece7bb22e84d70d01b71c6d6248b81a3c60d11869451b4cb24784" [[package]] name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" [[package]] name = "windows_x86_64_msvc" @@ -5436,15 +5400,9 @@ checksum = "ff1e4aa646495048ec7f3ffddc411e1d829c026a2ec62b39da15c1055e406eaa" [[package]] name = "windows_x86_64_msvc" -version = "0.36.1" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" [[package]] name = "wyz" @@ -5493,10 +5451,11 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.4+zstd.1.5.2" +version = "2.0.5+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fa202f2ef00074143e219d15b62ffc317d17cc33909feac471c044087cad7b0" +checksum = "edc50ffce891ad571e9f9afe5039c4837bede781ac4bb13052ed7ae695518596" dependencies = [ "cc", "libc", + "pkg-config", ] diff --git a/massa-node/base_config/gas_costs/abi_gas_costs.json b/massa-node/base_config/gas_costs/abi_gas_costs.json index 72871f441d4..aed9b578e5a 100644 --- a/massa-node/base_config/gas_costs/abi_gas_costs.json +++ b/massa-node/base_config/gas_costs/abi_gas_costs.json @@ -1,49 +1,49 @@ { - "assembly_script_caller_has_write_access": 142, - "assembly_script_function_exists": 40653, "assembly_script_abort": 0, - "assembly_script_address_from_public_key": 317, - "assembly_script_append_data": 314, - "assembly_script_append_data_for": 337, - "assembly_script_call": 32288, - "assembly_script_create_sc": 305, - "assembly_script_date_now": 93, - "assembly_script_delete_data": 217, - "assembly_script_delete_data_for": 214, - "assembly_script_generate_event": 161, - "assembly_script_get_balance": 143, - "assembly_script_get_balance_for": 173, - "assembly_script_get_bytecode": 156, - "assembly_script_get_bytecode_for": 181, - "assembly_script_get_call_coins": 141, - "assembly_script_get_call_stack": 280, - "assembly_script_get_current_period": 142, - "assembly_script_get_current_thread": 142, - "assembly_script_get_data": 218, - "assembly_script_get_data_for": 265, - "assembly_script_get_keys": 460, - "assembly_script_get_keys_for": 483, - "assembly_script_get_op_data": 109, - "assembly_script_get_op_keys": 266, - "assembly_script_get_owned_addresses": 272, - "assembly_script_get_remaining_gas": 150, - "assembly_script_get_time": 140, - "assembly_script_has_data": 189, - "assembly_script_has_data_for": 226, - "assembly_script_has_op_key": 234, - "assembly_script_hash": 238, - "assembly_script_local_call": 34482, - "assembly_script_local_execution": 40401, - "assembly_script_print": 176, - "assembly_script_seed": 67, - "assembly_script_send_message": 462, - "assembly_script_set_bytecode": 224, - "assembly_script_set_bytecode_for": 275, - "assembly_script_set_data": 280, - "assembly_script_set_data_for": 400, - "assembly_script_signature_verify": 204, - "assembly_script_transfer_coins": 196, - "assembly_script_transfer_coins_for": 226, - "assembly_script_unsafe_random": 144, - "launch": 40555 + "assembly_script_address_from_public_key": 275, + "assembly_script_append_data": 200, + "assembly_script_append_data_for": 224, + "assembly_script_call": 7752, + "assembly_script_caller_has_write_access": 134, + "assembly_script_create_sc": 410, + "assembly_script_date_now": 70, + "assembly_script_delete_data": 163, + "assembly_script_delete_data_for": 186, + "assembly_script_function_exists": 25302, + "assembly_script_generate_event": 142, + "assembly_script_get_balance": 125, + "assembly_script_get_balance_for": 162, + "assembly_script_get_bytecode": 155, + "assembly_script_get_bytecode_for": 206, + "assembly_script_get_call_coins": 123, + "assembly_script_get_call_stack": 264, + "assembly_script_get_current_period": 130, + "assembly_script_get_current_thread": 143, + "assembly_script_get_data": 183, + "assembly_script_get_data_for": 202, + "assembly_script_get_keys": 153, + "assembly_script_get_keys_for": 177, + "assembly_script_get_op_data": 11485, + "assembly_script_get_op_keys": 252, + "assembly_script_get_owned_addresses": 268, + "assembly_script_get_remaining_gas": 93, + "assembly_script_get_time": 144, + "assembly_script_has_data": 149, + "assembly_script_has_data_for": 173, + "assembly_script_has_op_key": 235, + "assembly_script_hash": 244, + "assembly_script_local_call": 7752, + "assembly_script_local_execution": 7752, + "assembly_script_print": 156, + "assembly_script_seed": 66, + "assembly_script_send_message": 247, + "assembly_script_set_bytecode": 146, + "assembly_script_set_bytecode_for": 170, + "assembly_script_set_data": 202, + "assembly_script_set_data_for": 210, + "assembly_script_signature_verify": 209, + "assembly_script_transfer_coins": 176, + "assembly_script_transfer_coins_for": 208, + "assembly_script_unsafe_random": 145, + "launch": 7752 } \ No newline at end of file diff --git a/massa-node/base_config/gas_costs/wasm_gas_costs.json b/massa-node/base_config/gas_costs/wasm_gas_costs.json index 5aa482e5e65..ee5f8c394fc 100644 --- a/massa-node/base_config/gas_costs/wasm_gas_costs.json +++ b/massa-node/base_config/gas_costs/wasm_gas_costs.json @@ -1,13 +1,13 @@ { - "Wasm:Drop": 38, - "Wasm:GlobalGet": 8, - "Wasm:GlobalSet": 51, - "Wasm:I32Add": 0, + "Wasm:Drop": 0, + "Wasm:GlobalGet": 4, + "Wasm:GlobalSet": 0, + "Wasm:I32Add": 126, "Wasm:I32Const": 0, - "Wasm:I32DivS": 61, - "Wasm:I32Mul": 26, - "Wasm:I32Sub": 0, - "Wasm:If": 78, - "Wasm:LocalGet": 3, - "Wasm:LocalSet": 18 + "Wasm:I32DivS": 46, + "Wasm:I32Mul": 11, + "Wasm:I32Sub": 22, + "Wasm:If": 48, + "Wasm:LocalGet": 0, + "Wasm:LocalSet": 0 } \ No newline at end of file From 7c41424cdd23e32aa2e92a570f25fe7832325bf7 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Mon, 30 Jan 2023 11:37:40 +0100 Subject: [PATCH 65/80] Update cargo --- Cargo.lock | 61 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 291a3114018..6152784f6cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -144,7 +144,7 @@ checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" [[package]] name = "as-ffi-bindings" version = "0.2.5" -source = "git+https://github.com/massalabs/as-ffi-bindings.git?tag=v0.3.0#d40a1586953d396508ef739f39f48e1a18e0b0cc" +source = "git+https://github.com/massalabs/as-ffi-bindings.git?tag=v0.3.1#bc2cf68abd3e763ac21793de8cb3b428a56ca504" dependencies = [ "anyhow", "wasmer", @@ -469,9 +469,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" dependencies = [ "jobserver", ] @@ -994,6 +994,17 @@ dependencies = [ "parking_lot_core", ] +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "dialoguer" version = "0.10.3" @@ -2279,7 +2290,7 @@ dependencies = [ [[package]] name = "massa-sc-runtime" version = "0.10.0" -source = "git+https://github.com/massalabs/massa-sc-runtime?branch=testnet_19#7182b80c4bcb74de61b8ce29eb2f64e7e57617c4" +source = "git+https://github.com/massalabs/massa-sc-runtime?branch=testnet_19#a1eb0b21ef2f27c86aa9c4e174d90aca406006c8" dependencies = [ "anyhow", "as-ffi-bindings", @@ -4050,9 +4061,9 @@ checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" [[package]] name = "security-framework" -version = "2.8.1" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c4437699b6d34972de58652c68b98cb5b53a4199ab126db8e20ec8ded29a721" +checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" dependencies = [ "bitflags", "core-foundation", @@ -4589,9 +4600,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.24.2" +version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a12a59981d9e3c38d216785b0c37399f6e415e8d0712047620f189371b0bb" +checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" dependencies = [ "autocfg", "bytes", @@ -5069,12 +5080,13 @@ dependencies = [ [[package]] name = "wasmer" -version = "3.1.1" +version = "3.2.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "840af6d21701220cb805dc7201af301cb99e9b4f646f48a41befbc1d949f0f90" +checksum = "b370ee845c45c8a94964e25a99b98cceec487fad2ca0e99986117bc0709bf5e7" dependencies = [ "bytes", "cfg-if", + "derivative", "indexmap", "js-sys", "more-asserts 0.2.2", @@ -5095,9 +5107,9 @@ dependencies = [ [[package]] name = "wasmer-compiler" -version = "3.1.1" +version = "3.2.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b86fab98beaaace77380cb04e681773739473860d1b8499ea6b14f920923e0c5" +checksum = "62e9aff72e22851e0dbabee9a769d6292cb8f5f601b137acfadb438bd8f80da1" dependencies = [ "backtrace", "cfg-if", @@ -5119,9 +5131,9 @@ dependencies = [ [[package]] name = "wasmer-compiler-cranelift" -version = "3.1.1" +version = "3.2.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "015eef629fc84889540dc1686bd7fa524b93da9fd2d275b16c49dbe96268e58f" +checksum = "b77b1e6b7aada98318ffd76d9be79894879fd91bb9c9d1ab4b88389c4b22125a" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -5138,9 +5150,9 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" -version = "3.1.1" +version = "3.2.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07e235ccc192d5f39147e8a430f48040dcfeebc1f1b0d979d2232ec1618d255c" +checksum = "d2e517ccbc64ef34ea54148d8551356a067c9dc385861efb5b8dd8b7d1c6c2fc" dependencies = [ "byteorder", "dynasm", @@ -5157,9 +5169,9 @@ dependencies = [ [[package]] name = "wasmer-derive" -version = "3.1.1" +version = "3.2.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ff577b7c1cfcd3d7c5b3a09fe1a499b73f7c17084845ff71225c8250a6a63a9" +checksum = "3d78af99a44fe5ba0a261e6ae2b6488877578d5f4bc3e9eb646ea45791d4020c" dependencies = [ "proc-macro-error", "proc-macro2", @@ -5169,9 +5181,9 @@ dependencies = [ [[package]] name = "wasmer-middlewares" -version = "3.1.1" +version = "3.2.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3f7b2443d00487fcd63e0158ea2eb7a12253fcc99b1c73a7a89796f3cb5a10f" +checksum = "8cb58b909e069484bf48ace103085ae100c1295d3a407db744de96fa09ee0309" dependencies = [ "wasmer", "wasmer-types", @@ -5180,9 +5192,9 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "3.1.1" +version = "3.2.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9600f9da966abae3be0b0a4560e7d1f2c88415a2d01ce362ac06063cb1c473" +checksum = "ad3d70c9f8df77de3483b3381c5de78aa48d9caa99a6c3df15697efc3a5270f7" dependencies = [ "enum-iterator", "enumset", @@ -5195,14 +5207,15 @@ dependencies = [ [[package]] name = "wasmer-vm" -version = "3.1.1" +version = "3.2.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc68a7f0a003e6cb63845b7510065097d289553201d64afb9a5e1744da3c6a0" +checksum = "c0c328ad1b4d0f2f18e1fd58101b6496ac4fbdd642790251524728912b3d5b4f" dependencies = [ "backtrace", "cc", "cfg-if", "corosensei", + "derivative", "enum-iterator", "indexmap", "lazy_static", From cc8a13e54ffbef68e06fae40a372b77b3a2dfd62 Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Mon, 30 Jan 2023 11:52:57 +0100 Subject: [PATCH 66/80] update SCs --- .../src/tests/wasm/datastore.wasm | Bin 6142 -> 6134 bytes .../tests/wasm/datastore_manipulations.wasm | Bin 6699 -> 6678 bytes .../src/tests/wasm/deploy_sc.wasm | Bin 2952 -> 2956 bytes .../src/tests/wasm/execution_error.wasm | Bin 2230 -> 2221 bytes .../src/tests/wasm/init_sc.wasm | Bin 1115 -> 1111 bytes .../src/tests/wasm/local.wasm | Bin 0 -> 3780 bytes .../src/tests/wasm/local_call.wasm | Bin 2982 -> 2986 bytes .../src/tests/wasm/local_execution.wasm | Bin 2918 -> 2921 bytes .../src/tests/wasm/local_function.wasm | Bin 3274 -> 3270 bytes .../src/tests/wasm/nested_call.wasm | Bin 2770 -> 2774 bytes .../src/tests/wasm/receive_message.wasm | Bin 3483 -> 3479 bytes .../src/tests/wasm/send_message.wasm | Bin 2951 -> 2955 bytes .../tests/wasm/send_message_condition.wasm | Bin 3272 -> 3268 bytes .../wasm/send_message_condition_deployer.wasm | Bin 1306 -> 1302 bytes .../src/tests/wasm/send_message_trigger.wasm | Bin 3016 -> 3008 bytes .../wasm/send_message_wrong_trigger.wasm | Bin 2985 -> 2977 bytes .../src/tests/wasm/set_bytecode_fail.wasm | Bin 2539 -> 2542 bytes .../src/tests/wasm/smart-contract.wasm | Bin 986 -> 983 bytes .../src/tests/wasm/test.wasm | Bin 4817 -> 4811 bytes .../src/tests/wasm/use_builtins.wasm | Bin 726 -> 726 bytes 20 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 massa-execution-worker/src/tests/wasm/local.wasm diff --git a/massa-execution-worker/src/tests/wasm/datastore.wasm b/massa-execution-worker/src/tests/wasm/datastore.wasm index 6f6917aff5976855a7fed2d315ebef27ece4cf33..f0d782b705b2de40ab36024900dbe9caa0b3eea9 100644 GIT binary patch delta 2127 zcmZWqU5Hgx6kdCu-+T7C_nv9=PIa7dpW{d)IgL_In1**bR-;kYLl04KEgi^v{r5T| z2zThAdI&PkLp>PSTMq`JFFuF_LHH11PyJvK^kNVs5)v}~eCwQheR5#bvkr~6# zY3_1pJvfKYrL6k{(OGwAn%DSOaVW!u{8Pw36OWbgB2Id6YaV4~-4t*n>PdD)yN0aG zZZ8i3n)}x6KAm~C#z{AKc(}_)jzXCQ!0=1X;Jrkp0xG`u;(=>}ZticR+~cIrP4UWw z2zdI|>EWDCmlqaJALV4ewB&;SkC!Wt!G8 z#0l+UrTbm0VQOx>Di~Pe6}<_aJXNMpB|)zEdc+h8DNZ;j&g->fX0HLDp9IQEL>QKArL7ElNw}n7(6OjL)J^O1KAOo-Ar3Gu}+9fExle= zN@3=JN>sAFhevVBdE^0Qy^EY<`klX;g_{_O~fIzM^BkIZlBDmE_%E?8BetE$AI22v3K3Vt~uVg(K^sDjfTpn(GEBeFQI)m@Y)lSGtd$Q-NX zS|NwC?!ap6lrlDHSL(@H#%yXbUveonINUupSj!%4tlyJBl`}|sQk-!B`&|%4eZegN zi^wXZIS?X2tfb*CedGH|#l?@oTSki)oKzAQhr>0nM*}!*pm=x`00qKmDV)7KNtD!! zi{Xr_7k9$_N*8--Gw53+8G2npYFtO*SK*tFG@6jl)iXyUB~=nw&*wq$UF{(i6e^n8 zCWsCYar1VSiSwn2r5{`@%Z!15)UM1St9cYv^_Ss_x1+T_?p-(Yi;L05!ELR)L820q zYqSD7>3XV#LJo>}@L0*iLbG*x(7Nb(>j)Ad)3i)5X?Ux3&;;Na66DSwP5+nc{^?1D5$WXigf)wqz^#+WLi{luFR5^AiXTWFeIPPW{ zSn(M=0+K<-wMGG2WzFV{^^7e6#kLi17+9+%#0eyT7%IW+8I@5Pm`JTHhc)&nms zd0b1)uY6bc{{_i@&UN-;SCgU0i65BFtB{Jk>x?9yv~9wNB^kapoS0I-Nr&jvnnE8qm1zbWRTj zM>?;+cBboz;8^$AiPIM(gL2!EM>Kpuy0GHY*1cSGs6&K$r_23S*?)TNK0)=6;Txlts2==o3Les(_q3Hsx3oSL_o^IECMgU zixDru%MtH^_n5b;5Jt{!VF$C4T7JK9Tv&L35;3a(;wZcR*7ef(Rb*xSo(pa~7reac zubYD-1z$zP*}+3vd2mD-N5YCECMy5%^I>En8@`-dIcRwl77U4^|uXx}JUbLf9<;DA#yaa(5K4j>m{ z!XA1Ro3PI_B#cIdF+A?LIHEL`un3uQYcNk>F}PUCLC+*^zHv5qv#2KmVbbfr1c4B` z{H^x37JM`?03y@n8{sr)tq>SVl#Ua`p+X)#Hz9LGSyFx*E{de|qa#9;C!)nRJ5bn{ zE;*h&7s3)^f8KB*X&8E|=Uf`^F zEVtM4YQ?9x5UvBbcgpwlx&nH>!R%!9Oj=xgC?(kk`8?4sB3rYnyr~zH1~!*BX2=hM zwaKQxv6bCJcBK-( zvq3jh88ve_o@s8ue}8kwZVe^e2(+z^AD)ACpqq4YZcJ)mB?|Ek=ro;0EPJQg`*Bi_ ziSp~_B;5SeoS)!$tQ!I4MlAsL)AKLP4xf^zUBcF7M6Ed;kCWGrO^Bt;H)0JP~=0VV);1wlXd1er!iTGk}nE=P0(MH{<<0V4x6!l;DppImWKP;av; z0>Xtzl4wSXz%XV?kus978A&6Jnkf;^a{$b!I?Ezy#0U}%lWwF91bq=yg%=6R69m~v zR)wl4SvSdcspIg(nJ!Ip1tc*aIYu?i1Y62Djj8~S1o~0tStwy5SraxY=%Lnzt9g8M zY*skP;0603f9+6v=pYcJXGU6f3DPrXNTt`5lt^5A-Y>YoK zZ~Bct#{9(}W$p=Tbq8qG)mR2vbF~%#pcs?<(z}k{a<%8|>ImvD&{oITNesIb^q)>_ z$>@VIE~h)?wAOq2FdXG_9lgZ^at$81wH>XG2)h;3xSf6B3FeC_KMs#ONi+NH=b&gm zh6SI`_ByZeKG55|ZVLN5yvxxy3!E9R71sG*im&wcDApSN*NaJRg2TLTIqj!a);+va z|AAt_dWOMWwAtf|PX_gzu!VtJmy?`4qX~0x4{pOTz6kzE8$&u5vTXi?T0?qxmX`t< V#K`jR$Lr)d(;3omLH6gs9bA7Gb2-u_EC%?QOy#LkW{5i#NL+Ag6%s}MD6$D;X}DJ&qj z)v79FoR1W%TI4WjvC(4WXvJ8IlvdgqEi%qY0F1iBmbOAPvYOJ$79tH{K2lYcj*v49 zVJdQ}%B{Ez6>x^7Eb6A$lZiJ{9FZ)p23B*&BTsTjtoEj=3amihF3BwCK)+oxPE{a{ zL|QVY<@h2AHH?{e!KL%-<-Ndi5w!|r9N6yyulR%|;HN$j0)Q(vC_k^q{Dx0y*UX0P z=d8z?f?vOZcVhQFBC@0-mWN(RCuwZD|M-J&SklG(M;S!ZXQD3A5e|rsV(ysWg(lw5 z9hLc;Tvrx>Uj&3VfnNtyL-QkdT|D&`+0j^SS(QiC7;kHJg_~|4FIeSD?2r^HH3e*x zs8uSomoaOwLtdvTbj&W;xInB1lW+s-a70cjy;$p{OenM#v!77!J89oUyaHvn$tSlR pkEwXHOKHWOGT|xUhh=KfvEyGPLtj{*zIOG>%S-}e5LvGjMaXoRAA2zJBrn+!NgH}$7~(CXLZ_;CbeYpv+fk>b}xFW z(X8t#l1*O)HrLL;67fTP3Mzk{^8K6#{8E9u;-$)r_hGdZSWhcUcD6h_tQ>oa5bWO` zvgu6Z)`nHee~W*Y>=b|4_WprOUWjn;@*e%bMH}$0@O|uod&OiX6L1<#A{gldIn- zBTBibE6anLFYm%wCS)n@Ft_XReB&sotN5g4=$-tXQE{SP~d46inSIGa()h9^!}- zRgo2v0v&{inQow)1KmQmqO&Uv>7`|Z1X880_bS66#i0=lzoAWP-1BQFcIj$A{AY^P&Wy)}$v zEn_qcWi0fL+y!}>k2_&4dvKz7BAI5Yky8&)4DDEGYjAK7g5+nU8GNk@MVl&#!Vme3B_OdaMZMC{Hxlu zpZa5%zx78k-}A@&k>anipyw5TlZ9Z~W9eYW_H&(BY)Zr0hA*crCq_XZ6?okJ!QuSwBgY4pJho zP9yA)(%3+#t-m$98$UblRYH2td}NB}>;wnY`2Di*(?UD-!|_Jtux)}xrlxSE@nV`# zt+K6hY8U=ACK4lzWUUGoc5GZQL_#XkB7|UIUSI=k7B~Wq0#;kHn9-I&fRUkLJTDvM z$_P}F!0P`z>f7RueE*&jwt-J!PVz?0-+LjFb}Vw*gdWNfl%Qo*r@fI@=O zg=fmMG8Et30?K1-;O^+Ot%Suk7@Kr<5QlYmPY-+!~Vi#Oc!pOLxQ}aRKZSU^Ml0MoP!-`6; z2k2NNPI-UGNZl;Y4bUS8Vpgj~&u}KunZYpCo57)JvC|t){~}#&;(09s|NbS+2@gPy z!tpjH1Ju?+S$00`He-P{K9AO=TFj7WX{Hx1;jrvTByqzTyrY&%y<`usuykg__#_Rj z7W>){_QOB{4C7kuy%pLw!JMKc5-k9E?MAO#k^HKp-vY*c3n@%i?CZp;X*FOb&}b1*iO__S?yWvK}J@4;OT}5R4HZrWh-; zKa;E(c6=z|ulqXn{GqCn{GmWo^Hh<(AoOSbh-W`oxGf5kF;2K>z}!)(0!fN8i?e{Xmm{!Q=Z)tfr9%5yS5Yz;T&% zUZYxmM$cs-ragEHAx~bnJ$h9D?Y?TX87=ZB*C1f*UDb;W97>1>m7!b(9b+AN+a)+k z+;;6mt3?sgEiKC|!nEQ(wshu+v2DDdxIh`x5bmlD_g||ekHSb@XIMzwFCtrNNeE)y zPDoN@!HRKC7}a*J;3#lda2TtEf+IU}wAK;SPK>7n#hCH-n#kE%%wSrNoQd0}v;Yf( zLKX&vWZUC+n962BEMm&#ZaR-4F<6(xE!FZixHhd$z&oR>ge%Aq6z=}tC4%JNQir21 z_xrb`-zvaVvPSxcxL2;s4$2w6A3FaU54C?%kKAhP(3NIw&dWr*b*AX)| zT#}an48epfO^`JH5Dg&;WT<0oAs3;WgU23H z-bGLmPxc~uk{$|PJ^BZDh#;OsdJq&8blz?%xXZrTZ{Ex|-<#QeRef6>)#fl;16WfT zUxnGiOx%)k>!uf#H{{LFLTnLQkUXB4Tq}ZbU-~Wxy+}<9-ZiOfEgUZq~Bv){)eL+A05=_ z0DHY95!8i~vjjFWZvc2wC+9+;g0lrIx@by>DZVM1Jnc5j(LC0nO)xR3a!?m44V{>}R~JcY_+wD1^iR~nB@<@RAA}x;8K;<+ z1;@iqN=t%s^K7RIB*G^(KEe%d>Y17S$~+X+rmcNxxa4+Z@hZ^c$TrYF&{q)sYkh&& zPrAWt)m%QKfS$${Ye2iPwFm%;pBCS=&;D~j?_+xkeb+2-#xrx9*I#C_67tG9`)=7T zpl_C%yt7#fywCIZt~u_%m8NvyyzXC^Ie#`f=SEY?H8XArKb&mjikis6FMXf)gd80-dL z!DPPR8kFTX12eNv`>>bNEbl=F0;x2-wvmGqlnxLpz6M&v^lM31C>bF_ipf_qYRqr1 z3E5jVQ^?VBMA@7shO!+ERSSw#Uo`4gAh~1Hf}9;Q0q~Wvo)nrVkelNfWr?@YkK9Xp b-;Gta*kFwmatgR!(;)mK*MO_5Y~c4lUuPpR delta 212 zcmXv_tqKBR5S;zK5Bd1^1cT9Vh+t4TEC>FS#VQIugK$lK4lxK<3>S<>AHZnv4Gj7S zX43`tg1gMjGBf-1FMlm*^^Q6ah-=t3$uS7Z0Eic>h6btmr$$>S88Kp$8mB@k%wOAt z96Zw$a`K!|zAzJ_d~b%zH=`*ZTqR<|8No diff --git a/massa-execution-worker/src/tests/wasm/local.wasm b/massa-execution-worker/src/tests/wasm/local.wasm new file mode 100644 index 0000000000000000000000000000000000000000..3e0c560e6bad8e0298430a24fae8e2ec33aa1771 GIT binary patch literal 3780 zcmbtXJ!~Au6@D|bd%JscB$t+xAfltpo*0FJEh$A{B!&U=1&||IwiPHpU2r;*E1ApV z9eKB;EFj1U0Rpg4p&~^J7cK(Cg^D1R3l%PczzBkXMUXTu0;F*v1SwMxP`)>F$FoQy zDZ<6vo1J_A?|W}})E#XrB2q7=x71jTZ<+CUOtbMZRs>y-5Kn3w#s`W zivBy#Mz`(~1)i^-)YBWRcYB@k-Ew`e-W>EPF^f5A(keoLN-JaHIEvMd(mFPZRAbSM z6_X7g#Q(}|awUnjyPJJlj60ovc^9E|Iy-ouOFEsszU-dMI-T`FuUD?ubjEf%!@Az= ztaV4F(T(kLdoaAGDOJyBi6T~37QcEowj3v$?wA?PA!T)f3lQ}O-#Ki%bgza8T=eq(8s zn682)o@~fk>&!Aa<>+NiPTT8Bix*Fx_2RF@=fn+slUI4%Hey~gWFqHD>alO$O zb7#P3d(g!#j`BuZT|q=G)_J2))*-24&66mQ6snIye?R5Jl+W;YCN>EgV8+pr6<4(v z76M_hmpWxH_#pWCtreZ$kn}bAu*rWW{zg#ZRCN&%ta!E+olbZjTK=8li-BiF6jn~Z z0>)aIv0jzuyqecalO@Zp0!mu|+QKe_cL`Y}!Qe$UV(dIzmby1qG_?~X>h&Up zvAk+$$Cxa%OI&shUZ+^utfT?W-{Qi%jT%<%1lUby*v%x?RK!nUH^XT*!)~^U>?4sL zy9uz{@PLQ`y+jg#SJ$|{1e5}jE;(uva1GSO-X*boEQ6d&L@xG_#U8P!3P6jU*$P;T zz6Y-mxD?ov2u&aYskNU*Qmsj81>kT@u+Hz#0Uxl-IVXab&x(WJBi56aqXmlwNgxFM z5T8H-`zbu6<@My;U~gp45i+ejlB62(RsrM!G=)KzW!{O;X|Xt<5c46buAxUm!wum% zQ1#Iqe;Mwg&;patVi+1#=rZHG3>G*-?xnlH|2LWnz!UgU01ZCkC^Wbyk@F-Cqy@xa zwmc;naRJMJAbwTM0;~dFfRzDOGsz`6Bb7jS;*uxO=)6C04>Jc17P~~ygF@$+M3rwT zq{=s8fj+{443MkQ7~n8|k3)K6Nl=6Dow>SXiv|$jdDICWydx*V;~IYM1!1U^ae$(@ z2BwBbTH=t17KRJJC@7UopvdWunnOG?8pXO0wR{I5dCQph6@{W4|F`@%~e%RFe{8a5?s$mpW zg$Yv))oJ7lelUt6b*uIuE=EM2wvI0bcb{thjG|`U2 z1nra?ez@T0t0YOfuPNmTSo8#@Lic%s?wbv$Q&^OK1Qw+;p(SFJMSut&r9_^{O$%72 zAn3LhQ=!Z%vM33ggcM%dlJMD$^P3Yl4lbqw>Lm{zIv$3npaWY19e4uhc>913MEspa zxU>BCle;y1SyHy zM@dV%J1xl*$RMD9&)Gs`&ORe^DxL4mdqW?9C42LCu7%RVA zv>9Wou{MYwE!w7*cl_y$`1gxeeV6zzAdcGkXs|b2FW>6!;OEz!AKiR2zjWFE)Vp*S Lzg;hFcX$2+N&|4? literal 0 HcmV?d00001 diff --git a/massa-execution-worker/src/tests/wasm/local_call.wasm b/massa-execution-worker/src/tests/wasm/local_call.wasm index 0762260d49f3aaad366f0c3d20a30e4ca76c6c16..1548e6aaf1049c5e26865faa1e6bcd2e857b1e8a 100644 GIT binary patch delta 1487 zcmZWp&1)T16hHT4KJWV&jo8?U;m$N-ti)CV(Q2_diuzKOAc6}wFSTaT_mVVepB14p z(WPe5Fq{EPseMjQq`KNs*2Xs{`5Oa@86o;|9rdK>yoiXDN>qr9jeoB_k!VYYyBgNK)0`K zQ9l|EKim>7ONPVCS2s4+FHh(pHymD@Os)*yzjS@w=x}p=^Xj#aHO1=TBvQo6scuKj zrC)Ws^{46&A7oLf_*Tkvm=ZaT+2VwlmNYgF>M!(0b>FC@^2*b^?yTBnub2jQnRh$< zbC*9;{AdPKoT^b7h*DfS);HdOX25^rA+UTW5$!2H+bBbeij)s=YrJDMDUCO+xSE%i zV;{gcek*4^spQVvmAp*&ffzLIV!jvi0r70(FXe0uv;Gb%Z*znrxn5u+x2MQkw&OBJ z&@%LP^jZ=4gtJj;cxuGkJGd+�VSAzmr*cz5^a4rezSyulz}MhQ_UZ;lvp&iQbTeC#9CH}H`Uk5c#1N}h!&jlN`JoG5N&1@u7pEPhW=>7=&nvb)Ybag-V;2bO-FbwvhB> zhXQvzIi8H|gDiwgrNX@m9{ zj{3fN<}u}i1{*3FAaz(sZ4kUZYo{wXvNDY5D@X8P+e{i_QDMoXC7u6|^Do5bWx|fl zE2gR~9C{!fK|qP$5O{2Z0}HxfmMaWUBy&U_>3TgvdkQH;(}u!$EuR%?IIxx1-ZVT8 z>0%y;ENhUvB9vN+4w5^j16j_XzJ0xjz~Kl$(O+PTfCAk_nIi!bb(9R8 zTS1#Lli32l1n$)DMg!HUzlmN_s{TDHXZNx>ba75)@k!?nFyXuxJ9VD;cI?jRdNzJh z>H59+S?qi98SHoCb591uU#CvZ5Pz3Cr-{g7y?~eR;`~kGUsL=?>X~F^>b7(E7xIrF z@cNT;3%cG(&cV|U$#d8bnmtb!!LOzZ*gr{g>|ds@e~W+XyW#_gT46C(LddUuUOuArO?Ubq*pcwo delta 1490 zcmZ8h&x;&I6n?L&dZxOoXSO9`Hck?%JG(e0teX&-m?&nS63x0w5dVP5x~{OZKeC%l zB8t#!E{g0SOM4LXum=$l(W{3X^d@-lhi5sty-I_n>TL0smSsJahpllahmdM zve!wgyZnncS-W7lmk1puL{6+|?2ynvVG&d9sg2nmEO$#!^5A-3Wmn7s4yg7!aE+g2 z(yDAUTUuSAii&7GuaV6)Qi(%W|IMTNF?#Hn@=+7n_-Hf;zFybCtK+TdIS?6e z<#DJE44sCd7RJ}YHX`+LwcP5Jv5&>R)Dtx>bX{SnLLWNv9j`*9TEMpn)A8{@rFy}~ zzPn@=JbBdUc_ci_LzQ*AQ3qoKmqb@h>DikaW0PL!ML`em)t<|B8M+pX)c=g2hdmg1 zy&jkvZ=i7fDFW+}=P&@i>pOjwUPCtBz_lQ|seIFsyDSf7m=EkC7gW$!wy>h^guIRX zg@=}&hxtJq%#X;~+8Sn*J2}L$_EvaYFhbYrwH|t8k(l|XWjOMBu~#J3JNj7ZBnzod z?cnmcSI^u}R_1WsNaIwfz^oVT`mWKk=g_7^vJp6sjAVNUhk46uAJzFGN8Ln)DhF1; z^tj}8itJmXBDze4k!&ne!MV^&rbJmjLc36#9?9QVZjt!ovm`t_Jf2h{1)X#v`BB^NnvK9Om7W5vJo7$y25?laoZ^Faj8f zUCy&2u$ppJcAq z>^ZC-*?Fwr+l!AFl8+O|$4Nd*oMR#~crW26_p$#X$#;npuFk}Z=@&2n-Pg{|arJI| z5ftCX7qI?Wuji8Uz^lpJi9loVzD~Dki&jVuJ2lmNU3Y=2uaakborwkh?|$vpXMc3v z<>2>3H6Nd<&bkvQMM$X@&4H?kT1qM6@};H``d*SY?Q2C4 zCQA_)4Fgh8uuB(i1qBzb#DzOST?$emA_#5`)bGrTh2jkNo^$U#Ki~b%nfd+j?%^YJ z`R0ZpA~Tz=n95WuuBs|pF*`>t8M||5dgsGS?TI!y?~Ea1$?oi)y4a5T{mr#^DTcg$ zb(1ENe*e~{YLi*Nzj|$beQk9_MdL=A z9I;>Sl$rdg_D!@@eof^!lIbQ~F2(W?Zj)PL*msbQ^n6a79-kog;)i95q-D&0@Jcu0 zOo~D2WNIMSw{X}^*m2xou8+sZD$mKFj9;QMl42y2YE^1x;ELG|aW6NJ?d|usq`0lv zIa=y0f}$muxP65}2pso_Q%=BN#0kgySLI~6Q$%p|94pi8x<25_@Yc+|>OUt$Q0$y7 z*aDhj<}eWAjKgp*z>)J;;ROXL#=?VNbx2ieSr%-oq1NaK;ud zHf*bW&CE%Q09w0f*lo15>i{Kh&_05r{=q$68IBrkU^2qh z;i23hIXY833MAVt*>20vBuUdfIPlt!C^dFs^idPE5gw%L<;J4*|Bn8Se5j1mo=UW}h`|8c0V>v2Zkoz;9b5gfKyz0TL|n~IWB#O>f6ShX)bD6LmpxvW`N8A5N-^G{TeL~5Bzx^9!v_<{P+!c?n^yf< jeh3l1%+JlXVaX4N{4yDyxPqlM7=n=zZaaSJ(_#K!T1xIW delta 1417 zcmZ8hy>A>v6n}4K_HK4(@4OH&4i}=g8(SEHF$n39ohbH`_(%v*3jYBY6b#~QoJ1H9 z)gtH+MXaTuph$y6k%le>1r&Fj1+sX$yS!WFyCO)|P^pklqne1(UNIl4_ z@9fc_KbgG07tt`COfFy9-QB*tPjk&FKKf9R_L-CehnyF)U-P`#=DXsGUd4JnQ##Cu zf_k;kkkZ&-QP*5CyGyq{4{ITPWM|nFFS|_~Q0sRibbeZBuldU@)gEdSEpjzQuQWkS z8>$no6JFiSpT|r1oh>7`Ifrwr5fuv)T+szt|Lj)8O zlrB6~o|dur_7+ecLxH=av#u5v*J3E?wNVoH@jW{VrH#FeHs%2v?4u4gVs~Po&KW2U zMUD#>I~9&|AwwA~oBSf!3}diO{WyP7 zLn02|G1GrO2oOn2HZ}zi$g=n;ZYUGK6DNlyyb7m*cHhn*3KuX!@bFQ_3&9uxVv4ad z`%}r=VaJCO56fZBNHb{G`pZ9~Utlzflo%99ZC$bf+=d%&kx3de61%&W;@mF?l*arS*7&f^1 pDSPQm4!z)w55AM%=fcvP-HuF5jmPLrrk#vi{Ly_;1a8*D>c5RH<81%{ diff --git a/massa-execution-worker/src/tests/wasm/local_function.wasm b/massa-execution-worker/src/tests/wasm/local_function.wasm index 7dab755e1c0e7fabcecee1e98537dc4efbc3d935..cc965cf45a2ebb5a8e8694aa7c5c0a3a02204d06 100644 GIT binary patch delta 179 zcmX>lc}#KxJ2NBGWDe%}Kyn510ku04Dh!Scj;sRAN{o&ZxEvY&a4|4AayYU81%MJ} zOkml`eJs*~@AxGd9D6vp8EqIGXK--qGfm#bVhuFr8;c>3)L_*Ik`b(y{HzR)bGWz} zWf&Y+aB*`pOF&&-|5q1U!1_d~FJR!l& KmNIz;j}ZVdKO<8B delta 183 zcmX>mc}j8vJ2NBWWDe%}Kyn510kt<0Dh!Scjw}MqN{o&ZxEvY&a4|4AayT*r1%MJ} zOkml`eJs*~pZFyi9D6vp8EqIGXK--qGfv*cVhuFr8;c>3)L_*Ik`b(y{45NPbGWz} zWf&Y+aB*`pPF}z&4wTu!S`H))*en?tH)pY}Wdu?Z9KtL>F&&-|2{r}>1_dAn0R;xf PD-zsXDIoUbDLh61y@w-4 diff --git a/massa-execution-worker/src/tests/wasm/nested_call.wasm b/massa-execution-worker/src/tests/wasm/nested_call.wasm index 23ea780b600529d0835758dc62dca85c6982265b..6db9aa2734268b958434f6776b093df660f5be03 100644 GIT binary patch delta 1488 zcmY*ZO^6&-5U%&r{kr@0>~@TsL?^-O&MG4zMp0K118ynm#voAykIu%phxBCsk})C( z9Yn!{h)W}Q@ZiOtV?gwjbMPQ29@K*ekBXPzO<2(Hb&rwl;dRw}@2je>etLdf_-Ww~ zoxifKh)6BERn@3w)ig~*t7_-aH%jk(e`HRZK~BafMM{(2`TO1%2hn)EvGxWz$gPVT zH0Q?S*EfPTpN_{DHZNUTyD+7~kH?p%(~IL*&tF+HDqde(-@N>$rbO*aogz_Q<+!XgjVdbT=#M-m$#K1D2O~xRb52^lvG~y)w4iG@(&(@ zDxanSyg^5=cB|{?4(K%po-bn&y*3TQq+}^{k3duVFy!o6 zSV2LEURVzaizLX9chc5p4O}Z^?zCA8Ya1OGSbDL zy=RE_rasW50Tm2#l--pow4VZ`6Cnn6iC78lG&Y2*E@m$R!U7S1h)+dQq|h;Au;_IS zUC(p_-2`21sacKg4{3xBN0YMClG1=m)^Xp%qkYFb@QUK7zfMj*8j*aGd3BiN%glRCL>B85esZHf{}w`#{0aeIzi0lq zZV#s?VgGXa7~UUr@0;nvQLw(d<@8{?kllfsQFi17Q2K7r`Tu3$(>Wj#Ecm-M@Pm1% ce0#}zbH02HTdlAJDi;A zkIHm1xpZZ7bN$kc=Ims0bvC;^S-W^`UGrdTee25AcNH0~(u7Iavdy{9J}K-sJA8~6 z?-(vyNAmE-NL4RJ%R)j`(y;uP3GHV@QpuqEB3f(>*vf0fW~W9^cn2dzO}tSDWNM96QlHg- z^XPWslW!^)_mLwPPeX90L-3J8jw>kRmX%w%{6>;gL?~vYBDk+pUoe~&z0*J<7l`Re z?$T~Q9=54V#k@8YHEVPz+83txExE!eA3PA)_K^#hj#aLgUFyp7(Xu0lvK>!_r?oFU zOaP@Z80bH(M6F{N1q>#=GK~G%ua%*#b?Y1HmDK-~aP~YXIlbXM_0~WU>dFyVPaXT& zy3!RRm9HY3()$WcxtGg_ERTeyls*?!fTlG@)ODYCB!A@nTnu2`K+HkSrY;Y67x&%^>oRAADQwFM zPqk8&u1R9Cok~`jyEl>(oOSOfV^-a_$>YcWDi`p)!mwFBe(;P98k;l_z_pil_mknF z&trJ{$XI@s< j#?8_$zSW;d`PlfB9MH6<{)oD6mzG~3`5C19Iy>G*0tyU{Pb9gyQb6p#FqQ@w@Ay?aIgFbC)h&Ts=2a4}|e}b2hs$ ze*5e@t5&CLt814w-#04LyK}D<>!1fc-4ws~2kljTS10YJIdkNW)%lz>sgdcOaz{zC zT5(7DX5c@1{GsNDN~Hp4t`(T61D*_*_olO_!={`jn`DLRL@|5oMM*dh;rf_qVZWT(AtzAHmKp=(g#e@(W zpnTbs&;&Sz2`kDeOt%8!sCWrMP*9;0ET4}bDk&F*B*iOZ#}aSwQ1}#!bV58F zJj4+NRhgFsbgT;^I^94wJGzB#MQ2wV(xU@{TL?_1b=0!j0!k6V-iM?8&OUZVQxdUZ zkO?|Rgv0!(7WUV!+XmSqbgt>>I@uRY)w zxnC=GWrkD{BbFnQ{&IzsGFb3>ylOOt8Ugd8QeO5l@U4E?uXX#Grv)JqL$Rd`Z)iJb zRjX2$z4k|cde4pFK5Rt9r}_GSn+Kv=&Z=E^lSc8USl+PM8Pc~njb?{yeSzpu8`hjlTF5m z5SSo>0X+oTg9i^@1W%HK2M>ZE-px&rMU-5Eco4klqJH&yBWMrrRlTZuRbTzQd4K-B z`5S-s1_c>1tyaq~43f!YYvV2IgI+wlMZ^AN^5&LsWjdLhxp3~>#+fP2`N`zcbb5C3 z+N+m0jOv}=IDg^N+nSuZC+#a@KTi&v)*eSOeoxq;b>p&78j{?w3SJW~?pTSE(cnr$y&95*s3M9mzx59`221X-L_f9I>9( zCMGS3nO#qz2wH+ig1cShBBX0NH|rq{gA;Z=P(a#2HLRLS5|14~Y6=3>pN`sDP{BqX zLOMQ5w)2BTm$#Zz}1oJC$a0-Gi%>1`NRC(To#01A`S}R10$5SJe#Q}@GTP3K1 zIX0>@{#ESZj6ZSwljGaO55{<&OF=x`##pEk^d#yP3<6rTD2dq3x*w+im3yXIup#5J zL7;sNU)+Ya>ID;$h_n6LEUc=~YwF}Fsx6mO9*R{hk%22gd60`~_}aCr+gx6$4er{u zu=BHIKZSnip^HiAg+vk)W$)Oi?157uiS;v;@=368CvpD0<9$RLvNc_T13(pAgGOY* zZOVYC;Ge~%qI({ZSdSwvIH9XjcuWg;j3t_*r%lM?K;topvKr(HVG2K1YQ_os_VNBQ z=M|yJ4ke7!Brijz^`QnOC~~v>)c>xnX=wY5hye z%$O=FRq5NE{>%684EN*h#z|6qn^p#zrq)na8 b0Ktcfbu{g$95wM5L$97D{uZR2_~m~9H~i)d diff --git a/massa-execution-worker/src/tests/wasm/send_message_condition.wasm b/massa-execution-worker/src/tests/wasm/send_message_condition.wasm index ce9ab26cf07c7ba3c0e5f2c10ed72703b6ddac16..4e455612815d2b316f068d7c0d110118a88963b0 100644 GIT binary patch delta 1362 zcmYLJO=w(I6h7y^`+o1s%u7>h)3Nc+?SxKiq-J3-RWK)FZ7tQM%UPsZ^i4^VGFF7p zH|`5IK7}kwaU*C^D7X>HLZnESUAdOHt+XhJi$MMEOIzP??z{Kg@0{=a&AUH+Z~Ep- zT2&Qo%^ccVJi7I1FIiu`dg;nVO13^cw)OSqWYMO8IMA9XRHUM)p6CAYA{-3XRzIc~ z@AXS-G#L*DAFcV_fpjofxpMjP>dJ_w>M>7G9!z5Q9M-qh>{M99 zj^$=1w3iVXNkrGbsXlZ4M4hO<4LGSRTk5OC1){E<*Grb=2_C{$zDi}B%apuYz}BOv zt7Q+jfenO5PFb~o{Gj8MB=E$NT9}cQfSlnI!h#U)_ZumA!Ce?>+jmrdC4d*)vC%m^NQ{5D)rg$=MrIyqQO;@`&b^QonG5<# zcXfcKT7?V+#`Q`#&)E-OhB z^|(lVbS#f2idHv}hb>^``bLpBEst9$vTsn)Q~)uOJea`vDVr?MY+Cj9^7#8*y-dpp zz@lv^R}mVG5is~XG}0p3Y4>QK>WDG7BS&&0G5jXUc4AJcdX&Dws=k}fW8FoGyGZ(6bWx}a1;L+<8-*-fxX7Z5;>JxE#Z?zYih>{v=y%^}X1M>~Ip25AJ@5WJ zb1<{}^o%aclFN0Xb%R++>%=?j3X{DT=D4x<_R`*43wvK~XYCegVjU3~MJfoYQ`|e& z4*LDgjSnfrcsh=tDYPO}Lo=WqEaFGYO@~bG1MO|MrD^AHj z_z|Y^c`QF!nU?1=xbZ0JMl!~!cCqj<*G^BCmpZwY$SD{{Z*)Wr;Z!+&p_3bVsn_dEAmvP3%Rz1!>)FT zOD{mJMN20l4msp`>DG!Np~#b0D7TUgrR|OLbj_47^Y#NostXy7wznj^o~PJNFLqW) z=)Cv(--N6MdVyT%^l3$b1Gf(zOBb$nvIf$iT;fyhbXVD+*5s)VZQ#I%m7ju|>o#dL5jYfMPNjWZYXsb>@w0AgzVt$$3zX&2f&arC|9;oF%#LDbqE2 z#UY^(FG{$&8l2?#`#V9(T}DM{?+(HXr)sS&r!$Cc$;f85y4zTqwXW4h3LKKpLKmTj zeW2*7EIe}b5M1MMXCSsc=28M_RA3*VCDtv|FujesvfIP(=-19 DHY@Yi diff --git a/massa-execution-worker/src/tests/wasm/send_message_condition_deployer.wasm b/massa-execution-worker/src/tests/wasm/send_message_condition_deployer.wasm index 4adf0b4baa83cdf7da487f3a15a56d024c0d3513..42514ce24d515f17620aa2facd5823259fb2531b 100644 GIT binary patch delta 218 zcmbQmHH~Y72_vJ}WK+g>8mt1WN{o&S3Jia^859_~O&FQ#9T^-Uq7%3r8UAoFFgS8J zvP|}7@?d12JcTKek!kWfCNrrX9u)=wb}4S|mCRxcjy)XQj5Z98GdQ^QnI_vYTLTqU zF&hHOHO%@z@(#15IxBA~83xA{T-@AD3=9k`Kx_qsj(dROIt-2{xVV*>Cfl%p rbmXu|1IZ2+O*JM4#|PZpyqrMA3UKWB11OXN8Y}{=N{o&S3Jia^859_~O&FQ#9T^-Uq7%3r8UAoFFgS8J zGEeqq@?d0}JcTKek#X`nCNrruJSq$V>{8s^YnjCv9D6vp8EqIGXK--qGfuW+wgxJy zVm1VlYnb(c8^aB(X$PPSnI z>BwP`29g~tnp%tujt{uGc{zZJ6@VB76c`*^c(}PzAUp;ppprQ}+>Dd2v)BUwGc6{5 diff --git a/massa-execution-worker/src/tests/wasm/send_message_trigger.wasm b/massa-execution-worker/src/tests/wasm/send_message_trigger.wasm index 8cca53b6a30ae4af1dd8d3569cca09201adbef5a..01a8b26b3f0dca07d1da2e20833af9c5e7a45117 100644 GIT binary patch delta 1379 zcmZ8hJ!l+96n<}JRyVt|cela;A#XslV~5C!jN@SB{6YK(N-POuNEJfh9Bc)==O`9F zD~(}QhLFO?HZEMGv>{zu6)IJ_PY5YpxCjY^6bH#Scd`PxC1w99Hd_66&Hk2Gm!GNee24_|w|n+yg!+uu-v=iS>o z)awie_jjV!PX~jWU*Ea2eRD)boAcuQeA;0WcIR@Pj1OJpYb&B}SvG4UBfm>GsS!R(0B(Kdtf|X(<{TLk5Ez=+@#t#8a*RsF=U{{L0 zkiwd7mRCsVYRr19kaNy=&XS+=YE4n%Q9Gi=*3WH~g#m8%ok>RIRmCou_7qE>#2`V0 z=lNE6?a zXIYW9c5dav)c5+%=N=Pbp-nW&5j{%`S0~|o9IpNgcQF#9&D#5OdyCPXqkHZ3)R$dF zl1QgDo%QBOanhh@MFj)mE5l_~2=B#PI1C0vK{m@^;zb*xYwgWu8T-()p5TZ47=Wnb z{9v!h!ZBs(|JayO8Aq91EkRA=4PfD(CiRThq{i(7ZzTIUw0T2uE@FcrSEJdB#$%4uaZ2;oKr;joDjW>zZ}f$M|dcbUuL`KnM&Md=|MFD!d#>As!Jmjc>bcXmuvLr&KMzq7r5(G={{lg>D+~6#ai@_HK9o-ra^EocMsuZj5joha?iR1sLIvL`ZCr^l8ozT(B36PdQ8z z>0E-8!e$!^3JQ=Y=+dM}5xNMaproLPgpepwAVFyf-t1lAPBZi8&zt|>fAjAi%sret zMepDGn2Cs&;w_%=1QTtUNw6@};i(bx;i2zY+wG7cW62Q{AO85#%ULuS>}-EV5!T(0 zcBs=H3_jfnRyP?8ZhUg{=Jt&-_393vJeDVICS~C?<0Ad8*Qrk&?^Pn5@{^>(_w z)-SEb-r#clUSG`^L5;Up`lZt+0pCQ6^>KV%e{*Za$`qN8@5cqqyVsf9r26Iy>dFPYik)S#szl)qOkYc(xXdEuYjn>Y$AY|ov zdLGqpyK|h>yKZ?d$=jt}G_G)V-9tQ(SEF3tbr(6g`@6&2a~^>u!hv|@O~bY8Z5~Iy zt3RiCTtCxV;<$dZbz&)C(F8Lr&#>lytoUwE@H|O9Y3-d1a1QXw+Xl;0kVe|7yX|)- zKN*fD$WTzuCF`@pMUyM<;i1hCO#;P~Hqb7Rgz@~LO*Z;LT?0P^fgAD3vzi%isF5cn zhmJ*i{a3nDLADXlH)jz-MVB}F;U%4?(1a1xgG@fE&_!U(`aobEbJS>x_Ae-7JQc*u zO8jnyp|ERE^RehbJs%f*P_MwZ@{85|xX feDDC@b|w9Ax+8-O_q#IhpYC;Pm}afNkkx+y2ENug diff --git a/massa-execution-worker/src/tests/wasm/send_message_wrong_trigger.wasm b/massa-execution-worker/src/tests/wasm/send_message_wrong_trigger.wasm index 037756ec7fbb7cfe4715313732c1f900f0aab33f..0e07a54748c028a6931660d7fbe54936d5dc6e3d 100644 GIT binary patch delta 1306 zcmZ8fO=ule6h7zvWbVwJyf>jjNS~BDH&xr1QiCP_YY%E|6N(Er?p~#h=)4#k`WiQd z3Ahn)(J&hqUFbqEYga-S;;PH+73oHB;ZB4u0`|M_#R$%D?woVx{C(fK`}5z&>7{T7PYf(E(Vr=@DNn_CYJ**C*-+`$fqc(jU3{y4qA8|RZvs&-9c31 zP>ID|9f%r7s6kyBMBDwQ7Fr|KD6;go1^xjllRR{CPIM}~NJulIID`5z3*20)U9eI$ zF_#mK+}y^`T7@j+S1_J~LYGt3BZa*8Av;ZBCa6_KHlTMx3p32D4=MxP9J0fLD5#pfoy?S4 zALpPzf)wnks)7#hb3((7P_RLd4m}VD^A37KL5u0ffZ~+lynmKe3j>UoAeNh`E0-(- z!qvF>H%WIdnsZ!qADZR)qROI1L~S&77!(i*g1ddQ!o?52n38K%*{D(008JCr1VAt7 zDz~902St^4Zf5DtJoNfLlmQ!Ip*0N22|Y_nSI6mml&=0u_bC&rExOw?I}0hCQ+N~f zB$jroI2Lo8Rr?#2$Y8%`>@J6y*LYuRc_5$Qh%_U=> z;I@o}Vd?~muY%sYUJklBSMx#lyt}}v`^bfrvMMX>4VLFM@kCz0HsxOLG=UqNSdqJh zP~t?KnC?e6nETS6BKgXBewE~F=g+I|clQb^*7*v~_ww^NKhIxUwRj KN|JP&{D+~6#ai@_HK4(?`}=g*t>|GfEkU(J3q zJ5TT4eV>Vlm+eg+^B4o&RO9Fo3?5D9*I7@h7nvs$-!r<~Aw|kiqM3N|_=T79WH8v? z`iK(DJMV2%r#%>axE;N2IvCvg;Le?`TO;b#9iE#h(l(Q@<1FXX*%!S|eS!aGQ=d_% znCf-4G(OPm#-0{c9$LaxNP>zh8&Xkwn`X@``3E0@D_^Fv@8pEMToAd4qSDF{cC}B1 zM?rf%U0&}8E!Ha>wr}-CjXIM ztmwEqPvA1c&_>dbc~z~K&KoJJkjsfmc6PB@YM=T18ftd1yuPGQj*+zr+3OUX6eHH(km7`}cOG*b6zL`9^<@gsw)0V~3mrdVze~>+^~dk38|ZSo-#6zc9GC z^4U>F=&J8!QbCmf`hP6iss1GdrH z_!fk$JWuzN`VDiI(|X6O%%(*<=tX5pqt`sdL-C@7>qlml(?`FXoJ%eeR0%p1UU}8j z+V#4yiSNqKSz+sETFY$f%dL~k5sM}`#_};%{f~9N+jDrHv>vzi<|3RUyz;uivMWgv zY1Q5Ko8uo9Cu3wNso=o!>~K*P!h3jVHAIs@F`*5#3nXDYe{7SDepFW>4nYtGKY12) zTsPDx(!jA}(O&;uU8p482_0`(x1Pbzc~DrWh?!JA2_(G=}p zQqFiPh?xicZiew<*P-U2ll^+mmb_nIw68GNJJzqd!WG&XFgZ=!*acQ&Ip{8+gTzE# zWIq#%s)!X`Keqju&y&+653J)$B%fJ#j_bedMKCUi|%5S!;b6Z2zXfhK;e(OF1tNl WkplO_t~=$Qu4U?|X0C6$%l`uSz}1fc diff --git a/massa-execution-worker/src/tests/wasm/set_bytecode_fail.wasm b/massa-execution-worker/src/tests/wasm/set_bytecode_fail.wasm index aa7bcfe970fe68a04b0352eec261e30c17aa6753..dbc146e552098ebbabb62754d9677601e6a77843 100644 GIT binary patch delta 1312 zcmY*ZON$&;6u!^8RduVKlJONPi&K>-BRYmb9Z4cOXQ56E65O~EZA_d+s*_13wh=+- z;Mzr`HVOe<3W5xX8}SDOL~tRv5sW)U5pnCl_?=s0Fx}jH9``)H^XUG4`OoF+pJ$Uw zS*t(XedOinr_=4Nca#Uce12P1VLE+#TewLvou0dN;lkFrxw8@wC&uZrK- zd|$0pgjV;R7o)t3Y_6V$r5}EF53EC_+LHJ7_xCMD*7MGi9mO+E=Qt-%p7WO)HtC7n zsirH2Rexwvay^5^(hh5K4U#IpmGdfFNqIz(V>jz^#P2e4{qwD-g6qDsyxjBU9Xz&y zEM*A`@El}?$e-pC=?QKVct@e{vS(H2xt{ZqICu86Yfu7ZWM>TMJzu-_-VWDS1wKl< z1USW>6%`a` zdl7zAz5pjM$S@KYLE(@KeMXwTZYuCA#$g0z-jjiC{M+fUAjS90R!sd|YMicpr}_Jm zm0;qU!!S1wE(%eLMTM^VR?8%nq)SACLdw~(_!|fcPbtYr#KOTs43SXPSslP*UEneD z2D~}oEqE(DyVj6id024E0R5~@T;5thDHGT`a13l8dtH-H*w9Fi%HbisL2|4eyMwjd zt@ua9VO&czM)nVbg~nrlcN|`a@BnOzokGA z5epBfQ(lL)(A@otJFNJFJnE+vf0V~#W_T@})MofNtl|DP9K-!jIR2zpe4~sS#-Eij z8l{xOIe{;KGwN@G;2-8E5XAbmjH_lin;(b&jr=LxKcu@V9tXcste&XgpX0!1cM>NP buyp(I%}G4;CPbrg7^hGGJ${C-i?x3N6cfxM delta 1344 zcmZ8hy>A>v6o2!vx3fFDmqmu^EcA9`qeIapL`a7M2>c4b1_g^IC6|!6$e!cG;Rqlh zT?$Hyplv8pq>MykphAL<9ttERM1e$u_!57BCHT$kxqv;*yx*Jm{pQX6wf6hky-$1_7SK|n<|n_a!RzrS~NL8YI~ZZ8(sXK!73d(WuB zjlCN;Z@;g}sbQ8X66IA^sP+6o;lG%u(`xfuNR~|U=zOfJm+Y31P?a=FzRQJ1Yig2t9g(XIQprMA|IMSDBxm2$ob-_`Cv6PQCI%mCPq(;H>*H87(u;#9bVTUNj~a9SSqYp15Qkf=2?| zK61&~R2OE8GakNXx0o1ZvuZ`PbtpXE07_FhK>ummE?KdS7>D%gC<%O6+aq6_*Fz(N zlK!6(_;3a#HuK=Aw+6DPt3Y7WvI=+0LoUa<*hMzO?uveFISjFpF`Cpk(RV_gR{p_9 zfbt-dzYAHDr((yTMYWe>NDVtti$)<*WOqksi9;Utq(cy~*%>vt{1Nn{Hzz+k`Gw^1 z=*~;E6Vg3(h?!8MIEs)@Fa@}u)1eAGZ_+pdXxqzZRW4PFKx?hsI)tzuu;C=;+`VAd zmx>2%le|ccm1-fUf>skEBd-LlL0zVmyLUf0l2MYriXt);44j_gUoL;nC#PP<{2*P?;C`2i}Bc@7M#_uYVErn{TROPyF2A7_= zKioiVaR!v!J9*s>?M)g8;4VnJt#tIrpLU((Bj?rgB%e5cPIdd~b4qm&)AQJWOwVD@ z-G#H3f=JWks`|1{O7ZIP|LfIy?U_XPnO# diff --git a/massa-execution-worker/src/tests/wasm/smart-contract.wasm b/massa-execution-worker/src/tests/wasm/smart-contract.wasm index 7e26ded01f89ccca8f757037b311b47add036013..87e783fbf688f30b126e845d35ca89b2fb5b7d00 100644 GIT binary patch delta 257 zcmYjLy-EXN5Zs^7%iVpSkRqob7JE@4f*43^iY!>93IX5Z6syx`ND;yCH5Nh$SO|Fq zA0S0~!AD4ClP-mu&V^xShZ%N%8sClA1&91)_OW(L!X(ysmL>|rLy#oSadfBCtV5vq z+&1T-QmmDlSP~D!NiuXsO11u`mBrd@I|*8<5*F6heTSO+GMlx_0R)BPEnNhsSd}iI z_jc%s`o~}SIe5Rt06I-QUV*-)zM#0G5-D!z@fu-diOhR08_YXH!EC~Pr delta 256 zcmWlSu}T9`5Jl(CyhnETWids>CWP6j5JAibm?G1qvh^QU8)5M)QW#!iA&6j+&L6O} zOfQHZVPR?E?1jtBT+U@a2VaAS7pbf5_H`fL7%_J^E`rgzCJp%+SJxVBQ_h(T_cOX} z4V__xhK(ALm5PRS@L}B9PtiI!i+;1h$yTFA8{f=%)Yqd&e-)8JV_xy;Pz-G&L!{)- z?s$2$uTChXU({rqBH^6uu}Fu=AKXkpMC@+JzKb-S_$uyRk|EOrkUfTnchq|D?tS0+`JIpRJ`a5uS}hl0Ubp3e zdBFBs?G);@nYE(HtJnPMebRChh zuj-YY5A>VqY1C~872?CUYn1SEv!WdS1E!H`?hK^hw4QL9Nos;4r+i5VPBk1l6Y4w2 z?wT{%YHp?RU-f@e!jih)=+ zQj!q4uxP9mi)vUKY~*biY?zpoJfmoj(Q;EzBQ=gv6k^6j*Q8ujN6}M63(SP=mf4r5gD$|Klqq`A@FN@gjFRqO9_$B|(>D zSZwjJMKMK7`!HE-2`(Pse87E6W!}YBYlJ*GKe$W$H40oMDcMV zO5{bc4r-*m0NsU=RnbY5DuxuZa(;ML`>e&KeFgTU1d&Q5#S!u=;wv}`$SxqY`P)E( zNg;_73bz!iVv?&+a)=EVvitej6DxyN=$cE`zVELCujDOW1b&vcb;`cyFUWEa70${z zR}cZS$A!@z1N<_!SO$I_TT9ue!cjv2P|L=9k7rR_mbjDgJvm>*qez=y;&u5`HXjxH zwb-5}H+p1SR|dL$2JA3p*n3_)qrJYvt=>W3;cY4S-<7=oN$`IR{$JtyTwf}&bA8p* bRywe0N{ delta 1051 zcmZ`&&ubGw6n<}JHr?z*x=93^kjQLIHMED;9$K4|DZ?@JtzqJ&2B(EILrKaZ{B;~_uiZRF#d6TtCHj1 zD$%OyVbGv)mc7BvK~9eNOp-~EQiH=aIUW3r@A4t5__`P`s?e*k-3l!I3W&7zt=xMo zZZmWIO}@bTNWH#xjb+b}J^7#^Lc7tf3B!K{*{Z3lYSH#fquMCT2&fDh;o=!#RLiiD ziJ;=HH_~Ueu^_u!PFWZl)t2j^RgP$Axm9jOLN2<%%L>~RQ%%}F zFRLENaLY50!c-Ee^h367e^)MnxoE+yo%r=w*nV=gFPETUt6CAm1{>u(t)Y=EtrMMa zI!<&HdQrki4jFBYTiFdxRAd`+BWFgejgS0oYVo2Vfe8w41fvo zf`bdY4m+19hVYOJ>-LB{omt_CxN?93Hknj~;+>J|83&ZcY?6RgQYmMLO3AcR@pEr3 zat;08E6`td6lN2jJ%AqG?*r$3n04Nb;33wR!94Tc*WfLFn7t>tqJnNa zyi;T#mQuu$o^-M5@oM2z9OWypxRiI8Yx(LZFb~RU>@w`)XZbnYd`j*`!JV6h2sB2_Fe+ From c4c155f1c9dc2cdf577b0859080ca01ce33ba39d Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Mon, 30 Jan 2023 13:39:37 +0100 Subject: [PATCH 67/80] Bind to IPv6 addr. (#3463) * Added comments for IPv6 setup. --- massa-client/base_config/config.toml | 1 + massa-node/base_config/config.toml | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/massa-client/base_config/config.toml b/massa-client/base_config/config.toml index f3459f28729..586465305c7 100644 --- a/massa-client/base_config/config.toml +++ b/massa-client/base_config/config.toml @@ -3,6 +3,7 @@ history_file_path = "config/.massa_history" timeout = 1000 [default_node] +# The IP of your node. Works both with IPv4 (like 127.0.0.1) and IPv6 (like ::1) addresses, if the node is bound to the correct protocol. ip = "127.0.0.1" private_port = 33034 public_port = 33035 diff --git a/massa-node/base_config/config.toml b/massa-node/base_config/config.toml index ffacc36aeb9..e6ad4f77846 100644 --- a/massa-node/base_config/config.toml +++ b/massa-node/base_config/config.toml @@ -7,11 +7,11 @@ [api] # max number of future periods considered during requests draw_lookahead_period_count = 10 - # port on which the node API listens for admin and node management requests. Dangerous if publicly exposed + # port on which the node API listens for admin and node management requests. Dangerous if publicly exposed. Bind to "[::1]:port" if you want to access the node from IPv6. bind_private = "127.0.0.1:33034" - # port on which the node API listens for public requests. Can be exposed to the Internet + # port on which the node API listens for public requests. Can be exposed to the Internet. Bind to "[::]:port" if you want to access the node from IPv6. bind_public = "0.0.0.0:33035" - # port on which the node API(V2) listens for HTTP requests and WebSockets subscriptions. Can be exposed to the Internet + # port on which the node API(V2) listens for HTTP requests and WebSockets subscriptions. Can be exposed to the Internet. Bind to "[::]:port" if you want to access the node from IPv6. bind_api = "0.0.0.0:33036" # max number of arguments per RPC call max_arguments = 128 From 72a41b7970a40e832dab3bd5f4c0f6e95a79d6d4 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 30 Jan 2023 16:14:08 +0100 Subject: [PATCH 68/80] Provide context for Address dbg impl (#3482) --- massa-models/src/address.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/massa-models/src/address.rs b/massa-models/src/address.rs index 63266f78a3c..384c01f0c6a 100644 --- a/massa-models/src/address.rs +++ b/massa-models/src/address.rs @@ -41,6 +41,8 @@ impl std::fmt::Display for Address { } } +// See https://github.com/massalabs/massa/pull/3479#issuecomment-1408694720 +// as to why more information is not provided impl std::fmt::Debug for Address { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self) From 362dd2dd8f06537a0cee08a6082a0c774b5df9d6 Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA <22281426+aoudiamoncef@users.noreply.github.com> Date: Tue, 31 Jan 2023 13:24:27 +0100 Subject: [PATCH 69/80] Add current/next slot timestamp to `get_status` (#3472) --- .rusty-hook.toml | 2 +- massa-api-exports/src/node.rs | 4 ++++ massa-api/src/public.rs | 37 ++++++++++++++++++++++++++--- massa-client/src/cmds.rs | 2 +- massa-node/base_config/openrpc.json | 10 ++++++++ 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/.rusty-hook.toml b/.rusty-hook.toml index e51c329f52c..34a4f400b96 100644 --- a/.rusty-hook.toml +++ b/.rusty-hook.toml @@ -1,4 +1,4 @@ -# Generate git hooks run: cargo install rusty-hook && rusty-hook +# Generate git hooks run: cargo install rusty-hook && rusty-hook init [hooks] pre-commit= "cargo check && cargo fmt -- --check && cargo clippy -- -A clippy::uninlined-format-args" diff --git a/massa-api-exports/src/node.rs b/massa-api-exports/src/node.rs index 4b44abc51f2..7f8069e291a 100644 --- a/massa-api-exports/src/node.rs +++ b/massa-api-exports/src/node.rs @@ -21,6 +21,10 @@ pub struct NodeStatus { pub current_time: MassaTime, /// current cycle pub current_cycle: u64, + /// current cycle starting timestamp + pub current_cycle_time: MassaTime, + /// next cycle starting timestamp + pub next_cycle_time: MassaTime, /// connected nodes (node id, ip address, true if the connection is outgoing, false if incoming) pub connected_nodes: BTreeMap, /// latest slot, none if now is before genesis timestamp diff --git a/massa-api/src/public.rs b/massa-api/src/public.rs index 3d06e86ae6d..7b01b99ae0b 100644 --- a/massa-api/src/public.rs +++ b/massa-api/src/public.rs @@ -381,11 +381,44 @@ impl MassaRpcServer for API { }) .collect::>(); + let current_cycle = last_slot + .unwrap_or_else(|| Slot::new(0, 0)) + .get_cycle(api_settings.periods_per_cycle); + + let cycle_duration = match api_settings.t0.checked_mul(api_settings.periods_per_cycle) { + Ok(cycle_duration) => cycle_duration, + Err(e) => return Err(ApiError::TimeError(e).into()), + }; + + let current_cycle_time_result = if current_cycle == 0 { + Ok(api_settings.genesis_timestamp) + } else { + cycle_duration.checked_mul(current_cycle).and_then( + |elapsed_time_before_current_cycle| { + api_settings + .genesis_timestamp + .checked_add(elapsed_time_before_current_cycle) + }, + ) + }; + + let current_cycle_time = match current_cycle_time_result { + Ok(current_cycle_time) => current_cycle_time, + Err(e) => return Err(ApiError::TimeError(e).into()), + }; + + let next_cycle_time = match current_cycle_time.checked_add(cycle_duration) { + Ok(next_cycle_time) => next_cycle_time, + Err(e) => return Err(ApiError::TimeError(e).into()), + }; + Ok(NodeStatus { node_id, node_ip: network_config.routable_ip, version, current_time: now, + current_cycle_time, + next_cycle_time, connected_nodes, last_slot, next_slot, @@ -394,9 +427,7 @@ impl MassaRpcServer for API { network_stats, pool_stats, config, - current_cycle: last_slot - .unwrap_or_else(|| Slot::new(0, 0)) - .get_cycle(api_settings.periods_per_cycle), + current_cycle, }) } diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index 734b72a0919..ea8967dfeaf 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -1443,7 +1443,7 @@ where value .1 .parse::() - .map(|op| Some(op)) + .map(Option::Some) .map_err(|e| anyhow!("failed to parse \"{}\" due to: {}", value.1, e)) } else { Ok(None) diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index 652ecaf69ef..04dfb618083 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -2346,6 +2346,8 @@ "consensus_stats", "current_cycle", "current_time", + "current_cycle_time", + "next_cycle_time", "network_stats", "next_slot", "node_id", @@ -2374,6 +2376,14 @@ "description": "Time in milliseconds since 1970-01-01", "type": "number" }, + "current_cycle_time": { + "description": "current cycle starting time in milliseconds since 1970-01-01", + "type": "number" + }, + "next_cycle_time": { + "description": "next cycle starting time in milliseconds since 1970-01-01", + "type": "number" + }, "last_slot": { "$ref": "#/components/schemas/Slot", "description": "Latest slot, none if now is before genesis timestamp" From dc6cda4c608409de2a26ee0d904d49bdc8108a2b Mon Sep 17 00:00:00 2001 From: Thomas Plisson Date: Tue, 31 Jan 2023 18:11:17 +0100 Subject: [PATCH 70/80] update setup_test.rs version --- tools/setup_test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/setup_test.rs b/tools/setup_test.rs index cc84ccbdde1..4401cc9e06e 100644 --- a/tools/setup_test.rs +++ b/tools/setup_test.rs @@ -26,7 +26,7 @@ use glob::glob; use tar::Archive; // git tag -const TAG: &str = "TEST.19.0"; +const TAG: &str = "TEST.19.1"; // 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) From f5cb1bc8f0bd9ea28379e9ac4287b5931cd11d56 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Wed, 1 Feb 2023 01:38:35 +0100 Subject: [PATCH 71/80] Update dependencies and increase block size --- Cargo.lock | 101 ++++++++++++--------------- massa-models/src/config/constants.rs | 2 +- 2 files changed, 45 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6152784f6cd..ff98c8842d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -144,7 +144,7 @@ checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" [[package]] name = "as-ffi-bindings" version = "0.2.5" -source = "git+https://github.com/massalabs/as-ffi-bindings.git?tag=v0.3.1#bc2cf68abd3e763ac21793de8cb3b428a56ca504" +source = "git+https://github.com/massalabs/as-ffi-bindings.git?tag=v0.3.2#156c2a86fa03d14c72c1baec3fb25c6c517ca546" dependencies = [ "anyhow", "wasmer", @@ -188,9 +188,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.63" +version = "0.1.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eff18d764974428cf3a9328e23fc5c986f5fbed46e6cd4cdf42544df5d297ec1" +checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2" dependencies = [ "proc-macro2", "quote", @@ -446,9 +446,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "bzip2-sys" @@ -994,17 +994,6 @@ dependencies = [ "parking_lot_core", ] -[[package]] -name = "derivative" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "dialoguer" version = "0.10.3" @@ -1348,9 +1337,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" +checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84" dependencies = [ "futures-channel", "futures-core", @@ -1363,9 +1352,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" +checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" dependencies = [ "futures-core", "futures-sink", @@ -1373,15 +1362,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" +checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" [[package]] name = "futures-executor" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" +checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e" dependencies = [ "futures-core", "futures-task", @@ -1390,9 +1379,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" +checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" [[package]] name = "futures-lite" @@ -1411,9 +1400,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" +checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" dependencies = [ "proc-macro2", "quote", @@ -1422,15 +1411,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" +checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" [[package]] name = "futures-task" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" +checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" [[package]] name = "futures-timer" @@ -1444,9 +1433,9 @@ dependencies = [ [[package]] name = "futures-util" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" +checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" dependencies = [ "futures-channel", "futures-core", @@ -2290,7 +2279,7 @@ dependencies = [ [[package]] name = "massa-sc-runtime" version = "0.10.0" -source = "git+https://github.com/massalabs/massa-sc-runtime?branch=testnet_19#a1eb0b21ef2f27c86aa9c4e174d90aca406006c8" +source = "git+https://github.com/massalabs/massa-sc-runtime?branch=testnet_19#6602be544a08513c52837b052116f4264b689302" dependencies = [ "anyhow", "as-ffi-bindings", @@ -4862,9 +4851,9 @@ checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "unicode-segmentation" -version = "1.10.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" @@ -5080,13 +5069,12 @@ dependencies = [ [[package]] name = "wasmer" -version = "3.2.0-alpha.1" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b370ee845c45c8a94964e25a99b98cceec487fad2ca0e99986117bc0709bf5e7" +checksum = "840af6d21701220cb805dc7201af301cb99e9b4f646f48a41befbc1d949f0f90" dependencies = [ "bytes", "cfg-if", - "derivative", "indexmap", "js-sys", "more-asserts 0.2.2", @@ -5107,9 +5095,9 @@ dependencies = [ [[package]] name = "wasmer-compiler" -version = "3.2.0-alpha.1" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62e9aff72e22851e0dbabee9a769d6292cb8f5f601b137acfadb438bd8f80da1" +checksum = "b86fab98beaaace77380cb04e681773739473860d1b8499ea6b14f920923e0c5" dependencies = [ "backtrace", "cfg-if", @@ -5131,9 +5119,9 @@ dependencies = [ [[package]] name = "wasmer-compiler-cranelift" -version = "3.2.0-alpha.1" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b77b1e6b7aada98318ffd76d9be79894879fd91bb9c9d1ab4b88389c4b22125a" +checksum = "015eef629fc84889540dc1686bd7fa524b93da9fd2d275b16c49dbe96268e58f" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -5150,9 +5138,9 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" -version = "3.2.0-alpha.1" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2e517ccbc64ef34ea54148d8551356a067c9dc385861efb5b8dd8b7d1c6c2fc" +checksum = "07e235ccc192d5f39147e8a430f48040dcfeebc1f1b0d979d2232ec1618d255c" dependencies = [ "byteorder", "dynasm", @@ -5169,9 +5157,9 @@ dependencies = [ [[package]] name = "wasmer-derive" -version = "3.2.0-alpha.1" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d78af99a44fe5ba0a261e6ae2b6488877578d5f4bc3e9eb646ea45791d4020c" +checksum = "1ff577b7c1cfcd3d7c5b3a09fe1a499b73f7c17084845ff71225c8250a6a63a9" dependencies = [ "proc-macro-error", "proc-macro2", @@ -5181,9 +5169,9 @@ dependencies = [ [[package]] name = "wasmer-middlewares" -version = "3.2.0-alpha.1" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cb58b909e069484bf48ace103085ae100c1295d3a407db744de96fa09ee0309" +checksum = "c3f7b2443d00487fcd63e0158ea2eb7a12253fcc99b1c73a7a89796f3cb5a10f" dependencies = [ "wasmer", "wasmer-types", @@ -5192,9 +5180,9 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "3.2.0-alpha.1" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad3d70c9f8df77de3483b3381c5de78aa48d9caa99a6c3df15697efc3a5270f7" +checksum = "8b9600f9da966abae3be0b0a4560e7d1f2c88415a2d01ce362ac06063cb1c473" dependencies = [ "enum-iterator", "enumset", @@ -5207,15 +5195,14 @@ dependencies = [ [[package]] name = "wasmer-vm" -version = "3.2.0-alpha.1" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0c328ad1b4d0f2f18e1fd58101b6496ac4fbdd642790251524728912b3d5b4f" +checksum = "9fc68a7f0a003e6cb63845b7510065097d289553201d64afb9a5e1744da3c6a0" dependencies = [ "backtrace", "cc", "cfg-if", "corosensei", - "derivative", "enum-iterator", "indexmap", "lazy_static", @@ -5464,9 +5451,9 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.5+zstd.1.5.2" +version = "2.0.6+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edc50ffce891ad571e9f9afe5039c4837bede781ac4bb13052ed7ae695518596" +checksum = "68a3f9792c0c3dc6c165840a75f47ae1f4da402c2d006881129579f6597e801b" dependencies = [ "cc", "libc", diff --git a/massa-models/src/config/constants.rs b/massa-models/src/config/constants.rs index cc2ae63be14..a09935817ca 100644 --- a/massa-models/src/config/constants.rs +++ b/massa-models/src/config/constants.rs @@ -94,7 +94,7 @@ pub const DELTA_F0: u64 = 64 * (ENDORSEMENT_COUNT as u64 + 1); /// Maximum number of operations per block pub const MAX_OPERATIONS_PER_BLOCK: u32 = 5000; /// Maximum block size in bytes -pub const MAX_BLOCK_SIZE: u32 = 500_000; +pub const MAX_BLOCK_SIZE: u32 = 1_000_000; /// Maximum capacity of the asynchronous messages pool pub const MAX_ASYNC_POOL_LENGTH: u64 = 10_000; /// Maximum data size in async message From 03776e58ad0f31060f3c0b7bf5cb7e31d1c2cfb6 Mon Sep 17 00:00:00 2001 From: Moncef AOUDIA <22281426+aoudiamoncef@users.noreply.github.com> Date: Wed, 1 Feb 2023 13:23:21 +0100 Subject: [PATCH 72/80] Enhance transfer coins error messages (#3483) --- .../src/speculative_ledger.rs | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/massa-execution-worker/src/speculative_ledger.rs b/massa-execution-worker/src/speculative_ledger.rs index 49fa3e3128f..4baf0d46f18 100644 --- a/massa-execution-worker/src/speculative_ledger.rs +++ b/massa-execution-worker/src/speculative_ledger.rs @@ -147,10 +147,11 @@ impl SpeculativeLedger { if let Some(from_addr) = from_addr { let new_balance = self .get_balance(&from_addr) - .ok_or_else(|| ExecutionError::RuntimeError("source addr not found".to_string()))? + .ok_or_else(|| ExecutionError::RuntimeError(format!("spending address {} not found", from_addr)))? .checked_sub(amount) .ok_or_else(|| { - ExecutionError::RuntimeError("insufficient from_addr balance".into()) + ExecutionError::RuntimeError(format!("failed to transfer {} from spending address {} due to insufficient balance {}", amount, from_addr, self + .get_balance(&from_addr).unwrap_or_default())) })?; changes.set_balance(from_addr, new_balance); } @@ -161,14 +162,17 @@ impl SpeculativeLedger { let old_balance = changes.get_balance_or_else(&to_addr, || self.get_balance(&to_addr)); match (old_balance, from_addr) { // if `to_addr` exists we increase the balance - (Some(old_balance), _) => { + (Some(old_balance), _from_addr) => { let new_balance = old_balance.checked_add(amount).ok_or_else(|| { - ExecutionError::RuntimeError("overflow in to_addr balance".into()) + ExecutionError::RuntimeError(format!( + "overflow in crediting address {} balance {} due to adding {}", + to_addr, old_balance, amount + )) })?; changes.set_balance(to_addr, new_balance); } // if `to_addr` doesn't exist but `from_addr` is defined. `from_addr` will create the address using the coins sent. - (None, Some(_)) => { + (None, Some(_from_addr)) => { //TODO: Remove when stabilized debug!("Creating address {} from coins in transactions", to_addr); if amount >= self.storage_costs_constants.ledger_entry_base_cost { @@ -179,17 +183,18 @@ impl SpeculativeLedger { .checked_sub(self.storage_costs_constants.ledger_entry_base_cost) .ok_or_else(|| { ExecutionError::RuntimeError( - "overflow in subtract ledger cost for addr".to_string(), + format!("underflow in subtract ledger cost {} for new crediting address {}", to_addr, self.storage_costs_constants.ledger_entry_base_cost), ) })?, ); } else { - return Err(ExecutionError::RuntimeError( - "insufficient amount to create receiver address".to_string(), - )); + return Err(ExecutionError::RuntimeError(format!( + "insufficient amount {} to create crediting address {}", + amount, to_addr + ))); } } - // if `from_addr` is none and `to_addr` doesn't exist try to create it from coins sent + // if `from_addr` is none and `to_addr` doesn't exist(in the ledger) try to create it from coins sent (None, None) => { //TODO: Remove when stabilized debug!("Creating address {} from coins generated", to_addr); @@ -202,7 +207,7 @@ impl SpeculativeLedger { .checked_sub(self.storage_costs_constants.ledger_entry_base_cost) .ok_or_else(|| { ExecutionError::RuntimeError( - "overflow in subtract ledger cost for addr".to_string(), + format!("underflow in subtract ledger cost {} for new crediting address {}", to_addr, self.storage_costs_constants.ledger_entry_base_cost), ) })?, ); From fad42ae05c24b90e9f8c397e1d9fcca0f041c085 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 1 Feb 2023 14:08:01 +0100 Subject: [PATCH 73/80] ledger-db restructuring (#3441) --- .../src/speculative_ledger.rs | 9 +- massa-ledger-exports/src/controller.rs | 10 - massa-ledger-worker/src/ledger.rs | 19 +- massa-ledger-worker/src/ledger_db.rs | 389 +++++++++--------- 4 files changed, 206 insertions(+), 221 deletions(-) diff --git a/massa-execution-worker/src/speculative_ledger.rs b/massa-execution-worker/src/speculative_ledger.rs index 4baf0d46f18..a251f3c050d 100644 --- a/massa-execution-worker/src/speculative_ledger.rs +++ b/massa-execution-worker/src/speculative_ledger.rs @@ -460,9 +460,12 @@ impl SpeculativeLedger { .fetch_active_history_data_entry(addr, key) { HistorySearchResult::Present(_entry) => true, - HistorySearchResult::NoInfo => { - self.final_state.read().ledger.has_data_entry(addr, key) - } + HistorySearchResult::NoInfo => self + .final_state + .read() + .ledger + .get_data_entry(addr, key) + .is_some(), HistorySearchResult::Absent => false, } }) diff --git a/massa-ledger-exports/src/controller.rs b/massa-ledger-exports/src/controller.rs index 016b08f07ed..e25f43e27bb 100644 --- a/massa-ledger-exports/src/controller.rs +++ b/massa-ledger-exports/src/controller.rs @@ -42,16 +42,6 @@ pub trait LedgerController: Send + Sync + Debug { /// A copy of the datastore value, or `None` if the ledger entry or datastore entry was not found fn get_data_entry(&self, addr: &Address, key: &[u8]) -> Option>; - /// Checks for the existence of a datastore entry for a given address. - /// - /// # Arguments - /// * `addr`: target address - /// * `key`: datastore key - /// - /// # Returns - /// true if the datastore entry was found, or false if the ledger entry or datastore entry was not found - fn has_data_entry(&self, addr: &Address, key: &[u8]) -> bool; - /// Get every key of the datastore for a given address. /// /// # Returns diff --git a/massa-ledger-worker/src/ledger.rs b/massa-ledger-worker/src/ledger.rs index fc168b31e1a..b21bb1413c6 100644 --- a/massa-ledger-worker/src/ledger.rs +++ b/massa-ledger-worker/src/ledger.rs @@ -134,29 +134,12 @@ impl LedgerController for FinalLedger { .get_sub_entry(addr, LedgerSubEntry::Datastore(key.to_owned())) } - /// Checks for the existence of a datastore entry for a given address. - /// - /// # Arguments - /// * `addr`: target address - /// * `key`: datastore key - /// - /// # Returns - /// true if the datastore entry was found, or false if the ledger entry or datastore entry was not found - fn has_data_entry(&self, addr: &Address, key: &[u8]) -> bool { - self.sorted_ledger - .get_sub_entry(addr, LedgerSubEntry::Datastore(key.to_owned())) - .is_some() - } - /// Get every key of the datastore for a given address. /// /// # Returns /// A `BTreeSet` of the datastore keys fn get_datastore_keys(&self, addr: &Address) -> Option>> { - match self.entry_exists(addr) { - true => Some(self.sorted_ledger.get_datastore_keys(addr)), - false => None, - } + self.sorted_ledger.get_datastore_keys(addr) } /// Get the current disk ledger hash diff --git a/massa-ledger-worker/src/ledger_db.rs b/massa-ledger-worker/src/ledger_db.rs index 4f01b8f4a61..4493c2c61e2 100644 --- a/massa-ledger-worker/src/ledger_db.rs +++ b/massa-ledger-worker/src/ledger_db.rs @@ -52,6 +52,16 @@ pub enum LedgerSubEntry { Datastore(Vec), } +impl LedgerSubEntry { + fn derive_key(&self, addr: &Address) -> Vec { + match self { + LedgerSubEntry::Balance => balance_key!(addr), + LedgerSubEntry::Bytecode => bytecode_key!(addr), + LedgerSubEntry::Datastore(hash) => data_key!(addr, hash), + } + } +} + /// Disk ledger DB module /// /// Contains a `RocksDB` DB instance @@ -73,29 +83,6 @@ impl Debug for LedgerDB { } } -/// For a given start prefix (inclusive), returns the correct end prefix (non-inclusive). -/// This assumes the key bytes are ordered in lexicographical order. -/// Since key length is not limited, for some case we return `None` because there is -/// no bounded limit (every keys in the series `[]`, `[255]`, `[255, 255]` ...). -fn end_prefix(prefix: &[u8]) -> Option> { - let mut end_range = prefix.to_vec(); - while let Some(0xff) = end_range.last() { - end_range.pop(); - } - if let Some(byte) = end_range.last_mut() { - *byte += 1; - Some(end_range) - } else { - None - } -} - -#[test] -fn test_end_prefix() { - assert_eq!(end_prefix(&[5, 6, 7]), Some(vec![5, 6, 8])); - assert_eq!(end_prefix(&[5, 6, 255]), Some(vec![5, 7])); -} - /// Batch containing write operations to perform on disk and cache for the ledger hash computing pub struct LedgerBatch { // Rocksdb write batch @@ -210,6 +197,164 @@ impl LedgerDB { self.write_batch(batch); } + /// Get the current disk ledger hash + pub fn get_ledger_hash(&self) -> Hash { + let handle = self.db.cf_handle(METADATA_CF).expect(CF_ERROR); + if let Some(ledger_hash_bytes) = self + .db + .get_pinned_cf(handle, LEDGER_HASH_KEY) + .expect(CRUD_ERROR) + .as_deref() + { + Hash::from_bytes(ledger_hash_bytes.try_into().expect(LEDGER_HASH_ERROR)) + } else { + // initial ledger_hash value to avoid matching an option in every XOR operation + // because of a one time case being an empty ledger + // also note that the if you XOR a hash with itself result is LEDGER_HASH_INITIAL_BYTES + Hash::from_bytes(LEDGER_HASH_INITIAL_BYTES) + } + } + + /// Get the given sub-entry of a given address. + /// + /// # Arguments + /// * `addr`: associated address + /// * `ty`: type of the queried sub-entry + /// + /// # Returns + /// An Option of the sub-entry value as bytes + pub fn get_sub_entry(&self, addr: &Address, ty: LedgerSubEntry) -> Option> { + let handle = self.db.cf_handle(LEDGER_CF).expect(CF_ERROR); + self.db + .get_cf(handle, ty.derive_key(addr)) + .expect(CRUD_ERROR) + } + + /// Get every key of the datastore for a given address. + /// + /// # Returns + /// A `BTreeSet` of the datastore keys + pub fn get_datastore_keys(&self, addr: &Address) -> Option>> { + let handle = self.db.cf_handle(LEDGER_CF).expect(CF_ERROR); + + let mut opt = ReadOptions::default(); + opt.set_iterate_range(data_prefix!(addr).clone()..end_prefix(data_prefix!(addr)).unwrap()); + + let mut iter = self + .db + .iterator_cf_opt(handle, opt, IteratorMode::Start) + .flatten() + .map(|(key, _)| key.split_at(ADDRESS_SIZE_BYTES + 1).1.to_vec()) + .peekable(); + + // Return None if empty + // TODO: function should return None if complete entry does not exist + // and Some([]) if it does but datastore is empty + iter.peek()?; + Some(iter.collect()) + } + + /// Get a part of the disk Ledger. + /// Mainly used in the bootstrap process. + /// + /// # Arguments + /// * `last_key`: key where the part retrieving must start + /// + /// # Returns + /// A tuple containing: + /// * The ledger part as bytes + /// * The last taken key (this is an optimization to easily keep a reference to the last key) + pub fn get_ledger_part( + &self, + cursor: StreamingStep>, + ) -> Result<(Vec, StreamingStep>), ModelsError> { + let handle = self.db.cf_handle(LEDGER_CF).expect(CF_ERROR); + let opt = ReadOptions::default(); + let ser = VecU8Serializer::new(); + let key_serializer = KeySerializer::new(); + let mut ledger_part = Vec::new(); + + // Creates an iterator from the next element after the last if defined, otherwise initialize it at the first key of the ledger. + let (db_iterator, mut new_cursor) = match cursor { + StreamingStep::Started => ( + self.db.iterator_cf_opt(handle, opt, IteratorMode::Start), + StreamingStep::Started, + ), + StreamingStep::Ongoing(last_key) => { + let mut iter = self.db.iterator_cf_opt( + handle, + opt, + IteratorMode::From(&last_key, Direction::Forward), + ); + iter.next(); + (iter, StreamingStep::Finished(None)) + } + StreamingStep::Finished(_) => return Ok((ledger_part, cursor)), + }; + + // Iterates over the whole database + for (key, entry) in db_iterator.flatten() { + if (ledger_part.len() as u64) < (self.ledger_part_size_message_bytes) { + key_serializer.serialize(&key.to_vec(), &mut ledger_part)?; + ser.serialize(&entry.to_vec(), &mut ledger_part)?; + new_cursor = StreamingStep::Ongoing(key.to_vec()); + } else { + break; + } + } + Ok((ledger_part, new_cursor)) + } + + /// Set a part of the ledger in the database. + /// We deserialize in this function because we insert in the ledger while deserializing. + /// Used for bootstrap. + /// + /// # Arguments + /// * data: must be the serialized version provided by `get_ledger_part` + /// + /// # Returns + /// The last key of the inserted entry (this is an optimization to easily keep a reference to the last key) + pub fn set_ledger_part<'a>( + &self, + data: &'a [u8], + ) -> Result>, ModelsError> { + let handle = self.db.cf_handle(LEDGER_CF).expect(CF_ERROR); + let vec_u8_deserializer = + VecU8Deserializer::new(Bound::Included(0), Bound::Excluded(u64::MAX)); + let key_deserializer = KeyDeserializer::new(self.max_datastore_key_length); + let mut last_key = Rc::new(Vec::new()); + let mut batch = LedgerBatch::new(self.get_ledger_hash()); + + // Since this data is coming from the network, deser to address and ser back to bytes for a security check. + let (rest, _) = many0(|input: &'a [u8]| { + let (rest, (key, value)) = tuple(( + |input| key_deserializer.deserialize(input), + |input| vec_u8_deserializer.deserialize(input), + ))(input)?; + *Rc::get_mut(&mut last_key).ok_or_else(|| { + nom::Err::Error(nom::error::Error::new(input, nom::error::ErrorKind::Fail)) + })? = key.clone(); + self.put_entry_value(handle, &mut batch, &key, &value); + Ok((rest, ())) + })(data) + .map_err(|_| ModelsError::SerializeError("Error in deserialization".to_string()))?; + + // Every byte should have been read + if last_key.is_empty() { + Ok(StreamingStep::Finished(None)) + } else if rest.is_empty() { + self.write_batch(batch); + Ok(StreamingStep::Ongoing((*last_key).clone())) + } else { + Err(ModelsError::SerializeError( + "rest is not empty.".to_string(), + )) + } + } +} + +// Private helpers +impl LedgerDB { /// Apply the given operation batch to the disk ledger fn write_batch(&self, mut batch: LedgerBatch) { let handle = self.db.cf_handle(METADATA_CF).expect(CF_ERROR); @@ -235,26 +380,12 @@ impl LedgerDB { .write_batch .put_cf(handle, SLOT_KEY, slot_bytes.clone()); // XOR previous slot and new one - if let Some(prev_bytes) = self.db.get_cf(handle, SLOT_KEY).expect(CRUD_ERROR) { + if let Some(prev_bytes) = self.db.get_pinned_cf(handle, SLOT_KEY).expect(CRUD_ERROR) { batch.ledger_hash ^= Hash::compute_from(&prev_bytes); } batch.ledger_hash ^= Hash::compute_from(&slot_bytes); } - /// Get the current disk ledger hash - pub fn get_ledger_hash(&self) -> Hash { - let handle = self.db.cf_handle(METADATA_CF).expect(CF_ERROR); - if let Some(ledger_hash_bytes) = self.db.get_cf(handle, LEDGER_HASH_KEY).expect(CRUD_ERROR) - { - Hash::from_bytes(&ledger_hash_bytes.try_into().expect(LEDGER_HASH_ERROR)) - } else { - // initial ledger_hash value to avoid matching an option in every XOR operation - // because of a one time case being an empty ledger - // also note that the if you XOR a hash with itself result is LEDGER_HASH_INITIAL_BYTES - Hash::from_bytes(LEDGER_HASH_INITIAL_BYTES) - } - } - /// Internal function to put a key & value and perform the ledger hash XORs fn put_entry_value( &self, @@ -299,54 +430,6 @@ impl LedgerDB { } } - /// Get the given sub-entry of a given address. - /// - /// # Arguments - /// * `addr`: associated address - /// * `ty`: type of the queried sub-entry - /// - /// # Returns - /// An Option of the sub-entry value as bytes - pub fn get_sub_entry(&self, addr: &Address, ty: LedgerSubEntry) -> Option> { - let handle = self.db.cf_handle(LEDGER_CF).expect(CF_ERROR); - - match ty { - LedgerSubEntry::Balance => self - .db - .get_cf(handle, balance_key!(addr)) - .expect(CRUD_ERROR), - LedgerSubEntry::Bytecode => self - .db - .get_cf(handle, bytecode_key!(addr)) - .expect(CRUD_ERROR), - LedgerSubEntry::Datastore(hash) => self - .db - .get_cf(handle, data_key!(addr, hash)) - .expect(CRUD_ERROR), - } - } - - /// Get every key of the datastore for a given address. - /// - /// # Returns - /// A `BTreeSet` of the datastore keys - pub fn get_datastore_keys(&self, addr: &Address) -> BTreeSet> { - let handle = self.db.cf_handle(LEDGER_CF).expect(CF_ERROR); - - let mut opt = ReadOptions::default(); - opt.set_iterate_upper_bound(end_prefix(data_prefix!(addr)).unwrap()); - - self.db - .iterator_cf_opt( - handle, - opt, - IteratorMode::From(data_prefix!(addr), Direction::Forward), - ) - .flatten() - .map(|(key, _)| key.split_at(ADDRESS_SIZE_BYTES + 1).1.to_vec()) - .collect() - } - /// Internal function to update a key & value and perform the ledger hash XORs fn update_key_value( &self, @@ -361,7 +444,7 @@ impl LedgerDB { .expect(KEY_LEN_SER_ERROR); if let Some(added_hash) = batch.aeh_list.get(key) { batch.ledger_hash ^= *added_hash; - } else if let Some(prev_bytes) = self.db.get_cf(handle, key).expect(CRUD_ERROR) { + } else if let Some(prev_bytes) = self.db.get_pinned_cf(handle, key).expect(CRUD_ERROR) { batch.ledger_hash ^= Hash::compute_from(&[&len_bytes, key, &prev_bytes].concat()); } let hash = Hash::compute_from(&[&len_bytes, key, value].concat()); @@ -413,7 +496,7 @@ impl LedgerDB { fn delete_key(&self, handle: &ColumnFamily, batch: &mut LedgerBatch, key: &[u8]) { if let Some(added_hash) = batch.aeh_list.get(key) { batch.ledger_hash ^= *added_hash; - } else if let Some(prev_bytes) = self.db.get_cf(handle, key).expect(CRUD_ERROR) { + } else if let Some(prev_bytes) = self.db.get_pinned_cf(handle, key).expect(CRUD_ERROR) { let mut len_bytes = Vec::new(); self.len_serializer .serialize(&(key.len() as u64), &mut len_bytes) @@ -451,112 +534,16 @@ impl LedgerDB { self.delete_key(handle, batch, &key); } } - - /// Get a part of the disk Ledger. - /// Mainly used in the bootstrap process. - /// - /// # Arguments - /// * `last_key`: key where the part retrieving must start - /// - /// # Returns - /// A tuple containing: - /// * The ledger part as bytes - /// * The last taken key (this is an optimization to easily keep a reference to the last key) - pub fn get_ledger_part( - &self, - cursor: StreamingStep>, - ) -> Result<(Vec, StreamingStep>), ModelsError> { - let handle = self.db.cf_handle(LEDGER_CF).expect(CF_ERROR); - let opt = ReadOptions::default(); - let ser = VecU8Serializer::new(); - let key_serializer = KeySerializer::new(); - let mut ledger_part = Vec::new(); - - // Creates an iterator from the next element after the last if defined, otherwise initialize it at the first key of the ledger. - let (db_iterator, mut new_cursor) = match cursor { - StreamingStep::Started => ( - self.db.iterator_cf_opt(handle, opt, IteratorMode::Start), - StreamingStep::Started, - ), - StreamingStep::Ongoing(last_key) => { - let mut iter = self.db.iterator_cf_opt( - handle, - opt, - IteratorMode::From(&last_key, Direction::Forward), - ); - iter.next(); - (iter, StreamingStep::Finished(None)) - } - StreamingStep::Finished(_) => return Ok((ledger_part, cursor)), - }; - - // Iterates over the whole database - for (key, entry) in db_iterator.flatten() { - if (ledger_part.len() as u64) < (self.ledger_part_size_message_bytes) { - key_serializer.serialize(&key.to_vec(), &mut ledger_part)?; - ser.serialize(&entry.to_vec(), &mut ledger_part)?; - new_cursor = StreamingStep::Ongoing(key.to_vec()); - } else { - break; - } - } - Ok((ledger_part, new_cursor)) - } - - /// Set a part of the ledger in the database. - /// We deserialize in this function because we insert in the ledger while deserializing. - /// Used for bootstrap. - /// - /// # Arguments - /// * data: must be the serialized version provided by `get_ledger_part` - /// - /// # Returns - /// The last key of the inserted entry (this is an optimization to easily keep a reference to the last key) - pub fn set_ledger_part<'a>( - &self, - data: &'a [u8], - ) -> Result>, ModelsError> { - let handle = self.db.cf_handle(LEDGER_CF).expect(CF_ERROR); - let vec_u8_deserializer = - VecU8Deserializer::new(Bound::Included(0), Bound::Excluded(u64::MAX)); - let key_deserializer = KeyDeserializer::new(self.max_datastore_key_length); - let mut last_key = Rc::new(Vec::new()); - let mut batch = LedgerBatch::new(self.get_ledger_hash()); - - // Since this data is coming from the network, deser to address and ser back to bytes for a security check. - let (rest, _) = many0(|input: &'a [u8]| { - let (rest, (key, value)) = tuple(( - |input| key_deserializer.deserialize(input), - |input| vec_u8_deserializer.deserialize(input), - ))(input)?; - *Rc::get_mut(&mut last_key).ok_or_else(|| { - nom::Err::Error(nom::error::Error::new(input, nom::error::ErrorKind::Fail)) - })? = key.clone(); - self.put_entry_value(handle, &mut batch, &key, &value); - Ok((rest, ())) - })(data) - .map_err(|_| ModelsError::SerializeError("Error in deserialization".to_string()))?; - - // Every byte should have been read - if last_key.is_empty() { - Ok(StreamingStep::Finished(None)) - } else if rest.is_empty() { - self.write_batch(batch); - Ok(StreamingStep::Ongoing((*last_key).clone())) - } else { - Err(ModelsError::SerializeError( - "rest is not empty.".to_string(), - )) - } - } - +} +// test helpers +impl LedgerDB { /// Get every address and their corresponding balance. /// /// IMPORTANT: This should only be used for debug purposes. /// /// # Returns /// A `BTreeMap` with the address as key and the balance as value - #[cfg(feature = "testing")] + #[cfg(any(feature = "testing"))] pub fn get_every_address( &self, ) -> std::collections::BTreeMap { @@ -620,10 +607,26 @@ impl LedgerDB { } } +/// For a given start prefix (inclusive), returns the correct end prefix (non-inclusive). +/// This assumes the key bytes are ordered in lexicographical order. +/// Since key length is not limited, for some case we return `None` because there is +/// no bounded limit (every keys in the series `[]`, `[255]`, `[255, 255]` ...). +fn end_prefix(prefix: &[u8]) -> Option> { + let mut end_range = prefix.to_vec(); + while let Some(0xff) = end_range.last() { + end_range.pop(); + } + if let Some(byte) = end_range.last_mut() { + *byte += 1; + Some(end_range) + } else { + None + } +} + #[cfg(test)] mod tests { - use super::LedgerDB; - use crate::ledger_db::{LedgerBatch, LedgerSubEntry, LEDGER_HASH_INITIAL_BYTES}; + use super::*; use massa_hash::Hash; use massa_ledger_exports::{LedgerEntry, LedgerEntryUpdate, SetOrKeep}; use massa_models::{ @@ -716,4 +719,10 @@ mod tests { let res = db.get_ledger_part(StreamingStep::Started).unwrap(); db.set_ledger_part(&res.0[..]).unwrap(); } + + #[test] + fn test_end_prefix() { + assert_eq!(end_prefix(&[5, 6, 7]), Some(vec![5, 6, 8])); + assert_eq!(end_prefix(&[5, 6, 255]), Some(vec![5, 7])); + } } From b6e004b19e7baaa355dde6ca376d7f8368a24ca2 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Wed, 1 Feb 2023 15:41:26 +0100 Subject: [PATCH 74/80] Fix format issue. --- massa-api/src/public.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/massa-api/src/public.rs b/massa-api/src/public.rs index 4bbc6cd8660..fb50bf0c11d 100644 --- a/massa-api/src/public.rs +++ b/massa-api/src/public.rs @@ -544,7 +544,9 @@ impl MassaRpcServer for API { id, in_pool, is_final, - thread: operation.content_creator_address.get_thread(api_cfg.thread_count), + thread: operation + .content_creator_address + .get_thread(api_cfg.thread_count), operation, in_blocks: in_blocks.into_iter().collect(), }); From 4889d07c2959e922f7c038ade987af69df39a480 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Wed, 1 Feb 2023 16:41:17 +0100 Subject: [PATCH 75/80] Update addresses. --- massa-node/base_config/initial_ledger.json | 18 +++++++++--------- massa-node/base_config/initial_rolls.json | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/massa-node/base_config/initial_ledger.json b/massa-node/base_config/initial_ledger.json index 3d93a1a5fda..a652cf1b597 100644 --- a/massa-node/base_config/initial_ledger.json +++ b/massa-node/base_config/initial_ledger.json @@ -1,45 +1,45 @@ { - "A1qDAxGJ387ETi9JRQzZWSPKYq4YPXrFvdiE4VoXUaiAt38JFEC": { + "A12dhs6CsQk8AXFTYyUpc1P9e8GDf65ozU6RcigW68qfJV7vdbNf": { "balance": "1000000000", "datastore": {}, "bytecode": [] }, - "A12M3AQqs7JH7mSe1UZyEA5NQ7nGQHXaqqxe1TGEpkimcRhsQ4eF": { + "A12WQRoxQJKMjNG8hVjkyh4YgBwaYeUH4BsqJEEdTUJda37GhSx9": { "balance": "1000000000", "datastore": {}, "bytecode": [] }, - "A1nsqw9mCcYLyyMJx5f4in4NXDoe4B1LzV9pQdvX5Wrxq9ehf6h": { + "A1226KGgzq425xzpNmrUCggKcru4yMkFSUXGxYnTwCt6vso5PVbn": { "balance": "1000000000", "datastore": {}, "bytecode": [] }, - "A1pdnk7gME8DSA6ueNZdCHqfSt9YfTwAJSgRCcB8g3z3kkapWtU": { + "A12p3neq9Caq8idS33jrWuRZgfoBL3wAAfG2NdZEBxNdfujVtCLq": { "balance": "1000000000", "datastore": {}, "bytecode": [] }, - "A1H1Ze77ctAFi4FBc3nVe9AtWdtg7246V9pVXSeXqWaJFLPKfB1": { + "A122tXU6uhDfGP1BxCtvLQTvyascwsjX5NVo3vv1fssmdeKSeytM": { "balance": "1000000000", "datastore": {}, "bytecode": [] }, - "A12Dvay7jT1maaKpV9CHX6yMt3cS5ZEWy6Q67HV8twVGS3ihoq5x": { + "A1xfaL8CTrZWTBY79JDMEokwYjc2U4gUFJqqgtbahj7gwYn2s6Y": { "balance": "1000000000", "datastore": {}, "bytecode": [] }, - "A13evhD7c9AXFc6CxWWjWWRT6bQnejYhq3MsNofJWJDe4UQStJE": { + "A1xgxVCw4Vnr2s8JSnFYzz8UGuqZdMH7wHBDUapndgRCdDteWS": { "balance": "1000000000", "datastore": {}, "bytecode": [] }, - "A1UpZLobUAWqj3M9DpBZNhh4GD4ZLvixKXQu2kt7ZDUiEepD89E": { + "A12DPHgthL9JJGrASquAmsdef9oYpLCXzZRvyiXzY3TG87Hgcs4o": { "balance": "1000000000", "datastore": {}, "bytecode": [] }, - "A12p8v9V68SiehQb2Syzy6smfv9NTCJh2p6JPbsacy7PaGRw39uH": { + "A124Lusm3gJFwkCkY13FKXae2z2cV4pvhepJfxPHM2LJz8fEjU3C": { "balance": "1000000000", "datastore": {}, "bytecode": [] diff --git a/massa-node/base_config/initial_rolls.json b/massa-node/base_config/initial_rolls.json index 19b631e303e..be2fe62f7d8 100644 --- a/massa-node/base_config/initial_rolls.json +++ b/massa-node/base_config/initial_rolls.json @@ -1,11 +1,11 @@ { - "A1qDAxGJ387ETi9JRQzZWSPKYq4YPXrFvdiE4VoXUaiAt38JFEC": 10, - "A12M3AQqs7JH7mSe1UZyEA5NQ7nGQHXaqqxe1TGEpkimcRhsQ4eF": 10, - "A1nsqw9mCcYLyyMJx5f4in4NXDoe4B1LzV9pQdvX5Wrxq9ehf6h": 10, - "A1pdnk7gME8DSA6ueNZdCHqfSt9YfTwAJSgRCcB8g3z3kkapWtU": 10, - "A1H1Ze77ctAFi4FBc3nVe9AtWdtg7246V9pVXSeXqWaJFLPKfB1": 10, - "A12Dvay7jT1maaKpV9CHX6yMt3cS5ZEWy6Q67HV8twVGS3ihoq5x": 10, - "A13evhD7c9AXFc6CxWWjWWRT6bQnejYhq3MsNofJWJDe4UQStJE": 10, - "A1UpZLobUAWqj3M9DpBZNhh4GD4ZLvixKXQu2kt7ZDUiEepD89E": 10, - "A12p8v9V68SiehQb2Syzy6smfv9NTCJh2p6JPbsacy7PaGRw39uH": 10 + "A12dhs6CsQk8AXFTYyUpc1P9e8GDf65ozU6RcigW68qfJV7vdbNf": 10, + "A12WQRoxQJKMjNG8hVjkyh4YgBwaYeUH4BsqJEEdTUJda37GhSx9": 10, + "A1226KGgzq425xzpNmrUCggKcru4yMkFSUXGxYnTwCt6vso5PVbn": 10, + "A12p3neq9Caq8idS33jrWuRZgfoBL3wAAfG2NdZEBxNdfujVtCLq": 10, + "A122tXU6uhDfGP1BxCtvLQTvyascwsjX5NVo3vv1fssmdeKSeytM": 10, + "A1xfaL8CTrZWTBY79JDMEokwYjc2U4gUFJqqgtbahj7gwYn2s6Y": 10, + "A1xgxVCw4Vnr2s8JSnFYzz8UGuqZdMH7wHBDUapndgRCdDteWS": 10, + "A12DPHgthL9JJGrASquAmsdef9oYpLCXzZRvyiXzY3TG87Hgcs4o": 10, + "A124Lusm3gJFwkCkY13FKXae2z2cV4pvhepJfxPHM2LJz8fEjU3C": 10 } From 7aa1d4c8c53abbfe3a4a7418cb3740ce35564d2e Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Wed, 1 Feb 2023 16:47:45 +0100 Subject: [PATCH 76/80] Update genesis and end timestamp --- .github/workflows/ci.yml | 10 +++++----- massa-models/src/config/constants.rs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7643818392a..b59441fb114 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "sanity" - save-if: ${{ github.ref_name == 'testnet_19' }} + save-if: ${{ github.ref == 'refs/heads/main' }} - uses: actions-rs/cargo@v1 with: command: fmt @@ -55,7 +55,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "check" - save-if: ${{ github.ref_name == 'testnet_19' }} + save-if: ${{ github.ref == 'refs/heads/main' }} - uses: actions-rs/cargo@v1 with: command: check @@ -78,7 +78,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "clippy" - save-if: ${{ github.ref_name == 'testnet_19' }} + save-if: ${{ github.ref == 'refs/heads/main' }} - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} @@ -108,7 +108,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "massa" - save-if: ${{ github.ref_name == 'testnet_19' }} + save-if: ${{ github.ref == 'refs/heads/main' }} - uses: actions-rs/cargo@v1 with: command: install @@ -176,7 +176,7 @@ jobs: - uses: Swatinem/rust-cache@v2 with: shared-key: "doc" - save-if: ${{ github.ref_name == 'testnet_19' }} + save-if: ${{ github.ref == 'refs/heads/main' }} - uses: actions-rs/cargo@v1 with: command: doc diff --git a/massa-models/src/config/constants.rs b/massa-models/src/config/constants.rs index a09935817ca..f24c1eed1c6 100644 --- a/massa-models/src/config/constants.rs +++ b/massa-models/src/config/constants.rs @@ -45,14 +45,14 @@ lazy_static::lazy_static! { .saturating_add(MassaTime::from_millis(1000 * 10)) ) } else { - 1672790401000.into() // Wednesday, January 04, 2022 00:00:01 AM UTC + 1675296001000.into() // Thursday, February 02, 2022 00:00:01 AM UTC }; /// TESTNET: time when the blockclique is ended. pub static ref END_TIMESTAMP: Option = if cfg!(feature = "sandbox") { None } else { - Some(1675105200000.into()) // Monday, January 30, 2022 19:00:00 PM UTC + Some(1677596400000.into()) // Tuesday, February 28, 2022 15:00:00 PM UTC }; /// `KeyPair` to sign genesis blocks. pub static ref GENESIS_KEY: KeyPair = KeyPair::from_str("S1UxdCJv5ckDK8z87E5Jq5fEfSVLi2cTHgtpfZy7iURs3KpPns8") From 9c10fa5fe7e9247a799352dddb5ad6c2ec976ecc Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Wed, 1 Feb 2023 17:06:10 +0100 Subject: [PATCH 77/80] Update sc-runtime --- Cargo.lock | 66 ++++++++++++++++++++++++++++--- massa-execution-worker/Cargo.toml | 2 +- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ff98c8842d3..70fbe42b32a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -150,6 +150,15 @@ dependencies = [ "wasmer", ] +[[package]] +name = "as-ffi-bindings" +version = "0.2.5" +source = "git+https://github.com/massalabs/as-ffi-bindings.git?tag=v0.3.3#81a1cba61a20a6e5065341b00d7f751c7974e65b" +dependencies = [ + "anyhow", + "wasmer", +] + [[package]] name = "async-compression" version = "0.3.15" @@ -498,9 +507,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" dependencies = [ "iana-time-zone", + "js-sys", "num-integer", "num-traits", "serde", + "time 0.1.45", + "wasm-bindgen", "winapi", ] @@ -2282,8 +2294,35 @@ version = "0.10.0" source = "git+https://github.com/massalabs/massa-sc-runtime?branch=testnet_19#6602be544a08513c52837b052116f4264b689302" dependencies = [ "anyhow", - "as-ffi-bindings", + "as-ffi-bindings 0.2.5 (git+https://github.com/massalabs/as-ffi-bindings.git?tag=v0.3.2)", + "base64 0.13.1", + "displaydoc", + "function_name", + "loupe", + "more-asserts 0.3.1", + "parking_lot", + "rand 0.8.5", + "regex", + "serde", + "serde_json", + "serial_test 0.8.0", + "thiserror", + "tracing", + "wasmer", + "wasmer-compiler-singlepass", + "wasmer-middlewares", + "wasmer-types", +] + +[[package]] +name = "massa-sc-runtime" +version = "0.10.0" +source = "git+https://github.com/massalabs/massa-sc-runtime#3c4815dd78e3e78c387045df0117eac24d016db3" +dependencies = [ + "anyhow", + "as-ffi-bindings 0.2.5 (git+https://github.com/massalabs/as-ffi-bindings.git?tag=v0.3.3)", "base64 0.13.1", + "chrono", "displaydoc", "function_name", "loupe", @@ -2494,7 +2533,7 @@ name = "massa_execution_exports" version = "0.1.0" dependencies = [ "displaydoc", - "massa-sc-runtime", + "massa-sc-runtime 0.10.0 (git+https://github.com/massalabs/massa-sc-runtime?branch=testnet_19)", "massa_final_state", "massa_hash", "massa_ledger_exports", @@ -2512,7 +2551,7 @@ version = "0.1.0" dependencies = [ "anyhow", "criterion", - "massa-sc-runtime", + "massa-sc-runtime 0.10.0 (git+https://github.com/massalabs/massa-sc-runtime)", "massa_async_pool", "massa_executed_ops", "massa_execution_exports", @@ -2908,7 +2947,7 @@ dependencies = [ "nom", "serde", "thiserror", - "time", + "time 0.3.17", ] [[package]] @@ -4143,7 +4182,7 @@ dependencies = [ "serde", "serde_json", "serde_with_macros", - "time", + "time 0.3.17", ] [[package]] @@ -4550,6 +4589,17 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + [[package]] name = "time" version = "0.3.17" @@ -4963,6 +5013,12 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/massa-execution-worker/Cargo.toml b/massa-execution-worker/Cargo.toml index 4cdd92c9878..2f0c7c281af 100644 --- a/massa-execution-worker/Cargo.toml +++ b/massa-execution-worker/Cargo.toml @@ -25,7 +25,7 @@ massa_execution_exports = { path = "../massa-execution-exports" } massa_models = { path = "../massa-models" } massa_storage = { path = "../massa-storage" } massa_hash = { path = "../massa-hash" } -massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", branch = "testnet_19" } +massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime" } massa_signature = { path = "../massa-signature" } massa_time = { path = "../massa-time" } massa_ledger_worker = { path = "../massa-ledger-worker", optional = true } From b70f2eccd685067db294bf1b3cc14eb85510bbdf Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Wed, 1 Feb 2023 17:09:34 +0100 Subject: [PATCH 78/80] Update sc-runtime in massa-exeuction-exports. --- Cargo.lock | 41 +++--------------------------- massa-execution-exports/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 70fbe42b32a..7744f7ac220 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -141,15 +141,6 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" -[[package]] -name = "as-ffi-bindings" -version = "0.2.5" -source = "git+https://github.com/massalabs/as-ffi-bindings.git?tag=v0.3.2#156c2a86fa03d14c72c1baec3fb25c6c517ca546" -dependencies = [ - "anyhow", - "wasmer", -] - [[package]] name = "as-ffi-bindings" version = "0.2.5" @@ -2288,39 +2279,13 @@ dependencies = [ "tracing-subscriber", ] -[[package]] -name = "massa-sc-runtime" -version = "0.10.0" -source = "git+https://github.com/massalabs/massa-sc-runtime?branch=testnet_19#6602be544a08513c52837b052116f4264b689302" -dependencies = [ - "anyhow", - "as-ffi-bindings 0.2.5 (git+https://github.com/massalabs/as-ffi-bindings.git?tag=v0.3.2)", - "base64 0.13.1", - "displaydoc", - "function_name", - "loupe", - "more-asserts 0.3.1", - "parking_lot", - "rand 0.8.5", - "regex", - "serde", - "serde_json", - "serial_test 0.8.0", - "thiserror", - "tracing", - "wasmer", - "wasmer-compiler-singlepass", - "wasmer-middlewares", - "wasmer-types", -] - [[package]] name = "massa-sc-runtime" version = "0.10.0" source = "git+https://github.com/massalabs/massa-sc-runtime#3c4815dd78e3e78c387045df0117eac24d016db3" dependencies = [ "anyhow", - "as-ffi-bindings 0.2.5 (git+https://github.com/massalabs/as-ffi-bindings.git?tag=v0.3.3)", + "as-ffi-bindings", "base64 0.13.1", "chrono", "displaydoc", @@ -2533,7 +2498,7 @@ name = "massa_execution_exports" version = "0.1.0" dependencies = [ "displaydoc", - "massa-sc-runtime 0.10.0 (git+https://github.com/massalabs/massa-sc-runtime?branch=testnet_19)", + "massa-sc-runtime", "massa_final_state", "massa_hash", "massa_ledger_exports", @@ -2551,7 +2516,7 @@ version = "0.1.0" dependencies = [ "anyhow", "criterion", - "massa-sc-runtime 0.10.0 (git+https://github.com/massalabs/massa-sc-runtime)", + "massa-sc-runtime", "massa_async_pool", "massa_executed_ops", "massa_execution_exports", diff --git a/massa-execution-exports/Cargo.toml b/massa-execution-exports/Cargo.toml index cef2ca90c2d..7086b5e7988 100644 --- a/massa-execution-exports/Cargo.toml +++ b/massa-execution-exports/Cargo.toml @@ -18,7 +18,7 @@ massa_storage = { path = "../massa-storage" } massa_final_state = { path = "../massa-final-state" } massa_ledger_exports = { path = "../massa-ledger-exports", optional = true } parking_lot = { version = "0.12", features = ["deadlock_detection"], optional = true } -massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", branch = "testnet_19" } +massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime" } # for more information on what are the following features used for, see the cargo.toml at workspace level [features] From f88519d0bd3115606ec9ed276a7ce2041f87cf4e Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Wed, 1 Feb 2023 17:23:38 +0100 Subject: [PATCH 79/80] Update toolchain --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index e1431a3b8ba..eb673314741 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2022-12-24" \ No newline at end of file +channel = "nightly-2023-01-30" \ No newline at end of file From f7dec64b81571e2bf9a0f926e8ad0f8cd464d610 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Wed, 1 Feb 2023 17:50:51 +0100 Subject: [PATCH 80/80] Fix gas costs and failed check. --- Cargo.lock | 2 +- massa-client/src/main.rs | 1 - massa-execution-exports/Cargo.toml | 2 +- massa-execution-worker/Cargo.toml | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7744f7ac220..b9886772bba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2282,7 +2282,7 @@ dependencies = [ [[package]] name = "massa-sc-runtime" version = "0.10.0" -source = "git+https://github.com/massalabs/massa-sc-runtime#3c4815dd78e3e78c387045df0117eac24d016db3" +source = "git+https://github.com/massalabs/massa-sc-runtime?branch=main#3c4815dd78e3e78c387045df0117eac24d016db3" dependencies = [ "anyhow", "as-ffi-bindings", diff --git a/massa-client/src/main.rs b/massa-client/src/main.rs index 392ba57af00..2ccf3ba48cd 100644 --- a/massa-client/src/main.rs +++ b/massa-client/src/main.rs @@ -1,6 +1,5 @@ // Copyright (c) 2022 MASSA LABS //! Massa stateless CLI -#![feature(str_split_whitespace_as_str)] #![warn(missing_docs)] #![warn(unused_crate_dependencies)] use crate::settings::SETTINGS; diff --git a/massa-execution-exports/Cargo.toml b/massa-execution-exports/Cargo.toml index 7086b5e7988..2b18e80a532 100644 --- a/massa-execution-exports/Cargo.toml +++ b/massa-execution-exports/Cargo.toml @@ -18,7 +18,7 @@ massa_storage = { path = "../massa-storage" } massa_final_state = { path = "../massa-final-state" } massa_ledger_exports = { path = "../massa-ledger-exports", optional = true } parking_lot = { version = "0.12", features = ["deadlock_detection"], optional = true } -massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime" } +massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", branch = "main" } # for more information on what are the following features used for, see the cargo.toml at workspace level [features] diff --git a/massa-execution-worker/Cargo.toml b/massa-execution-worker/Cargo.toml index 2f0c7c281af..9ae34093684 100644 --- a/massa-execution-worker/Cargo.toml +++ b/massa-execution-worker/Cargo.toml @@ -25,7 +25,7 @@ massa_execution_exports = { path = "../massa-execution-exports" } massa_models = { path = "../massa-models" } massa_storage = { path = "../massa-storage" } massa_hash = { path = "../massa-hash" } -massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime" } +massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", branch = "main" } massa_signature = { path = "../massa-signature" } massa_time = { path = "../massa-time" } massa_ledger_worker = { path = "../massa-ledger-worker", optional = true }