This commit is contained in:
Jack Robison 2020-04-01 15:11:45 -04:00
parent 640b5b0ea9
commit 5eafd3bf6b
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 20 additions and 16 deletions

View file

@ -335,9 +335,9 @@ class BlockchainNode:
except asyncio.CancelledError: except asyncio.CancelledError:
self.running.clear() self.running.clear()
raise raise
except: except Exception as e:
self.running.clear() self.running.clear()
log.exception("boom") log.exception('failed to start lbrycrdd', exc_info=e)
async def stop(self, cleanup=True): async def stop(self, cleanup=True):
self.stopped = True self.stopped = True

View file

@ -1,9 +1,7 @@
import logging import logging
import asyncio import asyncio
from binascii import unhexlify
from lbry.testcase import CommandTestCase from lbry.testcase import CommandTestCase
from lbry.wallet.server.prometheus import REORG_COUNT from lbry.wallet.server.prometheus import REORG_COUNT
from lbry.wallet.transaction import Transaction
class BlockchainReorganizationTests(CommandTestCase): class BlockchainReorganizationTests(CommandTestCase):
@ -41,22 +39,27 @@ class BlockchainReorganizationTests(CommandTestCase):
async def test_reorg_dropping_claim(self): async def test_reorg_dropping_claim(self):
# sanity check # sanity check
result_txs, _, _, _ = await self.ledger.claim_search([], name='hovercraft') txos, _, _, _ = await self.ledger.claim_search([], name='hovercraft')
self.assertListEqual(result_txs, []) self.assertListEqual(txos, [])
# create a claim and verify it is returned by claim_search # create a claim and verify it's returned by claim_search
self.assertEqual(self.ledger.headers.height, 206) self.assertEqual(self.ledger.headers.height, 206)
broadcast_tx = Transaction(unhexlify((await self.stream_create(name='hovercraft'))['hex'].encode())) broadcast_tx = await self.daemon.jsonrpc_stream_create(
'hovercraft', '1.0', file_path=self.create_upload_file(data=b'hi!')
)
await self.ledger.wait(broadcast_tx)
await self.generate(1)
await self.ledger.wait(broadcast_tx, self.blockchain.block_expected)
self.assertEqual(self.ledger.headers.height, 207) self.assertEqual(self.ledger.headers.height, 207)
result_txs, _, _, _ = await self.ledger.claim_search([], name='hovercraft') txos, _, _, _ = await self.ledger.claim_search([], name='hovercraft')
self.assertEqual(1, len(result_txs)) self.assertEqual(1, len(txos))
tx = result_txs[0] txo = txos[0]
self.assertEqual(tx.tx_ref.id, broadcast_tx.id) self.assertEqual(txo.tx_ref.id, broadcast_tx.id)
# check that our tx is in block 207 as returned by lbrycrdd # check that our tx is in block 207 as returned by lbrycrdd
invalidated_block_hash = (await self.ledger.headers.hash(207)).decode() invalidated_block_hash = (await self.ledger.headers.hash(207)).decode()
block_207 = await self.blockchain.get_block(invalidated_block_hash) block_207 = await self.blockchain.get_block(invalidated_block_hash)
self.assertIn(tx.tx_ref.id, block_207['tx']) self.assertIn(txo.tx_ref.id, block_207['tx'])
# reorg the last block dropping our claim tx # reorg the last block dropping our claim tx
await self.blockchain.invalidate_block(invalidated_block_hash) await self.blockchain.invalidate_block(invalidated_block_hash)
@ -67,7 +70,7 @@ class BlockchainReorganizationTests(CommandTestCase):
reorg_block_hash = await self.blockchain.get_block_hash(207) reorg_block_hash = await self.blockchain.get_block_hash(207)
self.assertNotEqual(invalidated_block_hash, reorg_block_hash) self.assertNotEqual(invalidated_block_hash, reorg_block_hash)
block_207 = await self.blockchain.get_block(reorg_block_hash) block_207 = await self.blockchain.get_block(reorg_block_hash)
self.assertNotIn(tx.tx_ref.id, block_207['tx']) self.assertNotIn(txo.tx_ref.id, block_207['tx'])
# wait for the client to catch up and verify the reorg # wait for the client to catch up and verify the reorg
await asyncio.wait_for(self.on_header(208), 3.0) await asyncio.wait_for(self.on_header(208), 3.0)
@ -77,5 +80,6 @@ class BlockchainReorganizationTests(CommandTestCase):
client_reorg_block_hash = (await self.ledger.headers.hash(207)).decode() client_reorg_block_hash = (await self.ledger.headers.hash(207)).decode()
self.assertEqual(client_reorg_block_hash, reorg_block_hash) self.assertEqual(client_reorg_block_hash, reorg_block_hash)
result_txs, _, _, _ = await self.ledger.claim_search([], name='hovercraft') # verify the dropped claim is no longer returned by claim search
self.assertListEqual(result_txs, []) txos, _, _, _ = await self.ledger.claim_search([], name='hovercraft')
self.assertListEqual(txos, [])