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 30983a85d6..a43f995436 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,12 +498,6 @@ fn execute( receipt.gas_spent = receipt.gas_limit; } - let contract_id = tx - .payload() - .contract_call - .clone() - .map(|call| ContractId::from_bytes(call.contract)); - // 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. @@ -513,12 +505,7 @@ fn execute( .call::<_, ()>( TRANSFER_CONTRACT, "refund", - &( - tx.payload().fee, - receipt.gas_spent, - receipt.economic_mode.clone(), - contract_id, - ), + &(tx.payload().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 5399817cf8..0000000000 --- a/rusk/tests/services/contract_pays.rs +++ /dev/null @@ -1,178 +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::{transfer::ContractCall, 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_contract_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 { - 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 contract_call = ContractCall { - contract: CHARLIE_CONTRACT_ID.to_bytes(), - fn_name: String::from(method.as_ref()), - fn_args: Vec::new(), - }; - let tx = wallet - .execute(&mut rng, contract_call, SENDER_INDEX, GAS_LIMIT, 1, 0) - .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 b673a16859..c8413d4516 100644 --- a/rusk/tests/services/gas_behavior.rs +++ b/rusk/tests/services/gas_behavior.rs @@ -25,8 +25,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/unspendable.rs b/rusk/tests/services/unspendable.rs index 7f79d163fe..3899d1b928 100644 --- a/rusk/tests/services/unspendable.rs +++ b/rusk/tests/services/unspendable.rs @@ -27,7 +27,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 {