From 35cfaaf2d13b29681980e2faa5a66f42c71f9c7d Mon Sep 17 00:00:00 2001 From: Alan Penner Date: Wed, 22 Jan 2014 11:38:06 -0800 Subject: [PATCH] try both hash_hex and block_hex on checking for block submission --- lib/bitcoin_rpc.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/bitcoin_rpc.py b/lib/bitcoin_rpc.py index 938a6f9..89c6113 100644 --- a/lib/bitcoin_rpc.py +++ b/lib/bitcoin_rpc.py @@ -63,7 +63,7 @@ class BitcoinRPC(object): @defer.inlineCallbacks def submitblock(self, block_hex, hash_hex): - #try 5 times? 500 Internal Server Error could mean random error or that TX messages setting is wrong + #try 5 times? 500 Internal Server Error could mean random error or that TX messages setting is wrong attempts = 0 while True: attempts += 1 @@ -75,7 +75,7 @@ class BitcoinRPC(object): log.debug("SUBMITBLOCK RESULT: %s", resp) break except Exception as e: - if attempts > 5: + if attempts > 4: log.exception("submitblock failed. Problem Submitting block %s" % str(e)) log.exception("Try Enabling TX Messages in config.py!") raise @@ -88,7 +88,7 @@ class BitcoinRPC(object): resp = (yield self._call('getblocktemplate', [{'mode': 'submit', 'data': block_hex}])) break except Exception as e: - if attempts > 5: + if attempts > 4: log.exception("getblocktemplate submit failed. Problem Submitting block %s" % str(e)) log.exception("Try Enabling TX Messages in config.py!") raise @@ -107,13 +107,19 @@ class BitcoinRPC(object): resp = (yield self._call('getblocktemplate', [{'mode': 'submit', 'data': block_hex}])) break except Exception as e: - if attempts > 5: + if attempts > 4: log.exception("submitblock failed. Problem Submitting block %s" % str(e)) log.exception("Try Enabling TX Messages in config.py!") raise else: continue + if json.loads(resp)['result'] == None: + # make sure the block was created. + log.info("CHECKING FOR BLOCK AFTER SUBMITBLOCK") + defer.returnValue((yield self.blockexists(hash_hex, scrypt_hex))) + else: + defer.returnValue(False) @defer.inlineCallbacks def getinfo(self):