Skip to content

Commit

Permalink
Support catching up from genesis
Browse files Browse the repository at this point in the history
If the subscriber wants to get caught up since genesis, they can pass the
NULL_BLOCK_IDENTIFIER in last_known_block_ids.

Signed-off-by: Adam Ludvik <[email protected]>
  • Loading branch information
Adam Ludvik committed Nov 14, 2017
1 parent 55c8246 commit 03f1eb3
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions validator/sawtooth_validator/server/events/broadcaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import BlockEventExtractor
from sawtooth_validator.journal.event_extractors \
import ReceiptEventExtractor
from sawtooth_validator.journal.block_wrapper import NULL_BLOCK_IDENTIFIER

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -121,8 +122,10 @@ def get_catchup_blocks(self, last_known_block_id):
# Start from the chain head and get blocks until we reach the
# known block
for block in self._block_store.get_predecessor_iter():
if block.identifier == last_known_block_id:
break
# All the blocks if NULL_BLOCK_IDENTIFIER
if last_known_block_id != NULL_BLOCK_IDENTIFIER:
if block.identifier == last_known_block_id:
break
catchup_up_blocks.append(block)

return list(reversed(catchup_up_blocks))
Expand All @@ -136,12 +139,16 @@ def get_latest_known_block_id(self, last_known_block_ids):
blocks = []
if last_known_block_ids:
for block_id in last_known_block_ids:
try:
block = self._block_store[block_id]
except KeyError:
continue
block_num = block.block_num
blocks.append((block_num, block_id))
# If the subscriber wants all the blocks
if block_id == NULL_BLOCK_IDENTIFIER:
blocks.append((-1, block_id))
else:
try:
block = self._block_store[block_id]
except KeyError:
continue
block_num = block.block_num
blocks.append((block_num, block_id))

# No known blocks in the current chain
if not blocks:
Expand Down

0 comments on commit 03f1eb3

Please sign in to comment.