Skip to content

Commit

Permalink
Reorganize main battle agent logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
scnale committed Mar 18, 2022
1 parent 8db47bb commit d4c4075
Showing 1 changed file with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,36 @@ private class SuperblocksBattleBaseAgentTimerTask extends TimerTask {
@Override
public void run() {
try {
if (!ethWrapper.isEthNodeSyncing()) {
if (arePendingTransactions()) {
log.debug("Skipping because there are pending transaction for the sender address.");
return;
}
if (ethWrapper.isEthNodeSyncing()) {
log.warn("SuperblocksBattleBaseAgentTimerTask skipped because the eth node is syncing blocks");
return;
}

if (arePendingTransactions()) {
log.debug("Skipping because there are pending transaction for the sender address.");
return;
}

ethWrapper.updateContractFacadesGasPrice();
ethWrapper.updateContractFacadesGasPrice();

reactToElapsedTime();
reactToElapsedTime();

long fromBlock = latestEthBlockProcessed + 1;
long toBlock = ethWrapper.getEthBlockCount() - getConfirmations() + 1;
// Block interval: [from, to)
long fromBlock = latestEthBlockProcessed + 1;
long toBlock = ethWrapper.getEthBlockCount() - getConfirmations() + 1;

// Ignore execution if nothing to process
if (fromBlock > toBlock) return;
// Ignore execution if nothing to process
if (fromBlock > toBlock) return;

// Maintain data structures and react to events
removeApproved(fromBlock, toBlock);
removeInvalid(fromBlock, toBlock);
getNewBattles(fromBlock, toBlock);
deleteFinishedBattles(fromBlock, toBlock);
latestEthBlockProcessed = reactToEvents(fromBlock, toBlock);
// Maintain data structures and react to events
removeApproved(fromBlock, toBlock);
removeInvalid(fromBlock, toBlock);
getNewBattles(fromBlock, toBlock);
deleteFinishedBattles(fromBlock, toBlock);
latestEthBlockProcessed = reactToEvents(fromBlock, toBlock);

flush(latestEthBlockProcessed, latestEthBlockProcessedFile);
flushFiles();
} else {
log.warn("SuperblocksBattleBaseAgentTimerTask skipped because the eth node is syncing blocks");
}
flush(latestEthBlockProcessed, latestEthBlockProcessedFile);
flushFiles();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
Expand Down

0 comments on commit d4c4075

Please sign in to comment.