diff --git a/lbry/wallet/header.py b/lbry/wallet/header.py index 2fa066cdf..fd5a85c61 100644 --- a/lbry/wallet/header.py +++ b/lbry/wallet/header.py @@ -136,6 +136,8 @@ class Headers: raise IndexError(f"failed to get {height}, at {len(self)}") def estimated_timestamp(self, height): + if height <= 0: + return return int(self.first_block_timestamp + (height * self.timestamp_average_offset)) def estimated_julian_day(self, height): diff --git a/tests/unit/wallet/test_headers.py b/tests/unit/wallet/test_headers.py index 5ebb333c3..e014f6e46 100644 --- a/tests/unit/wallet/test_headers.py +++ b/tests/unit/wallet/test_headers.py @@ -147,6 +147,12 @@ class TestHeaders(AsyncioTestCase): await headers.repair(start_height=10) self.assertEqual(19, headers.height) + def test_do_not_estimate_unconfirmed(self): + headers = Headers(':memory:') + self.assertIsNone(headers.estimated_timestamp(-1)) + self.assertIsNone(headers.estimated_timestamp(0)) + self.assertIsNotNone(headers.estimated_timestamp(1)) + async def test_misalignment_triggers_repair_on_open(self): headers = Headers(':memory:') headers.io.seek(0)