Exemple #1
0
 def _streamer(self):
     # start the stream
     while True:
         current_time = datetime.utcnow()
         if current_time > self._latest_block_time + timedelta(
                 seconds=(BLOCK_TIME_SECS * 10)):
             next_block = self._latest_block + 1
             block = self._fetch_block(next_block)
             self._add_block_to_cache(next_block, block[1])
             SystemStatus.set_sync_status(self._latest_block,
                                          self._latest_block_time,
                                          self.is_behind_schedule())
         if (self._latest_block_time +
                 timedelta(seconds=(BLOCK_TIME_SECS * 20))) < current_time:
             # catchup if behind
             self._fetch_dynamic_global_props()
             self._fetch_multiple_blocks((self._latest_block + 1),
                                         (self._hive_head_block))
         time.sleep(0.3)
Exemple #2
0
 def _feeder(self):
     block_to_push = self._start_block
     while True:
         while block_to_push not in self._cache:
             time.sleep(0.1)
         # check before pushing
         block = self._cache[block_to_push]
         if self._is_valid_block(block_to_push, block):
             self._prev_hash = block['block_id']
         else:
             print("Invalid block detected.")
             os._exit(1)  # TODO: replace with standby
         BlockProcessor.process_block(block_to_push,
                                      self._cache[block_to_push])
         self._latest_block = block_to_push
         self._latest_block_time = datetime.strptime(
             block['timestamp'], UTC_TIMESTAMP_FORMAT)
         SystemStatus.set_sync_status(self._latest_block,
                                      self._latest_block_time,
                                      self.is_behind_schedule())
         self._prune_block(block_to_push)
         block_to_push += 1