Revert regressions.

Merge branch 'master' of github.com:gavofyork/ethcore
This commit is contained in:
Gav Wood 2015-12-13 16:44:14 +01:00
commit 6852976c9c
7 changed files with 283 additions and 105 deletions

2
.gitignore vendored
View File

@ -11,3 +11,5 @@ Cargo.lock
# Generated by Cargo # Generated by Cargo
/target/ /target/
*.swp

View File

@ -10,14 +10,6 @@ pub struct JitI256 {
pub words: [u64; 4] pub words: [u64; 4]
} }
impl JitI256 {
pub fn new() -> JitI256 {
JitI256 {
words: [0; 4]
}
}
}
#[repr(C)] #[repr(C)]
pub struct JitRuntimeData { pub struct JitRuntimeData {
pub gas: i64, pub gas: i64,
@ -38,31 +30,8 @@ pub struct JitRuntimeData {
pub code_hash: JitI256 pub code_hash: JitI256
} }
impl JitRuntimeData {
pub fn new() -> JitRuntimeData {
JitRuntimeData {
gas: 0,
gas_price: 0,
call_data: ptr::null(),
call_data_size: 0,
address: JitI256::new(),
caller: JitI256::new(),
origin: JitI256::new(),
call_value: JitI256::new(),
coinbase: JitI256::new(),
difficulty: JitI256::new(),
gas_limit: JitI256::new(),
number: 0,
timestamp: 0,
code: ptr::null(),
code_size: 0,
code_hash: JitI256::new()
}
}
}
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug, Eq, PartialEq)]
pub enum JitReturnCode { pub enum JitReturnCode {
Stop = 0, Stop = 0,
Return = 1, Return = 1,
@ -74,22 +43,31 @@ pub enum JitReturnCode {
UnexpectedError = -111 UnexpectedError = -111
} }
#[derive(Copy, Clone)]
pub enum JitContext {} pub enum JitContext {}
#[link(name="evmjit")] #[link(name="evmjit")]
extern "C" { extern "C" {
pub fn evmjit_create(data: JitRuntimeData, env: u8) -> JitContext; pub fn evmjit_create_runtime_data() -> *mut JitRuntimeData;
pub fn evmjit_exec(context: JitContext) -> JitReturnCode; pub fn evmjit_destroy_runtime_data(data: *mut JitRuntimeData);
pub fn evmjit_destroy(context: JitContext);
pub fn evmjit_create_context(data: *mut JitRuntimeData, env: u8) -> *mut JitContext;
pub fn evmjit_destroy_context(context: *mut JitContext);
pub fn evmjit_exec(context: *mut JitContext) -> JitReturnCode;
} }
#[test] #[test]
fn it_works() { fn it_works() {
unsafe { unsafe {
let context = evmjit_create(JitRuntimeData::new(), 0); let data = evmjit_create_runtime_data();
let _result = evmjit_exec(context); let context = evmjit_create_context(data, 0);
evmjit_destroy(context);
let code = evmjit_exec(context);
assert_eq!(code, JitReturnCode::Stop);
evmjit_destroy_runtime_data(data);
evmjit_destroy_context(context);
} }
} }

107
src/blockheader.rs Normal file
View File

@ -0,0 +1,107 @@
use util::hash::*;
use util::bytes::*;
use util::uint::*;
use util::rlp::*;
pub static ZERO_ADDRESS: Address = Address([0x00; 20]);
pub static ZERO_H256: H256 = H256([0x00; 32]);
pub static ZERO_LOGBLOOM: LogBloom = H2048([0x00; 256]);
pub type LogBloom = H2048;
#[derive(Debug)]
pub struct Header {
parent_hash: H256,
timestamp: U256,
number: U256,
author: Address,
transactions_root: H256,
uncles_hash: H256,
extra_data: Bytes,
state_root: H256,
receipts_root: H256,
log_bloom: LogBloom,
gas_used: U256,
gas_limit: U256,
difficulty: U256,
seal: Vec<Bytes>,
}
impl Header {
pub fn new() -> Header {
Header {
parent_hash: ZERO_H256.clone(),
timestamp: BAD_U256.clone(),
number: ZERO_U256.clone(),
author: ZERO_ADDRESS.clone(),
transactions_root: ZERO_H256.clone(),
uncles_hash: ZERO_H256.clone(),
extra_data: vec![],
state_root: ZERO_H256.clone(),
receipts_root: ZERO_H256.clone(),
log_bloom: ZERO_LOGBLOOM.clone(),
gas_used: ZERO_U256.clone(),
gas_limit: ZERO_U256.clone(),
difficulty: ZERO_U256.clone(),
seal: vec![],
}
}
}
impl Decodable for Header {
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
decoder.read_list(| d | {
let blockheader = Header {
parent_hash: try!(Decodable::decode(&d[0])),
uncles_hash: try!(Decodable::decode(&d[1])),
author: try!(Decodable::decode(&d[2])),
state_root: try!(Decodable::decode(&d[3])),
transactions_root: try!(Decodable::decode(&d[4])),
receipts_root: try!(Decodable::decode(&d[5])),
log_bloom: try!(Decodable::decode(&d[6])),
difficulty: try!(Decodable::decode(&d[7])),
number: try!(Decodable::decode(&d[8])),
gas_limit: try!(Decodable::decode(&d[9])),
gas_used: try!(Decodable::decode(&d[10])),
timestamp: try!(Decodable::decode(&d[11])),
extra_data: try!(Decodable::decode(&d[12])),
seal: vec![],
};
// TODO: fill blockheader.seal with (raw) list items index 12..)
Ok(blockheader)
})
}
}
impl Encodable for Header {
fn encode<E>(&self, encoder: &mut E) where E: Encoder {
encoder.emit_list(| e | {
self.parent_hash.encode(e);
self.uncles_hash.encode(e);
self.author.encode(e);
self.state_root.encode(e);
self.transactions_root.encode(e);
self.receipts_root.encode(e);
self.log_bloom.encode(e);
self.difficulty.encode(e);
self.number.encode(e);
self.gas_limit.encode(e);
self.gas_used.encode(e);
self.timestamp.encode(e);
self.extra_data.encode(e);
// TODO: emit raw seal items.
})
}
}
#[cfg(test)]
mod tests {
fn encoding_and_decoding() {
}
}

