Skip to content

Commit e669650

Browse files
authoredNov 12, 2024
add option for cache capacity (#1054)
1 parent ce8fd1d commit e669650

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed
 
+11-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import { ApiPromise, WsProvider } from '@polkadot/api';
2-
import { withAcalaTypes } from '@acala-network/api';
2+
import { acalaTypesBundle } from '@acala-network/types';
33

44
import { BaseProvider, BaseProviderOptions } from './base-provider';
55

6+
export type EvmRpcProviderOptions = BaseProviderOptions & {
7+
rpcCacheCapacity?: number;
8+
};
9+
610
export class EvmRpcProvider extends BaseProvider {
7-
constructor(endpoint: string | string[], opts?: BaseProviderOptions) {
11+
constructor(endpoint: string | string[], opts?: EvmRpcProviderOptions) {
812
super(opts);
913

10-
const api = new ApiPromise(withAcalaTypes({
14+
const api = new ApiPromise({
1115
provider: new WsProvider(endpoint),
12-
}));
16+
typesBundle: acalaTypesBundle,
17+
rpcCacheCapacity: opts?.rpcCacheCapacity,
18+
});
1319

1420
this.setApi(api);
1521
}
1622

17-
static from(endpoint: string | string[], opt?: BaseProviderOptions): EvmRpcProvider {
23+
static from(endpoint: string | string[], opt?: EvmRpcProviderOptions): EvmRpcProvider {
1824
return new EvmRpcProvider(endpoint, opt);
1925
}
2026
}

‎packages/eth-rpc-adapter/src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export async function start(): Promise<void> {
1818
subqlUrl: opts.subqlUrl,
1919
maxBlockCacheSize: opts.maxBlockCacheSize,
2020
storageCacheSize: opts.storageCacheSize,
21+
rpcCacheCapacity: opts.rpcCacheCapacity,
2122
});
2223

2324
const bridge = new Eip1193Bridge(provider);
@@ -58,8 +59,9 @@ export async function start(): Promise<void> {
5859
server host : ${opts.host}
5960
server port : ${opts.port}
6061
max blockCache : ${opts.maxBlockCacheSize}
61-
max batchSize : ${opts.maxBatchSize}
62+
max batchSize : ${opts.maxBatchSize}
6263
max storageSize : ${opts.storageCacheSize}
64+
cache capacity : ${opts.rpcCacheCapacity}
6365
safe mode : ${opts.safeMode}
6466
local mode : ${opts.localMode}
6567
http only : ${opts.httpOnly}

‎packages/eth-rpc-adapter/src/utils/utils.ts

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
MAX_CACHE_SIZE,
1212
MAX_BATCH_SIZE,
1313
STORAGE_CACHE_SIZE,
14+
RPC_CACHE_CAPACITY,
1415
SAFE_MODE,
1516
LOCAL_MODE,
1617
HTTP_ONLY,
@@ -76,6 +77,12 @@ export const yargsOptions = yargs(hideBin(process.argv))
7677
describe: 'max storage cache size',
7778
type: 'number',
7879
},
80+
rpcCacheCapacity: {
81+
demandOption: false,
82+
default: Number(RPC_CACHE_CAPACITY ?? 1000),
83+
describe: 'polkadot api rpc cache capacity',
84+
type: 'number',
85+
},
7986
safeMode: {
8087
alias: 's',
8188
demandOption: false,

‎packages/eth-rpc-adapter/src/wrapped-provider.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ApiPromise, WsProvider } from '@polkadot/api';
2-
import { BaseProvider, BaseProviderOptions } from '@acala-network/eth-providers/base-provider';
3-
import { withAcalaTypes } from '@acala-network/api';
2+
import { BaseProvider } from '@acala-network/eth-providers/base-provider';
3+
import { EvmRpcProviderOptions } from '@acala-network/eth-providers';
4+
import { acalaTypesBundle } from '@acala-network/types';
45
import tracer from 'dd-trace';
56

67
const TRACE_METHODS = [
@@ -78,17 +79,19 @@ export class BaseProviderWithTrace extends BaseProvider {
7879
}
7980

8081
export class EvmRpcProviderWithTrace extends BaseProviderWithTrace {
81-
constructor(endpoint: string | string[], opts?: BaseProviderOptions) {
82+
constructor(endpoint: string | string[], opts?: EvmRpcProviderOptions) {
8283
super(opts);
8384

84-
const api = new ApiPromise(withAcalaTypes({
85+
const api = new ApiPromise({
8586
provider: new WsProvider(endpoint),
86-
}));
87+
typesBundle: acalaTypesBundle,
88+
rpcCacheCapacity: opts?.rpcCacheCapacity,
89+
});
8790

8891
this.setApi(api);
8992
}
9093

91-
static from(endpoint: string | string[], opt?: BaseProviderOptions): EvmRpcProviderWithTrace {
94+
static from(endpoint: string | string[], opt?: EvmRpcProviderOptions): EvmRpcProviderWithTrace {
9295
return new EvmRpcProviderWithTrace(endpoint, opt);
9396
}
9497
}

0 commit comments

Comments
 (0)