Skip to content
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 possible completed job state issue #99

Merged
merged 2 commits into from
Nov 10, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions zp-relayer/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async function getJob(req: Request, res: Response) {

async function getPoolJobState(requestedJobId: string): Promise<GetJobResponse | null> {
const jobId = await pool.state.jobIdsMapping.get(requestedJobId)
const job = await poolTxQueue.getJob(jobId)
let job = await poolTxQueue.getJob(jobId)
if (!job) return null

// Default result object
Expand All @@ -146,8 +146,13 @@ async function getJob(req: Request, res: Response) {
const poolJobState = await job.getState()
if (poolJobState === 'completed') {
// Transaction was included in optimistic state, waiting to be mined
if (job.returnvalue === null) {
job = await poolTxQueue.getJob(jobId)
// Sanity check
if (!job) throw new Error('Pool job not found')
}
lok52 marked this conversation as resolved.
Show resolved Hide resolved
const sentJobId = job.returnvalue[0][1]
const sentJob = await sentTxQueue.getJob(sentJobId)
let sentJob = await sentTxQueue.getJob(sentJobId)
// Should not happen here, but need to verify to be sure
if (!sentJob) throw new Error('Sent job not found')

Expand All @@ -158,6 +163,11 @@ async function getJob(req: Request, res: Response) {
result.state = JobStatus.SENT
result.txHash = txHash || null
} else if (sentJobState === 'completed') {
if (sentJob.returnvalue === null) {
sentJob = await sentTxQueue.getJob(sentJobId)
// Sanity check
if (!sentJob) throw new Error('Sent job not found')
}
const [txState, txHash] = sentJob.returnvalue
if (txState === SentTxState.MINED) {
// Transaction mined successfully
Expand Down