@xyo-network/chain-orchestration 1.17.2 → 1.17.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/ChainInitializableParams.d.ts +11 -0
- package/dist/neutral/ChainInitializableParams.d.ts.map +1 -0
- package/dist/neutral/actor/Actor.d.ts.map +1 -1
- package/dist/neutral/actor/BalanceActor.d.ts +14 -0
- package/dist/neutral/actor/BalanceActor.d.ts.map +1 -0
- package/dist/neutral/actor/ValidatorActor.d.ts +23 -0
- package/dist/neutral/actor/ValidatorActor.d.ts.map +1 -0
- package/dist/neutral/actor/index.d.ts +2 -0
- package/dist/neutral/actor/index.d.ts.map +1 -1
- package/dist/neutral/archivists/ChainFinalized/archivist.d.ts +4 -0
- package/dist/neutral/archivists/ChainFinalized/archivist.d.ts.map +1 -0
- package/dist/neutral/archivists/ChainFinalized/index.d.ts +2 -0
- package/dist/neutral/archivists/ChainFinalized/index.d.ts.map +1 -0
- package/dist/neutral/archivists/ChainFinalized/local.d.ts +7 -0
- package/dist/neutral/archivists/ChainFinalized/local.d.ts.map +1 -0
- package/dist/neutral/archivists/PendingBlocks/archivist.d.ts +4 -0
- package/dist/neutral/archivists/PendingBlocks/archivist.d.ts.map +1 -0
- package/dist/neutral/archivists/PendingBlocks/index.d.ts +2 -0
- package/dist/neutral/archivists/PendingBlocks/index.d.ts.map +1 -0
- package/dist/neutral/archivists/PendingBlocks/local.d.ts +7 -0
- package/dist/neutral/archivists/PendingBlocks/local.d.ts.map +1 -0
- package/dist/neutral/archivists/PendingTransactions/archivist.d.ts +4 -0
- package/dist/neutral/archivists/PendingTransactions/archivist.d.ts.map +1 -0
- package/dist/neutral/archivists/PendingTransactions/index.d.ts +2 -0
- package/dist/neutral/archivists/PendingTransactions/index.d.ts.map +1 -0
- package/dist/neutral/archivists/PendingTransactions/local.d.ts +7 -0
- package/dist/neutral/archivists/PendingTransactions/local.d.ts.map +1 -0
- package/dist/neutral/archivists/RejectedTransactions/archivist.d.ts +4 -0
- package/dist/neutral/archivists/RejectedTransactions/archivist.d.ts.map +1 -0
- package/dist/neutral/archivists/RejectedTransactions/index.d.ts +2 -0
- package/dist/neutral/archivists/RejectedTransactions/index.d.ts.map +1 -0
- package/dist/neutral/archivists/RejectedTransactions/local.d.ts +4 -0
- package/dist/neutral/archivists/RejectedTransactions/local.d.ts.map +1 -0
- package/dist/neutral/archivists/StakeIntentState/archivist.d.ts +5 -0
- package/dist/neutral/archivists/StakeIntentState/archivist.d.ts.map +1 -0
- package/dist/neutral/archivists/StakeIntentState/index.d.ts +2 -0
- package/dist/neutral/archivists/StakeIntentState/index.d.ts.map +1 -0
- package/dist/neutral/archivists/StakeIntentState/local.d.ts +7 -0
- package/dist/neutral/archivists/StakeIntentState/local.d.ts.map +1 -0
- package/dist/neutral/archivists/index.d.ts +6 -0
- package/dist/neutral/archivists/index.d.ts.map +1 -0
- package/dist/neutral/archivists/lib/index.d.ts +2 -0
- package/dist/neutral/archivists/lib/index.d.ts.map +1 -0
- package/dist/neutral/archivists/lib/localPersistentArchivist.d.ts +21 -0
- package/dist/neutral/archivists/lib/localPersistentArchivist.d.ts.map +1 -0
- package/dist/neutral/buildTelemetryConfig.d.ts +13 -0
- package/dist/neutral/buildTelemetryConfig.d.ts.map +1 -0
- package/dist/neutral/health/index.d.ts +2 -0
- package/dist/neutral/health/index.d.ts.map +1 -0
- package/dist/neutral/health/initHealthEndpoints.d.ts +11 -0
- package/dist/neutral/health/initHealthEndpoints.d.ts.map +1 -0
- package/dist/neutral/host/implementation/DefaultHost.d.ts +12 -0
- package/dist/neutral/host/implementation/DefaultHost.d.ts.map +1 -0
- package/dist/neutral/host/implementation/DefaultServiceCollection.d.ts +24 -0
- package/dist/neutral/host/implementation/DefaultServiceCollection.d.ts.map +1 -0
- package/dist/neutral/host/implementation/DefaultServiceProvider.d.ts +7 -0
- package/dist/neutral/host/implementation/DefaultServiceProvider.d.ts.map +1 -0
- package/dist/neutral/host/implementation/index.d.ts +3 -0
- package/dist/neutral/host/implementation/index.d.ts.map +1 -0
- package/dist/neutral/host/index.d.ts +3 -0
- package/dist/neutral/host/index.d.ts.map +1 -0
- package/dist/neutral/host/model/Host.d.ts +19 -0
- package/dist/neutral/host/model/Host.d.ts.map +1 -0
- package/dist/neutral/host/model/ServiceCollection.d.ts +20 -0
- package/dist/neutral/host/model/ServiceCollection.d.ts.map +1 -0
- package/dist/neutral/host/model/ServiceProvider.d.ts +4 -0
- package/dist/neutral/host/model/ServiceProvider.d.ts.map +1 -0
- package/dist/neutral/host/model/index.d.ts +4 -0
- package/dist/neutral/host/model/index.d.ts.map +1 -0
- package/dist/neutral/index.d.ts +7 -2
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +701 -626
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/init/index.d.ts +1 -2
- package/dist/neutral/init/index.d.ts.map +1 -1
- package/dist/neutral/init/initChainStakeViewer.d.ts +4 -1
- package/dist/neutral/init/initChainStakeViewer.d.ts.map +1 -1
- package/dist/neutral/init/initServerNode.d.ts +4 -2
- package/dist/neutral/init/initServerNode.d.ts.map +1 -1
- package/dist/neutral/init/initStatusReporter.d.ts +6 -0
- package/dist/neutral/init/initStatusReporter.d.ts.map +1 -0
- package/dist/neutral/manifest/getLocator.d.ts +1 -1
- package/dist/neutral/manifest/getLocator.d.ts.map +1 -1
- package/dist/neutral/manifest/loadNode.d.ts.map +1 -1
- package/dist/neutral/manifest/public/index.d.ts +5 -2
- package/dist/neutral/manifest/public/index.d.ts.map +1 -1
- package/dist/neutral/orchestrator/Orchestrator.d.ts +0 -2
- package/dist/neutral/orchestrator/Orchestrator.d.ts.map +1 -1
- package/dist/neutral/status/RuntimeStatusMonitor.d.ts +31 -0
- package/dist/neutral/status/RuntimeStatusMonitor.d.ts.map +1 -0
- package/dist/neutral/status/ServiceStatus.d.ts +8 -0
- package/dist/neutral/status/ServiceStatus.d.ts.map +1 -0
- package/dist/neutral/status/index.d.ts +3 -0
- package/dist/neutral/status/index.d.ts.map +1 -0
- package/package.json +16 -18
- package/src/ChainInitializableParams.ts +12 -0
- package/src/actor/Actor.ts +0 -1
- package/src/actor/BalanceActor.ts +36 -0
- package/src/actor/ValidatorActor.ts +126 -0
- package/src/actor/index.ts +2 -0
- package/src/archivists/ChainFinalized/archivist.ts +21 -0
- package/src/archivists/ChainFinalized/index.ts +1 -0
- package/src/archivists/ChainFinalized/local.ts +18 -0
- package/src/archivists/PendingBlocks/archivist.ts +21 -0
- package/src/archivists/PendingBlocks/index.ts +1 -0
- package/src/archivists/PendingBlocks/local.ts +18 -0
- package/src/archivists/PendingTransactions/archivist.ts +21 -0
- package/src/archivists/PendingTransactions/index.ts +1 -0
- package/src/archivists/PendingTransactions/local.ts +18 -0
- package/src/archivists/RejectedTransactions/archivist.ts +21 -0
- package/src/archivists/RejectedTransactions/index.ts +1 -0
- package/src/archivists/RejectedTransactions/local.ts +20 -0
- package/src/archivists/StakeIntentState/archivist.ts +24 -0
- package/src/archivists/StakeIntentState/index.ts +1 -0
- package/src/archivists/StakeIntentState/local.ts +19 -0
- package/src/archivists/index.ts +5 -0
- package/src/archivists/lib/index.ts +1 -0
- package/src/archivists/lib/localPersistentArchivist.ts +63 -0
- package/src/buildTelemetryConfig.ts +15 -0
- package/src/health/index.ts +1 -0
- package/src/health/initHealthEndpoints.ts +71 -0
- package/src/host/implementation/DefaultHost.ts +25 -0
- package/src/host/implementation/DefaultServiceCollection.ts +60 -0
- package/src/host/implementation/DefaultServiceProvider.ts +12 -0
- package/src/host/implementation/index.ts +2 -0
- package/src/host/index.ts +2 -0
- package/src/host/model/Host.ts +21 -0
- package/src/host/model/ServiceCollection.ts +22 -0
- package/src/host/model/ServiceProvider.ts +3 -0
- package/src/host/model/index.ts +3 -0
- package/src/index.ts +7 -2
- package/src/init/index.ts +1 -2
- package/src/init/initChainStakeViewer.ts +1 -1
- package/src/init/initServerNode.ts +26 -12
- package/src/init/initStatusReporter.ts +16 -0
- package/src/manifest/getLocator.ts +2 -33
- package/src/manifest/loadNode.ts +1 -3
- package/src/manifest/public/{WithoutMempool/Pending.json → Chain.json} +18 -18
- package/src/manifest/public/{WithMempool/Pending.json → Pending.json} +2 -2
- package/src/manifest/public/index.ts +20 -2
- package/src/orchestrator/Orchestrator.ts +0 -2
- package/src/status/RuntimeStatusMonitor.ts +117 -0
- package/src/status/ServiceStatus.ts +20 -0
- package/src/status/index.ts +2 -0
- package/dist/neutral/archivist/index.d.ts +0 -3
- package/dist/neutral/archivist/index.d.ts.map +0 -1
- package/dist/neutral/archivist/initArchivistSync.d.ts +0 -6
- package/dist/neutral/archivist/initArchivistSync.d.ts.map +0 -1
- package/dist/neutral/archivist/wrapWithReadCachingArchivist.d.ts +0 -5
- package/dist/neutral/archivist/wrapWithReadCachingArchivist.d.ts.map +0 -1
- package/dist/neutral/bridge.d.ts +0 -3
- package/dist/neutral/bridge.d.ts.map +0 -1
- package/dist/neutral/init/initPendingBlockArchivist.d.ts +0 -4
- package/dist/neutral/init/initPendingBlockArchivist.d.ts.map +0 -1
- package/dist/neutral/init/initPendingTransactionArchivist.d.ts +0 -4
- package/dist/neutral/init/initPendingTransactionArchivist.d.ts.map +0 -1
- package/dist/neutral/manifest/public/WithMempool/index.d.ts +0 -6
- package/dist/neutral/manifest/public/WithMempool/index.d.ts.map +0 -1
- package/dist/neutral/manifest/public/WithoutMempool/index.d.ts +0 -6
- package/dist/neutral/manifest/public/WithoutMempool/index.d.ts.map +0 -1
- package/src/archivist/index.ts +0 -2
- package/src/archivist/initArchivistSync.ts +0 -61
- package/src/archivist/wrapWithReadCachingArchivist.ts +0 -56
- package/src/bridge.ts +0 -25
- package/src/init/initPendingBlockArchivist.ts +0 -31
- package/src/init/initPendingTransactionArchivist.ts +0 -31
- package/src/manifest/public/WithMempool/Chain.json +0 -175
- package/src/manifest/public/WithMempool/index.ts +0 -20
- package/src/manifest/public/WithoutMempool/Chain.json +0 -97
- package/src/manifest/public/WithoutMempool/index.ts +0 -20
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { rm } from 'node:fs/promises'
|
|
2
|
+
import Path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { LmdbArchivist, LmdbArchivistConfigSchema } from '@xyo-network/archivist-lmdb'
|
|
5
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
6
|
+
import { getStoreDirectory, type StoreKind } from '@xyo-network/chain-protocol'
|
|
7
|
+
|
|
8
|
+
const DEFAULT_STORAGE_ROOT = Path.join(process.cwd(), '.store')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Returns a local persistent archivist
|
|
12
|
+
* @param name The name of the archivist
|
|
13
|
+
* @param dbName The name of the database
|
|
14
|
+
* @param storeName The name of the store
|
|
15
|
+
* @param storageRoot The root directory for storage (default is '.store' in the current working directory)
|
|
16
|
+
* @param kind The kind of the archivist
|
|
17
|
+
* @returns an archivist instance
|
|
18
|
+
*/
|
|
19
|
+
export const getLocalPersistentArchivist = (
|
|
20
|
+
name: string,
|
|
21
|
+
dbName: string,
|
|
22
|
+
storeName: string,
|
|
23
|
+
storageRoot?: string,
|
|
24
|
+
kind: StoreKind = 'lmdb',
|
|
25
|
+
): Promise<ArchivistInstance> => {
|
|
26
|
+
switch (kind) {
|
|
27
|
+
case 'lmdb': {
|
|
28
|
+
const root = storageRoot ?? DEFAULT_STORAGE_ROOT
|
|
29
|
+
return LmdbArchivist.create({
|
|
30
|
+
account: 'random',
|
|
31
|
+
config: {
|
|
32
|
+
name,
|
|
33
|
+
clearStoreOnStart: false,
|
|
34
|
+
dbName,
|
|
35
|
+
location: getStoreDirectory(dbName, root, 'lmdb'),
|
|
36
|
+
schema: LmdbArchivistConfigSchema,
|
|
37
|
+
storeName,
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Deletes a local persistent archivist
|
|
46
|
+
* @param dbName The name of the database
|
|
47
|
+
* @param storageRoot The root directory for storage (default is '.store' in the current working directory)
|
|
48
|
+
* @param kind The kind of the archivist
|
|
49
|
+
* @returns A promise that resolves when the archivist is deleted
|
|
50
|
+
*/
|
|
51
|
+
export const deleteLocalPersistentArchivist = async (dbName: string, storageRoot?: string, kind: StoreKind = 'lmdb'): Promise<void> => {
|
|
52
|
+
await Promise.resolve()
|
|
53
|
+
console.warn(`Deleting local persistent archivist for ${dbName} of kind ${kind}.`)
|
|
54
|
+
let location = ''
|
|
55
|
+
switch (kind) {
|
|
56
|
+
case 'lmdb': {
|
|
57
|
+
const root = storageRoot ?? DEFAULT_STORAGE_ROOT
|
|
58
|
+
location = getStoreDirectory(dbName, root, 'lmdb')
|
|
59
|
+
break
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
await rm(location, { recursive: true, force: true })
|
|
63
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
2
|
+
|
|
3
|
+
export function buildTelemetryConfig(config: Config, serviceName: string, serviceVersion: string) {
|
|
4
|
+
const { otlpEndpoint } = config.telemetry?.otel ?? {}
|
|
5
|
+
const { path: endpoint = '/metrics', port: port = 9464 } = config.telemetry?.metrics?.scrape ?? {}
|
|
6
|
+
const telemetryConfig = {
|
|
7
|
+
attributes: {
|
|
8
|
+
serviceName,
|
|
9
|
+
serviceVersion,
|
|
10
|
+
},
|
|
11
|
+
otlpEndpoint,
|
|
12
|
+
metricsConfig: { endpoint, port },
|
|
13
|
+
}
|
|
14
|
+
return telemetryConfig
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './initHealthEndpoints.ts'
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
IncomingMessage, Server, ServerResponse,
|
|
3
|
+
} from 'node:http'
|
|
4
|
+
import http from 'node:http'
|
|
5
|
+
|
|
6
|
+
import type { CreatableStatus, Logger } from '@xylabs/sdk-js'
|
|
7
|
+
import { isDefined } from '@xylabs/sdk-js'
|
|
8
|
+
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
9
|
+
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
10
|
+
|
|
11
|
+
import type { RuntimeStatusMonitor } from '../status/index.ts'
|
|
12
|
+
|
|
13
|
+
const sendStatus = (res: ServerResponse, status: CreatableStatus, errorCode: number) => {
|
|
14
|
+
const statusCode = status === 'started' ? 200 : errorCode
|
|
15
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' })
|
|
16
|
+
res.end(JSON.stringify({ status }))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const notFound = (res: ServerResponse) => {
|
|
20
|
+
res.writeHead(404, { 'Content-Type': 'application/json' })
|
|
21
|
+
res.end(JSON.stringify({ status: 'not found' }))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Starts an HTTP server with Kubernetes health endpoints:
|
|
26
|
+
* - /healthz
|
|
27
|
+
* - /livez
|
|
28
|
+
* - /readyz
|
|
29
|
+
* @param port The port to listen on (default: 8080)
|
|
30
|
+
*/
|
|
31
|
+
const createHealthServer = (port: number, statusMonitor: RuntimeStatusMonitor, logger: Logger) => {
|
|
32
|
+
const server = http.createServer((req: IncomingMessage, res: ServerResponse) => {
|
|
33
|
+
const url = req.url ?? ''
|
|
34
|
+
|
|
35
|
+
const status = statusMonitor.getGlobalStatus()
|
|
36
|
+
|
|
37
|
+
switch (url) {
|
|
38
|
+
case '/healthz': {
|
|
39
|
+
sendStatus(res, status, 500)
|
|
40
|
+
break
|
|
41
|
+
}
|
|
42
|
+
case '/livez': {
|
|
43
|
+
sendStatus(res, status, 503)
|
|
44
|
+
break
|
|
45
|
+
}
|
|
46
|
+
case '/readyz': {
|
|
47
|
+
sendStatus(res, status, 503)
|
|
48
|
+
break
|
|
49
|
+
}
|
|
50
|
+
default: {
|
|
51
|
+
notFound(res)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
server.listen(port, () => {
|
|
57
|
+
logger.log(`Health server running on http://localhost:${port}`)
|
|
58
|
+
logger.log(' - /healthz')
|
|
59
|
+
logger.log(' - /livez')
|
|
60
|
+
logger.log(' - /readyz')
|
|
61
|
+
})
|
|
62
|
+
return server
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const initHealthEndpoints: Initializable<{ config: Config; logger: Logger; statusReporter: RuntimeStatusMonitor }, Server | undefined> = (params) => {
|
|
66
|
+
const {
|
|
67
|
+
config, logger, statusReporter,
|
|
68
|
+
} = params
|
|
69
|
+
const { healthCheckPort } = config.producer
|
|
70
|
+
return isDefined(healthCheckPort) ? createHealthServer(healthCheckPort, statusReporter, logger) : undefined
|
|
71
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Host, ServiceProvider } from '../model/index.ts'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A generic host implementation that can be used as a starting point for
|
|
5
|
+
* more complex host implementations.
|
|
6
|
+
*/
|
|
7
|
+
export class GenericHost implements Host {
|
|
8
|
+
services: ServiceProvider
|
|
9
|
+
|
|
10
|
+
constructor(services: ServiceProvider) {
|
|
11
|
+
this.services = services
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async start(): Promise<void> {
|
|
15
|
+
await Promise.resolve()
|
|
16
|
+
// Initialize or start your services here
|
|
17
|
+
console.log('Host is starting...')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async stop(): Promise<void> {
|
|
21
|
+
await Promise.resolve()
|
|
22
|
+
// Stop or clean up services here
|
|
23
|
+
console.log('Host is stopping...')
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ServiceCollection, ServiceDescriptor, ServiceProvider,
|
|
3
|
+
} from '../model/index.ts'
|
|
4
|
+
import { ServiceLifetime } from '../model/index.ts'
|
|
5
|
+
import { DefaultServiceProvider } from './DefaultServiceProvider.ts'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A collection of service descriptors, allowing adding/removing services before building.
|
|
9
|
+
*/
|
|
10
|
+
export class DefaultServiceCollection implements ServiceCollection {
|
|
11
|
+
private readonly descriptors: ServiceDescriptor[] = []
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Register a service as Singleton: a single instance is created and shared.
|
|
15
|
+
*/
|
|
16
|
+
addSingleton<T>(
|
|
17
|
+
identifier: string | symbol,
|
|
18
|
+
implementationFactory: () => T,
|
|
19
|
+
): void {
|
|
20
|
+
this.descriptors.push({
|
|
21
|
+
identifier,
|
|
22
|
+
lifetime: ServiceLifetime.Singleton,
|
|
23
|
+
implementationFactory,
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Register a service as Transient: a new instance is created on each request.
|
|
29
|
+
*/
|
|
30
|
+
addTransient<T>(
|
|
31
|
+
_identifier: string | symbol,
|
|
32
|
+
_implementationFactory: () => T,
|
|
33
|
+
): void {
|
|
34
|
+
throw new Error('Not implemented')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Build a concrete, immutable service provider from the current descriptors.
|
|
39
|
+
*/
|
|
40
|
+
build(): ServiceProvider {
|
|
41
|
+
const services: Record<string, unknown> = {}
|
|
42
|
+
for (const descriptor of this.descriptors) {
|
|
43
|
+
if (descriptor.lifetime === ServiceLifetime.Singleton) {
|
|
44
|
+
services[descriptor.identifier.toString()] = descriptor.implementationFactory()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return new DefaultServiceProvider(services)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Removes all registrations matching the given identifier.
|
|
52
|
+
*/
|
|
53
|
+
remove(identifier: string | symbol): void {
|
|
54
|
+
for (let i = this.descriptors.length - 1; i >= 0; i--) {
|
|
55
|
+
if (this.descriptors[i].identifier === identifier) {
|
|
56
|
+
this.descriptors.splice(i, 1)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ServiceProvider } from '../model/index.ts'
|
|
2
|
+
|
|
3
|
+
export class DefaultServiceProvider implements ServiceProvider {
|
|
4
|
+
protected _services: Record<string, unknown>
|
|
5
|
+
constructor(services: Record<string, unknown>) {
|
|
6
|
+
this._services = services
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
getService<T>(serviceIdentifier: string): T | undefined {
|
|
10
|
+
return this._services[serviceIdentifier] as T
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ServiceProvider } from './ServiceProvider.ts'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents the host for an application.
|
|
5
|
+
*/
|
|
6
|
+
export interface Host {
|
|
7
|
+
/**
|
|
8
|
+
* Provides access to the application's services (for dependency injection).
|
|
9
|
+
*/
|
|
10
|
+
services: ServiceProvider
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Starts the host and any underlying services (e.g., background tasks).
|
|
14
|
+
*/
|
|
15
|
+
start(): Promise<void>
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Stops the host and attempts to gracefully shut down services.
|
|
19
|
+
*/
|
|
20
|
+
stop(): Promise<void>
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ServiceProvider } from './ServiceProvider.ts'
|
|
2
|
+
|
|
3
|
+
export interface ServiceCollection {
|
|
4
|
+
build(): ServiceProvider
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Represents the lifetime of a service
|
|
9
|
+
*/
|
|
10
|
+
export const ServiceLifetime = {
|
|
11
|
+
Singleton: 'Singleton',
|
|
12
|
+
Transient: 'Transient',
|
|
13
|
+
} as const
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Describes a single service registration
|
|
17
|
+
*/
|
|
18
|
+
export interface ServiceDescriptor<T = unknown> {
|
|
19
|
+
identifier: string | symbol
|
|
20
|
+
implementationFactory: () => T
|
|
21
|
+
lifetime: keyof typeof ServiceLifetime
|
|
22
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export * from './actor/index.ts'
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
2
|
+
export * from './archivists/index.ts'
|
|
3
|
+
export * from './buildTelemetryConfig.ts'
|
|
4
|
+
export * from './ChainInitializableParams.ts'
|
|
4
5
|
export * from './ConfigContext.ts'
|
|
5
6
|
export * from './createDeclarationIntentBlock.ts'
|
|
7
|
+
export * from './evm/index.ts'
|
|
8
|
+
export * from './health/index.ts'
|
|
9
|
+
export * from './host/index.ts'
|
|
6
10
|
export * from './init/index.ts'
|
|
7
11
|
export * from './manifest/index.ts'
|
|
8
12
|
export * from './orchestrator/index.ts'
|
|
13
|
+
export * from './status/index.ts'
|
package/src/init/index.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export * from './initBalanceSummaryMap.ts'
|
|
2
2
|
export * from './initBridgedModule.ts'
|
|
3
3
|
export * from './initChainStakeViewer.ts'
|
|
4
|
-
export * from './initPendingBlockArchivist.ts'
|
|
5
|
-
export * from './initPendingTransactionArchivist.ts'
|
|
6
4
|
export * from './initProducerAccount.ts'
|
|
7
5
|
export * from './initSeedPhrase.ts'
|
|
8
6
|
export * from './initServerNode.ts'
|
|
9
7
|
export * from './initServerWallet.ts'
|
|
8
|
+
export * from './initStatusReporter.ts'
|
|
10
9
|
export * from './initTransferSummaryMap.ts'
|
|
11
10
|
export * from './iterator.ts'
|
|
@@ -32,7 +32,7 @@ export async function initSimpleStakeViewer(config: Config, logger?: Logger): Pr
|
|
|
32
32
|
return stakeChainViewer
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export async function initStakeViewer(config: Config
|
|
35
|
+
export async function initStakeViewer({ config, logger}: { config: Config; logger?: Logger }): Promise<StakeViewer> {
|
|
36
36
|
if (canUseEvmProvider({ config })) {
|
|
37
37
|
return await initEvmChainStakeViewer(config, logger)
|
|
38
38
|
} else {
|
|
@@ -10,20 +10,32 @@ import type {
|
|
|
10
10
|
import type { ConfigContext } from '../ConfigContext.ts'
|
|
11
11
|
import { loadNode } from '../manifest/index.ts'
|
|
12
12
|
|
|
13
|
-
async function
|
|
14
|
-
|
|
13
|
+
async function writableChainArchivistFromNode(node: NodeInstance) {
|
|
14
|
+
return asArchivistInstance(
|
|
15
15
|
await node.resolve('Chain:Validated'),
|
|
16
16
|
{ required: true },
|
|
17
|
-
)
|
|
18
|
-
return chainArchivist
|
|
17
|
+
)
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
async function
|
|
22
|
-
|
|
23
|
-
await node.resolve('
|
|
20
|
+
async function readonlyChainArchivistFromNode(node: NodeInstance) {
|
|
21
|
+
return assertEx(asArchivistInstance(
|
|
22
|
+
await node.resolve('Chain:Validated'),
|
|
23
|
+
{ required: true },
|
|
24
|
+
))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function pendingTransactionsArchivistFromNode(node: NodeInstance) {
|
|
28
|
+
return asArchivistInstance(
|
|
29
|
+
await node.resolve('XYOChain:Pending:Transactions'),
|
|
30
|
+
{ required: true },
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function pendingBlocksArchivistFromNode(node: NodeInstance) {
|
|
35
|
+
return asArchivistInstance(
|
|
36
|
+
await node.resolve('XYOChain:Pending:Blocks'),
|
|
24
37
|
{ required: true },
|
|
25
|
-
)
|
|
26
|
-
return pendingArchivist
|
|
38
|
+
)
|
|
27
39
|
}
|
|
28
40
|
|
|
29
41
|
export async function initServerNode({
|
|
@@ -37,9 +49,11 @@ export async function initServerNode({
|
|
|
37
49
|
const node: NodeInstance = providedNode ?? await loadNode({
|
|
38
50
|
wallet, logger, config, transfersSummaryMap, balancesSummaryMap,
|
|
39
51
|
})
|
|
40
|
-
const
|
|
41
|
-
const
|
|
52
|
+
const writableChainArchivist = await writableChainArchivistFromNode(node)
|
|
53
|
+
const readonlyChainArchivist = await readonlyChainArchivistFromNode(node)
|
|
54
|
+
const pendingTransactionsArchivist = await pendingTransactionsArchivistFromNode(node)
|
|
55
|
+
const pendingBlocksArchivist = await pendingBlocksArchivistFromNode(node)
|
|
42
56
|
return {
|
|
43
|
-
node,
|
|
57
|
+
node, writableChainArchivist, readonlyChainArchivist, pendingTransactionsArchivist, pendingBlocksArchivist,
|
|
44
58
|
}
|
|
45
59
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Logger } from '@xylabs/sdk-js'
|
|
2
|
+
|
|
3
|
+
import { RuntimeStatusMonitor } from '../status/index.ts'
|
|
4
|
+
|
|
5
|
+
export function initStatusReporter({ logger }: { logger: Logger }) {
|
|
6
|
+
const statusReporter = new RuntimeStatusMonitor(logger)
|
|
7
|
+
statusReporter.onGlobalTransition({ to: 'started' }, () => {
|
|
8
|
+
logger.log('All services started.')
|
|
9
|
+
})
|
|
10
|
+
statusReporter.onGlobalTransition({ to: 'error' }, () => {
|
|
11
|
+
logger.error('Producer encountered an unhandled error!')
|
|
12
|
+
// eslint-disable-next-line unicorn/no-process-exit
|
|
13
|
+
process.exit(1)
|
|
14
|
+
})
|
|
15
|
+
return statusReporter
|
|
16
|
+
}
|
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import { type BaseMongoSdkPrivateConfig } from '@xylabs/mongo'
|
|
2
|
-
import {
|
|
3
|
-
asAddress, assertEx, isDefined,
|
|
4
|
-
ZERO_ADDRESS,
|
|
5
|
-
} from '@xylabs/sdk-js'
|
|
2
|
+
import { isDefined } from '@xylabs/sdk-js'
|
|
6
3
|
import { MemoryArchivist } from '@xyo-network/archivist-memory'
|
|
7
4
|
import { MongoDBArchivistV2 } from '@xyo-network/archivist-mongodb'
|
|
8
5
|
import { ViewArchivist } from '@xyo-network/archivist-view'
|
|
9
|
-
import {
|
|
10
|
-
AddressBalanceDivinerV2, AddressTransferDiviner, ArchivistSyncDiviner, HeadValidationDiviner,
|
|
11
|
-
} from '@xyo-network/chain-modules'
|
|
12
6
|
import { initTelemetry } from '@xyo-network/chain-telemetry'
|
|
13
7
|
import { AbstractModule, LoggerModuleStatusReporter } from '@xyo-network/module-abstract'
|
|
14
8
|
import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
|
|
15
9
|
import type { MongoDBModuleParamsV2 } from '@xyo-network/module-model-mongodb'
|
|
16
10
|
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
17
11
|
import { MemorySentinel } from '@xyo-network/sentinel-memory'
|
|
18
|
-
import { StepSizes } from '@xyo-network/xl1-protocol'
|
|
19
12
|
import type {
|
|
20
13
|
BalancesStepSummary, MapType, TransfersStepSummary,
|
|
21
14
|
} from '@xyo-network/xl1-protocol-sdk'
|
|
22
15
|
import { hasMongoConfig } from '@xyo-network/xl1-protocol-sdk'
|
|
23
|
-
import { Semaphore } from 'async-mutex'
|
|
24
16
|
|
|
25
17
|
import type { ConfigContext } from '../ConfigContext.ts'
|
|
26
18
|
|
|
@@ -29,9 +21,7 @@ import type { ConfigContext } from '../ConfigContext.ts'
|
|
|
29
21
|
* operation of the node (entirely in memory)
|
|
30
22
|
* @returns A locator with the necessary modules registered
|
|
31
23
|
*/
|
|
32
|
-
export const getLocator = async ({
|
|
33
|
-
config, logger, balancesSummaryMap, transfersSummaryMap,
|
|
34
|
-
}: ConfigContext<{
|
|
24
|
+
export const getLocator = async ({ config, logger}: ConfigContext<{
|
|
35
25
|
balancesSummaryMap: MapType<string, WithStorageMeta<BalancesStepSummary>>
|
|
36
26
|
transfersSummaryMap: MapType<string, WithStorageMeta<TransfersStepSummary>>
|
|
37
27
|
}>) => {
|
|
@@ -67,24 +57,6 @@ export const getLocator = async ({
|
|
|
67
57
|
locator.register(MongoDBArchivistV2.factory(params), undefined, true)
|
|
68
58
|
}
|
|
69
59
|
|
|
70
|
-
locator.register(AddressBalanceDivinerV2.factory<AddressBalanceDivinerV2>({
|
|
71
|
-
traceProvider, meterProvider, statusReporter, summaryMap: balancesSummaryMap, stepSemaphores: StepSizes.map(() => new Semaphore(20)),
|
|
72
|
-
}))
|
|
73
|
-
|
|
74
|
-
locator.register(AddressTransferDiviner.factory<AddressTransferDiviner>({
|
|
75
|
-
traceProvider, meterProvider, statusReporter, summaryMap: transfersSummaryMap, stepSemaphores: StepSizes.map(() => new Semaphore(20)),
|
|
76
|
-
}))
|
|
77
|
-
|
|
78
|
-
const chainId = isDefined(config.chain.id)
|
|
79
|
-
? assertEx(asAddress(config.chain.id), () => 'chain.id must be an Address')
|
|
80
|
-
: ZERO_ADDRESS
|
|
81
|
-
locator.register(HeadValidationDiviner.factory<HeadValidationDiviner>({
|
|
82
|
-
traceProvider,
|
|
83
|
-
meterProvider,
|
|
84
|
-
statusReporter,
|
|
85
|
-
chainId,
|
|
86
|
-
allowedProducers: config.producer.allowlist,
|
|
87
|
-
}))
|
|
88
60
|
locator.register(MemoryArchivist.factory({
|
|
89
61
|
traceProvider, meterProvider, statusReporter,
|
|
90
62
|
}))
|
|
@@ -94,8 +66,5 @@ export const getLocator = async ({
|
|
|
94
66
|
locator.register(ViewArchivist.factory({
|
|
95
67
|
traceProvider, meterProvider, statusReporter,
|
|
96
68
|
}))
|
|
97
|
-
locator.register(ArchivistSyncDiviner.factory({
|
|
98
|
-
traceProvider, meterProvider, statusReporter,
|
|
99
|
-
}))
|
|
100
69
|
return locator
|
|
101
70
|
}
|
package/src/manifest/loadNode.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { ConfigContext } from '../ConfigContext.ts'
|
|
|
9
9
|
import { getLocator } from './getLocator.ts'
|
|
10
10
|
import { NodeManifest } from './nodeManifest.ts'
|
|
11
11
|
import { PrivateChildManifests } from './private/index.ts'
|
|
12
|
-
import {
|
|
12
|
+
import { PublicChildManifests } from './public/index.ts'
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Creates a node with the xyo-chain modules registered
|
|
@@ -22,8 +22,6 @@ export const loadNode = async ({
|
|
|
22
22
|
transfersSummaryMap: MapType<string, WithStorageMeta<TransfersStepSummary>>
|
|
23
23
|
wallet: WalletInstance
|
|
24
24
|
}>) => {
|
|
25
|
-
const { enabled: mempoolEnabled } = config.mempool
|
|
26
|
-
const PublicChildManifests = mempoolEnabled ? PublicChildManifestsWithoutMempool : PublicChildManifestsWithMempool
|
|
27
25
|
const locator = await getLocator({
|
|
28
26
|
config, balancesSummaryMap, transfersSummaryMap,
|
|
29
27
|
})
|
|
@@ -3,42 +3,42 @@
|
|
|
3
3
|
"nodes": [
|
|
4
4
|
{
|
|
5
5
|
"config": {
|
|
6
|
-
"accountPath": "
|
|
7
|
-
"name": "
|
|
6
|
+
"accountPath": "1",
|
|
7
|
+
"name": "Chain",
|
|
8
8
|
"schema": "network.xyo.node.config"
|
|
9
9
|
},
|
|
10
10
|
"modules": {
|
|
11
|
-
"private": [
|
|
12
|
-
"public": [
|
|
11
|
+
"private": [
|
|
13
12
|
{
|
|
14
13
|
"config": {
|
|
15
|
-
"accountPath": "
|
|
16
|
-
"name": "
|
|
14
|
+
"accountPath": "1/1'/1'",
|
|
15
|
+
"name": "Validated",
|
|
17
16
|
"getCache": {
|
|
18
17
|
"enabled": true,
|
|
19
18
|
"maxEntries": 5000
|
|
20
19
|
},
|
|
21
|
-
"labels": {
|
|
22
|
-
"network.xyo.storage.class": "mongodb"
|
|
23
|
-
},
|
|
24
20
|
"payloadSdkConfig": {
|
|
25
|
-
"collection": "
|
|
21
|
+
"collection": "chain_validated"
|
|
26
22
|
},
|
|
27
23
|
"schema": "network.xyo.archivist.config"
|
|
28
24
|
}
|
|
29
|
-
}
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"public": [
|
|
30
28
|
{
|
|
31
29
|
"config": {
|
|
32
|
-
"accountPath": "
|
|
33
|
-
"name": "
|
|
30
|
+
"accountPath": "1/1/1",
|
|
31
|
+
"name": "Finalized",
|
|
32
|
+
"allowedQueries": [
|
|
33
|
+
"network.xyo.query.archivist.get",
|
|
34
|
+
"network.xyo.query.archivist.next"
|
|
35
|
+
],
|
|
34
36
|
"getCache": {
|
|
35
37
|
"enabled": true,
|
|
36
|
-
"maxEntries":
|
|
37
|
-
},
|
|
38
|
-
"payloadSdkConfig": {
|
|
39
|
-
"collection": "pending_block_bundles"
|
|
38
|
+
"maxEntries": 50000
|
|
40
39
|
},
|
|
41
|
-
"
|
|
40
|
+
"originArchivist": "Validated",
|
|
41
|
+
"schema": "network.xyo.archivist.view.config"
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
]
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
{
|
|
14
14
|
"config": {
|
|
15
15
|
"accountPath": "2/1/1",
|
|
16
|
-
"name": "
|
|
16
|
+
"name": "Transactions",
|
|
17
17
|
"getCache": {
|
|
18
18
|
"enabled": true,
|
|
19
19
|
"maxEntries": 5000
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
{
|
|
31
31
|
"config": {
|
|
32
32
|
"accountPath": "2/1/2",
|
|
33
|
-
"name": "
|
|
33
|
+
"name": "Blocks",
|
|
34
34
|
"getCache": {
|
|
35
35
|
"enabled": true,
|
|
36
36
|
"maxEntries": 5000
|
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { ModuleManifest, PackageManifestPayload } from '@xyo-network/manifest-model'
|
|
2
|
+
|
|
3
|
+
import Chain from './Chain.json' with { type: 'json' }
|
|
4
|
+
import Pending from './Pending.json' with { type: 'json' }
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Chain Node Manifest
|
|
8
|
+
*/
|
|
9
|
+
const ChainNodeManifest = Chain as PackageManifestPayload
|
|
10
|
+
/**
|
|
11
|
+
* Pending Node Manifest
|
|
12
|
+
*/
|
|
13
|
+
const PendingNodeManifest = Pending as PackageManifestPayload
|
|
14
|
+
/**
|
|
15
|
+
* Public Child Manifests
|
|
16
|
+
*/
|
|
17
|
+
export const PublicChildManifests: ModuleManifest[] = [
|
|
18
|
+
...ChainNodeManifest.nodes,
|
|
19
|
+
...PendingNodeManifest.nodes,
|
|
20
|
+
]
|