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

Feat: data bus #247

Merged
merged 31 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8fe62d7
feat: basic data-bus impl
eddort Sep 20, 2024
03a5f11
feat: forFeature method
eddort Sep 20, 2024
8be7e79
feat: human readable abi
eddort Sep 20, 2024
ccbe92a
feat: data-bus client
eddort Sep 21, 2024
d0b6122
feat: data bus client
eddort Sep 21, 2024
4a16e24
fix: add zod to package json
eddort Sep 22, 2024
da37e50
fix: config and types
eddort Sep 22, 2024
c890638
feat: dsm binding
eddort Sep 22, 2024
ad3d19a
fix: config tests
eddort Sep 22, 2024
0fb7f3f
feat: connect new transport
eddort Sep 22, 2024
045843a
feat: first prototype
eddort Sep 22, 2024
663367d
fix: cyclical dependency
eddort Sep 22, 2024
7194184
test: skip test and add todo
eddort Sep 22, 2024
577d5ee
test: add todo
eddort Sep 22, 2024
fd26d01
fix: lazy provider for data bus
eddort Sep 23, 2024
761b6e6
fix: concurrent requests and nonce errors
eddort Sep 23, 2024
687141e
fix: import abi and error flow
eddort Sep 24, 2024
0213a0f
refactor: ping messages and code style
eddort Sep 26, 2024
adff78a
fix: MessagePauseV3
eddort Sep 26, 2024
a4e3ad8
fix: prom data bus metrics
eddort Sep 26, 2024
ca08729
Merge branch 'prerelease-3.1.0' of github.com:lidofinance/lido-counci…
eddort Sep 30, 2024
c6dec90
feat: timeout handling in data bus
eddort Sep 30, 2024
2950838
refactor: mutex tests
eddort Sep 30, 2024
0f62c2f
refactor: code review
eddort Sep 30, 2024
7c8c439
refactor: abi client generation
eddort Sep 30, 2024
2f558fe
feat: update config and docs
eddort Sep 30, 2024
14d8ca0
fix: balance monitoring
eddort Sep 30, 2024
7086a3d
fix: data bus naming
eddort Sep 30, 2024
6214344
fix: code review
eddort Oct 2, 2024
a1ca44b
feat: send ping message in async way
eddort Oct 2, 2024
ab77642
fix: set lastContractsStateByModuleId after message publishing
eddort Oct 3, 2024
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
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The Lido Council Daemon monitors deposit contract keys and compares them to Lido
## Table of Contents

