Skip to content

Commit db2d16a

Browse files
Merge pull request #1594 from skalenetwork/enchancement/BLS-signature-gathering-analysis
Echancement: BLS signatures are gathered more asynchronously
2 parents 024521c + 952815b commit db2d16a

File tree

1 file changed

+53
-15
lines changed

1 file changed

+53
-15
lines changed

agent/bls.mjs

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,8 @@ async function prepareSignMessagesImpl( optsSignOperation ) {
12071207
optsSignOperation.nCountOfBlsPartsToCollect = 0 + optsSignOperation.nThreshold;
12081208
if( log.verboseGet() >= log.verboseReversed().trace ) {
12091209
optsSignOperation.details.write( optsSignOperation.strLogPrefix +
1210-
cc.debug( "Will collect " ) + cc.info( optsSignOperation.nCountOfBlsPartsToCollect ) +
1210+
cc.debug( "Will BLS-collect " ) +
1211+
cc.info( optsSignOperation.nCountOfBlsPartsToCollect ) +
12111212
cc.debug( " from " ) + cc.info( optsSignOperation.jarrNodes.length ) +
12121213
cc.debug( " nodes" ) + cc.debug( ", " ) + cc.notice( "sequence ID" ) +
12131214
cc.debug( " is " ) + cc.attention( optsSignOperation.sequenceId ) + "\n" );
@@ -1223,6 +1224,24 @@ async function gatherSigningStartImpl( optsSignOperation ) {
12231224
optsSignOperation.errGathering = null;
12241225
optsSignOperation.promiseCompleteGathering = new Promise( ( resolve, reject ) => {
12251226
const iv = setInterval( function() {
1227+
if( optsSignOperation.joGatheringTracker.nCountReceivedPrevious !=
1228+
optsSignOperation.joGatheringTracker.nCountReceived ) {
1229+
if( log.verboseGet() >= log.verboseReversed().debug ) {
1230+
optsSignOperation.details.write(
1231+
cc.bright( optsSignOperation.strDirection ) + cc.debug( "/" ) +
1232+
cc.attention( "#" ) + cc.sunny( optsSignOperation.nTransferLoopCounter ) +
1233+
cc.debug( " BLS signature gathering progress updated, now have " ) +
1234+
cc.info( optsSignOperation.joGatheringTracker.nCountReceived ) +
1235+
cc.debug( " BLS parts of " ) +
1236+
cc.info( optsSignOperation.nCountOfBlsPartsToCollect ) +
1237+
cc.debug( " arrived, have " ) + cc.info( optsSignOperation.cntSuccess ) +
1238+
cc.debug( " success(es) and " ) +
1239+
cc.info( optsSignOperation.joGatheringTracker.nCountErrors ) +
1240+
cc.debug( " error(s)" ) + "\n" );
1241+
}
1242+
optsSignOperation.joGatheringTracker.nCountReceivedPrevious =
1243+
0 + optsSignOperation.joGatheringTracker.nCountReceived;
1244+
}
12261245
++ optsSignOperation.joGatheringTracker.nWaitIntervalStepsDone;
12271246
optsSignOperation.cntSuccess =
12281247
optsSignOperation.joGatheringTracker.nCountReceived -
@@ -1297,7 +1316,7 @@ async function gatherSigningStartImpl( optsSignOperation ) {
12971316
cc.debug( ", glue result is " ) + cc.j( joGlueResult ) + "\n";
12981317
if( log.verboseGet() >= log.verboseReversed().trace )
12991318
optsSignOperation.details.write( strCallbackCallDescription );
1300-
optsSignOperation.fn( // NOTICE: no await here, executed async
1319+
optsSignOperation.fn(
13011320
strError, optsSignOperation.jarrMessages, joGlueResult )
13021321
.catch( ( err ) => {
13031322
if( log.verboseGet() >= log.verboseReversed().critical ) {
@@ -1325,7 +1344,7 @@ async function gatherSigningStartImpl( optsSignOperation ) {
13251344
if( optsSignOperation.joGatheringTracker.nCountReceived >=
13261345
optsSignOperation.jarrNodes.length ) {
13271346
clearInterval( iv );
1328-
optsSignOperation.fn( // NOTICE: no await here, executed async
1347+
optsSignOperation.fn(
13291348
"signature error(2), got " +
13301349
optsSignOperation.joGatheringTracker.nCountErrors +
13311350
" errors(s) for " + optsSignOperation.jarrNodes.length +
@@ -1360,7 +1379,7 @@ async function gatherSigningStartImpl( optsSignOperation ) {
13601379
optsSignOperation.joGatheringTracker.nWaitIntervalMaxSteps
13611380
) {
13621381
clearInterval( iv );
1363-
optsSignOperation.fn( // NOTICE: no await here, executed async
1382+
optsSignOperation.fn(
13641383
"signature error(3), got " +
13651384
optsSignOperation.joGatheringTracker.nCountErrors +
13661385
" errors(s) for " + optsSignOperation.jarrNodes.length + " node(s)",
@@ -1548,7 +1567,7 @@ async function doSignProcessHandleCall(
15481567
joNode, joParams,
15491568
joIn, joOut, err, strNodeURL, i
15501569
) {
1551-
++optsSignOperation.joGatheringTracker.nCountReceived; // including errors
1570+
++optsSignOperation.joGatheringTracker.nCountReceived;
15521571
if( err ) {
15531572
++optsSignOperation.joGatheringTracker.nCountErrors;
15541573
const strErrorMessage =
@@ -1742,10 +1761,10 @@ async function doSignProcessOneImpl( i, optsSignOperation ) {
17421761
cc.debug( ", " ) + cc.notice( "sequence ID" ) + cc.debug( " is " ) +
17431762
cc.attention( optsSignOperation.sequenceId );
17441763
const rpcCallOpts = null;
1745-
rpcCall.create( // NOTICE: no await here, executed async
1764+
rpcCall.create(
17461765
strNodeURL, rpcCallOpts, async function( joCall, err ) {
17471766
if( err ) {
1748-
++optsSignOperation.joGatheringTracker.nCountReceived; // including errors
1767+
++optsSignOperation.joGatheringTracker.nCountReceived;
17491768
++optsSignOperation.joGatheringTracker.nCountErrors;
17501769
const strErrorMessage =
17511770
optsSignOperation.strLogPrefix + cc.fatal( "CRITICAL ERROR:" ) +
@@ -1844,7 +1863,8 @@ async function doSignMessagesImpl(
18441863
cc.attention( optsSignOperation.imaState.isCrossImaBlsMode ? "IMA agent" : "skaled" ) +
18451864
cc.info( ":" ) + " ";
18461865
optsSignOperation.joGatheringTracker = {
1847-
nCountReceived: 0, // including errors
1866+
nCountReceivedPrevious: 0,
1867+
nCountReceived: 0,
18481868
nCountErrors: 0,
18491869
nCountSkipped: 0,
18501870
nWaitIntervalStepMilliseconds: 100,
@@ -1877,7 +1897,7 @@ async function doSignMessagesImpl(
18771897
}
18781898
break;
18791899
}
1880-
await doSignProcessOneImpl( i, optsSignOperation );
1900+
doSignProcessOneImpl( i, optsSignOperation );
18811901
}
18821902
await gatherSigningStartImpl( optsSignOperation );
18831903
await gatherSigningFinishImpl( optsSignOperation );
@@ -2032,8 +2052,8 @@ async function doSignU256OneImpl( optsSignU256 ) {
20322052
cc.debug( ", ID " ) + cc.info( joNode.nodeID ) + cc.debug( ")" );
20332053
const rpcCallOpts = null;
20342054
await rpcCall.create( strNodeURL, rpcCallOpts, async function( joCall, err ) {
2055+
++optsSignU256.joGatheringTracker.nCountReceived;
20352056
if( err ) {
2036-
++optsSignU256.joGatheringTracker.nCountReceived; // including errors
20372057
++optsSignU256.joGatheringTracker.nCountErrors;
20382058
const strErrorMessage =
20392059
optsSignU256.strLogPrefix + cc.fatal( "CRITICAL ERROR:" ) +
@@ -2062,7 +2082,7 @@ async function doSignU256OneImpl( optsSignU256 ) {
20622082
"valueToSign": optsSignU256.u256 // must be 0x string, came from outside 0x string
20632083
}
20642084
}, async function( joIn, joOut, err ) {
2065-
++optsSignU256.joGatheringTracker.nCountReceived; // including errors
2085+
++optsSignU256.joGatheringTracker.nCountReceived;
20662086
if( err ) {
20672087
++optsSignU256.joGatheringTracker.nCountErrors;
20682088
const strErrorMessage =
@@ -2220,6 +2240,23 @@ async function doSignU256Gathering( optsSignU256 ) {
22202240
optsSignU256.errGathering = null;
22212241
optsSignU256.promiseCompleteGathering = new Promise( ( resolve, reject ) => {
22222242
const iv = setInterval( function() {
2243+
if( optsSignU256.joGatheringTracker.nCountReceivedPrevious !=
2244+
optsSignU256.joGatheringTracker.nCountReceived ) {
2245+
if( log.verboseGet() >= log.verboseReversed().debug ) {
2246+
optsSignU256.details.write(
2247+
cc.info( "BLS u256" ) +
2248+
cc.debug( " BLS signature gathering progress updated, now have " ) +
2249+
cc.info( optsSignU256.joGatheringTracker.nCountReceived ) +
2250+
cc.debug( " BLS parts of " ) +
2251+
cc.info( optsSignU256.nCountOfBlsPartsToCollect ) +
2252+
cc.debug( " arrived, have " ) + cc.info( optsSignU256.cntSuccess ) +
2253+
cc.debug( " success(es) and " ) +
2254+
cc.info( optsSignU256.joGatheringTracker.nCountErrors ) +
2255+
cc.debug( " error(s)" ) + "\n" );
2256+
}
2257+
optsSignU256.joGatheringTracker.nCountReceivedPrevious =
2258+
0 + optsSignU256.joGatheringTracker.nCountReceived;
2259+
}
22232260
++ optsSignU256.joGatheringTracker.nWaitIntervalStepsDone;
22242261
const cntSuccess =
22252262
optsSignU256.joGatheringTracker.nCountReceived -
@@ -2291,7 +2328,7 @@ async function doSignU256Gathering( optsSignU256 ) {
22912328
cc.debug( ", glue result is " ) + cc.j( joGlueResult ) + "\n";
22922329
if( log.verboseGet() >= log.verboseReversed().trace )
22932330
optsSignU256.details.write( strCallbackCallDescription );
2294-
optsSignU256.fn( // NOTICE: no await here, executed async
2331+
optsSignU256.fn(
22952332
strError, optsSignU256.u256, joGlueResult )
22962333
.catch( ( err ) => {
22972334
if( log.verboseGet() >= log.verboseReversed().critical ) {
@@ -2318,7 +2355,7 @@ async function doSignU256Gathering( optsSignU256 ) {
23182355
if( optsSignU256.joGatheringTracker.nCountReceived >=
23192356
optsSignU256.jarrNodes.length ) {
23202357
clearInterval( iv );
2321-
optsSignU256.fn( // NOTICE: no await here, executed async
2358+
optsSignU256.fn(
23222359
"signature error(2, u256), got " +
23232360
optsSignU256.joGatheringTracker.nCountErrors +
23242361
" errors(s) for " + optsSignU256.jarrNodes.length + " node(s)",
@@ -2350,7 +2387,7 @@ async function doSignU256Gathering( optsSignU256 ) {
23502387
optsSignU256.joGatheringTracker.nWaitIntervalMaxSteps
23512388
) {
23522389
clearInterval( iv );
2353-
optsSignU256.fn( // NOTICE: no await here, executed async
2390+
optsSignU256.fn(
23542391
"signature error(3, u256), got " +
23552392
optsSignU256.joGatheringTracker.nCountErrors +
23562393
" errors(s) for " + optsSignU256.jarrNodes.length + " node(s)",
@@ -2389,7 +2426,8 @@ export async function doSignU256( u256, details, fn ) {
23892426
imaState: state.get(),
23902427
strLogPrefix: cc.info( "Sign u256:" ) + " ",
23912428
joGatheringTracker: {
2392-
nCountReceived: 0, // including errors
2429+
nCountReceivedPrevious: 0,
2430+
nCountReceived: 0,
23932431
nCountErrors: 0,
23942432
nCountSkipped: 0,
23952433
nWaitIntervalStepMilliseconds: 100,

0 commit comments

Comments
 (0)