Skip to content

additional helpful logs #326

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ npm install

The Validator History Service only supports Postgres. You'll need to create a database, but the Validator History Service will create the schema for you.

Here are some helpful commands to set up the Postgres SQL data base on MacOS.
```
brew install postgresql # installs utility tools to interact with the data base
```

If you would like to only view/inspect some records of an existing database, you can install the essential tools with `brew install psql` (You need to add the binary file to the PATH variable)

Homebrew sets the machine username as the super user of the Postgres data base. You can find your user name through `whoami` command on the terminal.
```
psql -U <username> -c '\l' # lists all the databases managed by psql
psql -U <username> -c 'create database <data_base_name>;' # This step is required by the VHS. The database_name must match the environment variable in .env file
```

These step should suffice to run VHS on your local machine.

## Linting and testing

### Linting
Expand Down
11 changes: 9 additions & 2 deletions src/connection-manager/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
try {
await Promise.all(promises)
} catch (err: unknown) {
log.error('Error saving validator chains', err)
log.error(`Error saving chain data into validators table: ${err}`)

Check failure on line 65 in src/connection-manager/chains.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Invalid type "unknown" of template literal expression

Check failure on line 65 in src/connection-manager/chains.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Invalid type "unknown" of template literal expression

Check failure on line 65 in src/connection-manager/chains.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Invalid type "unknown" of template literal expression

Check failure on line 65 in src/connection-manager/chains.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Invalid type "unknown" of template literal expression
}
}

