-
Notifications
You must be signed in to change notification settings - Fork 14
Store validated ledgers inside a persistent DB #370
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
base: main
Are you sure you want to change the base?
Changes from all commits
e9f7d0e
b0ab1e0
e9cfe98
b453d0d
3206c8a
51411e7
ecf914b
7c5c96f
98b148b
ec29db5
01b381e
986698f
197929b
9bf4e1c
4078df4
84740c0
a122679
94abe5f
a24ac13
8208f4e
30e3c9d
98cc0aa
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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { Chain } from '../shared/types' | ||
| import { getLists, overlaps } from '../shared/utils' | ||
| import logger from '../shared/utils/logger' | ||
|
|
||
| const log = logger({ name: 'connection-manager-utils' }) | ||
|
|
||
| /** | ||
| * Finds network name from chain id. | ||
| * | ||
| * @param chain - A chain object. | ||
| * @returns String. | ||
| */ | ||
| export default async function getNetworkNameFromChainId( | ||
| chain: Chain, | ||
| ): Promise<string> { | ||
| let id = chain.id | ||
| const lists = await getLists().catch((err) => { | ||
| log.error('Error getting validator lists', err) | ||
| return undefined | ||
| }) | ||
|
|
||
| if (lists != null) { | ||
| Object.entries(lists).forEach(([network, set]) => { | ||
| if (overlaps(chain.validators, set)) { | ||
| id = network | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| return id | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ import { | |
| NETWORKS_HOSTS, | ||
| deleteAmendmentStatus, | ||
| } from '../shared/database/amendments' | ||
| import { insertValidatedLedger } from '../shared/database/validatedLedgers' | ||
| import { | ||
| AmendmentStatus, | ||
| FeeVote, | ||
|
|
@@ -110,7 +111,10 @@ export async function handleWsMessageSubscribeTypes( | |
| } else if (data.type.includes('ledger')) { | ||
| const current_ledger = data as StreamLedger | ||
| ledger_hashes.push(current_ledger.ledger_hash) | ||
|
|
||
| if (networks) { | ||
| await insertValidatedLedger(networks, current_ledger) | ||
|
Collaborator
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 think we are not de-duplicating when hitting database. Not sure if this will lead to deadlock. If we want to keep this as it is, I would suggest deploying this branch on staging/dev and then deploying it in production if it works well.
Contributor
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.
On line 33, I'm checking against for duplicates against the primary-key of the db. Given that these 3 columns make the primary-key, I expect this operation to be optimized by the DB. Besides, I'm not executing any other instruction in that method. Hence, there is no possibility of ungraceful-closure of the db operation (or) leakage of DB-connections in this method. Sure, we can observe in dev/stg environment for a few days.
Collaborator
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. Not blocking the PR review: I would recommend testing it in staging/dev for a few days. |
||
|
|
||
| const fee: FeeVote = { | ||
| fee_base: current_ledger.fee_base, | ||
| reserve_base: current_ledger.reserve_base, | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets update this after all comments are addressed.