From 2d4f4bdd614fda07373bf5f901d8845fa970cc43 Mon Sep 17 00:00:00 2001 From: Arkadiy Paronyan Date: Mon, 9 Oct 2017 13:07:57 +0200 Subject: [PATCH] [beta] Backporting (#6675) * Required validators >= num owners (#6551) * Debounce sync status. (#6572) * Fixed network protocol version negotiation * Renamed RPC receipt statusCode field to status * Fixed RETURNDATA size for built-ins --- ethcore/src/executive.rs | 11 ++++-- js/package-lock.json | 36 +++++++++---------- .../modals/CreateWallet/createWalletStore.js | 6 ++++ js/src/redux/providers/status.js | 11 ++++-- rpc/src/v1/tests/mocked/eth.rs | 2 +- rpc/src/v1/types/receipt.rs | 4 +-- util/network/src/session.rs | 1 + 7 files changed, 46 insertions(+), 25 deletions(-) diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index 60db246f7..dd0f80bdd 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -412,13 +412,19 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> { let cost = builtin.cost(data); if cost <= params.gas { - if let Err(e) = builtin.execute(data, &mut output) { + let mut builtin_out_buffer = Vec::new(); + let result = { + let mut builtin_output = BytesRef::Flexible(&mut builtin_out_buffer); + builtin.execute(data, &mut builtin_output) + }; + if let Err(e) = result { self.state.revert_to_checkpoint(); let evm_err: evm::evm::Error = e.into(); tracer.trace_failed_call(trace_info, vec![], evm_err.clone().into()); Err(evm_err) } else { self.state.discard_checkpoint(); + output.write(0, &builtin_out_buffer); // trace only top level calls to builtins to avoid DDoS attacks if self.depth == 0 { @@ -435,9 +441,10 @@ impl<'a, B: 'a + StateBackend, E: Engine + ?Sized> Executive<'a, B, E> { ); } + let out_len = builtin_out_buffer.len(); Ok(FinalizationResult { gas_left: params.gas - cost, - return_data: ReturnData::new(output.to_owned(), 0, output.len()), + return_data: ReturnData::new(builtin_out_buffer, 0, out_len), apply_state: true, }) } diff --git a/js/package-lock.json b/js/package-lock.json index e0ed440e3..881c20f1a 100644 --- a/js/package-lock.json +++ b/js/package-lock.json @@ -9,6 +9,16 @@ "resolved": "https://registry.npmjs.org/@parity/wordlist/-/wordlist-1.0.1.tgz", "integrity": "sha1-wn5A4as2OKCe1TtKLoHVMbXrWjE=" }, + "JSONStream": { + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-0.8.4.tgz", + "integrity": "sha1-kWV9/m/4V0gwZhMrRhi2Lo9Ih70=", + "dev": true, + "requires": { + "jsonparse": "0.0.5", + "through": "2.3.8" + } + }, "abab": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/abab/-/abab-1.0.3.tgz", @@ -7154,16 +7164,6 @@ "integrity": "sha1-T9kss04OnbPInIYi7PUfm5eMbLk=", "dev": true }, - "JSONStream": { - "version": "0.8.4", - "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-0.8.4.tgz", - "integrity": "sha1-kWV9/m/4V0gwZhMrRhi2Lo9Ih70=", - "dev": true, - "requires": { - "jsonparse": "0.0.5", - "through": "2.3.8" - } - }, "jsprim": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", @@ -11649,14 +11649,6 @@ "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz", "integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=" }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "requires": { - "safe-buffer": "5.1.1" - } - }, "string-width": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", @@ -11672,6 +11664,14 @@ "resolved": "https://registry.npmjs.org/string.prototype.repeat/-/string.prototype.repeat-0.2.0.tgz", "integrity": "sha1-q6Nt4I3O5qWjN9SbLqHaGyj8Ds8=" }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "requires": { + "safe-buffer": "5.1.1" + } + }, "stringify-object": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/stringify-object/-/stringify-object-3.2.0.tgz", diff --git a/js/src/modals/CreateWallet/createWalletStore.js b/js/src/modals/CreateWallet/createWalletStore.js index 26ed5816c..c155ad1c1 100644 --- a/js/src/modals/CreateWallet/createWalletStore.js +++ b/js/src/modals/CreateWallet/createWalletStore.js @@ -281,6 +281,12 @@ export default class CreateWalletStore { const daylimitValidation = validateUint(_wallet.daylimit); const nameValidation = validateName(_wallet.name); + const owners = _wallet.owners.filter((owner) => !/^(0x)?0*$/.test(owner)); + + if (_wallet.required > owners.length) { + requiredValidation.valueError = 'the number of required validators should be lower or equal the number of owners'; + } + const errors = { address: addressValidation.addressError, account: accountValidation.addressError, diff --git a/js/src/redux/providers/status.js b/js/src/redux/providers/status.js index c1689ea0e..5e294ffae 100644 --- a/js/src/redux/providers/status.js +++ b/js/src/redux/providers/status.js @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -import { isEqual } from 'lodash'; +import { isEqual, debounce } from 'lodash'; import { LOG_KEYS, getLogger } from '~/config'; import UpgradeStore from '~/modals/UpgradeParity/store'; @@ -179,6 +179,12 @@ export default class Status { }); } + _updateStatus = debounce(status => { + this._store.dispatch(statusCollection(status)); + }, 2500, { + maxWait: 5000 + }); + _subscribeEthSyncing = () => { return this._api.pubsub .eth @@ -187,7 +193,7 @@ export default class Status { return; } - this._store.dispatch(statusCollection({ syncing })); + this._updateStatus({ syncing }); }); } @@ -198,6 +204,7 @@ export default class Status { if (error || !netPeers) { return; } + this._store.dispatch(statusCollection({ netPeers })); }); } diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index 43c251bb9..f4b417f20 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -1019,7 +1019,7 @@ fn rpc_eth_transaction_receipt() { "params": ["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"], "id": 1 }"#; - let response = r#"{"jsonrpc":"2.0","result":{"blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","contractAddress":null,"cumulativeGasUsed":"0x20","gasUsed":"0x10","logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","data":"0x","logIndex":"0x1","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"}],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","root":"0x0000000000000000000000000000000000000000000000000000000000000000","statusCode":null,"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0"},"id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":{"blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","contractAddress":null,"cumulativeGasUsed":"0x20","gasUsed":"0x10","logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","data":"0x","logIndex":"0x1","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"}],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","root":"0x0000000000000000000000000000000000000000000000000000000000000000","status":null,"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0"},"id":1}"#; assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned())); } diff --git a/rpc/src/v1/types/receipt.rs b/rpc/src/v1/types/receipt.rs index ca313a440..bb8af2cd0 100644 --- a/rpc/src/v1/types/receipt.rs +++ b/rpc/src/v1/types/receipt.rs @@ -50,7 +50,7 @@ pub struct Receipt { #[serde(rename="logsBloom")] pub logs_bloom: H2048, /// Status code - #[serde(rename="statusCode")] + #[serde(rename="status")] pub status_code: Option, } @@ -131,7 +131,7 @@ mod tests { #[test] fn receipt_serialization() { - let s = r#"{"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","cumulativeGasUsed":"0x20","gasUsed":"0x10","contractAddress":null,"logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"data":"0x","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","logIndex":"0x1","transactionLogIndex":null,"type":"mined"}],"root":"0x000000000000000000000000000000000000000000000000000000000000000a","logsBloom":"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f","statusCode":null}"#; + let s = r#"{"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","cumulativeGasUsed":"0x20","gasUsed":"0x10","contractAddress":null,"logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"data":"0x","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","logIndex":"0x1","transactionLogIndex":null,"type":"mined"}],"root":"0x000000000000000000000000000000000000000000000000000000000000000a","logsBloom":"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f","status":null}"#; let receipt = Receipt { transaction_hash: Some(0.into()), diff --git a/util/network/src/session.rs b/util/network/src/session.rs index 8affb4cf7..938287021 100644 --- a/util/network/src/session.rs +++ b/util/network/src/session.rs @@ -511,6 +511,7 @@ impl Session { i += 1; } debug!(target: "network", "Hello: {} v{} {} {:?}", client_version, protocol, id, caps); + let protocol = ::std::cmp::min(protocol, host.protocol_version); self.info.protocol_version = protocol; self.info.client_version = client_version; self.info.capabilities = caps;