Skip to content

Commit

Permalink
Trigger sync actions without QN confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
WRadoslaw committed Jun 9, 2023
1 parent 316f10b commit 47dca59
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions packages/atlas/src/providers/transactions/transactions.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,45 +203,49 @@ export const useTransaction = (): HandleTransactionFn => {
let isAfterBlockCheck = false
let isAfterMetaStatusCheck = false
// if this is a metaprotocol transaction, we will also wait until we successfully query the transaction result from QN
const queryNodeSyncPromise = new Promise<void>((resolve, reject) => {
const syncCallback = async () => {
let status: MetaprotocolTransactionResultFieldsFragment | undefined = undefined
isAfterBlockCheck = true
try {
if (result.metaprotocol && result.transactionHash) {
status = await getMetaprotocolTxStatus(result.transactionHash)
const queryNodeSyncPromiseFactory = () =>
new Promise<void>((resolve, reject) => {
const syncCallback = async () => {
let status: MetaprotocolTransactionResultFieldsFragment | undefined = undefined
isAfterBlockCheck = true
try {
if (result.metaprotocol && result.transactionHash) {
status = await getMetaprotocolTxStatus(result.transactionHash)
}
} catch (e) {
reject(e)
return
} finally {
isAfterMetaStatusCheck = true
}
} catch (e) {
reject(e)
return
} finally {
isAfterMetaStatusCheck = true
}

if (onTxSync) {
try {
await onTxSync(result, status)
} catch (error) {
SentryLogger.error('Failed transaction sync callback', 'TransactionManager', error)
if (onTxSync) {
try {
await onTxSync(result, status)
} catch (error) {
SentryLogger.error('Failed transaction sync callback', 'TransactionManager', error)
}
}
resolve()
}
resolve()
}

if (disableQNSync) {
syncCallback()
} else {
addBlockAction({ callback: syncCallback, targetBlock: result.block })
}
})
if (disableQNSync) {
syncCallback()
} else {
addBlockAction({ callback: syncCallback, targetBlock: result.block })
}
})

await withTimeout(queryNodeSyncPromise, 20_000).catch((error) => {
await withTimeout(queryNodeSyncPromiseFactory(), 15_000).catch(async (error) => {
SentryLogger.error('TEST: Processor sync promise timeout error', 'TransactionManager', {
error,
txResult: result,
isAfterBlockCheck,
isAfterMetaStatusCheck,
})

disableQNSync = true
await queryNodeSyncPromiseFactory()
})

/* === transaction was successful, do necessary cleanup === */
Expand Down

0 comments on commit 47dca59

Please sign in to comment.