Compare commits

...
8 Commits
Author SHA1 Message Date
Chris Troutner e881b68ca5 Merge pull request #65 from Permissionless-Software-Foundation/ct-unstable
ix(electrumx): Fixed connect/disconnect bug that was preventing tests
2020-11-21 11:39:05 -08:00
Chris Troutner f54c69a664 Fixing test typo 2020-11-21 11:35:01 -08:00
Chris Troutner 319281c096 fix(electrumx): Fixed connect/disconnect bug that was preventing tests 2020-11-21 11:29:18 -08:00
Chris Troutner 7dee8c0604 Merge branch 'master' into ct-unstable 2020-11-21 11:15:41 -08:00
Chris Troutner efbcbc5deb linting 2020-11-21 11:15:33 -08:00
Chris Troutner c742518612 Merge pull request #64 from Permissionless-Software-Foundation/ct-unstable
fix(electrumx): Automatically reconnecting when Electrumx disconnects
2020-11-20 20:53:40 -08:00
Chris Troutner 6a0ed46413 fix(electrumx): Automatically reconnecting when Electrumx disconnects 2020-11-20 20:52:22 -08:00
Chris Troutner 5ea71bc89b Updating default Docker run script 2020-11-20 08:36:34 -08:00
5 changed files with 33 additions and 3 deletions
+5 -1
View File
@@ -17,7 +17,11 @@ export BLOCKBOOK_URL=https://172.17.0.1:9131/
# Allow node.js to make network calls to https using self-signed certificate.
export NODE_TLS_REJECT_UNAUTHORIZED=0
# Redis DB
# Mainnet Fulcrum / ElectrumX
export FULCRUM_URL=172.17.0.1
export FULCRUM_PORT=50002
# Redis DB - Used for rate limiting
export REDIS_PORT=6379
export REDIS_HOST=172.17.0.1
+4
View File
@@ -14,6 +14,10 @@ export BLOCKBOOK_URL=https://172.17.0.1:19131/
# Allow node.js to make network calls to https using self-signed certificate.
export NODE_TLS_REJECT_UNAUTHORIZED=0
# Mainnet Fulcrum / ElectrumX
export FULCRUM_URL=172.17.0.1
export FULCRUM_PORT=50002
# Redis DB
export REDIS_PORT=6380
export REDIS_HOST=172.17.0.1
+18
View File
@@ -79,6 +79,21 @@ class Electrum {
// Set the connection flag.
_this.isReady = true
// Periodically check the connection. If it's not connected, attempt to
// reconnect.
_this.reconnectIntervalHandle = setInterval(async function () {
const status = _this.electrumx.connection.status
// console.log(`Electrumx status: ${status}`)
// 1 = connected. If we're not connected, attemp to reconnect.
if (status !== 1) {
wlogger.info(`Electrumx not connectes. Status: ${status}`)
wlogger.info('Attempting to reconnect...')
await _this.electrumx.connect()
wlogger.info('...reconnected.')
}
}, 30000)
console.log('...Successfully connected to ElectrumX server.')
// console.log(`_this.isReady: ${_this.isReady}`)
@@ -96,6 +111,9 @@ class Electrum {
// Return immediately if the isReady flag is false.
if (!_this.isReady) return true
// Disable the reconnect timer.
clearInterval(_this.reconnectIntervalHandle)
// Disconnect from the server.
await _this.electrumx.disconnect()
+1 -1
View File
@@ -42,7 +42,7 @@ function expectRouteError (res, result, expectedError, code = 400) {
assert.equal(result.success, false)
}
describe('#ElectrumX Router', () => {
describe('#Electrumx', () => {
let req, res
let sandbox
const electrumxRoute = new ElecrumxRoute()
+5 -1
View File
@@ -821,6 +821,7 @@ describe('#BlockchainRouter', () => {
])
})
})
describe('getRawMempool()', () => {
it('should throw 503 when network issues', async () => {
// Save the existing RPC URL.
@@ -842,6 +843,7 @@ describe('#BlockchainRouter', () => {
'Error message expected'
)
})
it('returns proper error when downstream service stalls', async () => {
// Mock the timeout error.
sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNABORTED' })
@@ -856,6 +858,7 @@ describe('#BlockchainRouter', () => {
'Error message expected'
)
})
it('returns proper error when downstream service is down', async () => {
// Mock the timeout error.
sandbox.stub(uut.axios, 'request').throws({ code: 'ECONNREFUSED' })
@@ -871,7 +874,7 @@ describe('#BlockchainRouter', () => {
)
})
it('should GET /getMempoolInfo', async () => {
it('should GET /getRawMempool', async () => {
// Mock the RPC call for unit tests.
if (process.env.TEST === 'unit') {
sandbox
@@ -886,6 +889,7 @@ describe('#BlockchainRouter', () => {
// Not sure what other assertions should be made here.
})
})
describe('getMempoolEntrySingle()', () => {
it('should throw 400 if txid is empty', async () => {
const result = await uut.getMempoolEntrySingle(req, res)