-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fix and optimise fetching the recovery state #2807
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,17 +7,10 @@ import type { JsonRpcProvider } from '@ethersproject/providers' | |
import type { TransactionReceipt } from '@ethersproject/abstract-provider' | ||
|
||
import type { RecoveryQueueItem, RecoveryState } from '@/store/recoverySlice' | ||
import { hexZeroPad } from 'ethers/lib/utils' | ||
|
||
const MAX_PAGE_SIZE = 100 | ||
|
||
export const _getQueuedTransactionsAdded = ( | ||
transactionsAdded: Array<TransactionAddedEvent>, | ||
txNonce: BigNumber, | ||
): Array<TransactionAddedEvent> => { | ||
// Only queued transactions with queueNonce >= current txNonce | ||
return transactionsAdded.filter(({ args }) => args.queueNonce.gte(txNonce)) | ||
} | ||
|
||
export const _getRecoveryQueueItem = async ( | ||
transactionAdded: TransactionAddedEvent, | ||
txCooldown: BigNumber, | ||
|
@@ -48,7 +41,7 @@ export const _getSafeCreationReceipt = memoize( | |
safeAddress: string | ||
provider: JsonRpcProvider | ||
}): Promise<TransactionReceipt> => { | ||
const url = `${transactionService}/v1/${safeAddress}/creation/` | ||
const url = `${transactionService}api/v1/safes/${safeAddress}/creation/` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems as though there can be a forward slash on some networks. Perhaps we should check if one is required and/or fix the configs. |
||
|
||
const { transactionHash } = await fetch(url).then((res) => { | ||
if (res.ok && res.status === 200) { | ||
|
@@ -63,6 +56,28 @@ export const _getSafeCreationReceipt = memoize( | |
({ transactionService, safeAddress }) => transactionService + safeAddress, | ||
) | ||
|
||
const queryAddedTransactions = async ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a unit test for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added more tests for it's outside function effectively also testing this logic. |
||
delayModifier: Delay, | ||
queueNonce: BigNumber, | ||
txNonce: BigNumber, | ||
startBlockNumber: number, | ||
) => { | ||
if (queueNonce.eq(txNonce)) { | ||
// There are no queued txs | ||
return [] | ||
} | ||
|
||
const transactionAddedFilter = delayModifier.filters.TransactionAdded() | ||
|
||
const diff = queueNonce.sub(txNonce).toNumber() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can move this into the |
||
if (transactionAddedFilter.topics) { | ||
const queueNonceFilter = Array.from({ length: diff }, (_, idx) => hexZeroPad(txNonce.add(idx).toHexString(), 32)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a comment explaining this? |
||
transactionAddedFilter.topics[1] = queueNonceFilter | ||
} | ||
|
||
return await delayModifier.queryFilter(transactionAddedFilter, startBlockNumber, 'latest') | ||
} | ||
|
||
export const getRecoveryState = async ({ | ||
delayModifier, | ||
...rest | ||
|
@@ -72,21 +87,17 @@ export const getRecoveryState = async ({ | |
safeAddress: string | ||
provider: JsonRpcProvider | ||
}): Promise<RecoveryState[number]> => { | ||
const { blockHash } = await _getSafeCreationReceipt(rest) | ||
|
||
const transactionAddedFilter = delayModifier.filters.TransactionAdded() | ||
const { blockNumber } = await _getSafeCreationReceipt(rest) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this into |
||
|
||
const [[modules], txExpiration, txCooldown, txNonce, queueNonce, transactionsAdded] = await Promise.all([ | ||
const [[modules], txExpiration, txCooldown, txNonce, queueNonce] = await Promise.all([ | ||
delayModifier.getModulesPaginated(SENTINEL_ADDRESS, MAX_PAGE_SIZE), | ||
delayModifier.txExpiration(), | ||
delayModifier.txCooldown(), | ||
delayModifier.txNonce(), | ||
delayModifier.queueNonce(), | ||
// TODO: Improve log retrieval | ||
delayModifier.queryFilter(transactionAddedFilter, blockHash), | ||
]) | ||
|
||
const queuedTransactionsAdded = _getQueuedTransactionsAdded(transactionsAdded, txNonce) | ||
const queuedTransactionsAdded = await queryAddedTransactions(delayModifier, queueNonce, txNonce, blockNumber) | ||
|
||
const queue = await Promise.all( | ||
queuedTransactionsAdded.map((transactionAdded) => | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the unit test for this.