@@ -324,7 +324,7 @@ export class DataStore {
324
324
public static async monitorStoreIndefinitely ( storeId : string ) : Promise < void > {
325
325
// Check if a monitor is already running for this storeId
326
326
if ( this . activeMonitors . get ( storeId ) ) {
327
- console . log ( `Monitor already running for storeId: ${ storeId } ` ) ;
327
+ console . log ( "Monitor:" , `Monitor already running for storeId: ${ storeId } ` ) ;
328
328
return ;
329
329
}
330
330
@@ -338,19 +338,19 @@ export class DataStore {
338
338
} > ( `stores` ) ;
339
339
340
340
// Clear the cache at the start
341
- console . log ( `Clearing cache for storeId: ${ storeId } ` ) ;
341
+ console . log ( "Monitor:" , `Clearing cache for storeId: ${ storeId } ` ) ;
342
342
storeCoinCache . delete ( storeId ) ;
343
343
344
344
while ( true ) {
345
345
try {
346
- console . log ( `Connecting to peer for storeId: ${ storeId } ` ) ;
346
+ console . log ( "Monitor:" , `Connecting to peer for storeId: ${ storeId } ` ) ;
347
347
const peer = await FullNodePeer . connect ( ) ;
348
348
const cachedInfo = storeCoinCache . get ( storeId ) ;
349
349
350
350
if ( cachedInfo ) {
351
351
// Log cached store info retrieval
352
352
console . log (
353
- `Cached store info found for storeId: ${ storeId } , syncing...`
353
+ "Monitor:" , `Cached store info found for storeId: ${ storeId } , syncing...`
354
354
) ;
355
355
356
356
// Deserialize cached info and wait for the coin to be spent
@@ -361,16 +361,20 @@ export class DataStore {
361
361
} ) ;
362
362
363
363
console . log (
364
- `Waiting for coin to be spent for storeId: ${ storeId } ...`
364
+ "Monitor:" , `Waiting for coin to be spent for storeId: ${ storeId } ...`
365
365
) ;
366
+
367
+ const dataStore = DataStore . from ( storeId ) ;
368
+ const { createdAtHeight, createdAtHash } = await dataStore . getCreationHeight ( ) ;
369
+
366
370
await peer . waitForCoinToBeSpent (
367
371
getCoinId ( previousStore . latestStore . coin ) ,
368
- previousStore . latestHeight ,
369
- previousStore . latestHash
372
+ createdAtHeight ,
373
+ createdAtHash
370
374
) ;
371
375
372
376
// Sync store and get updated details
373
- console . log ( `Syncing store for storeId: ${ storeId } ` ) ;
377
+ console . log ( "Monitor:" , `Syncing store for storeId: ${ storeId } ` ) ;
374
378
const { latestStore, latestHeight } = await peer . syncStore (
375
379
previousStore . latestStore ,
376
380
previousStore . latestHeight ,
@@ -386,7 +390,7 @@ export class DataStore {
386
390
latestHash
387
391
) . serialize ( ) ;
388
392
389
- console . log ( `Caching updated store info for storeId: ${ storeId } ` ) ;
393
+ console . log ( "Monitor:" , `Caching updated store info for storeId: ${ storeId } ` ) ;
390
394
storeCoinCache . set ( storeId , {
391
395
latestStore : serializedLatestStore ,
392
396
latestHeight,
@@ -398,14 +402,14 @@ export class DataStore {
398
402
399
403
// If no cached info exists, log and sync from the creation height
400
404
console . log (
401
- `No cached info found for storeId: ${ storeId } . Retrieving creation height.`
405
+ "Monitor:" , `No cached info found for storeId: ${ storeId } . Retrieving creation height.`
402
406
) ;
403
407
404
408
const dataStore = DataStore . from ( storeId ) ;
405
409
const { createdAtHeight, createdAtHash } = await dataStore . getCreationHeight ( ) ;
406
410
407
411
// Sync store from the peer using launcher ID
408
- console . log ( `Syncing store from launcher ID for storeId: ${ storeId } ` ) ;
412
+ console . log ( "Monitor:" , `Syncing store from launcher ID for storeId: ${ storeId } ` ) ;
409
413
const { latestStore, latestHeight } = await peer . syncStoreFromLauncherId (
410
414
Buffer . from ( storeId , "hex" ) ,
411
415
createdAtHeight ,
@@ -422,15 +426,15 @@ export class DataStore {
422
426
latestHash
423
427
) . serialize ( ) ;
424
428
425
- console . log ( `Caching new store info for storeId: ${ storeId } ` ) ;
429
+ console . log ( "Monitor:" , `Caching new store info for storeId: ${ storeId } ` ) ;
426
430
storeCoinCache . set ( storeId , {
427
431
latestStore : serializedLatestStore ,
428
432
latestHeight,
429
433
latestHash : latestHash . toString ( "hex" ) ,
430
434
} ) ;
431
435
} catch ( error : any ) {
432
436
console . error (
433
- `Error in monitorStoreIndefinitely for storeId: ${ storeId } - ${ error . message } `
437
+ "Monitor:" , `Error in monitorStoreIndefinitely for storeId: ${ storeId } - ${ error . message } `
434
438
) ;
435
439
436
440
// Delay before restarting to avoid rapid retries
0 commit comments