@xyo-network/chain-orchestration 1.17.7 → 1.18.0
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 +2 -10
- package/dist/neutral/ChainInitializableParams.d.ts.map +1 -1
- package/dist/neutral/actor/Actor.d.ts +205 -2
- package/dist/neutral/actor/Actor.d.ts.map +1 -1
- package/dist/neutral/actor/ValidatorActor.d.ts +13 -10
- package/dist/neutral/actor/ValidatorActor.d.ts.map +1 -1
- package/dist/neutral/archivists/ChainFinalized/archivist.d.ts +1 -1
- package/dist/neutral/archivists/ChainFinalized/archivist.d.ts.map +1 -1
- package/dist/neutral/archivists/ChainFinalized/local.d.ts +2 -4
- package/dist/neutral/archivists/ChainFinalized/local.d.ts.map +1 -1
- package/dist/neutral/archivists/PendingBlocks/archivist.d.ts +1 -1
- package/dist/neutral/archivists/PendingBlocks/archivist.d.ts.map +1 -1
- package/dist/neutral/archivists/StakeIntentState/local.d.ts +2 -4
- package/dist/neutral/archivists/StakeIntentState/local.d.ts.map +1 -1
- package/dist/neutral/archivists/index.d.ts +0 -1
- package/dist/neutral/archivists/index.d.ts.map +1 -1
- package/dist/neutral/createDeclarationIntentBlock.d.ts.map +1 -1
- package/dist/neutral/health/initHealthEndpoints.d.ts +1 -2
- package/dist/neutral/health/initHealthEndpoints.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +0 -2
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +156 -279
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/init/index.d.ts +1 -1
- package/dist/neutral/init/index.d.ts.map +1 -1
- package/dist/neutral/init/initChainStakeViewer.d.ts +5 -4
- package/dist/neutral/init/initChainStakeViewer.d.ts.map +1 -1
- package/dist/neutral/init/initFinalizedArchivist.d.ts +4 -0
- package/dist/neutral/init/initFinalizedArchivist.d.ts.map +1 -0
- package/dist/neutral/init/initServerNode.d.ts.map +1 -1
- package/dist/neutral/init/initStatusReporter.d.ts +1 -1
- package/dist/neutral/init/initStatusReporter.d.ts.map +1 -1
- package/package.json +10 -12
- package/src/ChainInitializableParams.ts +2 -11
- package/src/actor/Actor.ts +43 -6
- package/src/actor/BalanceActor.ts +1 -1
- package/src/actor/ValidatorActor.ts +30 -67
- package/src/archivists/ChainFinalized/archivist.ts +3 -3
- package/src/archivists/ChainFinalized/local.ts +2 -2
- package/src/archivists/PendingBlocks/archivist.ts +3 -3
- package/src/archivists/StakeIntentState/archivist.ts +3 -3
- package/src/archivists/StakeIntentState/local.ts +3 -2
- package/src/archivists/index.ts +0 -1
- package/src/createDeclarationIntentBlock.ts +2 -1
- package/src/health/initHealthEndpoints.ts +1 -3
- package/src/index.ts +0 -2
- package/src/init/index.ts +1 -1
- package/src/init/initChainStakeViewer.ts +29 -15
- package/src/init/initFinalizedArchivist.ts +16 -0
- package/src/init/initServerNode.ts +1 -0
- package/src/init/initStatusReporter.ts +1 -2
- package/dist/neutral/archivists/PendingTransactions/archivist.d.ts +0 -4
- package/dist/neutral/archivists/PendingTransactions/archivist.d.ts.map +0 -1
- package/dist/neutral/archivists/PendingTransactions/index.d.ts +0 -2
- package/dist/neutral/archivists/PendingTransactions/index.d.ts.map +0 -1
- package/dist/neutral/archivists/PendingTransactions/local.d.ts +0 -7
- package/dist/neutral/archivists/PendingTransactions/local.d.ts.map +0 -1
- package/dist/neutral/init/iterator.d.ts +0 -7
- package/dist/neutral/init/iterator.d.ts.map +0 -1
- package/dist/neutral/status/RuntimeStatusMonitor.d.ts +0 -31
- package/dist/neutral/status/RuntimeStatusMonitor.d.ts.map +0 -1
- package/dist/neutral/status/ServiceStatus.d.ts +0 -8
- package/dist/neutral/status/ServiceStatus.d.ts.map +0 -1
- package/dist/neutral/status/index.d.ts +0 -3
- package/dist/neutral/status/index.d.ts.map +0 -1
- package/src/archivists/PendingTransactions/archivist.ts +0 -21
- package/src/archivists/PendingTransactions/index.ts +0 -1
- package/src/archivists/PendingTransactions/local.ts +0 -18
- package/src/init/iterator.ts +0 -42
- package/src/status/RuntimeStatusMonitor.ts +0 -117
- package/src/status/ServiceStatus.ts +0 -20
- package/src/status/index.ts +0 -2
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RuntimeStatusMonitor.d.ts","sourceRoot":"","sources":["../../../src/status/RuntimeStatusMonitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AA8CzD,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,CAAC,EAAE,eAAe,CAAA;IACtB,OAAO,EAAE,CAAC,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,eAAe,KAAK,IAAI,CAAA;IAC7D,EAAE,CAAC,EAAE,eAAe,CAAA;CACrB,CAAA;AACD,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,GAAG;IACxD,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED,qBAAa,oBAAqB,SAAQ,oBAAoB;IAC5D,OAAO,CAAC,iBAAiB,CAAgC;IACzD,OAAO,CAAC,WAAW,CAA0B;IAE7C,eAAe,IAAI,eAAe;IAMlC,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,eAAe,GAAG,SAAS;IAI3D,kBAAkB,CAAC,KAAK,EAAE;QAAE,IAAI,CAAC,EAAE,eAAe,CAAC;QAAC,EAAE,CAAC,EAAE,eAAe,CAAA;KAAE,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,eAAe,KAAK,IAAI;IAIzI;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE;QAAE,IAAI,CAAC,EAAE,eAAe,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,eAAe,CAAA;KAAE,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,eAAe,KAAK,IAAI;IAIxI,MAAM,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAkB9F,OAAO,CAAC,cAAc;CAgBvB"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { CreatableName, CreatableStatus, CreatableStatusReporter, Logger } from '@xylabs/sdk-js';
|
|
2
|
-
export declare class LoggerStatusReporter implements CreatableStatusReporter {
|
|
3
|
-
protected logger: Logger;
|
|
4
|
-
protected statusMap: Record<CreatableName, CreatableStatus>;
|
|
5
|
-
constructor(logger: Logger);
|
|
6
|
-
report(name: CreatableName, status: CreatableStatus, progress?: number | Error): void;
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=ServiceStatus.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceStatus.d.ts","sourceRoot":"","sources":["../../../src/status/ServiceStatus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,EAChE,MAAM,gBAAgB,CAAA;AAEvB,qBAAa,oBAAqB,YAAW,uBAAuB;IAClE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAA;IAExB,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC,aAAa,EAAE,eAAe,CAAC,CAAK;gBAEpD,MAAM,EAAE,MAAM;IAI1B,MAAM,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;CAMtF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/status/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
|
-
import { startupSpanAsync } from '@xyo-network/chain-utils'
|
|
3
|
-
import { timeBudget } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
import { Mutex } from 'async-mutex'
|
|
5
|
-
|
|
6
|
-
import type { ChainInitializableParams } from '../../ChainInitializableParams.ts'
|
|
7
|
-
import { initLocalPendingTransactionsArchivist } from './local.ts'
|
|
8
|
-
|
|
9
|
-
const mutex = new Mutex()
|
|
10
|
-
let singleton: ArchivistInstance | undefined
|
|
11
|
-
|
|
12
|
-
export async function initPendingTransactionsArchivist({ config, logger }: ChainInitializableParams) {
|
|
13
|
-
return await mutex.runExclusive(async () => {
|
|
14
|
-
if (singleton) return singleton
|
|
15
|
-
return await timeBudget('initPendingTransactionsArchivist', logger, async () => {
|
|
16
|
-
const local = await startupSpanAsync('PendingTransactionsArchivist:initLocal', () => initLocalPendingTransactionsArchivist({ config, logger }))
|
|
17
|
-
singleton = local
|
|
18
|
-
return singleton
|
|
19
|
-
}, 2000, true)
|
|
20
|
-
})
|
|
21
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './archivist.ts'
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
|
-
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
import { Mutex } from 'async-mutex'
|
|
5
|
-
|
|
6
|
-
import { getLocalPersistentArchivist } from '../lib/index.ts'
|
|
7
|
-
|
|
8
|
-
const mutex = new Mutex()
|
|
9
|
-
let singleton: ArchivistInstance | undefined
|
|
10
|
-
|
|
11
|
-
export const initLocalPendingTransactionsArchivist: Initializable<{ config: Config }, ArchivistInstance> = async ({ config }): Promise<ArchivistInstance> => {
|
|
12
|
-
return await mutex.runExclusive(async () => {
|
|
13
|
-
if (singleton) return singleton
|
|
14
|
-
const { root } = config.storage
|
|
15
|
-
singleton = await getLocalPersistentArchivist('local-pending-transactions', 'chain', 'pending_transaction_bundles', root)
|
|
16
|
-
return singleton
|
|
17
|
-
})
|
|
18
|
-
}
|
package/src/init/iterator.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseElectionService,
|
|
3
|
-
type BaseElectionServicesParams,
|
|
4
|
-
ChainBlockNumberIterationService,
|
|
5
|
-
type XyoChainIteratorParams, XyoStakeIntentService, type XyoStakeIntentServiceParams,
|
|
6
|
-
} from '@xyo-network/chain-services'
|
|
7
|
-
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
8
|
-
import type {
|
|
9
|
-
BlockViewer,
|
|
10
|
-
ElectionService, StakeIntentService,
|
|
11
|
-
} from '@xyo-network/xl1-protocol-sdk'
|
|
12
|
-
import { timeBudget } from '@xyo-network/xl1-protocol-sdk'
|
|
13
|
-
|
|
14
|
-
let chainIteratorServiceSingleton: Promise<BlockViewer> | undefined
|
|
15
|
-
let stakeIntentServiceSingleton: Promise<StakeIntentService> | undefined
|
|
16
|
-
let electionServiceSingleton: Promise<ElectionService> | undefined
|
|
17
|
-
|
|
18
|
-
export const initChainIterator: Initializable<XyoChainIteratorParams, BlockViewer> = (params) => {
|
|
19
|
-
if (chainIteratorServiceSingleton) return chainIteratorServiceSingleton
|
|
20
|
-
return timeBudget('initChainIterator', params.logger, () => {
|
|
21
|
-
chainIteratorServiceSingleton = ChainBlockNumberIterationService.create(params)
|
|
22
|
-
return chainIteratorServiceSingleton
|
|
23
|
-
}, 2000, true)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const initStakeIntentService: Initializable<XyoStakeIntentServiceParams, StakeIntentService>
|
|
27
|
-
= (params) => {
|
|
28
|
-
if (stakeIntentServiceSingleton) return stakeIntentServiceSingleton
|
|
29
|
-
return timeBudget('initStakeIntentService', params.logger, () => {
|
|
30
|
-
stakeIntentServiceSingleton = XyoStakeIntentService.create(params)
|
|
31
|
-
return stakeIntentServiceSingleton
|
|
32
|
-
}, 2000, true)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const initElectionService: Initializable<BaseElectionServicesParams, ElectionService>
|
|
36
|
-
= (params) => {
|
|
37
|
-
if (electionServiceSingleton) return electionServiceSingleton
|
|
38
|
-
return timeBudget('initElectionService', params.logger, () => {
|
|
39
|
-
electionServiceSingleton = BaseElectionService.create(params)
|
|
40
|
-
return electionServiceSingleton
|
|
41
|
-
}, 2000, true)
|
|
42
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import type { CreatableName, CreatableStatus } from '@xylabs/sdk-js'
|
|
2
|
-
|
|
3
|
-
import { LoggerStatusReporter } from './ServiceStatus.ts'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Enum-like record for statuses with priority allowing
|
|
7
|
-
* for determination of the aggregated status.
|
|
8
|
-
*/
|
|
9
|
-
const statusPriority: Record<CreatableStatus, number> = {
|
|
10
|
-
error: 0,
|
|
11
|
-
stopped: 1,
|
|
12
|
-
stopping: 2,
|
|
13
|
-
creating: 3,
|
|
14
|
-
created: 4,
|
|
15
|
-
starting: 5,
|
|
16
|
-
started: 6,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A sentinel status that represents the initial state
|
|
21
|
-
* before any statuses are reported.
|
|
22
|
-
* It is used to ensure that the monitor has a valid status
|
|
23
|
-
* even when no statuses have been reported yet and to
|
|
24
|
-
* prevent the system from showing an "error" state
|
|
25
|
-
* when no statuses are available.
|
|
26
|
-
*/
|
|
27
|
-
const SENTINEL_STATUS: CreatableStatus = 'starting'
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Given an array of statuses, this function reduces them
|
|
31
|
-
* to the minimum status based on the defined priority.
|
|
32
|
-
* @param statuses An array of statuses to reduce.
|
|
33
|
-
* @returns The minimum status based on priority.
|
|
34
|
-
*/
|
|
35
|
-
const reduceToMinimumStatus = (statuses: CreatableStatus[]): CreatableStatus => {
|
|
36
|
-
let minStatus: CreatableStatus = SENTINEL_STATUS
|
|
37
|
-
let minPriority = Infinity
|
|
38
|
-
|
|
39
|
-
for (const status of statuses) {
|
|
40
|
-
const priority = statusPriority[status]
|
|
41
|
-
if (priority < minPriority) {
|
|
42
|
-
minPriority = priority
|
|
43
|
-
minStatus = status
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return minStatus
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export type GlobalTransitionHandler = {
|
|
50
|
-
from?: CreatableStatus
|
|
51
|
-
handler: (from: CreatableStatus, to: CreatableStatus) => void
|
|
52
|
-
to?: CreatableStatus
|
|
53
|
-
}
|
|
54
|
-
export type TransitionHandler = GlobalTransitionHandler & {
|
|
55
|
-
name?: string
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export class RuntimeStatusMonitor extends LoggerStatusReporter {
|
|
59
|
-
private globalTransitions: GlobalTransitionHandler[] = []
|
|
60
|
-
private transitions: TransitionHandler[] = []
|
|
61
|
-
|
|
62
|
-
getGlobalStatus(): CreatableStatus {
|
|
63
|
-
// If no statuses have been reported, return the sentinel status
|
|
64
|
-
if (Object.keys(this.statusMap).length === 0) return SENTINEL_STATUS
|
|
65
|
-
return reduceToMinimumStatus(Object.values(this.statusMap))
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
getStatus(name: CreatableName): CreatableStatus | undefined {
|
|
69
|
-
return this.statusMap[name]
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
onGlobalTransition(match: { from?: CreatableStatus; to?: CreatableStatus }, handler: (from: CreatableStatus, to: CreatableStatus) => void) {
|
|
73
|
-
this.globalTransitions.push({ ...match, handler })
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Register a callback to be called on a specific transition.
|
|
78
|
-
*/
|
|
79
|
-
onTransition(match: { from?: CreatableStatus; name: string; to?: CreatableStatus }, handler: (from: CreatableStatus, to: CreatableStatus) => void) {
|
|
80
|
-
this.transitions.push({ ...match, handler })
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
override report(name: CreatableName, status: CreatableStatus, progress?: number | Error): void {
|
|
84
|
-
// Capture the current status before updating
|
|
85
|
-
const previous = this.statusMap[name]
|
|
86
|
-
const previousGlobal = this.getGlobalStatus()
|
|
87
|
-
|
|
88
|
-
// Update the status map with the new status
|
|
89
|
-
super.report(name, status, progress)
|
|
90
|
-
|
|
91
|
-
// If the status hasn't changed, do not run handlers
|
|
92
|
-
if (previous === status) return
|
|
93
|
-
this.runTransitions(this.transitions, previous, status, name)
|
|
94
|
-
|
|
95
|
-
// If the global status hasn't changed, do not run handlers
|
|
96
|
-
const globalStatus = this.getGlobalStatus()
|
|
97
|
-
if (previousGlobal === globalStatus) return
|
|
98
|
-
this.runTransitions(this.globalTransitions, previousGlobal, globalStatus)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
private runTransitions(
|
|
102
|
-
transitions: (TransitionHandler | GlobalTransitionHandler)[],
|
|
103
|
-
prev: CreatableStatus,
|
|
104
|
-
next: CreatableStatus,
|
|
105
|
-
name?: string,
|
|
106
|
-
) {
|
|
107
|
-
for (const {
|
|
108
|
-
from, to, name: matchName, handler,
|
|
109
|
-
} of transitions as TransitionHandler[]) {
|
|
110
|
-
if ((matchName === undefined || matchName === name)
|
|
111
|
-
&& (from === undefined || from === prev)
|
|
112
|
-
&& (to === undefined || to === next)) {
|
|
113
|
-
handler(prev, next)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CreatableName, CreatableStatus, CreatableStatusReporter, Logger,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
|
|
5
|
-
export class LoggerStatusReporter implements CreatableStatusReporter {
|
|
6
|
-
protected logger: Logger
|
|
7
|
-
|
|
8
|
-
protected statusMap: Record<CreatableName, CreatableStatus> = {}
|
|
9
|
-
|
|
10
|
-
constructor(logger: Logger) {
|
|
11
|
-
this.logger = logger
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
report(name: CreatableName, status: CreatableStatus, progress?: number | Error): void {
|
|
15
|
-
this.statusMap[name] = status
|
|
16
|
-
const starting = (Object.entries(this.statusMap).map(([, value]): number => value === 'starting' ? 1 : 0)).reduce((a, b) => a + b, 0)
|
|
17
|
-
const started = (Object.entries(this.statusMap).map(([, value]): number => value === 'started' ? 1 : 0)).reduce((a, b) => a + b, 0)
|
|
18
|
-
this.logger.info(`${started}/${starting + started} ${name} status: ${status}`, { progress })
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/status/index.ts
DELETED