From fffc59179f93a6718c4ceee67b014995f950ea4b Mon Sep 17 00:00:00 2001 From: Patrick Strateman Date: Tue, 9 Jun 2015 21:29:36 -0700 Subject: [PATCH 1/2] Limit send-to-sidechain transaction size to avoid un-claimable transactions. --- contrib/sidechain-manipulation.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/contrib/sidechain-manipulation.py b/contrib/sidechain-manipulation.py index a6d5fa54883eb..04e456e71c1ff 100755 --- a/contrib/sidechain-manipulation.py +++ b/contrib/sidechain-manipulation.py @@ -118,7 +118,26 @@ def __init__(self, value): print("Sending %s to %s..." % (sys.argv[3], send_address)) print("(nonce: %s)" % nonce) - txid = bitcoin.sendtoaddress(send_address, Decimal(sys.argv[3])) + try: + tx_hex = bitcoin.createrawtransaction([], {send_address: Decimal(sys.argv[3])}) + tx_hex = bitcoin.fundrawtransaction(tx_hex)['hex'] + tx = bitcoin.signrawtransaction(tx_hex) + assert(tx['complete']) + + tx_hex = tx['hex'] + + total_length = len(tx_hex)/2 + total_length += 14*32 + total_length += 1000 # wild guess + + if total_length >= 10000: + print("Transaction is too large.") + exit(1) + + txid = bitcoin.sendrawtransaction(tx_hex) + except: + txid = bitcoin.sendtoaddress(send_address, Decimal(sys.argv[3])) + print("Sent tx with id %s" % txid) elif sys.argv[1] == "claim-on-sidechain": if len(sys.argv) != 5: From 2319a2e6db0cc60ea0732afe99f82b38c4eef1ad Mon Sep 17 00:00:00 2001 From: Patrick Strateman Date: Thu, 11 Jun 2015 18:32:27 -0700 Subject: [PATCH 2/2] add comments around magic numbers --- contrib/sidechain-manipulation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/sidechain-manipulation.py b/contrib/sidechain-manipulation.py index 04e456e71c1ff..893b531268d22 100755 --- a/contrib/sidechain-manipulation.py +++ b/contrib/sidechain-manipulation.py @@ -127,8 +127,8 @@ def __init__(self, value): tx_hex = tx['hex'] total_length = len(tx_hex)/2 - total_length += 14*32 - total_length += 1000 # wild guess + total_length += 14*32 # maximum length of spv proof 1MB blocks + total_length += 1000 # len(full_contract) + len(secondScriptPubKey) and rounded up to 1000 if total_length >= 10000: print("Transaction is too large.")