diff --git a/src/api.ts b/src/api.ts index ba0e404..577ffca 100755 --- a/src/api.ts +++ b/src/api.ts @@ -2785,6 +2785,10 @@ export const methods = { unsubscribe, type: Types.FilterTypes.block, } + if (filtersMap.size >= config.maxEntriesAllowed) { + filtersMap.clear() + console.log(`filtersMap cleared after ${config.maxEntriesAllowed} entries`) + } filtersMap.set(filterId.toString(), internalFilter) callback(null, filterId) @@ -2819,6 +2823,10 @@ export const methods = { unsubscribe, type: Types.FilterTypes.pendingTransaction, } + if (filtersMap.size >= config.maxEntriesAllowed) { + filtersMap.clear() + console.log(`filtersMap cleared after ${config.maxEntriesAllowed} entries`) + } filtersMap.set(filterId.toString(), internalFilter) callback(null, filterId) @@ -2920,6 +2928,10 @@ export const methods = { unsubscribe, type: Types.FilterTypes.log, } + if (filtersMap.size >= config.maxEntriesAllowed) { + filtersMap.clear() + console.log(`filtersMap cleared after ${config.maxEntriesAllowed} entries`) + } filtersMap.set(filterId.toString(), internalFilter) callback(null, filterId) diff --git a/src/config.ts b/src/config.ts index a633cf3..ae3e8be 100644 --- a/src/config.ts +++ b/src/config.ts @@ -106,6 +106,7 @@ type Config = { } axiosTimeoutInMs: number enableBlacklistingIP: boolean + maxEntriesAllowed: number // maximum number of entries allowed for map to store } export type ServicePointTypes = 'aalg-warmup' @@ -249,4 +250,5 @@ export const CONFIG: Config = { }, axiosTimeoutInMs: 3000, enableBlacklistingIP: false, + maxEntriesAllowed: 10000, }