From 6ad65a1715ce3b62fd969456bbc7a360b85a5471 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Mon, 20 Nov 2017 13:30:29 +0800 Subject: [PATCH 1/8] Release v0.8.2 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 975b752a..0f77b0c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sputnikvm" -version = "0.8.1" +version = "0.8.2" license = "Apache-2.0" authors = ["Wei Tang "] description = "SputnikVM - a Portable Blockchain Virtual Machine" @@ -27,7 +27,7 @@ libsecp256k1 = { version = "0.1", optional = true } etcommon-hexutil = "0.2" [features] -default = ["std", "c-secp256k1"] +default = ["std", "rust-secp256k1"] c-secp256k1 = ["secp256k1-plus"] rust-secp256k1 = ["libsecp256k1"] std = ["etcommon-block-core/std", "etcommon-rlp/std", "etcommon-bigint/std", "etcommon-block"] From 643b8dfdb86d0d0c6cbe7e8854172e946c6d7ecc Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 23 Nov 2017 15:29:13 +0800 Subject: [PATCH 2/8] Fix recursive secp256k1 dependency in etcommon-block --- Cargo.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0f77b0c1..c50d7ca8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sputnikvm" -version = "0.8.2" +version = "0.8.3" license = "Apache-2.0" authors = ["Wei Tang "] description = "SputnikVM - a Portable Blockchain Virtual Machine" @@ -19,7 +19,7 @@ etcommon-block-core = { version = "0.1", default-features = false } etcommon-rlp = { version = "0.2", default-features = false } etcommon-bigint = { version = "0.2", default-features = false, features = ["rlp"] } -etcommon-block = { version = "0.3", optional = true } +etcommon-block = { version = "0.3", default-features = false, optional = true } secp256k1-plus = { version = "0.5.7", optional = true } libsecp256k1 = { version = "0.1", optional = true } @@ -27,9 +27,9 @@ libsecp256k1 = { version = "0.1", optional = true } etcommon-hexutil = "0.2" [features] -default = ["std", "rust-secp256k1"] -c-secp256k1 = ["secp256k1-plus"] -rust-secp256k1 = ["libsecp256k1"] +default = ["std", "c-secp256k1"] +c-secp256k1 = ["secp256k1-plus", "etcommon-block/c-secp256k1"] +rust-secp256k1 = ["libsecp256k1", "etcommon-block/rust-secp256k1"] std = ["etcommon-block-core/std", "etcommon-rlp/std", "etcommon-bigint/std", "etcommon-block"] [workspace] From d27e9daaf031f74346d5d1fb09a6f49523981acb Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 23 Nov 2017 16:27:25 +0800 Subject: [PATCH 3/8] Reexport block_core's TransactionAction for convenience --- Cargo.toml | 2 +- src/lib.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c50d7ca8..9ea989a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sputnikvm" -version = "0.8.3" +version = "0.8.4" license = "Apache-2.0" authors = ["Wei Tang "] description = "SputnikVM - a Portable Blockchain Virtual Machine" diff --git a/src/lib.rs b/src/lib.rs index 0320d6f9..0efb0667 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,6 +60,7 @@ pub use self::commit::{AccountCommitment, AccountChange, AccountState, Blockhash pub use self::transaction::{ValidTransaction, TransactionVM}; pub use self::errors::{OnChainError, NotSupportedError, RequireError, CommitError, PreExecutionError}; pub use self::util::opcode::Opcode; +pub use block_core::TransactionAction; #[cfg(not(feature = "std"))] use alloc::Vec; From 03d6493cf3fd868ca6e7dbba9781731ca1dfc34e Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 23 Nov 2017 18:03:37 +0800 Subject: [PATCH 4/8] Implement used_gas in VM interface --- src/lib.rs | 20 ++++++++++++++++++++ src/transaction.rs | 42 ++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0efb0667..d45fa4b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,6 +67,8 @@ use alloc::Vec; #[cfg(feature = "std")] use std::collections::{HashSet as Set, hash_map as map}; #[cfg(not(feature = "std"))] use alloc::{BTreeSet as Set, btree_map as map}; +#[cfg(feature = "std")] use std::cmp::min; +#[cfg(not(feature = "std"))] use core::cmp::min; use bigint::{U256, H256, Gas, Address}; #[derive(Debug, Clone)] @@ -126,6 +128,10 @@ pub trait VM { fn logs(&self) -> &[Log]; /// Returns all removed account addresses as for current VM execution. fn removed(&self) -> &[Address]; + /// Returns the real used gas by the transaction or the VM + /// context. Only available when the status of the VM is + /// exited. Otherwise returns zero. + fn used_gas(&self) -> Gas; } /// A sequencial VM. It uses sequencial memory representation and hash @@ -289,4 +295,18 @@ impl VM for ContextVM { fn removed(&self) -> &[Address] { self.machines[0].state().removed.as_slice() } + + fn used_gas(&self) -> Gas { + match self.machines[0].status() { + MachineStatus::ExitedErr(_) => + self.machines[0].state().context.gas_limit, + MachineStatus::ExitedOk => { + let total_used = self.machines[0].state().memory_gas() + self.machines[0].state().used_gas; + let refund_cap = total_used / Gas::from(2u64); + let refunded = min(refund_cap, self.machines[0].state().refunded_gas); + total_used - refunded + } + _ => Gas::zero(), + } + } } diff --git a/src/transaction.rs b/src/transaction.rs index 6604aa4b..264b4362 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -252,27 +252,6 @@ impl TransactionVM { }) } - /// Returns the real used gas by the transaction. This is what is - /// recorded in the transaction receipt. - pub fn real_used_gas(&self) -> Gas { - match self.0 { - TransactionVMState::Running { ref vm, intrinsic_gas, .. } => { - match vm.machines[0].status() { - MachineStatus::ExitedErr(_) => - vm.machines[0].state().context.gas_limit + intrinsic_gas, - MachineStatus::ExitedOk => { - let total_used = vm.machines[0].state().memory_gas() + vm.machines[0].state().used_gas + intrinsic_gas; - let refund_cap = total_used / Gas::from(2u64); - let refunded = min(refund_cap, vm.machines[0].state().refunded_gas); - total_used - refunded - } - _ => Gas::zero(), - } - } - TransactionVMState::Constructing { .. } => Gas::zero(), - } - } - /// Returns the current state of the VM. pub fn current_state(&self) -> Option<&State> { self.current_machine().map(|m| m.state()) @@ -326,7 +305,7 @@ impl VM for TransactionVM { let ccode_deposit: bool; let cpreclaimed_value: U256; - let real_used_gas = self.real_used_gas(); + let real_used_gas = self.used_gas(); match self.0 { TransactionVMState::Running { @@ -454,6 +433,25 @@ impl VM for TransactionVM { TransactionVMState::Constructing { .. } => &[], } } + + fn used_gas(&self) -> Gas { + match self.0 { + TransactionVMState::Running { ref vm, intrinsic_gas, .. } => { + match vm.machines[0].status() { + MachineStatus::ExitedErr(_) => + vm.machines[0].state().context.gas_limit + intrinsic_gas, + MachineStatus::ExitedOk => { + let total_used = vm.machines[0].state().memory_gas() + vm.machines[0].state().used_gas + intrinsic_gas; + let refund_cap = total_used / Gas::from(2u64); + let refunded = min(refund_cap, vm.machines[0].state().refunded_gas); + total_used - refunded + } + _ => Gas::zero(), + } + } + TransactionVMState::Constructing { .. } => Gas::zero(), + } + } } #[cfg(test)] From 6ce5e162b0d212a191c335e2429c6ef6a7e991ef Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 23 Nov 2017 18:09:17 +0800 Subject: [PATCH 5/8] regtests: real_used_gas -> used_gas --- regtests/src/bin/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regtests/src/bin/main.rs b/regtests/src/bin/main.rs index 3ac65a5e..76b12bd0 100644 --- a/regtests/src/bin/main.rs +++ b/regtests/src/bin/main.rs @@ -163,7 +163,7 @@ fn test_block(client: &mut T, number: usize) { handle_fire(client, &mut vm, last_id); - assert!(Gas::from_str(&receipt.gasUsed).unwrap() == vm.real_used_gas()); + assert!(Gas::from_str(&receipt.gasUsed).unwrap() == vm.used_gas()); assert!(receipt.logs.len() == vm.logs().len()); for i in 0..receipt.logs.len() { assert!(from_rpc_log(&receipt.logs[i]) == vm.logs()[i]); From 8969cb2b3928bd46a177979bd14087d500988f99 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 23 Nov 2017 18:09:43 +0800 Subject: [PATCH 6/8] core, stateful: release v0.9.0 --- Cargo.toml | 2 +- stateful/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9ea989a0..87d3a4f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sputnikvm" -version = "0.8.4" +version = "0.9.0" license = "Apache-2.0" authors = ["Wei Tang "] description = "SputnikVM - a Portable Blockchain Virtual Machine" diff --git a/stateful/Cargo.toml b/stateful/Cargo.toml index 795577dc..ed735799 100644 --- a/stateful/Cargo.toml +++ b/stateful/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sputnikvm-stateful" -version = "0.8.0" +version = "0.9.0" license = "Apache-2.0" description = "Stateful SputnikVM wrapped with tries." authors = ["Wei Tang "] From 5d8196e67432c7a75d32f8199c461c250191da2a Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 23 Nov 2017 19:49:40 +0800 Subject: [PATCH 7/8] stateful: upgrade sputnikvm version --- stateful/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stateful/Cargo.toml b/stateful/Cargo.toml index ed735799..c487c166 100644 --- a/stateful/Cargo.toml +++ b/stateful/Cargo.toml @@ -6,7 +6,7 @@ description = "Stateful SputnikVM wrapped with tries." authors = ["Wei Tang "] [dependencies] -sputnikvm = { version = "0.8", path = '..' } +sputnikvm = { version = "0.9", path = '..' } etcommon-bigint = "0.2" etcommon-trie = "0.3" etcommon-block = "0.3" From 23a581b3e73904d76f16551fbb527add37cc409d Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Thu, 23 Nov 2017 19:49:58 +0800 Subject: [PATCH 8/8] stateful: release v0.9.1 --- stateful/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stateful/Cargo.toml b/stateful/Cargo.toml index c487c166..da26407a 100644 --- a/stateful/Cargo.toml +++ b/stateful/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sputnikvm-stateful" -version = "0.9.0" +version = "0.9.1" license = "Apache-2.0" description = "Stateful SputnikVM wrapped with tries." authors = ["Wei Tang "]