@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
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@xyo-network/chain-orchestration",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.18.0",
|
|
5
5
|
"description": "XYO Layer One SDK Orchestration",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"!**/*.test.*"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@opentelemetry/api": "~1.9.0",
|
|
43
42
|
"@xylabs/mongo": "~5.0.51",
|
|
44
43
|
"@xylabs/sdk-js": "~5.0.51",
|
|
45
44
|
"@xyo-network/archivist-lmdb": "~5.2.17",
|
|
@@ -49,11 +48,10 @@
|
|
|
49
48
|
"@xyo-network/archivist-view": "~5.2.17",
|
|
50
49
|
"@xyo-network/bios": "~7.2.0",
|
|
51
50
|
"@xyo-network/bridge-model": "~5.2.17",
|
|
52
|
-
"@xyo-network/chain-protocol": "~1.
|
|
53
|
-
"@xyo-network/chain-sdk": "~1.
|
|
54
|
-
"@xyo-network/chain-
|
|
55
|
-
"@xyo-network/chain-
|
|
56
|
-
"@xyo-network/chain-utils": "~1.17.7",
|
|
51
|
+
"@xyo-network/chain-protocol": "~1.18.0",
|
|
52
|
+
"@xyo-network/chain-sdk": "~1.18.0",
|
|
53
|
+
"@xyo-network/chain-telemetry": "~1.18.0",
|
|
54
|
+
"@xyo-network/chain-utils": "~1.18.0",
|
|
57
55
|
"@xyo-network/manifest-wrapper": "~5.2.17",
|
|
58
56
|
"@xyo-network/module-abstract": "~5.2.17",
|
|
59
57
|
"@xyo-network/module-factory-locator": "~5.2.17",
|
|
@@ -63,16 +61,16 @@
|
|
|
63
61
|
"@xyo-network/typechain": "~4.0.11",
|
|
64
62
|
"@xyo-network/wallet": "~5.2.17",
|
|
65
63
|
"@xyo-network/xl1-protocol": "~1.14.17",
|
|
66
|
-
"@xyo-network/xl1-protocol-sdk": "~1.
|
|
64
|
+
"@xyo-network/xl1-protocol-sdk": "~1.18.0",
|
|
67
65
|
"async-mutex": "~0.5.0",
|
|
68
66
|
"ethers": "^6.16.0"
|
|
69
67
|
},
|
|
70
68
|
"devDependencies": {
|
|
71
|
-
"@types/node": "~25.0.
|
|
69
|
+
"@types/node": "~25.0.2",
|
|
72
70
|
"@xylabs/sdk-js": "~5.0.51",
|
|
73
71
|
"@xylabs/telemetry": "~5.0.51",
|
|
74
|
-
"@xylabs/ts-scripts-yarn3": "~7.2.
|
|
75
|
-
"@xylabs/tsconfig": "~7.2.
|
|
72
|
+
"@xylabs/ts-scripts-yarn3": "~7.2.32",
|
|
73
|
+
"@xylabs/tsconfig": "~7.2.32",
|
|
76
74
|
"@xyo-network/account-model": "~5.2.17",
|
|
77
75
|
"@xyo-network/bios-model": "~7.2.0",
|
|
78
76
|
"@xyo-network/manifest-model": "~5.2.17",
|
|
@@ -80,7 +78,7 @@
|
|
|
80
78
|
"@xyo-network/node-model": "~5.2.17",
|
|
81
79
|
"@xyo-network/payload-model": "~5.2.17",
|
|
82
80
|
"@xyo-network/wallet-model": "~5.2.17",
|
|
83
|
-
"eslint": "^9.39.
|
|
81
|
+
"eslint": "^9.39.2",
|
|
84
82
|
"typescript": "~5.9.3"
|
|
85
83
|
},
|
|
86
84
|
"engines": {
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { InitializableParams } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
1
|
+
import type { CreatableProviderContext } from '@xyo-network/xl1-protocol-sdk'
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export type ChainInitializableParams = InitializableParams<{
|
|
8
|
-
config: Config
|
|
9
|
-
meterProvider: MeterProvider
|
|
10
|
-
statusReporter: RuntimeStatusMonitor
|
|
11
|
-
traceProvider: TracerProvider
|
|
12
|
-
}>
|
|
3
|
+
export type ChainInitializableParams = CreatableProviderContext
|
package/src/actor/Actor.ts
CHANGED
|
@@ -3,13 +3,26 @@ import type {
|
|
|
3
3
|
} from '@xylabs/sdk-js'
|
|
4
4
|
import {
|
|
5
5
|
AbstractCreatable,
|
|
6
|
+
assertEx,
|
|
6
7
|
Base, creatable, delay, IdLogger,
|
|
7
8
|
} from '@xylabs/sdk-js'
|
|
8
|
-
import
|
|
9
|
+
import { AccountInstance } from '@xyo-network/account-model'
|
|
10
|
+
import {
|
|
11
|
+
type BaseContext, type Config,
|
|
12
|
+
getDefaultConfig,
|
|
13
|
+
ProviderFactoryLocator,
|
|
14
|
+
type ProviderFactoryLocatorInstance,
|
|
15
|
+
} from '@xyo-network/xl1-protocol-sdk'
|
|
9
16
|
import { Semaphore } from 'async-mutex'
|
|
10
17
|
|
|
11
|
-
export type
|
|
18
|
+
export type ActorContext = BaseContext & {
|
|
12
19
|
config: Config
|
|
20
|
+
locator: ProviderFactoryLocatorInstance
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type ActorParams<T extends EmptyObject | void = void> = CreatableParams & {
|
|
24
|
+
account: AccountInstance
|
|
25
|
+
context: ActorContext
|
|
13
26
|
displayName?: string
|
|
14
27
|
id: string
|
|
15
28
|
} & (T extends void ? EmptyObject : T)
|
|
@@ -34,6 +47,22 @@ export class Actor<TParams extends ActorParams = ActorParams> extends AbstractCr
|
|
|
34
47
|
return this.params.id
|
|
35
48
|
}
|
|
36
49
|
|
|
50
|
+
protected get account() {
|
|
51
|
+
return this.params.account!
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
protected get config() {
|
|
55
|
+
return this.context.config
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
protected get context() {
|
|
59
|
+
return this.params.context
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
protected get locator() {
|
|
63
|
+
return this.context.locator
|
|
64
|
+
}
|
|
65
|
+
|
|
37
66
|
protected get logPrefix() {
|
|
38
67
|
return `[${this.displayName} (${this.id})] `
|
|
39
68
|
}
|
|
@@ -42,11 +71,18 @@ export class Actor<TParams extends ActorParams = ActorParams> extends AbstractCr
|
|
|
42
71
|
const baseParams = await super.paramsHandler(params)
|
|
43
72
|
const id = params?.id ?? baseParams.name
|
|
44
73
|
const displayName = params?.displayName ?? baseParams.name
|
|
74
|
+
const account = assertEx(params?.account, () => `Account is required for actor ${id}.`)
|
|
75
|
+
const logger = baseParams.logger ?? new IdLogger(Base.defaultLogger ?? console, () => `[${displayName} (${id})] `)
|
|
76
|
+
const singletons = params?.context?.singletons ?? {}
|
|
77
|
+
const config = params?.context?.config ?? getDefaultConfig()
|
|
78
|
+
const context = params?.context ?? {
|
|
79
|
+
config,
|
|
80
|
+
locator: new ProviderFactoryLocator({
|
|
81
|
+
config, logger, singletons,
|
|
82
|
+
}),
|
|
83
|
+
}
|
|
45
84
|
return {
|
|
46
|
-
...baseParams,
|
|
47
|
-
displayName,
|
|
48
|
-
id,
|
|
49
|
-
logger: baseParams.logger ?? new IdLogger(Base.defaultLogger ?? console, () => `[${displayName} (${id})] `),
|
|
85
|
+
...baseParams, account, context, displayName, id, logger,
|
|
50
86
|
}
|
|
51
87
|
}
|
|
52
88
|
|
|
@@ -93,6 +129,7 @@ export class Actor<TParams extends ActorParams = ActorParams> extends AbstractCr
|
|
|
93
129
|
})
|
|
94
130
|
.catch((error) => {
|
|
95
131
|
this.logger?.error(`Error in timer '${this.name}:${timerName}': ${error}`)
|
|
132
|
+
this.logger?.error(error.stack)
|
|
96
133
|
})
|
|
97
134
|
.finally(() => {
|
|
98
135
|
release()
|
|
@@ -30,7 +30,7 @@ export class BalanceActor extends Actor<BalanceActorParams> {
|
|
|
30
30
|
if (this._updateMutex.isLocked()) return
|
|
31
31
|
await this._updateMutex.runExclusive(async () => {
|
|
32
32
|
const head = await this.blockViewer.currentBlockHash()
|
|
33
|
-
await this.balanceService.accountBalances([], head)
|
|
33
|
+
await this.balanceService.accountBalances([], { head })
|
|
34
34
|
})
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -1,107 +1,70 @@
|
|
|
1
1
|
import type { Hash } from '@xylabs/sdk-js'
|
|
2
2
|
import { assertEx, creatable } from '@xylabs/sdk-js'
|
|
3
|
+
import { AccountInstance } from '@xyo-network/account-model'
|
|
3
4
|
import { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
4
5
|
import { processPendingBlocks } from '@xyo-network/chain-sdk'
|
|
5
6
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
6
7
|
import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
|
|
7
|
-
import
|
|
8
|
+
import {
|
|
9
|
+
BlockViewer,
|
|
10
|
+
BlockViewerMoniker,
|
|
11
|
+
MempoolViewer, MempoolViewerMoniker,
|
|
12
|
+
} from '@xyo-network/xl1-protocol-sdk'
|
|
8
13
|
|
|
9
14
|
import { Actor, ActorParams } from './Actor.ts'
|
|
10
15
|
|
|
11
16
|
export type ValidatorActorParams = ActorParams<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
| 'mempoolViewer'
|
|
18
|
-
// | 'chainSubmissionsArchivistWrite'
|
|
19
|
-
// | 'pendingBundledTransactionsArchivistWrite'
|
|
20
|
-
// | 'stakeIntent'
|
|
21
|
-
> & {
|
|
22
|
-
config: Config
|
|
23
|
-
pendingBlocksArchivist: ArchivistInstance
|
|
17
|
+
{
|
|
18
|
+
account: AccountInstance
|
|
19
|
+
blockViewer?: BlockViewer
|
|
20
|
+
finalizedArchivist: ArchivistInstance
|
|
21
|
+
mempoolViewer?: MempoolViewer
|
|
24
22
|
}>
|
|
25
23
|
|
|
26
24
|
@creatable()
|
|
27
25
|
export class ValidatorActor extends Actor<ValidatorActorParams> {
|
|
26
|
+
protected _blockViewer: BlockViewer | undefined
|
|
28
27
|
protected _lastValidatedBlock: BlockBoundWitness | undefined
|
|
29
28
|
protected _lastValidatedBlockHash: Hash | undefined
|
|
30
|
-
|
|
31
|
-
protected get account() {
|
|
32
|
-
return assertEx(this.params.account, () => 'account not set')
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
protected get balanceService() {
|
|
36
|
-
return assertEx(this.params.balance, () => 'balanceService not set')
|
|
37
|
-
}
|
|
29
|
+
protected _mempoolViewer: MempoolViewer | undefined
|
|
38
30
|
|
|
39
31
|
protected get blockViewer() {
|
|
40
|
-
return
|
|
32
|
+
return this._blockViewer!
|
|
41
33
|
}
|
|
42
34
|
|
|
43
|
-
protected get
|
|
44
|
-
return assertEx(this.params.
|
|
35
|
+
protected get finalizedArchivist() {
|
|
36
|
+
return assertEx(this.params.finalizedArchivist, () => 'finalizedArchivist not set')
|
|
45
37
|
}
|
|
46
38
|
|
|
47
39
|
protected get mempoolViewer() {
|
|
48
|
-
return
|
|
40
|
+
return this._mempoolViewer!
|
|
49
41
|
}
|
|
50
42
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
43
|
+
override async createHandler() {
|
|
44
|
+
await super.createHandler()
|
|
54
45
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
46
|
+
this._blockViewer = assertEx(
|
|
47
|
+
this.params.blockViewer ?? await this.locator.getInstance<BlockViewer>(BlockViewerMoniker),
|
|
48
|
+
() => 'Unable to locate a BlockViewer',
|
|
49
|
+
)
|
|
58
50
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// return assertEx(this.params.stakeIntent, () => 'stakeIntentService not set')
|
|
65
|
-
// }
|
|
66
|
-
|
|
67
|
-
// protected get validator() {
|
|
68
|
-
// return assertEx(this.params.validator, () => 'validator not set')
|
|
69
|
-
// }
|
|
51
|
+
this._mempoolViewer = assertEx(
|
|
52
|
+
this.params.mempoolViewer ?? await this.locator.getInstance<MempoolViewer>(MempoolViewerMoniker),
|
|
53
|
+
() => 'Unable to locate a MempoolViewer',
|
|
54
|
+
)
|
|
55
|
+
}
|
|
70
56
|
|
|
71
57
|
override async startHandler(): Promise<void> {
|
|
72
58
|
await super.startHandler()
|
|
73
|
-
// Register a timer to check if we should produce a block
|
|
74
|
-
// this.registerTimer('BlockProductionTimer', async () => {
|
|
75
|
-
// await this.spanAsync('produceBlock', async () => {
|
|
76
|
-
// // Get the updated head
|
|
77
|
-
// const block = (await this.blockViewer.currentBlock())[0]
|
|
78
|
-
// if (isUndefined(block)) return
|
|
79
|
-
// // Check if we've already validated this head
|
|
80
|
-
// const hash = await PayloadBuilder.hash(block)
|
|
81
|
-
// // If our last validated block was this head, skip validation
|
|
82
|
-
// if (isDefined(this._lastValidatedBlock) && this._lastValidatedBlockHash === hash) {
|
|
83
|
-
// this.logger?.log('Block already validated:', `0x${toHex(block.block)}`)
|
|
84
|
-
// } else {
|
|
85
|
-
// this.logger?.log('Validating block:', `0x${toHex(block.block)}`)
|
|
86
|
-
// const valid = await this.validateBlock(block)
|
|
87
|
-
// if (valid) {
|
|
88
|
-
// this.logger?.log('Validated block:', `0x${toHex(block.block)}`)
|
|
89
|
-
// } else {
|
|
90
|
-
// this.logger?.log('Invalid block:', `0x${toHex(block.block)}`)
|
|
91
|
-
// await this.slashInvalidBlock(block)
|
|
92
|
-
// }
|
|
93
|
-
// }
|
|
94
|
-
// })
|
|
95
|
-
// }, 2000, 1500/* 500 */)
|
|
96
|
-
|
|
97
59
|
this.registerTimer('ValidatorActor', async () => {
|
|
98
60
|
await this.spanAsync('processPendingBlocks', async () => {
|
|
99
61
|
console.log('ValidatorActor: Processing pending blocks...')
|
|
100
62
|
await processPendingBlocks({
|
|
63
|
+
context: this.context,
|
|
101
64
|
logger: this.logger,
|
|
102
65
|
mempoolViewer: this.mempoolViewer,
|
|
103
66
|
blockViewer: this.blockViewer,
|
|
104
|
-
|
|
67
|
+
finalizedArchivist: this.finalizedArchivist,
|
|
105
68
|
})
|
|
106
69
|
})
|
|
107
70
|
}, 2000, 1500/* 500 */)
|
|
@@ -9,11 +9,11 @@ import { initLocalChainFinalizedArchivist } from './local.ts'
|
|
|
9
9
|
const mutex = new Mutex()
|
|
10
10
|
let singleton: ArchivistInstance | undefined
|
|
11
11
|
|
|
12
|
-
export async function initChainFinalizedArchivist(
|
|
12
|
+
export async function initChainFinalizedArchivist(context: ChainInitializableParams) {
|
|
13
13
|
return await mutex.runExclusive(async () => {
|
|
14
14
|
if (singleton) return singleton
|
|
15
|
-
return await timeBudget('initChainFinalizedArchivist', logger, async () => {
|
|
16
|
-
const local = await startupSpanAsync('ChainFinalizedArchivist:initLocal', () => initLocalChainFinalizedArchivist(
|
|
15
|
+
return await timeBudget('initChainFinalizedArchivist', context.logger, async () => {
|
|
16
|
+
const local = await startupSpanAsync('ChainFinalizedArchivist:initLocal', () => initLocalChainFinalizedArchivist(context))
|
|
17
17
|
singleton = local
|
|
18
18
|
return singleton
|
|
19
19
|
}, 2000, true)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
2
|
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import type {
|
|
3
|
+
import type { CreatableProviderContext } from '@xyo-network/xl1-protocol-sdk'
|
|
4
4
|
import { Mutex } from 'async-mutex'
|
|
5
5
|
|
|
6
6
|
import { getLocalPersistentArchivist } from '../lib/index.ts'
|
|
@@ -8,7 +8,7 @@ import { getLocalPersistentArchivist } from '../lib/index.ts'
|
|
|
8
8
|
const mutex = new Mutex()
|
|
9
9
|
let singleton: ArchivistInstance | undefined
|
|
10
10
|
|
|
11
|
-
export const initLocalChainFinalizedArchivist: Initializable<
|
|
11
|
+
export const initLocalChainFinalizedArchivist: Initializable<CreatableProviderContext, ArchivistInstance> = async ({ config }): Promise<ArchivistInstance> => {
|
|
12
12
|
return await mutex.runExclusive(async () => {
|
|
13
13
|
if (singleton) return singleton
|
|
14
14
|
const { root } = config.storage
|
|
@@ -9,11 +9,11 @@ import { initLocalPendingBlocksArchivist } from './local.ts'
|
|
|
9
9
|
const mutex = new Mutex()
|
|
10
10
|
let singleton: ArchivistInstance | undefined
|
|
11
11
|
|
|
12
|
-
export async function initPendingBlocksArchivist(
|
|
12
|
+
export async function initPendingBlocksArchivist(context: ChainInitializableParams) {
|
|
13
13
|
return await mutex.runExclusive(async () => {
|
|
14
14
|
if (singleton) return singleton
|
|
15
|
-
return await timeBudget('initPendingBlocksArchivist', logger, async () => {
|
|
16
|
-
const local = await startupSpanAsync('PendingBlocksArchivist:initLocal', () => initLocalPendingBlocksArchivist(
|
|
15
|
+
return await timeBudget('initPendingBlocksArchivist', context.logger, async () => {
|
|
16
|
+
const local = await startupSpanAsync('PendingBlocksArchivist:initLocal', () => initLocalPendingBlocksArchivist(context))
|
|
17
17
|
singleton = local
|
|
18
18
|
return singleton
|
|
19
19
|
}, 2000, true)
|
|
@@ -12,11 +12,11 @@ const mutex = new Mutex()
|
|
|
12
12
|
let singleton: ArchivistInstance | undefined
|
|
13
13
|
|
|
14
14
|
export const initStakeIntentStateArchivist: Initializable<ChainInitializableParams, ArchivistInstance>
|
|
15
|
-
= async (
|
|
15
|
+
= async (context: ChainInitializableParams): Promise<ArchivistInstance> => {
|
|
16
16
|
return await mutex.runExclusive(async () => {
|
|
17
17
|
if (singleton) return singleton
|
|
18
|
-
return await timeBudget('initStakeIntentStateArchivist',
|
|
19
|
-
const local = await startupSpanAsync('StakeIntentStateArchivist:initLocal', () => initLocalStakeIntentStateArchivist(
|
|
18
|
+
return await timeBudget('initStakeIntentStateArchivist', context.logger, async () => {
|
|
19
|
+
const local = await startupSpanAsync('StakeIntentStateArchivist:initLocal', () => initLocalStakeIntentStateArchivist(context))
|
|
20
20
|
singleton = local
|
|
21
21
|
return assertEx(singleton, () => 'StakeIntentStateArchivist is undefined')
|
|
22
22
|
}, 2000, true)
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/sdk-js'
|
|
2
2
|
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
3
|
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
4
|
-
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
5
4
|
import { Mutex } from 'async-mutex'
|
|
6
5
|
|
|
6
|
+
import type { ChainInitializableParams } from '../../ChainInitializableParams.ts'
|
|
7
7
|
import { getLocalPersistentArchivist } from '../lib/index.ts'
|
|
8
8
|
|
|
9
9
|
const mutex = new Mutex()
|
|
10
10
|
let singleton: ArchivistInstance | undefined
|
|
11
11
|
|
|
12
|
-
export const initLocalStakeIntentStateArchivist: Initializable<
|
|
12
|
+
export const initLocalStakeIntentStateArchivist: Initializable<ChainInitializableParams,
|
|
13
|
+
ArchivistInstance> = async ({ config }): Promise<ArchivistInstance> => {
|
|
13
14
|
return await mutex.runExclusive(async () => {
|
|
14
15
|
if (singleton) return singleton
|
|
15
16
|
const { root } = config.storage
|
package/src/archivists/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { AccountInstance } from '@xyo-network/account-model'
|
|
2
|
-
import { buildNextBlock
|
|
2
|
+
import { buildNextBlock } from '@xyo-network/chain-sdk'
|
|
3
3
|
import type { WithHashMeta } from '@xyo-network/payload-model'
|
|
4
4
|
import type { BlockBoundWitness, XL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
5
|
+
import { createDeclarationIntent } from '@xyo-network/xl1-protocol-sdk'
|
|
5
6
|
|
|
6
7
|
export async function createProducerChainStakeIntentBlock(prevBlock: WithHashMeta<BlockBoundWitness>, producerAccount: AccountInstance, range: XL1BlockRange) {
|
|
7
8
|
const producerDeclarationPayload = createDeclarationIntent(
|
|
@@ -6,9 +6,7 @@ import http from 'node:http'
|
|
|
6
6
|
import type { CreatableStatus, Logger } from '@xylabs/sdk-js'
|
|
7
7
|
import { isDefined } from '@xylabs/sdk-js'
|
|
8
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'
|
|
9
|
+
import type { Config, RuntimeStatusMonitor } from '@xyo-network/xl1-protocol-sdk'
|
|
12
10
|
|
|
13
11
|
const sendStatus = (res: ServerResponse, status: CreatableStatus, errorCode: number) => {
|
|
14
12
|
const statusCode = status === 'started' ? 200 : errorCode
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,6 @@ export * from './actor/index.ts'
|
|
|
2
2
|
export * from './archivists/index.ts'
|
|
3
3
|
export * from './buildTelemetryConfig.ts'
|
|
4
4
|
export * from './ChainInitializableParams.ts'
|
|
5
|
-
export * from './ConfigContext.ts'
|
|
6
5
|
export * from './createDeclarationIntentBlock.ts'
|
|
7
6
|
export * from './evm/index.ts'
|
|
8
7
|
export * from './health/index.ts'
|
|
@@ -10,4 +9,3 @@ export * from './host/index.ts'
|
|
|
10
9
|
export * from './init/index.ts'
|
|
11
10
|
export * from './manifest/index.ts'
|
|
12
11
|
export * from './orchestrator/index.ts'
|
|
13
|
-
export * from './status/index.ts'
|
package/src/init/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export * from './initBalanceSummaryMap.ts'
|
|
2
2
|
export * from './initBridgedModule.ts'
|
|
3
3
|
export * from './initChainStakeViewer.ts'
|
|
4
|
+
export * from './initFinalizedArchivist.ts'
|
|
4
5
|
export * from './initProducerAccount.ts'
|
|
5
6
|
export * from './initSeedPhrase.ts'
|
|
6
7
|
export * from './initServerNode.ts'
|
|
7
8
|
export * from './initServerWallet.ts'
|
|
8
9
|
export * from './initStatusReporter.ts'
|
|
9
10
|
export * from './initTransferSummaryMap.ts'
|
|
10
|
-
export * from './iterator.ts'
|
|
@@ -2,41 +2,55 @@ import {
|
|
|
2
2
|
asAddress,
|
|
3
3
|
assertEx, type Logger, toAddress, toEthAddress,
|
|
4
4
|
} from '@xylabs/sdk-js'
|
|
5
|
-
import {
|
|
5
|
+
import type { EthereumChainStakeEventsParams, EthereumChainStakeViewerParams } from '@xyo-network/chain-sdk'
|
|
6
|
+
import { EthereumChainStakeEventsViewer, EthereumChainStakeViewer } from '@xyo-network/chain-sdk'
|
|
6
7
|
import { StakedXyoChainV2__factory } from '@xyo-network/typechain'
|
|
7
8
|
import type { ChainId } from '@xyo-network/xl1-protocol'
|
|
8
|
-
import {
|
|
9
|
-
|
|
9
|
+
import type {
|
|
10
|
+
Config,
|
|
11
|
+
CreatableProviderContext, StakeViewer,
|
|
10
12
|
} from '@xyo-network/xl1-protocol-sdk'
|
|
13
|
+
import { SimpleStakeViewer } from '@xyo-network/xl1-protocol-sdk'
|
|
11
14
|
|
|
12
15
|
import { canUseEvmProvider, initEvmProvider } from '../evm/index.ts'
|
|
13
16
|
|
|
14
|
-
export async function initEvmChainStakeViewer(config: Config, logger?: Logger): Promise<StakeViewer> {
|
|
17
|
+
export async function initEvmChainStakeViewer(context: CreatableProviderContext, config: Config, logger?: Logger): Promise<StakeViewer> {
|
|
15
18
|
const provider = await initEvmProvider({ config, logger })
|
|
16
19
|
const contractAddress = assertEx(config.chain.id, () => 'Missing config.evm.chainId') as ChainId
|
|
17
20
|
const contract = StakedXyoChainV2__factory.connect(toEthAddress(contractAddress), provider)
|
|
18
|
-
const stakeEventsViewer = await
|
|
21
|
+
const stakeEventsViewer = await EthereumChainStakeEventsViewer.create({
|
|
22
|
+
contract, logger, context,
|
|
23
|
+
} satisfies EthereumChainStakeEventsParams)
|
|
19
24
|
assertEx(await stakeEventsViewer.start(), () => 'Failed to start EthereumChainStakeEvents reader')
|
|
20
25
|
const stakeChainViewer = await EthereumChainStakeViewer.create({
|
|
21
|
-
contract, stakeEventsViewer, logger,
|
|
22
|
-
})
|
|
26
|
+
contract, stakeEventsViewer, logger, context,
|
|
27
|
+
} satisfies EthereumChainStakeViewerParams)
|
|
23
28
|
assertEx(await stakeChainViewer.start(), () => 'Failed to start EthereumChainStake viewer')
|
|
24
29
|
return stakeChainViewer
|
|
25
30
|
}
|
|
26
31
|
|
|
27
|
-
export async function initSimpleStakeViewer(config: Config, logger?: Logger): Promise<StakeViewer> {
|
|
28
|
-
const
|
|
29
|
-
|
|
32
|
+
export async function initSimpleStakeViewer(context: CreatableProviderContext, config: Config, logger?: Logger): Promise<StakeViewer> {
|
|
33
|
+
const stakeViewer = await SimpleStakeViewer.create({
|
|
34
|
+
context,
|
|
35
|
+
chainId: asAddress(toAddress(1n), true),
|
|
36
|
+
logger,
|
|
37
|
+
positions: [],
|
|
30
38
|
})
|
|
31
|
-
assertEx(await
|
|
32
|
-
return
|
|
39
|
+
assertEx(await stakeViewer.start(), () => 'Failed to start SimpleChainStake viewer')
|
|
40
|
+
return stakeViewer
|
|
33
41
|
}
|
|
34
42
|
|
|
35
|
-
export async function initStakeViewer({
|
|
43
|
+
export async function initStakeViewer({
|
|
44
|
+
config, logger, context,
|
|
45
|
+
}: {
|
|
46
|
+
config: Config
|
|
47
|
+
context: CreatableProviderContext
|
|
48
|
+
logger?: Logger
|
|
49
|
+
}): Promise<StakeViewer> {
|
|
36
50
|
if (canUseEvmProvider({ config })) {
|
|
37
|
-
return await initEvmChainStakeViewer(config, logger)
|
|
51
|
+
return await initEvmChainStakeViewer(context, config, logger)
|
|
38
52
|
} else {
|
|
39
53
|
console.warn('[API] Infura configuration not found. Using SimpleChainStakeViewer with no positions. This means no staking data will be available.')
|
|
40
|
-
return await initSimpleStakeViewer(config, logger)
|
|
54
|
+
return await initSimpleStakeViewer(context, config, logger)
|
|
41
55
|
}
|
|
42
56
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MongoDBArchivistV2 } from '@xyo-network/archivist-mongodb'
|
|
2
|
+
import type { MongoDBModuleParamsV2 } from '@xyo-network/module-model-mongodb'
|
|
3
|
+
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
+
|
|
5
|
+
async function initMongoFinalizedArchivist(config: Config) {
|
|
6
|
+
const payloadSdkConfig = {
|
|
7
|
+
...config.storage.mongo,
|
|
8
|
+
collection: 'chain_validated',
|
|
9
|
+
} satisfies MongoDBModuleParamsV2['payloadSdkConfig']
|
|
10
|
+
return await MongoDBArchivistV2.create({ payloadSdkConfig })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function initFinalizedArchivist(config: Config) {
|
|
14
|
+
const finalizedArchivist = await initMongoFinalizedArchivist(config)
|
|
15
|
+
return finalizedArchivist
|
|
16
|
+
}
|
|
@@ -49,6 +49,7 @@ export async function initServerNode({
|
|
|
49
49
|
const node: NodeInstance = providedNode ?? await loadNode({
|
|
50
50
|
wallet, logger, config, transfersSummaryMap, balancesSummaryMap,
|
|
51
51
|
})
|
|
52
|
+
assertEx(await node.start(), () => 'Failed to start node')
|
|
52
53
|
const writableChainArchivist = await writableChainArchivistFromNode(node)
|
|
53
54
|
const readonlyChainArchivist = await readonlyChainArchivistFromNode(node)
|
|
54
55
|
const pendingTransactionsArchivist = await pendingTransactionsArchivistFromNode(node)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Logger } from '@xylabs/sdk-js'
|
|
2
|
-
|
|
3
|
-
import { RuntimeStatusMonitor } from '../status/index.ts'
|
|
2
|
+
import { RuntimeStatusMonitor } from '@xyo-network/xl1-protocol-sdk'
|
|
4
3
|
|
|
5
4
|
export function initStatusReporter({ logger }: { logger: Logger }) {
|
|
6
5
|
const statusReporter = new RuntimeStatusMonitor(logger)
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model';
|
|
2
|
-
import type { ChainInitializableParams } from '../../ChainInitializableParams.ts';
|
|
3
|
-
export declare function initPendingTransactionsArchivist({ config, logger }: ChainInitializableParams): Promise<ArchivistInstance<import("@xyo-network/archivist-model").ArchivistParams<import("@xyo-network/module-model").AnyConfigSchema<import("@xyo-network/archivist-model").ArchivistConfig>>, import("@xyo-network/archivist-model").ArchivistModuleEventData, import("@xyo-network/payload-model").Payload>>;
|
|
4
|
-
//# sourceMappingURL=archivist.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"archivist.d.ts","sourceRoot":"","sources":["../../../../src/archivists/PendingTransactions/archivist.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAKrE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAA;AAMjF,wBAAsB,gCAAgC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,wBAAwB,kTASlG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/archivists/PendingTransactions/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
|
@@ -1,7 +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
|
-
export declare const initLocalPendingTransactionsArchivist: Initializable<{
|
|
5
|
-
config: Config;
|
|
6
|
-
}, ArchivistInstance>;
|
|
7
|
-
//# sourceMappingURL=local.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../../../src/archivists/PendingTransactions/local.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAQ3D,eAAO,MAAM,qCAAqC,EAAE,aAAa,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,iBAAiB,CAOtG,CAAA"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type BaseElectionServicesParams, type XyoChainIteratorParams, type XyoStakeIntentServiceParams } from '@xyo-network/chain-services';
|
|
2
|
-
import type { Initializable } from '@xyo-network/xl1-protocol';
|
|
3
|
-
import type { BlockViewer, ElectionService, StakeIntentService } from '@xyo-network/xl1-protocol-sdk';
|
|
4
|
-
export declare const initChainIterator: Initializable<XyoChainIteratorParams, BlockViewer>;
|
|
5
|
-
export declare const initStakeIntentService: Initializable<XyoStakeIntentServiceParams, StakeIntentService>;
|
|
6
|
-
export declare const initElectionService: Initializable<BaseElectionServicesParams, ElectionService>;
|
|
7
|
-
//# sourceMappingURL=iterator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iterator.d.ts","sourceRoot":"","sources":["../../../src/init/iterator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,0BAA0B,EAE/B,KAAK,sBAAsB,EAAyB,KAAK,2BAA2B,EACrF,MAAM,6BAA6B,CAAA;AACpC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EAAE,kBAAkB,EACpC,MAAM,+BAA+B,CAAA;AAOtC,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,sBAAsB,EAAE,WAAW,CAMhF,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,aAAa,CAAC,2BAA2B,EAAE,kBAAkB,CAO/F,CAAA;AAEH,eAAO,MAAM,mBAAmB,EAAE,aAAa,CAAC,0BAA0B,EAAE,eAAe,CAOxF,CAAA"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { CreatableName, CreatableStatus } from '@xylabs/sdk-js';
|
|
2
|
-
import { LoggerStatusReporter } from './ServiceStatus.ts';
|
|
3
|
-
export type GlobalTransitionHandler = {
|
|
4
|
-
from?: CreatableStatus;
|
|
5
|
-
handler: (from: CreatableStatus, to: CreatableStatus) => void;
|
|
6
|
-
to?: CreatableStatus;
|
|
7
|
-
};
|
|
8
|
-
export type TransitionHandler = GlobalTransitionHandler & {
|
|
9
|
-
name?: string;
|
|
10
|
-
};
|
|
11
|
-
export declare class RuntimeStatusMonitor extends LoggerStatusReporter {
|
|
12
|
-
private globalTransitions;
|
|
13
|
-
private transitions;
|
|
14
|
-
getGlobalStatus(): CreatableStatus;
|
|
15
|
-
getStatus(name: CreatableName): CreatableStatus | undefined;
|
|
16
|
-
onGlobalTransition(match: {
|
|
17
|
-
from?: CreatableStatus;
|
|
18
|
-
to?: CreatableStatus;
|
|
19
|
-
}, handler: (from: CreatableStatus, to: CreatableStatus) => void): void;
|
|
20
|
-
/**
|
|
21
|
-
* Register a callback to be called on a specific transition.
|
|
22
|
-
*/
|
|
23
|
-
onTransition(match: {
|
|
24
|
-
from?: CreatableStatus;
|
|
25
|
-
name: string;
|
|
26
|
-
to?: CreatableStatus;
|
|
27
|
-
}, handler: (from: CreatableStatus, to: CreatableStatus) => void): void;
|
|
28
|
-
report(name: CreatableName, status: CreatableStatus, progress?: number | Error): void;
|
|
29
|
-
private runTransitions;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=RuntimeStatusMonitor.d.ts.map
|