Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Create a `config.json` file with the following structure:
"metricPort": 70001,
"logLevel": "info",
"rpcRequestTimeout": 5000,
"clientRefreshRate": 0.1,
"chains": [
{
"bech32Prefix": "init",
Expand Down Expand Up @@ -117,6 +118,7 @@ You can also configure Rapid Relayer using environment variables. The following
- `LOG_LEVEL`: Log level
- `RPC_REQUEST_TIMEOUT`: Timeout for RPC requests in milliseconds
- `DB_PATH`: Path to the database directory
- `CLIENT_REFRESH_RATE`: The rate at which to refresh the client. Fraction of the trusting period. Default: 1/3

**Chain configuration:**
You can configure chains in two ways:
Expand Down
8 changes: 5 additions & 3 deletions src/db/controller/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ export class ClientController {
},
])

return client ?? this.addClient(rest, chainId, clientId)
return client ?? (await this.addClient(rest, chainId, clientId))
}

public static getClientsToUpdate(
chainId: string,
counterpartyChainIds: string[]
counterpartyChainIds: string[],
clientRefreshRate?: number
): ClientTable[] {
ClientController.logger.info(
`getClientsToUpdate: chainId=${chainId}, counterpartyChainIds=${counterpartyChainIds.join(',')}`
Expand All @@ -166,7 +167,8 @@ export class ClientController {

// check need update
if (
client.last_update_time + client.trusting_period * 0.666 <
client.last_update_time +
client.trusting_period * (clientRefreshRate ?? 0.333) <
currentTimestamp
) {
return true
Expand Down
5 changes: 5 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export const loadEnvConfig = (): Partial<Config> => {
if (env.MAX_PARALLEL_BLOCKS)
envConfig.maxParallelBlocks = Number(env.MAX_PARALLEL_BLOCKS)
if (env.DB_PATH) envConfig.dbPath = env.DB_PATH
if (env.CLIENT_REFRESH_RATE)
envConfig.clientRefreshRate = Number(env.CLIENT_REFRESH_RATE)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

// chains configuration
if (env.CHAINS) {
Expand Down Expand Up @@ -277,6 +279,8 @@ export const mergeConfigs = (
merged.rpcRequestTimeout = envConfig.rpcRequestTimeout
if (envConfig.maxParallelBlocks !== undefined)
merged.maxParallelBlocks = envConfig.maxParallelBlocks
if (envConfig.clientRefreshRate !== undefined)
merged.clientRefreshRate = envConfig.clientRefreshRate

// merge chains if provided in environment variables
if (envConfig.chains && envConfig.chains.length > 0) {
Expand Down Expand Up @@ -314,6 +318,7 @@ export interface Config {
maxParallelBlocks?: number
chains: ChainConfig[]
raft?: RaftConfig
clientRefreshRate?: number
}

export interface RaftConfig {
Expand Down
3 changes: 2 additions & 1 deletion src/workers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ export class WorkerController {
walletConfig.maxHandlePacket ?? 100,
new Wallet(rest, key),
balance,
walletConfig.packetFilter
walletConfig.packetFilter,
config.clientRefreshRate
)
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/workers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export class WalletWorker {
private maxHandlePacket: number,
public wallet: Wallet,
public gasTokenBalance: bigint,
public packetFilter?: PacketFilter
public packetFilter?: PacketFilter,
public clientRefreshRate?: number
) {
this.logger = createLoggerWithPrefix(
`<Wallet(${this.chain.chainId}-${this.address()})>`
Expand Down Expand Up @@ -224,7 +225,8 @@ export class WalletWorker {
// check clients that need to update
const clientsToUpdate = ClientController.getClientsToUpdate(
this.chain.chainId,
counterpartyChainIdsWithFeeFilter.map((f) => f.chainId)
counterpartyChainIdsWithFeeFilter.map((f) => f.chainId),
this.clientRefreshRate
)

// get unique client id
Expand Down