Skip to content

Commit

Permalink
Merge pull request #123 from powerpool-finance/fix-getLogs
Browse files Browse the repository at this point in the history
Fix get logs and handle blacklist error
  • Loading branch information
defi-dev authored Nov 24, 2024
2 parents 67e6a4e + 73896d1 commit 2b9b621
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
5 changes: 2 additions & 3 deletions app/Cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ let app: App;
const version = await getVersion(__dirname);
console.log(`PowerPool Agent Node version: ${version}`);

let config: Config;
let configPath;
let config: Config, configPath: string;

try {
const configPath = process.env.CONFIG_PATH || path.resolve(__dirname, '../config/main.yaml');
configPath = process.env.CONFIG_PATH || path.resolve(__dirname, '../config/main.yaml');
logger.info(`CLI: Reading configuration from ${configPath} ...`);
config = YAML.parse(fs.readFileSync(configPath).toString()) as Config;
} catch (error) {
Expand Down
4 changes: 4 additions & 0 deletions app/ConfigGetters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export function getMaxBlocksSubgraphDelay(_ /*networkName*/) {
return 10000;
}

export function getMaxBlockEventsQuery(_ /*networkName*/) {
return 4900;
}

export function setConfigDefaultValues(config, defaultValues) {
Object.keys(defaultValues).forEach(name => {
if (typeof config[name] === 'undefined') {
Expand Down
18 changes: 15 additions & 3 deletions app/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getAverageBlockTime,
getDefaultNetworkConfig,
getExternalLensAddress,
getMaxBlockEventsQuery,
getMulticall2Address,
getResolverCallSkipBlocksNumber,
setConfigDefaultValues,
Expand Down Expand Up @@ -402,8 +403,8 @@ export class Network {

if (this.contractEventsEmitter.blockLogsMode) {
this.contractEventsEmitter.emitByBlockQuery({
fromBlock: Number(this.agentsStartBlockNumber) + 1,
toBlock: Number(this.agentsStartBlockNumber) + count,
fromBlock: startBlockNumber + 1,
toBlock: startBlockNumber + count,
});
}

Expand Down Expand Up @@ -484,7 +485,7 @@ export class Network {
blockNumber = BigInt(blockNumber.toString());
const before = this.nowMs();

const oldLatestBlockNumber = this.latestBlockNumber ? BigInt(this.latestBlockNumber) : null;
let oldLatestBlockNumber = this.latestBlockNumber ? BigInt(this.latestBlockNumber) : null;
if (this.latestBlockNumber && blockNumber <= this.latestBlockNumber) {
return null;
}
Expand All @@ -505,6 +506,9 @@ export class Network {

if (this.contractEventsEmitter.blockLogsMode) {
const blocksDiff = oldLatestBlockNumber ? blockNumber - oldLatestBlockNumber : 0n;
if (blocksDiff > getMaxBlockEventsQuery(this.name)) {
oldLatestBlockNumber = blockNumber - BigInt(getMaxBlockEventsQuery(this.name));
}
const fromBlock = bigintToHex(blocksDiff > 1n ? oldLatestBlockNumber + 1n : blockNumber);
const toBlock = bigintToHex(blockNumber);
this.contractEventsEmitter.emitByBlockQuery({ fromBlock, toBlock });
Expand Down Expand Up @@ -594,6 +598,7 @@ export class Network {
// TODO: protect from handlers queueing on the networks with < 3s block time
const resolversToCall = [];
const callbacks = [];

for (const [jobKey, jobData] of Object.entries(this.resolverJobData)) {
callbacks.push(jobData.callback);
resolversToCall.push({
Expand Down Expand Up @@ -622,6 +627,13 @@ export class Network {
for (let i = 0; i < results.length; i++) {
const { jobKey } = resolversToCall[i];
const agent = this.getAgent(jobKey.split('/')[0]);

// Watch job in case of blockchain node lag
if (!this.resolverJobData[jobKey]) {
const jobEntity = await agent.getJob(jobKey.split('/')[1]);
jobEntity.watch();
}

let decoded;
try {
decoded = results[i].success
Expand Down
1 change: 1 addition & 0 deletions app/jobs/AbstractJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ export abstract class AbstractJob {
e.message.includes('Tx not mined, max attempts') ||
e.message.includes('Too many requests') ||
e.message.includes('InsufficientFunds') ||
e.message.includes('exceeds the configured cap') ||
e.message.toLowerCase().includes('insufficient funds') ||
e.message.includes('could not replace existing tx') ||
e.message.includes('replacement fee too low') ||
Expand Down

0 comments on commit 2b9b621

Please sign in to comment.