Add sync block range config (#628)

* Add sync block range config

* Fix block range config
This commit is contained in:
Jonathan Zernik 2021-01-12 20:03:38 -08:00 committed by GitHub
parent b26c3ea9df
commit 8c8f777882
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View file

@ -35,6 +35,7 @@ DEFAULT_SQK_DIR = ".sqk"
DEFAULT_SQK_DIR_PATH = str(Path.home() / DEFAULT_SQK_DIR)
DEFAULT_LND_HOST = "localhost"
DEFAULT_SYNC_INTERVAL_S = 10
DEFAULT_SYNC_BLOCK_RANGE = 2016
@section('bitcoin')
@ -98,6 +99,8 @@ class CoreConfig(Config):
class SyncConfig(Config):
enabled = key(cast=bool, required=False, default=True)
interval_s = key(cast=int, required=False, default=DEFAULT_SYNC_INTERVAL_S)
block_range = key(cast=int, required=False,
default=DEFAULT_SYNC_BLOCK_RANGE)
@section('db')

View file

@ -262,6 +262,7 @@ def run_node(config):
sync_controller = SqueakSyncController(
squeak_controller,
config.sync.block_range,
)
admin_handler = load_admin_handler(

View file

@ -6,14 +6,13 @@ from squeaknode.sync.network_task import TimelineNetworkSyncTask
logger = logging.getLogger(__name__)
LOOKUP_BLOCK_INTERVAL = 1008 # 1 week
class SqueakSyncController:
def __init__(self, squeak_controller):
def __init__(self, squeak_controller, sync_block_range):
self.squeak_controller = squeak_controller
self.sync_block_range = sync_block_range
def sync_timeline(self):
def sync_timeline(self, block_range=None):
block_range = block_range or self.sync_block_range
try:
block_height = self.squeak_controller.get_best_block_height()
except Exception:
@ -21,7 +20,7 @@ class SqueakSyncController:
"Failed to sync timeline because unable to get best block height.", exc_info=False
)
return
min_block = block_height - LOOKUP_BLOCK_INTERVAL
min_block = block_height - block_range
max_block = block_height
dowload_timeline_task = TimelineNetworkSyncTask(
self.squeak_controller,