Merge pull request #2909 from lbryio/none_for_unconfirmed_time

do not estimate timestamp for unconfirmed txs
This commit is contained in:
Lex Berezhny 2020-04-06 11:41:17 -04:00 committed by GitHub
commit d17f0cfa40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View file

@ -136,6 +136,8 @@ class Headers:
raise IndexError(f"failed to get {height}, at {len(self)}") raise IndexError(f"failed to get {height}, at {len(self)}")
def estimated_timestamp(self, height): def estimated_timestamp(self, height):
if height <= 0:
return
return int(self.first_block_timestamp + (height * self.timestamp_average_offset)) return int(self.first_block_timestamp + (height * self.timestamp_average_offset))
def estimated_julian_day(self, height): def estimated_julian_day(self, height):

View file

@ -147,6 +147,12 @@ class TestHeaders(AsyncioTestCase):
await headers.repair(start_height=10) await headers.repair(start_height=10)
self.assertEqual(19, headers.height) 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): async def test_misalignment_triggers_repair_on_open(self):
headers = Headers(':memory:') headers = Headers(':memory:')
headers.io.seek(0) headers.io.seek(0)