-
Notifications
You must be signed in to change notification settings - Fork 14
fix: remove db access per validation for fee data #328
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
Changes from 6 commits
98877d0
be59d1e
5e248f7
f770602
9aa3c13
f85a9b1
4ffb62b
37b9a43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ const ports = [443, 80, 6005, 6006, 51233, 51234] | |
| const protocols = ['wss://', 'ws://'] | ||
| const connections: Map<string, WebSocket> = new Map() | ||
| const networkFee: Map<string, FeeVote> = new Map() | ||
| const validationNetworkDb: Map<string, string> = new Map() | ||
| const CM_INTERVAL = 60 * 60 * 1000 | ||
| const WS_TIMEOUT = 10000 | ||
| const REPORTING_INTERVAL = 15 * 60 * 1000 | ||
|
|
@@ -60,11 +61,11 @@ async function setHandlers( | |
| isInitialNode = false, | ||
| retryCount = 0, | ||
| ): Promise<void> { | ||
| log.info( | ||
| `Initiated Websocket connection for: ${ws_url} on ${ | ||
| networks ?? 'unknown network' | ||
| }`, | ||
| ) | ||
| // log.info( | ||
| // `Initiated Websocket connection for: ${ws_url} on ${ | ||
| // networks ?? 'unknown network' | ||
| // }`, | ||
| // ) | ||
|
|
||
| const ledger_hashes: string[] = [] | ||
| return new Promise(function setHandlersPromise(resolve, _reject) { | ||
|
|
@@ -119,24 +120,25 @@ async function setHandlers( | |
| networks, | ||
| networkFee, | ||
| ws, | ||
| validationNetworkDb, | ||
| ) | ||
| } | ||
| }) | ||
| ws.on('close', async (code, reason) => { | ||
| log.error( | ||
| `Websocket closed for ${ws.url} on ${ | ||
| networks ?? 'unknown network' | ||
| } with code ${code} and reason ${reason.toString('utf-8')}.`, | ||
| ) | ||
| ws.on('close', async (code) => { | ||
| // log.error( | ||
| // `Websocket closed for ${ws.url} on ${ | ||
| // networks ?? 'unknown network' | ||
| // } with code ${code} and reason ${reason.toString('utf-8')}.`, | ||
| // ) | ||
|
|
||
| const delay = BASE_RETRY_DELAY * 2 ** retryCount | ||
|
|
||
| if (CLOSING_CODES.includes(code) && delay <= MAX_RETRY_DELAY) { | ||
| log.info( | ||
| `Reconnecting to ${ws.url} on ${ | ||
| networks ?? 'unknown network' | ||
| } after ${delay}ms...`, | ||
| ) | ||
| // log.info( | ||
| // `Reconnecting to ${ws.url} on ${ | ||
| // networks ?? 'unknown network' | ||
| // } after ${delay}ms...`, | ||
| // ) | ||
| // Clean up the old Websocket connection | ||
| connections.delete(ws.url) | ||
| ws.terminate() | ||
|
|
@@ -166,12 +168,12 @@ async function setHandlers( | |
| ws.terminate() | ||
| resolve() | ||
| }) | ||
| ws.on('error', (err) => { | ||
| log.error( | ||
| `Websocket connection error for ${ws.url} on ${ | ||
| networks ?? 'unknown network' | ||
| } - ${err.message}`, | ||
| ) | ||
| ws.on('error', () => { | ||
| // log.error( | ||
| // `Websocket connection error for ${ws.url} on ${ | ||
| // networks ?? 'unknown network' | ||
| // } - ${err.message}`, | ||
| // ) | ||
Patel-Raj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (connections.get(ws.url)?.url === ws.url) { | ||
| connections.delete(ws.url) | ||
|
|
@@ -230,13 +232,23 @@ async function findConnection(node: WsNode): Promise<void> { | |
| return Promise.resolve() | ||
| } | ||
|
|
||
| async function getValidationNetworkDb(): Promise<void> { | ||
| const validatorNetwork: Array<{ signing_key: string; networks: string }> = | ||
| await query('validators').select('signing_key', 'networks') | ||
| for (const entry of validatorNetwork) { | ||
| validationNetworkDb.set(entry.signing_key, entry.networks) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Creates connections to nodes found in the database. | ||
| * | ||
| * @returns A promise that resolves to void once all possible connections have been created. | ||
| */ | ||
| async function createConnections(): Promise<void> { | ||
| log.info('Finding Connections...') | ||
| validationNetworkDb.clear() | ||
| await getValidationNetworkDb() | ||
|
Comment on lines
+244
to
+245
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The New entries into the This is a hypothetical scenario: When we start the VHS connection service, we are not aware of many validators. However, we populate the In the meantime, we can receive validations from new validators which are not present in our We can remedy this situation by falling-back to do a fresh db access, if we don't have any entry in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a fallback to database if we don't find in cache.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| const tenMinutesAgo = new Date() | ||
| tenMinutesAgo.setMinutes(tenMinutesAgo.getMinutes() - 10) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,18 +9,13 @@ import { | |
| import { AMENDMENTS_ID } from 'xrpl/dist/npm/models/ledger' | ||
| import { LedgerResponseExpanded } from 'xrpl/dist/npm/models/methods/ledger' | ||
|
|
||
| import { | ||
| query, | ||
| saveAmendmentStatus, | ||
| saveAmendmentsStatus, | ||
| } from '../shared/database' | ||
| import { saveAmendmentStatus, saveAmendmentsStatus } from '../shared/database' | ||
| import { | ||
| NETWORKS_HOSTS, | ||
| deleteAmendmentStatus, | ||
| } from '../shared/database/amendments' | ||
| import { | ||
| AmendmentStatus, | ||
| DatabaseValidator, | ||
| FeeVote, | ||
| StreamLedger, | ||
| StreamManifest, | ||
|
|
@@ -106,6 +101,7 @@ function isFlagLedgerPlusOne(ledger_index: number): boolean { | |
| * @param networks - The networks of subscribed node. | ||
| * @param network_fee - The map of default fee for the network to be used in case the validator does not vote for a new fee. | ||
| * @param ws - The WebSocket message received from. | ||
| * @param validationNetworkDb -- The validation network map to fetch fee data. | ||
Patel-Raj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @returns Void. | ||
| */ | ||
| // eslint-disable-next-line max-params -- Disabled for this function. | ||
|
|
@@ -115,22 +111,17 @@ export async function handleWsMessageSubscribeTypes( | |
| networks: string | undefined, | ||
| network_fee: Map<string, FeeVote>, | ||
| ws: WebSocket, | ||
| validationNetworkDb: Map<string, string>, | ||
| ): Promise<void> { | ||
| if (data.type === 'validationReceived') { | ||
| const validationData = data as ValidationRaw | ||
| if (ledger_hashes.includes(validationData.ledger_hash)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we rely on the networks field passed to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are picking up the ws_urls to open up websocket connection from crawls table. And this piece of code makes sure that at least some network is set. So, I wanted to know if we can remove the networks check in the first place and assume that it would always be defined. Also, we can pick only those ws_urls where networks is not null from the existing database:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, this is the current fall-back mechanism of the code. This is the
Are you suggesting that we use the crawls table to fetch this network information? We can use it, however it only changes the database read access from
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It is possible for one rippled validator to be configured for multiple networks, for instance In such cases, I suspect one websocket connection could serve ledgers, validations pertaining to multiple networks. That is the only reason why we cannot use the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The networks value is not undefined. We are using the I have identified one scenario where this code does not work correctly, however I don't know of many such cases. I believe its a worthy optimization to get the VHS back on track.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The validation gets its network from the function input parameter. It does not implicitly have network field. It would either remain undefined or get it from the function parameter.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the original interface:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Patel-Raj we cannot use the |
||
| validationData.networks = networks | ||
| } | ||
|
|
||
| // Get network of the validation if ledger_hash is not in cache. | ||
| const validationNetworkDb: DatabaseValidator | undefined = await query( | ||
| 'validators', | ||
| ) | ||
| .select('*') | ||
| .where('signing_key', validationData.validation_public_key) | ||
| .first() | ||
| const validationNetwork = | ||
| validationNetworkDb?.networks ?? validationData.networks | ||
| validationNetworkDb.get(validationData.validation_public_key) ?? | ||
| validationData.networks | ||
|
|
||
| // Get the fee for the network to be used in case the validator does not vote for a new fee. | ||
| if (validationNetwork) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.