diff --git a/VERSION b/VERSION index 227cea215..38f77a65b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.0 +2.0.1 diff --git a/agent/bls.mjs b/agent/bls.mjs index 45c1a1212..d6a09f1b7 100644 --- a/agent/bls.mjs +++ b/agent/bls.mjs @@ -280,6 +280,8 @@ export function keccak256ForPendingWorkAnalysis( nNodeNumber, strLoopWorkType, i function splitSignatureShare( signatureShare ) { const jarr = signatureShare.split( ":" ); + if( jarr.length < 2 ) + throw new Error( "Failed to split signatureShare=" + signatureShare.toString() ); return { X: jarr[0], Y: jarr[1] @@ -301,10 +303,7 @@ function allocBlsTmpActionDir() { } function performBlsGlue( - details, - strDirection, - jarrMessages, nIdxCurrentMsgBlockStart, strFromChainName, - arrSignResults + details, strDirection, jarrMessages, nIdxCurrentMsgBlockStart, strFromChainName, arrSignResults ) { const imaState = state.get(); const strLogPrefix = @@ -345,6 +344,8 @@ function performBlsGlue( const cnt = arrSignResults.length; for( let i = 0; i < cnt; ++i ) { const jo = arrSignResults[i]; + if( ( !jo ) || typeof jo != "object" ) + throw new Error( "Failed to save BLS part " + i + "because it's not JSON object" ); const strPath = strActionDir + "/sign-result" + jo.index + ".json"; if( log.verboseGet() >= log.verboseReversed().trace ) { details.write( strLogPrefix + cc.debug( "Saving " ) + cc.notice( strPath ) + @@ -483,6 +484,8 @@ function performBlsGlueU256( details, u256, arrSignResults ) { const cnt = arrSignResults.length; for( let i = 0; i < cnt; ++i ) { const jo = arrSignResults[i]; + if( ( !jo ) || typeof jo != "object" ) + throw new Error( "Failed to save BLS part " + i + "because it's not JSON object" ); const strPath = strActionDir + "/sign-result" + jo.index + ".json"; if( log.verboseGet() >= log.verboseReversed().trace ) { details.write( strLogPrefix + cc.debug( "Saving " ) + cc.notice( strPath ) + @@ -1191,6 +1194,7 @@ async function gatherSigningStartImpl( optsSignOperation ) { optsSignOperation.errGathering = null; optsSignOperation.promiseCompleteGathering = new Promise( ( resolve, reject ) => { const iv = setInterval( function() { + const cntSuccess = optsSignOperation.arrSignResults.length; if( optsSignOperation.joGatheringTracker.nCountReceivedPrevious != optsSignOperation.joGatheringTracker.nCountReceived ) { if( log.verboseGet() >= log.verboseReversed().debug ) { @@ -1199,9 +1203,9 @@ async function gatherSigningStartImpl( optsSignOperation ) { cc.attention( "#" ) + cc.sunny( optsSignOperation.nTransferLoopCounter ) + cc.debug( " BLS signature gathering progress updated, now have " ) + cc.info( optsSignOperation.joGatheringTracker.nCountReceived ) + - cc.debug( " BLS parts of " ) + + cc.debug( " BLS parts of needed " ) + cc.info( optsSignOperation.nCountOfBlsPartsToCollect ) + - cc.debug( " arrived, have " ) + cc.info( optsSignOperation.cntSuccess ) + + cc.debug( " arrived, have " ) + cc.info( cntSuccess ) + cc.debug( " success(es) and " ) + cc.info( optsSignOperation.joGatheringTracker.nCountErrors ) + cc.debug( " error(s)" ) + "\n" ); @@ -1210,10 +1214,7 @@ async function gatherSigningStartImpl( optsSignOperation ) { 0 + optsSignOperation.joGatheringTracker.nCountReceived; } ++ optsSignOperation.joGatheringTracker.nWaitIntervalStepsDone; - optsSignOperation.cntSuccess = - optsSignOperation.joGatheringTracker.nCountReceived - - optsSignOperation.joGatheringTracker.nCountErrors; - if( optsSignOperation.cntSuccess >= optsSignOperation.nCountOfBlsPartsToCollect ) { + if( cntSuccess >= optsSignOperation.nCountOfBlsPartsToCollect ) { optsSignOperation.strLogPrefixB = cc.bright( optsSignOperation.strDirection ) + cc.debug( "/" ) + cc.attention( "#" ) + cc.sunny( optsSignOperation.nTransferLoopCounter ) + @@ -1221,13 +1222,10 @@ async function gatherSigningStartImpl( optsSignOperation ) { cc.debug( "/" ) + cc.sunny( "Summary" ) + cc.debug( ":" ) + " "; clearInterval( iv ); let strError = null, strSuccessfulResultDescription = null; - const joGlueResult = performBlsGlue( - optsSignOperation.details, optsSignOperation.strDirection, - optsSignOperation.jarrMessages, - optsSignOperation.nIdxCurrentMsgBlockStart, - optsSignOperation.strFromChainName, - optsSignOperation.arrSignResults - ); + const joGlueResult = performBlsGlue( optsSignOperation.details, + optsSignOperation.strDirection, optsSignOperation.jarrMessages, + optsSignOperation.nIdxCurrentMsgBlockStart, optsSignOperation.strFromChainName, + optsSignOperation.arrSignResults ); if( joGlueResult ) { if( log.verboseGet() >= log.verboseReversed().debug ) { optsSignOperation.details.write( optsSignOperation.strLogPrefixB + @@ -1271,7 +1269,7 @@ async function gatherSigningStartImpl( optsSignOperation ) { "\n"; if( log.verboseGet() >= log.verboseReversed().error ) { optsSignOperation.details.write( strErrorMessage ); - if( log.id != details.id ) + if( log.id != optsSignOperation.details.id ) log.write( strErrorMessage ); } } @@ -1318,15 +1316,14 @@ async function gatherSigningStartImpl( optsSignOperation ) { " node(s)", optsSignOperation.jarrMessages, null ).catch( ( err ) => { + const cntSuccess = optsSignOperation.arrSignResults.length; if( log.verboseGet() >= log.verboseReversed().critical ) { const strErrorMessage = cc.error( "Problem(3) in BLS sign result handler, " + "not enough successful BLS signature parts(" ) + - cc.info( optsSignOperation.cntSuccess ) + - cc.error( " when all attempts done, " + + cc.info( cntSuccess ) + cc.error( " when all attempts done, " + "error optsSignOperation.details: " ) + - cc.warning( owaspUtils.extractErrorMessage( err ) ) + - "\n"; + cc.warning( owaspUtils.extractErrorMessage( err ) ) + "\n"; optsSignOperation.details.write( strErrorMessage ); if( log.id != optsSignOperation.details.id ) log.write( strErrorMessage ); @@ -1334,7 +1331,7 @@ async function gatherSigningStartImpl( optsSignOperation ) { optsSignOperation.errGathering = "Problem(3) in BLS sign result handler," + " not enough successful BLS signature parts(" + - optsSignOperation.cntSuccess + + cntSuccess + " when all attempts done, error optsSignOperation.details: " + owaspUtils.extractErrorMessage( err ); reject( new Error( optsSignOperation.errGathering ) ); @@ -1353,13 +1350,13 @@ async function gatherSigningStartImpl( optsSignOperation ) { optsSignOperation.jarrMessages, null ).catch( ( err ) => { + const cntSuccess = optsSignOperation.arrSignResults.length; if( log.verboseGet() >= log.verboseReversed().critical ) { const strErrorMessage = cc.error( "Problem(4) in BLS sign result handler, " + "not enough successful BLS signature parts(" ) + - cc.info( optsSignOperation.cntSuccess ) + - cc.error( ") and timeout reached, " + + cc.info( cntSuccess ) + cc.error( ") and timeout reached, " + "error optsSignOperation.details: " ) + cc.warning( owaspUtils.extractErrorMessage( err ) ) + "\n"; @@ -1369,8 +1366,7 @@ async function gatherSigningStartImpl( optsSignOperation ) { } optsSignOperation.errGathering = "Problem(4) in BLS sign result handler, " + - "not enough successful BLS signature parts(" + - optsSignOperation.cntSuccess + + "not enough successful BLS signature parts(" + cntSuccess + ") and timeout reached, error optsSignOperation.details: " + owaspUtils.extractErrorMessage( err ); reject( new Error( optsSignOperation.errGathering ) ); @@ -1429,14 +1425,13 @@ async function gatherSigningFinishImpl( optsSignOperation ) { optsSignOperation.jarrMessages, null ).catch( ( err ) => { + const cntSuccess = optsSignOperation.arrSignResults.length; if( log.verboseGet() >= log.verboseReversed().critical ) { const strErrorMessage = cc.error( "Problem(5) in BLS sign result handler, " + - "not enough successful BLS signature parts(" ) + - cc.info( optsSignOperation.cntSuccess ) + + "not enough successful BLS signature parts(" ) + cc.info( cntSuccess ) + cc.error( ") and timeout reached, error optsSignOperation.details: " ) + - cc.warning( owaspUtils.extractErrorMessage( err ) ) + - "\n"; + cc.warning( owaspUtils.extractErrorMessage( err ) ) + "\n"; if( log.verboseGet() >= log.verboseReversed().error ) { if( log.id != optsSignOperation.details.id ) log.write( strErrorMessage ); @@ -1467,11 +1462,11 @@ async function gatherSigningFinishImpl( optsSignOperation ) { JSON.stringify( optsSignOperation.joGatheringTracker ), optsSignOperation.jarrMessages, null ).catch( ( err ) => { + const cntSuccess = optsSignOperation.arrSignResults.length; if( log.verboseGet() >= log.verboseReversed().critical ) { const strErrorMessage = cc.error( "Problem(6) in BLS sign result handler, " + - "not enough successful BLS signature parts(" ) + - cc.info( optsSignOperation.cntSuccess ) + + "not enough successful BLS signature parts(" ) + cc.info( cntSuccess ) + cc.error( ") and timeout reached, error optsSignOperation.details: " ) + cc.warning( owaspUtils.extractErrorMessage( err ) ) + "\n"; if( log.id != optsSignOperation.details.id ) @@ -1564,10 +1559,8 @@ async function doSignProcessHandleCall( cc.j( joOut ) + cc.debug( ", " ) + cc.notice( "sequence ID" ) + cc.debug( " is " ) + cc.attention( optsSignOperation.sequenceId ) + "\n" ); } - if( joOut.result == null || - joOut.result == undefined || - ( !typeof joOut.result == "object" ) - ) { + if( ( !joOut ) || typeof joOut != "object" || ( !( "result" in joOut ) ) || ( !joOut.result ) || + typeof joOut.result != "object" || ( "error" in joOut && joOut.error ) ) { ++optsSignOperation.joGatheringTracker.nCountErrors; const strErrorMessage = optsSignOperation.strLogPrefix + cc.fatal( "Wallet CRITICAL ERROR:" ) + " " + @@ -1605,11 +1598,8 @@ async function doSignProcessHandleCall( cc.notice( "#" ) + cc.bright( nZeroBasedNodeIndex ) + cc.debug( ":" ) + " "; try { - optsSignOperation.cntSuccess = - optsSignOperation.joGatheringTracker.nCountReceived - - optsSignOperation.joGatheringTracker.nCountErrors; - if( optsSignOperation.cntSuccess > - optsSignOperation.nCountOfBlsPartsToCollect ) { + const cntSuccess = optsSignOperation.arrSignResults.length; + if( cntSuccess > optsSignOperation.nCountOfBlsPartsToCollect ) { ++optsSignOperation.joGatheringTracker.nCountSkipped; if( log.verboseGet() >= log.verboseReversed().notice ) { optsSignOperation.details.write( @@ -1810,7 +1800,6 @@ async function doSignMessagesImpl( strLogPrefixB: "", joGatheringTracker: {}, arrSignResults: [], - cntSuccess: 0, details: log, strGatheredDetailsName: "", sequenceId: "", @@ -1851,10 +1840,8 @@ async function doSignMessagesImpl( if( ! ( await prepareSignMessagesImpl( optsSignOperation ) ) ) return; for( let i = 0; i < optsSignOperation.jarrNodes.length; ++i ) { - optsSignOperation.cntSuccess = - optsSignOperation.joGatheringTracker.nCountReceived - - optsSignOperation.joGatheringTracker.nCountErrors; - if( optsSignOperation.cntSuccess >= optsSignOperation.nCountOfBlsPartsToCollect ) { + const cntSuccess = optsSignOperation.arrSignResults.length; + if( cntSuccess >= optsSignOperation.nCountOfBlsPartsToCollect ) { if( log.verboseGet() >= log.verboseReversed().trace ) { optsSignOperation.details.write( optsSignOperation.strLogPrefix + log.generateTimestampString( null, true ) + " " + @@ -1862,7 +1849,7 @@ async function doSignMessagesImpl( cc.debug( " for transfer from chain " ) + cc.info( fromChainName ) + cc.debug( " at #" ) + cc.info( i ) + cc.debug( " because successfully gathered count is reached " ) + - cc.j( optsSignOperation.cntSuccess ) + "\n" ); + cc.j( cntSuccess ) + "\n" ); } break; } @@ -2077,9 +2064,10 @@ async function doSignU256OneImpl( i, optsSignU256 ) { cc.info( optsSignU256.u256.toString() ) + cc.debug( ", answer is: " ) + cc.j( joOut ) + "\n" ); } - if( joOut.result == null || - joOut.result == undefined || - ( !typeof joOut.result == "object" ) + if( ( !joOut ) || typeof joOut != "object" || ( !( "result" in joOut ) ) || + "error" in joOut || joOut.error || + ( !joOut.result ) || typeof joOut.result != "object" || + ( !( "signature" in joOut.result ) ) || joOut.result.signature != "object" ) { ++optsSignU256.joGatheringTracker.nCountErrors; const strErrorMessage = @@ -2110,8 +2098,7 @@ async function doSignU256OneImpl( i, optsSignU256 ) { const strLogPrefixA = cc.info( "BLS" ) + cc.debug( "/" ) + cc.notice( "#" ) + cc.bright( nZeroBasedNodeIndex ) + cc.debug( ":" ) + " "; try { - const cntSuccess = optsSignU256.joGatheringTracker.nCountReceived - - optsSignU256.joGatheringTracker.nCountErrors; + const cntSuccess = optsSignU256.arrSignResults.length; if( cntSuccess > optsSignU256.nCountOfBlsPartsToCollect ) { ++optsSignU256.joGatheringTracker.nCountSkipped; if( log.verboseGet() >= log.verboseReversed().notice ) { @@ -2214,14 +2201,15 @@ async function doSignU256Gathering( optsSignU256 ) { const iv = setInterval( function() { if( optsSignU256.joGatheringTracker.nCountReceivedPrevious != optsSignU256.joGatheringTracker.nCountReceived ) { + const cntSuccess = optsSignU256.arrSignResults.length; if( log.verboseGet() >= log.verboseReversed().debug ) { optsSignU256.details.write( cc.info( "BLS u256" ) + cc.debug( " BLS signature gathering progress updated, now have " ) + cc.info( optsSignU256.joGatheringTracker.nCountReceived ) + - cc.debug( " BLS parts of " ) + + cc.debug( " BLS parts of needed " ) + cc.info( optsSignU256.nCountOfBlsPartsToCollect ) + - cc.debug( " arrived, have " ) + cc.info( optsSignU256.cntSuccess ) + + cc.debug( " arrived, have " ) + cc.info( cntSuccess ) + cc.debug( " success(es) and " ) + cc.info( optsSignU256.joGatheringTracker.nCountErrors ) + cc.debug( " error(s)" ) + "\n" ); @@ -2230,9 +2218,7 @@ async function doSignU256Gathering( optsSignU256 ) { 0 + optsSignU256.joGatheringTracker.nCountReceived; } ++ optsSignU256.joGatheringTracker.nWaitIntervalStepsDone; - const cntSuccess = - optsSignU256.joGatheringTracker.nCountReceived - - optsSignU256.joGatheringTracker.nCountErrors; + const cntSuccess = optsSignU256.arrSignResults.length; if( cntSuccess >= optsSignU256.nCountOfBlsPartsToCollect ) { const strLogPrefixB = cc.info( "BLS u256" ) + cc.debug( "/" ) + cc.sunny( "Summary" ) + cc.debug( ":" ) + " "; @@ -2696,16 +2682,28 @@ export async function doSignReadyHash( strMessageHash, isExposeOutput ) { if( joOut.signResult != null && joOut.signResult != undefined && typeof joOut.signResult == "object" ) joSignResult = joOut.signResult; + if( !joSignResult ) { + const strError = "No signature arrived"; + joRetVal.error = strError; + if( log.id != details.id ) { + log.write( strLogPrefix + cc.error( "BLS-sign(1) finished with error: }" ) + + cc.warning( strError ) + "\n" ); + } + details.write( strLogPrefix + cc.error( "BLS-sign(1) finished with error: }" ) + + cc.warning( strError ) + "\n" ); + await joCall.disconnect(); + throw new Error( strError ); + } if( "errorMessage" in joSignResult && typeof joSignResult.errorMessage == "string" && joSignResult.errorMessage.length > 0 ) { const strError = - "BLS signing finished with error: " + joSignResult.errorMessage; + "BLS-sign(2) finished with error: " + joSignResult.errorMessage; joRetVal.error = strError; const strErrorMessage = strLogPrefix + cc.fatal( "CRITICAL ERROR:" ) + - cc.error( " BLS signing(1) finished with error: " ) + + cc.error( " BLS-sign(2) finished with error: " ) + cc.warning( joSignResult.errorMessage ) + "\n"; if( log.verboseGet() >= log.verboseReversed().error ) { @@ -2766,9 +2764,9 @@ async function prepareHandlingOfSkaleImaVerifyAndSign( optsHandleVerifyAndSign ) optsHandleVerifyAndSign.joCallData.params.direction; optsHandleVerifyAndSign.jarrMessages = optsHandleVerifyAndSign.joCallData.params.messages; + const strDir = cc.bright( optsHandleVerifyAndSign.strDirection ); if( log.verboseGet() >= log.verboseReversed().trace ) { - optsHandleVerifyAndSign.details.write( optsHandleVerifyAndSign.strLogPrefix + - cc.bright( optsHandleVerifyAndSign.strDirection ) + + optsHandleVerifyAndSign.details.write( optsHandleVerifyAndSign.strLogPrefix + strDir + cc.debug( " verification algorithm will work for transfer from chain " ) + cc.info( optsHandleVerifyAndSign.strFromChainName ) + cc.debug( "/" ) + cc.notice( optsHandleVerifyAndSign.strFromChainID ) + cc.debug( " to chain" ) + @@ -2782,12 +2780,10 @@ async function prepareHandlingOfSkaleImaVerifyAndSign( optsHandleVerifyAndSign ) optsHandleVerifyAndSign.nParticipants = discoverBlsParticipants( optsHandleVerifyAndSign.imaState.joSChainNetworkInfo ); if( log.verboseGet() >= log.verboseReversed().debug ) { - optsHandleVerifyAndSign.details.write( optsHandleVerifyAndSign.strLogPrefix + - cc.bright( optsHandleVerifyAndSign.strDirection ) + + optsHandleVerifyAndSign.details.write( optsHandleVerifyAndSign.strLogPrefix + strDir + cc.debug( " verification algorithm discovered BLS threshold is " ) + cc.info( optsHandleVerifyAndSign.nThreshold ) + cc.debug( "." ) + "\n" ); - optsHandleVerifyAndSign.details.write( optsHandleVerifyAndSign.strLogPrefix + - cc.bright( optsHandleVerifyAndSign.strDirection ) + + optsHandleVerifyAndSign.details.write( optsHandleVerifyAndSign.strLogPrefix + strDir + cc.debug( " verification algorithm discovered number of BLS participants is " ) + cc.info( optsHandleVerifyAndSign.nParticipants ) + cc.debug( "." ) + "\n" ); } @@ -2806,11 +2802,9 @@ async function prepareHandlingOfSkaleImaVerifyAndSign( optsHandleVerifyAndSign ) ) ); if( log.verboseGet() >= log.verboseReversed().debug ) { - optsHandleVerifyAndSign.details.write( optsHandleVerifyAndSign.strLogPrefix + - cc.bright( optsHandleVerifyAndSign.strDirection ) + + optsHandleVerifyAndSign.details.write( optsHandleVerifyAndSign.strLogPrefix + strDir + cc.debug( " verification algorithm message hash to sign is " ) + - cc.info( optsHandleVerifyAndSign.strMessageHash ) + - "\n" ); + cc.info( optsHandleVerifyAndSign.strMessageHash ) + "\n" ); } return true; } @@ -2818,9 +2812,9 @@ async function prepareHandlingOfSkaleImaVerifyAndSign( optsHandleVerifyAndSign ) async function prepareS2sOfSkaleImaVerifyAndSign( optsHandleVerifyAndSign ) { const strSChainNameSrc = optsHandleVerifyAndSign.joCallData.params.srcChainName; const strSChainNameDst = optsHandleVerifyAndSign.joCallData.params.dstChainName; + const strDir = cc.bright( optsHandleVerifyAndSign.strDirection ); if( log.verboseGet() >= log.verboseReversed().trace ) { - optsHandleVerifyAndSign.details.write( optsHandleVerifyAndSign.strLogPrefix + - cc.bright( optsHandleVerifyAndSign.strDirection ) + + optsHandleVerifyAndSign.details.write( optsHandleVerifyAndSign.strLogPrefix + strDir + cc.debug( " verification algorithm will use for source chain name " ) + cc.info( strSChainNameSrc ) + cc.debug( " and destination chain name " ) + cc.info( strSChainNameDst ) + "\n" ); @@ -2887,19 +2881,18 @@ export async function handleSkaleImaVerifyAndSign( joCallData ) { nThreshold: 1, nParticipants: 1 }; + const strDir = cc.bright( optsHandleVerifyAndSign.strDirection ); try { if( ! ( await prepareHandlingOfSkaleImaVerifyAndSign( optsHandleVerifyAndSign ) ) ) return null; optsHandleVerifyAndSign.joExtraSignOpts = null; if( optsHandleVerifyAndSign.strDirection == "S2S" ) await prepareS2sOfSkaleImaVerifyAndSign( optsHandleVerifyAndSign ); - await checkCorrectnessOfMessagesToSign( optsHandleVerifyAndSign.details, optsHandleVerifyAndSign.strLogPrefix, optsHandleVerifyAndSign.strDirection, optsHandleVerifyAndSign.jarrMessages, optsHandleVerifyAndSign.nIdxCurrentMsgBlockStart, - optsHandleVerifyAndSign.joExtraSignOpts - ); + optsHandleVerifyAndSign.joExtraSignOpts ); if( log.verboseGet() >= log.verboseReversed().debug ) { optsHandleVerifyAndSign.details.write( optsHandleVerifyAndSign.strLogPrefix + cc.debug( "Will BLS-sign verified messages." ) + "\n" ); @@ -2930,12 +2923,10 @@ export async function handleSkaleImaVerifyAndSign( joCallData ) { const signerIndex = optsHandleVerifyAndSign.imaState.nNodeNumber; await rpcCall.create( joAccount.strSgxURL, rpcCallOpts, async function( joCall, err ) { if( err ) { - const strErrorMessage = optsHandleVerifyAndSign.strLogPrefix + - cc.bright( optsHandleVerifyAndSign.strDirection ) + " " + - cc.fatal( "CRITICAL ERROR:" ) + - cc.error( " JSON RPC call(handleSkaleImaVerifyAndSign) to SGX failed, " + - "RPC call was not created, error is: " ) + - cc.warning( owaspUtils.extractErrorMessage( err ) ) + "\n"; + const strErrorMessage = optsHandleVerifyAndSign.strLogPrefix + strDir + " " + + cc.fatal( "CRITICAL ERROR:" ) + cc.error( " JSON RPC call" + + "(handleSkaleImaVerifyAndSign) to SGX failed, RPC call was not created, " + + "error is: " ) + cc.warning( owaspUtils.extractErrorMessage( err ) ) + "\n"; if( log.verboseGet() >= log.verboseReversed().error ) { if( log.id != optsHandleVerifyAndSign.details.id ) log.write( strErrorMessage ); @@ -2944,10 +2935,8 @@ export async function handleSkaleImaVerifyAndSign( joCallData ) { if( joCall ) await joCall.disconnect(); throw new Error( - "JSON RPC call(handleSkaleImaVerifyAndSign) to SGX failed, " + - "RPC call was not created, error is: " + - owaspUtils.extractErrorMessage( err ) - ); + "JSON RPC call(handleSkaleImaVerifyAndSign) to SGX failed, RPC call was " + + "not created, error is: " + owaspUtils.extractErrorMessage( err ) ); } const joCallSGX = { "jsonrpc": "2.0", @@ -2963,22 +2952,19 @@ export async function handleSkaleImaVerifyAndSign( joCallData ) { }; if( log.verboseGet() >= log.verboseReversed().trace ) { optsHandleVerifyAndSign.details.write( optsHandleVerifyAndSign.strLogPrefix + - cc.bright( optsHandleVerifyAndSign.strDirection ) + - cc.debug( " verification algorithm will invoke " ) + cc.info( "SGX" ) + " " + - cc.debug( "with call data" ) + " " + cc.j( joCallSGX ) + "\n" ); + strDir + cc.debug( " verification algorithm will invoke " ) + cc.info( "SGX" ) + + " " + cc.debug( "with call data" ) + " " + cc.j( joCallSGX ) + "\n" ); } await joCall.call( joCallSGX, async function( joIn, joOut, err ) { if( err ) { const strError = - "JSON RPC call(handleSkaleImaVerifyAndSign) " + - "to SGX failed, RPC call reported error: " + - owaspUtils.extractErrorMessage( err ); + "JSON RPC call(handleSkaleImaVerifyAndSign) to SGX failed, RPC call " + + "reported error: " + owaspUtils.extractErrorMessage( err ); optsHandleVerifyAndSign.joRetVal.error = strError; const jsErrorObject = new Error( strError ); const strErrorMessage = optsHandleVerifyAndSign.strLogPrefix + - cc.fatal( "CRITICAL ERROR:" ) + - cc.error( " JSON RPC call(handleSkaleImaVerifyAndSign) to SGX failed, " + - "RPC call reported error: " ) + + cc.fatal( "CRITICAL ERROR:" ) + cc.error( " JSON RPC call" + + "(handleSkaleImaVerifyAndSign) to SGX failed, RPC call reported error: " ) + cc.warning( owaspUtils.extractErrorMessage( err ) ) + cc.error( ", stack is:" ) + "\n" + cc.stack( jsErrorObject.stack ) + "\n"; if( log.verboseGet() >= log.verboseReversed().error ) { @@ -2991,8 +2977,7 @@ export async function handleSkaleImaVerifyAndSign( joCallData ) { } if( log.verboseGet() >= log.verboseReversed().trace ) { optsHandleVerifyAndSign.details.write( optsHandleVerifyAndSign.strLogPrefix + - cc.bright( optsHandleVerifyAndSign.strDirection ) + - cc.debug( " Call to " ) + cc.info( "SGX" ) + + strDir + cc.debug( " Call to " ) + cc.info( "SGX" ) + cc.debug( " done, answer is: " ) + cc.j( joOut ) + "\n" ); } let joSignResult = joOut; @@ -3004,18 +2989,29 @@ export async function handleSkaleImaVerifyAndSign( joCallData ) { joSignResult = joOut.signResult; if( "qa" in optsHandleVerifyAndSign.joCallData ) optsHandleVerifyAndSign.joRetVal.qa = optsHandleVerifyAndSign.joCallData.qa; + if( !joSignResult ) { + const strError = "No signature arrived"; + joRetVal.error = strError; + if( log.id != details.id ) { + log.write( strLogPrefix + cc.error( "BLS-sign(1) finished with error: }" ) + + cc.warning( strError ) + "\n" ); + } + details.write( strLogPrefix + cc.error( "BLS-sign(1) finished with error: }" ) + + cc.warning( strError ) + "\n" ); + await joCall.disconnect(); + throw new Error( strError ); + } if( "errorMessage" in joSignResult && typeof joSignResult.errorMessage == "string" && joSignResult.errorMessage.length > 0 ) { optsHandleVerifyAndSign.isSuccess = false; const strError = - "BLS signing finished with error: " + joSignResult.errorMessage; + "BLS-sign(2) finished with error: " + joSignResult.errorMessage; optsHandleVerifyAndSign.joRetVal.error = strError; const strErrorMessage = optsHandleVerifyAndSign.strLogPrefix + - cc.fatal( "CRITICAL ERROR:" ) + - cc.error( " BLS signing(2) finished with error: " ) + - cc.warning( joSignResult.errorMessage ) + "\n"; + cc.fatal( "CRITICAL ERROR:" ) + cc.error( " BLS-sign(2) finished with " + + "error: " ) + cc.warning( joSignResult.errorMessage ) + "\n"; if( log.verboseGet() >= log.verboseReversed().error ) { if( log.id != optsHandleVerifyAndSign.details.id ) log.write( strErrorMessage ); @@ -3039,8 +3035,7 @@ export async function handleSkaleImaVerifyAndSign( joCallData ) { const strErrorMessage = optsHandleVerifyAndSign.strLogPrefix + cc.fatal( "CRITICAL ERROR:" ) + " " + cc.error( "IMA messages verifier/signer error: " ) + cc.warning( strError ) + - cc.error( ", stack is:" ) + "\n" + cc.stack( err.stack ) + - "\n"; + cc.error( ", stack is:" ) + "\n" + cc.stack( err.stack ) + "\n"; if( log.id != optsHandleVerifyAndSign.details.id ) log.write( strErrorMessage ); optsHandleVerifyAndSign.details.write( strErrorMessage ); @@ -3204,17 +3199,28 @@ export async function handleSkaleImaBSU256( joCallData ) { if( joOut.signResult != null && joOut.signResult != undefined && typeof joOut.signResult == "object" ) joSignResult = joOut.signResult; + if( !joSignResult ) { + const strError = "No signature arrived"; + joRetVal.error = strError; + if( log.id != details.id ) { + log.write( strLogPrefix + cc.error( "U256/BLS-sign(1) finished " + + "with error: " ) + cc.warning( strError ) + "\n" ); + } + details.write( strLogPrefix + cc.error( "U256/BLS-sign(1) finished " + + "with error: " ) + cc.warning( strError ) + "\n" ); + await joCall.disconnect(); + throw new Error( strError ); + } if( "errorMessage" in joSignResult && typeof joSignResult.errorMessage == "string" && joSignResult.errorMessage.length > 0 ) { optsBSU256.isSuccess = false; const strError = - "BLS signing finished with error: " + joSignResult.errorMessage; + "U256/BLS-sign(2) finished with error: " + joSignResult.errorMessage; optsBSU256.joRetVal.error = strError; const strErrorMessage = optsBSU256.strLogPrefix + - cc.fatal( "CRITICAL ERROR:" ) + - cc.error( " BLS signing(3) finished with error: " ) + - cc.warning( joSignResult.errorMessage ) + "\n"; + cc.fatal( "CRITICAL ERROR:" ) + cc.error( " U256/BLS-sign(2) finished" + + " with error: " ) + cc.warning( joSignResult.errorMessage ) + "\n"; if( log.verboseGet() >= log.verboseReversed().error ) { if( log.id != optsBSU256.details.id ) log.write( strErrorMessage ); @@ -3235,11 +3241,9 @@ export async function handleSkaleImaBSU256( joCallData ) { const strError = owaspUtils.extractErrorMessage( err ); optsBSU256.joRetVal.error = strError; if( log.verboseGet() >= log.verboseReversed().critical ) { - const strErrorMessage = - optsBSU256.strLogPrefix + cc.fatal( "CRITICAL ERROR:" ) + " " + + const strErrorMessage = optsBSU256.strLogPrefix + cc.fatal( "CRITICAL ERROR:" ) + " " + cc.error( "U256-BLS-signer error: " ) + cc.warning( strError ) + - cc.error( ", stack is:" ) + "\n" + cc.stack( err.stack ) + - "\n"; + cc.error( ", stack is:" ) + "\n" + cc.stack( err.stack ) + "\n"; if( log.id != optsBSU256.details.id ) log.write( strErrorMessage ); optsBSU256.details.write( strErrorMessage ); diff --git a/agent/loop.mjs b/agent/loop.mjs index 71a1170a6..564079c8e 100644 --- a/agent/loop.mjs +++ b/agent/loop.mjs @@ -229,7 +229,6 @@ async function singleTransferLoopPartM2S( optsLoop, strLogPrefix ) { imaState.chainProperties.mn.joAccount, imaState.chainProperties.sc.ethersProvider, imaState.joMessageProxySChain, - imaState.chainProperties.sc.joAccount, imaState.chainProperties.mn.strChainName, imaState.chainProperties.sc.strChainName, @@ -309,7 +308,6 @@ async function singleTransferLoopPartS2M( optsLoop, strLogPrefix ) { imaState.chainProperties.sc.joAccount, imaState.chainProperties.mn.ethersProvider, imaState.joMessageProxyMainNet, - imaState.chainProperties.mn.joAccount, imaState.chainProperties.sc.strChainName, imaState.chainProperties.mn.strChainName, @@ -512,17 +510,21 @@ const gArrClients = []; export function notifyCacheChangedSNB( arrSChainsCached ) { const cntWorkers = gArrWorkers.length; if( cntWorkers == 0 ) { - if( log.verboseGet() >= log.verboseReversed().debug ) { - log.write( cc.warning( "Will skip chainsCacheChanged dispatch event with " ) + - cc.warning( "no chains arrived in " ) + threadInfo.threadDescription() + "\n" ); + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + if( log.verboseGet() >= log.verboseReversed().debug ) { + log.write( cc.warning( "Will skip chainsCacheChanged dispatch event with " ) + + cc.warning( "no chains arrived in " ) + threadInfo.threadDescription() + "\n" ); + } } return; } - if( log.verboseGet() >= log.verboseReversed().debug ) { - log.write( - cc.debug( "Loop module will broadcast arrSChainsCached event to its " ) + - cc.info( cntWorkers ) + cc.debug( " worker(s) in " ) + - threadInfo.threadDescription() + cc.debug( "..." ) + "\n" ); + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + if( log.verboseGet() >= log.verboseReversed().debug ) { + log.write( + cc.debug( "Loop module will broadcast arrSChainsCached event to its " ) + + cc.info( cntWorkers ) + cc.debug( " worker(s) in " ) + + threadInfo.threadDescription() + cc.debug( "..." ) + "\n" ); + } } for( let idxWorker = 0; idxWorker < cntWorkers; ++ idxWorker ) { const jo = { @@ -531,34 +533,44 @@ export function notifyCacheChangedSNB( arrSChainsCached ) { "arrSChainsCached": arrSChainsCached } }; - if( log.verboseGet() >= log.verboseReversed().debug ) { - log.write( cc.debug( "S-Chains cache will be sent to " ) + - cc.notice( gArrClients[idxWorker].url ) + cc.debug( " loop worker..." ) + - "\n" ); + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + if( log.verboseGet() >= log.verboseReversed().debug ) { + log.write( cc.debug( "S-Chains cache will be sent to " ) + + cc.notice( gArrClients[idxWorker].url ) + cc.debug( " loop worker..." ) + + "\n" ); + } } gArrClients[idxWorker].send( jo ); - if( log.verboseGet() >= log.verboseReversed().debug ) { - log.write( cc.debug( "S-Chains cache did sent to " ) + - cc.notice( gArrClients[idxWorker].url ) + cc.debug( " loop worker" ) + - "\n" ); + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + if( log.verboseGet() >= log.verboseReversed().debug ) { + log.write( cc.debug( "S-Chains cache did sent to " ) + + cc.notice( gArrClients[idxWorker].url ) + cc.debug( " loop worker" ) + + "\n" ); + } } } - if( log.verboseGet() >= log.verboseReversed().debug ) { - log.write( - cc.debug( "Loop module did finished broadcasting arrSChainsCached event to its " ) + - cc.info( cntWorkers ) + cc.debug( " worker(s) in " ) + - threadInfo.threadDescription() + cc.debug( "..." ) + "\n" ); + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + if( log.verboseGet() >= log.verboseReversed().debug ) { + log.write( + cc.debug( "Loop module did finished broadcasting arrSChainsCached event to its " ) + + cc.info( cntWorkers ) + cc.debug( " worker(s) in " ) + + threadInfo.threadDescription() + cc.debug( "..." ) + "\n" ); + } } } if( log.verboseGet() >= log.verboseReversed().trace ) { - log.write( cc.debug( "Subscribe to chainsCacheChanged event in " ) + - threadInfo.threadDescription() + "\n" ); + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + log.write( cc.debug( "Subscribe to chainsCacheChanged event in " ) + + threadInfo.threadDescription() + "\n" ); + } } skaleObserver.events.on( "chainsCacheChanged", function( eventData ) { - if( log.verboseGet() >= log.verboseReversed().trace ) { - log.write( cc.debug( "Did arrived chainsCacheChanged event in " ) + - threadInfo.threadDescription() + "\n" ); + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + if( log.verboseGet() >= log.verboseReversed().trace ) { + log.write( cc.debug( "Did arrived chainsCacheChanged event in " ) + + threadInfo.threadDescription() + "\n" ); + } } notifyCacheChangedSNB( eventData.detail.arrSChainsCached ); } ); @@ -757,14 +769,12 @@ export async function ensureHaveWorkers( opts ) { "nMaxTransactionsM2S": opts.imaState.nMaxTransactionsM2S, "nMaxTransactionsS2M": opts.imaState.nMaxTransactionsS2M, "nMaxTransactionsS2S": opts.imaState.nMaxTransactionsS2S, - "nBlockAwaitDepthM2S": opts.imaState.nBlockAwaitDepthM2S, "nBlockAwaitDepthS2M": opts.imaState.nBlockAwaitDepthS2M, "nBlockAwaitDepthS2S": opts.imaState.nBlockAwaitDepthS2S, "nBlockAgeM2S": opts.imaState.nBlockAgeM2S, "nBlockAgeS2M": opts.imaState.nBlockAgeS2M, "nBlockAgeS2S": opts.imaState.nBlockAgeS2S, - "nLoopPeriodSeconds": opts.imaState.nLoopPeriodSeconds, "nNodeNumber": opts.imaState.nNodeNumber, "nNodesCount": opts.imaState.nNodesCount, @@ -836,7 +846,7 @@ export async function ensureHaveWorkers( opts ) { }; while( ! aClient.logicalInitComplete ) { if( log.verboseGet() >= log.verboseReversed().info ) - log.write( "LOOP server is not inited yet...\n" ); + log.write( "LOOP server is not initialized yet...\n" ); await threadInfo.sleep( 1000 ); aClient.send( jo ); } @@ -846,12 +856,14 @@ export async function ensureHaveWorkers( opts ) { cc.info( gArrWorkers.length ) + cc.debug( " worker(s) in " ) + threadInfo.threadDescription() + cc.debug( "" ) + "\n" ); } - if( log.verboseGet() >= log.verboseReversed().trace ) { + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded && + log.verboseGet() >= log.verboseReversed().trace ) { log.write( cc.debug( "Subscribe to inThread-arrSChainsCached event in " ) + threadInfo.threadDescription() + "\n" ); } skaleObserver.events.on( "inThread-arrSChainsCached", function( eventData ) { - if( log.verboseGet() >= log.verboseReversed().trace ) { + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded && + log.verboseGet() >= log.verboseReversed().trace ) { log.write( cc.debug( "Did arrived inThread-arrSChainsCached event in " ) + threadInfo.threadDescription() + "\n" ); } @@ -861,9 +873,8 @@ export async function ensureHaveWorkers( opts ) { // Force broadcast what we have in SNB right now because works above can start later than SNB // is finished download connected chains quickly if( log.verboseGet() >= log.verboseReversed().debug ) { - log.write( - cc.debug( "Loop module will do first initial broadcast of arrSChainsCached to its " ) + - cc.info( cntWorkers ) + cc.debug( " worker(s) in " ) + + log.write( cc.debug( "Loop module will do first initial broadcast of arrSChainsCached " + + "to its " ) + cc.info( cntWorkers ) + cc.debug( " worker(s) in " ) + threadInfo.threadDescription() + cc.debug( "..." ) + "\n" ); } notifyCacheChangedSNB( skaleObserver.getLastCachedSChains() ); diff --git a/agent/loopWorker.mjs b/agent/loopWorker.mjs index 09111c278..f9664ad07 100644 --- a/agent/loopWorker.mjs +++ b/agent/loopWorker.mjs @@ -108,9 +108,17 @@ class ObserverServer extends SocketServer { const isFlush = true; socket.send( jo, isFlush ); } ); - if( log.verboseGet() >= log.verboseReversed().debug ) { - log.write( - cc.debug( "Loop worker " ) + cc.notice( workerData.url ) + + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + if( log.verboseGet() >= log.verboseReversed().debug ) { + log.write( + cc.debug( "Loop worker " ) + cc.notice( workerData.url ) + + cc.debug( " will save cached S-Chains..." ) + "\n" ); + } + } + if( ! self.opts.imaState.optsLoop.enableStepS2S ) + threadInfo.joCustomThreadProperties.isSChainsCacheNeeded = false; + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + log.write( cc.debug( "Loop worker " ) + cc.notice( workerData.url ) + cc.debug( " will save cached S-Chains..." ) + "\n" ); } skaleObserver.setLastCachedSChains( self.opts.imaState.arrSChainsCached ); @@ -200,11 +208,13 @@ class ObserverServer extends SocketServer { 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 " ) + - cc.notice( workerData.url ) + cc.debug( " loop worker in " ) + - threadInfo.threadDescription() + cc.debug( ": " ) + - cc.j( joMessage.message.arrSChainsCached ) + "\n" ); + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + if( log.verboseGet() >= log.verboseReversed().debug ) { + self.log( cc.debug( "S-Chains cache did arrived to " ) + + cc.notice( workerData.url ) + cc.debug( " loop worker in " ) + + threadInfo.threadDescription() + cc.debug( ": " ) + + cc.j( joMessage.message.arrSChainsCached ) + "\n" ); + } } skaleObserver.setLastCachedSChains( joMessage.message.arrSChainsCached ); }; diff --git a/agent/main.mjs b/agent/main.mjs index 5d0edc449..165b228d5 100644 --- a/agent/main.mjs +++ b/agent/main.mjs @@ -392,8 +392,13 @@ function initJsonRpcServer() { } break; default: - throw new Error( "Unknown method name \"" + joMessage.method + "\" was specified" ); + joAnswer.error = `Unknown method name ${joMessage.method} was specified`; + break; } // switch( joMessage.method ) + if( ( !joAnswer ) || typeof joAnswer != "object" ) { + joAnswer = {}; + joAnswer.error = "internal error, null data returned"; + } } catch ( err ) { if( log.verboseGet() >= log.verboseReversed().error ) { const strError = owaspUtils.extractErrorMessage( err ); diff --git a/agent/run.sh b/agent/run.sh index e71c6a06f..cacf2dab7 100644 --- a/agent/run.sh +++ b/agent/run.sh @@ -112,7 +112,7 @@ BASE_OPTIONS="--gas-price-multiplier=$GAS_PRICE_MULTIPLIER \ --monitoring-port=$MONITORING_PORT \ --pwa \ --no-expose-pwa \ ---auto-exit=86400" +--auto-exit=3600" echo "Running loop cmd..." node "$DIR/main.mjs" --loop $BASE_OPTIONS diff --git a/agent/threadInfo.mjs b/agent/threadInfo.mjs index 1e9c6767d..dc7f03451 100644 --- a/agent/threadInfo.mjs +++ b/agent/threadInfo.mjs @@ -29,6 +29,11 @@ import * as cc from "../npms/skale-cc/cc.mjs"; const Worker = worker_threads.Worker; export { Worker }; +const joCustomThreadProperties = { + "isSChainsCacheNeeded": true // by default is set to true +}; +export { joCustomThreadProperties }; + export const sleep = ( milliseconds ) => { return new Promise( resolve => setTimeout( resolve, milliseconds ) ); }; diff --git a/npms/skale-ima/imaEventLogScan.mjs b/npms/skale-ima/imaEventLogScan.mjs index 5b22f155d..a757c1fcd 100644 --- a/npms/skale-ima/imaEventLogScan.mjs +++ b/npms/skale-ima/imaEventLogScan.mjs @@ -86,10 +86,26 @@ export function createProgressiveEventsScanPlan( details, nLatestBlockNumber ) { return arrProgressiveEventsScanPlan; } +function generateWhileTransferringLogMessageSuffix( optsChainPair ) { + if( ! optsChainPair ) + return ""; + if( ! optsChainPair.strDirection ) + return ""; + if( optsChainPair.strDirection == "S2S" ) { + return cc.debug( " (while performing " ) + cc.attention( optsChainPair.strDirection ) + + cc.debug( " transfer with external S-Chain " ) + + cc.info( optsChainPair.optsSpecificS2S.joSChain.data.name ) + cc.debug( " / " ) + + cc.notice( optsChainPair.optsSpecificS2S.joSChain.data.computed.chainId ) + + cc.debug( " node " ) + cc.info( optsChainPair.optsSpecificS2S.idxNode ) + + cc.debug( ")" ); + } + return cc.debug( " (while performing " ) + cc.attention( optsChainPair.strDirection ) + + cc.debug( " transfer)" ); +} + export async function safeGetPastEventsProgressive( - details, strLogPrefix, - ethersProvider, attempts, joContract, strEventName, - nBlockFrom, nBlockTo, joFilter + details, strLogPrefix, ethersProvider, attempts, joContract, strEventName, + nBlockFrom, nBlockTo, joFilter, optsChainPair ) { if( ! imaTransferErrorHandling.getEnabledProgressiveEventsScan() ) { details.write( strLogPrefix + @@ -104,6 +120,16 @@ export async function safeGetPastEventsProgressive( nBlockFrom, nBlockTo, joFilter ); } + if( log.verboseGet() >= log.verboseReversed().information ) { + details.write( strLogPrefix + + cc.info( "Will run progressive event log search for event " ) + + cc.j( strEventName ) + cc.info( " via URL " ) + + cc.u( owaspUtils.ethersProviderToUrl( ethersProvider ) ) + + generateWhileTransferringLogMessageSuffix( optsChainPair ) + + cc.info( ", from block " ) + cc.notice( nBlockFrom ) + + cc.info( ", to block " ) + cc.notice( nBlockTo ) + + cc.info( "..." ) + "\n" ); + } const nLatestBlockNumber = owaspUtils.toBN( await imaHelperAPIs.safeGetBlockNumber( details, 10, ethersProvider ) ); const nLatestBlockNumberPlus1 = nLatestBlockNumber.add( owaspUtils.toBN( 1 ) ); diff --git a/npms/skale-ima/index.mjs b/npms/skale-ima/index.mjs index 6666a1cbf..2b3ccd659 100644 --- a/npms/skale-ima/index.mjs +++ b/npms/skale-ima/index.mjs @@ -44,15 +44,13 @@ const perMessageGasForTransfer = 1000000; const additionalS2MTransferOverhead = 200000; async function findOutReferenceLogRecord( - details, strLogPrefix, - ethersProvider, joMessageProxy, + details, strLogPrefix, ethersProvider, joMessageProxy, bnBlockId, nMessageNumberToFind, isVerbose ) { const bnMessageNumberToFind = owaspUtils.toBN( nMessageNumberToFind.toString() ); const strEventName = "PreviousMessageReference"; const arrLogRecords = await imaEventLogScan.safeGetPastEventsProgressive( - details, strLogPrefix, - ethersProvider, 10, joMessageProxy, strEventName, + details, strLogPrefix, ethersProvider, 10, joMessageProxy, strEventName, bnBlockId, bnBlockId, joMessageProxy.filters[strEventName]() ); const cntLogRecord = arrLogRecords.length; @@ -98,9 +96,8 @@ async function findOutReferenceLogRecord( } async function findOutAllReferenceLogRecords( - details, strLogPrefix, - ethersProvider, joMessageProxy, - bnBlockId, nIncMsgCnt, nOutMsgCnt, isVerbose + details, strLogPrefix, ethersProvider, joMessageProxy, + bnBlockId, nIncMsgCnt, nOutMsgCnt, isVerbose, optsChainPair ) { if( isVerbose ) { if( log.verboseGet() >= log.verboseReversed().debug ) { @@ -128,12 +125,9 @@ async function findOutAllReferenceLogRecords( let nWalkMsgNumber = nOutMsgCnt - 1; let nWalkBlockId = bnBlockId; for( ; nWalkMsgNumber >= nIncMsgCnt; -- nWalkMsgNumber ) { - const joReferenceLogRecord = - await findOutReferenceLogRecord( - details, strLogPrefix, - ethersProvider, joMessageProxy, - nWalkBlockId, nWalkMsgNumber, isVerbose - ); + const joReferenceLogRecord = await findOutReferenceLogRecord( + details, strLogPrefix, ethersProvider, joMessageProxy, + nWalkBlockId, nWalkMsgNumber, isVerbose, optsChainPair ); if( joReferenceLogRecord == null ) break; nWalkBlockId = owaspUtils.toBN( joReferenceLogRecord.previousOutgoingMessageBlockId ); @@ -284,15 +278,16 @@ async function doQueryOutgoingMessageCounter( optsTransfer ) { optsTransfer.chainNameDst, { from: optsTransfer.joAccountSrc.address() } ) ); try { - optsTransfer.strActionName = - "in-getOutgoingMessagesCounter()--findOutAllReferenceLogRecords()"; - optsTransfer.arrLogRecordReferences = - await findOutAllReferenceLogRecords( - optsTransfer.details, optsTransfer.strLogPrefixShort, - optsTransfer.ethersProviderSrc, optsTransfer.joMessageProxySrc, - bnBlockId, optsTransfer.nIncMsgCnt, optsTransfer.nOutMsgCnt, true - ); - return true; // success, finish at this point + if( bnBlockId ) { + optsTransfer.strActionName = + "in-getOutgoingMessagesCounter()--findOutAllReferenceLogRecords()"; + optsTransfer.arrLogRecordReferences = + await findOutAllReferenceLogRecords( optsTransfer.details, + optsTransfer.strLogPrefixShort, optsTransfer.ethersProviderSrc, + optsTransfer.joMessageProxySrc, bnBlockId, optsTransfer.nIncMsgCnt, + optsTransfer.nOutMsgCnt, true, optsTransfer.optsChainPair ); + return true; // success, finish at this point + } } catch ( err ) { optsTransfer.arrLogRecordReferences = []; if( log.verboseGet() >= log.verboseReversed().error ) { @@ -326,15 +321,13 @@ async function doQueryOutgoingMessageCounter( optsTransfer ) { ++ nWalkMsgNumber ) { const joFilter = optsTransfer.joMessageProxySrc.filters[strEventName]( - owaspUtils.ethersMod.ethers.utils.id( optsTransfer.chainIdDst ), // dstChainHash + owaspUtils.ethersMod.ethers.utils.id( optsTransfer.chainNameDst ), owaspUtils.toBN( nWalkMsgNumber ) ); const arrLogRecordReferencesWalk = await imaEventLogScan.safeGetPastEventsProgressive( optsTransfer.details, optsTransfer.strLogPrefixShort, optsTransfer.ethersProviderSrc, attempts, optsTransfer.joMessageProxySrc, - strEventName, - nBlockFrom, nBlockTo, joFilter - ); + strEventName, nBlockFrom, nBlockTo, joFilter, optsTransfer.optsChainPair ); optsTransfer.arrLogRecordReferences = optsTransfer.arrLogRecordReferences.concat( arrLogRecordReferencesWalk ); } @@ -414,16 +407,18 @@ async function gatherMessages( optsTransfer ) { for( let idxInBlock = 0; // inner loop wil create block of transactions optsTransfer.nIdxCurrentMsg < optsTransfer.nOutMsgCnt && idxInBlock < optsTransfer.nTransactionsCountInBlock; - ++optsTransfer.nIdxCurrentMsg, ++idxInBlock, ++optsTransfer.cntAccumulatedForBlock - ) { + ++optsTransfer.nIdxCurrentMsg, ++idxInBlock, ++optsTransfer.cntAccumulatedForBlock ) { const idxProcessing = optsTransfer.cntProcessed + idxInBlock; if( idxProcessing > optsTransfer.nMaxTransactionsCount ) break; let nBlockFrom = 0, nBlockTo = "latest"; if( optsTransfer.arrLogRecordReferences.length > 0 ) { const joReferenceLogRecord = optsTransfer.arrLogRecordReferences.shift(); - nBlockFrom = joReferenceLogRecord.currentBlockId; - nBlockTo = joReferenceLogRecord.currentBlockId; + if( joReferenceLogRecord && "currentBlockId" in joReferenceLogRecord && + joReferenceLogRecord.currentBlockId ) { + nBlockFrom = joReferenceLogRecord.currentBlockId; + nBlockTo = joReferenceLogRecord.currentBlockId; + } } optsTransfer.strActionName = "src-chain->MessageProxy->scan-past-events()"; const strEventName = "OutgoingMessage"; @@ -432,13 +427,13 @@ async function gatherMessages( optsTransfer ) { cc.notice( optsTransfer.strActionName ) + cc.debug( " for " ) + cc.info( strEventName ) + cc.debug( " event..." ) + "\n" ); } - r = await imaEventLogScan.safeGetPastEventsProgressive( - optsTransfer.details, optsTransfer.strLogPrefixShort, optsTransfer.ethersProviderSrc, - 10, optsTransfer.joMessageProxySrc, strEventName, nBlockFrom, nBlockTo, + r = await imaEventLogScan.safeGetPastEventsProgressive( optsTransfer.details, + optsTransfer.strLogPrefixShort, optsTransfer.ethersProviderSrc, 10, + optsTransfer.joMessageProxySrc, strEventName, nBlockFrom, nBlockTo, optsTransfer.joMessageProxySrc.filters[strEventName]( - owaspUtils.ethersMod.ethers.utils.id( optsTransfer.chainNameDst ), // dstChainHash + owaspUtils.ethersMod.ethers.utils.id( optsTransfer.chainNameDst ), owaspUtils.toBN( optsTransfer.nIdxCurrentMsg ) - ) ); + ), optsTransfer.optsChainPair ); const joValues = await analyzeGatheredRecords( optsTransfer, r ); if( joValues == null ) return false; @@ -449,9 +444,8 @@ async function gatherMessages( optsTransfer ) { try { const transactionHash = r[0].transactionHash; if( log.verboseGet() >= log.verboseReversed().debug ) { - optsTransfer.details.write( optsTransfer.strLogPrefix + - cc.debug( "Event transactionHash is " ) + cc.info( transactionHash ) + - "\n" ); + optsTransfer.details.write( optsTransfer.strLogPrefix + cc.debug( "Event " + + "transactionHash is " ) + cc.info( transactionHash ) + "\n" ); } const blockNumber = r[0].blockNumber; optsTransfer.details.write( optsTransfer.strLogPrefix + @@ -459,28 +453,27 @@ async function gatherMessages( optsTransfer ) { const nLatestBlockNumber = await imaHelperAPIs.safeGetBlockNumber( optsTransfer.details, 10, optsTransfer.ethersProviderSrc ); if( log.verboseGet() >= log.verboseReversed().debug ) { - optsTransfer.details.write( optsTransfer.strLogPrefix + - cc.debug( "Latest blockNumber is " ) + cc.info( nLatestBlockNumber ) + - "\n" ); + optsTransfer.details.write( optsTransfer.strLogPrefix + cc.debug( "Latest " + + "blockNumber is " ) + cc.info( nLatestBlockNumber ) + "\n" ); } const nDist = nLatestBlockNumber - blockNumber; if( nDist < optsTransfer.nBlockAwaitDepth ) bSecurityCheckPassed = false; if( log.verboseGet() >= log.verboseReversed().debug ) { - optsTransfer.details.write( optsTransfer.strLogPrefix + - cc.debug( "Distance by blockNumber is " ) + cc.info( nDist ) + - cc.debug( ", await check is " ) + ( bSecurityCheckPassed - ? cc.success( "PASSED" ) : cc.error( "FAILED" ) ) + "\n" ); + const cp = bSecurityCheckPassed ? cc.success( "PASSED" ) : cc.error( "FAILED" ); + optsTransfer.details.write( optsTransfer.strLogPrefix + cc.debug( "Distance " + + "by blockNumber is " ) + cc.info( nDist ) + cc.debug( ", await check " + + "is " ) + cp + "\n" ); } } catch ( err ) { bSecurityCheckPassed = false; if( log.verboseGet() >= log.verboseReversed().critical ) { const strError = owaspUtils.extractErrorMessage( err ); const s = optsTransfer.strLogPrefix + cc.fatal( "CRITICAL ERROR:" ) + - cc.error( " Exception(evaluate block depth) while " + - "getting transaction hash and block number during " + - optsTransfer.strActionName + ": " ) + cc.error( strError ) + - cc.error( ", stack is: " ) + "\n" + cc.stack( err.stack ) + "\n"; + cc.error( " Exception(evaluate block depth) while getting transaction " + + "hash and block number during " + optsTransfer.strActionName + ": " ) + + cc.error( strError ) + cc.error( ", stack is: " ) + + "\n" + cc.stack( err.stack ) + "\n"; optsTransfer.details.write( s ); if( log.id != optsTransfer.details.id ) log.write( s ); @@ -511,9 +504,8 @@ async function gatherMessages( optsTransfer ) { try { const transactionHash = r[0].transactionHash; if( log.verboseGet() >= log.verboseReversed().debug ) { - optsTransfer.details.write( optsTransfer.strLogPrefix + - cc.debug( "Event transactionHash is " ) + cc.info( transactionHash ) + - "\n" ); + optsTransfer.details.write( optsTransfer.strLogPrefix + cc.debug( "Event " + + "transactionHash is " ) + cc.info( transactionHash ) + "\n" ); } const blockNumber = r[0].blockNumber; if( log.verboseGet() >= log.verboseReversed().debug ) { @@ -570,27 +562,21 @@ async function gatherMessages( optsTransfer ) { optsTransfer.strActionName = "" + strActionNameOld; if( !bSecurityCheckPassed ) { if( log.verboseGet() >= log.verboseReversed().warning ) { - optsTransfer.details.write( optsTransfer.strLogPrefix + - cc.warning( "Block age check was not passed, " + - "canceling search for transfer events" ) + "\n" ); + optsTransfer.details.write( optsTransfer.strLogPrefix + cc.warning( "Block " + + "age check was not passed, canceling search for transfer events" ) + "\n" ); } break; } } if( log.verboseGet() >= log.verboseReversed().debug ) { optsTransfer.details.write( optsTransfer.strLogPrefix + - cc.success( "Got event optsTransfer.details from " ) + - cc.notice( "getPastEvents()" ) + cc.success( " event invoked with " ) + - cc.notice( "msgCounter" ) + cc.success( " set to " ) + - cc.info( optsTransfer.nIdxCurrentMsg ) + cc.success( " and " ) + - cc.notice( "dstChain" ) + cc.success( " set to " ) + + cc.success( "Got event optsTransfer.details from getPastEvents() event invoked " + + "with msgCounter set to " ) + cc.info( optsTransfer.nIdxCurrentMsg ) + + cc.success( " and " ) + cc.notice( "dstChain" ) + cc.success( " set to " ) + cc.info( optsTransfer.chainNameDst ) + cc.success( ", event description: " ) + - cc.j( joValues ) + - // + cc.j(evs) + - "\n" ); - optsTransfer.details.write( optsTransfer.strLogPrefix + - cc.debug( "Will process message counter value " ) + - cc.info( optsTransfer.nIdxCurrentMsg ) + "\n" ); + cc.j( joValues ) + "\n" ); + optsTransfer.details.write( optsTransfer.strLogPrefix + cc.debug( "Will process " + + "message counter value " ) + cc.info( optsTransfer.nIdxCurrentMsg ) + "\n" ); } optsTransfer.arrMessageCounters.push( optsTransfer.nIdxCurrentMsg ); const joMessage = { @@ -599,8 +585,7 @@ async function gatherMessages( optsTransfer ) { "to": joValues.to, "amount": joValues.amount, "data": joValues.data, - "savedBlockNumberForOptimizations": - joValues.savedBlockNumberForOptimizations + "savedBlockNumberForOptimizations": joValues.savedBlockNumberForOptimizations }; optsTransfer.jarrMessages.push( joMessage ); } @@ -928,26 +913,24 @@ async function checkOutgoingMessageEvent( optsTransfer, joSChain ) { let bEventIsFound = false; try { // eslint-disable-next-line dot-notation - const ethersProviderNode = - owaspUtils.getEthersProviderFromURL( strUrlHttp ); - const joMessageProxyNode = - new owaspUtils.ethersMod.ethers.Contract( - optsTransfer.imaState.chainProperties.sc - .joAbiIMA.message_proxy_chain_address, - optsTransfer.imaState.chainProperties.sc - .joAbiIMA.message_proxy_chain_abi, - ethersProviderNode - ); + const ethersProviderNode = owaspUtils.getEthersProviderFromURL( strUrlHttp ); + const joMessageProxyNode = new owaspUtils.ethersMod.ethers.Contract( + optsTransfer.imaState.chainProperties.sc + .joAbiIMA.message_proxy_chain_address, + optsTransfer.imaState.chainProperties + .sc.joAbiIMA.message_proxy_chain_abi, + ethersProviderNode ); const strEventName = "OutgoingMessage"; const node_r = await imaEventLogScan.safeGetPastEventsProgressive( - optsTransfer.details, optsTransfer.strLogPrefixShort, - ethersProviderNode, 10, joMessageProxyNode, strEventName, + optsTransfer.details, optsTransfer.strLogPrefixShort, ethersProviderNode, + 10, joMessageProxyNode, strEventName, joMessage.savedBlockNumberForOptimizations, joMessage.savedBlockNumberForOptimizations, joMessageProxyNode.filters[strEventName]( owaspUtils.ethersMod.ethers.utils.id( optsTransfer.chainNameDst ), owaspUtils.toBN( idxImaMessage ) - ) + ), + optsTransfer.optsChainPair ); const cntEvents = node_r.length; if( log.verboseGet() >= log.verboseReversed().trace ) { diff --git a/npms/skale-observer/observer.mjs b/npms/skale-observer/observer.mjs index 47364448e..44956c704 100644 --- a/npms/skale-observer/observer.mjs +++ b/npms/skale-observer/observer.mjs @@ -779,12 +779,10 @@ async function checkWhetherSChainIsConnected( strSChainName, joMessageProxySChai ? opts.cntAttemptsCheckConnectedState : 3; for( let idxAttempt = 0; idxAttempt < cntAttempts; ++ idxAttempt ) { try { - isConnected = - await joMessageProxySChain.callStatic.isConnectedChain( strSChainName ); + isConnected = await joMessageProxySChain.callStatic.isConnectedChain( strSChainName ); isQueryPassed = true; break; } catch ( err ) { - isConnected = false; if( opts && opts.details ) { if( log.verboseGet() >= log.verboseReversed().error ) { opts.details.write( cc.error( "Failed attempt " ) + @@ -798,17 +796,14 @@ async function checkWhetherSChainIsConnected( strSChainName, joMessageProxySChai } } } - if( opts && opts.details ) { - if( ! isQueryPassed ) { - if( log.verboseGet() >= log.verboseReversed().warning ) { - opts.details.write( cc.debug( "Will assume S-Chain " ) + - cc.info( strSChainName ) + cc.debug( " connected status: " ) + - cc.yn( isConnected ) + "\n" ); - } - } else if( log.verboseGet() >= log.verboseReversed().trace ) { - opts.details.write( cc.debug( "Got S-Chain " ) + cc.info( strSChainName ) + - cc.debug( " connected status: " ) + cc.yn( isConnected ) + "\n" ); + if( ! isQueryPassed ) { + if( opts && opts.details ) { + opts.details.write( cc.error( "Failed all " ) + cc.info( cntAttempts ) + + cc.error( " attempt(s) to query connected state of " ) + cc.info( strSChainName ) + + cc.error( " S-Chain" ) + "\n" ); } + throw new Error( "Failed all " + cntAttempts + " attempt(s) to query connected state of " + + strSChainName + " S-Chain" ); } return isConnected; } @@ -843,50 +838,40 @@ export async function loadSChainsConnectedOnly( strChainNameConnectedTo, opts ) ); const arrSChains = [], arrSChainNames = await getAllSchainNames( arrSChainHashes, opts ); for( let idxSChain = 0; idxSChain < cntSChains; ++ idxSChain ) { - try { - if( opts && opts.bStopNeeded ) - break; - const strSChainHash = arrSChainHashes[idxSChain]; - const strSChainName = arrSChainNames[idxSChain]; - if( strChainNameConnectedTo == strSChainName ) { - if( opts && opts.details ) { - if( log.verboseGet() >= log.verboseReversed().trace ) { - opts.details.write( cc.debug( "Skip this S-Chain " ) + - cc.info( strSChainName ) + cc.debug( " connected status check" ) + - "\n" ); - } - } - continue; - } + if( opts && opts.bStopNeeded ) + break; + const strSChainHash = arrSChainHashes[idxSChain]; + const strSChainName = arrSChainNames[idxSChain]; + if( strChainNameConnectedTo == strSChainName ) { if( opts && opts.details ) { if( log.verboseGet() >= log.verboseReversed().trace ) { - opts.details.write( - cc.debug( "Querying(1) connected status between S-Chain " ) + - cc.info( strSChainName ) + cc.debug( " and S-Chain " ) + - cc.info( strChainNameConnectedTo ) + cc.debug( "..." ) + "\n" ); + opts.details.write( cc.debug( "Skip this S-Chain " ) + + cc.info( strSChainName ) + cc.debug( " connected status check" ) + + "\n" ); } } - let isConnected = false; - if( isLoadConnectedOnly ) { - isConnected = await checkWhetherSChainIsConnected( - strSChainName, joMessageProxySChain, opts ); - if( ! isConnected ) - continue; + continue; + } + if( opts && opts.details ) { + if( log.verboseGet() >= log.verboseReversed().trace ) { + opts.details.write( + cc.debug( "Querying(1) connected status between S-Chain " ) + + cc.info( strSChainName ) + cc.debug( " and S-Chain " ) + + cc.info( strChainNameConnectedTo ) + cc.debug( "..." ) + "\n" ); } - const joSChain = await loadSChain( idxSChain, strSChainHash, null, cntSChains, opts ); - if( ! joSChain ) + } + let isConnected = false; + if( isLoadConnectedOnly ) { + isConnected = await checkWhetherSChainIsConnected( + strSChainName, joMessageProxySChain, opts ); + if( ! isConnected ) continue; - joSChain.isConnected = isConnected; - arrSChains.push( joSChain ); - } catch ( err ) { - if( opts && opts.details ) { - if( log.verboseGet() >= log.verboseReversed().error ) { - opts.details.write( cc.error( "Got error: " ) + - cc.warning( owaspUtils.extractErrorMessage( err ) ) + - cc.error( ", stack is: " ) + "\n" + cc.stack( err.stack ) + "\n" ); - } - } } + const joSChain = await loadSChain( idxSChain, strSChainHash, null, cntSChains, opts ); + if( ! joSChain ) + continue; + joSChain.isConnected = isConnected; + arrSChains.push( joSChain ); } return arrSChains; } @@ -905,34 +890,22 @@ export async function checkConnectedSChains( strChainNameConnectedTo, arrSChains joSChain.isConnected = false; if( joSChain.data.name == strChainNameConnectedTo ) continue; - try { - const url = pickRandomSChainUrl( joSChain ); - if( opts && opts.details ) { - if( log.verboseGet() >= log.verboseReversed().trace ) { - opts.details.write( cc.debug( "Querying(2) via URL " ) + cc.u( url ) + - cc.debug( " to S-Chain " ) + cc.info( joSChain.data.name ) + - cc.debug( " whether it's connected to S-Chain " ) + - cc.info( strChainNameConnectedTo ) + cc.debug( "..." ) + "\n" ); - } - } - const ethersProvider = owaspUtils.getEthersProviderFromURL( url ); - const joMessageProxySChain = - new owaspUtils.ethersMod.ethers.Contract( - opts.imaState.chainProperties.sc.joAbiIMA.message_proxy_chain_address, - opts.imaState.chainProperties.sc.joAbiIMA.message_proxy_chain_abi, - ethersProvider - ); - joSChain.isConnected = await checkWhetherSChainIsConnected( - strChainNameConnectedTo, joMessageProxySChain, opts ); - } catch ( err ) { - if( opts && opts.details ) { - if( log.verboseGet() >= log.verboseReversed().error ) { - opts.details.write( cc.error( "Got error: " ) + - cc.warning( owaspUtils.extractErrorMessage( err ) ) + - cc.error( ", stack is: " ) + "\n" + cc.stack( err.stack ) + "\n" ); - } + const url = pickRandomSChainUrl( joSChain ); + if( opts && opts.details ) { + if( log.verboseGet() >= log.verboseReversed().trace ) { + opts.details.write( cc.debug( "Querying(2) via URL " ) + cc.u( url ) + + cc.debug( " to S-Chain " ) + cc.info( joSChain.data.name ) + + cc.debug( " whether it's connected to S-Chain " ) + + cc.info( strChainNameConnectedTo ) + cc.debug( "..." ) + "\n" ); } } + const ethersProvider = owaspUtils.getEthersProviderFromURL( url ); + const joMessageProxySChain = new owaspUtils.ethersMod.ethers.Contract( + opts.imaState.chainProperties.sc.joAbiIMA.message_proxy_chain_address, + opts.imaState.chainProperties.sc.joAbiIMA.message_proxy_chain_abi, + ethersProvider ); + joSChain.isConnected = await checkWhetherSChainIsConnected( + strChainNameConnectedTo, joMessageProxySChain, opts ); } return arrSChains; } @@ -1065,15 +1038,8 @@ export async function cacheSChains( strChainNameConnectedTo, opts ) { ( typeof strChainNameConnectedTo == "string" ) && strChainNameConnectedTo.length > 0 ) { - await checkConnectedSChains( - strChainNameConnectedTo, - arrSChains, - opts - ); - gArrSChainsCached = await filterSChainsMarkedAsConnected( - arrSChains, - opts - ); + await checkConnectedSChains( strChainNameConnectedTo, arrSChains, opts ); + gArrSChainsCached = await filterSChainsMarkedAsConnected( arrSChains, opts ); } else gArrSChainsCached = arrSChains; if( opts && opts.details ) { @@ -1084,21 +1050,23 @@ export async function cacheSChains( strChainNameConnectedTo, opts ) { } } if( opts && opts.details ) { - if( log.verboseGet() >= log.verboseReversed().trace ) { - opts.details.write( - cc.debug( "Will dispatch inThread-arrSChainsCached event in " ) + - threadInfo.threadDescription() + "\n" ); + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + if( log.verboseGet() >= log.verboseReversed().trace ) { + opts.details.write( + cc.debug( "Will dispatch inThread-arrSChainsCached event in " ) + + threadInfo.threadDescription() + "\n" ); + } } } - events.dispatchEvent( - new UniversalDispatcherEvent( - "inThread-arrSChainsCached", - { "detail": { "arrSChainsCached": arrSChains } } ) ); + events.dispatchEvent( new UniversalDispatcherEvent( + "inThread-arrSChainsCached", { "detail": { "arrSChainsCached": arrSChains } } ) ); if( opts && opts.details ) { - if( log.verboseGet() >= log.verboseReversed().trace ) { - opts.details.write( - cc.debug( "Did dispatched inThread-arrSChainsCached event in " ) + - threadInfo.threadDescription() + "\n" ); + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + if( log.verboseGet() >= log.verboseReversed().trace ) { + opts.details.write( + cc.debug( "Did dispatched inThread-arrSChainsCached event in " ) + + threadInfo.threadDescription() + "\n" ); + } } } if( opts.fnCacheChanged ) @@ -1114,7 +1082,7 @@ export async function cacheSChains( strChainNameConnectedTo, opts ) { if( opts && opts.details ) { if( log.verboseGet() >= log.verboseReversed().error ) { opts.details.write( cc.fatal( "ERROR:" ) + - cc.error( " Failed to cache: " ) + cc.error( err ) ); + cc.error( " Failed to cache: " ) + cc.error( err ) + "\n" ); opts.details.write( cc.stack( err.stack ) ); } } @@ -1127,12 +1095,12 @@ export function getLastCachedSChains() { } export function setLastCachedSChains( arrSChainsCached ) { - if( log.verboseGet() >= log.verboseReversed().debug ) { - log.write( cc.debug( "Will set arrSChainsCached in " ) + - threadInfo.threadDescription() + cc.debug( "..." ) + "\n" ); - log.write( cc.debug( "Value of arrSChainsCached in " ) + - threadInfo.threadDescription() + cc.debug( " is: " ) + - cc.j( arrSChainsCached ) + "\n" ); + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + if( log.verboseGet() >= log.verboseReversed().debug ) { + log.write( cc.debug( "Will save value of arrSChainsCached in " ) + + threadInfo.threadDescription() + cc.debug( " is: " ) + + cc.j( arrSChainsCached ) + "\n" ); + } } if( arrSChainsCached && typeof arrSChainsCached == "object" ) { gArrSChainsCached = JSON.parse( JSON.stringify( arrSChainsCached ) ); @@ -1143,20 +1111,24 @@ export function setLastCachedSChains( arrSChainsCached ) { const nMaxSize = getLastCachedHistoryMaxSize(); while( gArrCacheHistory.length > nMaxSize ) gArrCacheHistory.shift(); - if( log.verboseGet() >= log.verboseReversed().debug ) { - log.write( cc.debug( "Will dispatch arrSChainsCached event in " ) + - threadInfo.threadDescription() + cc.debug( "..." ) + "\n" ); + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + if( log.verboseGet() >= log.verboseReversed().debug ) { + log.write( cc.debug( "Will dispatch arrSChainsCached event in " ) + + threadInfo.threadDescription() + cc.debug( "..." ) + "\n" ); + } } events.dispatchEvent( new UniversalDispatcherEvent( "chainsCacheChanged", { "detail": { "arrSChainsCached": getLastCachedSChains() } } ) ); } else { - if( log.verboseGet() >= log.verboseReversed().error ) { - log.write( cc.fatal( "CRITICAL ERROR:" ) + - cc.error( " Cannot dispatch arrSChainsCached event with bad object " ) + - cc.j( arrSChainsCached ) + cc.error( " in " ) + - threadInfo.threadDescription() + "\n" ); + if( threadInfo.joCustomThreadProperties.isSChainsCacheNeeded ) { + if( log.verboseGet() >= log.verboseReversed().error ) { + log.write( cc.fatal( "CRITICAL ERROR:" ) + + cc.error( " Cannot dispatch arrSChainsCached event with bad object " ) + + cc.j( arrSChainsCached ) + cc.error( " in " ) + + threadInfo.threadDescription() + "\n" ); + } } } } @@ -1333,7 +1305,7 @@ export async function ensureHaveWorker( opts ) { }; while( ! gClient.logicalInitComplete ) { if( log.verboseGet() >= log.verboseReversed().info ) - log.write( "SNB server is not inited yet...\n" ); + log.write( "SNB server is not initialized yet...\n" ); await threadInfo.sleep( 1000 ); gClient.send( jo ); diff --git a/npms/skale-observer/observerWorker.mjs b/npms/skale-observer/observerWorker.mjs index 01ea4fd90..49c62da43 100644 --- a/npms/skale-observer/observerWorker.mjs +++ b/npms/skale-observer/observerWorker.mjs @@ -232,11 +232,7 @@ class ObserverServer extends SocketServer { cc.debug( " thread will invoke S-Chains caching(attempt + " ) + cc.info( idxAttempt ) + cc.debug( ")..." ) + "\n" ); } - strError = - await skaleObserver.cacheSChains( - strChainNameConnectedTo, - self.opts - ); + strError = await skaleObserver.cacheSChains( strChainNameConnectedTo, self.opts ); if( ! strError ) break; } catch ( err ) {