From ced68e4e022eb1020a4d15ab9a64552b4f92744a Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 13 Jul 2018 19:44:21 +0200 Subject: Expose Blockstreams blockRetention config as an OrderWatcher config --- packages/order-watcher/src/order_watcher/event_watcher.ts | 6 ++++++ packages/order-watcher/src/order_watcher/order_watcher.ts | 4 +++- packages/order-watcher/src/types.ts | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/order-watcher/src/order_watcher/event_watcher.ts b/packages/order-watcher/src/order_watcher/event_watcher.ts index 08ecf81cb..38ba8101e 100644 --- a/packages/order-watcher/src/order_watcher/event_watcher.ts +++ b/packages/order-watcher/src/order_watcher/event_watcher.ts @@ -27,13 +27,16 @@ export class EventWatcher { private _pollingIntervalMs: number; private _stateLayer: BlockParamLiteral; private _isVerbose: boolean; + private _blockRetention: number; constructor( web3Wrapper: Web3Wrapper, pollingIntervalIfExistsMs: undefined | number, stateLayer: BlockParamLiteral = BlockParamLiteral.Latest, + blockRetention: number, isVerbose: boolean, ) { this._isVerbose = isVerbose; + this._blockRetention = blockRetention; this._web3Wrapper = web3Wrapper; this._stateLayer = stateLayer; this._pollingIntervalMs = _.isUndefined(pollingIntervalIfExistsMs) @@ -69,6 +72,9 @@ export class EventWatcher { this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper, this._stateLayer), this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper, eventFilter), this._onBlockAndLogStreamerError.bind(this), + { + blockRetention: this._blockRetention, + }, ); const catchAllLogFilter = {}; this._blockAndLogStreamerIfExists.addLogFilter(catchAllLogFilter); diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index b09ba8d9d..2fe012593 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -61,6 +61,7 @@ interface OrderStateByOrderHash { // tslint:disable-next-line:custom-no-magic-numbers const DEFAULT_CLEANUP_JOB_INTERVAL_MS = 1000 * 60 * 60; // 1h +const DEFAULT_BLOCK_RETENTION = 100; /** * This class includes all the functionality related to watching a set of orders @@ -94,7 +95,8 @@ export class OrderWatcher { const stateLayer = _.isUndefined(config) || _.isUndefined(config.stateLayer) ? BlockParamLiteral.Latest : config.stateLayer; const isVerbose = !_.isUndefined(config) && !_.isUndefined(config.isVerbose) ? config.isVerbose : false; - this._eventWatcher = new EventWatcher(this._web3Wrapper, pollingIntervalIfExistsMs, stateLayer, isVerbose); + const blockRetention = !_.isUndefined(config) && !_.isUndefined(config.blockRetention) ? config.blockRetention : DEFAULT_BLOCK_RETENTION; + this._eventWatcher = new EventWatcher(this._web3Wrapper, pollingIntervalIfExistsMs, stateLayer, blockRetention, isVerbose); this._balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore( this._contractWrappers.token, stateLayer, diff --git a/packages/order-watcher/src/types.ts b/packages/order-watcher/src/types.ts index 63e4e7848..e9b8626b6 100644 --- a/packages/order-watcher/src/types.ts +++ b/packages/order-watcher/src/types.ts @@ -14,6 +14,7 @@ export type EventWatcherCallback = (err: null | Error, log?: LogEntryEvent) => v * of an orders expiration. Default=0. * cleanupJobIntervalMs: How often to run a cleanup job which revalidates all the orders. Default=1hr. * stateLayer: Optional blockchain state layer OrderWatcher will monitor for new events. Default=latest. + * blockRetention: The numbers of blocks to retain in-memory, in order to handle block-reorgs. Default=100. */ export interface OrderWatcherConfig { stateLayer: BlockParamLiteral; @@ -22,6 +23,7 @@ export interface OrderWatcherConfig { expirationMarginMs?: number; cleanupJobIntervalMs?: number; isVerbose?: boolean; + blockRetention?: number; } export type OnOrderStateChangeCallback = (err: Error | null, orderState?: OrderState) => void; -- cgit v1.2.3