Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ticket-1413 Fixed issue with continuation of own S-Chain discovery when have 5 or more nodes down #1582

Merged
merged 6 commits into from
Sep 8, 2023
2 changes: 1 addition & 1 deletion agent/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4043,7 +4043,7 @@ function commonInitGasMultipliersAndTransactionArgs() {
"\n" );
log.write(
cc.info( "SKALE network max discovery wait time is" ) +
cc.debug( "..............." ) +
cc.debug( "............." ) +
( imaState.optsS2S.secondsToWaitForSkaleNetworkDiscovered
? cc.info( imaState.optsS2S.secondsToWaitForSkaleNetworkDiscovered.toString() )
: cc.error( "disabled" ) ) +
Expand Down
143 changes: 112 additions & 31 deletions agent/discoveryTools.mjs

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion agent/loop.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,9 @@ export async function ensureHaveWorkers( opts ) {
"isSilentReDiscovery":
opts.imaState.joSChainDiscovery.isSilentReDiscovery,
"repeatIntervalMilliseconds":
opts.imaState.joSChainDiscovery.repeatIntervalMilliseconds
opts.imaState.joSChainDiscovery.repeatIntervalMilliseconds,
"periodicDiscoveryInterval":
opts.imaState.joSChainDiscovery.periodicDiscoveryInterval
},

"optsS2S": { // S-Chain to S-Chain transfer options
Expand Down Expand Up @@ -873,3 +875,15 @@ export async function spreadArrivedStateOfPendingWorkAnalysis( joMessage ) {
gArrClients[idxWorker].send( joMessage );

}

export async function spreadUpdatedSChainNetwork( isFinal ) {
const imaState = state.get();
const joMessage = {
"method": "spreadUpdatedSChainNetwork",
"isFinal": ( !!isFinal ),
"joSChainNetworkInfo": imaState.joSChainNetworkInfo
};
const cntWorkers = gArrWorkers.length;
for( let idxWorker = 0; idxWorker < cntWorkers; ++ idxWorker )
gArrClients[idxWorker].send( joMessage );
}
14 changes: 14 additions & 0 deletions agent/loopWorker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ class ObserverServer extends SocketServer {
}
return joAnswer;
};
self.mapApiHandlers.spreadUpdatedSChainNetwork =
function( joMessage, joAnswer, eventData, socket ) {
if( log.verboseGet() >= log.verboseReversed().debug ) {
self.log( cc.debug( "New own S-Chains network information is arrived to " ) +
cc.notice( workerData.url ) + cc.debug( " loop worker in " ) +
threadInfo.threadDescription() + cc.debug( ": " ) +
cc.j( joMessage.joSChainNetworkInfo ) +
cc.debug( ", this own S-Chain update is " ) +
( joMessage.isFinal
? cc.success( "final" ) : cc.warning( "partial" ) ) +
"\n" );
}
imaState.joSChainNetworkInfo = joMessage.joSChainNetworkInfo;
};
self.mapApiHandlers.schainsCached = function( joMessage, joAnswer, eventData, socket ) {
if( log.verboseGet() >= log.verboseReversed().debug ) {
self.log( cc.debug( "S-Chains cache did arrived to " ) +
Expand Down
38 changes: 31 additions & 7 deletions agent/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ async function main() {
parseCommandLine();
initMonitoringServer();
initJsonRpcServer();
const isSilentReDiscovery = imaState.isPrintSecurityValues
? false
: imaState.joSChainDiscovery.isSilentReDiscovery;
const fnOnPeriodicDiscoveryResultAvailable = function( isFinal ) {
loop.spreadUpdatedSChainNetwork( isFinal );
};
if( imaState.bSignMessages ) {
if( imaState.strPathBlsGlue.length == 0 ) {
if( log.verboseGet() >= log.verboseReversed().fatal ) {
Expand All @@ -501,8 +507,14 @@ async function main() {
}
process.exit( 165 );
}
if( log.verboseGet() >= log.verboseReversed().information ) {
log.write( cc.debug( "S-Chain network was discovery uses " ) +
( isSilentReDiscovery
? cc.warning( "silent" )
: cc.success( "exposed details" ) ) +
cc.debug( " mode" ) + "\n" );
}
if( ! imaState.bNoWaitSChainStarted ) {
const isSilent = imaState.joSChainDiscovery.isSilentReDiscovery;
discoveryTools.waitUntilSChainStarted().then( function() {
// uses call to discoveryTools.discoverSChainNetwork()
discoveryTools.discoverSChainNetwork( function( err, joSChainNetworkInfo ) {
Expand All @@ -515,10 +527,16 @@ async function main() {
cc.j( joSChainNetworkInfo ) + "\n" );
}
imaState.joSChainNetworkInfo = joSChainNetworkInfo;
discoveryTools.continueSChainDiscoveryInBackgroundIfNeeded( isSilent );
doTheJob();
return 0; // FINISH
}, isSilent, imaState.joSChainNetworkInfo, -1 ).catch( ( err ) => {
discoveryTools.continueSChainDiscoveryInBackgroundIfNeeded(
isSilentReDiscovery, function() {
discoveryTools.doPeriodicSChainNetworkDiscoveryIfNeeded(
isSilentReDiscovery, fnOnPeriodicDiscoveryResultAvailable );
doTheJob();
} );
// Finish of IMA Agent startup,
// everything else is in async calls executed later
return 0;
}, isSilentReDiscovery, imaState.joSChainNetworkInfo, -1 ).catch( ( err ) => {
if( log.verboseGet() >= log.verboseReversed().critical ) {
const strError = owaspUtils.extractErrorMessage( err );
log.write( cc.fatal( "CRITICAL ERROR:" ) +
Expand All @@ -528,9 +546,15 @@ async function main() {
} );
} );
}
} else
} else {
discoveryTools.doPeriodicSChainNetworkDiscoveryIfNeeded(
isSilentReDiscovery, fnOnPeriodicDiscoveryResultAvailable );
doTheJob();
// FINISH!!! (skip exit here to avoid early termination while tasks ase still running)
// Finish of IMA Agent startup,
// everything else is in async calls executed later,
// skip exit here to avoid early termination while tasks ase still running
}

}

main();
5 changes: 3 additions & 2 deletions agent/state.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ export function get() {
"nReimbursementRange": -1, // < 0 - do not change anything

"joSChainDiscovery": {
"isSilentReDiscovery": true,
"isSilentReDiscovery": false,
// zero to disable (for debugging only)
"repeatIntervalMilliseconds": 10 * 1000
"repeatIntervalMilliseconds": 5 * 1000,
"periodicDiscoveryInterval": 5 * 60 * 1000
},

// S-Chain to S-Chain transfer options
Expand Down
4 changes: 3 additions & 1 deletion npms/skale-observer/observer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,9 @@ export async function ensureHaveWorker( opts ) {
"isSilentReDiscovery":
opts.imaState.joSChainDiscovery.isSilentReDiscovery,
"repeatIntervalMilliseconds":
opts.imaState.joSChainDiscovery.repeatIntervalMilliseconds
opts.imaState.joSChainDiscovery.repeatIntervalMilliseconds,
"periodicDiscoveryInterval":
opts.imaState.joSChainDiscovery.periodicDiscoveryInterval
}
}
},
Expand Down