17
src/denominations.rs Normal file
View File

@ -0,0 +1,17 @@
use util::uint::*;
#[inline]
pub fn ether() -> U256 { U256::exp10(18) }
#[inline]
pub fn finney() -> U256 { U256::exp10(15) }
#[inline]
pub fn szabo() -> U256 { U256::exp10(12) }
#[inline]
pub fn shannon() -> U256 { U256::exp10(9) }
#[inline]
pub fn wei() -> U256 { U256::exp10(0) }

View File

@ -18,7 +18,7 @@
//! - OSX //! - OSX
//! //!
//! - rocksdb //! - rocksdb
//! ``` //! ```bash
//! brew install rocksdb //! brew install rocksdb
//! ``` //! ```
//! //!
@ -26,7 +26,7 @@
//! //!
//! - download llvm 3.7 from http://llvm.org/apt/ //! - download llvm 3.7 from http://llvm.org/apt/
//! //!
//! ``` //! ```bash
//! cd llvm-3.7.0.src //! cd llvm-3.7.0.src
//! mkdir build && cd $_ //! mkdir build && cd $_
//! cmake -G "Unix Makefiles" .. -DCMAKE_C_FLAGS_RELEASE= -DCMAKE_CXX_FLAGS_RELEASE= -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/llvm/3.7 -DCMAKE_BUILD_TYPE=Release //! cmake -G "Unix Makefiles" .. -DCMAKE_C_FLAGS_RELEASE= -DCMAKE_CXX_FLAGS_RELEASE= -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/llvm/3.7 -DCMAKE_BUILD_TYPE=Release
@ -36,7 +36,7 @@
//! //!
//! - download from https://github.com/debris/evmjit //! - download from https://github.com/debris/evmjit
//! //!
//! ``` //! ```bash
//! cd evmjit //! cd evmjit
//! mkdir build && cd $_ //! mkdir build && cd $_
//! cmake -DLLVM_DIR=/usr/local/lib/llvm-3.7/share/llvm/cmake .. //! cmake -DLLVM_DIR=/usr/local/lib/llvm-3.7/share/llvm/cmake ..
@ -47,7 +47,7 @@
//! //!
//! - rocksdb //! - rocksdb
//! //!
//! ``` //! ```bash
//! wget https://github.com/facebook/rocksdb/archive/rocksdb-3.13.tar.gz //! wget https://github.com/facebook/rocksdb/archive/rocksdb-3.13.tar.gz
//! tar xvf rocksdb-3.13.tar.gz && cd rocksdb-rocksdb-3.13 && make shared_lib //! tar xvf rocksdb-3.13.tar.gz && cd rocksdb-rocksdb-3.13 && make shared_lib
//! sudo make install //! sudo make install
@ -61,7 +61,7 @@
//! //!
//! - download from https://github.com/debris/evmjit //! - download from https://github.com/debris/evmjit
//! //!
//! ``` //! ```bash
//! cd evmjit //! cd evmjit
//! mkdir build && cd $_ //! mkdir build && cd $_
//! cmake .. && make //! cmake .. && make
@ -72,71 +72,21 @@
#[macro_use] #[macro_use]
extern crate log; extern crate log;
extern crate env_logger; extern crate env_logger;
extern crate ethcore_util;
#[cfg(feature = "jit" )] #[cfg(feature = "jit" )]
extern crate evmjit; extern crate evmjit;
extern crate ethcore_util as util;
//use ethcore_util::error::*; //use util::error::*;
use ethcore_util::hash::*; pub use util::hash::*;
use ethcore_util::uint::*; pub use util::uint::*;
use ethcore_util::bytes::*; pub use util::bytes::*;
pub type LogBloom = H2048;
pub mod state; pub mod state;
pub mod blockheader;
pub mod transaction;
pub mod networkparams;
pub mod denominations;
pub static ZERO_ADDRESS: Address = Address([0x00; 20]); #[test]
pub static ZERO_H256: H256 = H256([0x00; 32]); fn it_works() {
pub static ZERO_LOGBLOOM: LogBloom = H2048([0x00; 256]);
#[derive(Debug)]
pub struct Header {
parent_hash: H256,
timestamp: U256,
number: U256,
author: Address,
transactions_root: H256,
uncles_hash: H256,
extra_data_hash: H256,
state_root: H256,
receipts_root: H256,
log_bloom: LogBloom,
gas_used: U256,
gas_limit: U256,
difficulty: U256,
seal: Vec<Bytes>,
}
impl Header {
pub fn new() -> Header {
Header {
parent_hash: ZERO_H256.clone(),
timestamp: BAD_U256.clone(),
number: ZERO_U256.clone(),
author: ZERO_ADDRESS.clone(),
transactions_root: ZERO_H256.clone(),
uncles_hash: ZERO_H256.clone(),
extra_data_hash: ZERO_H256.clone(),
state_root: ZERO_H256.clone(),
receipts_root: ZERO_H256.clone(),
log_bloom: ZERO_LOGBLOOM.clone(),
gas_used: ZERO_U256.clone(),
gas_limit: ZERO_U256.clone(),
difficulty: ZERO_U256.clone(),
seal: vec![],
}
}
}
pub struct Transaction {
pub to: Address,
pub gas: U256,
pub data: Bytes,
pub code: Bytes,
} }

