Skip to content

Commit

Permalink
parallel get bock and event
Browse files Browse the repository at this point in the history
  • Loading branch information
cauta committed May 13, 2024
1 parent e5a15d1 commit 45eaf47
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 74 deletions.
76 changes: 39 additions & 37 deletions app/apps/worker-service/src/worker/ethereum.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,36 @@ export class EthereumWorker {
return;
}
try {
// Retrieve all transaction in block
const startGetBlock = Date.now();
const block = await this.provider.getBlock(blockNumber, true);
const result = await Promise.all([
this.provider.getBlock(blockNumber, true),
this.provider.getLogs({
fromBlock: blockNumber,
toBlock: blockNumber,
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
],
}),
]);
// Retrieve all transaction in block
const block = result[0];
const logs = result[1];
const endGetBlock = Date.now();

// Retrieve transfer event the block's logs
const startGetLogs = Date.now();
const logs = await this.provider.getLogs({
fromBlock: blockNumber,
toBlock: blockNumber,
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
],
});
const endGetLogs = Date.now();

const emitStart = Date.now();
// handle native transfer
await this.emitNativeTransaction(block, false);
// handle extracted event for erc20 and nft
await this.emitLog(logs, false);
await Promise.all([
this.emitNativeTransaction(block, true),
this.emitLog(logs, true),
]);
const emitEnd = Date.now();
//only update last sync for confirm
await this.saveBlockHistory(blockNumber, false);
this.logger.log(
`DETECT Scanning block ${blockNumber} in ${
Date.now() - start
}ms and emit ${emitEnd - emitStart}ms and getBlock ${
}ms and emit ${emitEnd - emitStart}ms and GetEvent ${
endGetBlock - startGetBlock
}ms and getLogs ${endGetLogs - startGetLogs}ms`,
}ms`,
);
} catch (error) {
this.logger.error([
Expand Down Expand Up @@ -102,33 +102,35 @@ export class EthereumWorker {
try {
// Retrieve all transaction in block
const startGetBlock = Date.now();
const block = await this.provider.getBlock(blockNumber, true);
const result = await Promise.all([
this.provider.getBlock(blockNumber, true),
this.provider.getLogs({
fromBlock: blockNumber,
toBlock: blockNumber,
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
],
}),
]);
// Retrieve all transaction in block
const block = result[0];
const logs = result[1];
const endGetBlock = Date.now();

// Retrieve transfer event the block's logs
const startGetLogs = Date.now();
const logs = await this.provider.getLogs({
fromBlock: blockNumber,
toBlock: blockNumber,
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
],
});
const endGetLogs = Date.now();

const emitStart = Date.now();
// handle native transfer
await this.emitNativeTransaction(block, true);
// handle extracted event for erc20 and nft
await this.emitLog(logs, true);
await Promise.all([
this.emitNativeTransaction(block, true),
this.emitLog(logs, true),
]);
const emitEnd = Date.now();

await this.saveBlockHistory(blockNumber, true);
this.logger.log(
`CONFIRM Scanning block ${blockNumber} in ${
Date.now() - start
}ms and emit ${emitEnd - emitStart}ms and getblock ${
}ms and emit ${emitEnd - emitStart}ms and GetEvent ${
endGetBlock - startGetBlock
}ms and getLogs ${endGetLogs - startGetLogs}ms`,
}ms`,
);
} catch (error) {
this.logger.error([
Expand Down
76 changes: 39 additions & 37 deletions app/apps/worker-service/src/worker/polygon.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,36 @@ export class PolygonWorker {
return;
}
try {
// Retrieve all transaction in block
const startGetBlock = Date.now();
const block = await this.provider.getBlock(blockNumber, true);
const result = await Promise.all([
this.provider.getBlock(blockNumber, true),
this.provider.getLogs({
fromBlock: blockNumber,
toBlock: blockNumber,
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
],
}),
]);
// Retrieve all transaction in block
const block = result[0];
const logs = result[1];
const endGetBlock = Date.now();

// Retrieve transfer event the block's logs
const startGetLogs = Date.now();
const logs = await this.provider.getLogs({
fromBlock: blockNumber,
toBlock: blockNumber,
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
],
});
const endGetLogs = Date.now();

const emitStart = Date.now();
// handle native transfer
await this.emitNativeTransaction(block, false);
// handle extracted event for erc20 and nft
await this.emitLog(logs, false);
await Promise.all([
this.emitNativeTransaction(block, true),
this.emitLog(logs, true),
]);
const emitEnd = Date.now();
//only update last sync for confirm
await this.saveBlockHistory(blockNumber, false);
this.logger.log(
`DETECT Scanning block ${blockNumber} in ${
Date.now() - start
}ms with emit ${emitEnd - emitStart}ms and getBlock ${
}ms and emit ${emitEnd - emitStart}ms and GetEvent ${
endGetBlock - startGetBlock
}ms and getLogs ${endGetLogs - startGetLogs}ms`,
}ms`,
);
} catch (error) {
this.logger.error([
Expand Down Expand Up @@ -101,33 +101,35 @@ export class PolygonWorker {
try {
// Retrieve all transaction in block
const startGetBlock = Date.now();
const block = await this.provider.getBlock(blockNumber, true);
const result = await Promise.all([
this.provider.getBlock(blockNumber, true),
this.provider.getLogs({
fromBlock: blockNumber,
toBlock: blockNumber,
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
],
}),
]);
// Retrieve all transaction in block
const block = result[0];
const logs = result[1];
const endGetBlock = Date.now();

// Retrieve transfer event the block's logs
const startGetLogs = Date.now();
const logs = await this.provider.getLogs({
fromBlock: blockNumber,
toBlock: blockNumber,
topics: [
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
],
});
const endGetLogs = Date.now();

const emitStart = Date.now();
// handle native transfer
await this.emitNativeTransaction(block, true);
// handle extracted event for erc20 and nft
await this.emitLog(logs, true);
await Promise.all([
this.emitNativeTransaction(block, true),
this.emitLog(logs, true),
]);
const emitEnd = Date.now();

await this.saveBlockHistory(blockNumber, true);
this.logger.log(
`CONFIRM Scanning block ${blockNumber} in ${
Date.now() - start
}ms with emit ${emitEnd - emitStart}ms and getBlock ${
}ms and emit ${emitEnd - emitStart}ms and GetEvent ${
endGetBlock - startGetBlock
}ms and getLogs ${endGetLogs - startGetLogs}ms`,
}ms`,
);
} catch (error) {
this.logger.error([
Expand Down

0 comments on commit 45eaf47

Please sign in to comment.