- [Environment Variables](#environment-variables)
- [RabbitMQ](#rabbitmq)
- [Data Bus Transports](#data-bus-transports)
- [Wallet Private Key](#wallet-private-key)
- [Keys-API Configuration](#keys-api-configuration)
- [Example ENV Config File](#example-env-config-file)
Expand All @@ -19,10 +19,12 @@ The Lido Council Daemon monitors deposit contract keys and compares them to Lido

## Environment Variables

Several environment variables must be set for the daemon to function properly. These variables include RabbitMQ settings, wallet private key, and Keys-API configuration.
Several environment variables must be set for the daemon to function properly. These variables include Data Bus Transports settings, wallet private key, and Keys-API configuration.

### RabbitMQ
### Data Bus Transports
You need to install one of the transports

#### RabbitMQ
```env
...
PUBSUB_SERVICE=rabbitmq
Expand All @@ -33,6 +35,16 @@ RABBITMQ_PASSCODE=<rabbitmq password>
...
```

#### EVM Chain transport
```env
...
PUBSUB_SERVICE=evm-chain

EVM_CHAIN_DATA_BUS_ADDRESS=<evm transport contract address>
EVM_CHAIN_DATA_BUS_PROVIDER_URL=<evm chain node url>
...
```

### Wallet Private Key

```env
Expand Down
11 changes: 4 additions & 7 deletions develop.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ LOG_LEVEL=info
LOG_FORMAT=simple

# Pubsub (default: rabbitmq)
PUBSUB_SERVICE=rabbitmq

# RabbitMQ

RABBITMQ_URL=ws://127.0.0.1:15674/ws
RABBITMQ_LOGIN=guest
RABBITMQ_PASSCODE=guest
PUBSUB_SERVICE=evm-chain
# This is a sample configuration, be sure to replace it with an up-to-date one
EVM_CHAIN_DATA_BUS_ADDRESS="0xD02E999e4F0d464a322d9969d0EdF32ec93257ac"
EVM_CHAIN_DATA_BUS_PROVIDER_URL="https://gnosis-chiado-rpc.publicnode.com"


# Private key
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"winston": "^3.3.3",
"ws": "^8.10.0"
"ws": "^8.10.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@nestjs/cli": "^8.2.5",
Expand Down
7 changes: 7 additions & 0 deletions src/abi/data-bus.abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
"event MessageDepositV1(address indexed guardianAddress, (uint256 blockNumber, bytes32 blockHash, bytes32 depositRoot, uint256 stakingModuleId, uint256 nonce, (bytes32 r, bytes32 vs) signature, (bytes32 version) app) data)",
"event MessagePauseV2(address indexed guardianAddress, (uint256 blockNumber, bytes32 blockHash, (bytes32 r, bytes32 vs) signature, uint256 stakingModuleId, (bytes32 version) app) data)",
"event MessagePauseV3(address indexed guardianAddress, (uint256 blockNumber, bytes32 blockHash, (bytes32 r, bytes32 vs) signature, (bytes32 version) app) data)",
"event MessagePingV1(address indexed guardianAddress, (uint256 blockNumber, (bytes32 version) app) data)",
"event MessageUnvetV1(address indexed guardianAddress, (uint256 blockNumber, bytes32 blockHash, uint256 stakingModuleId, uint256 nonce, bytes operatorIds, bytes vettedKeysByOperator, (bytes32 r, bytes32 vs) signature, (bytes32 version) app) data)"
]
2 changes: 2 additions & 0 deletions src/common/config/config-loader.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const DEFAULTS = {
RABBITMQ_URL: 'some-rabbit-url',
RABBITMQ_LOGIN: 'some-rabbit-login',
KEYS_API_URL: 'keys-api',
EVM_CHAIN_DATA_BUS_ADDRESS: 'DATA_BUS_ADDRESS',
EVM_CHAIN_DATA_BUS_PROVIDER_URL: 'DATA_BUS_PROVIDER_URL',
};

const extractError = async <T>(
Expand Down
5 changes: 4 additions & 1 deletion src/common/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ethers } from 'ethers';

export const Configuration = createInterface<Configuration>('Configuration');

export type PubsubService = 'rabbitmq' | 'kafka';
export type PubsubService = 'rabbitmq' | 'kafka' | 'evm-chain';

export interface Configuration {
NODE_ENV: string;
Expand Down Expand Up @@ -35,4 +35,7 @@ export interface Configuration {
LOCATOR_DEVNET_ADDRESS: string;
WALLET_MIN_BALANCE: ethers.BigNumber;
WALLET_CRITICAL_BALANCE: ethers.BigNumber;
EVM_CHAIN_DATA_BUS_ADDRESS: string;
EVM_CHAIN_DATA_BUS_PROVIDER_URL: string;
EVM_CHAIN_DATA_BUS_WALLET_MIN_BALANCE: ethers.BigNumber;
}
20 changes: 19 additions & 1 deletion src/common/config/in-memory-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TransformToWei } from 'common/decorators/transform-to-wei';

const RABBITMQ = 'rabbitmq';
const KAFKA = 'kafka';
const EVM_CHAIN = 'evm-chain';

@Injectable()
@implementationOf(Configuration)
Expand Down Expand Up @@ -57,7 +58,7 @@ export class InMemoryConfiguration implements Configuration {
BROKER_TOPIC = 'defender';

@IsString()
@IsIn([KAFKA, RABBITMQ])
@IsIn([KAFKA, RABBITMQ, EVM_CHAIN])
PUBSUB_SERVICE: PubsubService = RABBITMQ;

@ValidateIf((conf) => conf.PUBSUB_SERVICE === KAFKA)
Expand Down Expand Up @@ -160,4 +161,21 @@ export class InMemoryConfiguration implements Configuration {
@TransformToWei()
@IsInstance(BigNumber)
WALLET_CRITICAL_BALANCE: BigNumber = ethers.utils.parseEther('0.2');

@ValidateIf((conf) => conf.PUBSUB_SERVICE === EVM_CHAIN)
@IsNotEmpty()
@IsString()
EVM_CHAIN_DATA_BUS_ADDRESS = '';

@ValidateIf((conf) => conf.PUBSUB_SERVICE === EVM_CHAIN)
@IsNotEmpty()
@IsString()
EVM_CHAIN_DATA_BUS_PROVIDER_URL = '';

@ValidateIf((conf) => conf.PUBSUB_SERVICE === EVM_CHAIN)
@IsOptional()
@TransformToWei()
@IsInstance(BigNumber)
EVM_CHAIN_DATA_BUS_WALLET_MIN_BALANCE: BigNumber =
ethers.utils.parseEther('1');
}
5 changes: 5 additions & 0 deletions src/common/prometheus/prometheus.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export const METRIC_RPC_REQUEST_ERRORS = `${METRICS_PREFIX}rpc_requests_errors`;

export const METRIC_ACCOUNT_BALANCE = `${METRICS_PREFIX}account_balance`;

export const METRIC_DATA_BUS_RPC_REQUEST_DURATION = `${METRICS_PREFIX}_data_bus_rpc_requests_duration_seconds`;
export const METRIC_DATA_BUS_RPC_REQUEST_ERRORS = `${METRICS_PREFIX}_data_bus_rpc_requests_errors`;

export const METRIC_DATA_BUS_ACCOUNT_BALANCE = `${METRICS_PREFIX}_data_bus_account_balance`;

export const METRIC_BLOCK_DATA_REQUEST_DURATION = `${METRICS_PREFIX}block_data_requests_duration_seconds`;
export const METRIC_BLOCK_DATA_REQUEST_ERRORS = `${METRICS_PREFIX}block_data_requests_errors`;

Expand Down
6 changes: 6 additions & 0 deletions src/common/prometheus/prometheus.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {
PrometheusDuplicatedKeysProvider,
PrometheusInvalidKeysProvider,
PrometheusUnvetKeysCounterProvider,
PrometheusDataBusRPCErrorsCounterProvider,
PrometheusDataBusAccountBalanceProvider,
PrometheusDataBusRPCRequestsHistogramProvider,
} from './prometheus.provider';
import { METRICS_PREFIX, METRICS_URL } from './prometheus.constants';

Expand All @@ -33,6 +36,9 @@ const providers = [
PrometheusRPCRequestsHistogramProvider,
PrometheusRPCErrorsCounterProvider,
PrometheusAccountBalanceProvider,
PrometheusDataBusRPCRequestsHistogramProvider,
PrometheusDataBusRPCErrorsCounterProvider,
PrometheusDataBusAccountBalanceProvider,
PrometheusBlockDataRequestsProvider,
PrometheusBlockDataErrorsCounterProvider,
PrometheusBuildInfoGaugeProvider,
Expand Down
21 changes: 21 additions & 0 deletions src/common/prometheus/prometheus.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import {
METRIC_DUPLICATED_KEYS_TOTAL,
METRIC_INVALID_KEYS_TOTAL,
METRIC_UNVET_ATTEMPTS,
METRIC_DATA_BUS_ACCOUNT_BALANCE,
METRIC_DATA_BUS_RPC_REQUEST_DURATION,
METRIC_DATA_BUS_RPC_REQUEST_ERRORS,
} from './prometheus.constants';

export const PrometheusTransportMessageCounterProvider = makeCounterProvider({
Expand Down Expand Up @@ -49,6 +52,24 @@ export const PrometheusRPCErrorsCounterProvider = makeCounterProvider({
help: 'Number of RPC requests errors',
});

export const PrometheusDataBusAccountBalanceProvider = makeGaugeProvider({
name: METRIC_DATA_BUS_ACCOUNT_BALANCE,
help: 'DataBus guardian account balance',
labelNames: ['chainId'] as const,
});

export const PrometheusDataBusRPCRequestsHistogramProvider =
makeHistogramProvider({
name: METRIC_DATA_BUS_RPC_REQUEST_DURATION,
help: 'DataBus RPC request duration',
buckets: [0.1, 0.2, 0.3, 0.6, 1, 1.5, 2, 5],
});

export const PrometheusDataBusRPCErrorsCounterProvider = makeCounterProvider({
name: METRIC_DATA_BUS_RPC_REQUEST_ERRORS,
help: 'Number of DataBus RPC requests errors',
});

export const PrometheusAccountBalanceProvider = makeGaugeProvider({
name: METRIC_ACCOUNT_BALANCE,
help: 'Guardian account balance',
Expand Down
Loading
Loading