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 1620/rollback event log scanner #1631

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions agent/loop.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 27 additions & 3 deletions npms/skale-ima/imaEventLogScan.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand All @@ -104,6 +120,14 @@ 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( "..." ) );
}
const nLatestBlockNumber = owaspUtils.toBN(
await imaHelperAPIs.safeGetBlockNumber( details, 10, ethersProvider ) );
const nLatestBlockNumberPlus1 = nLatestBlockNumber.add( owaspUtils.toBN( 1 ) );
Expand Down
58 changes: 23 additions & 35 deletions npms/skale-ima/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ async function findOutReferenceLogRecord(
const bnMessageNumberToFind = owaspUtils.toBN( nMessageNumberToFind.toString() );
const strEventName = "PreviousMessageReference";
const arrLogRecords = await imaEventLogScan.safeGetPastEventsProgressive(
details, strLogPrefix,
ethersProvider, 10, joMessageProxy, strEventName,
bnBlockId, bnBlockId, joMessageProxy.filters[strEventName]()
details, strLogPrefix, ethersProvider, 10, joMessageProxy, strEventName,
bnBlockId, bnBlockId, joMessageProxy.filters[strEventName](), optsChainPair
sergiy-skalelabs marked this conversation as resolved.
Show resolved Hide resolved
);
const cntLogRecord = arrLogRecords.length;
if( isVerbose ) {
Expand Down Expand Up @@ -98,9 +97,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 ) {
Expand Down Expand Up @@ -128,12 +126,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 );
Expand Down Expand Up @@ -287,11 +282,10 @@ async function doQueryOutgoingMessageCounter( optsTransfer ) {
optsTransfer.strActionName =
"in-getOutgoingMessagesCounter()--findOutAllReferenceLogRecords()";
optsTransfer.arrLogRecordReferences =
await findOutAllReferenceLogRecords(
optsTransfer.details, optsTransfer.strLogPrefixShort,
optsTransfer.ethersProviderSrc, optsTransfer.joMessageProxySrc,
bnBlockId, optsTransfer.nIncMsgCnt, optsTransfer.nOutMsgCnt, true
);
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 = [];
Expand Down Expand Up @@ -332,9 +326,7 @@ async function doQueryOutgoingMessageCounter( optsTransfer ) {
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 );
}
Expand Down Expand Up @@ -432,11 +424,11 @@ 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,
optsTransfer.joMessageProxySrc.filters[strEventName](
owaspUtils.ethersMod.ethers.utils.id( optsTransfer.chainNameDst ), // dstChainHash
r = await imaEventLogScan.safeGetPastEventsProgressive( optsTransfer.details,
DmytroNazarenko marked this conversation as resolved.
Show resolved Hide resolved
optsTransfer.strLogPrefixShort, optsTransfer.ethersProviderSrc, 10,
optsTransfer.joMessageProxySrc, strEventName,
nBlockFrom, nBlockTo, optsTransfer.joMessageProxySrc.filters[strEventName](
owaspUtils.ethersMod.ethers.utils.id( optsTransfer.chainNameDst ),
owaspUtils.toBN( optsTransfer.nIdxCurrentMsg )
) );
const joValues = await analyzeGatheredRecords( optsTransfer, r );
Expand Down Expand Up @@ -930,18 +922,14 @@ async function checkOutgoingMessageEvent( optsTransfer, joSChain ) {
// 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 joMessageProxyNode = new owaspUtils.ethersMod.ethers.Contract(
sc.joAbiIMA.message_proxy_chain_address,
sc.joAbiIMA.message_proxy_chain_abi,
DmytroNazarenko marked this conversation as resolved.
Show resolved Hide resolved
ethersProviderNode );
const strEventName = "OutgoingMessage";
const node_r = await imaEventLogScan.safeGetPastEventsProgressive(
optsTransfer.details, optsTransfer.strLogPrefixShort,
ethersProviderNode, 10, joMessageProxyNode, strEventName,
optsTransfer.details, optsTransfer.strLogPrefixShort, ethersProviderNode,
DmytroNazarenko marked this conversation as resolved.
Show resolved Hide resolved
10, joMessageProxyNode, strEventName,
joMessage.savedBlockNumberForOptimizations,
joMessage.savedBlockNumberForOptimizations,
joMessageProxyNode.filters[strEventName](
Expand Down
Loading