forked from LBRYCommunity/lbry-sdk
Merge pull request #2909 from lbryio/none_for_unconfirmed_time
do not estimate timestamp for unconfirmed txs
This commit is contained in:
commit
d17f0cfa40
2 changed files with 8 additions and 0 deletions
|
@ -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):
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue