diff --git a/rusk/CHANGELOG.md b/rusk/CHANGELOG.md index e4a670ca4b..df6767afd7 100644 --- a/rusk/CHANGELOG.md +++ b/rusk/CHANGELOG.md @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed +- Remove economic protocol handling - Remove allowlist [#1257] - Remove STCO and WFCO [#1675] diff --git a/rusk/src/lib/chain/rusk.rs b/rusk/src/lib/chain/rusk.rs index 1b3f4eaafd..69523823dd 100644 --- a/rusk/src/lib/chain/rusk.rs +++ b/rusk/src/lib/chain/rusk.rs @@ -23,8 +23,8 @@ use execution_core::{ use node_data::ledger::{SpentTransaction, Transaction}; use rusk_abi::dusk::Dusk; use rusk_abi::{ - CallReceipt, ContractError, ContractId, Error as PiecrustError, Event, - Session, STAKE_CONTRACT, TRANSFER_CONTRACT, VM, + CallReceipt, ContractError, Error as PiecrustError, Event, Session, + STAKE_CONTRACT, TRANSFER_CONTRACT, VM, }; use rusk_profile::to_rusk_state_id_path; use tokio::sync::broadcast; @@ -150,7 +150,6 @@ impl Rusk { spent_txs.push(SpentTransaction { inner: unspent_tx, gas_spent, - economic_mode: receipt.economic_mode, block_height, err, }); @@ -439,7 +438,6 @@ fn accept( spent_txs.push(SpentTransaction { inner: unspent_tx.clone(), gas_spent, - economic_mode: receipt.economic_mode, block_height, // We're currently ignoring the result of successful calls err: receipt.data.err().map(|e| format!("{e}")), @@ -500,11 +498,6 @@ fn execute( receipt.gas_spent = receipt.gas_limit; } - let contract_id = tx - .call - .clone() - .map(|(module_id, _, _)| ContractId::from_bytes(module_id)); - // Refund the appropriate amount to the transaction. This call is guaranteed // to never error. If it does, then a programming error has occurred. As // such, the call to `Result::expect` is warranted. @@ -512,12 +505,7 @@ fn execute( .call::<_, ()>( TRANSFER_CONTRACT, "refund", - &( - tx.fee, - receipt.gas_spent, - receipt.economic_mode.clone(), - contract_id, - ), + &(tx.fee, receipt.gas_spent), u64::MAX, ) .expect("Refunding must succeed"); diff --git a/rusk/tests/services/contract_pays.rs b/rusk/tests/services/contract_pays.rs deleted file mode 100644 index 4c70a09c51..0000000000 --- a/rusk/tests/services/contract_pays.rs +++ /dev/null @@ -1,187 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// Copyright (c) DUSK NETWORK. All rights reserved. - -use dusk_bytes::Serializable; -use std::collections::HashMap; -use std::path::Path; -use std::sync::{Arc, RwLock}; - -use rand::prelude::*; -use rand::rngs::StdRng; -use rusk::{Result, Rusk}; -use rusk_abi::{ContractData, ContractId, EconomicMode, TRANSFER_CONTRACT}; -use rusk_recovery_tools::state; -use tempfile::tempdir; -use test_wallet::{self as wallet}; -use tokio::sync::broadcast; -use tracing::info; - -use execution_core::{BlsPublicKey, BlsSecretKey}; - -use crate::common::logger; -use crate::common::state::{generator_procedure, ExecuteResult}; -use crate::common::wallet::{TestProverClient, TestStateClient, TestStore}; - -const BLOCK_HEIGHT: u64 = 1; -const BLOCK_GAS_LIMIT: u64 = 1_000_000_000_000; -const INITIAL_BALANCE: u64 = 10_000_000_000; -const GAS_LIMIT: u64 = 200_000_000; -const CHARLIES_FUNDS: u64 = 140_000_000; -const POINT_LIMIT: u64 = 0x10000000; -const SENDER_INDEX: u64 = 0; - -const CHARLIE_CONTRACT_ID: ContractId = { - let mut bytes = [0u8; 32]; - bytes[0] = 0xFC; - ContractId::from_bytes(bytes) -}; - -fn initial_state>(dir: P) -> Result { - let snapshot = toml::from_str(include_str!("../config/contract_pays.toml")) - .expect("Cannot deserialize config"); - - let dir = dir.as_ref(); - - let (_vm, _commit_id) = state::deploy(dir, &snapshot, |session| { - let charlie_bytecode = include_bytes!( - "../../../target/dusk/wasm32-unknown-unknown/release/charlie.wasm" - ); - - let mut rng = StdRng::seed_from_u64(0xcafe); - let charlie_owner_ssk = BlsSecretKey::random(&mut rng); - let charlie_owner_psk = BlsPublicKey::from(&charlie_owner_ssk); - - session - .deploy( - charlie_bytecode, - ContractData::builder() - .owner(charlie_owner_psk.to_bytes()) - .contract_id(CHARLIE_CONTRACT_ID), - POINT_LIMIT, - ) - .expect("Deploying the charlie contract should succeed"); - - session - .call::<_, ()>( - TRANSFER_CONTRACT, - "add_module_balance", - &(CHARLIE_CONTRACT_ID, CHARLIES_FUNDS), - u64::MAX, - ) - .expect("stake contract balance to be set with provisioner stakes"); - }) - .expect("Deploying initial state should succeed"); - - let (sender, _) = broadcast::channel(10); - - let rusk = Rusk::new(dir, None, u64::MAX, sender) - .expect("Instantiating rusk should succeed"); - Ok(rusk) -} - -fn make_and_execute_transaction( - rusk: &Rusk, - wallet: &wallet::Wallet, - method: impl AsRef, -) -> EconomicMode { - // We will refund the transaction to ourselves. - let refund = wallet - .public_key(SENDER_INDEX) - .expect("Getting a public spend key should succeed"); - - let initial_balance = wallet - .get_balance(SENDER_INDEX) - .expect("Getting initial balance should succeed") - .value; - - assert_eq!( - initial_balance, INITIAL_BALANCE, - "The sender should have the given initial balance" - ); - - let mut rng = StdRng::seed_from_u64(0xcafe); - - let tx = wallet - .execute( - &mut rng, - CHARLIE_CONTRACT_ID.to_bytes().into(), - String::from(method.as_ref()), - (), - SENDER_INDEX, - &refund, - GAS_LIMIT, - 1, - ) - .expect("Making the transaction should succeed"); - - let expected = ExecuteResult { - discarded: 0, - executed: 1, - }; - - let spent_transactions = generator_procedure( - rusk, - &[tx], - BLOCK_HEIGHT, - BLOCK_GAS_LIMIT, - vec![], - Some(expected), - ) - .expect("generator procedure should succeed"); - - let mut spent_transactions = spent_transactions.into_iter(); - let tx = spent_transactions - .next() - .expect("There should be one spent transactions"); - - assert!(tx.err.is_none(), "Transaction should succeed"); - tx.economic_mode -} - -/// We call method 'pay' of a Charlie contract -/// and make sure the gas spent for us is zero -/// as it is the Charlie contract who has paid for gas. -#[tokio::test(flavor = "multi_thread")] -pub async fn contract_pays() -> Result<()> { - logger(); - - let tmp = tempdir().expect("Should be able to create temporary directory"); - let rusk = initial_state(&tmp)?; - - let cache = Arc::new(RwLock::new(HashMap::new())); - - let wallet = wallet::Wallet::new( - TestStore, - TestStateClient { - rusk: rusk.clone(), - cache, - }, - TestProverClient::default(), - ); - - let original_root = rusk.state_root(); - - info!("Original Root: {:?}", hex::encode(original_root)); - - let economic_mode = make_and_execute_transaction(&rusk, &wallet, "pay"); - assert!( - match economic_mode { - EconomicMode::Allowance(allowance) if allowance > 0 => true, - _ => false, - }, - "Transaction should be free" - ); - - // Check the state's root is changed from the original one - let new_root = rusk.state_root(); - info!( - "New root after the 1st transfer: {:?}", - hex::encode(new_root) - ); - assert_ne!(original_root, new_root, "Root should have changed"); - - Ok(()) -} diff --git a/rusk/tests/services/gas_behavior.rs b/rusk/tests/services/gas_behavior.rs index ab3f2bea02..0744b88486 100644 --- a/rusk/tests/services/gas_behavior.rs +++ b/rusk/tests/services/gas_behavior.rs @@ -24,8 +24,8 @@ const BLOCK_HEIGHT: u64 = 1; const BLOCK_GAS_LIMIT: u64 = 1_000_000_000_000; const INITIAL_BALANCE: u64 = 10_000_000_000; -const GAS_LIMIT_0: u64 = 7_000_000; -const GAS_LIMIT_1: u64 = 200_000_000; +const GAS_LIMIT_0: u64 = 100_000_000; +const GAS_LIMIT_1: u64 = 300_000_000; // Creates the Rusk initial state for the tests below fn initial_state>(dir: P) -> Result { diff --git a/rusk/tests/services/mod.rs b/rusk/tests/services/mod.rs index 2c29ea1a16..f89edd15ed 100644 --- a/rusk/tests/services/mod.rs +++ b/rusk/tests/services/mod.rs @@ -4,7 +4,6 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -pub mod contract_pays; pub mod gas_behavior; pub mod multi_transfer; pub mod stake; diff --git a/rusk/tests/services/multi_transfer.rs b/rusk/tests/services/multi_transfer.rs index 335429ccbf..9d8db9c41f 100644 --- a/rusk/tests/services/multi_transfer.rs +++ b/rusk/tests/services/multi_transfer.rs @@ -24,8 +24,8 @@ use crate::common::wallet::{TestProverClient, TestStateClient, TestStore}; const BLOCK_HEIGHT: u64 = 1; // This is purposefully chosen to be low to trigger the discarding of a // perfectly good transaction. -const BLOCK_GAS_LIMIT: u64 = 24_000_000; -const GAS_LIMIT: u64 = 12_000_000; // Lowest value for a transfer +const BLOCK_GAS_LIMIT: u64 = 42_000_000; +const GAS_LIMIT: u64 = 21_000_000; // Lowest value for a transfer const INITIAL_BALANCE: u64 = 10_000_000_000; // Creates the Rusk initial state for the tests below diff --git a/rusk/tests/services/unspendable.rs b/rusk/tests/services/unspendable.rs index 494ca9ec1e..6f2142749b 100644 --- a/rusk/tests/services/unspendable.rs +++ b/rusk/tests/services/unspendable.rs @@ -26,7 +26,7 @@ const INITIAL_BALANCE: u64 = 10_000_000_000; const GAS_LIMIT_0: u64 = 20_000_000; // Enough to spend, but OOG during ICC const GAS_LIMIT_1: u64 = 1_000; // Not enough to spend -const GAS_LIMIT_2: u64 = 200_000_000; // All ok +const GAS_LIMIT_2: u64 = 300_000_000; // All ok // Creates the Rusk initial state for the tests below fn initial_state>(dir: P) -> Result {