Skip to content

Commit

Permalink
Merge pull request #1627 from skalenetwork/revert-1623-ticket-1620/re…
Browse files Browse the repository at this point in the history
…solve-speed-issues-of-IMA-event-scanner

Revert "Ticket 1620/resolve speed issues of ima event scanner"
  • Loading branch information
DmytroNazarenko authored Oct 30, 2023
2 parents f43cc3f + a1a89f3 commit 21c1e96
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 321 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.1
2.0.0
21 changes: 2 additions & 19 deletions agent/clpTools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1314,21 +1314,14 @@ export function commandLineTaskTransferM2S() {
idxChainKnownForS2S: 0,
cntChainsKnownForS2S: 0
};
const optsChainPair = {
"strDirection": "M2S",
"chainSrc": imaState.chainProperties.mn,
"chainDst": imaState.chainProperties.sc
};
return await IMA.doTransfer( // main-net --> s-chain
"M2S",
joRuntimeOpts,
imaState.chainProperties.mn.ethersProvider,
imaState.joMessageProxyMainNet,
imaState.chainProperties.mn.joAbiIMA.message_proxy_mainnet_abi,
imaState.chainProperties.mn.joAccount,
imaState.chainProperties.sc.ethersProvider,
imaState.joMessageProxySChain,
imaState.chainProperties.sc.joAbiIMA.message_proxy_chain_abi,
imaState.chainProperties.sc.joAccount,
imaState.chainProperties.mn.strChainName,
imaState.chainProperties.sc.strChainName,
Expand All @@ -1343,8 +1336,7 @@ export function commandLineTaskTransferM2S() {
imaState.nBlockAgeM2S,
imaBLS.doSignMessagesM2S,
null,
imaState.chainProperties.sc.transactionCustomizer,
optsChainPair
imaState.chainProperties.sc.transactionCustomizer
);
}
} );
Expand All @@ -1362,21 +1354,14 @@ export function commandLineTaskTransferS2M() {
idxChainKnownForS2S: 0,
cntChainsKnownForS2S: 0
};
const optsChainPair = {
"strDirection": "S2M",
"chainSrc": imaState.chainProperties.sc,
"chainDst": imaState.chainProperties.mn
};
return await IMA.doTransfer( // s-chain --> main-net
"S2M",
joRuntimeOpts,
imaState.chainProperties.sc.ethersProvider,
imaState.joMessageProxySChain,
imaState.chainProperties.sc.joAbiIMA.message_proxy_chain_abi,
imaState.chainProperties.sc.joAccount,
imaState.chainProperties.mn.ethersProvider,
imaState.joMessageProxyMainNet,
imaState.chainProperties.sc.joAbiIMA.message_proxy_mainnet_abi,
imaState.chainProperties.mn.joAccount,
imaState.chainProperties.sc.strChainName,
imaState.chainProperties.mn.strChainName,
Expand All @@ -1391,8 +1376,7 @@ export function commandLineTaskTransferS2M() {
imaState.nBlockAgeS2M,
imaBLS.doSignMessagesS2M,
null,
imaState.chainProperties.mn.transactionCustomizer,
optsChainPair
imaState.chainProperties.mn.transactionCustomizer
);
}
} );
Expand All @@ -1419,7 +1403,6 @@ export function commandLineTaskTransferS2S() {
skaleObserver,
imaState.chainProperties.sc.ethersProvider,
imaState.joMessageProxySChain,
imaState.chainProperties.sc.joAbiIMA.message_proxy_chain_abi,
imaState.chainProperties.sc.joAccount,
imaState.chainProperties.sc.strChainName,
imaState.chainProperties.sc.chainId,
Expand Down
27 changes: 7 additions & 20 deletions agent/loop.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,16 @@ async function singleTransferLoopPartM2S( optsLoop, strLogPrefix ) {
if( checkTimeFraming( null, "m2s", optsLoop.joRuntimeOpts ) ) {
imaState.loopState.m2s.isInProgress = true;
await pwa.notifyOnLoopStart( imaState, "m2s" );
const optsChainPair = {
"strDirection": "M2S",
"chainSrc": imaState.chainProperties.mn,
"chainDst": imaState.chainProperties.sc
};
b1 = await IMA.doTransfer( // main-net --> s-chain
"M2S",
optsLoop.joRuntimeOpts,

imaState.chainProperties.mn.ethersProvider,
imaState.joMessageProxyMainNet,
imaState.chainProperties.sc.joAbiIMA.message_proxy_mainnet_abi,
imaState.chainProperties.mn.joAccount,
imaState.chainProperties.sc.ethersProvider,
imaState.joMessageProxySChain,
imaState.chainProperties.sc.joAbiIMA.message_proxy_chain_abi,

imaState.chainProperties.sc.joAccount,
imaState.chainProperties.mn.strChainName,
imaState.chainProperties.sc.strChainName,
Expand All @@ -249,8 +244,7 @@ async function singleTransferLoopPartM2S( optsLoop, strLogPrefix ) {
imaState.nBlockAgeM2S,
imaBLS.doSignMessagesM2S,
null,
imaState.chainProperties.sc.transactionCustomizer,
optsChainPair
imaState.chainProperties.sc.transactionCustomizer
);
imaState.loopState.m2s.isInProgress = false;
await pwa.notifyOnLoopEnd( imaState, "m2s" );
Expand Down Expand Up @@ -306,21 +300,16 @@ async function singleTransferLoopPartS2M( optsLoop, strLogPrefix ) {
if( checkTimeFraming( null, "s2m", optsLoop.joRuntimeOpts ) ) {
imaState.loopState.s2m.isInProgress = true;
await pwa.notifyOnLoopStart( imaState, "s2m" );
const optsChainPair = {
"strDirection": "S2M",
"chainSrc": imaState.chainProperties.sc,
"chainDst": imaState.chainProperties.mn
};
b2 = await IMA.doTransfer( // s-chain --> main-net
"S2M",
optsLoop.joRuntimeOpts,

imaState.chainProperties.sc.ethersProvider,
imaState.joMessageProxySChain,
imaState.chainProperties.sc.joAbiIMA.message_proxy_chain_abi,
imaState.chainProperties.sc.joAccount,
imaState.chainProperties.mn.ethersProvider,
imaState.joMessageProxyMainNet,
imaState.chainProperties.sc.joAbiIMA.message_proxy_mainnet_abi,

imaState.chainProperties.mn.joAccount,
imaState.chainProperties.sc.strChainName,
imaState.chainProperties.mn.strChainName,
Expand All @@ -335,8 +324,7 @@ async function singleTransferLoopPartS2M( optsLoop, strLogPrefix ) {
imaState.nBlockAgeS2M,
imaBLS.doSignMessagesS2M,
null,
imaState.chainProperties.mn.transactionCustomizer,
optsChainPair
imaState.chainProperties.mn.transactionCustomizer
);
imaState.loopState.s2m.isInProgress = false;
await pwa.notifyOnLoopEnd( imaState, "s2m" );
Expand Down Expand Up @@ -385,7 +373,6 @@ async function singleTransferLoopPartS2S( optsLoop, strLogPrefix ) {
skaleObserver,
imaState.chainProperties.sc.ethersProvider,
imaState.joMessageProxySChain,
imaState.chainProperties.sc.joAbiIMA.message_proxy_chain_abi,
imaState.chainProperties.sc.joAccount,
imaState.chainProperties.sc.strChainName,
imaState.chainProperties.sc.chainId,
Expand Down Expand Up @@ -849,7 +836,7 @@ export async function ensureHaveWorkers( opts ) {
};
while( ! aClient.logicalInitComplete ) {
if( log.verboseGet() >= log.verboseReversed().info )
log.write( "LOOP server is not initialized yet...\n" );
log.write( "LOOP server is not inited yet...\n" );
await threadInfo.sleep( 1000 );
aClient.send( jo );
}
Expand Down
8 changes: 0 additions & 8 deletions agent/test/agentUnitTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,6 @@ describe( "tests for `npms/skale-ima` 3", function() {

it( "should return `false` invoke `doTransfer`", async function() {
let joMessageProxySrc; // for `false` output
const joMessageProxySrcABI = null;
const joMessageProxyDstABI = null;
const chainNameSrc = "test";
const chainNameDst = "test";
const nTransactionsCountInBlock = 4;
Expand All @@ -510,11 +508,9 @@ describe( "tests for `npms/skale-ima` 3", function() {
joRuntimeOpts,
ethersProviderSrc,
joMessageProxySrc,
joMessageProxySrcABI,
joAccountSrc,
ethersProviderDst,
joMessageProxyDst,
joMessageProxyDstABI,
joAccountDst,
chainNameSrc,
chainNameDst,
Expand Down Expand Up @@ -546,19 +542,15 @@ describe( "tests for `npms/skale-ima` 3", function() {
idxChainKnownForS2S: 0,
cntChainsKnownForS2S: 0
};
const joMessageProxySrcABI = null;
const joMessageProxyDstABI = null;
// eslint-disable-next-line no-unused-expressions
expect( await IMA.doTransfer(
"M2S",
joRuntimeOpts,
ethersProviderSrc,
joMessageProxySrc,
joMessageProxySrcABI,
joAccountSrc,
ethersProviderDst,
joMessageProxyDst,
joMessageProxyDstABI,
joAccountDst,
chainNameSrc,
chainNameDst,
Expand Down
88 changes: 2 additions & 86 deletions npms/skale-ima/imaEventLogScan.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ import * as rpcCall from "../../agent/rpcCall.mjs";
import * as imaHelperAPIs from "./imaHelperAPIs.mjs";
import * as imaTransferErrorHandling from "./imaTransferErrorHandling.mjs";

import * as childProcessModule from "child_process";
import * as path from "path";
import * as url from "url";

const __dirname = path.dirname( url.fileURLToPath( import.meta.url ) );

export function createProgressiveEventsScanPlan( details, nLatestBlockNumber ) {
// assume Main Net mines 6 blocks per minute
const blocksInOneMinute = 6;
Expand Down Expand Up @@ -92,87 +86,9 @@ export function createProgressiveEventsScanPlan( details, nLatestBlockNumber ) {
return arrProgressiveEventsScanPlan;
}

export function extractEventArg( arg ) {
if( arg && typeof arg == "object" && "type" in arg && typeof arg.type == "string" &&
arg.type == "BigNumber" && "hex" in arg && typeof arg.hex == "string" )
return owaspUtils.toBN( arg.hex );
return arg;
}

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 safeGetPastEventsProgressiveExternal(
details, strLogPrefix, ethersProvider, attempts,
joContract, joABI, strEventName,
nBlockFrom, nBlockTo, joFilter, optsChainPair
) {
if( joABI && typeof joABI == "object" ) {
const escapeShell = function( cmd ) {
return "\"" + cmd.replace( /(["'$`\\])/g,"\\$1" ) + "\"";
};
const joArg = {
"url": owaspUtils.ethersProviderToUrl( ethersProvider ),
"attempts": attempts,
"strEventName": strEventName,
"nBlockFrom": nBlockFrom,
"nBlockTo": nBlockTo,
"joFilter": joFilter,
"address": joContract.address,
"abi": joABI
};
const cmd = "node " + path.join( __dirname, "imaExternalLogScan.mjs" ) + " " +
escapeShell( JSON.stringify( joArg ) );
if( log.verboseGet() >= log.verboseReversed().trace ) {
details.write( strLogPrefix +
cc.debug( "Will run external command to search logs for event " ) +
cc.j( strEventName ) + cc.debug( " via URL " ) + cc.u( joArg.url ) +
generateWhileTransferringLogMessageSuffix( optsChainPair ) +
cc.debug( "..." ) + "\n" );
}
const res = childProcessModule.execSync( cmd );
if( "error" in res && res.error ) {
if( log.verboseGet() >= log.verboseReversed().error ) {
details.write( strLogPrefix +
cc.error( "Got error from external command to search logs for event " ) +
cc.j( strEventName ) + cc.error( " via URL " ) + cc.u( joArg.url ) +
generateWhileTransferringLogMessageSuffix( optsChainPair ) +
cc.error( ":" ) + cc.warning( owaspUtils.extractErrorMessage( err ) ) + "\n" );
}
throw new Error( res.error );
}
if( log.verboseGet() >= log.verboseReversed().trace ) {
details.write( strLogPrefix +
cc.debug( "Done running external command to search logs for event " ) +
cc.j( strEventName ) + cc.debug( " via URL " ) + cc.u( joArg.url ) +
generateWhileTransferringLogMessageSuffix( optsChainPair ) +
cc.debug( "." ) + "\n" );
}
return JSON.parse( res ).result;
}
return await safeGetPastEventsProgressive(
details, strLogPrefix, ethersProvider, attempts,
joContract, strEventName,
nBlockFrom, nBlockTo, joFilter );
}

export async function safeGetPastEventsProgressive(
details, strLogPrefix, ethersProvider, attempts,
joContract, strEventName,
details, strLogPrefix,
ethersProvider, attempts, joContract, strEventName,
nBlockFrom, nBlockTo, joFilter
) {
if( ! imaTransferErrorHandling.getEnabledProgressiveEventsScan() ) {
Expand Down
88 changes: 0 additions & 88 deletions npms/skale-ima/imaExternalLogScan.mjs

This file was deleted.

Loading

0 comments on commit 21c1e96

Please sign in to comment.