71
src/networkparams.rs Normal file
View File

@ -0,0 +1,71 @@
use util::uint::*;
use denominations::*;
/// Network related const params
/// TODO: make it configurable from json file
pub struct NetworkParams {
maximum_extra_data_size: U256,
min_gas_limit: U256,
gas_limit_bounds_divisor: U256,
minimum_difficulty: U256,
difficulty_bound_divisor: U256,
duration_limit: U256,
block_reward: U256,
gas_floor_target: U256,
account_start_nonce: U256
}
impl NetworkParams {
pub fn olympic() -> NetworkParams {
NetworkParams {
maximum_extra_data_size: U256::from(1024u64),
min_gas_limit: U256::from(125_000u64),
gas_floor_target: U256::from(3_141_592u64),
gas_limit_bounds_divisor: U256::from(1024u64),
minimum_difficulty: U256::from(131_072u64),
difficulty_bound_divisor: U256::from(2048u64),
duration_limit: U256::from(8u64),
block_reward: finney() * U256::from(1500u64),
account_start_nonce: U256::from(0u64)
}
}
pub fn frontier() -> NetworkParams {
NetworkParams {
maximum_extra_data_size: U256::from(32u64),
min_gas_limit: U256::from(5000u64),
gas_floor_target: U256::from(3_141_592u64),
gas_limit_bounds_divisor: U256::from(1024u64),
minimum_difficulty: U256::from(131_072u64),
difficulty_bound_divisor: U256::from(2048u64),
duration_limit: U256::from(13u64),
block_reward: ether() * U256::from(5u64),
account_start_nonce: U256::from(0u64)
}
}
pub fn morden() -> NetworkParams {
NetworkParams {
maximum_extra_data_size: U256::from(32u64),
min_gas_limit: U256::from(5000u64),
gas_floor_target: U256::from(3_141_592u64),
gas_limit_bounds_divisor: U256::from(1024u64),
minimum_difficulty: U256::from(131_072u64),
difficulty_bound_divisor: U256::from(2048u64),
duration_limit: U256::from(13u64),
block_reward: ether() * U256::from(5u64),
account_start_nonce: U256::from(1u64) << 20
}
}
pub fn maximum_extra_data_size(&self) -> U256 { self.maximum_extra_data_size }
pub fn min_gas_limit(&self) -> U256 { self.min_gas_limit }
pub fn gas_limit_bounds_divisor(&self) -> U256 { self.gas_limit_bounds_divisor }
pub fn minimum_difficulty(&self) -> U256 { self.minimum_difficulty }
pub fn difficulty_bound_divisor(&self) -> U256 { self.difficulty_bound_divisor }
pub fn duration_limit(&self) -> U256 { self.duration_limit }
pub fn block_reward(&self) -> U256 { self.block_reward }
pub fn gas_floor_target(&self) -> U256 { self.gas_floor_target }
pub fn account_start_nonce(&self) -> U256 { self.account_start_nonce }
}

