示例#1
0
    def check_block(self, num, block):
        """Handle a successful or failed block fetch.

        If an expected block was not available, we add a backwards
        drift to the internal schedule. If it was successfully fetched,
        we need to inspect it for missed blocks and adjust our timing
        to account for them."""
        if block:
            self._drift_forward()
            date = block_date(block)
            self._check_missing(num, self._last_date, date)
            self._check_head_date(num, date)
            self._last_date = date
        else:
            self._drift_backward()
            log.info("block %d not available. head:%s drift:%fs", num,
                     self._head_num, self._drift)
def test_block_date():
    block = dict(timestamp='2018-03-16T10:08:42')
    assert block_date(block) == datetime(2018, 3, 16, 10, 8, 42)