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

Blockchain events improvements #3446

Merged
merged 12 commits into from
Dec 1, 2024
19 changes: 18 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@
"config": {
"blockchains": ["hardhat1:31337", "hardhat2:31337"],
"rpcEndpoints": {
"hardhat1:31337:": ["http://localhost:8545"],
"hardhat1:31337": ["http://localhost:8545"],
"hardhat2:31337": ["http://localhost:9545"]
},
"hubContractAddress": {
"hardhat1:31337": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
"hardhat2:31337": "0x5FbDB2315678afecb367f032d93F642f64180aa3"
}
}
}
Expand Down Expand Up @@ -356,6 +360,10 @@
"rpcEndpoints": {
"hardhat1:31337:": ["http://localhost:8545"],
"hardhat2:31337": ["http://localhost:9545"]
},
"hubContractAddress": {
"hardhat1:31337": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
"hardhat2:31337": "0x5FbDB2315678afecb367f032d93F642f64180aa3"
}
}
}
Expand Down Expand Up @@ -539,6 +547,9 @@
"blockchains": ["base:84532"],
"rpcEndpoints": {
"base:84532": ["https://sepolia.base.org"]
},
"hubContractAddress": {
"base:84532": "0xCca0eA14540588A09c85cD6A6Fc53eA3A7010692"
}
}
}
Expand Down Expand Up @@ -721,6 +732,9 @@
"blockchains": ["base:84532"],
"rpcEndpoints": {
"base:84532": ["https://sepolia.base.org"]
},
"hubContractAddress": {
"base:84532": "0xAB4A4794Fc1F415C24807B947280aCa8dC492238"
}
}
}
Expand Down Expand Up @@ -930,6 +944,9 @@
"https://astrosat.origintrail.network/",
"https://astrosat-2.origintrail.network/"
]
},
"hubContractAddress": {
"otp:2043": "0x5fA7916c48Fe6D5F1738d12Ad234b78c90B4cAdA"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,9 @@ class BlockchainEventListenerCommand extends Command {
contractName,
);

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

const result = await this.blockchainEventsService.getPastEvents(
blockchain,
contractName,
contract,
eventsToFilter,
lastCheckedBlockObject?.lastCheckedBlock ?? 0,
currentBlock,
Expand Down
30 changes: 30 additions & 0 deletions src/commands/command-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ class CommandExecutor {
async _execute(executeCommand) {
const command = executeCommand;
const now = Date.now();

if (command.isBlocking) {
// Check the db to see if the previous instance of this command is still running
const blockingCommands = await this.repositoryModuleManager.getCommandWithNameAndStatus(
command.name,
[COMMAND_STATUS.STARTED],
);
if (blockingCommands.length !== 0) {
for (const blockingCommand of blockingCommands) {
// Sometimes we run 2 commands with the same name but, e.g. for different blockchains. We can differentiate them by their data values
if (JSON.stringify(blockingCommand.data) === JSON.stringify(command.data)) {
// eslint-disable-next-line no-await-in-loop
await this.repositoryModuleManager.removeCommands([command.id]);
this.logger.info(
`Skipping command: ${command.name}, because the previous iteration of this command has not yet finished execution`,
);
return;
}
}
}
}

await this._update(command, {
startedAt: now,
});
Expand Down Expand Up @@ -387,6 +409,7 @@ class CommandExecutor {
command.delay = command.delay ?? 0;
command.transactional = command.transactional ?? 0;
command.priority = command.priority ?? DEFAULT_COMMAND_PRIORITY;
command.isBlocking = command.isBlocking ?? false;
command.status = COMMAND_STATUS.PENDING;

if (!command.data) {
Expand Down Expand Up @@ -449,6 +472,12 @@ class CommandExecutor {

const commands = [];
for (const command of pendingCommands) {
if (command?.isBlocking === true && command?.parentId === null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need to check if boolean is equal to true, you can just use isBlocking && ...

Copy link
Member

Choose a reason for hiding this comment

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

Imo we should have stricter conditions, truthy conditions may cause issues that are hard to debug

this.logger.trace(`Commands: ${command.name} will replay`);
commands.push(command);
continue;
}

if (!command?.parentId) {
continue;
}
Expand All @@ -470,6 +499,7 @@ class CommandExecutor {
name: commandModel.name,
data: commandModel.data,
priority: commandModel.priority ?? DEFAULT_COMMAND_PRIORITY,
isBlocking: commandModel.isBlocking ?? false,
readyAt: commandModel.readyAt,
delay: commandModel.delay,
startedAt: commandModel.startedAt,
Expand Down
32 changes: 32 additions & 0 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BigNumber, ethers } from 'ethers';
import { createRequire } from 'module';

export const WS_RPC_PROVIDER_PRIORITY = 2;

Expand Down Expand Up @@ -229,6 +230,37 @@ export const TRANSACTION_PRIORITY = {
LOWEST: 20,
};

const require = createRequire(import.meta.url);

export const ABIs = {
ContentAsset: require('dkg-evm-module/abi/ContentAssetV2.json'),
ContentAssetStorage: require('dkg-evm-module/abi/ContentAssetStorageV2.json'),
AssertionStorage: require('dkg-evm-module/abi/AssertionStorage.json'),
Staking: require('dkg-evm-module/abi/Staking.json'),
StakingStorage: require('dkg-evm-module/abi/StakingStorage.json'),
Token: require('dkg-evm-module/abi/Token.json'),
HashingProxy: require('dkg-evm-module/abi/HashingProxy.json'),
Hub: require('dkg-evm-module/abi/Hub.json'),
IdentityStorage: require('dkg-evm-module/abi/IdentityStorage.json'),
Log2PLDSF: require('dkg-evm-module/abi/Log2PLDSF.json'),
ParametersStorage: require('dkg-evm-module/abi/ParametersStorage.json'),
Profile: require('dkg-evm-module/abi/Profile.json'),
ProfileStorage: require('dkg-evm-module/abi/ProfileStorage.json'),
ScoringProxy: require('dkg-evm-module/abi/ScoringProxy.json'),
ServiceAgreementV1: require('dkg-evm-module/abi/ServiceAgreementV1.json'),
CommitManagerV1: require('dkg-evm-module/abi/CommitManagerV2.json'),
CommitManagerV1U1: require('dkg-evm-module/abi/CommitManagerV2U1.json'),
ProofManagerV1: require('dkg-evm-module/abi/ProofManagerV1.json'),
ProofManagerV1U1: require('dkg-evm-module/abi/ProofManagerV1U1.json'),
ShardingTable: require('dkg-evm-module/abi/ShardingTableV2.json'),
ShardingTableStorage: require('dkg-evm-module/abi/ShardingTableStorageV2.json'),
ServiceAgreementStorageProxy: require('dkg-evm-module/abi/ServiceAgreementStorageProxy.json'),
UnfinalizedStateStorage: require('dkg-evm-module/abi/UnfinalizedStateStorage.json'),
LinearSum: require('dkg-evm-module/abi/LinearSum.json'),
ParanetsRegistry: require('dkg-evm-module/abi/ParanetsRegistry.json'),
ParanetKnowledgeAssetsRegistry: require('dkg-evm-module/abi/ParanetKnowledgeAssetsRegistry.json'),
};

export const CONTRACT_FUNCTION_PRIORITY = {
'submitCommit((address,uint256,bytes,uint8,uint16,uint72,uint72,uint72))':
TRANSACTION_PRIORITY.MEDIUM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class BlockchainEventsModuleManager extends BaseModuleManager {
async getPastEvents(
implementationName,
blockchain,
contract,
contractName,
eventsToFilter,
lastCheckedBlock,
Expand All @@ -20,7 +19,6 @@ class BlockchainEventsModuleManager extends BaseModuleManager {
if (this.getImplementation(implementationName)) {
return this.getImplementation(implementationName).module.getPastEvents(
blockchain,
contract,
contractName,
eventsToFilter,
lastCheckedBlock,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { CONTRACTS } from '../../../constants/constants.js';

class BlockchainEventsService {
async initialize(config, logger) {
this.logger = logger;
this.config = config;

this.contractsToMonitor = [
CONTRACTS.SHARDING_TABLE_CONTRACT,
CONTRACTS.STAKING_CONTRACT,
CONTRACTS.PROFILE_CONTRACT,
CONTRACTS.COMMIT_MANAGER_V1_U1_CONTRACT,
CONTRACTS.PARAMETERS_STORAGE_CONTRACT,
CONTRACTS.LOG2PLDSF_CONTRACT,
CONTRACTS.LINEAR_SUM_CONTRACT,
];
}

async getBlock() {
Expand Down
Loading
Loading