[block] Update prevblock with nextblockhash on new bestblockhash

This commit is contained in:
Daniel Edgecumbe 2017-09-28 00:03:58 +01:00
parent 2fdf157182
commit a4dea8dcdd

View File

@ -94,7 +94,23 @@ class BlockStore(object):
async def on_bestblockhash(self, blockhash):
with await self._lock:
self._bestblockhash = blockhash
# TODO: if the previous block exists, update its' nextblockhash
# Pre-fetch it if necessary and update the previous block
# TODO: think about the locking here.
block = await self.get_block(blockhash)
with await self._lock:
try:
prevblock = self._blocks[block["previousblockhash"]]
except KeyError:
return
if "nextblockhash" in prevblock:
if prevblock["nextblockhash"] == blockhash:
return
raise Exception("BlockStore does not handle re-orgs")
prevblock["nextblockhash"] = blockhash
async def get_bestblockhash(self):
with await self._lock: