From 2911c549e317a17bf50d3e7395a006d2bbf36eef Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 4 Dec 2016 10:48:26 -0800 Subject: [PATCH 1/5] Encode networkid as a u64. --- ethcore/src/client/client.rs | 2 +- ethcore/src/client/test_client.rs | 2 +- ethcore/src/client/traits.rs | 2 +- ethcore/src/engines/mod.rs | 2 +- ethcore/src/ethereum/ethash.rs | 8 ++++---- ethcore/src/spec/spec.rs | 4 ++-- ethcore/src/types/transaction.rs | 16 ++++++++-------- parity/run.rs | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 85ec05b03..ddfdd836d 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -1272,7 +1272,7 @@ impl BlockChainClient for Client { self.miner.pending_transactions(self.chain.read().best_block_number()) } - fn signing_network_id(&self) -> Option { + fn signing_network_id(&self) -> Option { self.engine.signing_network_id(&self.latest_env_info()) } diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index c03b5920b..8d7e0b715 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -662,7 +662,7 @@ impl BlockChainClient for TestBlockChainClient { self.miner.pending_transactions(self.chain_info().best_block_number) } - fn signing_network_id(&self) -> Option { None } + fn signing_network_id(&self) -> Option { None } fn mode(&self) -> Mode { Mode::Active } diff --git a/ethcore/src/client/traits.rs b/ethcore/src/client/traits.rs index 6d774e250..30e47601a 100644 --- a/ethcore/src/client/traits.rs +++ b/ethcore/src/client/traits.rs @@ -237,7 +237,7 @@ pub trait BlockChainClient : Sync + Send { } /// Get the preferred network ID to sign on - fn signing_network_id(&self) -> Option; + fn signing_network_id(&self) -> Option; /// Get the mode. fn mode(&self) -> Mode; diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index c70a19de8..2732f3032 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -113,7 +113,7 @@ pub trait Engine : Sync + Send { fn verify_transaction(&self, _t: &SignedTransaction, _header: &Header) -> Result<(), Error> { Ok(()) } /// The network ID that transactions should be signed with. - fn signing_network_id(&self, _env_info: &EnvInfo) -> Option { None } + fn signing_network_id(&self, _env_info: &EnvInfo) -> Option { None } /// Verify the seal of a block. This is an auxilliary method that actually just calls other `verify_` methods /// to get the job done. By default it must pass `verify_basic` and `verify_block_unordered`. If more or fewer diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 38a1df525..ab6169d00 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -163,9 +163,9 @@ impl Engine for Ethash { } } - fn signing_network_id(&self, env_info: &EnvInfo) -> Option { - if env_info.number >= self.ethash_params.eip155_transition && self.params().network_id < 127 { - Some(self.params().network_id as u8) + fn signing_network_id(&self, env_info: &EnvInfo) -> Option { + if env_info.number >= self.ethash_params.eip155_transition { + Some(self.params().network_id) } else { None } @@ -314,7 +314,7 @@ impl Engine for Ethash { } if let Some(n) = t.network_id() { - if header.number() < self.ethash_params.eip155_transition || n as usize != self.params().network_id { + if header.number() < self.ethash_params.eip155_transition || n != self.params().network_id { return Err(TransactionError::InvalidNetworkId.into()) } } diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 71c15bca2..a4a4a4c6b 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -38,7 +38,7 @@ pub struct CommonParams { /// Maximum size of extra data. pub maximum_extra_data_size: usize, /// Network id. - pub network_id: usize, + pub network_id: u64, /// Main subprotocol name. pub subprotocol_name: String, /// Minimum gas limit. @@ -167,7 +167,7 @@ impl Spec { pub fn nodes(&self) -> &[String] { &self.nodes } /// Get the configured Network ID. - pub fn network_id(&self) -> usize { self.params.network_id } + pub fn network_id(&self) -> u64 { self.params.network_id } /// Get the configured subprotocol name. pub fn subprotocol_name(&self) -> String { self.params.subprotocol_name.clone() } diff --git a/ethcore/src/types/transaction.rs b/ethcore/src/types/transaction.rs index 7dba4da53..29afb2226 100644 --- a/ethcore/src/types/transaction.rs +++ b/ethcore/src/types/transaction.rs @@ -72,7 +72,7 @@ pub struct Transaction { impl Transaction { /// Append object with a without signature into RLP stream - pub fn rlp_append_unsigned_transaction(&self, s: &mut RlpStream, network_id: Option) { + pub fn rlp_append_unsigned_transaction(&self, s: &mut RlpStream, network_id: Option) { s.begin_list(if network_id.is_none() { 6 } else { 9 }); s.append(&self.nonce); s.append(&self.gas_price); @@ -140,26 +140,26 @@ impl From for SignedTransaction { impl Transaction { /// The message hash of the transaction. - pub fn hash(&self, network_id: Option) -> H256 { + pub fn hash(&self, network_id: Option) -> H256 { let mut stream = RlpStream::new(); self.rlp_append_unsigned_transaction(&mut stream, network_id); stream.out().sha3() } /// Signs the transaction as coming from `sender`. - pub fn sign(self, secret: &Secret, network_id: Option) -> SignedTransaction { + pub fn sign(self, secret: &Secret, network_id: Option) -> SignedTransaction { let sig = ::ethkey::sign(secret, &self.hash(network_id)) .expect("data is valid and context has signing capabilities; qed"); self.with_signature(sig, network_id) } /// Signs the transaction with signature. - pub fn with_signature(self, sig: Signature, network_id: Option) -> SignedTransaction { + pub fn with_signature(self, sig: Signature, network_id: Option) -> SignedTransaction { SignedTransaction { unsigned: self, r: sig.r().into(), s: sig.s().into(), - v: sig.v() + if let Some(n) = network_id { 35 + n * 2 } else { 27 }, + v: sig.v() as u64 + if let Some(n) = network_id { 35 + n * 2 } else { 27 }, hash: Cell::new(None), sender: Cell::new(None), } @@ -211,7 +211,7 @@ pub struct SignedTransaction { unsigned: Transaction, /// The V field of the signature; the LS bit described which half of the curve our point falls /// in. The MS bits describe which network this transaction is for. If 27/28, its for all networks. - v: u8, + v: u64, /// The R field of the signature; helps describe the point on the curve. r: U256, /// The S field of the signature; helps describe the point on the curve. @@ -302,10 +302,10 @@ impl SignedTransaction { } /// 0 if `v` would have been 27 under "Electrum" notation, 1 if 28 or 4 if invalid. - pub fn standard_v(&self) -> u8 { match self.v { v if v == 27 || v == 28 || v > 36 => (v - 1) % 2, _ => 4 } } + pub fn standard_v(&self) -> u8 { match self.v { v if v == 27 || v == 28 || v > 36 => ((v - 1) % 2) as u8, _ => 4 } } /// The network ID, or `None` if this is a global transaction. - pub fn network_id(&self) -> Option { + pub fn network_id(&self) -> Option { match self.v { v if v > 36 => Some((v - 35) / 2), _ => None, diff --git a/parity/run.rs b/parity/run.rs index f977c450c..70c0b86f3 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -194,7 +194,7 @@ pub fn execute(cmd: RunCmd, logger: Arc) -> Result<(), String> { let mut sync_config = SyncConfig::default(); sync_config.network_id = match cmd.network_id { Some(id) => id, - None => spec.network_id(), + None => spec.network_id() as usize, }; if spec.subprotocol_name().len() != 3 { warn!("Your chain specification's subprotocol length is not 3. Ignoring."); From 22632e63240dd65ff43d76669d1da33ee1e9e0a7 Mon Sep 17 00:00:00 2001 From: keorn Date: Mon, 5 Dec 2016 14:07:31 +0000 Subject: [PATCH 2/5] make generic seal take valid rlp --- ethcore/res/authority_round.json | 3 +-- ethcore/res/instant_seal.json | 1 - ethcore/src/spec/seal.rs | 9 ++------- ethcore/src/spec/spec.rs | 13 ++----------- json/src/spec/seal.rs | 9 +++------ 5 files changed, 8 insertions(+), 27 deletions(-) diff --git a/ethcore/res/authority_round.json b/ethcore/res/authority_round.json index 9ab782395..a0f88b85b 100644 --- a/ethcore/res/authority_round.json +++ b/ethcore/res/authority_round.json @@ -21,8 +21,7 @@ "genesis": { "seal": { "generic": { - "fields": 2, - "rlp": "0x200" + "rlp": "0xc28080" } }, "difficulty": "0x20000", diff --git a/ethcore/res/instant_seal.json b/ethcore/res/instant_seal.json index a6b24faf9..fbb650102 100644 --- a/ethcore/res/instant_seal.json +++ b/ethcore/res/instant_seal.json @@ -12,7 +12,6 @@ "genesis": { "seal": { "generic": { - "fields": 0, "rlp": "0x0" } }, diff --git a/ethcore/src/spec/seal.rs b/ethcore/src/spec/seal.rs index e25f174d2..f3e5dca95 100644 --- a/ethcore/src/spec/seal.rs +++ b/ethcore/src/spec/seal.rs @@ -30,11 +30,9 @@ pub struct Ethereum { impl Into for Ethereum { fn into(self) -> Generic { - let mut s = RlpStream::new(); - s.append(&self.mix_hash); - s.append(&self.nonce); + let mut s = RlpStream::new_list(2); + s.append(&self.mix_hash).append(&self.nonce); Generic { - fields: 2, rlp: s.out() } } @@ -42,8 +40,6 @@ impl Into for Ethereum { /// Generic seal. pub struct Generic { - /// Number of seal fields. - pub fields: usize, /// Seal rlp. pub rlp: Vec, } @@ -64,7 +60,6 @@ impl From for Seal { mix_hash: eth.mix_hash.into() }), ethjson::spec::Seal::Generic(g) => Seal::Generic(Generic { - fields: g.fields, rlp: g.rlp.into() }) } diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 71c15bca2..63a692701 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -94,8 +94,6 @@ pub struct Spec { pub receipts_root: H256, /// The genesis block's extra data field. pub extra_data: Bytes, - /// The number of seal fields in the genesis block. - pub seal_fields: usize, /// Each seal field, expressed as RLP, concatenated. pub seal_rlp: Bytes, @@ -127,7 +125,6 @@ impl From for Spec { gas_used: g.gas_used, timestamp: g.timestamp, extra_data: g.extra_data, - seal_fields: seal.fields, seal_rlp: seal.rlp, state_root_memo: RwLock::new(g.state_root), genesis_state: From::from(s.accounts), @@ -192,13 +189,8 @@ impl Spec { header.set_gas_limit(self.gas_limit.clone()); header.set_difficulty(self.difficulty.clone()); header.set_seal({ - let seal = { - let mut s = RlpStream::new_list(self.seal_fields); - s.append_raw(&self.seal_rlp, self.seal_fields); - s.out() - }; - let r = Rlp::new(&seal); - (0..self.seal_fields).map(|i| r.at(i).as_raw().to_vec()).collect() + let r = Rlp::new(&self.seal_rlp); + r.iter().map(|f| f.as_raw().to_vec()).collect() }); trace!(target: "spec", "Header hash is {}", header.hash()); header @@ -227,7 +219,6 @@ impl Spec { self.gas_used = g.gas_used; self.timestamp = g.timestamp; self.extra_data = g.extra_data; - self.seal_fields = seal.fields; self.seal_rlp = seal.rlp; self.state_root_memo = RwLock::new(g.state_root); } diff --git a/json/src/spec/seal.rs b/json/src/spec/seal.rs index a1a53819a..5bff73d31 100644 --- a/json/src/spec/seal.rs +++ b/json/src/spec/seal.rs @@ -32,9 +32,7 @@ pub struct Ethereum { /// Generic seal. #[derive(Debug, PartialEq, Deserialize)] pub struct Generic { - /// Number of fields. - pub fields: usize, - /// Their rlp. + /// Seal rlp. pub rlp: Bytes, } @@ -63,11 +61,10 @@ mod tests { } },{ "generic": { - "fields": 1, - "rlp": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa" + "rlp": "0xe011bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa" } }]"#; - let _deserialized: Vec = serde_json::from_str(s).unwrap(); + let deserialized: Vec = serde_json::from_str(s).unwrap(); // TODO: validate all fields } } From 0860a3a7676eb6cb08170d2ed9f193bf0848c8eb Mon Sep 17 00:00:00 2001 From: keorn Date: Mon, 5 Dec 2016 14:09:41 +0000 Subject: [PATCH 3/5] ignore variable --- json/src/spec/seal.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json/src/spec/seal.rs b/json/src/spec/seal.rs index 5bff73d31..0daea1ba4 100644 --- a/json/src/spec/seal.rs +++ b/json/src/spec/seal.rs @@ -64,7 +64,7 @@ mod tests { "rlp": "0xe011bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa" } }]"#; - let deserialized: Vec = serde_json::from_str(s).unwrap(); + let _deserialized: Vec = serde_json::from_str(s).unwrap(); // TODO: validate all fields } } From 43ec3d8f79b0435be55c87af1586c73e750b99d3 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 5 Dec 2016 06:54:31 -0800 Subject: [PATCH 4/5] network_id -> u64 --- parity/cli/mod.rs | 6 +++--- parity/configuration.rs | 2 +- parity/run.rs | 4 ++-- rpc/src/v1/tests/helpers/sync_provider.rs | 2 +- sync/src/api.rs | 2 +- sync/src/chain.rs | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/parity/cli/mod.rs b/parity/cli/mod.rs index d33c58d9d..7fcdd2209 100644 --- a/parity/cli/mod.rs +++ b/parity/cli/mod.rs @@ -48,7 +48,7 @@ usage! { flag_testnet: bool, flag_import_geth_keys: bool, flag_datadir: Option, - flag_networkid: Option, + flag_networkid: Option, flag_peers: Option, flag_nodekey: Option, flag_nodiscover: bool, @@ -122,7 +122,7 @@ usage! { or |c: &Config| otry!(c.network).nat.clone(), flag_allow_ips: String = "all", or |c: &Config| otry!(c.network).allow_ips.clone(), - flag_network_id: Option = None, + flag_network_id: Option = None, or |c: &Config| otry!(c.network).id.clone().map(Some), flag_bootnodes: Option = None, or |c: &Config| otry!(c.network).bootnodes.clone().map(|vec| Some(vec.join(","))), @@ -328,7 +328,7 @@ struct Network { max_pending_peers: Option, nat: Option, allow_ips: Option, - id: Option, + id: Option, bootnodes: Option>, discovery: Option, node_key: Option, diff --git a/parity/configuration.rs b/parity/configuration.rs index c4a54f747..37c699521 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -527,7 +527,7 @@ impl Configuration { Ok(ret) } - fn network_id(&self) -> Option { + fn network_id(&self) -> Option { self.args.flag_network_id.or(self.args.flag_networkid) } diff --git a/parity/run.rs b/parity/run.rs index 70c0b86f3..42a972000 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -70,7 +70,7 @@ pub struct RunCmd { pub http_conf: HttpConfiguration, pub ipc_conf: IpcConfiguration, pub net_conf: NetworkConfiguration, - pub network_id: Option, + pub network_id: Option, pub warp_sync: bool, pub acc_conf: AccountsConfig, pub gas_pricer: GasPricerConfig, @@ -194,7 +194,7 @@ pub fn execute(cmd: RunCmd, logger: Arc) -> Result<(), String> { let mut sync_config = SyncConfig::default(); sync_config.network_id = match cmd.network_id { Some(id) => id, - None => spec.network_id() as usize, + None => spec.network_id(), }; if spec.subprotocol_name().len() != 3 { warn!("Your chain specification's subprotocol length is not 3. Ignoring."); diff --git a/rpc/src/v1/tests/helpers/sync_provider.rs b/rpc/src/v1/tests/helpers/sync_provider.rs index 24be33417..8800d926a 100644 --- a/rpc/src/v1/tests/helpers/sync_provider.rs +++ b/rpc/src/v1/tests/helpers/sync_provider.rs @@ -23,7 +23,7 @@ use ethsync::{SyncProvider, SyncStatus, SyncState, PeerInfo, TransactionStats}; /// TestSyncProvider config. pub struct Config { /// Protocol version. - pub network_id: usize, + pub network_id: u64, /// Number of peers. pub num_peers: usize, } diff --git a/sync/src/api.rs b/sync/src/api.rs index cdab0983a..5613b77ff 100644 --- a/sync/src/api.rs +++ b/sync/src/api.rs @@ -44,7 +44,7 @@ pub struct SyncConfig { /// Enable ancient block download. pub download_old_blocks: bool, /// Network ID - pub network_id: usize, + pub network_id: u64, /// Main "eth" subprotocol name. pub subprotocol_name: [u8; 3], /// Fork block to check diff --git a/sync/src/chain.rs b/sync/src/chain.rs index bd312c9ee..2d53ad5ee 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -192,7 +192,7 @@ pub struct SyncStatus { /// Syncing protocol version. That's the maximum protocol version we connect to. pub protocol_version: u8, /// The underlying p2p network version. - pub network_id: usize, + pub network_id: u64, /// `BlockChain` height for the moment the sync started. pub start_block_number: BlockNumber, /// Last fully downloaded and imported block number (if any). @@ -273,7 +273,7 @@ struct PeerInfo { /// Peer chain genesis hash genesis: H256, /// Peer network id - network_id: usize, + network_id: u64, /// Peer best block hash latest_hash: H256, /// Peer total difficulty if known @@ -341,7 +341,7 @@ pub struct ChainSync { /// Last propagated block number last_sent_block_number: BlockNumber, /// Network ID - network_id: usize, + network_id: u64, /// Optional fork block to check fork_block: Option<(BlockNumber, H256)>, /// Snapshot downloader. From e6ed49b2c993fa3c7036583aa0823bc88921e45f Mon Sep 17 00:00:00 2001 From: GitLab Build Bot Date: Mon, 5 Dec 2016 15:05:10 +0000 Subject: [PATCH 5/5] [ci skip] js-precompiled 20161205-150312 --- Cargo.lock | 2 +- js/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 19fe95318..a6fa12b3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1270,7 +1270,7 @@ dependencies = [ [[package]] name = "parity-ui-precompiled" version = "1.4.0" -source = "git+https://github.com/ethcore/js-precompiled.git#d6232885df4b43c91291d31c769e48f107246d73" +source = "git+https://github.com/ethcore/js-precompiled.git#7700411d2b0ba1372e0d6cf72a84ecf873a181f3" dependencies = [ "parity-dapps-glue 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/js/package.json b/js/package.json index 588a06e1b..5341cee31 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "parity.js", - "version": "0.2.90", + "version": "0.2.91", "main": "release/index.js", "jsnext:main": "src/index.js", "author": "Parity Team ",