Compare commits
195 Commits
v3.1.1-rc.
...
main
Author | SHA1 | Date |
---|---|---|
POA | 6e06824c23 | |
Rim Rakhimov | 43d6da6b52 | |
Rim Rakhimov | 412d797a3b | |
Rim Rakhimov | 63bab44e3c | |
Rim Rakhimov | f703d01f23 | |
POA | f13fa10b8a | |
POA | 657100cebc | |
POA | d2d19ec8c2 | |
POA | 0f872aff78 | |
Rim Rakhimov | 405738c791 | |
Rim Rakhimov | 3b19a79c37 | |
POA | 64a1614769 | |
POA | b981f7beef | |
POA | caa210107e | |
POA | 88eb7d3257 | |
POA | 73895aae88 | |
POA | c5719983b2 | |
POA | f9b2db206a | |
POA | 437ba9b044 | |
uink45 | 98873fc0c0 | |
POA | 415a522429 | |
POA | 646f49fdd0 | |
POA | 25ce4b2ec8 | |
POA | ac30783c82 | |
POA | 5e9b4c58ae | |
POA | 74e709fd55 | |
POA | 3413343caa | |
sunce86 | 8bb02dd479 | |
sunce86 | 79be8f1ab8 | |
sunce86 | a049baf6b2 | |
sunce86 | d8305c52ea | |
Jochen Müller | 239d790df1 | |
Jochen Müller | 298a1a0ecc | |
Jochen Müller | 36b3f125a4 | |
sunce86 | 5d9ff63043 | |
sunce86 | 01996c8867 | |
varasev | 2ae294990a | |
sunce86 | 745c4bd00c | |
sunce86 | ecae5f1c47 | |
Dusan Stanivukovic | 87ae05d99e | |
sunce86 | a92e5e761b | |
Dusan Stanivukovic | 87603926b5 | |
Dusan Stanivukovic | eb42f0c5d9 | |
Dusan Stanivukovic | 33908e8361 | |
Dusan Stanivukovic | aa09846200 | |
Dusan Stanivukovic | 67ab600bc9 | |
Dusan Stanivukovic | 4b437428bd | |
Jochen Müller | 38e40f649c | |
Jochen Müller | 43ee520904 | |
sunce86 | fdaee51ca0 | |
Dusan Stanivukovic | eec38b30e3 | |
Dusan Stanivukovic | 287409f9f5 | |
Dusan Stanivukovic | e5ae846de4 | |
Dusan Stanivukovic | e6f3794dd4 | |
sunce86 | 5920f232d0 | |
sunce86 | 3bce814090 | |
sunce86 | 118051696e | |
Dusan Stanivukovic | 17057eeedc | |
Dusan Stanivukovic | 7aa1e987de | |
Jochen Müller | 193b25a22d | |
Jochen Müller | 99a8ddae41 | |
Dusan Stanivukovic | 93b39df02d | |
Dusan Stanivukovic | 5dec58ba9f | |
Dusan Stanivukovic | b928380b64 | |
Dusan Stanivukovic | 5e7086d54c | |
Jochen Müller | 144b2293a2 | |
Jochen Müller | f14d3e5a5c | |
Jochen Müller | f9f492638c | |
varasev | fe198ddf7d | |
Jochen Müller | 32d8b5487a | |
rakita | 6835ec53ad | |
Jochen Müller | 09ab40b956 | |
Jochen Müller | 2df74c26dd | |
varasev | ed12fffeef | |
Jochen Müller | c03cc15468 | |
rakita | 3b3ecf6676 | |
rakita | be9b16ab67 | |
varasev | 392a909cb7 | |
Jochen Müller | 6f5a00a642 | |
Jochen Müller | 2453f1a803 | |
rakita | 09967329af | |
rakita | 459a1a02a4 | |
Wei Tang | a716eb3871 | |
Wei Tang | 0fd7c59724 | |
rakita | aa41520dd1 | |
Wei Tang | 4bffab6715 | |
Wei Tang | 5709dbc3e0 | |
Wei Tang | 6ce6666cbb | |
rakita | 582bca385f | |
rakita | 9037ad0ea7 | |
rakita | c9190a39ed | |
rakita | 85391f99ac | |
rakita | 561ed8df3c | |
rakita | 5eacff59e8 | |
rakita | d030870220 | |
Karim Agha | ee88247e71 | |
Jochen Müller | 37f5291538 | |
rakita | 5fdedf0858 | |
Jochen Müller | 504777e879 | |
rakita | 3317797285 | |
rakita | 33a3a9deec | |
Karim Agha | 327c4bcb14 | |
Karim Agha | b6b5129058 | |
Karim Agha | 29dc10c446 | |
Simon KP | 48e7d6cee4 | |
rakita | a0f406e26b | |
rakita | 3f8e0cfec4 | |
rakita | f143ddb75a | |
rakita | 32fd2b484c | |
rakita | 187c81b3f1 | |
rakita | d7a958129f | |
rakita | eca8fb74ae | |
Karim Agha | e2024c4b81 | |
rakita | 5b904476cd | |
rakita | 7ea5707904 | |
rakita | 458d55559e | |
rakita | 6f50061f0c | |
gakada | dbc5f94241 | |
rakita | 0cf0cdbb86 | |
rakita | 91e57c803d | |
adria0.eth | 0fcb102f03 | |
Dusan Stanivukovic | 973a5a594b | |
rakita | ba011eba15 | |
Anonymous | 7c9eed8d65 | |
Anonymous | 63fdad8d86 | |
Dusan Stanivukovic | 0947261cf2 | |
Giacomo | efb80e1032 | |
draganrakita | f0fd88aa12 | |
draganrakita | 142b63a4f9 | |
rakita | 1d2b640834 | |
draganrakita | f1dc682168 | |
draganrakita | 0bb2f8f6b8 | |
rakita | d5c2a0fbe2 | |
rakita | 98563b0a45 | |
adria0.eth | d8ce175846 | |
rakita | fb9699d8e1 | |
rakita | dbf9a1cd98 | |
rakita | 6b4e56b214 | |
Jochen Müller | f40e198eb7 | |
rakita | bbecb0415e | |
rakita | 6d81fce451 | |
rakita | 65c5e6dfd3 | |
adria0.eth | 2e23ca353f | |
rakita | a831379ad8 | |
rakita | cfc6439f2e | |
François Garillot | 52d966ccaa | |
rakita | 59d891edf4 | |
draganrakita | f3bdc0da3c | |
Denis Granha | a55799d523 | |
draganrakita | 1d07c4c06b | |
rakita | ea25ffd79d | |
Adria Massanet | eb876cb2d7 | |
Adria Massanet | 814526a248 | |
Adria Massanet | d3ba83405c | |
Adria Massanet | c46fe330dc | |
draganrakita | 0e5d6944b7 | |
adria0.eth | b0a1e3da03 | |
rakita | 0706e5468d | |
rakita | f286597d10 | |
Giacomo | e2f665e9cf | |
draganrakita | eab41b49cf | |
draganrakita | 8d3e0582a8 | |
draganrakita | 705bc71593 | |
draganrakita | f723e288c3 | |
Justin Beaurone | a6bd3516e0 | |
draganrakita | 08e6cca3e5 | |
draganrakita | 8a9d14141a | |
draganrakita | 832fc444b6 | |
adria0.eth | 612a71ecb2 | |
Giacomo | 06fc61d7c5 | |
rakita | 837e8b8725 | |
rakita | ea3efd926e | |
rakita | 3f01b69084 | |
rakita | 647ff31942 | |
rakita | 56131b6d92 | |
rakita | 51d824fbdc | |
rakita | 1225ff2c5a | |
adria0.eth | cb91b7e828 | |
Adria Massanet | 233bab2ee7 | |
Lachezar Lechev | fed80cc075 | |
Giacomo | 26ab00b6c7 | |
Giacomo | 01e72efb80 | |
adria0.eth | 81ae80b7f1 | |
adria0.eth | 910bb78f0d | |
adria0.eth | 6078eeaed7 | |
rakita | 50a4d5fa57 | |
Adria Massanet | 410853e280 | |
Denis Granha | bf5830f766 | |
rakita | d811f6e3ce | |
adria0.eth | 9110b1d9e4 | |
varasev | cb0513a8b1 | |
adria0.eth | 84f675021c | |
rakita | 03bfb012a1 | |
Denis Granha | 16542bd355 | |
Giacomo | 24cff45334 |
|
@ -1,3 +1,3 @@
|
|||
[target.x86_64-pc-windows-msvc]
|
||||
# Link the C runtime statically ; https://github.com/openethereum/openethereum/issues/6643
|
||||
# Link the C runtime statically ; https://github.com/openethereum/parity-ethereum/issues/6643
|
||||
rustflags = ["-Ctarget-feature=+crt-static"]
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
name: Build and Test Suite on Windows
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- dev
|
||||
jobs:
|
||||
build-tests:
|
||||
name: Test and Build
|
||||
strategy:
|
||||
matrix:
|
||||
platform:
|
||||
- windows2019 # custom runner
|
||||
toolchain:
|
||||
- 1.52.1
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@main
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.toolchain }}
|
||||
profile: minimal
|
||||
override: true
|
||||
- name: Build tests
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
args: --locked --all --release --features "json-tests" --verbose --no-run
|
|
@ -15,7 +15,7 @@ jobs:
|
|||
- ubuntu-16.04
|
||||
- macos-latest
|
||||
toolchain:
|
||||
- stable
|
||||
- 1.52.1
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
|
@ -33,3 +33,8 @@ jobs:
|
|||
with:
|
||||
command: test
|
||||
args: --locked --all --release --features "json-tests" --verbose --no-run
|
||||
- name: Run tests for ${{ matrix.platform }}
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
args: --locked --all --release --features "json-tests" --verbose
|
||||
|
|
|
@ -20,7 +20,7 @@ jobs:
|
|||
- ubuntu-16.04
|
||||
- macos-latest
|
||||
toolchain:
|
||||
- stable
|
||||
- 1.52.1
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
|
|
|
@ -15,10 +15,10 @@ jobs:
|
|||
uses: actions/checkout@main
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install stable toolchain
|
||||
- name: Install 1.52.1 toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
toolchain: 1.52.1
|
||||
profile: minimal
|
||||
override: true
|
||||
- name: Run cargo check 1/3
|
||||
|
@ -30,12 +30,12 @@ jobs:
|
|||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
args: --locked --manifest-path util/io/Cargo.toml --no-default-features --verbose
|
||||
args: --locked --manifest-path crates/runtime/io/Cargo.toml --no-default-features --verbose
|
||||
- name: Run cargo check 3/3
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
args: --locked --manifest-path util/io/Cargo.toml --features "mio" --verbose
|
||||
args: --locked --manifest-path crates/runtime/io/Cargo.toml --features "mio" --verbose
|
||||
- name: Run cargo check evmbin
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
|
|
|
@ -16,7 +16,7 @@ jobs:
|
|||
- name: Install toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
toolchain: 1.52.1
|
||||
profile: minimal
|
||||
override: true
|
||||
- name: Deploy to docker hub
|
||||
|
|
|
@ -17,7 +17,7 @@ jobs:
|
|||
- name: Install toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
toolchain: 1.52.1
|
||||
profile: minimal
|
||||
override: true
|
||||
- name: Deploy to docker hub
|
||||
|
|
|
@ -17,7 +17,7 @@ jobs:
|
|||
- name: Install toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
toolchain: 1.52.1
|
||||
profile: minimal
|
||||
override: true
|
||||
- name: Deploy to docker hub
|
||||
|
|
|
@ -11,7 +11,7 @@ jobs:
|
|||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
toolchain: 1.52.1
|
||||
override: true
|
||||
- run: rustup component add rustfmt
|
||||
- uses: actions-rs/cargo@v1
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
[submodule "ethcore/res/ethereum/tests"]
|
||||
path = ethcore/res/ethereum/tests
|
||||
[submodule "crates/ethcore/res/json_tests"]
|
||||
path = crates/ethcore/res/json_tests
|
||||
url = https://github.com/ethereum/tests.git
|
||||
branch = develop
|
||||
[submodule "ethcore/res/wasm-tests"]
|
||||
path = ethcore/res/wasm-tests
|
||||
url = https://github.com/paritytech/wasm-tests
|
||||
|
|
243
CHANGELOG.md
243
CHANGELOG.md
|
@ -1,55 +1,208 @@
|
|||
## OpenEthereum v3.1.1-rc.1
|
||||
|
||||
Bug fixes:
|
||||
* Ancient target set. InvalidStateRoot bug (#69) (#149)
|
||||
* Update linked-hash-map to 0.5.3
|
||||
## OpenEthereum v3.3.3
|
||||
|
||||
Enhancements:
|
||||
* Add --ws-max-paxload (#155)
|
||||
* Add flag to disable storage output in openethereum-evm tool #97 (#115)
|
||||
* ethstore - remove unnecessary dir & tiny-keccak dependencies from the lib (#107)
|
||||
* Sync block verification (#74)
|
||||
* Add `wasmDisableTransition` spec option (#60)
|
||||
* EIP2929 with journaling + Yolov3 (#79)
|
||||
* EIP2565 impl (#82)
|
||||
* TypedTransaction (EIP-2718) and Optional access list (EIP-2930) (#135)
|
||||
* Implement eip-3607 (#593)
|
||||
|
||||
DevOps:
|
||||
* Add custom windows runner (#162)
|
||||
* Remove sscache (#138)
|
||||
* Fix deprecated set-env declaration (#106)
|
||||
Bug fixes:
|
||||
* Add type field for legacy transactions in RPC calls (#580)
|
||||
* Makes eth_mining to return False if not is not allowed to seal (#581)
|
||||
* Made nodes data concatenate as RLP sequences instead of bytes (#598)
|
||||
|
||||
## OpenEthereum v3.3.2
|
||||
|
||||
## OpenEthereum v3.1.0
|
||||
Enhancements:
|
||||
* London hardfork block: Sokol (24114400)
|
||||
|
||||
OpenEthereum 3.1.0 is a release based on v2.5.13 which is the last stable version known of the client that does not include any of the issues introduced in v2.7. It removes non core features like Ethereum Classic, Private Transactions, Light Client, Updater, IPFS and Swarm support, currently deprecated flags such as expanse, kotti, mordor testnets.
|
||||
Bug fixes:
|
||||
* Fix for maxPriorityFeePerGas overflow
|
||||
|
||||
Database migration utility currently in beta: https://github.com/openethereum/3.1-db-upgrade-tool
|
||||
## OpenEthereum v3.3.1
|
||||
|
||||
The full list of included changes from v2.5.13 to v3.1.0:
|
||||
Enhancements:
|
||||
* Add eth_maxPriorityFeePerGas implementation (#570)
|
||||
* Add a bootnode for Kovan
|
||||
|
||||
* Use ubuntu-16.04 for glibc compatibility (#11888) (#73)
|
||||
* Remove classic, kotti, mordor, expanse (#52)
|
||||
* Added bad block header hash for ropsten (#49)
|
||||
* Remove accounts bloom (#33)
|
||||
* Bump jsonrpc-- to v15
|
||||
* Implement eth/64, remove eth/62 (#46)
|
||||
* No snapshotting by default (#11814)
|
||||
* Update Ellaism chainspec
|
||||
* Prometheus, heavy memory calls removed (#27)
|
||||
Bug fixes:
|
||||
* Fix for modexp overflow in debug mode (#578)
|
||||
|
||||
## OpenEthereum v3.3.0
|
||||
|
||||
Enhancements:
|
||||
* Add `validateServiceTransactionsTransition` spec option to be able to enable additional checking of zero gas price transactions by block verifier
|
||||
|
||||
## OpenEthereum v3.3.0-rc.15
|
||||
|
||||
* Revert eip1559BaseFeeMinValue activation on xDai at London hardfork block
|
||||
|
||||
## OpenEthereum v3.3.0-rc.14
|
||||
|
||||
Enhancements:
|
||||
* Add eip1559BaseFeeMinValue and eip1559BaseFeeMinValueTransition spec options
|
||||
* Activate eip1559BaseFeeMinValue on xDai at London hardfork block (19040000), set it to 20 GWei
|
||||
* Activate eip1559BaseFeeMinValue on POA Core at block 24199500 (November 8, 2021), set it to 10 GWei
|
||||
* Delay difficulty bomb to June 2022 for Ethereum Mainnet (EIP-4345)
|
||||
|
||||
## OpenEthereum v3.3.0-rc.13
|
||||
|
||||
Enhancements:
|
||||
* London hardfork block: POA Core (24090200)
|
||||
|
||||
## OpenEthereum v3.3.0-rc.12
|
||||
|
||||
Enhancements:
|
||||
* London hardfork block: xDai (19040000)
|
||||
|
||||
## OpenEthereum v3.3.0-rc.11
|
||||
|
||||
Bug fixes:
|
||||
* Ignore GetNodeData requests only for non-AuRa chains
|
||||
|
||||
## OpenEthereum v3.3.0-rc.10
|
||||
|
||||
Enhancements:
|
||||
* Add eip1559FeeCollector and eip1559FeeCollectorTransition spec options
|
||||
|
||||
## OpenEthereum v3.3.0-rc.9
|
||||
|
||||
Bug fixes:
|
||||
* Add service transactions support for EIP-1559
|
||||
* Fix MinGasPrice config option for POSDAO and EIP-1559
|
||||
|
||||
Enhancements:
|
||||
* min_gas_price becomes min_effective_priority_fee
|
||||
* added version 4 for TxPermission contract
|
||||
|
||||
## OpenEthereum v3.3.0-rc.8
|
||||
|
||||
Bug fixes:
|
||||
* Ignore GetNodeData requests (#519)
|
||||
|
||||
## OpenEthereum v3.3.0-rc.7
|
||||
|
||||
Bug fixes:
|
||||
* GetPooledTransactions is sent in invalid form (wrong packet id)
|
||||
|
||||
## OpenEthereum v3.3.0-rc.6
|
||||
|
||||
Enhancements:
|
||||
* London hardfork block: kovan (26741100) (#502)
|
||||
|
||||
## OpenEthereum v3.3.0-rc.4
|
||||
|
||||
Enhancements:
|
||||
* London hardfork block: mainnet (12,965,000) (#475)
|
||||
* Support for eth/66 protocol version (#465)
|
||||
* Bump ethereum/tests to v9.0.3
|
||||
* Add eth_feeHistory
|
||||
|
||||
Bug fixes:
|
||||
* GetNodeData from eth63 is missing (#466)
|
||||
* Effective gas price not omitting (#477)
|
||||
* London support in openethereum-evm (#479)
|
||||
* gasPrice is required field for Transaction object (#481)
|
||||
|
||||
## OpenEthereum v3.3.0-rc.3
|
||||
|
||||
Bug fixes:
|
||||
* Add effective_gas_price to eth_getTransactionReceipt #445 (#450)
|
||||
* Update eth_gasPrice to support EIP-1559 #449 (#458)
|
||||
* eth_estimateGas returns "Requires higher than upper limit of X" after London Ropsten Hard Fork #459 (#460)
|
||||
|
||||
## OpenEthereum v3.3.0-rc.2
|
||||
|
||||
Enhancements:
|
||||
* EIP-1559: Fee market change for ETH 1.0 chain
|
||||
* EIP-3198: BASEFEE opcode
|
||||
* EIP-3529: Reduction in gas refunds
|
||||
* EIP-3541: Reject new contracts starting with the 0xEF byte
|
||||
* Delay difficulty bomb to December 2021 (EIP-3554)
|
||||
* London hardfork blocks: goerli (5,062,605), rinkeby (8,897,988), ropsten (10,499,401)
|
||||
* Add chainspecs for aleut and baikal
|
||||
* Bump ethereum/tests to v9.0.2
|
||||
|
||||
## OpenEthereum v3.2.6
|
||||
|
||||
Enhancement:
|
||||
* Berlin hardfork blocks: poacore (21,364,900), poasokol (21,050,600)
|
||||
|
||||
## OpenEthereum v3.2.5
|
||||
|
||||
Bug fixes:
|
||||
* Backport: Block sync stopped without any errors. #277 (#286)
|
||||
* Strict memory order (#306)
|
||||
|
||||
Enhancements:
|
||||
* Executable queue for ancient blocks inclusion (#208)
|
||||
* Backport AuRa commits for xdai (#330)
|
||||
* Add Nethermind to clients that accept service transactions (#324)
|
||||
* Implement the filter argument in parity_pendingTransactions (#295)
|
||||
* Ethereum-types and various libs upgraded (#315)
|
||||
* [evmbin] Omit storage output, now for std-json (#311)
|
||||
* Freeze pruning while creating snapshot (#205)
|
||||
* AuRa multi block reward (#290)
|
||||
* Improved metrics. DB read/write. prometheus prefix config (#240)
|
||||
* Send RLPx auth in EIP-8 format (#287)
|
||||
* rpc module reverted for RPC JSON api (#284)
|
||||
* Revert "Remove eth/63 protocol version (#252)"
|
||||
* Support for eth/65 protocol version (#366)
|
||||
* Berlin hardfork blocks: kovan (24,770,900), xdai (16,101,500)
|
||||
* Bump ethereum/tests to v8.0.3
|
||||
|
||||
devops:
|
||||
* Upgrade docker alpine to `v1.13.2`. for rust `v1.47`.
|
||||
* Send SIGTERM instead of SIGHUP to OE daemon (#317)
|
||||
|
||||
## OpenEthereum v3.2.4
|
||||
|
||||
* Fix for Typed transaction broadcast.
|
||||
|
||||
## OpenEthereum v3.2.3
|
||||
|
||||
* Hotfix for berlin consensus error.
|
||||
|
||||
## OpenEthereum v3.2.2-rc.1
|
||||
|
||||
Bug fixes:
|
||||
* Backport: Block sync stopped without any errors. #277 (#286)
|
||||
* Strict memory order (#306)
|
||||
|
||||
Enhancements:
|
||||
* Executable queue for ancient blocks inclusion (#208)
|
||||
* Backport AuRa commits for xdai (#330)
|
||||
* Add Nethermind to clients that accept service transactions (#324)
|
||||
* Implement the filter argument in parity_pendingTransactions (#295)
|
||||
* Ethereum-types and various libs upgraded (#315)
|
||||
* Bump ethereum/tests to v8.0.2
|
||||
* [evmbin] Omit storage output, now for std-json (#311)
|
||||
* Freeze pruning while creating snapshot (#205)
|
||||
* AuRa multi block reward (#290)
|
||||
* Improved metrics. DB read/write. prometheus prefix config (#240)
|
||||
* Send RLPx auth in EIP-8 format (#287)
|
||||
* rpc module reverted for RPC JSON api (#284)
|
||||
* Revert "Remove eth/63 protocol version (#252)"
|
||||
|
||||
devops:
|
||||
* Upgrade docker alpine to `v1.13.2`. for rust `v1.47`.
|
||||
* Send SIGTERM instead of SIGHUP to OE daemon (#317)
|
||||
|
||||
## OpenEthereum v3.2.1
|
||||
|
||||
Hot fix issue, related to initial sync:
|
||||
* Initial sync gets stuck. (#318)
|
||||
|
||||
## OpenEthereum v3.2.0
|
||||
|
||||
Bug fixes:
|
||||
* Update EWF's chains with Istanbul transition block numbers (#11482) (#254)
|
||||
* fix Supplied instant is later than self (#169)
|
||||
* ethcore/snapshot: fix double-lock in Service::feed_chunk (#289)
|
||||
|
||||
Enhancements:
|
||||
* Berlin hardfork blocks: mainnet (12,244,000), goerli (4,460,644), rinkeby (8,290,928) and ropsten (9,812,189)
|
||||
* yolo3x spec (#241)
|
||||
* EIP-2930 RPC support
|
||||
* Remove eth/63 protocol version (#252)
|
||||
* Snapshot manifest block added to prometheus (#232)
|
||||
* EIP-1898: Allow default block parameter to be blockHash
|
||||
* Change ProtocolId to U64
|
||||
* Update ethereum/tests
|
||||
* Implement JSON test suite (#11801)
|
||||
* Fix issues during block sync (#11265)
|
||||
* Fix race same block (#11400)
|
||||
* EIP-2537: Precompile for BLS12-381 curve operations (#11707)
|
||||
* Remove private transactions
|
||||
* Remove GetNodeData
|
||||
* Remove IPFS integration (#11532)
|
||||
* Remove updater
|
||||
* Remove light client
|
||||
* Remove C and Java bindings (#11346)
|
||||
* Remove whisper (#10855)
|
||||
* EIP-2315: Simple Subroutines for the EVM (#11629)
|
||||
* Remove deprecated flags (removal of --geth flag)
|
||||
* Remove support for hardware wallets (#10678)
|
||||
* Update bootnodes
|
||||
|
|
File diff suppressed because it is too large
Load Diff
93
Cargo.toml
93
Cargo.toml
|
@ -2,7 +2,7 @@
|
|||
description = "OpenEthereum"
|
||||
name = "openethereum"
|
||||
# NOTE Make sure to update util/version/Cargo.toml as well
|
||||
version = "3.1.1-rc.1"
|
||||
version = "3.3.3"
|
||||
license = "GPL-3.0"
|
||||
authors = [
|
||||
"OpenEthereum developers",
|
||||
|
@ -10,7 +10,7 @@ authors = [
|
|||
]
|
||||
|
||||
[dependencies]
|
||||
blooms-db = { path = "util/blooms-db" }
|
||||
blooms-db = { path = "crates/db/blooms-db" }
|
||||
log = "0.4"
|
||||
rustc-hex = "1.0"
|
||||
docopt = "1.0"
|
||||
|
@ -22,7 +22,7 @@ number_prefix = "0.2"
|
|||
rpassword = "1.0"
|
||||
semver = "0.9"
|
||||
ansi_term = "0.10"
|
||||
parking_lot = "0.7"
|
||||
parking_lot = "0.11.1"
|
||||
regex = "1.0"
|
||||
atty = "0.2.8"
|
||||
toml = "0.4"
|
||||
|
@ -35,44 +35,43 @@ fdlimit = "0.1"
|
|||
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
|
||||
jsonrpc-core = "15.0.0"
|
||||
parity-bytes = "0.1"
|
||||
common-types = { path = "ethcore/types" }
|
||||
ethcore = { path = "ethcore", features = ["parity"] }
|
||||
ethcore-accounts = { path = "accounts", optional = true }
|
||||
ethcore-blockchain = { path = "ethcore/blockchain" }
|
||||
ethcore-call-contract = { path = "ethcore/call-contract"}
|
||||
ethcore-db = { path = "ethcore/db" }
|
||||
ethcore-io = { path = "util/io" }
|
||||
ethcore-logger = { path = "parity/logger" }
|
||||
ethcore-miner = { path = "miner" }
|
||||
ethcore-network = { path = "util/network" }
|
||||
ethcore-service = { path = "ethcore/service" }
|
||||
ethcore-sync = { path = "ethcore/sync" }
|
||||
ethereum-types = "0.4"
|
||||
ethkey = { path = "accounts/ethkey" }
|
||||
ethstore = { path = "accounts/ethstore" }
|
||||
fetch = { path = "util/fetch" }
|
||||
node-filter = { path = "ethcore/node-filter" }
|
||||
rlp = { version = "0.3.0", features = ["ethereum"] }
|
||||
cli-signer= { path = "cli-signer" }
|
||||
common-types = { path = "crates/ethcore/types" }
|
||||
ethcore = { path = "crates/ethcore", features = ["parity"] }
|
||||
ethcore-accounts = { path = "crates/accounts", optional = true }
|
||||
ethcore-blockchain = { path = "crates/ethcore/blockchain" }
|
||||
ethcore-call-contract = { path = "crates/vm/call-contract"}
|
||||
ethcore-db = { path = "crates/db/db" }
|
||||
ethcore-io = { path = "crates/runtime/io" }
|
||||
ethcore-logger = { path = "bin/oe/logger" }
|
||||
ethcore-miner = { path = "crates/concensus/miner" }
|
||||
ethcore-network = { path = "crates/net/network" }
|
||||
ethcore-service = { path = "crates/ethcore/service" }
|
||||
ethcore-sync = { path = "crates/ethcore/sync" }
|
||||
ethereum-types = "0.9.2"
|
||||
ethkey = { path = "crates/accounts/ethkey" }
|
||||
ethstore = { path = "crates/accounts/ethstore" }
|
||||
fetch = { path = "crates/net/fetch" }
|
||||
node-filter = { path = "crates/net/node-filter" }
|
||||
parity-crypto = { version = "0.6.2", features = [ "publickey" ] }
|
||||
rlp = { version = "0.4.6" }
|
||||
cli-signer= { path = "crates/util/cli-signer" }
|
||||
parity-daemonize = "0.3"
|
||||
parity-local-store = { path = "miner/local-store" }
|
||||
parity-runtime = { path = "util/runtime" }
|
||||
parity-rpc = { path = "rpc" }
|
||||
parity-version = { path = "util/version" }
|
||||
parity-local-store = { path = "crates/concensus/miner/local-store" }
|
||||
parity-runtime = { path = "crates/runtime/runtime" }
|
||||
parity-rpc = { path = "crates/rpc" }
|
||||
parity-version = { path = "crates/util/version" }
|
||||
parity-path = "0.1"
|
||||
dir = { path = "util/dir" }
|
||||
panic_hook = { path = "util/panic-hook" }
|
||||
keccak-hash = "0.1"
|
||||
migration-rocksdb = { path = "util/migration-rocksdb" }
|
||||
dir = { path = "crates/util/dir" }
|
||||
panic_hook = { path = "crates/util/panic-hook" }
|
||||
keccak-hash = "0.5.0"
|
||||
migration-rocksdb = { path = "crates/db/migration-rocksdb" }
|
||||
kvdb = "0.1"
|
||||
kvdb-rocksdb = "0.1.3"
|
||||
journaldb = { path = "util/journaldb" }
|
||||
stats = { path = "util/stats" }
|
||||
journaldb = { path = "crates/db/journaldb" }
|
||||
stats = { path = "crates/util/stats" }
|
||||
prometheus = "0.9.0"
|
||||
|
||||
ethcore-secretstore = { path = "secret-store", optional = true }
|
||||
|
||||
registrar = { path = "util/registrar" }
|
||||
# ethcore-secretstore = { path = "crates/util/secret-store", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
rustc_version = "0.2"
|
||||
|
@ -81,7 +80,7 @@ rustc_version = "0.2"
|
|||
pretty_assertions = "0.1"
|
||||
ipnetwork = "0.12.6"
|
||||
tempdir = "0.3"
|
||||
fake-fetch = { path = "util/fake-fetch" }
|
||||
fake-fetch = { path = "crates/net/fake-fetch" }
|
||||
lazy_static = "1.2.0"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
|
@ -97,7 +96,6 @@ test-heavy = ["ethcore/test-heavy"]
|
|||
evm-debug = ["ethcore/evm-debug"]
|
||||
evm-debug-tests = ["ethcore/evm-debug-tests"]
|
||||
slow-blocks = ["ethcore/slow-blocks"]
|
||||
secretstore = ["ethcore-secretstore", "ethcore-secretstore/accounts"]
|
||||
final = ["parity-version/final"]
|
||||
deadlock_detection = ["parking_lot/deadlock_detection"]
|
||||
# to create a memory profile (requires nightly rust), use e.g.
|
||||
|
@ -109,10 +107,10 @@ deadlock_detection = ["parking_lot/deadlock_detection"]
|
|||
memory_profiling = []
|
||||
|
||||
[lib]
|
||||
path = "parity/lib.rs"
|
||||
path = "bin/oe/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
path = "parity/main.rs"
|
||||
path = "bin/oe/main.rs"
|
||||
name = "openethereum"
|
||||
|
||||
[profile.test]
|
||||
|
@ -128,17 +126,8 @@ lto = true
|
|||
# in the dependency tree in any other way
|
||||
# (i.e. pretty much only standalone CLI tools)
|
||||
members = [
|
||||
"accounts/ethkey/cli",
|
||||
"accounts/ethstore/cli",
|
||||
"chainspec",
|
||||
"ethcore/wasm/run",
|
||||
"evmbin",
|
||||
"util/triehash-ethereum",
|
||||
"util/keccak-hasher",
|
||||
"util/patricia-trie-ethereum",
|
||||
"util/fastmap",
|
||||
"util/time-utils"
|
||||
"bin/ethkey",
|
||||
"bin/ethstore",
|
||||
"bin/evmbin",
|
||||
"bin/chainspec"
|
||||
]
|
||||
|
||||
[patch.crates-io]
|
||||
heapsize = { git = "https://github.com/cheme/heapsize.git", branch = "ec-macfix" }
|
||||
|
|
|
@ -297,9 +297,9 @@ Caching, Importing Blocks, and Block Information
|
|||
|
||||
In addition to the OpenEthereum client, there are additional tools in this repository available:
|
||||
|
||||
- [evmbin](./evmbin) - OpenEthereum EVM Implementation.
|
||||
- [ethstore](./accounts/ethstore) - OpenEthereum Key Management.
|
||||
- [ethkey](./accounts/ethkey) - OpenEthereum Keys Generator.
|
||||
- [evmbin](./bin/evmbin) - OpenEthereum EVM Implementation.
|
||||
- [ethstore](./crates/accounts/ethstore) - OpenEthereum Key Management.
|
||||
- [ethkey](./crates/accounts/ethkey) - OpenEthereum Keys Generator.
|
||||
|
||||
The following tools are available in a separate repository:
|
||||
- [ethabi](https://github.com/openethereum/ethabi) - OpenEthereum Encoding of Function Calls. [Docs here](https://crates.io/crates/ethabi)
|
||||
|
|
|
@ -1,202 +0,0 @@
|
|||
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of OpenEthereum.
|
||||
|
||||
// OpenEthereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// OpenEthereum is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#![allow(deprecated)]
|
||||
|
||||
use parity_crypto::error::SymmError;
|
||||
use secp256k1;
|
||||
use std::io;
|
||||
|
||||
quick_error! {
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Secp(e: secp256k1::Error) {
|
||||
display("secp256k1 error: {}", e)
|
||||
cause(e)
|
||||
from()
|
||||
}
|
||||
Io(e: io::Error) {
|
||||
display("i/o error: {}", e)
|
||||
cause(e)
|
||||
from()
|
||||
}
|
||||
InvalidMessage {
|
||||
display("invalid message")
|
||||
}
|
||||
Symm(e: SymmError) {
|
||||
cause(e)
|
||||
from()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// ECDH functions
|
||||
pub mod ecdh {
|
||||
use super::Error;
|
||||
use secp256k1::{self, ecdh, key};
|
||||
use Public;
|
||||
use Secret;
|
||||
use SECP256K1;
|
||||
|
||||
/// Agree on a shared secret
|
||||
pub fn agree(secret: &Secret, public: &Public) -> Result<Secret, Error> {
|
||||
let context = &SECP256K1;
|
||||
let pdata = {
|
||||
let mut temp = [4u8; 65];
|
||||
(&mut temp[1..65]).copy_from_slice(&public[0..64]);
|
||||
temp
|
||||
};
|
||||
|
||||
let publ = key::PublicKey::from_slice(context, &pdata)?;
|
||||
let sec = key::SecretKey::from_slice(context, &secret)?;
|
||||
let shared = ecdh::SharedSecret::new_raw(context, &publ, &sec);
|
||||
|
||||
Secret::from_unsafe_slice(&shared[0..32])
|
||||
.map_err(|_| Error::Secp(secp256k1::Error::InvalidSecretKey))
|
||||
}
|
||||
}
|
||||
|
||||
/// ECIES function
|
||||
pub mod ecies {
|
||||
use super::{ecdh, Error};
|
||||
use ethereum_types::H128;
|
||||
use parity_crypto::{aes, digest, hmac, is_equal};
|
||||
use Generator;
|
||||
use Public;
|
||||
use Random;
|
||||
use Secret;
|
||||
|
||||
/// Encrypt a message with a public key, writing an HMAC covering both
|
||||
/// the plaintext and authenticated data.
|
||||
///
|
||||
/// Authenticated data may be empty.
|
||||
pub fn encrypt(public: &Public, auth_data: &[u8], plain: &[u8]) -> Result<Vec<u8>, Error> {
|
||||
let r = Random.generate()?;
|
||||
let z = ecdh::agree(r.secret(), public)?;
|
||||
let mut key = [0u8; 32];
|
||||
kdf(&z, &[0u8; 0], &mut key);
|
||||
|
||||
let ekey = &key[0..16];
|
||||
let mkey = hmac::SigKey::sha256(&digest::sha256(&key[16..32]));
|
||||
|
||||
let mut msg = vec![0u8; 1 + 64 + 16 + plain.len() + 32];
|
||||
msg[0] = 0x04u8;
|
||||
{
|
||||
let msgd = &mut msg[1..];
|
||||
msgd[0..64].copy_from_slice(r.public());
|
||||
let iv = H128::random();
|
||||
msgd[64..80].copy_from_slice(&iv);
|
||||
{
|
||||
let cipher = &mut msgd[(64 + 16)..(64 + 16 + plain.len())];
|
||||
aes::encrypt_128_ctr(ekey, &iv, plain, cipher)?;
|
||||
}
|
||||
let mut hmac = hmac::Signer::with(&mkey);
|
||||
{
|
||||
let cipher_iv = &msgd[64..(64 + 16 + plain.len())];
|
||||
hmac.update(cipher_iv);
|
||||
}
|
||||
hmac.update(auth_data);
|
||||
let sig = hmac.sign();
|
||||
msgd[(64 + 16 + plain.len())..].copy_from_slice(&sig);
|
||||
}
|
||||
Ok(msg)
|
||||
}
|
||||
|
||||
/// Decrypt a message with a secret key, checking HMAC for ciphertext
|
||||
/// and authenticated data validity.
|
||||
pub fn decrypt(secret: &Secret, auth_data: &[u8], encrypted: &[u8]) -> Result<Vec<u8>, Error> {
|
||||
let meta_len = 1 + 64 + 16 + 32;
|
||||
if encrypted.len() < meta_len || encrypted[0] < 2 || encrypted[0] > 4 {
|
||||
return Err(Error::InvalidMessage); //invalid message: publickey
|
||||
}
|
||||
|
||||
let e = &encrypted[1..];
|
||||
let p = Public::from_slice(&e[0..64]);
|
||||
let z = ecdh::agree(secret, &p)?;
|
||||
let mut key = [0u8; 32];
|
||||
kdf(&z, &[0u8; 0], &mut key);
|
||||
|
||||
let ekey = &key[0..16];
|
||||
let mkey = hmac::SigKey::sha256(&digest::sha256(&key[16..32]));
|
||||
|
||||
let clen = encrypted.len() - meta_len;
|
||||
let cipher_with_iv = &e[64..(64 + 16 + clen)];
|
||||
let cipher_iv = &cipher_with_iv[0..16];
|
||||
let cipher_no_iv = &cipher_with_iv[16..];
|
||||
let msg_mac = &e[(64 + 16 + clen)..];
|
||||
|
||||
// Verify tag
|
||||
let mut hmac = hmac::Signer::with(&mkey);
|
||||
hmac.update(cipher_with_iv);
|
||||
hmac.update(auth_data);
|
||||
let mac = hmac.sign();
|
||||
|
||||
if !is_equal(&mac.as_ref()[..], msg_mac) {
|
||||
return Err(Error::InvalidMessage);
|
||||
}
|
||||
|
||||
let mut msg = vec![0u8; clen];
|
||||
aes::decrypt_128_ctr(ekey, cipher_iv, cipher_no_iv, &mut msg[..])?;
|
||||
Ok(msg)
|
||||
}
|
||||
|
||||
fn kdf(secret: &Secret, s1: &[u8], dest: &mut [u8]) {
|
||||
// SEC/ISO/Shoup specify counter size SHOULD be equivalent
|
||||
// to size of hash output, however, it also notes that
|
||||
// the 4 bytes is okay. NIST specifies 4 bytes.
|
||||
let mut ctr = 1u32;
|
||||
let mut written = 0usize;
|
||||
while written < dest.len() {
|
||||
let mut hasher = digest::Hasher::sha256();
|
||||
let ctrs = [
|
||||
(ctr >> 24) as u8,
|
||||
(ctr >> 16) as u8,
|
||||
(ctr >> 8) as u8,
|
||||
ctr as u8,
|
||||
];
|
||||
hasher.update(&ctrs);
|
||||
hasher.update(secret);
|
||||
hasher.update(s1);
|
||||
let d = hasher.finish();
|
||||
&mut dest[written..(written + 32)].copy_from_slice(&d);
|
||||
written += 32;
|
||||
ctr += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ecies;
|
||||
use Generator;
|
||||
use Random;
|
||||
|
||||
#[test]
|
||||
fn ecies_shared() {
|
||||
let kp = Random.generate().unwrap();
|
||||
let message = b"So many books, so little time";
|
||||
|
||||
let shared = b"shared";
|
||||
let wrong_shared = b"incorrect";
|
||||
let encrypted = ecies::encrypt(kp.public(), shared, message).unwrap();
|
||||
assert!(encrypted[..] != message[..]);
|
||||
assert_eq!(encrypted[0], 0x04);
|
||||
|
||||
assert!(ecies::decrypt(kp.secret(), wrong_shared, &encrypted).is_err());
|
||||
let decrypted = ecies::decrypt(kp.secret(), shared, &encrypted).unwrap();
|
||||
assert_eq!(decrypted[..message.len()], message[..]);
|
||||
}
|
||||
}
|
|
@ -1,589 +0,0 @@
|
|||
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of OpenEthereum.
|
||||
|
||||
// OpenEthereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// OpenEthereum is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Extended keys
|
||||
|
||||
pub use self::derivation::Error as DerivationError;
|
||||
use ethereum_types::H256;
|
||||
use secret::Secret;
|
||||
use Public;
|
||||
|
||||
/// Represents label that can be stored as a part of key derivation
|
||||
pub trait Label {
|
||||
/// Length of the data that label occupies
|
||||
fn len() -> usize;
|
||||
|
||||
/// Store label data to the key derivation sequence
|
||||
/// Must not use more than `len()` bytes from slice
|
||||
fn store(&self, target: &mut [u8]);
|
||||
}
|
||||
|
||||
impl Label for u32 {
|
||||
fn len() -> usize {
|
||||
4
|
||||
}
|
||||
|
||||
fn store(&self, target: &mut [u8]) {
|
||||
let bytes = self.to_be_bytes();
|
||||
target[0..4].copy_from_slice(&bytes);
|
||||
}
|
||||
}
|
||||
|
||||
/// Key derivation over generic label `T`
|
||||
pub enum Derivation<T: Label> {
|
||||
/// Soft key derivation (allow proof of parent)
|
||||
Soft(T),
|
||||
/// Hard key derivation (does not allow proof of parent)
|
||||
Hard(T),
|
||||
}
|
||||
|
||||
impl From<u32> for Derivation<u32> {
|
||||
fn from(index: u32) -> Self {
|
||||
if index < (2 << 30) {
|
||||
Derivation::Soft(index)
|
||||
} else {
|
||||
Derivation::Hard(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Label for H256 {
|
||||
fn len() -> usize {
|
||||
32
|
||||
}
|
||||
|
||||
fn store(&self, target: &mut [u8]) {
|
||||
self.copy_to(&mut target[0..32]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Extended secret key, allows deterministic derivation of subsequent keys.
|
||||
pub struct ExtendedSecret {
|
||||
secret: Secret,
|
||||
chain_code: H256,
|
||||
}
|
||||
|
||||
impl ExtendedSecret {
|
||||
/// New extended key from given secret and chain code.
|
||||
pub fn with_code(secret: Secret, chain_code: H256) -> ExtendedSecret {
|
||||
ExtendedSecret {
|
||||
secret: secret,
|
||||
chain_code: chain_code,
|
||||
}
|
||||
}
|
||||
|
||||
/// New extended key from given secret with the random chain code.
|
||||
pub fn new_random(secret: Secret) -> ExtendedSecret {
|
||||
ExtendedSecret::with_code(secret, H256::random())
|
||||
}
|
||||
|
||||
/// New extended key from given secret.
|
||||
/// Chain code will be derived from the secret itself (in a deterministic way).
|
||||
pub fn new(secret: Secret) -> ExtendedSecret {
|
||||
let chain_code = derivation::chain_code(*secret);
|
||||
ExtendedSecret::with_code(secret, chain_code)
|
||||
}
|
||||
|
||||
/// Derive new private key
|
||||
pub fn derive<T>(&self, index: Derivation<T>) -> ExtendedSecret
|
||||
where
|
||||
T: Label,
|
||||
{
|
||||
let (derived_key, next_chain_code) =
|
||||
derivation::private(*self.secret, self.chain_code, index);
|
||||
|
||||
let derived_secret = Secret::from(derived_key.0);
|
||||
|
||||
ExtendedSecret::with_code(derived_secret, next_chain_code)
|
||||
}
|
||||
|
||||
/// Private key component of the extended key.
|
||||
pub fn as_raw(&self) -> &Secret {
|
||||
&self.secret
|
||||
}
|
||||
}
|
||||
|
||||
/// Extended public key, allows deterministic derivation of subsequent keys.
|
||||
pub struct ExtendedPublic {
|
||||
public: Public,
|
||||
chain_code: H256,
|
||||
}
|
||||
|
||||
impl ExtendedPublic {
|
||||
/// New extended public key from known parent and chain code
|
||||
pub fn new(public: Public, chain_code: H256) -> Self {
|
||||
ExtendedPublic {
|
||||
public: public,
|
||||
chain_code: chain_code,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create new extended public key from known secret
|
||||
pub fn from_secret(secret: &ExtendedSecret) -> Result<Self, DerivationError> {
|
||||
Ok(ExtendedPublic::new(
|
||||
derivation::point(**secret.as_raw())?,
|
||||
secret.chain_code.clone(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Derive new public key
|
||||
/// Operation is defined only for index belongs [0..2^31)
|
||||
pub fn derive<T>(&self, index: Derivation<T>) -> Result<Self, DerivationError>
|
||||
where
|
||||
T: Label,
|
||||
{
|
||||
let (derived_key, next_chain_code) =
|
||||
derivation::public(self.public, self.chain_code, index)?;
|
||||
Ok(ExtendedPublic::new(derived_key, next_chain_code))
|
||||
}
|
||||
|
||||
pub fn public(&self) -> &Public {
|
||||
&self.public
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ExtendedKeyPair {
|
||||
secret: ExtendedSecret,
|
||||
public: ExtendedPublic,
|
||||
}
|
||||
|
||||
impl ExtendedKeyPair {
|
||||
pub fn new(secret: Secret) -> Self {
|
||||
let extended_secret = ExtendedSecret::new(secret);
|
||||
let extended_public = ExtendedPublic::from_secret(&extended_secret)
|
||||
.expect("Valid `Secret` always produces valid public; qed");
|
||||
ExtendedKeyPair {
|
||||
secret: extended_secret,
|
||||
public: extended_public,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_code(secret: Secret, public: Public, chain_code: H256) -> Self {
|
||||
ExtendedKeyPair {
|
||||
secret: ExtendedSecret::with_code(secret, chain_code.clone()),
|
||||
public: ExtendedPublic::new(public, chain_code),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_secret(secret: Secret, chain_code: H256) -> Self {
|
||||
let extended_secret = ExtendedSecret::with_code(secret, chain_code);
|
||||
let extended_public = ExtendedPublic::from_secret(&extended_secret)
|
||||
.expect("Valid `Secret` always produces valid public; qed");
|
||||
ExtendedKeyPair {
|
||||
secret: extended_secret,
|
||||
public: extended_public,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_seed(seed: &[u8]) -> Result<ExtendedKeyPair, DerivationError> {
|
||||
let (master_key, chain_code) = derivation::seed_pair(seed);
|
||||
Ok(ExtendedKeyPair::with_secret(
|
||||
Secret::from_unsafe_slice(&*master_key).map_err(|_| DerivationError::InvalidSeed)?,
|
||||
chain_code,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn secret(&self) -> &ExtendedSecret {
|
||||
&self.secret
|
||||
}
|
||||
|
||||
pub fn public(&self) -> &ExtendedPublic {
|
||||
&self.public
|
||||
}
|
||||
|
||||
pub fn derive<T>(&self, index: Derivation<T>) -> Result<Self, DerivationError>
|
||||
where
|
||||
T: Label,
|
||||
{
|
||||
let derived = self.secret.derive(index);
|
||||
|
||||
Ok(ExtendedKeyPair {
|
||||
public: ExtendedPublic::from_secret(&derived)?,
|
||||
secret: derived,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Derivation functions for private and public keys
|
||||
// Work is based on BIP0032
|
||||
// https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
|
||||
mod derivation {
|
||||
use super::{Derivation, Label};
|
||||
use ethereum_types::{H256, H512, U256, U512};
|
||||
use keccak;
|
||||
use math::curve_order;
|
||||
use parity_crypto::hmac;
|
||||
use secp256k1::key::{PublicKey, SecretKey};
|
||||
use SECP256K1;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
InvalidHardenedUse,
|
||||
InvalidPoint,
|
||||
MissingIndex,
|
||||
InvalidSeed,
|
||||
}
|
||||
|
||||
// Deterministic derivation of the key using secp256k1 elliptic curve.
|
||||
// Derivation can be either hardened or not.
|
||||
// For hardened derivation, pass u32 index at least 2^31 or custom Derivation::Hard(T) enum
|
||||
//
|
||||
// Can panic if passed `private_key` is not a valid secp256k1 private key
|
||||
// (outside of (0..curve_order()]) field
|
||||
pub fn private<T>(private_key: H256, chain_code: H256, index: Derivation<T>) -> (H256, H256)
|
||||
where
|
||||
T: Label,
|
||||
{
|
||||
match index {
|
||||
Derivation::Soft(index) => private_soft(private_key, chain_code, index),
|
||||
Derivation::Hard(index) => private_hard(private_key, chain_code, index),
|
||||
}
|
||||
}
|
||||
|
||||
fn hmac_pair(data: &[u8], private_key: H256, chain_code: H256) -> (H256, H256) {
|
||||
let private: U256 = private_key.into();
|
||||
|
||||
// produces 512-bit derived hmac (I)
|
||||
let skey = hmac::SigKey::sha512(&*chain_code);
|
||||
let i_512 = hmac::sign(&skey, &data[..]);
|
||||
|
||||
// left most 256 bits are later added to original private key
|
||||
let hmac_key: U256 = H256::from_slice(&i_512[0..32]).into();
|
||||
// right most 256 bits are new chain code for later derivations
|
||||
let next_chain_code = H256::from(&i_512[32..64]);
|
||||
|
||||
let child_key = private_add(hmac_key, private).into();
|
||||
(child_key, next_chain_code)
|
||||
}
|
||||
|
||||
// Can panic if passed `private_key` is not a valid secp256k1 private key
|
||||
// (outside of (0..curve_order()]) field
|
||||
fn private_soft<T>(private_key: H256, chain_code: H256, index: T) -> (H256, H256)
|
||||
where
|
||||
T: Label,
|
||||
{
|
||||
let mut data = vec![0u8; 33 + T::len()];
|
||||
|
||||
let sec_private = SecretKey::from_slice(&SECP256K1, &*private_key)
|
||||
.expect("Caller should provide valid private key");
|
||||
let sec_public = PublicKey::from_secret_key(&SECP256K1, &sec_private)
|
||||
.expect("Caller should provide valid private key");
|
||||
let public_serialized = sec_public.serialize_vec(&SECP256K1, true);
|
||||
|
||||
// curve point (compressed public key) -- index
|
||||
// 0.33 -- 33..end
|
||||
data[0..33].copy_from_slice(&public_serialized);
|
||||
index.store(&mut data[33..]);
|
||||
|
||||
hmac_pair(&data, private_key, chain_code)
|
||||
}
|
||||
|
||||
// Deterministic derivation of the key using secp256k1 elliptic curve
|
||||
// This is hardened derivation and does not allow to associate
|
||||
// corresponding public keys of the original and derived private keys
|
||||
fn private_hard<T>(private_key: H256, chain_code: H256, index: T) -> (H256, H256)
|
||||
where
|
||||
T: Label,
|
||||
{
|
||||
let mut data: Vec<u8> = vec![0u8; 33 + T::len()];
|
||||
let private: U256 = private_key.into();
|
||||
|
||||
// 0x00 (padding) -- private_key -- index
|
||||
// 0 -- 1..33 -- 33..end
|
||||
private.to_big_endian(&mut data[1..33]);
|
||||
index.store(&mut data[33..(33 + T::len())]);
|
||||
|
||||
hmac_pair(&data, private_key, chain_code)
|
||||
}
|
||||
|
||||
fn private_add(k1: U256, k2: U256) -> U256 {
|
||||
let sum = U512::from(k1) + U512::from(k2);
|
||||
modulo(sum, curve_order())
|
||||
}
|
||||
|
||||
// todo: surely can be optimized
|
||||
fn modulo(u1: U512, u2: U256) -> U256 {
|
||||
let dv = u1 / U512::from(u2);
|
||||
let md = u1 - (dv * U512::from(u2));
|
||||
md.into()
|
||||
}
|
||||
|
||||
pub fn public<T>(
|
||||
public_key: H512,
|
||||
chain_code: H256,
|
||||
derivation: Derivation<T>,
|
||||
) -> Result<(H512, H256), Error>
|
||||
where
|
||||
T: Label,
|
||||
{
|
||||
let index = match derivation {
|
||||
Derivation::Soft(index) => index,
|
||||
Derivation::Hard(_) => {
|
||||
return Err(Error::InvalidHardenedUse);
|
||||
}
|
||||
};
|
||||
|
||||
let mut public_sec_raw = [0u8; 65];
|
||||
public_sec_raw[0] = 4;
|
||||
public_sec_raw[1..65].copy_from_slice(&*public_key);
|
||||
let public_sec =
|
||||
PublicKey::from_slice(&SECP256K1, &public_sec_raw).map_err(|_| Error::InvalidPoint)?;
|
||||
let public_serialized = public_sec.serialize_vec(&SECP256K1, true);
|
||||
|
||||
let mut data = vec![0u8; 33 + T::len()];
|
||||
// curve point (compressed public key) -- index
|
||||
// 0.33 -- 33..end
|
||||
data[0..33].copy_from_slice(&public_serialized);
|
||||
index.store(&mut data[33..(33 + T::len())]);
|
||||
|
||||
// HMAC512SHA produces [derived private(256); new chain code(256)]
|
||||
let skey = hmac::SigKey::sha512(&*chain_code);
|
||||
let i_512 = hmac::sign(&skey, &data[..]);
|
||||
|
||||
let new_private = H256::from(&i_512[0..32]);
|
||||
let new_chain_code = H256::from(&i_512[32..64]);
|
||||
|
||||
// Generated private key can (extremely rarely) be out of secp256k1 key field
|
||||
if curve_order() <= new_private.clone().into() {
|
||||
return Err(Error::MissingIndex);
|
||||
}
|
||||
let new_private_sec = SecretKey::from_slice(&SECP256K1, &*new_private)
|
||||
.expect("Private key belongs to the field [0..CURVE_ORDER) (checked above); So initializing can never fail; qed");
|
||||
let mut new_public = PublicKey::from_secret_key(&SECP256K1, &new_private_sec)
|
||||
.expect("Valid private key produces valid public key");
|
||||
|
||||
// Adding two points on the elliptic curves (combining two public keys)
|
||||
new_public
|
||||
.add_assign(&SECP256K1, &public_sec)
|
||||
.expect("Addition of two valid points produce valid point");
|
||||
|
||||
let serialized = new_public.serialize_vec(&SECP256K1, false);
|
||||
|
||||
Ok((H512::from(&serialized[1..65]), new_chain_code))
|
||||
}
|
||||
|
||||
fn sha3(slc: &[u8]) -> H256 {
|
||||
keccak::Keccak256::keccak256(slc).into()
|
||||
}
|
||||
|
||||
pub fn chain_code(secret: H256) -> H256 {
|
||||
// 10,000 rounds of sha3
|
||||
let mut running_sha3 = sha3(&*secret);
|
||||
for _ in 0..99999 {
|
||||
running_sha3 = sha3(&*running_sha3);
|
||||
}
|
||||
running_sha3
|
||||
}
|
||||
|
||||
pub fn point(secret: H256) -> Result<H512, Error> {
|
||||
let sec = SecretKey::from_slice(&SECP256K1, &*secret).map_err(|_| Error::InvalidPoint)?;
|
||||
let public_sec =
|
||||
PublicKey::from_secret_key(&SECP256K1, &sec).map_err(|_| Error::InvalidPoint)?;
|
||||
let serialized = public_sec.serialize_vec(&SECP256K1, false);
|
||||
Ok(H512::from(&serialized[1..65]))
|
||||
}
|
||||
|
||||
pub fn seed_pair(seed: &[u8]) -> (H256, H256) {
|
||||
let skey = hmac::SigKey::sha512(b"Bitcoin seed");
|
||||
let i_512 = hmac::sign(&skey, seed);
|
||||
|
||||
let master_key = H256::from_slice(&i_512[0..32]);
|
||||
let chain_code = H256::from_slice(&i_512[32..64]);
|
||||
|
||||
(master_key, chain_code)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{derivation, Derivation, ExtendedKeyPair, ExtendedPublic, ExtendedSecret};
|
||||
use ethereum_types::{H128, H256};
|
||||
use secret::Secret;
|
||||
use std::str::FromStr;
|
||||
|
||||
fn master_chain_basic() -> (H256, H256) {
|
||||
let seed = H128::from_str("000102030405060708090a0b0c0d0e0f")
|
||||
.expect("Seed should be valid H128")
|
||||
.to_vec();
|
||||
|
||||
derivation::seed_pair(&*seed)
|
||||
}
|
||||
|
||||
fn test_extended<F>(f: F, test_private: H256)
|
||||
where
|
||||
F: Fn(ExtendedSecret) -> ExtendedSecret,
|
||||
{
|
||||
let (private_seed, chain_code) = master_chain_basic();
|
||||
let extended_secret = ExtendedSecret::with_code(Secret::from(private_seed.0), chain_code);
|
||||
let derived = f(extended_secret);
|
||||
assert_eq!(**derived.as_raw(), test_private);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smoky() {
|
||||
let secret =
|
||||
Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65")
|
||||
.unwrap();
|
||||
let extended_secret = ExtendedSecret::with_code(secret.clone(), 0u64.into());
|
||||
|
||||
// hardened
|
||||
assert_eq!(&**extended_secret.as_raw(), &*secret);
|
||||
assert_eq!(
|
||||
&**extended_secret.derive(2147483648.into()).as_raw(),
|
||||
&"0927453daed47839608e414a3738dfad10aed17c459bbd9ab53f89b026c834b6".into()
|
||||
);
|
||||
assert_eq!(
|
||||
&**extended_secret.derive(2147483649.into()).as_raw(),
|
||||
&"44238b6a29c6dcbe9b401364141ba11e2198c289a5fed243a1c11af35c19dc0f".into()
|
||||
);
|
||||
|
||||
// normal
|
||||
assert_eq!(
|
||||
&**extended_secret.derive(0.into()).as_raw(),
|
||||
&"bf6a74e3f7b36fc4c96a1e12f31abc817f9f5904f5a8fc27713163d1f0b713f6".into()
|
||||
);
|
||||
assert_eq!(
|
||||
&**extended_secret.derive(1.into()).as_raw(),
|
||||
&"bd4fca9eb1f9c201e9448c1eecd66e302d68d4d313ce895b8c134f512205c1bc".into()
|
||||
);
|
||||
assert_eq!(
|
||||
&**extended_secret.derive(2.into()).as_raw(),
|
||||
&"86932b542d6cab4d9c65490c7ef502d89ecc0e2a5f4852157649e3251e2a3268".into()
|
||||
);
|
||||
|
||||
let extended_public = ExtendedPublic::from_secret(&extended_secret)
|
||||
.expect("Extended public should be created");
|
||||
let derived_public = extended_public
|
||||
.derive(0.into())
|
||||
.expect("First derivation of public should succeed");
|
||||
assert_eq!(&*derived_public.public(), &"f7b3244c96688f92372bfd4def26dc4151529747bab9f188a4ad34e141d47bd66522ff048bc6f19a0a4429b04318b1a8796c000265b4fa200dae5f6dda92dd94".into());
|
||||
|
||||
let keypair = ExtendedKeyPair::with_secret(
|
||||
Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65")
|
||||
.unwrap(),
|
||||
064.into(),
|
||||
);
|
||||
assert_eq!(
|
||||
&**keypair
|
||||
.derive(2147483648u32.into())
|
||||
.expect("Derivation of keypair should succeed")
|
||||
.secret()
|
||||
.as_raw(),
|
||||
&"edef54414c03196557cf73774bc97a645c9a1df2164ed34f0c2a78d1375a930c".into()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn h256_soft_match() {
|
||||
let secret =
|
||||
Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65")
|
||||
.unwrap();
|
||||
let derivation_secret =
|
||||
H256::from_str("51eaf04f9dbbc1417dc97e789edd0c37ecda88bac490434e367ea81b71b7b015")
|
||||
.unwrap();
|
||||
|
||||
let extended_secret = ExtendedSecret::with_code(secret.clone(), 0u64.into());
|
||||
let extended_public = ExtendedPublic::from_secret(&extended_secret)
|
||||
.expect("Extended public should be created");
|
||||
|
||||
let derived_secret0 = extended_secret.derive(Derivation::Soft(derivation_secret));
|
||||
let derived_public0 = extended_public
|
||||
.derive(Derivation::Soft(derivation_secret))
|
||||
.expect("First derivation of public should succeed");
|
||||
|
||||
let public_from_secret0 = ExtendedPublic::from_secret(&derived_secret0)
|
||||
.expect("Extended public should be created");
|
||||
|
||||
assert_eq!(public_from_secret0.public(), derived_public0.public());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn h256_hard() {
|
||||
let secret =
|
||||
Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65")
|
||||
.unwrap();
|
||||
let derivation_secret =
|
||||
H256::from_str("51eaf04f9dbbc1417dc97e789edd0c37ecda88bac490434e367ea81b71b7b015")
|
||||
.unwrap();
|
||||
let extended_secret = ExtendedSecret::with_code(secret.clone(), 1u64.into());
|
||||
|
||||
assert_eq!(
|
||||
&**extended_secret
|
||||
.derive(Derivation::Hard(derivation_secret))
|
||||
.as_raw(),
|
||||
&"2bc2d696fb744d77ff813b4a1ef0ad64e1e5188b622c54ba917acc5ebc7c5486".into()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match_() {
|
||||
let secret =
|
||||
Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65")
|
||||
.unwrap();
|
||||
let extended_secret = ExtendedSecret::with_code(secret.clone(), 1.into());
|
||||
let extended_public = ExtendedPublic::from_secret(&extended_secret)
|
||||
.expect("Extended public should be created");
|
||||
|
||||
let derived_secret0 = extended_secret.derive(0.into());
|
||||
let derived_public0 = extended_public
|
||||
.derive(0.into())
|
||||
.expect("First derivation of public should succeed");
|
||||
|
||||
let public_from_secret0 = ExtendedPublic::from_secret(&derived_secret0)
|
||||
.expect("Extended public should be created");
|
||||
|
||||
assert_eq!(public_from_secret0.public(), derived_public0.public());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_seeds() {
|
||||
let seed = H128::from_str("000102030405060708090a0b0c0d0e0f")
|
||||
.expect("Seed should be valid H128")
|
||||
.to_vec();
|
||||
|
||||
// private key from bitcoin test vector
|
||||
// xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs
|
||||
let test_private =
|
||||
H256::from_str("e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35")
|
||||
.expect("Private should be decoded ok");
|
||||
|
||||
let (private_seed, _) = derivation::seed_pair(&*seed);
|
||||
|
||||
assert_eq!(private_seed, test_private);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vector_1() {
|
||||
// xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7
|
||||
// H(0)
|
||||
test_extended(
|
||||
|secret| secret.derive(2147483648.into()),
|
||||
H256::from_str("edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea")
|
||||
.expect("Private should be decoded ok"),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vector_2() {
|
||||
// xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs
|
||||
// H(0)/1
|
||||
test_extended(
|
||||
|secret| secret.derive(2147483648.into()).derive(1.into()),
|
||||
H256::from_str("3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368")
|
||||
.expect("Private should be decoded ok"),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of OpenEthereum.
|
||||
|
||||
// OpenEthereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// OpenEthereum is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use super::{Address, Error, Public, Secret, SECP256K1};
|
||||
use keccak::Keccak256;
|
||||
use rustc_hex::ToHex;
|
||||
use secp256k1::key;
|
||||
use std::fmt;
|
||||
|
||||
pub fn public_to_address(public: &Public) -> Address {
|
||||
let hash = public.keccak256();
|
||||
let mut result = Address::default();
|
||||
result.copy_from_slice(&hash[12..]);
|
||||
result
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
/// secp256k1 key pair
|
||||
pub struct KeyPair {
|
||||
secret: Secret,
|
||||
public: Public,
|
||||
}
|
||||
|
||||
impl fmt::Display for KeyPair {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
writeln!(f, "secret: {}", self.secret.to_hex())?;
|
||||
writeln!(f, "public: {}", self.public.to_hex())?;
|
||||
write!(f, "address: {}", self.address().to_hex())
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyPair {
|
||||
/// Create a pair from secret key
|
||||
pub fn from_secret(secret: Secret) -> Result<KeyPair, Error> {
|
||||
let context = &SECP256K1;
|
||||
let s: key::SecretKey = key::SecretKey::from_slice(context, &secret[..])?;
|
||||
let pub_key = key::PublicKey::from_secret_key(context, &s)?;
|
||||
let serialized = pub_key.serialize_vec(context, false);
|
||||
|
||||
let mut public = Public::default();
|
||||
public.copy_from_slice(&serialized[1..65]);
|
||||
|
||||
let keypair = KeyPair {
|
||||
secret: secret,
|
||||
public: public,
|
||||
};
|
||||
|
||||
Ok(keypair)
|
||||
}
|
||||
|
||||
pub fn from_secret_slice(slice: &[u8]) -> Result<KeyPair, Error> {
|
||||
Self::from_secret(Secret::from_unsafe_slice(slice)?)
|
||||
}
|
||||
|
||||
pub fn from_keypair(sec: key::SecretKey, publ: key::PublicKey) -> Self {
|
||||
let context = &SECP256K1;
|
||||
let serialized = publ.serialize_vec(context, false);
|
||||
let secret = Secret::from(sec);
|
||||
let mut public = Public::default();
|
||||
public.copy_from_slice(&serialized[1..65]);
|
||||
|
||||
KeyPair {
|
||||
secret: secret,
|
||||
public: public,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn secret(&self) -> &Secret {
|
||||
&self.secret
|
||||
}
|
||||
|
||||
pub fn public(&self) -> &Public {
|
||||
&self.public
|
||||
}
|
||||
|
||||
pub fn address(&self) -> Address {
|
||||
public_to_address(&self.public)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
use KeyPair;
|
||||
use Secret;
|
||||
|
||||
#[test]
|
||||
fn from_secret() {
|
||||
let secret =
|
||||
Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65")
|
||||
.unwrap();
|
||||
let _ = KeyPair::from_secret(secret).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keypair_display() {
|
||||
let expected =
|
||||
"secret: a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65
|
||||
public: 8ce0db0b0359ffc5866ba61903cc2518c3675ef2cf380a7e54bde7ea20e6fa1ab45b7617346cd11b7610001ee6ae5b0155c41cad9527cbcdff44ec67848943a4
|
||||
address: 5b073e9233944b5e729e46d618f0d8edf3d9c34a".to_owned();
|
||||
let secret =
|
||||
Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65")
|
||||
.unwrap();
|
||||
let kp = KeyPair::from_secret(secret).unwrap();
|
||||
assert_eq!(format!("{}", kp), expected);
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of OpenEthereum.
|
||||
|
||||
// OpenEthereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// OpenEthereum is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// #![warn(missing_docs)]
|
||||
|
||||
extern crate edit_distance;
|
||||
extern crate ethereum_types;
|
||||
extern crate memzero;
|
||||
extern crate parity_crypto;
|
||||
extern crate parity_wordlist;
|
||||
#[macro_use]
|
||||
extern crate quick_error;
|
||||
extern crate rand;
|
||||
extern crate rustc_hex;
|
||||
extern crate secp256k1;
|
||||
extern crate serde;
|
||||
extern crate tiny_keccak;
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
mod brain;
|
||||
mod brain_prefix;
|
||||
mod error;
|
||||
mod extended;
|
||||
mod keccak;
|
||||
mod keypair;
|
||||
mod password;
|
||||
mod prefix;
|
||||
mod random;
|
||||
mod secret;
|
||||
mod signature;
|
||||
|
||||
pub mod brain_recover;
|
||||
pub mod crypto;
|
||||
pub mod math;
|
||||
|
||||
pub use self::{
|
||||
brain::Brain,
|
||||
brain_prefix::BrainPrefix,
|
||||
error::Error,
|
||||
extended::{Derivation, DerivationError, ExtendedKeyPair, ExtendedPublic, ExtendedSecret},
|
||||
keypair::{public_to_address, KeyPair},
|
||||
math::public_is_valid,
|
||||
parity_wordlist::Error as WordlistError,
|
||||
password::Password,
|
||||
prefix::Prefix,
|
||||
random::Random,
|
||||
secret::Secret,
|
||||
signature::{recover, sign, verify_address, verify_public, Signature},
|
||||
};
|
||||
|
||||
use ethereum_types::H256;
|
||||
|
||||
pub use ethereum_types::{Address, Public};
|
||||
pub type Message = H256;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref SECP256K1: secp256k1::Secp256k1 = secp256k1::Secp256k1::new();
|
||||
}
|
||||
|
||||
/// Uninstantiatable error type for infallible generators.
|
||||
#[derive(Debug)]
|
||||
pub enum Void {}
|
||||
|
||||
/// Generates new keypair.
|
||||
pub trait Generator {
|
||||
type Error;
|
||||
|
||||
/// Should be called to generate new keypair.
|
||||
fn generate(&mut self) -> Result<KeyPair, Self::Error>;
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of OpenEthereum.
|
||||
|
||||
// OpenEthereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// OpenEthereum is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use super::{Error, Public, Secret, SECP256K1};
|
||||
use ethereum_types::{H256, U256};
|
||||
use secp256k1::{
|
||||
constants::{CURVE_ORDER, GENERATOR_X, GENERATOR_Y},
|
||||
key,
|
||||
};
|
||||
|
||||
/// Whether the public key is valid.
|
||||
pub fn public_is_valid(public: &Public) -> bool {
|
||||
to_secp256k1_public(public)
|
||||
.ok()
|
||||
.map_or(false, |p| p.is_valid())
|
||||
}
|
||||
|
||||
/// Inplace multiply public key by secret key (EC point * scalar)
|
||||
pub fn public_mul_secret(public: &mut Public, secret: &Secret) -> Result<(), Error> {
|
||||
let key_secret = secret.to_secp256k1_secret()?;
|
||||
let mut key_public = to_secp256k1_public(public)?;
|
||||
key_public.mul_assign(&SECP256K1, &key_secret)?;
|
||||
set_public(public, &key_public);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Inplace add one public key to another (EC point + EC point)
|
||||
pub fn public_add(public: &mut Public, other: &Public) -> Result<(), Error> {
|
||||
let mut key_public = to_secp256k1_public(public)?;
|
||||
let other_public = to_secp256k1_public(other)?;
|
||||
key_public.add_assign(&SECP256K1, &other_public)?;
|
||||
set_public(public, &key_public);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Inplace sub one public key from another (EC point - EC point)
|
||||
pub fn public_sub(public: &mut Public, other: &Public) -> Result<(), Error> {
|
||||
let mut key_neg_other = to_secp256k1_public(other)?;
|
||||
key_neg_other.mul_assign(&SECP256K1, &key::MINUS_ONE_KEY)?;
|
||||
|
||||
let mut key_public = to_secp256k1_public(public)?;
|
||||
key_public.add_assign(&SECP256K1, &key_neg_other)?;
|
||||
set_public(public, &key_public);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Replace public key with its negation (EC point = - EC point)
|
||||
pub fn public_negate(public: &mut Public) -> Result<(), Error> {
|
||||
let mut key_public = to_secp256k1_public(public)?;
|
||||
key_public.mul_assign(&SECP256K1, &key::MINUS_ONE_KEY)?;
|
||||
set_public(public, &key_public);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Return base point of secp256k1
|
||||
pub fn generation_point() -> Public {
|
||||
let mut public_sec_raw = [0u8; 65];
|
||||
public_sec_raw[0] = 4;
|
||||
public_sec_raw[1..33].copy_from_slice(&GENERATOR_X);
|
||||
public_sec_raw[33..65].copy_from_slice(&GENERATOR_Y);
|
||||
|
||||
let public_key = key::PublicKey::from_slice(&SECP256K1, &public_sec_raw)
|
||||
.expect("constructing using predefined constants; qed");
|
||||
let mut public = Public::default();
|
||||
set_public(&mut public, &public_key);
|
||||
public
|
||||
}
|
||||
|
||||
/// Return secp256k1 elliptic curve order
|
||||
pub fn curve_order() -> U256 {
|
||||
H256::from_slice(&CURVE_ORDER).into()
|
||||
}
|
||||
|
||||
fn to_secp256k1_public(public: &Public) -> Result<key::PublicKey, Error> {
|
||||
let public_data = {
|
||||
let mut temp = [4u8; 65];
|
||||
(&mut temp[1..65]).copy_from_slice(&public[0..64]);
|
||||
temp
|
||||
};
|
||||
|
||||
Ok(key::PublicKey::from_slice(&SECP256K1, &public_data)?)
|
||||
}
|
||||
|
||||
fn set_public(public: &mut Public, key_public: &key::PublicKey) {
|
||||
let key_public_serialized = key_public.serialize_vec(&SECP256K1, false);
|
||||
public.copy_from_slice(&key_public_serialized[1..65]);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
super::{Generator, Random},
|
||||
public_add, public_sub,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn public_addition_is_commutative() {
|
||||
let public1 = Random.generate().unwrap().public().clone();
|
||||
let public2 = Random.generate().unwrap().public().clone();
|
||||
|
||||
let mut left = public1.clone();
|
||||
public_add(&mut left, &public2).unwrap();
|
||||
|
||||
let mut right = public2.clone();
|
||||
public_add(&mut right, &public1).unwrap();
|
||||
|
||||
assert_eq!(left, right);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn public_addition_is_reversible_with_subtraction() {
|
||||
let public1 = Random.generate().unwrap().public().clone();
|
||||
let public2 = Random.generate().unwrap().public().clone();
|
||||
|
||||
let mut sum = public1.clone();
|
||||
public_add(&mut sum, &public2).unwrap();
|
||||
public_sub(&mut sum, &public2).unwrap();
|
||||
|
||||
assert_eq!(sum, public1);
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of OpenEthereum.
|
||||
|
||||
// OpenEthereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// OpenEthereum is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use super::{Generator, KeyPair, SECP256K1};
|
||||
use rand::os::OsRng;
|
||||
|
||||
/// Randomly generates new keypair, instantiating the RNG each time.
|
||||
pub struct Random;
|
||||
|
||||
impl Generator for Random {
|
||||
type Error = ::std::io::Error;
|
||||
|
||||
fn generate(&mut self) -> Result<KeyPair, Self::Error> {
|
||||
let mut rng = OsRng::new()?;
|
||||
match rng.generate() {
|
||||
Ok(pair) => Ok(pair),
|
||||
Err(void) => match void {}, // LLVM unreachable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Generator for OsRng {
|
||||
type Error = ::Void;
|
||||
|
||||
fn generate(&mut self) -> Result<KeyPair, Self::Error> {
|
||||
let (sec, publ) = SECP256K1
|
||||
.generate_keypair(self)
|
||||
.expect("context always created with full capabilities; qed");
|
||||
|
||||
Ok(KeyPair::from_keypair(sec, publ))
|
||||
}
|
||||
}
|
|
@ -1,322 +0,0 @@
|
|||
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of OpenEthereum.
|
||||
|
||||
// OpenEthereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// OpenEthereum is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use ethereum_types::H256;
|
||||
use memzero::Memzero;
|
||||
use rustc_hex::ToHex;
|
||||
use secp256k1::{constants::SECRET_KEY_SIZE as SECP256K1_SECRET_KEY_SIZE, key};
|
||||
use std::{fmt, ops::Deref, str::FromStr};
|
||||
use Error;
|
||||
use SECP256K1;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct Secret {
|
||||
inner: Memzero<H256>,
|
||||
}
|
||||
|
||||
impl ToHex for Secret {
|
||||
fn to_hex(&self) -> String {
|
||||
format!("{:x}", *self.inner)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::LowerHex for Secret {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.inner.fmt(fmt)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Secret {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.inner.fmt(fmt)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Secret {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
fmt,
|
||||
"Secret: 0x{:x}{:x}..{:x}{:x}",
|
||||
self.inner[0], self.inner[1], self.inner[30], self.inner[31]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Secret {
|
||||
/// Creates a `Secret` from the given slice, returning `None` if the slice length != 32.
|
||||
pub fn from_slice(key: &[u8]) -> Option<Self> {
|
||||
if key.len() != 32 {
|
||||
return None;
|
||||
}
|
||||
let mut h = H256::default();
|
||||
h.copy_from_slice(&key[0..32]);
|
||||
Some(Secret {
|
||||
inner: Memzero::from(h),
|
||||
})
|
||||
}
|
||||
|
||||
/// Creates zero key, which is invalid for crypto operations, but valid for math operation.
|
||||
pub fn zero() -> Self {
|
||||
Secret {
|
||||
inner: Memzero::from(H256::default()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Imports and validates the key.
|
||||
pub fn from_unsafe_slice(key: &[u8]) -> Result<Self, Error> {
|
||||
let secret = key::SecretKey::from_slice(&super::SECP256K1, key)?;
|
||||
Ok(secret.into())
|
||||
}
|
||||
|
||||
/// Checks validity of this key.
|
||||
pub fn check_validity(&self) -> Result<(), Error> {
|
||||
self.to_secp256k1_secret().map(|_| ())
|
||||
}
|
||||
|
||||
/// Inplace add one secret key to another (scalar + scalar)
|
||||
pub fn add(&mut self, other: &Secret) -> Result<(), Error> {
|
||||
match (self.is_zero(), other.is_zero()) {
|
||||
(true, true) | (false, true) => Ok(()),
|
||||
(true, false) => {
|
||||
*self = other.clone();
|
||||
Ok(())
|
||||
}
|
||||
(false, false) => {
|
||||
let mut key_secret = self.to_secp256k1_secret()?;
|
||||
let other_secret = other.to_secp256k1_secret()?;
|
||||
key_secret.add_assign(&SECP256K1, &other_secret)?;
|
||||
|
||||
*self = key_secret.into();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Inplace subtract one secret key from another (scalar - scalar)
|
||||
pub fn sub(&mut self, other: &Secret) -> Result<(), Error> {
|
||||
match (self.is_zero(), other.is_zero()) {
|
||||
(true, true) | (false, true) => Ok(()),
|
||||
(true, false) => {
|
||||
*self = other.clone();
|
||||
self.neg()
|
||||
}
|
||||
(false, false) => {
|
||||
let mut key_secret = self.to_secp256k1_secret()?;
|
||||
let mut other_secret = other.to_secp256k1_secret()?;
|
||||
other_secret.mul_assign(&SECP256K1, &key::MINUS_ONE_KEY)?;
|
||||
key_secret.add_assign(&SECP256K1, &other_secret)?;
|
||||
|
||||
*self = key_secret.into();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Inplace decrease secret key (scalar - 1)
|
||||
pub fn dec(&mut self) -> Result<(), Error> {
|
||||
match self.is_zero() {
|
||||
true => {
|
||||
*self = key::MINUS_ONE_KEY.into();
|
||||
Ok(())
|
||||
}
|
||||
false => {
|
||||
let mut key_secret = self.to_secp256k1_secret()?;
|
||||
key_secret.add_assign(&SECP256K1, &key::MINUS_ONE_KEY)?;
|
||||
|
||||
*self = key_secret.into();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Inplace multiply one secret key to another (scalar * scalar)
|
||||
pub fn mul(&mut self, other: &Secret) -> Result<(), Error> {
|
||||
match (self.is_zero(), other.is_zero()) {
|
||||
(true, true) | (true, false) => Ok(()),
|
||||
(false, true) => {
|
||||
*self = Self::zero();
|
||||
Ok(())
|
||||
}
|
||||
(false, false) => {
|
||||
let mut key_secret = self.to_secp256k1_secret()?;
|
||||
let other_secret = other.to_secp256k1_secret()?;
|
||||
key_secret.mul_assign(&SECP256K1, &other_secret)?;
|
||||
|
||||
*self = key_secret.into();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Inplace negate secret key (-scalar)
|
||||
pub fn neg(&mut self) -> Result<(), Error> {
|
||||
match self.is_zero() {
|
||||
true => Ok(()),
|
||||
false => {
|
||||
let mut key_secret = self.to_secp256k1_secret()?;
|
||||
key_secret.mul_assign(&SECP256K1, &key::MINUS_ONE_KEY)?;
|
||||
|
||||
*self = key_secret.into();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Inplace inverse secret key (1 / scalar)
|
||||
pub fn inv(&mut self) -> Result<(), Error> {
|
||||
let mut key_secret = self.to_secp256k1_secret()?;
|
||||
key_secret.inv_assign(&SECP256K1)?;
|
||||
|
||||
*self = key_secret.into();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Compute power of secret key inplace (secret ^ pow).
|
||||
/// This function is not intended to be used with large powers.
|
||||
pub fn pow(&mut self, pow: usize) -> Result<(), Error> {
|
||||
if self.is_zero() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
match pow {
|
||||
0 => *self = key::ONE_KEY.into(),
|
||||
1 => (),
|
||||
_ => {
|
||||
let c = self.clone();
|
||||
for _ in 1..pow {
|
||||
self.mul(&c)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Create `secp256k1::key::SecretKey` based on this secret
|
||||
pub fn to_secp256k1_secret(&self) -> Result<key::SecretKey, Error> {
|
||||
Ok(key::SecretKey::from_slice(&SECP256K1, &self[..])?)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Secret {
|
||||
type Err = Error;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(H256::from_str(s)
|
||||
.map_err(|e| Error::Custom(format!("{:?}", e)))?
|
||||
.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[u8; 32]> for Secret {
|
||||
fn from(k: [u8; 32]) -> Self {
|
||||
Secret {
|
||||
inner: Memzero::from(H256(k)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<H256> for Secret {
|
||||
fn from(s: H256) -> Self {
|
||||
s.0.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for Secret {
|
||||
fn from(s: &'static str) -> Self {
|
||||
s.parse().expect(&format!(
|
||||
"invalid string literal for {}: '{}'",
|
||||
stringify!(Self),
|
||||
s
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<key::SecretKey> for Secret {
|
||||
fn from(key: key::SecretKey) -> Self {
|
||||
let mut a = [0; SECP256K1_SECRET_KEY_SIZE];
|
||||
a.copy_from_slice(&key[0..SECP256K1_SECRET_KEY_SIZE]);
|
||||
a.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Secret {
|
||||
type Target = H256;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
super::{Generator, Random},
|
||||
Secret,
|
||||
};
|
||||
use std::str::FromStr;
|
||||
|
||||
#[test]
|
||||
fn multiplicating_secret_inversion_with_secret_gives_one() {
|
||||
let secret = Random.generate().unwrap().secret().clone();
|
||||
let mut inversion = secret.clone();
|
||||
inversion.inv().unwrap();
|
||||
inversion.mul(&secret).unwrap();
|
||||
assert_eq!(
|
||||
inversion,
|
||||
Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001")
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn secret_inversion_is_reversible_with_inversion() {
|
||||
let secret = Random.generate().unwrap().secret().clone();
|
||||
let mut inversion = secret.clone();
|
||||
inversion.inv().unwrap();
|
||||
inversion.inv().unwrap();
|
||||
assert_eq!(inversion, secret);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn secret_pow() {
|
||||
let secret = Random.generate().unwrap().secret().clone();
|
||||
|
||||
let mut pow0 = secret.clone();
|
||||
pow0.pow(0).unwrap();
|
||||
assert_eq!(
|
||||
pow0,
|
||||
Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001")
|
||||
.unwrap()
|
||||
);
|
||||
|
||||
let mut pow1 = secret.clone();
|
||||
pow1.pow(1).unwrap();
|
||||
assert_eq!(pow1, secret);
|
||||
|
||||
let mut pow2 = secret.clone();
|
||||
pow2.pow(2).unwrap();
|
||||
let mut pow2_expected = secret.clone();
|
||||
pow2_expected.mul(&secret).unwrap();
|
||||
assert_eq!(pow2, pow2_expected);
|
||||
|
||||
let mut pow3 = secret.clone();
|
||||
pow3.pow(3).unwrap();
|
||||
let mut pow3_expected = secret.clone();
|
||||
pow3_expected.mul(&secret).unwrap();
|
||||
pow3_expected.mul(&secret).unwrap();
|
||||
assert_eq!(pow3, pow3_expected);
|
||||
}
|
||||
}
|
|
@ -1,325 +0,0 @@
|
|||
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of OpenEthereum.
|
||||
|
||||
// OpenEthereum is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// OpenEthereum is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use ethereum_types::{H256, H520};
|
||||
use public_to_address;
|
||||
use rustc_hex::{FromHex, ToHex};
|
||||
use secp256k1::{
|
||||
key::{PublicKey, SecretKey},
|
||||
Error as SecpError, Message as SecpMessage, RecoverableSignature, RecoveryId,
|
||||
};
|
||||
use std::{
|
||||
cmp::PartialEq,
|
||||
fmt,
|
||||
hash::{Hash, Hasher},
|
||||
ops::{Deref, DerefMut},
|
||||
str::FromStr,
|
||||
};
|
||||
use Address;
|
||||
use Error;
|
||||
use Message;
|
||||
use Public;
|
||||
use Secret;
|
||||
use SECP256K1;
|
||||
|
||||
/// Signature encoded as RSV components
|
||||
#[repr(C)]
|
||||
pub struct Signature([u8; 65]);
|
||||
|
||||
impl Signature {
|
||||
/// Get a slice into the 'r' portion of the data.
|
||||
pub fn r(&self) -> &[u8] {
|
||||
&self.0[0..32]
|
||||
}
|
||||
|
||||
/// Get a slice into the 's' portion of the data.
|
||||
pub fn s(&self) -> &[u8] {
|
||||
&self.0[32..64]
|
||||
}
|
||||
|
||||
/// Get the recovery byte.
|
||||
pub fn v(&self) -> u8 {
|
||||
self.0[64]
|
||||
}
|
||||
|
||||
/// Encode the signature into RSV array (V altered to be in "Electrum" notation).
|
||||
pub fn into_electrum(mut self) -> [u8; 65] {
|
||||
self.0[64] += 27;
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Parse bytes as a signature encoded as RSV (V in "Electrum" notation).
|
||||
/// May return empty (invalid) signature if given data has invalid length.
|
||||
pub fn from_electrum(data: &[u8]) -> Self {
|
||||
if data.len() != 65 || data[64] < 27 {
|
||||
// fallback to empty (invalid) signature
|
||||
return Signature::default();
|
||||
}
|
||||
|
||||
let mut sig = [0u8; 65];
|
||||
sig.copy_from_slice(data);
|
||||
sig[64] -= 27;
|
||||
Signature(sig)
|
||||
}
|
||||
|
||||
/// Create a signature object from the sig.
|
||||
pub fn from_rsv(r: &H256, s: &H256, v: u8) -> Self {
|
||||
let mut sig = [0u8; 65];
|
||||
sig[0..32].copy_from_slice(&r);
|
||||
sig[32..64].copy_from_slice(&s);
|
||||
sig[64] = v;
|
||||
Signature(sig)
|
||||
}
|
||||
|
||||
/// Check if this is a "low" signature.
|
||||
pub fn is_low_s(&self) -> bool {
|
||||
H256::from_slice(self.s())
|
||||
<= "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0".into()
|
||||
}
|
||||
|
||||
/// Check if each component of the signature is in range.
|
||||
pub fn is_valid(&self) -> bool {
|
||||
self.v() <= 1
|
||||
&& H256::from_slice(self.r())
|
||||
< "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141".into()
|
||||
&& H256::from_slice(self.r()) >= 1.into()
|
||||
&& H256::from_slice(self.s())
|
||||
< "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141".into()
|
||||
&& H256::from_slice(self.s()) >= 1.into()
|
||||
}
|
||||
}
|
||||
|
||||
// manual implementation large arrays don't have trait impls by default.
|
||||
// remove when integer generics exist
|
||||
impl PartialEq for Signature {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
&self.0[..] == &other.0[..]
|
||||
}
|
||||
}
|
||||
|
||||
// manual implementation required in Rust 1.13+, see `std::cmp::AssertParamIsEq`.
|
||||
impl Eq for Signature {}
|
||||
|
||||
// also manual for the same reason, but the pretty printing might be useful.
|
||||
impl fmt::Debug for Signature {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
f.debug_struct("Signature")
|
||||
.field("r", &self.0[0..32].to_hex())
|
||||
.field("s", &self.0[32..64].to_hex())
|
||||
.field("v", &self.0[64..65].to_hex())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Signature {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
write!(f, "{}", self.to_hex())
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Signature {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s.from_hex() {
|
||||
Ok(ref hex) if hex.len() == 65 => {
|
||||
let mut data = [0; 65];
|
||||
data.copy_from_slice(&hex[0..65]);
|
||||
Ok(Signature(data))
|
||||
}
|
||||
_ => Err(Error::InvalidSignature),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Signature {
|
||||
fn default() -> Self {
|
||||
Signature([0; 65])
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for Signature {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
H520::from(self.0).hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Signature {
|
||||
fn clone(&self) -> Self {
|
||||
Signature(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[u8; 65]> for Signature {
|
||||
fn from(s: [u8; 65]) -> Self {
|
||||
Signature(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<[u8; 65]> for Signature {
|
||||
fn into(self) -> [u8; 65] {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Signature> for H520 {
|
||||
fn from(s: Signature) -> Self {
|
||||
H520::from(s.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<H520> for Signature {
|
||||
fn from(bytes: H520) -> Self {
|
||||
Signature(bytes.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Signature {
|
||||
type Target = [u8; 65];
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Signature {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sign(secret: &Secret, message: &Message) -> Result<Signature, Error> {
|
||||
let context = &SECP256K1;
|
||||
let sec = SecretKey::from_slice(context, &secret)?;
|
||||
let s = context.sign_recoverable(&SecpMessage::from_slice(&message[..])?, &sec)?;
|
||||
let (rec_id, data) = s.serialize_compact(context);
|
||||
let mut data_arr = [0; 65];
|
||||
|
||||
// no need to check if s is low, it always is
|
||||
data_arr[0..64].copy_from_slice(&data[0..64]);
|
||||
data_arr[64] = rec_id.to_i32() as u8;
|
||||
Ok(Signature(data_arr))
|
||||
}
|
||||
|
||||
pub fn verify_public(
|
||||
public: &Public,
|
||||
signature: &Signature,
|
||||
message: &Message,
|
||||
) -> Result<bool, Error> {
|
||||
let context = &SECP256K1;
|
||||
let rsig = RecoverableSignature::from_compact(
|
||||
context,
|
||||
&signature[0..64],
|
||||
RecoveryId::from_i32(signature[64] as i32)?,
|
||||
)?;
|
||||
let sig = rsig.to_standard(context);
|
||||
|
||||
let pdata: [u8; 65] = {
|
||||
let mut temp = [4u8; 65];
|
||||
temp[1..65].copy_from_slice(&**public);
|
||||
temp
|
||||
};
|
||||
|
||||
let publ = PublicKey::from_slice(context, &pdata)?;
|
||||
match context.verify(&SecpMessage::from_slice(&message[..])?, &sig, &publ) {
|
||||
Ok(_) => Ok(true),
|
||||
Err(SecpError::IncorrectSignature) => Ok(false),
|
||||
Err(x) => Err(Error::from(x)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verify_address(
|
||||
address: &Address,
|
||||
signature: &Signature,
|
||||
message: &Message,
|
||||
) -> Result<bool, Error> {
|
||||
let public = recover(signature, message)?;
|
||||
let recovered_address = public_to_address(&public);
|
||||
Ok(address == &recovered_address)
|
||||
}
|
||||
|
||||
pub fn recover(signature: &Signature, message: &Message) -> Result<Public, Error> {
|
||||
let context = &SECP256K1;
|
||||
let rsig = RecoverableSignature::from_compact(
|
||||
context,
|
||||
&signature[0..64],
|
||||
RecoveryId::from_i32(signature[64] as i32)?,
|
||||
)?;
|
||||
let pubkey = context.recover(&SecpMessage::from_slice(&message[..])?, &rsig)?;
|
||||
let serialized = pubkey.serialize_vec(context, false);
|
||||
|
||||
let mut public = Public::default();
|
||||
public.copy_from_slice(&serialized[1..65]);
|
||||
Ok(public)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{recover, sign, verify_address, verify_public, Signature};
|
||||
use std::str::FromStr;
|
||||
use Generator;
|
||||
use Message;
|
||||
use Random;
|
||||
|
||||
#[test]
|
||||
fn vrs_conversion() {
|
||||
// given
|
||||
let keypair = Random.generate().unwrap();
|
||||
let message = Message::default();
|
||||
let signature = sign(keypair.secret(), &message).unwrap();
|
||||
|
||||
// when
|
||||
let vrs = signature.clone().into_electrum();
|
||||
let from_vrs = Signature::from_electrum(&vrs);
|
||||
|
||||
// then
|
||||
assert_eq!(signature, from_vrs);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn signature_to_and_from_str() {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let message = Message::default();
|
||||
let signature = sign(keypair.secret(), &message).unwrap();
|
||||
let string = format!("{}", signature);
|
||||
let deserialized = Signature::from_str(&string).unwrap();
|
||||
assert_eq!(signature, deserialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sign_and_recover_public() {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let message = Message::default();
|
||||
let signature = sign(keypair.secret(), &message).unwrap();
|
||||
assert_eq!(keypair.public(), &recover(&signature, &message).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sign_and_verify_public() {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let message = Message::default();
|
||||
let signature = sign(keypair.secret(), &message).unwrap();
|
||||
assert!(verify_public(keypair.public(), &signature, &message).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sign_and_verify_address() {
|
||||
let keypair = Random.generate().unwrap();
|
||||
let message = Message::default();
|
||||
let signature = sign(keypair.secret(), &message).unwrap();
|
||||
assert!(verify_address(&keypair.address(), &signature, &message).unwrap());
|
||||
}
|
||||
}
|
|
@ -5,5 +5,5 @@ version = "0.1.0"
|
|||
authors = ["Marek Kotewicz <marek@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
ethjson = { path = "../json" }
|
||||
ethjson = { path = "../../crates/ethjson" }
|
||||
serde_json = "1.0"
|
|
@ -7,8 +7,9 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
|||
[dependencies]
|
||||
docopt = "1.0"
|
||||
env_logger = "0.5"
|
||||
ethkey = { path = "../" }
|
||||
panic_hook = { path = "../../../util/panic-hook" }
|
||||
ethkey = { path = "../../crates/accounts/ethkey" }
|
||||
panic_hook = { path = "../../crates/util/panic-hook" }
|
||||
parity-crypto = { version = "0.6.2", features = [ "publickey" ] }
|
||||
parity-wordlist="1.3"
|
||||
rustc-hex = "1.0"
|
||||
serde = "1.0"
|
|
@ -18,6 +18,7 @@ extern crate docopt;
|
|||
extern crate env_logger;
|
||||
extern crate ethkey;
|
||||
extern crate panic_hook;
|
||||
extern crate parity_crypto as crypto;
|
||||
extern crate parity_wordlist;
|
||||
extern crate rustc_hex;
|
||||
extern crate serde;
|
||||
|
@ -28,11 +29,11 @@ extern crate serde_derive;
|
|||
|
||||
use std::{env, fmt, io, num::ParseIntError, process, sync};
|
||||
|
||||
use docopt::Docopt;
|
||||
use ethkey::{
|
||||
brain_recover, sign, verify_address, verify_public, Brain, BrainPrefix, Error as EthkeyError,
|
||||
Generator, KeyPair, Prefix, Random,
|
||||
use crypto::publickey::{
|
||||
sign, verify_address, verify_public, Error as EthkeyError, Generator, KeyPair, Random,
|
||||
};
|
||||
use docopt::Docopt;
|
||||
use ethkey::{brain_recover, Brain, BrainPrefix, Prefix};
|
||||
use rustc_hex::{FromHex, FromHexError};
|
||||
|
||||
const USAGE: &'static str = r#"
|
||||
|
@ -202,15 +203,13 @@ where
|
|||
let result = if args.flag_brain {
|
||||
let phrase = args.arg_secret_or_phrase;
|
||||
let phrase_info = validate_phrase(&phrase);
|
||||
let keypair = Brain::new(phrase)
|
||||
.generate()
|
||||
.expect("Brain wallet generator is infallible; qed");
|
||||
let keypair = Brain::new(phrase).generate();
|
||||
(keypair, Some(phrase_info))
|
||||
} else {
|
||||
let secret = args
|
||||
.arg_secret_or_phrase
|
||||
.parse()
|
||||
.map_err(|_| EthkeyError::InvalidSecret)?;
|
||||
.map_err(|_| EthkeyError::InvalidSecretKey)?;
|
||||
(KeyPair::from_secret(secret)?, None)
|
||||
};
|
||||
Ok(display(result, display_mode))
|
||||
|
@ -223,7 +222,7 @@ where
|
|||
let phrase = format!("recovery phrase: {}", brain.phrase());
|
||||
(keypair, Some(phrase))
|
||||
} else {
|
||||
(Random.generate()?, None)
|
||||
(Random.generate(), None)
|
||||
}
|
||||
} else if args.cmd_prefix {
|
||||
let prefix = args.arg_prefix.from_hex()?;
|
||||
|
@ -254,7 +253,7 @@ where
|
|||
let secret = args
|
||||
.arg_secret
|
||||
.parse()
|
||||
.map_err(|_| EthkeyError::InvalidSecret)?;
|
||||
.map_err(|_| EthkeyError::InvalidSecretKey)?;
|
||||
let message = args
|
||||
.arg_message
|
||||
.parse()
|
||||
|
@ -274,7 +273,7 @@ where
|
|||
let public = args
|
||||
.arg_public
|
||||
.parse()
|
||||
.map_err(|_| EthkeyError::InvalidPublic)?;
|
||||
.map_err(|_| EthkeyError::InvalidPublicKey)?;
|
||||
verify_public(&public, &signature, &message)?
|
||||
} else if args.cmd_address {
|
||||
let address = args
|
||||
|
@ -301,7 +300,7 @@ where
|
|||
while let Some(phrase) = it.next() {
|
||||
i += 1;
|
||||
|
||||
let keypair = Brain::new(phrase.clone()).generate().unwrap();
|
||||
let keypair = Brain::new(phrase.clone()).generate();
|
||||
if keypair.address() == address {
|
||||
return Ok(Some((phrase, keypair)));
|
||||
}
|
|
@ -11,10 +11,10 @@ num_cpus = "1.6"
|
|||
rustc-hex = "1.0"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
parking_lot = "0.7"
|
||||
ethstore = { path = "../" }
|
||||
dir = { path = '../../../util/dir' }
|
||||
panic_hook = { path = "../../../util/panic-hook" }
|
||||
parking_lot = "0.11.1"
|
||||
ethstore = { path = "../../crates/accounts/ethstore" }
|
||||
dir = { path = '../../crates/util/dir' }
|
||||
panic_hook = { path = "../../crates/util/panic-hook" }
|
||||
|
||||
[[bin]]
|
||||
name = "ethstore"
|
|
@ -9,20 +9,20 @@ name = "openethereum-evm"
|
|||
path = "./src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
common-types = { path = "../ethcore/types", features = ["test-helpers"] }
|
||||
common-types = { path = "../../crates/ethcore/types", features = ["test-helpers"] }
|
||||
docopt = "1.0"
|
||||
env_logger = "0.5"
|
||||
ethcore = { path = "../ethcore", features = ["test-helpers", "json-tests", "to-pod-full"] }
|
||||
ethereum-types = "0.4"
|
||||
ethjson = { path = "../json" }
|
||||
evm = { path = "../ethcore/evm" }
|
||||
panic_hook = { path = "../util/panic-hook" }
|
||||
ethcore = { path = "../../crates/ethcore", features = ["test-helpers", "json-tests", "to-pod-full"] }
|
||||
ethereum-types = "0.9.2"
|
||||
ethjson = { path = "../../crates/ethjson" }
|
||||
evm = { path = "../../crates/vm/evm" }
|
||||
panic_hook = { path = "../../crates/util/panic-hook" }
|
||||
parity-bytes = "0.1"
|
||||
rustc-hex = "1.0"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
vm = { path = "../ethcore/vm" }
|
||||
vm = { path = "../../crates/vm/vm" }
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.3.0"
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
//! Config used by display informants
|
||||
|
||||
#[derive(Default, Copy, Clone)]
|
||||
#[derive(Default, Copy, Clone, Debug)]
|
||||
pub struct Config {
|
||||
omit_storage_output: bool,
|
||||
omit_memory_output: bool,
|
|
@ -22,7 +22,7 @@ use super::config::Config;
|
|||
use bytes::ToPretty;
|
||||
use display;
|
||||
use ethcore::trace;
|
||||
use ethereum_types::{H256, U256};
|
||||
use ethereum_types::{BigEndianHash, H256, U256};
|
||||
use info as vm;
|
||||
|
||||
/// JSON formatting informant.
|
||||
|
@ -208,7 +208,10 @@ impl trace::VMTracer for Informant {
|
|||
}
|
||||
|
||||
if let Some((pos, val)) = store_diff {
|
||||
informant.storage.insert(pos.into(), val.into());
|
||||
informant.storage.insert(
|
||||
BigEndianHash::from_uint(&pos),
|
||||
BigEndianHash::from_uint(&val),
|
||||
);
|
||||
}
|
||||
|
||||
if !informant.subtraces.is_empty() {
|
||||
|
@ -284,7 +287,7 @@ mod tests {
|
|||
gas_cost: U256,
|
||||
memory: String,
|
||||
stack: Vec<U256>,
|
||||
storage: HashMap<H256, H256>,
|
||||
storage: Option<HashMap<H256, H256>>,
|
||||
depth: usize,
|
||||
}
|
||||
|
||||
|
@ -399,6 +402,23 @@ mod tests {
|
|||
{"pc":1,"op":96,"opName":"PUSH1","gas":"0xfffd","gasCost":"0x3","memory":"0x","stack":["0x0"],"storage":{},"depth":1}
|
||||
{"pc":3,"op":85,"opName":"SSTORE","gas":"0xfffa","gasCost":"0x1388","memory":"0x","stack":["0x0","0xd8"],"storage":{},"depth":1}
|
||||
{"pc":4,"op":84,"opName":"SLOAD","gas":"0xec72","gasCost":"0x0","memory":"0x","stack":[],"storage":{"0x00000000000000000000000000000000000000000000000000000000000000d8":"0x0000000000000000000000000000000000000000000000000000000000000000"},"depth":1}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_omit_storage_and_memory_flag() {
|
||||
// should omit storage
|
||||
run_test(
|
||||
Informant::new(Config::new(true, true)),
|
||||
&compare_json,
|
||||
"3260D85554",
|
||||
0xffff,
|
||||
r#"
|
||||
{"pc":0,"op":50,"opName":"ORIGIN","gas":"0xffff","gasCost":"0x2","memory":"","stack":[],"storage":null,"depth":1}
|
||||
{"pc":1,"op":96,"opName":"PUSH1","gas":"0xfffd","gasCost":"0x3","memory":"","stack":["0x0"],"storage":null,"depth":1}
|
||||
{"pc":3,"op":85,"opName":"SSTORE","gas":"0xfffa","gasCost":"0x1388","memory":"","stack":["0x0","0xd8"],"storage":null,"depth":1}
|
||||
{"pc":4,"op":84,"opName":"SLOAD","gas":"0xec72","gasCost":"0x0","memory":"","stack":[],"storage":null,"depth":1}
|
||||
"#,
|
||||
)
|
||||
}
|
|
@ -22,7 +22,7 @@ use super::config::Config;
|
|||
use bytes::ToPretty;
|
||||
use display;
|
||||
use ethcore::{pod_state, trace};
|
||||
use ethereum_types::{H256, U256};
|
||||
use ethereum_types::{BigEndianHash, H256, U256};
|
||||
use info as vm;
|
||||
|
||||
pub trait Writer: io::Write + Send + Sized {
|
||||
|
@ -203,6 +203,11 @@ impl<Trace: Writer, Out: Writer> trace::VMTracer for Informant<Trace, Out> {
|
|||
fn trace_next_instruction(&mut self, pc: usize, instruction: u8, current_gas: U256) -> bool {
|
||||
let subdepth = self.subdepth;
|
||||
Self::with_informant_in_depth(self, subdepth, |informant: &mut Informant<Trace, Out>| {
|
||||
let storage = if informant.config.omit_storage_output() {
|
||||
None
|
||||
} else {
|
||||
Some(&informant.storage)
|
||||
};
|
||||
let info = ::evm::Instruction::from_u8(instruction).map(|i| i.info());
|
||||
informant.instruction = instruction;
|
||||
let trace_data = json!({
|
||||
|
@ -211,7 +216,7 @@ impl<Trace: Writer, Out: Writer> trace::VMTracer for Informant<Trace, Out> {
|
|||
"opName": info.map(|i| i.name).unwrap_or(""),
|
||||
"gas": format!("{:#x}", current_gas),
|
||||
"stack": informant.stack,
|
||||
"storage": informant.storage,
|
||||
"storage": storage,
|
||||
"depth": informant.depth,
|
||||
});
|
||||
|
||||
|
@ -232,7 +237,10 @@ impl<Trace: Writer, Out: Writer> trace::VMTracer for Informant<Trace, Out> {
|
|||
let subdepth = self.subdepth;
|
||||
Self::with_informant_in_depth(self, subdepth, |informant: &mut Informant<Trace, Out>| {
|
||||
if let Some((pos, val)) = store_written {
|
||||
informant.storage.insert(pos.into(), val.into());
|
||||
informant.storage.insert(
|
||||
BigEndianHash::from_uint(&pos),
|
||||
BigEndianHash::from_uint(&val),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -307,19 +315,16 @@ pub mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn informant() -> (Informant<TestWriter, TestWriter>, Arc<Mutex<Vec<u8>>>) {
|
||||
pub fn informant(config: Config) -> (Informant<TestWriter, TestWriter>, Arc<Mutex<Vec<u8>>>) {
|
||||
let trace_writer: TestWriter = Default::default();
|
||||
let out_writer: TestWriter = Default::default();
|
||||
let res = trace_writer.0.clone();
|
||||
(
|
||||
Informant::new(trace_writer, out_writer, Config::default()),
|
||||
res,
|
||||
)
|
||||
(Informant::new(trace_writer, out_writer, config), res)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_trace_failure() {
|
||||
let (inf, res) = informant();
|
||||
let (inf, res) = informant(Config::default());
|
||||
run_test(
|
||||
inf,
|
||||
move |_, expected| {
|
||||
|
@ -333,7 +338,7 @@ pub mod tests {
|
|||
"#,
|
||||
);
|
||||
|
||||
let (inf, res) = informant();
|
||||
let (inf, res) = informant(Config::default());
|
||||
run_test(
|
||||
inf,
|
||||
move |_, expected| {
|
||||
|
@ -349,7 +354,7 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
fn should_trace_create_correctly() {
|
||||
let (informant, res) = informant();
|
||||
let (informant, res) = informant(Config::default());
|
||||
run_test(
|
||||
informant,
|
||||
move |_, expected| {
|
||||
|
@ -382,6 +387,26 @@ pub mod tests {
|
|||
{"depth":2,"gas":"0x2102","op":88,"opName":"PC","pc":5,"stack":["0x0","0x0","0x0","0x0","0x0"],"storage":{}}
|
||||
{"depth":2,"gas":"0x2100","op":48,"opName":"ADDRESS","pc":6,"stack":["0x0","0x0","0x0","0x0","0x0","0x5"],"storage":{}}
|
||||
{"depth":2,"gas":"0x20fe","op":241,"opName":"CALL","pc":7,"stack":["0x0","0x0","0x0","0x0","0x0","0x5","0xbd770416a3345f91e4b34576cb804a576fa48eb1"],"storage":{}}
|
||||
"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_omit_storage_and_memory_flag() {
|
||||
// should omit storage
|
||||
let (informant, res) = informant(Config::new(true, true));
|
||||
run_test(
|
||||
informant,
|
||||
move |_, expected| {
|
||||
let bytes = res.lock().unwrap();
|
||||
assert_eq!(expected, &String::from_utf8_lossy(&**bytes))
|
||||
},
|
||||
"3260D85554",
|
||||
0xffff,
|
||||
r#"{"depth":1,"gas":"0xffff","op":50,"opName":"ORIGIN","pc":0,"stack":[],"storage":null}
|
||||
{"depth":1,"gas":"0xfffd","op":96,"opName":"PUSH1","pc":1,"stack":["0x0"],"storage":null}
|
||||
{"depth":1,"gas":"0xfffa","op":85,"opName":"SSTORE","pc":3,"stack":["0x0","0xd8"],"storage":null}
|
||||
{"depth":1,"gas":"0xec72","op":84,"opName":"SLOAD","pc":4,"stack":[],"storage":null}
|
||||
"#,
|
||||
)
|
||||
}
|
|
@ -103,7 +103,7 @@ pub fn run_action<T: Informant>(
|
|||
Ok(r) => (Ok(r.return_data.to_vec()), Some(r.gas_left)),
|
||||
Err(err) => (Err(err), None),
|
||||
};
|
||||
(result.0, 0.into(), None, result.1, informant.drain())
|
||||
(result.0, H256::zero(), None, result.1, informant.drain())
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -262,6 +262,7 @@ where
|
|||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use super::*;
|
||||
use ethereum_types::Address;
|
||||
use rustc_hex::FromHex;
|
||||
use std::sync::Arc;
|
||||
use tempdir::TempDir;
|
||||
|
@ -287,11 +288,11 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
fn should_call_account_from_spec() {
|
||||
use display::std_json::tests::informant;
|
||||
use display::{config::Config, std_json::tests::informant};
|
||||
|
||||
let (inf, res) = informant();
|
||||
let (inf, res) = informant(Config::default());
|
||||
let mut params = ActionParams::default();
|
||||
params.code_address = 0x20.into();
|
||||
params.code_address = Address::from_low_u64_be(0x20);
|
||||
params.gas = 0xffff.into();
|
||||
|
||||
let spec = ::ethcore::ethereum::load(None, include_bytes!("../res/testchain.json"));
|
|
@ -46,6 +46,8 @@ use bytes::Bytes;
|
|||
use docopt::Docopt;
|
||||
use ethcore::{json_tests, spec, TrieSpec};
|
||||
use ethereum_types::{Address, U256};
|
||||
use ethjson::spec::ForkSpec;
|
||||
use evm::EnvInfo;
|
||||
use rustc_hex::FromHex;
|
||||
use std::{fmt, fs, path::PathBuf, sync::Arc};
|
||||
use vm::{ActionParams, CallType};
|
||||
|
@ -192,10 +194,18 @@ fn run_state_test(args: Args) {
|
|||
}
|
||||
|
||||
let multitransaction = test.transaction;
|
||||
let env_info = test.env.into();
|
||||
let env_info: EnvInfo = test.env.into();
|
||||
let pre = test.pre_state.into();
|
||||
|
||||
for (spec, states) in test.post_states {
|
||||
//hardcode base fee for part of the london tests, that miss base fee field in env
|
||||
let mut test_env = env_info.clone();
|
||||
if spec >= ForkSpec::London {
|
||||
if test_env.base_fee.is_none() {
|
||||
test_env.base_fee = Some(0x0a.into());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(false) = only_chain
|
||||
.as_ref()
|
||||
.map(|only_chain| &format!("{:?}", spec).to_lowercase() == only_chain)
|
||||
|
@ -204,7 +214,7 @@ fn run_state_test(args: Args) {
|
|||
}
|
||||
for (idx, state) in states.into_iter().enumerate() {
|
||||
let post_root = state.hash.into();
|
||||
let transaction = multitransaction.select(&state.indexes).into();
|
||||
let transaction = multitransaction.select(&state.indexes);
|
||||
|
||||
let trie_spec = if args.flag_std_dump_json {
|
||||
TrieSpec::Fat
|
||||
|
@ -218,7 +228,7 @@ fn run_state_test(args: Args) {
|
|||
&spec,
|
||||
&pre,
|
||||
post_root,
|
||||
&env_info,
|
||||
&test_env,
|
||||
transaction,
|
||||
display::json::Informant::new(config),
|
||||
trie_spec,
|
||||
|
@ -231,7 +241,7 @@ fn run_state_test(args: Args) {
|
|||
&spec,
|
||||
&pre,
|
||||
post_root,
|
||||
&env_info,
|
||||
&test_env,
|
||||
transaction,
|
||||
display::std_json::Informant::err_only(config),
|
||||
trie_spec,
|
||||
|
@ -243,7 +253,7 @@ fn run_state_test(args: Args) {
|
|||
&spec,
|
||||
&pre,
|
||||
post_root,
|
||||
&env_info,
|
||||
&test_env,
|
||||
transaction,
|
||||
display::std_json::Informant::out_only(config),
|
||||
trie_spec,
|
||||
|
@ -255,7 +265,7 @@ fn run_state_test(args: Args) {
|
|||
&spec,
|
||||
&pre,
|
||||
post_root,
|
||||
&env_info,
|
||||
&test_env,
|
||||
transaction,
|
||||
display::std_json::Informant::new_default(config),
|
||||
trie_spec,
|
||||
|
@ -268,7 +278,7 @@ fn run_state_test(args: Args) {
|
|||
&spec,
|
||||
&pre,
|
||||
post_root,
|
||||
&env_info,
|
||||
&test_env,
|
||||
transaction,
|
||||
display::simple::Informant::new(config),
|
||||
trie_spec,
|
||||
|
@ -429,6 +439,7 @@ fn die<T: fmt::Display>(msg: T) -> ! {
|
|||
mod tests {
|
||||
use super::{Args, USAGE};
|
||||
use docopt::Docopt;
|
||||
use ethereum_types::Address;
|
||||
|
||||
fn run<T: AsRef<str>>(args: &[T]) -> Args {
|
||||
Docopt::new(USAGE)
|
||||
|
@ -468,8 +479,8 @@ mod tests {
|
|||
assert_eq!(args.flag_std_out_only, true);
|
||||
assert_eq!(args.gas(), Ok(1.into()));
|
||||
assert_eq!(args.gas_price(), Ok(2.into()));
|
||||
assert_eq!(args.from(), Ok(3.into()));
|
||||
assert_eq!(args.to(), Ok(4.into()));
|
||||
assert_eq!(args.from(), Ok(Address::from_low_u64_be(3)));
|
||||
assert_eq!(args.to(), Ok(Address::from_low_u64_be(4)));
|
||||
assert_eq!(args.code(), Ok(Some(vec![05])));
|
||||
assert_eq!(args.data(), Ok(Some(vec![06])));
|
||||
assert_eq!(args.flag_chain, Some("./testfile".to_owned()));
|
|
@ -14,7 +14,7 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use params::SpecType;
|
||||
use crate::params::SpecType;
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
@ -53,9 +53,11 @@ pub fn execute(_cmd: AccountCmd) -> Result<String, String> {
|
|||
#[cfg(feature = "accounts")]
|
||||
mod command {
|
||||
use super::*;
|
||||
use accounts::{AccountProvider, AccountProviderSettings};
|
||||
use crate::{
|
||||
accounts::{AccountProvider, AccountProviderSettings},
|
||||
helpers::{password_from_file, password_prompt},
|
||||
};
|
||||
use ethstore::{accounts_dir::RootDiskDirectory, import_account, import_accounts, EthStore};
|
||||
use helpers::{password_from_file, password_prompt};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn execute(cmd: AccountCmd) -> Result<String, String> {
|
|
@ -16,11 +16,12 @@
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use crypto::publickey;
|
||||
use dir::Directories;
|
||||
use ethereum_types::Address;
|
||||
use ethereum_types::{Address, H160};
|
||||
use ethkey::Password;
|
||||
|
||||
use params::{AccountsConfig, SpecType};
|
||||
use crate::params::{AccountsConfig, SpecType};
|
||||
|
||||
#[cfg(not(feature = "accounts"))]
|
||||
mod accounts {
|
||||
|
@ -70,9 +71,10 @@ mod accounts {
|
|||
#[cfg(feature = "accounts")]
|
||||
mod accounts {
|
||||
use super::*;
|
||||
use upgrade::upgrade_key_location;
|
||||
use crate::{ethereum_types::H256, upgrade::upgrade_key_location};
|
||||
use std::str::FromStr;
|
||||
|
||||
pub use accounts::AccountProvider;
|
||||
pub use crate::accounts::AccountProvider;
|
||||
|
||||
/// Pops along with error messages when a password is missing or invalid.
|
||||
const VERIFY_PASSWORD_HINT: &str = "Make sure valid password is present in files passed using `--password` or in the configuration file.";
|
||||
|
@ -85,7 +87,7 @@ mod accounts {
|
|||
cfg: AccountsConfig,
|
||||
passwords: &[Password],
|
||||
) -> Result<AccountProvider, String> {
|
||||
use accounts::AccountProviderSettings;
|
||||
use crate::accounts::AccountProviderSettings;
|
||||
use ethstore::{accounts_dir::RootDiskDirectory, EthStore};
|
||||
|
||||
let path = dirs.keys_path(data_dir);
|
||||
|
@ -103,7 +105,8 @@ mod accounts {
|
|||
| SpecType::Goerli
|
||||
| SpecType::Sokol
|
||||
| SpecType::Dev => vec![],
|
||||
_ => vec!["00a329c0648769a73afac7f9381e08fb43dbea72".into()],
|
||||
_ => vec![H160::from_str("00a329c0648769a73afac7f9381e08fb43dbea72")
|
||||
.expect("the string is valid hex; qed")],
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -195,7 +198,8 @@ mod accounts {
|
|||
engine_signer,
|
||||
password.clone(),
|
||||
);
|
||||
if signer.sign(Default::default()).is_ok() {
|
||||
// sign dummy msg to check if password and account can be used.
|
||||
if signer.sign(H256::from_low_u64_be(1)).is_ok() {
|
||||
author = Some(::ethcore::miner::Author::Sealer(Box::new(signer)));
|
||||
}
|
||||
}
|
||||
|
@ -216,9 +220,11 @@ mod accounts {
|
|||
}
|
||||
|
||||
fn insert_dev_account(account_provider: &AccountProvider) {
|
||||
let secret: ethkey::Secret =
|
||||
"4d5db4107d237df6a3d58ee5f70ae63d73d7658d4026f2eefd2f204c81682cb7".into();
|
||||
let dev_account = ethkey::KeyPair::from_secret(secret.clone())
|
||||
let secret = publickey::Secret::from_str(
|
||||
"4d5db4107d237df6a3d58ee5f70ae63d73d7658d4026f2eefd2f204c81682cb7",
|
||||
)
|
||||
.expect("Valid account;qed");
|
||||
let dev_account = publickey::KeyPair::from_secret(secret.clone())
|
||||
.expect("Valid secret produces valid key;qed");
|
||||
if !account_provider.has_account(dev_account.address()) {
|
||||
match account_provider.insert_account(secret, &Password::from(String::new())) {
|
|
@ -16,10 +16,18 @@
|
|||
|
||||
use std::{fs, io, sync::Arc, time::Instant};
|
||||
|
||||
use crate::{
|
||||
bytes::ToPretty,
|
||||
cache::CacheConfig,
|
||||
db,
|
||||
hash::{keccak, KECCAK_NULL_RLP},
|
||||
helpers::{execute_upgrades, to_client_config},
|
||||
informant::{FullNodeInformantData, Informant, MillisecondDuration},
|
||||
params::{fatdb_switch_to_bool, tracing_switch_to_bool, Pruning, SpecType, Switch},
|
||||
types::data_format::DataFormat,
|
||||
user_defaults::UserDefaults,
|
||||
};
|
||||
use ansi_term::Colour;
|
||||
use bytes::ToPretty;
|
||||
use cache::CacheConfig;
|
||||
use db;
|
||||
use dir::Directories;
|
||||
use ethcore::{
|
||||
client::{
|
||||
|
@ -31,12 +39,6 @@ use ethcore::{
|
|||
};
|
||||
use ethcore_service::ClientService;
|
||||
use ethereum_types::{Address, H256, U256};
|
||||
use hash::{keccak, KECCAK_NULL_RLP};
|
||||
use helpers::{execute_upgrades, to_client_config};
|
||||
use informant::{FullNodeInformantData, Informant, MillisecondDuration};
|
||||
use params::{fatdb_switch_to_bool, tracing_switch_to_bool, Pruning, SpecType, Switch};
|
||||
use types::data_format::DataFormat;
|
||||
use user_defaults::UserDefaults;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum BlockchainCmd {
|
|
@ -248,7 +248,7 @@ usage! {
|
|||
|
||||
ARG arg_chain: (String) = "foundation", or |c: &Config| c.parity.as_ref()?.chain.clone(),
|
||||
"--chain=[CHAIN]",
|
||||
"Specify the blockchain type. CHAIN may be either a JSON chain specification file or ethereum, poacore, xdai, volta, ewc, musicoin, ellaism, mix, callisto, morden, ropsten, kovan, rinkeby, goerli, poasokol, testnet, or dev.",
|
||||
"Specify the blockchain type. CHAIN may be either a JSON chain specification file or ethereum, poacore, xdai, volta, ewc, musicoin, ellaism, mix, callisto, morden, ropsten, kovan, rinkeby, goerli, poasokol, testnet, yolo3 or dev.",
|
||||
|
||||
ARG arg_keys_path: (String) = "$BASE/keys", or |c: &Config| c.parity.as_ref()?.keys_path.clone(),
|
||||
"--keys-path=[PATH]",
|
||||
|
@ -409,9 +409,9 @@ usage! {
|
|||
"--jsonrpc-interface=[IP]",
|
||||
"Specify the hostname portion of the HTTP JSON-RPC API server, IP should be an interface's IP address, or all (all interfaces) or local.",
|
||||
|
||||
ARG arg_jsonrpc_apis: (String) = "web3,eth,pubsub,net,parity,parity_pubsub,traces", or |c: &Config| c.rpc.as_ref()?.apis.as_ref().map(|vec| vec.join(",")),
|
||||
ARG arg_jsonrpc_apis: (String) = "web3,eth,pubsub,net,parity,parity_pubsub,traces,rpc", or |c: &Config| c.rpc.as_ref()?.apis.as_ref().map(|vec| vec.join(",")),
|
||||
"--jsonrpc-apis=[APIS]",
|
||||
"Specify the APIs available through the HTTP JSON-RPC interface using a comma-delimited list of API names. Possible names are: all, safe, debug, web3, net, eth, pubsub, personal, signer, parity, parity_pubsub, parity_accounts, parity_set, traces, secretstore. You can also disable a specific API by putting '-' in the front, example: all,-personal. 'safe' enables the following APIs: web3, net, eth, pubsub, parity, parity_pubsub, traces",
|
||||
"Specify the APIs available through the HTTP JSON-RPC interface using a comma-delimited list of API names. Possible names are: all, safe, debug, web3, net, eth, pubsub, personal, signer, parity, parity_pubsub, parity_accounts, parity_set, traces, rpc, secretstore. You can also disable a specific API by putting '-' in the front, example: all,-personal. 'safe' enables the following APIs: web3, net, eth, pubsub, parity, parity_pubsub, traces, rpc",
|
||||
|
||||
ARG arg_jsonrpc_hosts: (String) = "none", or |c: &Config| c.rpc.as_ref()?.hosts.as_ref().map(|vec| vec.join(",")),
|
||||
"--jsonrpc-hosts=[HOSTS]",
|
||||
|
@ -450,9 +450,9 @@ usage! {
|
|||
"--ws-interface=[IP]",
|
||||
"Specify the hostname portion of the WebSockets JSON-RPC server, IP should be an interface's IP address, or all (all interfaces) or local.",
|
||||
|
||||
ARG arg_ws_apis: (String) = "web3,eth,pubsub,net,parity,parity_pubsub,traces", or |c: &Config| c.websockets.as_ref()?.apis.as_ref().map(|vec| vec.join(",")),
|
||||
ARG arg_ws_apis: (String) = "web3,eth,pubsub,net,parity,parity_pubsub,traces,rpc", or |c: &Config| c.websockets.as_ref()?.apis.as_ref().map(|vec| vec.join(",")),
|
||||
"--ws-apis=[APIS]",
|
||||
"Specify the JSON-RPC APIs available through the WebSockets interface using a comma-delimited list of API names. Possible names are: all, safe, web3, net, eth, pubsub, personal, signer, parity, parity_pubsub, parity_accounts, parity_set, traces, secretstore. You can also disable a specific API by putting '-' in the front, example: all,-personal. 'safe' enables the following APIs: web3, net, eth, pubsub, parity, parity_pubsub, traces",
|
||||
"Specify the JSON-RPC APIs available through the WebSockets interface using a comma-delimited list of API names. Possible names are: all, safe, web3, net, eth, pubsub, personal, signer, parity, parity_pubsub, parity_accounts, parity_set, traces, rpc, secretstore. You can also disable a specific API by putting '-' in the front, example: all,-personal. 'safe' enables the following APIs: web3, net, eth, pubsub, parity, parity_pubsub, traces, rpc",
|
||||
|
||||
ARG arg_ws_origins: (String) = "parity://*,chrome-extension://*,moz-extension://*", or |c: &Config| c.websockets.as_ref()?.origins.as_ref().map(|vec| vec.join(",")),
|
||||
"--ws-origins=[URL]",
|
||||
|
@ -475,6 +475,10 @@ usage! {
|
|||
"--metrics",
|
||||
"Enable prometheus metrics (only full client).",
|
||||
|
||||
ARG arg_metrics_prefix: (String) = "", or |c: &Config| c.metrics.as_ref()?.prefix.clone(),
|
||||
"--metrics-prefix=[prefix]",
|
||||
"Prepend the specified prefix to the exported metrics names.",
|
||||
|
||||
ARG arg_metrics_port: (u16) = 3000u16, or |c: &Config| c.metrics.as_ref()?.port.clone(),
|
||||
"--metrics-port=[PORT]",
|
||||
"Specify the port portion of the metrics server.",
|
||||
|
@ -492,9 +496,9 @@ usage! {
|
|||
"--ipc-path=[PATH]",
|
||||
"Specify custom path for JSON-RPC over IPC service.",
|
||||
|
||||
ARG arg_ipc_apis: (String) = "web3,eth,pubsub,net,parity,parity_pubsub,parity_accounts,traces", or |c: &Config| c.ipc.as_ref()?.apis.as_ref().map(|vec| vec.join(",")),
|
||||
ARG arg_ipc_apis: (String) = "web3,eth,pubsub,net,parity,parity_pubsub,parity_accounts,traces,rpc", or |c: &Config| c.ipc.as_ref()?.apis.as_ref().map(|vec| vec.join(",")),
|
||||
"--ipc-apis=[APIS]",
|
||||
"Specify custom API set available via JSON-RPC over IPC using a comma-delimited list of API names. Possible names are: all, safe, web3, net, eth, pubsub, personal, signer, parity, parity_pubsub, parity_accounts, parity_set, traces, secretstore. You can also disable a specific API by putting '-' in the front, example: all,-personal. 'safe' enables the following APIs: web3, net, eth, pubsub, parity, parity_pubsub, traces",
|
||||
"Specify custom API set available via JSON-RPC over IPC using a comma-delimited list of API names. Possible names are: all, safe, web3, net, eth, pubsub, personal, signer, parity, parity_pubsub, parity_accounts, parity_set, traces, rpc, secretstore. You can also disable a specific API by putting '-' in the front, example: all,-personal. 'safe' enables the following APIs: web3, net, eth, pubsub, parity, parity_pubsub, traces, rpc",
|
||||
|
||||
["Secret Store Options"]
|
||||
FLAG flag_no_secretstore: (bool) = false, or |c: &Config| c.secretstore.as_ref()?.disable.clone(),
|
||||
|
@ -676,7 +680,7 @@ usage! {
|
|||
|
||||
ARG arg_min_gas_price: (Option<u64>) = None, or |c: &Config| c.mining.as_ref()?.min_gas_price.clone(),
|
||||
"--min-gas-price=[STRING]",
|
||||
"Minimum amount of Wei per GAS to be paid for a transaction to be accepted for mining. Overrides --usd-per-tx.",
|
||||
"Minimum amount of Wei per GAS to be paid for a transaction on top of base fee, to be accepted for mining. Overrides --usd-per-tx.",
|
||||
|
||||
ARG arg_gas_price_percentile: (usize) = 50usize, or |c: &Config| c.mining.as_ref()?.gas_price_percentile,
|
||||
"--gas-price-percentile=[PCT]",
|
||||
|
@ -922,6 +926,7 @@ struct Ipc {
|
|||
#[serde(deny_unknown_fields)]
|
||||
struct Metrics {
|
||||
enable: Option<bool>,
|
||||
prefix: Option<String>,
|
||||
port: Option<u16>,
|
||||
interface: Option<String>,
|
||||
}
|
||||
|
@ -1312,7 +1317,7 @@ mod tests {
|
|||
arg_jsonrpc_port: 8545u16,
|
||||
arg_jsonrpc_interface: "local".into(),
|
||||
arg_jsonrpc_cors: "null".into(),
|
||||
arg_jsonrpc_apis: "web3,eth,net,parity,traces,secretstore".into(),
|
||||
arg_jsonrpc_apis: "web3,eth,net,parity,traces,rpc,secretstore".into(),
|
||||
arg_jsonrpc_hosts: "none".into(),
|
||||
arg_jsonrpc_server_threads: None,
|
||||
arg_jsonrpc_threads: 4,
|
||||
|
@ -1324,7 +1329,7 @@ mod tests {
|
|||
flag_no_ws: false,
|
||||
arg_ws_port: 8546u16,
|
||||
arg_ws_interface: "local".into(),
|
||||
arg_ws_apis: "web3,eth,net,parity,traces,secretstore".into(),
|
||||
arg_ws_apis: "web3,eth,net,parity,traces,rpc,secretstore".into(),
|
||||
arg_ws_origins: "none".into(),
|
||||
arg_ws_hosts: "none".into(),
|
||||
arg_ws_max_connections: 100,
|
||||
|
@ -1333,11 +1338,12 @@ mod tests {
|
|||
// IPC
|
||||
flag_no_ipc: false,
|
||||
arg_ipc_path: "$HOME/.parity/jsonrpc.ipc".into(),
|
||||
arg_ipc_apis: "web3,eth,net,parity,parity_accounts,personal,traces,secretstore"
|
||||
arg_ipc_apis: "web3,eth,net,parity,parity_accounts,personal,traces,rpc,secretstore"
|
||||
.into(),
|
||||
|
||||
// METRICS
|
||||
flag_metrics: false,
|
||||
arg_metrics_prefix: "".into(),
|
||||
arg_metrics_port: 3000u16,
|
||||
arg_metrics_interface: "local".into(),
|
||||
|
||||
|
@ -1542,6 +1548,7 @@ mod tests {
|
|||
}),
|
||||
metrics: Some(Metrics {
|
||||
enable: Some(true),
|
||||
prefix: Some("oe".to_string()),
|
||||
interface: Some("local".to_string()),
|
||||
port: Some(4000),
|
||||
}),
|
|
@ -39,7 +39,7 @@ disable = false
|
|||
port = 8545
|
||||
interface = "local"
|
||||
cors = ["null"]
|
||||
apis = ["web3", "eth", "net", "parity", "traces", "secretstore"]
|
||||
apis = ["web3", "eth", "net", "parity", "traces", "rpc", "secretstore"]
|
||||
hosts = ["none"]
|
||||
allow_missing_blocks = false
|
||||
|
||||
|
@ -48,13 +48,13 @@ disable = false
|
|||
port = 8546
|
||||
interface = "local"
|
||||
origins = ["none"]
|
||||
apis = ["web3", "eth", "net", "parity", "traces", "secretstore"]
|
||||
apis = ["web3", "eth", "net", "parity", "traces", "rpc", "secretstore"]
|
||||
hosts = ["none"]
|
||||
|
||||
[ipc]
|
||||
disable = false
|
||||
path = "$HOME/.parity/jsonrpc.ipc"
|
||||
apis = ["web3", "eth", "net", "parity", "parity_accounts", "personal", "traces", "secretstore"]
|
||||
apis = ["web3", "eth", "net", "parity", "parity_accounts", "personal", "traces", "rpc", "secretstore"]
|
||||
|
||||
[secretstore]
|
||||
disable = false
|
|
@ -36,7 +36,7 @@ apis = ["rpc", "eth"]
|
|||
enable = true
|
||||
interface = "local"
|
||||
port = 4000
|
||||
|
||||
prefix = "oe"
|
||||
|
||||
[secretstore]
|
||||
http_port = 8082
|
|
@ -14,9 +14,17 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{
|
||||
bytes::Bytes,
|
||||
cli::{Args, ArgsError},
|
||||
hash::keccak,
|
||||
metrics::MetricsConfiguration,
|
||||
miner::pool,
|
||||
sync::{self, validate_node_url, NetworkConfiguration},
|
||||
};
|
||||
use ansi_term::Colour;
|
||||
use bytes::Bytes;
|
||||
use cli::{Args, ArgsError};
|
||||
|
||||
use crypto::publickey::{Public, Secret};
|
||||
use ethcore::{
|
||||
client::VMType,
|
||||
miner::{stratum, MinerOptions},
|
||||
|
@ -24,10 +32,7 @@ use ethcore::{
|
|||
verification::queue::VerifierSettings,
|
||||
};
|
||||
use ethereum_types::{Address, H256, U256};
|
||||
use ethkey::{Public, Secret};
|
||||
use hash::keccak;
|
||||
use metrics::MetricsConfiguration;
|
||||
use miner::pool;
|
||||
|
||||
use num_cpus;
|
||||
use parity_version::{version, version_data};
|
||||
use std::{
|
||||
|
@ -40,35 +45,37 @@ use std::{
|
|||
path::PathBuf,
|
||||
time::Duration,
|
||||
};
|
||||
use sync::{self, validate_node_url, NetworkConfiguration};
|
||||
|
||||
use account::{AccountCmd, ImportAccounts, ListAccounts, NewAccount};
|
||||
use blockchain::{
|
||||
BlockchainCmd, ExportBlockchain, ExportState, ImportBlockchain, KillBlockchain, ResetBlockchain,
|
||||
use crate::{
|
||||
account::{AccountCmd, ImportAccounts, ListAccounts, NewAccount},
|
||||
blockchain::{
|
||||
BlockchainCmd, ExportBlockchain, ExportState, ImportBlockchain, KillBlockchain,
|
||||
ResetBlockchain,
|
||||
},
|
||||
cache::CacheConfig,
|
||||
helpers::{
|
||||
parity_ipc_path, to_address, to_addresses, to_block_id, to_bootnodes, to_duration, to_mode,
|
||||
to_pending_set, to_price, to_queue_penalization, to_queue_strategy, to_u256,
|
||||
},
|
||||
network::IpFilter,
|
||||
params::{AccountsConfig, GasPricerConfig, MinerExtras, ResealPolicy, SpecType},
|
||||
presale::ImportWallet,
|
||||
rpc::{HttpConfiguration, IpcConfiguration, WsConfiguration},
|
||||
run::RunCmd,
|
||||
secretstore::{
|
||||
Configuration as SecretStoreConfiguration, ContractAddress as SecretStoreContractAddress,
|
||||
NodeSecretKey,
|
||||
},
|
||||
snapshot::{self, SnapshotCommand},
|
||||
types::data_format::DataFormat,
|
||||
};
|
||||
use cache::CacheConfig;
|
||||
use dir::{
|
||||
self, default_data_path, default_local_path,
|
||||
helpers::{replace_home, replace_home_and_local},
|
||||
Directories,
|
||||
};
|
||||
use ethcore_logger::Config as LogConfig;
|
||||
use helpers::{
|
||||
parity_ipc_path, to_address, to_addresses, to_block_id, to_bootnodes, to_duration, to_mode,
|
||||
to_pending_set, to_price, to_queue_penalization, to_queue_strategy, to_u256,
|
||||
};
|
||||
use network::IpFilter;
|
||||
use params::{AccountsConfig, GasPricerConfig, MinerExtras, ResealPolicy, SpecType};
|
||||
use parity_rpc::NetworkSettings;
|
||||
use presale::ImportWallet;
|
||||
use rpc::{HttpConfiguration, IpcConfiguration, WsConfiguration};
|
||||
use run::RunCmd;
|
||||
use secretstore::{
|
||||
Configuration as SecretStoreConfiguration, ContractAddress as SecretStoreContractAddress,
|
||||
NodeSecretKey,
|
||||
};
|
||||
use snapshot::{self, SnapshotCommand};
|
||||
use types::data_format::DataFormat;
|
||||
|
||||
const DEFAULT_MAX_PEERS: u16 = 50;
|
||||
const DEFAULT_MIN_PEERS: u16 = 25;
|
||||
|
@ -166,7 +173,7 @@ impl Configuration {
|
|||
let cmd = if self.args.flag_version {
|
||||
Cmd::Version
|
||||
} else if self.args.cmd_signer {
|
||||
let authfile = ::signer::codes_path(&ws_conf.signer_path);
|
||||
let authfile = crate::signer::codes_path(&ws_conf.signer_path);
|
||||
|
||||
if self.args.cmd_signer_new_token {
|
||||
Cmd::SignerToken(ws_conf, logger_config.clone())
|
||||
|
@ -518,10 +525,8 @@ impl Configuration {
|
|||
}
|
||||
|
||||
fn ip_filter(&self) -> Result<IpFilter, String> {
|
||||
match IpFilter::parse(self.args.arg_allow_ips.as_str()) {
|
||||
Ok(allow_ip) => Ok(allow_ip),
|
||||
Err(_) => Err("Invalid IP filter value".to_owned()),
|
||||
}
|
||||
IpFilter::parse(self.args.arg_allow_ips.as_str())
|
||||
.map_err(|_| "Invalid IP filter value".to_owned())
|
||||
}
|
||||
|
||||
fn min_peers(&self) -> u32 {
|
||||
|
@ -635,14 +640,16 @@ impl Configuration {
|
|||
|
||||
fn pool_verification_options(&self) -> Result<pool::verifier::Options, String> {
|
||||
Ok(pool::verifier::Options {
|
||||
// NOTE min_gas_price and block_gas_limit will be overwritten right after start.
|
||||
// NOTE min_gas_price,block_gas_limit block_base_fee, and allow_non_eoa_sender will be overwritten right after start.
|
||||
minimal_gas_price: U256::from(20_000_000) * 1_000u32,
|
||||
block_gas_limit: U256::max_value(),
|
||||
block_base_fee: None,
|
||||
tx_gas_limit: match self.args.arg_tx_gas_limit {
|
||||
Some(ref d) => to_u256(d)?,
|
||||
None => U256::max_value(),
|
||||
},
|
||||
no_early_reject: self.args.flag_tx_queue_no_early_reject,
|
||||
allow_non_eoa_sender: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -812,7 +819,7 @@ impl Configuration {
|
|||
ret.public_address = public.map(|p| format!("{}", p));
|
||||
ret.use_secret = match self.args.arg_node_key.as_ref().map(|s| {
|
||||
s.parse::<Secret>()
|
||||
.or_else(|_| Secret::from_unsafe_slice(&keccak(s)))
|
||||
.or_else(|_| Secret::import_key(keccak(s).as_bytes()))
|
||||
.map_err(|e| format!("Invalid key: {:?}", e))
|
||||
}) {
|
||||
None => None,
|
||||
|
@ -960,6 +967,7 @@ impl Configuration {
|
|||
fn metrics_config(&self) -> Result<MetricsConfiguration, String> {
|
||||
let conf = MetricsConfiguration {
|
||||
enabled: self.metrics_enabled(),
|
||||
prefix: self.metrics_prefix(),
|
||||
interface: self.metrics_interface(),
|
||||
port: self.args.arg_ports_shift + self.args.arg_metrics_port,
|
||||
};
|
||||
|
@ -1149,6 +1157,10 @@ impl Configuration {
|
|||
self.args.flag_metrics
|
||||
}
|
||||
|
||||
fn metrics_prefix(&self) -> String {
|
||||
self.args.arg_metrics_prefix.clone()
|
||||
}
|
||||
|
||||
fn secretstore_enabled(&self) -> bool {
|
||||
!self.args.flag_no_secretstore && cfg!(feature = "secretstore")
|
||||
}
|
||||
|
@ -1240,23 +1252,25 @@ fn into_secretstore_service_contract_address(
|
|||
mod tests {
|
||||
use std::{fs::File, io::Write, str::FromStr};
|
||||
|
||||
use account::{AccountCmd, ImportAccounts, ListAccounts, NewAccount};
|
||||
use blockchain::{BlockchainCmd, ExportBlockchain, ExportState, ImportBlockchain};
|
||||
use cli::Args;
|
||||
use crate::{
|
||||
account::{AccountCmd, ImportAccounts, ListAccounts, NewAccount},
|
||||
blockchain::{BlockchainCmd, ExportBlockchain, ExportState, ImportBlockchain},
|
||||
cli::Args,
|
||||
helpers::default_network_config,
|
||||
miner::pool::PrioritizationStrategy,
|
||||
params::SpecType,
|
||||
presale::ImportWallet,
|
||||
rpc::WsConfiguration,
|
||||
rpc_apis::ApiSet,
|
||||
run::RunCmd,
|
||||
types::{data_format::DataFormat, ids::BlockId},
|
||||
};
|
||||
use dir::Directories;
|
||||
use ethcore::{client::VMType, miner::MinerOptions};
|
||||
use helpers::default_network_config;
|
||||
use miner::pool::PrioritizationStrategy;
|
||||
use params::SpecType;
|
||||
use parity_rpc::NetworkSettings;
|
||||
use presale::ImportWallet;
|
||||
use rpc::WsConfiguration;
|
||||
use rpc_apis::ApiSet;
|
||||
use run::RunCmd;
|
||||
use tempdir::TempDir;
|
||||
use types::{data_format::DataFormat, ids::BlockId};
|
||||
|
||||
use network::{AllowIP, IpFilter};
|
||||
use crate::network::{AllowIP, IpFilter};
|
||||
|
||||
extern crate ipnetwork;
|
||||
use self::ipnetwork::IpNetwork;
|
||||
|
@ -1743,7 +1757,7 @@ mod tests {
|
|||
ApiSet::List(set) => assert_eq!(set, ApiSet::All.list_apis()),
|
||||
_ => panic!("Incorrect rpc apis"),
|
||||
}
|
||||
// "web3,eth,net,personal,parity,parity_set,traces,parity_accounts");
|
||||
// "web3,eth,net,personal,parity,parity_set,traces,rpc,parity_accounts");
|
||||
assert_eq!(c.http_conf.hosts, None);
|
||||
}
|
||||
_ => panic!("Should be Cmd::Run"),
|
||||
|
@ -1764,7 +1778,7 @@ mod tests {
|
|||
ApiSet::List(set) => assert_eq!(set, ApiSet::All.list_apis()),
|
||||
_ => panic!("Incorrect rpc apis"),
|
||||
}
|
||||
// "web3,eth,net,personal,parity,parity_set,traces,parity_accounts");
|
||||
// "web3,eth,net,personal,parity,parity_set,traces,rpc,parity_accounts");
|
||||
assert_eq!(c.http_conf.hosts, None);
|
||||
}
|
||||
_ => panic!("Should be Cmd::Run"),
|
|
@ -24,7 +24,8 @@ use self::{
|
|||
};
|
||||
use blooms_db;
|
||||
use ethcore::client::ClientConfig;
|
||||
use kvdb::KeyValueDB;
|
||||
use ethcore_db::KeyValueDB;
|
||||
use stats::PrometheusMetrics;
|
||||
use std::{fs, io, path::Path, sync::Arc};
|
||||
|
||||
mod blooms;
|
||||
|
@ -53,6 +54,10 @@ impl BlockChainDB for AppDB {
|
|||
}
|
||||
}
|
||||
|
||||
impl PrometheusMetrics for AppDB {
|
||||
fn prometheus_metrics(&self, _: &mut stats::PrometheusRegistry) {}
|
||||
}
|
||||
|
||||
/// Open a secret store DB using the given secret store data path. The DB path is one level beneath the data path.
|
||||
#[cfg(feature = "secretstore")]
|
||||
pub fn open_secretstore_db(data_path: &str) -> Result<Arc<dyn KeyValueDB>, String> {
|
||||
|
@ -101,8 +106,11 @@ pub fn open_database(
|
|||
fs::create_dir_all(&blooms_path)?;
|
||||
fs::create_dir_all(&trace_blooms_path)?;
|
||||
|
||||
let db = Database::open(&config, client_path)?;
|
||||
let db_with_metrics = ethcore_db::DatabaseWithMetrics::new(db);
|
||||
|
||||
let db = AppDB {
|
||||
key_value: Arc::new(Database::open(&config, client_path)?),
|
||||
key_value: Arc::new(db_with_metrics),
|
||||
blooms: blooms_db::Database::open(blooms_path)?,
|
||||
trace_blooms: blooms_db::Database::open(trace_blooms_path)?,
|
||||
};
|
|
@ -14,17 +14,21 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use cache::CacheConfig;
|
||||
use db::migrate;
|
||||
use crate::{
|
||||
cache::CacheConfig,
|
||||
db::migrate,
|
||||
miner::pool::PrioritizationStrategy,
|
||||
sync::{self, validate_node_url},
|
||||
upgrade::{upgrade, upgrade_data_paths},
|
||||
};
|
||||
use dir::{helpers::replace_home, DatabaseDirectories};
|
||||
use ethcore::{
|
||||
client::{BlockId, ClientConfig, DatabaseCompactionProfile, Mode, VMType, VerifierType},
|
||||
miner::{Penalization, PendingSet},
|
||||
};
|
||||
use ethereum_types::{clean_0x, Address, U256};
|
||||
use ethereum_types::{Address, U256};
|
||||
use ethkey::Password;
|
||||
use journaldb::Algorithm;
|
||||
use miner::pool::PrioritizationStrategy;
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
fs::File,
|
||||
|
@ -32,13 +36,19 @@ use std::{
|
|||
io::{BufRead, BufReader, Write},
|
||||
time::Duration,
|
||||
};
|
||||
use sync::{self, validate_node_url};
|
||||
use upgrade::{upgrade, upgrade_data_paths};
|
||||
|
||||
pub fn to_duration(s: &str) -> Result<Duration, String> {
|
||||
to_seconds(s).map(Duration::from_secs)
|
||||
}
|
||||
|
||||
fn clean_0x(s: &str) -> &str {
|
||||
if s.starts_with("0x") {
|
||||
&s[2..]
|
||||
} else {
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
fn to_seconds(s: &str) -> Result<u64, String> {
|
||||
let bad = |_| {
|
||||
format!(
|
||||
|
@ -105,10 +115,10 @@ pub fn to_block_id(s: &str) -> Result<BlockId, String> {
|
|||
pub fn to_u256(s: &str) -> Result<U256, String> {
|
||||
if let Ok(decimal) = U256::from_dec_str(s) {
|
||||
Ok(decimal)
|
||||
} else if let Ok(hex) = clean_0x(s).parse() {
|
||||
Ok(hex)
|
||||
} else {
|
||||
Err(format!("Invalid numeric value: {}", s))
|
||||
clean_0x(s)
|
||||
.parse()
|
||||
.map_err(|_| format!("Invalid numeric value: {}", s))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,15 +181,12 @@ pub fn to_price(s: &str) -> Result<f32, String> {
|
|||
}
|
||||
|
||||
pub fn join_set(set: Option<&HashSet<String>>) -> Option<String> {
|
||||
match set {
|
||||
Some(s) => Some(
|
||||
s.iter()
|
||||
.map(|s| s.as_str())
|
||||
.collect::<Vec<&str>>()
|
||||
.join(","),
|
||||
),
|
||||
None => None,
|
||||
}
|
||||
set.map(|s| {
|
||||
s.iter()
|
||||
.map(|s| s.as_str())
|
||||
.collect::<Vec<&str>>()
|
||||
.join(",")
|
||||
})
|
||||
}
|
||||
|
||||
/// Flush output buffer.
|
||||
|
@ -218,9 +225,9 @@ pub fn to_bootnodes(bootnodes: &Option<String>) -> Result<Vec<String>, String> {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn default_network_config() -> ::sync::NetworkConfiguration {
|
||||
pub fn default_network_config() -> crate::sync::NetworkConfiguration {
|
||||
use super::network::IpFilter;
|
||||
use sync::NetworkConfiguration;
|
||||
use crate::sync::NetworkConfiguration;
|
||||
NetworkConfiguration {
|
||||
config_path: Some(replace_home(&::dir::default_data_path(), "$BASE/network")),
|
||||
net_config_path: None,
|
|
@ -29,6 +29,11 @@ use std::{
|
|||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
io::{IoContext, IoHandler, TimerToken},
|
||||
sync::{ManageNetwork, SyncProvider},
|
||||
types::BlockNumber,
|
||||
};
|
||||
use atty;
|
||||
use ethcore::{
|
||||
client::{
|
||||
|
@ -37,12 +42,9 @@ use ethcore::{
|
|||
},
|
||||
snapshot::{service::Service as SnapshotService, RestorationStatus, SnapshotService as SS},
|
||||
};
|
||||
use io::{IoContext, IoHandler, TimerToken};
|
||||
use number_prefix::{binary_prefix, Prefixed, Standalone};
|
||||
use parity_rpc::{informant::RpcStats, is_major_importing_or_waiting};
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use sync::{ManageNetwork, SyncProvider};
|
||||
use types::BlockNumber;
|
||||
|
||||
/// Format byte counts to standard denominations.
|
||||
pub fn format_bytes(b: usize) -> String {
|
||||
|
@ -224,7 +226,14 @@ impl<T: InformantData> Informant<T> {
|
|||
|
||||
pub fn tick(&self) {
|
||||
let now = Instant::now();
|
||||
let elapsed = now.duration_since(*self.last_tick.read());
|
||||
let elapsed;
|
||||
{
|
||||
let last_tick = self.last_tick.read();
|
||||
if now < *last_tick + Duration::from_millis(1500) {
|
||||
return;
|
||||
}
|
||||
elapsed = now - *last_tick;
|
||||
}
|
||||
|
||||
let (client_report, full_report) = {
|
||||
let last_report = self.last_report.lock();
|
|
@ -61,13 +61,13 @@ extern crate keccak_hash as hash;
|
|||
extern crate kvdb;
|
||||
extern crate node_filter;
|
||||
extern crate parity_bytes as bytes;
|
||||
extern crate parity_crypto as crypto;
|
||||
extern crate parity_local_store as local_store;
|
||||
extern crate parity_path as path;
|
||||
extern crate parity_rpc;
|
||||
extern crate parity_runtime;
|
||||
extern crate parity_version;
|
||||
extern crate prometheus;
|
||||
extern crate registrar;
|
||||
extern crate stats;
|
||||
|
||||
#[macro_use]
|
||||
|
@ -114,9 +114,11 @@ mod user_defaults;
|
|||
|
||||
use std::{fs::File, io::BufReader, sync::Arc};
|
||||
|
||||
use cli::Args;
|
||||
use configuration::{Cmd, Execute};
|
||||
use hash::keccak_buffer;
|
||||
use crate::{
|
||||
cli::Args,
|
||||
configuration::{Cmd, Execute},
|
||||
hash::keccak_buffer,
|
||||
};
|
||||
|
||||
#[cfg(feature = "memory_profiling")]
|
||||
use std::alloc::System;
|
|
@ -12,6 +12,6 @@ atty = "0.2"
|
|||
lazy_static = "1.0"
|
||||
regex = "1.0"
|
||||
time = "0.1"
|
||||
parking_lot = "0.7"
|
||||
parking_lot = "0.11.1"
|
||||
arrayvec = "0.4"
|
||||
ansi_term = "0.10"
|
|
@ -157,10 +157,11 @@ pub fn setup_log(config: &Config) -> Result<Arc<RotatingLogger>, String> {
|
|||
Ok(logs)
|
||||
})
|
||||
// couldn't create new logger - try to fall back on previous logger.
|
||||
.or_else(|err| match ROTATING_LOGGER.lock().upgrade() {
|
||||
Some(l) => Ok(l),
|
||||
// no previous logger. fatal.
|
||||
None => Err(format!("{:?}", err)),
|
||||
.or_else(|err| {
|
||||
ROTATING_LOGGER
|
||||
.lock()
|
||||
.upgrade()
|
||||
.ok_or_else(|| format!("{:?}", err))
|
||||
})
|
||||
}
|
||||
|
|
@ -8,13 +8,15 @@ use hyper::{service::service_fn_ok, Body, Method, Request, Response, Server, Sta
|
|||
|
||||
use stats::{
|
||||
prometheus::{self, Encoder},
|
||||
prometheus_gauge, PrometheusMetrics,
|
||||
PrometheusMetrics, PrometheusRegistry,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct MetricsConfiguration {
|
||||
/// Are metrics enabled (default is false)?
|
||||
pub enabled: bool,
|
||||
/// Prefix
|
||||
pub prefix: String,
|
||||
/// The IP of the network interface used (default is 127.0.0.1).
|
||||
pub interface: String,
|
||||
/// The network port (default is 3000).
|
||||
|
@ -25,6 +27,7 @@ impl Default for MetricsConfiguration {
|
|||
fn default() -> Self {
|
||||
MetricsConfiguration {
|
||||
enabled: false,
|
||||
prefix: "".into(),
|
||||
interface: "127.0.0.1".into(),
|
||||
port: 3000,
|
||||
}
|
||||
|
@ -35,19 +38,22 @@ struct State {
|
|||
rpc_apis: Arc<rpc_apis::FullDependencies>,
|
||||
}
|
||||
|
||||
fn handle_request(req: Request<Body>, state: Arc<Mutex<State>>) -> Response<Body> {
|
||||
fn handle_request(
|
||||
req: Request<Body>,
|
||||
conf: Arc<MetricsConfiguration>,
|
||||
state: Arc<Mutex<State>>,
|
||||
) -> Response<Body> {
|
||||
let (parts, _body) = req.into_parts();
|
||||
match (parts.method, parts.uri.path()) {
|
||||
(Method::GET, "/metrics") => {
|
||||
let start = Instant::now();
|
||||
|
||||
let mut reg = prometheus::Registry::new();
|
||||
let mut reg = PrometheusRegistry::new(conf.prefix.clone());
|
||||
let state = state.lock();
|
||||
state.rpc_apis.client.prometheus_metrics(&mut reg);
|
||||
state.rpc_apis.sync.prometheus_metrics(&mut reg);
|
||||
let elapsed = start.elapsed();
|
||||
prometheus_gauge(
|
||||
&mut reg,
|
||||
reg.register_gauge(
|
||||
"metrics_time",
|
||||
"Time to perform rpc metrics",
|
||||
elapsed.as_millis() as i64,
|
||||
|
@ -55,7 +61,7 @@ fn handle_request(req: Request<Body>, state: Arc<Mutex<State>>) -> Response<Body
|
|||
|
||||
let mut buffer = vec![];
|
||||
let encoder = prometheus::TextEncoder::new();
|
||||
let metric_families = reg.gather();
|
||||
let metric_families = reg.registry().gather();
|
||||
|
||||
encoder
|
||||
.encode(&metric_families, &mut buffer)
|
||||
|
@ -90,17 +96,20 @@ pub fn start_prometheus_metrics(
|
|||
rpc_apis: deps.apis.clone(),
|
||||
};
|
||||
let state = Arc::new(Mutex::new(state));
|
||||
|
||||
let conf = Arc::new(conf.to_owned());
|
||||
let server = Server::bind(&addr)
|
||||
.serve(move || {
|
||||
// This is the `Service` that will handle the connection.
|
||||
// `service_fn_ok` is a helper to convert a function that
|
||||
// returns a Response into a `Service`.
|
||||
let state = state.clone();
|
||||
service_fn_ok(move |req: Request<Body>| handle_request(req, state.clone()))
|
||||
let conf = conf.clone();
|
||||
service_fn_ok(move |req: Request<Body>| {
|
||||
handle_request(req, conf.clone(), state.clone())
|
||||
})
|
||||
})
|
||||
.map_err(|e| eprintln!("server error: {}", e));
|
||||
println!("Listening on http://{}", addr);
|
||||
info!("Started prometeus metrics at http://{}/metrics", addr);
|
||||
|
||||
deps.executor.spawn(server);
|
||||
|
|
@ -16,14 +16,16 @@
|
|||
|
||||
use std::sync::{mpsc, Arc};
|
||||
|
||||
use crate::{
|
||||
sync::{self, ConnectionFilter, NetworkConfiguration, Params, SyncConfig},
|
||||
types::BlockNumber,
|
||||
};
|
||||
use ethcore::{client::BlockChainClient, snapshot::SnapshotService};
|
||||
use std::collections::BTreeSet;
|
||||
use sync::{self, ConnectionFilter, NetworkConfiguration, Params, SyncConfig};
|
||||
use types::BlockNumber;
|
||||
|
||||
pub use crate::sync::{EthSync, ManageNetwork, SyncProvider};
|
||||
pub use ethcore::client::ChainNotify;
|
||||
use ethcore_logger::Config as LogConfig;
|
||||
pub use sync::{EthSync, ManageNetwork, SyncProvider};
|
||||
|
||||
pub type SyncModules = (
|
||||
Arc<dyn SyncProvider>,
|
|
@ -16,6 +16,13 @@
|
|||
|
||||
use std::{collections::HashSet, fmt, fs, num::NonZeroU32, str, time::Duration};
|
||||
|
||||
use crate::{
|
||||
miner::{
|
||||
gas_price_calibrator::{GasPriceCalibrator, GasPriceCalibratorOptions},
|
||||
gas_pricer::GasPricer,
|
||||
},
|
||||
user_defaults::UserDefaults,
|
||||
};
|
||||
use ethcore::{
|
||||
client::Mode,
|
||||
ethereum,
|
||||
|
@ -24,13 +31,8 @@ use ethcore::{
|
|||
use ethereum_types::{Address, U256};
|
||||
use fetch::Client as FetchClient;
|
||||
use journaldb::Algorithm;
|
||||
use miner::{
|
||||
gas_price_calibrator::{GasPriceCalibrator, GasPriceCalibratorOptions},
|
||||
gas_pricer::GasPricer,
|
||||
};
|
||||
use parity_runtime::Executor;
|
||||
use parity_version::version_data;
|
||||
use user_defaults::UserDefaults;
|
||||
|
||||
use crate::configuration;
|
||||
|
||||
|
@ -51,6 +53,7 @@ pub enum SpecType {
|
|||
Rinkeby,
|
||||
Goerli,
|
||||
Sokol,
|
||||
Yolo3,
|
||||
Dev,
|
||||
Custom(String),
|
||||
}
|
||||
|
@ -81,6 +84,7 @@ impl str::FromStr for SpecType {
|
|||
"rinkeby" => SpecType::Rinkeby,
|
||||
"goerli" | "görli" | "testnet" => SpecType::Goerli,
|
||||
"sokol" | "poasokol" => SpecType::Sokol,
|
||||
"yolo3" => SpecType::Yolo3,
|
||||
"dev" => SpecType::Dev,
|
||||
other => SpecType::Custom(other.into()),
|
||||
};
|
||||
|
@ -106,6 +110,7 @@ impl fmt::Display for SpecType {
|
|||
SpecType::Rinkeby => "rinkeby",
|
||||
SpecType::Goerli => "goerli",
|
||||
SpecType::Sokol => "sokol",
|
||||
SpecType::Yolo3 => "yolo3",
|
||||
SpecType::Dev => "dev",
|
||||
SpecType::Custom(ref custom) => custom,
|
||||
})
|
||||
|
@ -131,6 +136,7 @@ impl SpecType {
|
|||
SpecType::Rinkeby => Ok(ethereum::new_rinkeby(params)),
|
||||
SpecType::Goerli => Ok(ethereum::new_goerli(params)),
|
||||
SpecType::Sokol => Ok(ethereum::new_sokol(params)),
|
||||
SpecType::Yolo3 => Ok(ethereum::new_yolo3(params)),
|
||||
SpecType::Dev => Ok(Spec::new_instant()),
|
||||
SpecType::Custom(ref filename) => {
|
||||
let file = fs::File::open(filename).map_err(|e| {
|
||||
|
@ -370,8 +376,8 @@ pub fn mode_switch_to_bool(
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{tracing_switch_to_bool, Pruning, ResealPolicy, SpecType, Switch};
|
||||
use crate::user_defaults::UserDefaults;
|
||||
use journaldb::Algorithm;
|
||||
use user_defaults::UserDefaults;
|
||||
|
||||
#[test]
|
||||
fn test_spec_type_parsing() {
|
|
@ -14,10 +14,14 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{
|
||||
helpers::{password_from_file, password_prompt},
|
||||
params::SpecType,
|
||||
};
|
||||
use crypto::publickey;
|
||||
|
||||
use ethkey::Password;
|
||||
use ethstore::PresaleWallet;
|
||||
use helpers::{password_from_file, password_prompt};
|
||||
use params::SpecType;
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
@ -44,7 +48,8 @@ pub fn execute(cmd: ImportWallet) -> Result<String, String> {
|
|||
}
|
||||
|
||||
#[cfg(feature = "accounts")]
|
||||
pub fn import_account(cmd: &ImportWallet, kp: ethkey::KeyPair, password: Password) {
|
||||
|
||||
pub fn import_account(cmd: &ImportWallet, kp: publickey::KeyPair, password: Password) {
|
||||
use accounts::{AccountProvider, AccountProviderSettings};
|
||||
use ethstore::{accounts_dir::RootDiskDirectory, EthStore};
|
||||
|
||||
|
@ -57,4 +62,4 @@ pub fn import_account(cmd: &ImportWallet, kp: ethkey::KeyPair, password: Passwor
|
|||
}
|
||||
|
||||
#[cfg(not(feature = "accounts"))]
|
||||
pub fn import_account(_cmd: &ImportWallet, _kp: ethkey::KeyPair, _password: Password) {}
|
||||
pub fn import_account(_cmd: &ImportWallet, _kp: publickey::KeyPair, _password: Password) {}
|
|
@ -16,8 +16,11 @@
|
|||
|
||||
use std::{collections::HashSet, io, path::PathBuf, sync::Arc};
|
||||
|
||||
use crate::{
|
||||
helpers::parity_ipc_path,
|
||||
rpc_apis::{self, ApiSet},
|
||||
};
|
||||
use dir::{default_data_path, helpers::replace_home};
|
||||
use helpers::parity_ipc_path;
|
||||
use jsonrpc_core::MetaIoHandler;
|
||||
use parity_rpc::{
|
||||
self as rpc,
|
||||
|
@ -25,7 +28,6 @@ use parity_rpc::{
|
|||
DomainsValidation, Metadata,
|
||||
};
|
||||
use parity_runtime::Executor;
|
||||
use rpc_apis::{self, ApiSet};
|
||||
|
||||
pub use parity_rpc::{HttpServer, IpcServer, RequestMiddleware};
|
||||
//pub use parity_rpc::ws::Server as WsServer;
|
||||
|
@ -182,7 +184,7 @@ pub fn new_ws<D: rpc_apis::Dependencies>(
|
|||
let signer_path;
|
||||
let path = match conf.support_token_api {
|
||||
true => {
|
||||
signer_path = ::signer::codes_path(&conf.signer_path);
|
||||
signer_path = crate::signer::codes_path(&conf.signer_path);
|
||||
Some(signer_path.as_path())
|
||||
}
|
||||
false => None,
|
|
@ -14,16 +14,24 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::{cmp::PartialEq, collections::HashSet, str::FromStr, sync::Arc};
|
||||
use std::{
|
||||
cmp::PartialEq,
|
||||
collections::{BTreeMap, HashSet},
|
||||
str::FromStr,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
pub use parity_rpc::signer::SignerService;
|
||||
|
||||
use account_utils::{self, AccountProvider};
|
||||
use crate::{
|
||||
account_utils::{self, AccountProvider},
|
||||
miner::external::ExternalMiner,
|
||||
sync::{ManageNetwork, SyncProvider},
|
||||
};
|
||||
use ethcore::{client::Client, miner::Miner, snapshot::SnapshotService};
|
||||
use ethcore_logger::RotatingLogger;
|
||||
use fetch::Client as FetchClient;
|
||||
use jsonrpc_core::{self as core, MetaIoHandler};
|
||||
use miner::external::ExternalMiner;
|
||||
use parity_rpc::{
|
||||
dispatch::FullDispatcher,
|
||||
informant::{ActivityNotifier, ClientNotifier},
|
||||
|
@ -31,7 +39,6 @@ use parity_rpc::{
|
|||
};
|
||||
use parity_runtime::Executor;
|
||||
use parking_lot::Mutex;
|
||||
use sync::{ManageNetwork, SyncProvider};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Eq, Hash)]
|
||||
pub enum Api {
|
||||
|
@ -51,6 +58,8 @@ pub enum Api {
|
|||
Parity,
|
||||
/// Traces (Safe)
|
||||
Traces,
|
||||
/// Rpc (Safe)
|
||||
Rpc,
|
||||
/// Parity PubSub - Generic Publish-Subscriber (Safety depends on other APIs exposed).
|
||||
ParityPubSub,
|
||||
/// Parity Accounts extensions (UNSAFE: Passwords, Side Effects (new account))
|
||||
|
@ -80,6 +89,7 @@ impl FromStr for Api {
|
|||
"parity_set" => Ok(ParitySet),
|
||||
"personal" => Ok(Personal),
|
||||
"pubsub" => Ok(EthPubSub),
|
||||
"rpc" => Ok(Rpc),
|
||||
"secretstore" => Ok(SecretStore),
|
||||
"signer" => Ok(Signer),
|
||||
"traces" => Ok(Traces),
|
||||
|
@ -146,6 +156,30 @@ impl FromStr for ApiSet {
|
|||
}
|
||||
}
|
||||
|
||||
fn to_modules(apis: &HashSet<Api>) -> BTreeMap<String, String> {
|
||||
let mut modules = BTreeMap::new();
|
||||
for api in apis {
|
||||
let (name, version) = match *api {
|
||||
Api::Debug => ("debug", "1.0"),
|
||||
Api::Eth => ("eth", "1.0"),
|
||||
Api::EthPubSub => ("pubsub", "1.0"),
|
||||
Api::Net => ("net", "1.0"),
|
||||
Api::Parity => ("parity", "1.0"),
|
||||
Api::ParityAccounts => ("parity_accounts", "1.0"),
|
||||
Api::ParityPubSub => ("parity_pubsub", "1.0"),
|
||||
Api::ParitySet => ("parity_set", "1.0"),
|
||||
Api::Personal => ("personal", "1.0"),
|
||||
Api::Rpc => ("rpc", "1.0"),
|
||||
Api::SecretStore => ("secretstore", "1.0"),
|
||||
Api::Signer => ("signer", "1.0"),
|
||||
Api::Traces => ("traces", "1.0"),
|
||||
Api::Web3 => ("web3", "1.0"),
|
||||
};
|
||||
modules.insert(name.into(), version.into());
|
||||
}
|
||||
modules
|
||||
}
|
||||
|
||||
macro_rules! add_signing_methods {
|
||||
($namespace:ident, $handler:expr, $deps:expr, $dispatch:expr) => {{
|
||||
let deps = &$deps;
|
||||
|
@ -376,6 +410,10 @@ impl FullDependencies {
|
|||
);
|
||||
}
|
||||
Api::Traces => handler.extend_with(TracesClient::new(&self.client).to_delegate()),
|
||||
Api::Rpc => {
|
||||
let modules = to_modules(&apis);
|
||||
handler.extend_with(RpcClient::new(modules).to_delegate());
|
||||
}
|
||||
Api::SecretStore => {
|
||||
#[cfg(feature = "accounts")]
|
||||
handler.extend_with(SecretStoreClient::new(&self.accounts).to_delegate());
|
||||
|
@ -409,11 +447,17 @@ impl ApiSet {
|
|||
}
|
||||
|
||||
pub fn list_apis(&self) -> HashSet<Api> {
|
||||
let mut public_list: HashSet<Api> =
|
||||
[Api::Web3, Api::Net, Api::Eth, Api::EthPubSub, Api::Parity]
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect();
|
||||
let mut public_list: HashSet<Api> = [
|
||||
Api::Web3,
|
||||
Api::Net,
|
||||
Api::Eth,
|
||||
Api::EthPubSub,
|
||||
Api::Parity,
|
||||
Api::Rpc,
|
||||
]
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
match *self {
|
||||
ApiSet::List(ref apis) => apis.clone(),
|
||||
|
@ -470,6 +514,7 @@ mod test {
|
|||
assert_eq!(Api::ParityAccounts, "parity_accounts".parse().unwrap());
|
||||
assert_eq!(Api::ParitySet, "parity_set".parse().unwrap());
|
||||
assert_eq!(Api::Traces, "traces".parse().unwrap());
|
||||
assert_eq!(Api::Rpc, "rpc".parse().unwrap());
|
||||
assert_eq!(Api::SecretStore, "secretstore".parse().unwrap());
|
||||
assert!("rp".parse::<Api>().is_err());
|
||||
}
|
||||
|
@ -498,6 +543,7 @@ mod test {
|
|||
Api::Parity,
|
||||
Api::ParityPubSub,
|
||||
Api::Traces,
|
||||
Api::Rpc,
|
||||
]
|
||||
.into_iter()
|
||||
.collect();
|
||||
|
@ -515,6 +561,7 @@ mod test {
|
|||
Api::Parity,
|
||||
Api::ParityPubSub,
|
||||
Api::Traces,
|
||||
Api::Rpc,
|
||||
// semi-safe
|
||||
Api::ParityAccounts,
|
||||
]
|
||||
|
@ -536,6 +583,7 @@ mod test {
|
|||
Api::Parity,
|
||||
Api::ParityPubSub,
|
||||
Api::Traces,
|
||||
Api::Rpc,
|
||||
Api::SecretStore,
|
||||
Api::ParityAccounts,
|
||||
Api::ParitySet,
|
||||
|
@ -562,6 +610,7 @@ mod test {
|
|||
Api::Parity,
|
||||
Api::ParityPubSub,
|
||||
Api::Traces,
|
||||
Api::Rpc,
|
||||
Api::SecretStore,
|
||||
Api::ParityAccounts,
|
||||
Api::ParitySet,
|
||||
|
@ -587,6 +636,7 @@ mod test {
|
|||
Api::Parity,
|
||||
Api::ParityPubSub,
|
||||
Api::Traces,
|
||||
Api::Rpc,
|
||||
]
|
||||
.into_iter()
|
||||
.collect()
|
|
@ -16,15 +16,30 @@
|
|||
|
||||
use std::{
|
||||
any::Any,
|
||||
str::FromStr,
|
||||
sync::{atomic, Arc, Weak},
|
||||
thread,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use account_utils;
|
||||
use crate::{
|
||||
account_utils,
|
||||
cache::CacheConfig,
|
||||
db,
|
||||
helpers::{execute_upgrades, passwords_from_files, to_client_config},
|
||||
informant::{FullNodeInformantData, Informant},
|
||||
metrics::{start_prometheus_metrics, MetricsConfiguration},
|
||||
miner::{external::ExternalMiner, work_notify::WorkPoster},
|
||||
modules,
|
||||
params::{
|
||||
fatdb_switch_to_bool, mode_switch_to_bool, tracing_switch_to_bool, AccountsConfig,
|
||||
GasPricerConfig, MinerExtras, Pruning, SpecType, Switch,
|
||||
},
|
||||
rpc, rpc_apis, secretstore, signer,
|
||||
sync::{self, SyncConfig},
|
||||
user_defaults::UserDefaults,
|
||||
};
|
||||
use ansi_term::Colour;
|
||||
use cache::CacheConfig;
|
||||
use db;
|
||||
use dir::{DatabaseDirectories, Directories};
|
||||
use ethcore::{
|
||||
client::{BlockChainClient, BlockInfo, Client, DatabaseCompactionProfile, Mode, VMType},
|
||||
|
@ -34,37 +49,22 @@ use ethcore::{
|
|||
};
|
||||
use ethcore_logger::{Config as LogConfig, RotatingLogger};
|
||||
use ethcore_service::ClientService;
|
||||
use ethereum_types::H256;
|
||||
use helpers::{execute_upgrades, passwords_from_files, to_client_config};
|
||||
use informant::{FullNodeInformantData, Informant};
|
||||
use ethereum_types::{H256, U64};
|
||||
use journaldb::Algorithm;
|
||||
use jsonrpc_core;
|
||||
use metrics::{start_prometheus_metrics, MetricsConfiguration};
|
||||
use miner::{external::ExternalMiner, work_notify::WorkPoster};
|
||||
use modules;
|
||||
use node_filter::NodeFilter;
|
||||
use params::{
|
||||
fatdb_switch_to_bool, mode_switch_to_bool, tracing_switch_to_bool, AccountsConfig,
|
||||
GasPricerConfig, MinerExtras, Pruning, SpecType, Switch,
|
||||
};
|
||||
use parity_rpc::{
|
||||
informant, is_major_importing, FutureOutput, FutureResponse, FutureResult, Metadata,
|
||||
NetworkSettings, Origin, PubSubSession,
|
||||
};
|
||||
use parity_runtime::Runtime;
|
||||
use parity_version::version;
|
||||
use rpc;
|
||||
use rpc_apis;
|
||||
use secretstore;
|
||||
use signer;
|
||||
use sync::{self, SyncConfig};
|
||||
use user_defaults::UserDefaults;
|
||||
|
||||
// how often to take periodic snapshots.
|
||||
const SNAPSHOT_PERIOD: u64 = 5000;
|
||||
// How often we attempt to take a snapshot: only snapshot on blocknumbers that are multiples of this.
|
||||
const SNAPSHOT_PERIOD: u64 = 20000;
|
||||
|
||||
// how many blocks to wait before starting a periodic snapshot.
|
||||
const SNAPSHOT_HISTORY: u64 = 100;
|
||||
// Start snapshoting from `tip`-`history, with this we want to bypass reorgs. Should be smaller than prunning history.
|
||||
const SNAPSHOT_HISTORY: u64 = 50;
|
||||
|
||||
// Full client number of DNS threads
|
||||
const FETCH_FULL_NUM_DNS_THREADS: usize = 4;
|
||||
|
@ -119,8 +119,8 @@ struct FullNodeInfo {
|
|||
miner: Option<Arc<Miner>>, // TODO: only TXQ needed, just use that after decoupling.
|
||||
}
|
||||
|
||||
impl ::local_store::NodeInfo for FullNodeInfo {
|
||||
fn pending_transactions(&self) -> Vec<::types::transaction::PendingTransaction> {
|
||||
impl crate::local_store::NodeInfo for FullNodeInfo {
|
||||
fn pending_transactions(&self) -> Vec<crate::types::transaction::PendingTransaction> {
|
||||
let miner = match self.miner.as_ref() {
|
||||
Some(m) => m,
|
||||
None => return Vec::new(),
|
||||
|
@ -130,7 +130,7 @@ impl ::local_store::NodeInfo for FullNodeInfo {
|
|||
.local_transactions()
|
||||
.values()
|
||||
.filter_map(|status| match *status {
|
||||
::miner::pool::local_transactions::Status::Pending(ref tx) => {
|
||||
crate::miner::pool::local_transactions::Status::Pending(ref tx) => {
|
||||
Some(tx.pending().clone())
|
||||
}
|
||||
_ => None,
|
||||
|
@ -227,12 +227,10 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<RunningClient
|
|||
Some(id) => id,
|
||||
None => spec.network_id(),
|
||||
};
|
||||
if spec.subprotocol_name().len() != 3 {
|
||||
warn!("Your chain specification's subprotocol length is not 3. Ignoring.");
|
||||
if spec.subprotocol_name().len() > 8 {
|
||||
warn!("Your chain specification's subprotocol length is more then 8. Ignoring.");
|
||||
} else {
|
||||
sync_config
|
||||
.subprotocol_name
|
||||
.clone_from_slice(spec.subprotocol_name().as_bytes());
|
||||
sync_config.subprotocol_name = U64::from(spec.subprotocol_name().as_bytes())
|
||||
}
|
||||
|
||||
sync_config.fork_block = spec.fork_block();
|
||||
|
@ -256,6 +254,7 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<RunningClient
|
|||
_ => sync::WarpSync::Disabled,
|
||||
};
|
||||
sync_config.download_old_blocks = cmd.download_old_blocks;
|
||||
sync_config.eip1559_transition = spec.params().eip1559_transition;
|
||||
|
||||
let passwords = passwords_from_files(&cmd.acc_conf.password_files)?;
|
||||
|
||||
|
@ -367,8 +366,18 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<RunningClient
|
|||
|
||||
// take handle to client
|
||||
let client = service.client();
|
||||
// Update miners block gas limit
|
||||
miner.update_transaction_queue_limits(*client.best_block_header().gas_limit());
|
||||
// Update miners block gas limit and base_fee
|
||||
let base_fee = client
|
||||
.engine()
|
||||
.calculate_base_fee(&client.best_block_header());
|
||||
let allow_non_eoa_sender = client
|
||||
.engine()
|
||||
.allow_non_eoa_sender(client.best_block_header().number() + 1);
|
||||
miner.update_transaction_queue_limits(
|
||||
*client.best_block_header().gas_limit(),
|
||||
base_fee,
|
||||
allow_non_eoa_sender,
|
||||
);
|
||||
|
||||
let connection_filter = connection_filter_address.map(|a| {
|
||||
Arc::new(NodeFilter::new(
|
||||
|
@ -388,7 +397,7 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<RunningClient
|
|||
},
|
||||
};
|
||||
|
||||
let store = ::local_store::create(
|
||||
let store = crate::local_store::create(
|
||||
db.key_value().clone(),
|
||||
::ethcore_db::COL_NODE_INFO,
|
||||
node_info,
|
||||
|
@ -452,9 +461,17 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<RunningClient
|
|||
let is_ready = Arc::new(atomic::AtomicBool::new(true));
|
||||
miner.add_transactions_listener(Box::new(move |_hashes| {
|
||||
// we want to have only one PendingTransactions task in the queue.
|
||||
if is_ready.compare_and_swap(true, false, atomic::Ordering::SeqCst) {
|
||||
if is_ready
|
||||
.compare_exchange(
|
||||
true,
|
||||
false,
|
||||
atomic::Ordering::SeqCst,
|
||||
atomic::Ordering::SeqCst,
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
let task =
|
||||
::sync::PriorityTask::PropagateTransactions(Instant::now(), is_ready.clone());
|
||||
crate::sync::PriorityTask::PropagateTransactions(Instant::now(), is_ready.clone());
|
||||
// we ignore error cause it means that we are closing
|
||||
let _ = tx.lock().send(task);
|
||||
}
|
||||
|
@ -600,7 +617,10 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<RunningClient
|
|||
fn verification_bad_blocks(spec: &SpecType) -> Vec<H256> {
|
||||
match *spec {
|
||||
SpecType::Ropsten => {
|
||||
vec!["1eac3d16c642411f13c287e29144c6f58fda859407c8f24c38deb168e1040714".into()]
|
||||
vec![
|
||||
H256::from_str("1eac3d16c642411f13c287e29144c6f58fda859407c8f24c38deb168e1040714")
|
||||
.expect("Valid hex string"),
|
||||
]
|
||||
}
|
||||
_ => vec![],
|
||||
}
|
|
@ -14,14 +14,14 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use account_utils::AccountProvider;
|
||||
use crate::{account_utils::AccountProvider, sync::SyncProvider};
|
||||
use crypto::publickey::{Public, Secret};
|
||||
use dir::{default_data_path, helpers::replace_home};
|
||||
use ethcore::{client::Client, miner::Miner};
|
||||
use ethereum_types::Address;
|
||||
use ethkey::{Password, Public, Secret};
|
||||
use ethkey::Password;
|
||||
use parity_runtime::Executor;
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
use sync::SyncProvider;
|
||||
|
||||
/// This node secret key.
|
||||
#[derive(Debug, PartialEq, Clone)]
|
|
@ -19,12 +19,10 @@ use std::{
|
|||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use crate::{path::restrict_permissions_owner, rpc, rpc_apis};
|
||||
use ansi_term::Colour::White;
|
||||
use ethcore_logger::Config as LogConfig;
|
||||
use parity_rpc;
|
||||
use path::restrict_permissions_owner;
|
||||
use rpc;
|
||||
use rpc_apis;
|
||||
|
||||
pub const CODES_FILENAME: &'static str = "authcodes";
|
||||
|
|
@ -22,6 +22,7 @@ use std::{
|
|||
time::Duration,
|
||||
};
|
||||
|
||||
use crate::{hash::keccak, types::ids::BlockId};
|
||||
use ethcore::{
|
||||
client::{DatabaseCompactionProfile, Mode, VMType},
|
||||
miner::Miner,
|
||||
|
@ -32,15 +33,15 @@ use ethcore::{
|
|||
},
|
||||
};
|
||||
use ethcore_service::ClientService;
|
||||
use hash::keccak;
|
||||
use types::ids::BlockId;
|
||||
|
||||
use cache::CacheConfig;
|
||||
use db;
|
||||
use crate::{
|
||||
cache::CacheConfig,
|
||||
db,
|
||||
helpers::{execute_upgrades, to_client_config},
|
||||
params::{fatdb_switch_to_bool, tracing_switch_to_bool, Pruning, SpecType, Switch},
|
||||
user_defaults::UserDefaults,
|
||||
};
|
||||
use dir::Directories;
|
||||
use helpers::{execute_upgrades, to_client_config};
|
||||
use params::{fatdb_switch_to_bool, tracing_switch_to_bool, Pruning, SpecType, Switch};
|
||||
use user_defaults::UserDefaults;
|
||||
|
||||
/// Kinds of snapshot commands.
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
|
@ -303,7 +304,7 @@ impl SnapshotCommand {
|
|||
let cur_size = p.size();
|
||||
if cur_size != last_size {
|
||||
last_size = cur_size;
|
||||
let bytes = ::informant::format_bytes(cur_size as usize);
|
||||
let bytes = crate::informant::format_bytes(cur_size as usize);
|
||||
info!(
|
||||
"Snapshot: {} accounts {} blocks {}",
|
||||
p.accounts(),
|
|
@ -39,7 +39,7 @@ struct StratumControlService {
|
|||
impl ControlService for StratumControlService {
|
||||
fn shutdown(&self) -> bool {
|
||||
trace!(target: "hypervisor", "Received shutdown from control service");
|
||||
self.stop.store(true, ::std::sync::atomic::Ordering::Relaxed);
|
||||
self.stop.store(true, ::std::sync::atomic::Ordering::SeqCst);
|
||||
true
|
||||
}
|
||||
}
|
|
@ -12,11 +12,12 @@ common-types = { path = "../ethcore/types" }
|
|||
ethkey = { path = "ethkey" }
|
||||
ethstore = { path = "ethstore" }
|
||||
log = "0.4"
|
||||
parking_lot = "0.7"
|
||||
parity-crypto = { version = "0.6.2", features = [ "publickey" ] }
|
||||
parking_lot = "0.11.1"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
ethereum-types = "0.4"
|
||||
ethereum-types = "0.9.2"
|
||||
tempdir = "0.3"
|
|
@ -6,15 +6,15 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
|||
|
||||
[dependencies]
|
||||
edit-distance = "2.0"
|
||||
parity-crypto = "0.3.0"
|
||||
eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1", rev = "ccc06e7480148b723eb44ac56cf4d20eec380b6f" }
|
||||
ethereum-types = "0.4"
|
||||
parity-crypto = { version = "0.6.2", features = ["publickey"] }
|
||||
eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1", rev = "9791e79f21a5309dcb6e0bd254b1ef88fca2f1f4" }
|
||||
ethereum-types = "0.9.2"
|
||||
lazy_static = "1.0"
|
||||
log = "0.4"
|
||||
memzero = { path = "../../util/memzero" }
|
||||
memzero = { path = "../../../crates/util/memzero" }
|
||||
parity-wordlist = "1.3"
|
||||
quick-error = "1.2.2"
|
||||
rand = "0.4"
|
||||
rand = "0.7.3"
|
||||
rustc-hex = "1.0"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
|
@ -14,8 +14,10 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use super::{Generator, KeyPair, Secret};
|
||||
use keccak::Keccak256;
|
||||
use parity_crypto::{
|
||||
publickey::{KeyPair, Secret},
|
||||
Keccak256,
|
||||
};
|
||||
use parity_wordlist;
|
||||
|
||||
/// Simple brainwallet.
|
||||
|
@ -29,12 +31,8 @@ impl Brain {
|
|||
pub fn validate_phrase(phrase: &str, expected_words: usize) -> Result<(), ::WordlistError> {
|
||||
parity_wordlist::validate_phrase(phrase, expected_words)
|
||||
}
|
||||
}
|
||||
|
||||
impl Generator for Brain {
|
||||
type Error = ::Void;
|
||||
|
||||
fn generate(&mut self) -> Result<KeyPair, Self::Error> {
|
||||
pub fn generate(&mut self) -> KeyPair {
|
||||
let seed = self.0.clone();
|
||||
let mut secret = seed.into_bytes().keccak256();
|
||||
|
||||
|
@ -45,12 +43,10 @@ impl Generator for Brain {
|
|||
match i > 16384 {
|
||||
false => i += 1,
|
||||
true => {
|
||||
if let Ok(pair) =
|
||||
Secret::from_unsafe_slice(&secret).and_then(KeyPair::from_secret)
|
||||
{
|
||||
if let Ok(pair) = Secret::import_key(&secret).and_then(KeyPair::from_secret) {
|
||||
if pair.address()[0] == 0 {
|
||||
trace!("Testing: {}, got: {:?}", self.0, pair.address());
|
||||
return Ok(pair);
|
||||
return pair;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,13 +58,12 @@ impl Generator for Brain {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use Brain;
|
||||
use Generator;
|
||||
|
||||
#[test]
|
||||
fn test_brain() {
|
||||
let words = "this is sparta!".to_owned();
|
||||
let first_keypair = Brain::new(words.clone()).generate().unwrap();
|
||||
let second_keypair = Brain::new(words.clone()).generate().unwrap();
|
||||
let first_keypair = Brain::new(words.clone()).generate();
|
||||
let second_keypair = Brain::new(words.clone()).generate();
|
||||
assert_eq!(first_keypair.secret(), second_keypair.secret());
|
||||
}
|
||||
}
|
|
@ -14,7 +14,8 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use super::{Brain, Error, Generator, KeyPair};
|
||||
use super::Brain;
|
||||
use parity_crypto::publickey::{Error, KeyPair};
|
||||
use parity_wordlist as wordlist;
|
||||
|
||||
/// Tries to find brain-seed keypair with address starting with given prefix.
|
||||
|
@ -38,16 +39,12 @@ impl BrainPrefix {
|
|||
pub fn phrase(&self) -> &str {
|
||||
&self.last_phrase
|
||||
}
|
||||
}
|
||||
|
||||
impl Generator for BrainPrefix {
|
||||
type Error = Error;
|
||||
|
||||
fn generate(&mut self) -> Result<KeyPair, Error> {
|
||||
pub fn generate(&mut self) -> Result<KeyPair, Error> {
|
||||
for _ in 0..self.iterations {
|
||||
let phrase = wordlist::random_phrase(self.no_of_words);
|
||||
let keypair = Brain::new(phrase.clone()).generate().unwrap();
|
||||
if keypair.address().starts_with(&self.prefix) {
|
||||
let keypair = Brain::new(phrase.clone()).generate();
|
||||
if keypair.address().as_ref().starts_with(&self.prefix) {
|
||||
self.last_phrase = phrase;
|
||||
return Ok(keypair);
|
||||
}
|
||||
|
@ -60,7 +57,6 @@ impl Generator for BrainPrefix {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use BrainPrefix;
|
||||
use Generator;
|
||||
|
||||
#[test]
|
||||
fn prefix_generator() {
|
||||
|
@ -68,6 +64,6 @@ mod tests {
|
|||
let keypair = BrainPrefix::new(prefix.clone(), usize::max_value(), 12)
|
||||
.generate()
|
||||
.unwrap();
|
||||
assert!(keypair.address().starts_with(&prefix));
|
||||
assert!(keypair.address().as_bytes().starts_with(&prefix));
|
||||
}
|
||||
}
|
|
@ -17,9 +17,10 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use edit_distance::edit_distance;
|
||||
use parity_crypto::publickey::Address;
|
||||
use parity_wordlist;
|
||||
|
||||
use super::{Address, Brain, Generator};
|
||||
use super::Brain;
|
||||
|
||||
/// Tries to find a phrase for address, given the number
|
||||
/// of expected words and a partial phrase.
|
||||
|
@ -32,9 +33,7 @@ pub fn brain_recover(
|
|||
) -> Option<String> {
|
||||
let it = PhrasesIterator::from_known_phrase(known_phrase, expected_words);
|
||||
for phrase in it {
|
||||
let keypair = Brain::new(phrase.clone())
|
||||
.generate()
|
||||
.expect("Brain wallets are infallible; qed");
|
||||
let keypair = Brain::new(phrase.clone()).generate();
|
||||
trace!("Testing: {}, got: {:?}", phrase, keypair.address());
|
||||
if &keypair.address() == address {
|
||||
return Some(phrase);
|
|
@ -14,6 +14,7 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crypto::Error as CryptoError;
|
||||
use std::{error, fmt};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -53,7 +54,7 @@ impl fmt::Display for Error {
|
|||
|
||||
impl error::Error for Error {
|
||||
fn description(&self) -> &str {
|
||||
"Crypto error"
|
||||
format!("{:?}", &self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,6 +64,12 @@ impl Into<String> for Error {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<CryptoError> for Error {
|
||||
fn from(e: CryptoError) -> Error {
|
||||
Error::Custom(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<::secp256k1::Error> for Error {
|
||||
fn from(e: ::secp256k1::Error) -> Error {
|
||||
match e {
|
|
@ -14,14 +14,26 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
extern crate ethabi;
|
||||
extern crate futures;
|
||||
extern crate keccak_hash;
|
||||
// #![warn(missing_docs)]
|
||||
|
||||
extern crate edit_distance;
|
||||
extern crate parity_crypto;
|
||||
extern crate parity_wordlist;
|
||||
extern crate serde;
|
||||
|
||||
#[macro_use]
|
||||
extern crate ethabi_derive;
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate ethabi_contract;
|
||||
extern crate serde_derive;
|
||||
|
||||
mod registrar;
|
||||
pub use registrar::{Asynchronous, Registrar, RegistrarClient, Synchronous};
|
||||
mod brain;
|
||||
mod brain_prefix;
|
||||
mod password;
|
||||
mod prefix;
|
||||
|
||||
pub mod brain_recover;
|
||||
|
||||
pub use self::{
|
||||
brain::Brain, brain_prefix::BrainPrefix, parity_wordlist::Error as WordlistError,
|
||||
password::Password, prefix::Prefix,
|
||||
};
|
|
@ -14,7 +14,7 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use super::{Error, Generator, KeyPair, Random};
|
||||
use parity_crypto::publickey::{Error, Generator, KeyPair, Random};
|
||||
|
||||
/// Tries to find keypair with address starting with given prefix.
|
||||
pub struct Prefix {
|
||||
|
@ -24,20 +24,13 @@ pub struct Prefix {
|
|||
|
||||
impl Prefix {
|
||||
pub fn new(prefix: Vec<u8>, iterations: usize) -> Self {
|
||||
Prefix {
|
||||
prefix: prefix,
|
||||
iterations: iterations,
|
||||
}
|
||||
Prefix { prefix, iterations }
|
||||
}
|
||||
}
|
||||
|
||||
impl Generator for Prefix {
|
||||
type Error = Error;
|
||||
|
||||
fn generate(&mut self) -> Result<KeyPair, Error> {
|
||||
pub fn generate(&mut self) -> Result<KeyPair, Error> {
|
||||
for _ in 0..self.iterations {
|
||||
let keypair = Random.generate()?;
|
||||
if keypair.address().starts_with(&self.prefix) {
|
||||
let keypair = Random.generate();
|
||||
if keypair.address().as_ref().starts_with(&self.prefix) {
|
||||
return Ok(keypair);
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +41,6 @@ impl Generator for Prefix {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use Generator;
|
||||
use Prefix;
|
||||
|
||||
#[test]
|
||||
|
@ -57,6 +49,6 @@ mod tests {
|
|||
let keypair = Prefix::new(prefix.clone(), usize::max_value())
|
||||
.generate()
|
||||
.unwrap();
|
||||
assert!(keypair.address().starts_with(&prefix));
|
||||
assert!(keypair.address().as_bytes().starts_with(&prefix));
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue