From 1cbb5e62f2a85d331941ef73d668448e1106816c Mon Sep 17 00:00:00 2001 From: Sergiy Lavrynenko Date: Tue, 24 Jan 2023 17:26:36 +0000 Subject: [PATCH 1/4] ticket-1413 SNB does multiple attempts to download S-Chain descriptions --- npms/skale-observer/observer_worker.js | 27 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/npms/skale-observer/observer_worker.js b/npms/skale-observer/observer_worker.js index 9b799a93d..0f1a55d86 100644 --- a/npms/skale-observer/observer_worker.js +++ b/npms/skale-observer/observer_worker.js @@ -151,16 +151,24 @@ class ObserverServer extends Server { async periodic_caching_do_now( socket, secondsToReDiscoverSkaleNetwork, strChainNameConnectedTo, addressFrom ) { const self = this; if( self.bIsPeriodicCachingStepInProgress ) - return; + return null; self.bIsPeriodicCachingStepInProgress = true; - // const strError = - await skale_observer.cache_schains( - strChainNameConnectedTo, - self.opts.imaState.w3_main_net, - self.opts.imaState.w3_s_chain, - addressFrom, - self.opts - ); + let strError = null; + for( let idxAttempt = 0; idxAttempt < 10; ++ idxAttempt ) { + strError = + await skale_observer.cache_schains( + strChainNameConnectedTo, + self.opts.imaState.w3_main_net, + self.opts.imaState.w3_s_chain, + addressFrom, + self.opts + ); + if( ! strError ) + break; + await sleep( 5 * 1000 ); + } + if( strError ) + return strError; self.bIsPeriodicCachingStepInProgress = false; const arr_schains = skale_observer.get_last_cached_schains(); // self.log( cc.normal( "Got " ) + cc.info( "SKALE NETWORK" ) + cc.normal( " information in worker: " ) + cc.j( arr_schains ) + "\n" ); @@ -171,6 +179,7 @@ class ObserverServer extends Server { }; const isFlush = true; socket.send( jo, isFlush ); + return null; } async periodic_caching_start( socket, secondsToReDiscoverSkaleNetwork, strChainNameConnectedTo, addressFrom ) { const self = this; From 14a7fbc4ace8bb49858f2f6d02f7a6b7279ef80b Mon Sep 17 00:00:00 2001 From: Sergiy Lavrynenko Date: Tue, 24 Jan 2023 17:30:55 +0000 Subject: [PATCH 2/4] ticket-1413 SNB does multiple attempts to download S-Chain descriptions --- npms/skale-observer/observer_worker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/npms/skale-observer/observer_worker.js b/npms/skale-observer/observer_worker.js index 0f1a55d86..fe2b2815c 100644 --- a/npms/skale-observer/observer_worker.js +++ b/npms/skale-observer/observer_worker.js @@ -167,9 +167,9 @@ class ObserverServer extends Server { break; await sleep( 5 * 1000 ); } + self.bIsPeriodicCachingStepInProgress = false; if( strError ) return strError; - self.bIsPeriodicCachingStepInProgress = false; const arr_schains = skale_observer.get_last_cached_schains(); // self.log( cc.normal( "Got " ) + cc.info( "SKALE NETWORK" ) + cc.normal( " information in worker: " ) + cc.j( arr_schains ) + "\n" ); const jo = { From 55bbca24a90a90612b639a2e1ccab485d566ae0b Mon Sep 17 00:00:00 2001 From: Sergiy Lavrynenko Date: Tue, 24 Jan 2023 17:36:53 +0000 Subject: [PATCH 3/4] ticket-1413 SNB does multiple attempts to download S-Chain descriptions --- npms/skale-observer/observer_worker.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/npms/skale-observer/observer_worker.js b/npms/skale-observer/observer_worker.js index fe2b2815c..37bf7f086 100644 --- a/npms/skale-observer/observer_worker.js +++ b/npms/skale-observer/observer_worker.js @@ -152,19 +152,25 @@ class ObserverServer extends Server { const self = this; if( self.bIsPeriodicCachingStepInProgress ) return null; - self.bIsPeriodicCachingStepInProgress = true; let strError = null; + self.bIsPeriodicCachingStepInProgress = true; for( let idxAttempt = 0; idxAttempt < 10; ++ idxAttempt ) { - strError = - await skale_observer.cache_schains( - strChainNameConnectedTo, - self.opts.imaState.w3_main_net, - self.opts.imaState.w3_s_chain, - addressFrom, - self.opts + try { + strError = + await skale_observer.cache_schains( + strChainNameConnectedTo, + self.opts.imaState.w3_main_net, + self.opts.imaState.w3_s_chain, + addressFrom, + self.opts ); - if( ! strError ) - break; + if( ! strError ) + break; + } catch ( err ) { + strError = owaspUtils.extract_error_message( err ); + if( ! strError ) + strError = "runtime error without description"; + } await sleep( 5 * 1000 ); } self.bIsPeriodicCachingStepInProgress = false; From 47767b01e8d2d6252143e6c278782b764c0c1dde Mon Sep 17 00:00:00 2001 From: Sergiy Lavrynenko Date: Tue, 24 Jan 2023 18:46:09 +0000 Subject: [PATCH 4/4] ticket-1413 SNB does multiple attempts to download S-Chain descriptions --- npms/skale-observer/observer_worker.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/npms/skale-observer/observer_worker.js b/npms/skale-observer/observer_worker.js index 37bf7f086..e4bf14c0d 100644 --- a/npms/skale-observer/observer_worker.js +++ b/npms/skale-observer/observer_worker.js @@ -42,6 +42,8 @@ parentPort.on( "message", jo => { return; } ); +const sleep = ( milliseconds ) => { return new Promise( resolve => setTimeout( resolve, milliseconds ) ); }; + function doSendMessage( type, endpoint, worker_uuid, data ) { const jo = network_layer.socket_received_data_reverse_marshall( data ); const joSend = {