From 6831a98bb660e715b2ddce3c9d567c7fbff8dfac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Tue, 5 Jun 2018 16:27:22 +0200 Subject: [PATCH] fix potential issue during reorgs --- src/bridge/EthereumJSBridge.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/bridge/EthereumJSBridge.js b/src/bridge/EthereumJSBridge.js index 127e64db..b95a2469 100644 --- a/src/bridge/EthereumJSBridge.js +++ b/src/bridge/EthereumJSBridge.js @@ -93,6 +93,8 @@ function mergeOps(existing: Operation[], newFetched: Operation[]) { return uniqBy(all.sort((a, b) => b.date - a.date), 'id') } +const SAFE_REORG_THRESHOLD = 80 + const fetchCurrentBlock = (perCurrencyId => currency => { if (perCurrencyId[currency.id]) return perCurrencyId[currency.id]() const api = apiForCurrency(currency) @@ -231,6 +233,9 @@ const EthereumBridge: WalletBridge = { if (block.height === blockHeight) { complete() } else { + operations = operations.filter( + o => !o.blockHeight || blockHeight - o.blockHeight < SAFE_REORG_THRESHOLD, + ) const blockHash = operations.length > 0 ? operations[0].blockHash : undefined const { txs } = await api.getTransactions(freshAddress, blockHash) if (unsubscribed) return