forked from zcash/zcash
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of zcash#3520 - Eirik0:3327-sign-offline, r=bitcartel
Fix signing raw transactions with unsynced offline nodes This PR address the issue in two different ways: - In `signrawtransaction` we determine the consensus branch ID (which we then later use to construct the transaction) using the chain height. We now also consider the `APPROX_RELEASE_HEIGHT` as this is a better estimation than 0 for the height of the chain if we are unsynced. (This in and of itself solves the Overwinter signing issue). - We have added an additional parameter to `signrawtransaction` to allow manually overriding the consensus branch ID that zcashd determines we are on. This allows users to work around corner cases where the first strategy is still insufficient. Closes zcash#3327.
- Loading branch information
Showing
6 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python2 | ||
|
||
from test_framework.test_framework import BitcoinTestFramework | ||
from test_framework.util import assert_equal, assert_true, initialize_chain_clean, start_node | ||
|
||
class SignOfflineTest (BitcoinTestFramework): | ||
# Setup Methods | ||
def setup_chain(self): | ||
print "Initializing test directory " + self.options.tmpdir | ||
initialize_chain_clean(self.options.tmpdir, 2) | ||
|
||
def setup_network(self): | ||
self.nodes = [ start_node(0, self.options.tmpdir, ["-nuparams=5ba81b19:10"]) ] | ||
self.is_network_split = False | ||
self.sync_all() | ||
|
||
# Tests | ||
def run_test(self): | ||
print "Mining blocks..." | ||
self.nodes[0].generate(101) | ||
|
||
offline_node = start_node(1, self.options.tmpdir, ["-maxconnections=0", "-nuparams=5ba81b19:10"]) | ||
self.nodes.append(offline_node) | ||
|
||
assert_equal(0, len(offline_node.getpeerinfo())) # make sure node 1 has no peers | ||
|
||
privkeys = [self.nodes[0].dumpprivkey(self.nodes[0].getnewaddress())] | ||
taddr = self.nodes[0].getnewaddress() | ||
|
||
tx = self.nodes[0].listunspent()[0] | ||
txid = tx['txid'] | ||
scriptpubkey = tx['scriptPubKey'] | ||
|
||
create_inputs = [{'txid': txid, 'vout': 0}] | ||
sign_inputs = [{'txid': txid, 'vout': 0, 'scriptPubKey': scriptpubkey, 'amount': 10}] | ||
|
||
create_hex = self.nodes[0].createrawtransaction(create_inputs, {taddr: 9.9999}) | ||
|
||
signed_tx = offline_node.signrawtransaction(create_hex, sign_inputs, privkeys) | ||
|
||
# If we return the transaction hash, then we have have not thrown an error (success) | ||
online_tx_hash = self.nodes[0].sendrawtransaction(signed_tx['hex']) | ||
assert_true(len(online_tx_hash) > 0) | ||
|
||
if __name__ == '__main__': | ||
SignOfflineTest().main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters