ln: check if chain tip is stale when receiving HTLC
if so, don't release preimage / don't forward HTLC
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
# SOFTWARE.
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
from typing import Optional, Dict, Mapping, Sequence
|
||||
|
||||
from . import util
|
||||
@@ -484,6 +485,20 @@ class Blockchain(Logger):
|
||||
height = self.height()
|
||||
return self.read_header(height)
|
||||
|
||||
def is_tip_stale(self) -> bool:
|
||||
STALE_DELAY = 8 * 60 * 60 # in seconds
|
||||
header = self.header_at_tip()
|
||||
if not header:
|
||||
return True
|
||||
# note: We check the timestamp only in the latest header.
|
||||
# The Bitcoin consensus has a lot of leeway here:
|
||||
# - needs to be greater than the median of the timestamps of the past 11 blocks, and
|
||||
# - up to at most 2 hours into the future compared to local clock
|
||||
# so there is ~2 hours of leeway in either direction
|
||||
if header['timestamp'] + STALE_DELAY < time.time():
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_hash(self, height: int) -> str:
|
||||
def is_height_checkpoint():
|
||||
within_cp_range = height <= constants.net.max_checkpoint()
|
||||
|
||||
Reference in New Issue
Block a user