Skip to content

Commit

Permalink
Fabo/handle tx timeouts correctly (#234)
Browse files Browse the repository at this point in the history
* handle tx timeouts correctly

* add broadcastResponse to timeout error tracking

* correctly handle timeout issues in schema
  • Loading branch information
faboweb authored Dec 22, 2019
1 parent a21303f commit 07217e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions lib/controller/transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ async function broadcastTransaction(networkId, senderAddress, url, signedTx) {
.then(assertOk)

// check if tx is successful when executed vs when broadcasted
pollTransactionSuccess(networkId, senderAddress, url, res.txhash)
pollTransactionSuccess(networkId, senderAddress, url, res.txhash, res)

return res.txhash
}

function createBroadcastBody(signedTx, returnType = `block`) {
function createBroadcastBody(signedTx, returnType = `sync`) {
return JSON.stringify({
tx: signedTx,
mode: returnType
Expand Down Expand Up @@ -131,6 +131,7 @@ async function pollTransactionSuccess(
senderAddress,
url,
hash,
broadcastResponse,
iteration = 0
) {
let res
Expand All @@ -153,6 +154,7 @@ async function pollTransactionSuccess(
senderAddress,
url,
hash,
broadcastResponse,
iteration + 1
)
return
Expand All @@ -161,7 +163,7 @@ async function pollTransactionSuccess(
res = {
hash,
success: false,
height: null
height: -1
}
throw new Error(
'Timed out waiting for the transaction to be included in a block'
Expand All @@ -171,13 +173,24 @@ async function pollTransactionSuccess(
assertOk(res)
} catch (error) {
console.error('TX failed:', hash, error)
const transaction = reducers.transactionReducer(res, reducers)
let transaction
if (res.tx) {
transaction = reducers.transactionReducer(res, reducers)
} else {
// on timeout we don't get a transaction back
transaction = {
hash,
success: false,
log: error.message
}
}
publishUserTransactionAdded(networkId, senderAddress, transaction)
Sentry.withScope(scope => {
scope.setExtra('api_url', url)
scope.setExtra('hash', hash)
scope.setExtra('address', senderAddress)
scope.setExtra('transaction', res)
scope.setExtra('broadcast_response', broadcastResponse)
Sentry.captureException(error)
})
}
Expand Down
2 changes: 1 addition & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const typeDefs = gql`
type Transaction {
type: String!
hash: String # may be null if the transaction is not successful
hash: String!
height: Int!
group: String!
timestamp: String!
Expand Down

0 comments on commit 07217e7

Please sign in to comment.