Expand Down Expand Up @@ -131,6 +131,7 @@
* Clears all ledgers seen on a chain and saves the chain for each validator.
*/
public async purgeChains(): Promise<void> {
log.info('Purging chains...')
const promises: Array<Promise<void>> = []

this.chains = this.chains.filter((chain) => {
Expand All @@ -154,6 +155,7 @@
private getNextChainID(): string {
if (this.index > 10000) {
this.index = 0
log.error('Chain index overflowed at 10,000. Rounding back to 0.')
}

const id = `chain.${this.index}`
Expand Down Expand Up @@ -215,6 +217,8 @@
.sort(sortChainLength)
.shift()

// `ledger` has already been processed and added into the `chainAtThisIndex`.
// TODO: Add an additional check on the ledger_hash parameter to ensure that VHS is not processing conflicting ledgers.
if (chainAtThisIndex !== undefined) {
return
}
Expand All @@ -228,8 +232,11 @@
)

if (chainWithThisValidator !== undefined) {
// compute the difference between the most recent ledger versus the stored ledger in `chainWithThisValidator`.
const skipped = ledger.ledger_index - chainWithThisValidator.current
log.warn(`Possibly skipped ${skipped} ledgers`)
log.warn(
`Skipped ${skipped} ledgers in chain: ${chainWithThisValidator.id}. Processing incoming ledger with hash: ${ledger.ledger_hash} into the said chain.`,
)
if (skipped > 1 && skipped < 20) {
chainWithThisValidator.incomplete = true
addLedgerToChain(ledger, chainWithThisValidator)
Expand Down
27 changes: 18 additions & 9 deletions src/connection-manager/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@
): Promise<void> {
const ledger_hashes: string[] = []
return new Promise(function setHandlersPromise(resolve, _reject) {
ws.on('open', () => {
ws.on('open', (err: unknown) => {
if (err) {
log.error(`Error upon opening websocket: ${err}`)

Check failure on line 63 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

'err will evaluate to '[object Object]' when stringified

Check failure on line 63 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Invalid type "{}" of template literal expression

Check failure on line 63 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'err will evaluate to '[object Object]' when stringified

Check failure on line 63 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Invalid type "{}" of template literal expression

Check failure on line 63 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'err will evaluate to '[object Object]' when stringified

Check failure on line 63 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Invalid type "{}" of template literal expression

Check failure on line 63 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'err will evaluate to '[object Object]' when stringified

Check failure on line 63 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Invalid type "{}" of template literal expression
return
}
if (connections.has(ip)) {
resolve()
return
Expand All @@ -85,6 +89,7 @@
log.error('Error parsing validation message', error)
return
}
log.info(`Received message on websocket: ${data}`)

Check failure on line 92 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Invalid type "any" of template literal expression

Check failure on line 92 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Invalid type "any" of template literal expression

Check failure on line 92 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Invalid type "any" of template literal expression

Check failure on line 92 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Invalid type "any" of template literal expression

if (data.result?.node) {
void handleWsMessageLedgerEntryAmendments(
Expand All @@ -108,14 +113,15 @@
})
ws.on('close', async (code, reason) => {
const nodeNetworks = networks ?? 'unknown network'
log.error(
`Websocket closed for ${
ws.url
} on ${nodeNetworks} with code ${code} and reason ${reason.toString(
'utf-8',
)}.`,
)

if (connectionsInitialized) {
log.error(
`Websocket closed for ${
ws.url
} on ${nodeNetworks} with code ${code} and reason ${reason.toString(
'utf-8',
)}.`,
)
if (CLOSING_CODES.includes(code)) {
log.info(
`Reconnecting to ${ws.url} on ${networks ?? 'unknown network'}...`,
Expand All @@ -139,7 +145,10 @@
ws.terminate()
resolve()
})
ws.on('error', () => {
ws.on('error', (err) => {
if (err) {

Check failure on line 149 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Unnecessary conditional, value is always truthy

Check failure on line 149 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unnecessary conditional, value is always truthy

Check failure on line 149 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unnecessary conditional, value is always truthy

Check failure on line 149 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unnecessary conditional, value is always truthy
log.error(`Error on websocket: ${err}`)

Check failure on line 150 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

'err will evaluate to '[object Object]' when stringified

Check failure on line 150 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Invalid type "Error" of template literal expression

Check failure on line 150 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'err will evaluate to '[object Object]' when stringified

Check failure on line 150 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Invalid type "Error" of template literal expression

Check failure on line 150 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'err will evaluate to '[object Object]' when stringified

Check failure on line 150 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Invalid type "Error" of template literal expression

Check failure on line 150 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'err will evaluate to '[object Object]' when stringified

Check failure on line 150 in src/connection-manager/connections.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Invalid type "Error" of template literal expression
}
if (connections.get(ip)?.url === ws.url) {
connections.delete(ip)
}
Expand Down
3 changes: 3 additions & 0 deletions src/connection-manager/wsHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export function subscribe(ws: WebSocket): void {
streams: ['manifests', 'validations', 'ledger'],
}),
)
log.info(
`Subscribed to manifests, validations, and ledger streams on this websocket endpoint: ${ws.url}`,
)
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/crawler/crawl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
* @param unls - List of UNLs on the current network.
* @returns Void.
*/
private async crawlEndpoint(

Check warning on line 192 in src/crawler/crawl.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Async method 'crawlEndpoint' has too many lines (52). Maximum allowed is 50

Check warning on line 192 in src/crawler/crawl.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Async method 'crawlEndpoint' has too many statements (22). Maximum allowed is 20

Check warning on line 192 in src/crawler/crawl.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Async method 'crawlEndpoint' has too many lines (52). Maximum allowed is 50

Check warning on line 192 in src/crawler/crawl.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Async method 'crawlEndpoint' has too many statements (22). Maximum allowed is 20

Check warning on line 192 in src/crawler/crawl.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Async method 'crawlEndpoint' has too many lines (52). Maximum allowed is 50

Check warning on line 192 in src/crawler/crawl.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Async method 'crawlEndpoint' has too many statements (22). Maximum allowed is 20

Check warning on line 192 in src/crawler/crawl.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Async method 'crawlEndpoint' has too many lines (52). Maximum allowed is 50

Check warning on line 192 in src/crawler/crawl.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Async method 'crawlEndpoint' has too many statements (22). Maximum allowed is 20
host: string,
port: number,
unls: string[],
Expand All @@ -213,6 +213,9 @@
node.complete_ledgers,
)
) {
log.info(
`Node ${normalizedPublicKey} does not have relevant complete ledgers`,
)
continue
}

Expand All @@ -229,6 +232,9 @@
}

if (this.publicKeysSeen.has(normalizedPublicKey)) {
log.info(
`Node ${normalizedPublicKey} has already been processed for crawl process`,
)
continue
}

Expand Down
2 changes: 2 additions & 0 deletions src/crawler/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
const TIMEOUT = 6000

/**
* Crawl endpoint at host:port/crawl.

Check failure on line 35 in src/crawler/network.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Sentence must end with a period

Check failure on line 35 in src/crawler/network.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Sentence must end with a period

Check failure on line 35 in src/crawler/network.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Sentence must end with a period

Check failure on line 35 in src/crawler/network.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Sentence must end with a period
* Refer to the peer_crawler API docs for more information:
* https://xrpl.org/docs/references/http-websocket-apis/peer-port-methods/peer-crawler#response-format
*
* @param host - Hostname or ip address of peer.
* @param port - Port to hit /crawl endpoint.
Expand Down
Loading