mirror of
https://github.com/mempool/mempool.git
synced 2025-02-24 06:47:52 +01:00
Merge pull request #4254 from mempool/mononaut/failover-timeout-config
Add REQUEST_TIMEOUT and FALLBACK_TIMEOUT esplora config options
This commit is contained in:
commit
1e3babe714
7 changed files with 20 additions and 4 deletions
|
@ -51,6 +51,8 @@
|
||||||
"REST_API_URL": "http://127.0.0.1:3000",
|
"REST_API_URL": "http://127.0.0.1:3000",
|
||||||
"UNIX_SOCKET_PATH": "/tmp/esplora-bitcoin-mainnet",
|
"UNIX_SOCKET_PATH": "/tmp/esplora-bitcoin-mainnet",
|
||||||
"RETRY_UNIX_SOCKET_AFTER": 30000,
|
"RETRY_UNIX_SOCKET_AFTER": 30000,
|
||||||
|
"REQUEST_TIMEOUT": 10000,
|
||||||
|
"FALLBACK_TIMEOUT": 5000,
|
||||||
"FALLBACK": []
|
"FALLBACK": []
|
||||||
},
|
},
|
||||||
"SECOND_CORE_RPC": {
|
"SECOND_CORE_RPC": {
|
||||||
|
|
|
@ -52,6 +52,8 @@
|
||||||
"REST_API_URL": "__ESPLORA_REST_API_URL__",
|
"REST_API_URL": "__ESPLORA_REST_API_URL__",
|
||||||
"UNIX_SOCKET_PATH": "__ESPLORA_UNIX_SOCKET_PATH__",
|
"UNIX_SOCKET_PATH": "__ESPLORA_UNIX_SOCKET_PATH__",
|
||||||
"RETRY_UNIX_SOCKET_AFTER": 888,
|
"RETRY_UNIX_SOCKET_AFTER": 888,
|
||||||
|
"REQUEST_TIMEOUT": 10000,
|
||||||
|
"FALLBACK_TIMEOUT": 5000,
|
||||||
"FALLBACK": []
|
"FALLBACK": []
|
||||||
},
|
},
|
||||||
"SECOND_CORE_RPC": {
|
"SECOND_CORE_RPC": {
|
||||||
|
|
|
@ -56,6 +56,8 @@ describe('Mempool Backend Config', () => {
|
||||||
REST_API_URL: 'http://127.0.0.1:3000',
|
REST_API_URL: 'http://127.0.0.1:3000',
|
||||||
UNIX_SOCKET_PATH: null,
|
UNIX_SOCKET_PATH: null,
|
||||||
RETRY_UNIX_SOCKET_AFTER: 30000,
|
RETRY_UNIX_SOCKET_AFTER: 30000,
|
||||||
|
REQUEST_TIMEOUT: 10000,
|
||||||
|
FALLBACK_TIMEOUT: 5000,
|
||||||
FALLBACK: [],
|
FALLBACK: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -75,9 +75,9 @@ class FailoverRouter {
|
||||||
|
|
||||||
const results = await Promise.allSettled(this.hosts.map(async (host) => {
|
const results = await Promise.allSettled(this.hosts.map(async (host) => {
|
||||||
if (host.socket) {
|
if (host.socket) {
|
||||||
return this.pollConnection.get<number>('/blocks/tip/height', { socketPath: host.host, timeout: 5000 });
|
return this.pollConnection.get<number>('/blocks/tip/height', { socketPath: host.host, timeout: config.ESPLORA.FALLBACK_TIMEOUT });
|
||||||
} else {
|
} else {
|
||||||
return this.pollConnection.get<number>(host.host + '/blocks/tip/height', { timeout: 5000 });
|
return this.pollConnection.get<number>(host.host + '/blocks/tip/height', { timeout: config.ESPLORA.FALLBACK_TIMEOUT });
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
const maxHeight = results.reduce((max, result) => Math.max(max, result.status === 'fulfilled' ? result.value?.data || 0 : 0), 0);
|
const maxHeight = results.reduce((max, result) => Math.max(max, result.status === 'fulfilled' ? result.value?.data || 0 : 0), 0);
|
||||||
|
@ -168,10 +168,10 @@ class FailoverRouter {
|
||||||
let axiosConfig;
|
let axiosConfig;
|
||||||
let url;
|
let url;
|
||||||
if (host.socket) {
|
if (host.socket) {
|
||||||
axiosConfig = { socketPath: host.host, timeout: 10000, responseType };
|
axiosConfig = { socketPath: host.host, timeout: config.ESPLORA.REQUEST_TIMEOUT, responseType };
|
||||||
url = path;
|
url = path;
|
||||||
} else {
|
} else {
|
||||||
axiosConfig = { timeout: 10000, responseType };
|
axiosConfig = { timeout: config.ESPLORA.REQUEST_TIMEOUT, responseType };
|
||||||
url = host.host + path;
|
url = host.host + path;
|
||||||
}
|
}
|
||||||
return (method === 'post'
|
return (method === 'post'
|
||||||
|
|
|
@ -44,6 +44,8 @@ interface IConfig {
|
||||||
REST_API_URL: string;
|
REST_API_URL: string;
|
||||||
UNIX_SOCKET_PATH: string | void | null;
|
UNIX_SOCKET_PATH: string | void | null;
|
||||||
RETRY_UNIX_SOCKET_AFTER: number;
|
RETRY_UNIX_SOCKET_AFTER: number;
|
||||||
|
REQUEST_TIMEOUT: number;
|
||||||
|
FALLBACK_TIMEOUT: number;
|
||||||
FALLBACK: string[];
|
FALLBACK: string[];
|
||||||
};
|
};
|
||||||
LIGHTNING: {
|
LIGHTNING: {
|
||||||
|
@ -190,6 +192,8 @@ const defaults: IConfig = {
|
||||||
'REST_API_URL': 'http://127.0.0.1:3000',
|
'REST_API_URL': 'http://127.0.0.1:3000',
|
||||||
'UNIX_SOCKET_PATH': null,
|
'UNIX_SOCKET_PATH': null,
|
||||||
'RETRY_UNIX_SOCKET_AFTER': 30000,
|
'RETRY_UNIX_SOCKET_AFTER': 30000,
|
||||||
|
'REQUEST_TIMEOUT': 10000,
|
||||||
|
'FALLBACK_TIMEOUT': 5000,
|
||||||
'FALLBACK': [],
|
'FALLBACK': [],
|
||||||
},
|
},
|
||||||
'ELECTRUM': {
|
'ELECTRUM': {
|
||||||
|
|
|
@ -52,6 +52,8 @@
|
||||||
"REST_API_URL": "__ESPLORA_REST_API_URL__",
|
"REST_API_URL": "__ESPLORA_REST_API_URL__",
|
||||||
"UNIX_SOCKET_PATH": "__ESPLORA_UNIX_SOCKET_PATH__",
|
"UNIX_SOCKET_PATH": "__ESPLORA_UNIX_SOCKET_PATH__",
|
||||||
"RETRY_UNIX_SOCKET_AFTER": __ESPLORA_RETRY_UNIX_SOCKET_AFTER__,
|
"RETRY_UNIX_SOCKET_AFTER": __ESPLORA_RETRY_UNIX_SOCKET_AFTER__,
|
||||||
|
"REQUEST_TIMEOUT": __ESPLORA_REQUEST_TIMEOUT__,
|
||||||
|
"FALLBACK_TIMEOUT": __ESPLORA_FALLBACK_TIMEOUT__,
|
||||||
"FALLBACK": __ESPLORA_FALLBACK__
|
"FALLBACK": __ESPLORA_FALLBACK__
|
||||||
},
|
},
|
||||||
"SECOND_CORE_RPC": {
|
"SECOND_CORE_RPC": {
|
||||||
|
|
|
@ -53,6 +53,8 @@ __ELECTRUM_TLS_ENABLED__=${ELECTRUM_TLS_ENABLED:=false}
|
||||||
__ESPLORA_REST_API_URL__=${ESPLORA_REST_API_URL:=http://127.0.0.1:3000}
|
__ESPLORA_REST_API_URL__=${ESPLORA_REST_API_URL:=http://127.0.0.1:3000}
|
||||||
__ESPLORA_UNIX_SOCKET_PATH__=${ESPLORA_UNIX_SOCKET_PATH:="null"}
|
__ESPLORA_UNIX_SOCKET_PATH__=${ESPLORA_UNIX_SOCKET_PATH:="null"}
|
||||||
__ESPLORA_RETRY_UNIX_SOCKET_AFTER__=${ESPLORA_RETRY_UNIX_SOCKET_AFTER:=30000}
|
__ESPLORA_RETRY_UNIX_SOCKET_AFTER__=${ESPLORA_RETRY_UNIX_SOCKET_AFTER:=30000}
|
||||||
|
__ESPLORA_REQUEST_TIMEOUT__=${ESPLORA_REQUEST_TIMEOUT:=5000}
|
||||||
|
__ESPLORA_FALLBACK_TIMEOUT__=${ESPLORA_FALLBACK_TIMEOUT:=5000}
|
||||||
__ESPLORA_FALLBACK__=${ESPLORA_FALLBACK:=[]}
|
__ESPLORA_FALLBACK__=${ESPLORA_FALLBACK:=[]}
|
||||||
|
|
||||||
# SECOND_CORE_RPC
|
# SECOND_CORE_RPC
|
||||||
|
@ -194,6 +196,8 @@ sed -i "s!__ELECTRUM_TLS_ENABLED__!${__ELECTRUM_TLS_ENABLED__}!g" mempool-config
|
||||||
sed -i "s!__ESPLORA_REST_API_URL__!${__ESPLORA_REST_API_URL__}!g" mempool-config.json
|
sed -i "s!__ESPLORA_REST_API_URL__!${__ESPLORA_REST_API_URL__}!g" mempool-config.json
|
||||||
sed -i "s!__ESPLORA_UNIX_SOCKET_PATH__!${__ESPLORA_UNIX_SOCKET_PATH__}!g" mempool-config.json
|
sed -i "s!__ESPLORA_UNIX_SOCKET_PATH__!${__ESPLORA_UNIX_SOCKET_PATH__}!g" mempool-config.json
|
||||||
sed -i "s!__ESPLORA_RETRY_UNIX_SOCKET_AFTER__!${__ESPLORA_RETRY_UNIX_SOCKET_AFTER__}!g" mempool-config.json
|
sed -i "s!__ESPLORA_RETRY_UNIX_SOCKET_AFTER__!${__ESPLORA_RETRY_UNIX_SOCKET_AFTER__}!g" mempool-config.json
|
||||||
|
sed -i "s!__ESPLORA_REQUEST_TIMEOUT__!${__ESPLORA_REQUEST_TIMEOUT__}!g" mempool-config.json
|
||||||
|
sed -i "s!__ESPLORA_FALLBACK_TIMEOUT__!${__ESPLORA_FALLBACK_TIMEOUT__}!g" mempool-config.json
|
||||||
sed -i "s!__ESPLORA_FALLBACK__!${__ESPLORA_FALLBACK__}!g" mempool-config.json
|
sed -i "s!__ESPLORA_FALLBACK__!${__ESPLORA_FALLBACK__}!g" mempool-config.json
|
||||||
|
|
||||||
sed -i "s!__SECOND_CORE_RPC_HOST__!${__SECOND_CORE_RPC_HOST__}!g" mempool-config.json
|
sed -i "s!__SECOND_CORE_RPC_HOST__!${__SECOND_CORE_RPC_HOST__}!g" mempool-config.json
|
||||||
|
|
Loading…
Add table
Reference in a new issue