Skip to content

Commit

Permalink
Merge pull request #50 from XinFinOrg/fix-error-log
Browse files Browse the repository at this point in the history
Fix error log
  • Loading branch information
wanwiset25 authored Jul 1, 2024
2 parents 459006c + 91727af commit 0d88c73
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/service/mainnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,26 +131,38 @@ export class MainnetService {
}

async submitTxsDynamic(results: Array<{ encodedRLP: string; blockNum: number }>): Promise<void> {
const blocksPerTx = [30, 15, 5, 1];
const blocksPerTx = [20, 10, 5, 1];
//make 1 initial try, this is for when blocks are caught up
if (results.length < blocksPerTx[0]){
try{
this.logger.info("submitDynamic startblock", results[0].blockNum, "pushing", results.length, "blocks,",results.length, "remaining(inclusive) into PARENTNET");
await this.submitTxs(results);
return;
} catch (error){}
}

let errorCount = 0;
//loop while reducing tx size
while (results.length) {
let i = 0;
while (i < blocksPerTx.length){
const val = blocksPerTx[i];
if (results.length >= val){
try{
this.logger.info("submitDynamic startblock", results[0].blockNum, "pushing", val, "blocks,",results.length, "remaining(inclusive) into PARENTNET");
await this.submitTxs(results.slice(0, val));
results = results.slice(val, results.length);
break; //if push success, reset push size
} catch (error){
errorCount++;
if (errorCount > 10){
throw Error("submitDynamic failed 10X times, reset relayer process");
}
}
}
if (i < blocksPerTx.length - 1){
i++;
}
i++;
await sleep(3000);
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/service/subnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,21 +306,34 @@ export class SubnetService {
const blocksPerTx = [20, 10, 5, 1];
//make 1 initial try, this is for when blocks are caught up
if (results.length < blocksPerTx[0]){
try{
this.logger.info("submitDynamic startblock", results[0].blockNum, "pushing", results.length, "blocks,",results.length, "remaining(inclusive) into SUBNET");
await this.submitTxs(results);
return;
} catch (error){}
}

let errorCount = 0;
while (results.length) {
let i = 0;
while (i < blocksPerTx.length){
const val = blocksPerTx[i];
if (results.length >= val){
try{
this.logger.info("submitDynamic startblock", results[0].blockNum, "pushing", val, "blocks,", results.length, "remaining(inclusive) into SUBNET");
await this.submitTxs(results.slice(0, val));
results = results.slice(val, results.length);
break; //if push success, reset push size
} catch (error){
errorCount++;
if (errorCount > 10){
throw Error("submitDynamic failed 10X times, reset relayer process");
}
}
}
if (i < blocksPerTx.length-1){
i++;
}
i++;
await sleep(3000);
}
}
Expand Down

0 comments on commit 0d88c73

Please sign in to comment.