@@ -40,6 +40,7 @@ def __getitem__(self, chunk):
40
40
if cached_kv_bytes is not None :
41
41
return cached_kv_bytes
42
42
43
+ # TODO next code must be run only once, LOCK or something
43
44
backup_map = {}
44
45
start = chunk * PAGING
45
46
end = start + PAGING
@@ -216,24 +217,31 @@ def serve_forever(self):
216
217
# theoretically serve timestamp in place of every calendar server which supports this incremental live backup mechanism
217
218
class AskBackup (threading .Thread ):
218
219
219
- def __init__ (self , db , calendar_url , base_path ):
220
+ def __init__ (self , db , calendar_url , base_path , btc_net ):
220
221
self .db = db
221
222
self .calendar_url = calendar_url
222
223
calendar_url_parsed = urlparse (calendar_url )
223
224
self .up_to_path = os .path .join (base_path , calendar_url_parsed .netloc )
225
+ self .btc_net = btc_net
224
226
225
227
super ().__init__ (target = self .loop )
226
228
227
229
def loop (self ):
228
230
logging .info ("Starting loop for %s" % self .calendar_url )
229
231
230
232
try :
233
+ logging .debug ("Opening %s" % self .up_to_path )
231
234
with open (self .up_to_path , 'r' ) as up_to_fd :
232
235
last_known = int (up_to_fd .read ().strip ())
233
236
except FileNotFoundError as exp :
234
237
last_known = - 1
235
238
logging .info ("Checking calendar " + str (self .calendar_url ) + ", last_known commitment:" + str (last_known ))
236
239
240
+ if self .btc_net == 'testnet' :
241
+ bitcoin .SelectParams ('testnet' )
242
+ elif self .btc_net == 'regtest' :
243
+ bitcoin .SelectParams ('regtest' )
244
+
237
245
while True :
238
246
start_time = time .time ()
239
247
backup_url = urljoin (self .calendar_url , "/experimental/backup/%d" % (last_known + 1 ))
0 commit comments