mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-20 13:28:20 +02:00
Add sync block range config (#628)
* Add sync block range config * Fix block range config
This commit is contained in:
parent
b26c3ea9df
commit
8c8f777882
3 changed files with 9 additions and 6 deletions
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -262,6 +262,7 @@ def run_node(config):
|
|||
|
||||
sync_controller = SqueakSyncController(
|
||||
squeak_controller,
|
||||
config.sync.block_range,
|
||||
)
|
||||
|
||||
admin_handler = load_admin_handler(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue