-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR introduces a new feature to fetch the maximum block height information from an archive node. This information can then be used to check the synchronization of archive nodes with Mina nodes. The query below returns `canonicalMaxBlockHeight` and `pendingMaxBlockHeight`: ```graphql query maxBlockHeightInfo { networkState { maxBlockHeight { canonicalMaxBlockHeight pendingMaxBlockHeight } } } ``` closes #111
- Loading branch information
Showing
11 changed files
with
258 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
import type { EventFilterOptionsInput } from '../../resolvers-types.js'; | ||
import type { Actions, Events } from '../../blockchain/types.js'; | ||
import type { | ||
Actions, | ||
Events, | ||
NetworkState, | ||
} from '../../blockchain/types.js'; | ||
|
||
export interface DatabaseAdapter { | ||
getEvents(input: EventFilterOptionsInput, options?: unknown): Promise<Events>; | ||
getActions( | ||
input: EventFilterOptionsInput, | ||
options?: unknown | ||
): Promise<Actions>; | ||
getNetworkState(options?: unknown): Promise<NetworkState>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { NetworkState } from '../../blockchain/types.js'; | ||
|
||
export interface INetworkService { | ||
getNetworkState(options: unknown): Promise<NetworkState>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type postgres from 'postgres'; | ||
import { NetworkState } from '../../blockchain/types.js'; | ||
import { getNetworkStateQuery } from '../../db/sql/events-actions/queries.js'; | ||
|
||
import { INetworkService } from './network-service.interface.js'; | ||
import { | ||
TracingState, | ||
extractTraceStateFromOptions, | ||
} from '../../tracing/tracer.js'; | ||
|
||
export { NetworkService }; | ||
|
||
class NetworkService implements INetworkService { | ||
private readonly client: postgres.Sql; | ||
|
||
constructor(client: postgres.Sql) { | ||
this.client = client; | ||
} | ||
|
||
async getNetworkState(options: unknown): Promise<NetworkState> { | ||
const tracingState = extractTraceStateFromOptions(options); | ||
return (await this.getNetworkStateData({ tracingState })) ?? []; | ||
} | ||
|
||
async getNetworkStateData({ | ||
tracingState, | ||
}: { | ||
tracingState: TracingState; | ||
}): Promise<NetworkState> { | ||
const sqlSpan = tracingState.startSpan('networkState.SQL'); | ||
const rows = await this.executeNetworkStateQuery(); | ||
sqlSpan.end(); | ||
|
||
const processingSpan = tracingState.startSpan('networkState.processing'); | ||
const maxBlockHeightInfo = { | ||
canonicalMaxBlockHeight: Number( | ||
rows.filter((row) => row.chain_status === 'canonical')[0].height | ||
), | ||
pendingMaxBlockHeight: Number( | ||
rows.filter((row) => row.chain_status === 'pending')[0].height | ||
), | ||
}; | ||
const networkState = { | ||
maxBlockHeight: maxBlockHeightInfo | ||
} | ||
processingSpan.end(); | ||
return networkState; | ||
} | ||
|
||
private async executeNetworkStateQuery() { | ||
return getNetworkStateQuery(this.client); | ||
} | ||
} |
Oops, something went wrong.