Skip to content

Commit

Permalink
Merge pull request #3443 from OriginTrail/v8/blockchain-events-servic…
Browse files Browse the repository at this point in the history
…e-improvements

BlockchainEventsService improvements
  • Loading branch information
u-hubar authored Nov 29, 2024
2 parents bd57fb7 + 1c918e9 commit 7051518
Show file tree
Hide file tree
Showing 16 changed files with 210 additions and 226 deletions.
41 changes: 36 additions & 5 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@
"ot-ethers": {
"enabled": true,
"package": "./blockchain-events/implementation/ot-ethers/ot-ethers.js",
"config": {}
"config": {
"blockchains": ["hardhat1:31337", "hardhat2:31337"],
"rpcEndpoints": {
"hardhat1:31337:": ["http://localhost:8545"],
"hardhat2:31337": ["http://localhost:9545"]
}
}
}
}
}
Expand Down Expand Up @@ -345,7 +351,13 @@
"ot-ethers": {
"enabled": true,
"package": "./blockchain-events/implementation/ot-ethers/ot-ethers.js",
"config": {}
"config": {
"blockchains": ["hardhat1:31337", "hardhat2:31337"],
"rpcEndpoints": {
"hardhat1:31337:": ["http://localhost:8545"],
"hardhat2:31337": ["http://localhost:9545"]
}
}
}
}
}
Expand Down Expand Up @@ -523,7 +535,12 @@
"ot-ethers": {
"enabled": true,
"package": "./blockchain-events/implementation/ot-ethers/ot-ethers.js",
"config": {}
"config": {
"blockchains": ["base:84532"],
"rpcEndpoints": {
"base:84532": ["https://sepolia.base.org"]
}
}
}
}
}
Expand Down Expand Up @@ -700,7 +717,12 @@
"ot-ethers": {
"enabled": true,
"package": "./blockchain-events/implementation/ot-ethers/ot-ethers.js",
"config": {}
"config": {
"blockchains": ["base:84532"],
"rpcEndpoints": {
"base:84532": ["https://sepolia.base.org"]
}
}
}
}
}
Expand Down Expand Up @@ -900,7 +922,16 @@
"ot-ethers": {
"enabled": true,
"package": "./blockchain-events/implementation/ot-ethers/ot-ethers.js",
"config": {}
"config": {
"blockchains": ["otp:2043"],
"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 = {
'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
20 changes: 9 additions & 11 deletions src/modules/blockchain-events/blockchain-events-module-manager.js
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

0 comments on commit 7051518

Please sign in to comment.