Browse Source

Merge pull request #452 from gre/fix-eth-reorgs

fix potential issue during reorgs
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
d829be0695
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/bridge/EthereumJSBridge.js
  2. 1
      src/components/modals/AccountSettingRenderBody.js

10
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') return uniqBy(all.sort((a, b) => b.date - a.date), 'id')
} }
const SAFE_REORG_THRESHOLD = 80
const fetchCurrentBlock = (perCurrencyId => currency => { const fetchCurrentBlock = (perCurrencyId => currency => {
if (perCurrencyId[currency.id]) return perCurrencyId[currency.id]() if (perCurrencyId[currency.id]) return perCurrencyId[currency.id]()
const api = apiForCurrency(currency) const api = apiForCurrency(currency)
@ -231,10 +233,18 @@ const EthereumBridge: WalletBridge<Transaction> = {
if (block.height === blockHeight) { if (block.height === blockHeight) {
complete() complete()
} else { } else {
operations = operations.filter(
o => !o.blockHeight || blockHeight - o.blockHeight < SAFE_REORG_THRESHOLD,
)
const blockHash = operations.length > 0 ? operations[0].blockHash : undefined const blockHash = operations.length > 0 ? operations[0].blockHash : undefined
const { txs } = await api.getTransactions(freshAddress, blockHash) const { txs } = await api.getTransactions(freshAddress, blockHash)
if (unsubscribed) return if (unsubscribed) return
if (txs.length === 0) { if (txs.length === 0) {
next(a => ({
...a,
blockHeight: block.height,
lastSyncDate: new Date(),
}))
complete() complete()
return return
} }

1
src/components/modals/AccountSettingRenderBody.js

@ -167,6 +167,7 @@ class HelperComp extends PureComponent<Props, State> {
</Container> </Container>
<Spoiler title="Advanced logs"> <Spoiler title="Advanced logs">
<textarea <textarea
readOnly
style={{ style={{
userSelect: 'text', userSelect: 'text',
border: '1px dashed #f9f9f9', border: '1px dashed #f9f9f9',

Loading…
Cancel
Save