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

BlockchainEventsService improvements #3443

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
36 changes: 31 additions & 5 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@
"ot-ethers": {
"enabled": true,
"package": "./blockchain-events/implementation/ot-ethers/ot-ethers.js",
"config": {}
"config": {
"rpcEndpoints": {
"hardhat1:31337:": ["http://localhost:8545"],
"hardhat2:31337": ["http://localhost:9545"]
}
}
}
}
}
Expand Down Expand Up @@ -345,7 +350,12 @@
"ot-ethers": {
"enabled": true,
"package": "./blockchain-events/implementation/ot-ethers/ot-ethers.js",
"config": {}
"config": {
"rpcEndpoints": {
"hardhat1:31337:": ["http://localhost:8545"],
"hardhat2:31337": ["http://localhost:9545"]
}
}
}
}
}
Expand Down Expand Up @@ -523,7 +533,11 @@
"ot-ethers": {
"enabled": true,
"package": "./blockchain-events/implementation/ot-ethers/ot-ethers.js",
"config": {}
"config": {
"rpcEndpoints": {
"base:84532": ["https://sepolia.base.org"]
}
}
}
}
}
Expand Down Expand Up @@ -700,7 +714,11 @@
"ot-ethers": {
"enabled": true,
"package": "./blockchain-events/implementation/ot-ethers/ot-ethers.js",
"config": {}
"config": {
"rpcEndpoints": {
"base:84532": ["https://sepolia.base.org"]
}
}
}
}
}
Expand Down Expand Up @@ -900,7 +918,15 @@
"ot-ethers": {
"enabled": true,
"package": "./blockchain-events/implementation/ot-ethers/ot-ethers.js",
"config": {}
"config": {
"rpcEndpoints": {
"otp:2043": [
"https://astrosat-parachain-rpc.origin-trail.network",
"https://astrosat.origintrail.network/",
"https://astrosat-2.origintrail.network/"
]
}
}
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class OTNode {
await this.initializeCommandExecutor();
await this.initializeShardingTableService();

this.initializeBlockchainEventsService();

await this.initializeRouters();
await this.startNetworkModule();
await this.initializeBLSService();
Expand Down Expand Up @@ -295,6 +297,19 @@ class OTNode {
}
}

initializeBlockchainEventsService() {
try {
const blockchainEventsService = this.container.resolve('blockchainEventsService');
blockchainEventsService.initializeBlockchainEventsServices();
this.logger.info('Blockchain Events Service initialized successfully');
} catch (error) {
this.logger.error(
`Unable to initialize Blockchain Events Service. Error message: ${error.message} OT-node shutting down...`,
);
this.stop(1);
}
}

async removeUpdateFile() {
const updateFilePath = this.fileService.getUpdateFilePath();
await this.fileService.removeFile(updateFilePath).catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ class BlockchainEventListenerCommand extends Command {
this.serviceAgreementService = ctx.serviceAgreementService;
this.shardingTableService = ctx.shardingTableService;
this.paranetService = ctx.paranetService;
this.blockchainEventsModuleManager = ctx.blockchainEventsModuleManager;
this.blockchainEventsService = ctx.blockchainEventsService;
this.fileService = ctx.fileService;
this.dataService = ctx.dataService;
this.operationIdService = ctx.operationIdService;
this.commandExecutor = ctx.commandExecutor;

this.blockchainEventsModuleImplementation =
this.blockchainEventsModuleManager.getImplementation();
this.eventGroupsBuffer = {};

this.errorType = ERROR_TYPE.BLOCKCHAIN_EVENT_LISTENER_ERROR;
Expand All @@ -47,13 +45,6 @@ class BlockchainEventListenerCommand extends Command {
async execute(command) {
const { blockchainId } = command.data;

const blockchainConfig = this.blockchainModuleManager.getModuleConfiguration(blockchainId);

await this.blockchainEventsModuleManager.initializeImplementation(
this.blockchainEventsModuleImplementation,
blockchainConfig,
);

try {
await this.fetchAndHandleBlockchainEvents(blockchainId);
fetchEventsFailedCount[blockchainId] = 0;
Expand Down Expand Up @@ -154,27 +145,25 @@ class BlockchainEventListenerCommand extends Command {
);
}

async getContractEvents(blockchainId, contractName, currentBlock, eventsToFilter) {
async getContractEvents(blockchain, contractName, currentBlock, eventsToFilter) {
const lastCheckedBlockObject = await this.repositoryModuleManager.getLastCheckedBlock(
blockchainId,
blockchain,
contractName,
);

const contract = this.blockchainModuleManager.getContract(blockchainId, contractName);
const contract = this.blockchainModuleManager.getContract(blockchain, contractName);

const result = await this.blockchainEventsModuleManager.getAllPastEvents(
this.blockchainEventsModuleImplementation,
blockchainId,
const result = await this.blockchainEventsService.getPastEvents(
blockchain,
contractName,
contract,
eventsToFilter,
lastCheckedBlockObject?.lastCheckedBlock ?? 0,
lastCheckedBlockObject?.lastCheckedTimestamp ?? 0,
currentBlock,
);

if (!result.eventsMissed) {
await this.shardingTableService.pullBlockchainShardingTable(blockchainId, true);
await this.shardingTableService.pullBlockchainShardingTable(blockchain, true);
}

const { events, lastCheckedBlock } = result;
Expand Down
5 changes: 0 additions & 5 deletions src/commands/command-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,6 @@ class CommandExecutor {

const commands = [];
for (const command of pendingCommands) {
if (command.name === 'blockchainEventListenerCommand') {
commands.push(command);
continue;
}

if (!command?.parentId) {
continue;
}
Expand Down
12 changes: 0 additions & 12 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,20 +780,8 @@ export const CONTRACT_EVENT_FETCH_INTERVALS = {
DEVELOPMENT: 4 * 1000,
};

export const BLOCKCHAIN_ID_TO_NAME = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are still using this for backwards compatibility old and new ual format

'hardhat1:31337': 'HARDHAT',
'hardhat2:31337': 'HARDHAT',
'base:84532': 'BASE',
'otp:2043': 'OTP',
'gnosis:100': 'GNOSIS',
};

export const BLOCK_TIME_MILLIS = {
OTP: 12_000,
HARDHAT: 5_000,
GNOSIS: 5_000,
DEFAULT: 12_000,
BASE: 2_000,
};

export const TRANSACTION_CONFIRMATIONS = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import BaseModuleManager from '../base-module-manager.js';

class BlockchainEventsModuleManager extends BaseModuleManager {
async initializeImplementation(blockchainEventsImplementation, blockchainConfig) {
if (this.getImplementation(blockchainEventsImplementation)) {
return this.getImplementation(
blockchainEventsImplementation,
).module.initializeImplementation(blockchainConfig);
async getBlock(implementationName, blockchain, tag) {
if (this.getImplementation(implementationName)) {
return this.getImplementation(implementationName).module.getBlock(blockchain, tag);
}
}

async getAllPastEvents(
blockchainEventsImplementation,
blockchainId,
async getPastEvents(
implementationName,
blockchain,
contract,
contractName,
eventsToFilter,
lastCheckedBlock,
lastCheckedTimestamp,
currentBlock,
) {
if (this.getImplementation(blockchainEventsImplementation)) {
return this.getImplementation(blockchainEventsImplementation).module.getAllPastEvents(
blockchainId,
if (this.getImplementation(implementationName)) {
return this.getImplementation(implementationName).module.getPastEvents(
blockchain,
contract,
contractName,
eventsToFilter,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class BlockchainEventsService {
async initialize(config, logger) {
this.logger = logger;
this.config = config;
}

async getBlock() {
throw Error('getBlock not implemented');
}

async getPastEvents() {
throw Error('getPastEvents not implemented');
}
}

export default BlockchainEventsService;

This file was deleted.

Loading
Loading