53
src/transaction.rs Normal file
View File

@ -0,0 +1,53 @@
use util::hash::*;
use util::bytes::*;
use util::uint::*;
use util::rlp::*;
pub struct Transaction {
nonce: U256,
gas_price: U256,
gas: U256,
receive_address: Option<Address>,
value: U256,
data: Bytes,
}
impl Transaction {
pub fn is_contract_creation(&self) -> bool {
self.receive_address.is_none()
}
pub fn is_message_call(&self) -> bool {
!self.is_contract_creation()
}
}
impl Encodable for Transaction {
fn encode<E>(&self, encoder: &mut E) where E: Encoder {
encoder.emit_list(| e | {
self.nonce.encode(e);
self.gas_price.encode(e);
self.gas.encode(e);
self.receive_address.encode(e);
self.value.encode(e);
self.data.encode(e);
})
}
}
impl Decodable for Transaction {
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
decoder.read_list(| d | {
let transaction = Transaction {
nonce: try!(Decodable::decode(&d[0])),
gas_price: try!(Decodable::decode(&d[1])),
gas: try!(Decodable::decode(&d[2])),
receive_address: try!(Decodable::decode(&d[3])),
value: try!(Decodable::decode(&d[4])),
data: try!(Decodable::decode(&d[5])),
};
Ok(transaction)
})
}
}