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

zero bug #37

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
24 changes: 15 additions & 9 deletions src/processors/zero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import { ZeroService } from "../service/zero";
import { config } from "../config";

const NAME = "ZERO";
const REPEAT_JOB_OPT = { jobId: NAME, repeat: { cron: config.cronJob.zeroJobExpression}};
const REPEAT_JOB_OPT = {
jobId: NAME,
repeat: { cron: config.cronJob.zeroJobExpression },
};

export class Zero implements ProcessorInterface {
private queue: Bull.Queue;
private logger: bunyan;
private zeroService: ZeroService;

constructor(logger: bunyan) {
this.logger = logger;
this.queue = new Bull(NAME);
Expand All @@ -35,21 +38,24 @@ export class Zero implements ProcessorInterface {
});
return this;
}

async reset(): Promise<void> {
await this.queue.add({}, REPEAT_JOB_OPT);
}

async processEvent() {
const payloads = await this.zeroService.getPayloads();
if (payloads.length) {
this.logger.info("Nothing to process in xdc-zero, wait for the next event log");
if (payloads.length == 0) {
this.logger.info(
"Nothing to process in xdc-zero, wait for the next event log"
);
return;
}
const lastPayload = payloads[payloads.length - 1];
const lastIndexFromSubnet = lastPayload[0];

const lastIndexfromParentnet = await this.zeroService.getIndexFromParentnet();
const lastIndexfromParentnet =
await this.zeroService.getIndexFromParentnet();

const lastBlockNumber = lastPayload[7];
const cscBlockNumber = await this.zeroService.getLatestBlockNumberFromCsc();
Expand All @@ -62,7 +68,7 @@ export class Zero implements ProcessorInterface {
);
return;
}

if (lastIndexFromSubnet > lastIndexfromParentnet) {
for (let i = lastIndexfromParentnet; i < lastIndexFromSubnet; i++) {
if (payloads?.[i]?.[6]) {
Expand All @@ -79,4 +85,4 @@ export class Zero implements ProcessorInterface {
}
this.logger.info("Completed the xdc-zero sync, wait for the next cycle");
}
}
}
1 change: 1 addition & 0 deletions src/service/zero/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class ZeroService {
});

const parentChainId = await this.mainnetViemClient.getChainId();

logs?.forEach((log) => {
const values = decodeAbiParameters(
[
Expand Down