Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
Co-Authored-By: Thomas Pischulski <[email protected]>
  • Loading branch information
andrevmatos and nephix committed Feb 12, 2020
1 parent c2c39ca commit a0ef008
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
52 changes: 28 additions & 24 deletions raiden-ts/src/channels/epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,33 @@ export const channelSettleableEpic = (
}),
);

function checkPendingAction(
action: ConfirmableAction,
provider: RaidenEpicDeps['provider'],
blockNumber: number,
confirmationBlocks: number,
): Observable<ConfirmableAction> {
return defer(() => provider.getTransactionReceipt(action.payload.txHash)).pipe(
map(receipt => {
if (receipt?.confirmations !== undefined && receipt.confirmations >= confirmationBlocks) {
return {
...action,
// beyond setting confirmed, also re-set blockNumber,
// which may have changed on a reorg
payload: { ...action.payload, txBlock: receipt.blockNumber!, confirmed: true },
};
} else if (action.payload.txBlock + 2 * confirmationBlocks < blockNumber) {
// if this txs didn't get confirmed for more than 2*confirmationBlocks, it was removed
return {
...action,
payload: { ...action.payload, confirmed: false },
};
} // else, it seems removed, but give it twice confirmationBlocks to be picked up again
}),
filter(isntNil),
);
}

/**
* Process new blocks and re-emit confirmed or removed actions
*
Expand All @@ -916,30 +943,7 @@ export const confirmationEpic = (
...pendingTxs
// only txs/confirmable actions which are more than confirmationBlocks in the past
.filter(a => a.payload.txBlock + confirmationBlocks <= blockNumber)
.map(a =>
defer(() => provider.getTransactionReceipt(a.payload.txHash)).pipe(
map(receipt => {
if (
receipt?.confirmations !== undefined &&
receipt.confirmations >= confirmationBlocks
) {
return {
...a,
// beyond setting confirmed, also re-set blockNumber,
// which may have changed on a reorg
payload: { ...a.payload, txBlock: receipt.blockNumber!, confirmed: true },
};
} else if (a.payload.txBlock + 2 * confirmationBlocks < blockNumber) {
// if this txs didn't get confirmed for more than 2*confirmationBlocks, it was removed
return {
...a,
payload: { ...a.payload, confirmed: false },
};
} // else, it seems removed, but give it twice confirmationBlocks to be picked up again
}),
filter(isntNil),
),
),
.map(action => checkPendingAction(action, provider, blockNumber, confirmationBlocks)),
),
),
);
2 changes: 1 addition & 1 deletion raiden-ts/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const logLevels = t.keyof({
* - pfsSafetyMargin - Safety margin to be added to fees received from PFS. Use `1.1` to add a 10% safety margin.
* - matrixExcessRooms - Keep this much rooms for a single user of interest (partner, target).
* Leave LRU beyond this threshold.
* confirmationBlocks - How much blocks to wait before considering a transaction as confirmed
* - confirmationBlocks - How many blocks to wait before considering a transaction as confirmed
* - matrixServer? - Specify a matrix server to use.
* - logger? - String specifying the console log level of redux-logger. Use '' to disable.
* Defaults to 'debug' if undefined and process.env.NODE_ENV === 'development'
Expand Down

0 comments on commit a0ef008

Please sign in to comment.