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

[draft] fix: handle transaction checks #99

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
fix: don't rethrow on tx error
rafaelcr committed Oct 18, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit fb893d76b8b190ddca69d0ff26c9f20fbe86eeb3
2 changes: 1 addition & 1 deletion src/operations.js
Original file line number Diff line number Diff line change
@@ -223,13 +223,13 @@
const response = await axios.get(url)
const blockHeight = response.data.burn_block_height
if (SERVER_GLOBALS.lastSeenBlockHeight > blockHeight) {
throw new Error(

Check warning on line 226 in src/operations.js

Codecov / codecov/patch

src/operations.js#L226

Added line #L226 was not covered by tests
`Last seen block ${SERVER_GLOBALS.lastSeenBlockHeight} is greater than returned block height ${blockHeight}`
)
}
SERVER_GLOBALS.lastSeenBlockHeight = blockHeight
} catch (error) {
throw new Error(`Error fetching block height from ${url}: ${error}`)

Check warning on line 232 in src/operations.js

Codecov / codecov/patch

src/operations.js#L232

Added line #L232 was not covered by tests
}
}

@@ -257,12 +257,12 @@
tx.blockHeight = txInfo.block_height
}
} catch (error) {
if (error.response.status === 429) {
logger.warn(`Rate limit hit for ${bskConfig.network.coreApiUrl}, resuming transaction check later`)
return results

Check warning on line 262 in src/operations.js

Codecov / codecov/patch

src/operations.js#L260-L262

Added lines #L260 - L262 were not covered by tests
}
logger.error(`Error checking transaction at ${txUrl}: ${error}`)
throw error
continue

Check warning on line 265 in src/operations.js

Codecov / codecov/patch

src/operations.js#L264-L265

Added lines #L264 - L265 were not covered by tests
}
}
if (tx.blockHeight + 7 > blockHeight) {
@@ -281,11 +281,11 @@
if (
bskConfig.network.blockstackAPIUrl === 'https://core.blockstack.org'
) {
await directlyPublishZonefile(tx.zonefile)

Check warning on line 284 in src/operations.js

Codecov / codecov/patch

src/operations.js#L284

Added line #L284 was not covered by tests
// this is horrible. I know. but the reasons have to do with load balancing
// on node.blockstack.org and Atlas peering.
await directlyPublishZonefile(tx.zonefile)
results.push({

Check warning on line 288 in src/operations.js

Codecov / codecov/patch

src/operations.js#L287-L288

Added lines #L287 - L288 were not covered by tests
txHash: tx.txHash,
status: true,
blockHeight: tx.blockHeight
@@ -299,8 +299,8 @@
})
}
} catch (err) {
logger.error(`Error publishing zonefile for tx ${tx.txHash}: ${err}`)
results.push({

Check warning on line 303 in src/operations.js

Codecov / codecov/patch

src/operations.js#L302-L303

Added lines #L302 - L303 were not covered by tests
txHash: tx.txHash,
status: false,
blockHeight: tx.blockHeight
@@ -323,21 +323,21 @@
): Promise<boolean> {
// speak directly to node.blockstack

const b64Zonefile = Buffer.from(zonefile).toString('base64')

Check warning on line 326 in src/operations.js

Codecov / codecov/patch

src/operations.js#L326

Added line #L326 was not covered by tests

const postData =
'<?xml version=\'1.0\'?>' +

Check warning on line 329 in src/operations.js

Codecov / codecov/patch

src/operations.js#L329

Added line #L329 was not covered by tests
'<methodCall><methodName>put_zonefiles</methodName>' +
`<params><param><array><data><value>
<string>${b64Zonefile}</string></value>
</data></array></param></params>` +
'</methodCall>'
const resp = await fetch('https://node.blockstack.org:6263/RPC2', {

Check warning on line 335 in src/operations.js

Codecov / codecov/patch

src/operations.js#L335

Added line #L335 was not covered by tests
method: 'POST',
body: postData
})

const respText = await resp.text()

Check warning on line 340 in src/operations.js

Codecov / codecov/patch

src/operations.js#L340

Added line #L340 was not covered by tests

if (!(resp.status >= 200 && resp.status <= 299)) {
logger.error(
@@ -351,33 +351,33 @@
)
}

const start = respText.indexOf('<string>') + '<string>'.length
const stop = respText.indexOf('</string>')
const dataResp = respText.slice(start, stop)

Check warning on line 356 in src/operations.js

Codecov / codecov/patch

src/operations.js#L354-L356

Added lines #L354 - L356 were not covered by tests
let jsonResp
try {
jsonResp = JSON.parse(dataResp)

Check warning on line 359 in src/operations.js

Codecov / codecov/patch

src/operations.js#L359

Added line #L359 was not covered by tests
} catch (err) {
logger.error(
`Failed to parse JSON response from node.blockstack: ${respText}`
)
throw err

Check warning on line 364 in src/operations.js

Codecov / codecov/patch

src/operations.js#L364

Added line #L364 was not covered by tests
}

if ('error' in jsonResp) {
logger.error(`Error in publishing zonefile: ${JSON.stringify(jsonResp)}`)
throw new Error(jsonResp.error)

Check warning on line 369 in src/operations.js

Codecov / codecov/patch

src/operations.js#L367-L369

Added lines #L367 - L369 were not covered by tests
}

if (!jsonResp.saved || jsonResp.saved.length < 1) {
throw new Error('Invalid "saved" response from node.blockstack')

Check warning on line 373 in src/operations.js

Codecov / codecov/patch

src/operations.js#L373

Added line #L373 was not covered by tests
}

if (jsonResp.saved[0] === 1) {
return true

Check warning on line 377 in src/operations.js

Codecov / codecov/patch

src/operations.js#L377

Added line #L377 was not covered by tests
} else if (jsonResp.saved[0] === 0) {
throw new Error('Zonefile not saved')

Check warning on line 379 in src/operations.js

Codecov / codecov/patch

src/operations.js#L379

Added line #L379 was not covered by tests
}

throw new Error('Invalid "saved" response from node.blockstack')

Check warning on line 382 in src/operations.js

Codecov / codecov/patch

src/operations.js#L382

Added line #L382 was not covered by tests
}

Unchanged files with check annotations Beta

})
.then(() => app)
.catch(error => {
logger.error(`Unable to start server: ${error}`)

Check warning on line 368 in src/http.js

Codecov / codecov/patch

src/http.js#L368

Added line #L368 was not covered by tests
})
}
console.log('Subdomain registrar started on', config.port)
})
}).catch(error => {
winston.error(`Unable to initialize subdomain registrar: ${error}`)

Check warning on line 51 in src/index.js

Codecov / codecov/patch

src/index.js#L51

Added line #L51 was not covered by tests
})
|| err.response.status !== 200) {
return false
}
logger.error(`Error checking registered subdomain from ${nameInfoUrl}: ${err}`)
throw err

Check warning on line 18 in src/lookups.js

Codecov / codecov/patch

src/lookups.js#L17-L18

Added lines #L17 - L18 were not covered by tests
}
}