@xyo-network/xl1-cli-lib 1.16.26 → 1.17.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/node/commands/producer/runProducer.d.ts +1 -1
- package/dist/node/commands/producer/runProducer.d.ts.map +1 -1
- package/dist/node/commands/validator/runValidator.d.ts.map +1 -1
- package/dist/node/index.mjs +345 -509
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/orchestration/actor/implementation/BalanceActor.d.ts +2 -2
- package/dist/node/orchestration/actor/implementation/BalanceActor.d.ts.map +1 -1
- package/dist/node/orchestration/actor/implementation/ProducerActor.d.ts +2 -2
- package/dist/node/orchestration/actor/implementation/ProducerActor.d.ts.map +1 -1
- package/dist/node/orchestration/actor/implementation/ValidatorActor.d.ts +2 -2
- package/dist/node/orchestration/actor/implementation/ValidatorActor.d.ts.map +1 -1
- package/dist/node/orchestration/actor/implementation/index.d.ts +0 -1
- package/dist/node/orchestration/actor/implementation/index.d.ts.map +1 -1
- package/dist/node/orchestration/initServices.d.ts.map +1 -1
- package/dist/node/orchestration/services/implementation/accountBalance.d.ts +0 -2
- package/dist/node/orchestration/services/implementation/accountBalance.d.ts.map +1 -1
- package/dist/node/orchestration/services/implementation/blockViewer.d.ts +7 -0
- package/dist/node/orchestration/services/implementation/blockViewer.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/getBridgeSourceDetails.d.ts +3 -3
- package/dist/node/orchestration/services/implementation/head/createForkedHead/config/getBridgeSourceDetails.d.ts.map +1 -1
- package/dist/node/orchestration/services/implementation/head/head.d.ts +1 -1
- package/dist/node/orchestration/services/implementation/head/head.d.ts.map +1 -1
- package/dist/node/orchestration/services/implementation/index.d.ts +1 -0
- package/dist/node/orchestration/services/implementation/index.d.ts.map +1 -1
- package/dist/node/orchestration/services/implementation/pendingTransactions.d.ts +7 -3
- package/dist/node/orchestration/services/implementation/pendingTransactions.d.ts.map +1 -1
- package/dist/node/xl1.mjs +295 -704
- package/dist/node/xl1.mjs.map +1 -1
- package/package.json +18 -16
- package/src/commands/producer/runProducer.ts +7 -5
- package/src/commands/validator/runValidator.ts +2 -3
- package/src/orchestration/actor/implementation/BalanceActor.ts +4 -7
- package/src/orchestration/actor/implementation/ProducerActor.ts +6 -6
- package/src/orchestration/actor/implementation/ValidatorActor.ts +4 -4
- package/src/orchestration/actor/implementation/index.ts +0 -1
- package/src/orchestration/initServices.ts +30 -101
- package/src/orchestration/services/implementation/accountBalance.ts +10 -17
- package/src/orchestration/services/implementation/blockViewer.ts +29 -0
- package/src/orchestration/services/implementation/head/createBootstrapHead.ts +1 -1
- package/src/orchestration/services/implementation/head/createForkedHead/config/getBridgeSourceDetails.ts +5 -5
- package/src/orchestration/services/implementation/head/createForkedHead/getBridgeDestinationObservation.ts +1 -1
- package/src/orchestration/services/implementation/head/createForkedHead/getBridgeIntent.ts +1 -1
- package/src/orchestration/services/implementation/head/createForkedHead/getBridgeSourceObservation.ts +1 -1
- package/src/orchestration/services/implementation/head/createForkedHead/getFirstBlockForNewChain.ts +1 -1
- package/src/orchestration/services/implementation/head/getForkFromBlock.ts +1 -1
- package/src/orchestration/services/implementation/head/head.ts +1 -2
- package/src/orchestration/services/implementation/index.ts +1 -0
- package/src/orchestration/services/implementation/pendingTransactions.ts +28 -9
- package/src/orchestration/services/implementation/time.ts +2 -2
- package/dist/node/orchestration/actor/implementation/ChainHeadUpdateActor.d.ts +0 -20
- package/dist/node/orchestration/actor/implementation/ChainHeadUpdateActor.d.ts.map +0 -1
- package/src/orchestration/actor/implementation/ChainHeadUpdateActor.ts +0 -72
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/xl1-cli-lib",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "XYO Layer One CLI Library",
|
|
5
5
|
"homepage": "https://xylabs.com",
|
|
6
6
|
"bugs": {
|
|
@@ -49,22 +49,23 @@
|
|
|
49
49
|
"@xyo-network/archivist-lmdb": "~5.2.10",
|
|
50
50
|
"@xyo-network/archivist-memory": "~5.2.10",
|
|
51
51
|
"@xyo-network/archivist-model": "~5.2.10",
|
|
52
|
-
"@xyo-network/chain-api": "~1.
|
|
53
|
-
"@xyo-network/chain-bridge": "~1.
|
|
54
|
-
"@xyo-network/chain-mempool": "~1.
|
|
55
|
-
"@xyo-network/chain-orchestration": "~1.
|
|
56
|
-
"@xyo-network/chain-protocol": "~1.
|
|
57
|
-
"@xyo-network/chain-reward-redemption": "~1.
|
|
58
|
-
"@xyo-network/chain-services": "~1.
|
|
59
|
-
"@xyo-network/chain-telemetry": "~1.
|
|
60
|
-
"@xyo-network/chain-utils": "~1.
|
|
61
|
-
"@xyo-network/chain-validation": "~1.
|
|
52
|
+
"@xyo-network/chain-api": "~1.17.0",
|
|
53
|
+
"@xyo-network/chain-bridge": "~1.17.0",
|
|
54
|
+
"@xyo-network/chain-mempool": "~1.17.0",
|
|
55
|
+
"@xyo-network/chain-orchestration": "~1.17.0",
|
|
56
|
+
"@xyo-network/chain-protocol": "~1.17.0",
|
|
57
|
+
"@xyo-network/chain-reward-redemption": "~1.17.0",
|
|
58
|
+
"@xyo-network/chain-services": "~1.17.0",
|
|
59
|
+
"@xyo-network/chain-telemetry": "~1.17.0",
|
|
60
|
+
"@xyo-network/chain-utils": "~1.17.0",
|
|
61
|
+
"@xyo-network/chain-validation": "~1.17.0",
|
|
62
62
|
"@xyo-network/payload-builder": "~5.2.10",
|
|
63
63
|
"@xyo-network/payload-model": "~5.2.10",
|
|
64
64
|
"@xyo-network/wallet-model": "~5.2.10",
|
|
65
65
|
"@xyo-network/xl1-protocol": "~1.14.15",
|
|
66
|
-
"@xyo-network/xl1-protocol-sdk": "~1.
|
|
67
|
-
"@xyo-network/xl1-
|
|
66
|
+
"@xyo-network/xl1-protocol-sdk": "~1.17.0",
|
|
67
|
+
"@xyo-network/xl1-rpc": "~1.17.0",
|
|
68
|
+
"@xyo-network/xl1-validation": "~1.17.0",
|
|
68
69
|
"async-mutex": "~0.5.0",
|
|
69
70
|
"cosmiconfig": "~9.0.0",
|
|
70
71
|
"dotenv": "~17.2.3",
|
|
@@ -77,16 +78,17 @@
|
|
|
77
78
|
"@xylabs/tsconfig": "~7.2.8",
|
|
78
79
|
"@xylabs/vitest-extended": "~5.0.46",
|
|
79
80
|
"@xyo-network/account-model": "~5.2.10",
|
|
80
|
-
"@xyo-network/
|
|
81
|
+
"@xyo-network/archivist-mongodb": "~5.2.10",
|
|
82
|
+
"@xyo-network/chain-test": "~1.17.0",
|
|
81
83
|
"@xyo-network/wallet": "~5.2.10",
|
|
82
|
-
"@xyo-network/xl1-rpc": "~1.
|
|
84
|
+
"@xyo-network/xl1-rpc": "~1.17.0",
|
|
83
85
|
"eslint": "^9.39.1",
|
|
84
86
|
"lmdb": "~3.4.4",
|
|
85
87
|
"nodemon": "~3.1.11",
|
|
86
88
|
"rimraf": "~6.1.2",
|
|
87
89
|
"tslib": "~2.8.1",
|
|
88
90
|
"typescript": "~5.9.3",
|
|
89
|
-
"vitest": "~4.0.
|
|
91
|
+
"vitest": "~4.0.14",
|
|
90
92
|
"vitest-mock-extended": "~3.1.0"
|
|
91
93
|
},
|
|
92
94
|
"peerDependencies": {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
exists, isDefined, type Logger,
|
|
3
|
+
} from '@xylabs/sdk-js'
|
|
2
4
|
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
3
5
|
|
|
4
6
|
import type { Orchestrator } from '../../orchestration/index.ts'
|
|
5
7
|
import {
|
|
6
|
-
BalanceActor,
|
|
8
|
+
BalanceActor, initServices, ProducerActor,
|
|
7
9
|
} from '../../orchestration/index.ts'
|
|
8
10
|
|
|
9
11
|
interface RunProducerContext {
|
|
@@ -24,10 +26,10 @@ export const runProducer = async (context: RunProducerContext) => {
|
|
|
24
26
|
|
|
25
27
|
// Create actors
|
|
26
28
|
const params = { ...services, config }
|
|
27
|
-
const
|
|
28
|
-
const balances = await BalanceActor.create({ ...params, name: 'BalanceActor' })
|
|
29
|
+
const apiEndpoint = config.services.apiEndpoint
|
|
30
|
+
const balances = isDefined(apiEndpoint) ? undefined : await BalanceActor.create({ ...params, name: 'BalanceActor' })
|
|
29
31
|
const producer = await ProducerActor.create({ ...params, name: 'ProducerActor' })
|
|
30
|
-
const actors = [
|
|
32
|
+
const actors = [balances, producer].filter(exists)
|
|
31
33
|
|
|
32
34
|
for (const actor of actors) {
|
|
33
35
|
// Register the actor with the orchestrator
|
|
@@ -3,7 +3,7 @@ import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
|
3
3
|
|
|
4
4
|
import type { Orchestrator } from '../../orchestration/index.ts'
|
|
5
5
|
import {
|
|
6
|
-
BalanceActor,
|
|
6
|
+
BalanceActor, initServices, ValidatorActor,
|
|
7
7
|
} from '../../orchestration/index.ts'
|
|
8
8
|
|
|
9
9
|
interface RunValidatorContext {
|
|
@@ -24,10 +24,9 @@ export const runValidator = async (context: RunValidatorContext) => {
|
|
|
24
24
|
|
|
25
25
|
// Create actors
|
|
26
26
|
const params = { ...services, config }
|
|
27
|
-
const chainHeadUpdate = await ChainHeadUpdateActor.create({ ...params, name: 'ChainHeadUpdateActor' })
|
|
28
27
|
const balances = await BalanceActor.create({ ...params, name: 'BalanceActor' })
|
|
29
28
|
const producer = await ValidatorActor.create({ ...params, name: 'ValidatorActor' })
|
|
30
|
-
const actors = [
|
|
29
|
+
const actors = [balances, producer]
|
|
31
30
|
|
|
32
31
|
for (const actor of actors) {
|
|
33
32
|
// Register the actor with the orchestrator
|
|
@@ -8,7 +8,7 @@ import type { ActorParams } from '../model/index.ts'
|
|
|
8
8
|
import { Actor } from '../model/index.ts'
|
|
9
9
|
|
|
10
10
|
export type BalanceActorParams = ActorParams<
|
|
11
|
-
Pick<ChainServiceCollectionV2, 'balance' | '
|
|
11
|
+
Pick<ChainServiceCollectionV2, 'balance' | 'blockViewer'>
|
|
12
12
|
& { config: Config }>
|
|
13
13
|
|
|
14
14
|
export class BalanceActor extends Actor<BalanceActorParams> {
|
|
@@ -22,8 +22,8 @@ export class BalanceActor extends Actor<BalanceActorParams> {
|
|
|
22
22
|
return assertEx(this.params.balance, () => 'balanceService not set')
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
protected get
|
|
26
|
-
return assertEx(this.params.
|
|
25
|
+
protected get blockViewer() {
|
|
26
|
+
return assertEx(this.params.blockViewer, () => 'blockViewer not set')
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
static create(params: BalanceActorParams): Promisable<BalanceActor> {
|
|
@@ -32,9 +32,6 @@ export class BalanceActor extends Actor<BalanceActorParams> {
|
|
|
32
32
|
|
|
33
33
|
override async start(): Promise<void> {
|
|
34
34
|
await super.start()
|
|
35
|
-
this.chainIterator.on('headUpdate', async () => {
|
|
36
|
-
await this.updateBalance()
|
|
37
|
-
})
|
|
38
35
|
this.registerTimer('BalanceTimer', async () => {
|
|
39
36
|
await this.updateBalance()
|
|
40
37
|
}, 1000, 10_000/* 1000 */)
|
|
@@ -43,7 +40,7 @@ export class BalanceActor extends Actor<BalanceActorParams> {
|
|
|
43
40
|
protected async updateBalance(): Promise<void> {
|
|
44
41
|
if (this._updateMutex.isLocked()) return
|
|
45
42
|
await this._updateMutex.runExclusive(async () => {
|
|
46
|
-
const head = await
|
|
43
|
+
const head = await this.blockViewer.currentBlockHash()
|
|
47
44
|
await this.balanceService.accountsBalances([], head)
|
|
48
45
|
})
|
|
49
46
|
}
|
|
@@ -27,7 +27,7 @@ export type ProducerActorParams = ActorParams<
|
|
|
27
27
|
ChainServiceCollectionV2,
|
|
28
28
|
'account'
|
|
29
29
|
| 'balance'
|
|
30
|
-
| '
|
|
30
|
+
| 'blockViewer'
|
|
31
31
|
| 'chainStakeViewer'
|
|
32
32
|
| 'chainSubmissionsArchivistWrite'
|
|
33
33
|
| 'pendingBundledTransactionsArchivistWrite'
|
|
@@ -82,8 +82,8 @@ export class ProducerActor extends Actor<ProducerActorParams> {
|
|
|
82
82
|
return assertEx(this.params.balance, () => 'balanceService not set')
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
protected get
|
|
86
|
-
return assertEx(this.params.
|
|
85
|
+
protected get blockViewer() {
|
|
86
|
+
return assertEx(this.params.blockViewer, () => 'blockViewer not set')
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
protected get chainStakeViewer() {
|
|
@@ -154,7 +154,7 @@ export class ProducerActor extends Actor<ProducerActorParams> {
|
|
|
154
154
|
await this._produceBlockMutex.runExclusive(async () => {
|
|
155
155
|
// Get the updated head
|
|
156
156
|
const headStart = Date.now()
|
|
157
|
-
const head = await this.
|
|
157
|
+
const head = (await this.blockViewer.currentBlock())[0]
|
|
158
158
|
const headDuration = Date.now() - headStart
|
|
159
159
|
if (headDuration > 500) this.logger?.warn(`[Slow] Fetched head in ${headDuration}ms: 0x${toHex(head._hash)}`)
|
|
160
160
|
// Check if we've already produced the next block for this head
|
|
@@ -193,7 +193,7 @@ export class ProducerActor extends Actor<ProducerActorParams> {
|
|
|
193
193
|
if (this.params.config.producer.disableIntentRedeclaration) return
|
|
194
194
|
|
|
195
195
|
// Get the current block
|
|
196
|
-
const head = await this.
|
|
196
|
+
const head = (await this.blockViewer.currentBlock())[0]
|
|
197
197
|
if (isUndefined(head)) return
|
|
198
198
|
const currentBlock = head.block
|
|
199
199
|
|
|
@@ -256,7 +256,7 @@ export class ProducerActor extends Actor<ProducerActorParams> {
|
|
|
256
256
|
this.logger?.log('Submitting redeclaration intent for producer:', this.account.address)
|
|
257
257
|
// Create a transaction to submit the redeclaration intent
|
|
258
258
|
const tx = await buildTransaction(
|
|
259
|
-
this.
|
|
259
|
+
await this.chainStakeViewer.chainId(),
|
|
260
260
|
[redeclarationIntent],
|
|
261
261
|
[],
|
|
262
262
|
this.account,
|
|
@@ -13,7 +13,7 @@ export type ValidatorActorParams = ActorParams<
|
|
|
13
13
|
Pick<ChainServiceCollectionV2,
|
|
14
14
|
'account'
|
|
15
15
|
| 'balance'
|
|
16
|
-
| '
|
|
16
|
+
| 'blockViewer'
|
|
17
17
|
| 'chainStakeViewer'
|
|
18
18
|
| 'chainSubmissionsArchivistWrite'
|
|
19
19
|
| 'pendingBundledTransactionsArchivistWrite'
|
|
@@ -38,8 +38,8 @@ export class ValidatorActor extends Actor<ValidatorActorParams> {
|
|
|
38
38
|
return assertEx(this.params.balance, () => 'balanceService not set')
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
protected get
|
|
42
|
-
return assertEx(this.params.
|
|
41
|
+
protected get blockViewer() {
|
|
42
|
+
return assertEx(this.params.blockViewer, () => 'blockViewer not set')
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
protected get chainStakeViewer() {
|
|
@@ -72,7 +72,7 @@ export class ValidatorActor extends Actor<ValidatorActorParams> {
|
|
|
72
72
|
this.registerTimer('BlockProductionTimer', async () => {
|
|
73
73
|
await this.spanAsync('produceBlock', async () => {
|
|
74
74
|
// Get the updated head
|
|
75
|
-
const block = await this.
|
|
75
|
+
const block = (await this.blockViewer.currentBlock())[0]
|
|
76
76
|
if (isUndefined(block)) return
|
|
77
77
|
// Check if we've already validated this head
|
|
78
78
|
const hash = await PayloadBuilder.hash(block)
|
|
@@ -6,35 +6,27 @@ import {
|
|
|
6
6
|
asAddress, assertEx, isDefined,
|
|
7
7
|
} from '@xylabs/sdk-js'
|
|
8
8
|
import {
|
|
9
|
-
|
|
9
|
+
initElectionService, initProducerAccount, initStakeIntentService,
|
|
10
10
|
} from '@xyo-network/chain-orchestration'
|
|
11
|
-
import {
|
|
12
|
-
type BaseBlockProducerServiceParams, blockViewerFromChainIteratorAndArchivist, type XyoValidatorParams,
|
|
13
|
-
} from '@xyo-network/chain-services'
|
|
11
|
+
import { type BaseBlockProducerServiceParams, type XyoValidatorParams } from '@xyo-network/chain-services'
|
|
14
12
|
import { initTelemetry } from '@xyo-network/chain-telemetry'
|
|
15
13
|
import { startupSpanAsync } from '@xyo-network/chain-utils'
|
|
16
14
|
import { validateHydratedBlockState } from '@xyo-network/chain-validation'
|
|
17
|
-
import type {
|
|
18
|
-
import { StepSizes } from '@xyo-network/xl1-protocol'
|
|
19
|
-
import type {
|
|
20
|
-
BalanceStepSummaryContext, ChainServiceCollectionV2, Config, TransfersStepSummaryContext,
|
|
21
|
-
} from '@xyo-network/xl1-protocol-sdk'
|
|
22
|
-
import { readPayloadMapFromStore } from '@xyo-network/xl1-protocol-sdk'
|
|
15
|
+
import type { ChainServiceCollectionV2, Config } from '@xyo-network/xl1-protocol-sdk'
|
|
23
16
|
import {
|
|
24
17
|
CompletedStepRewardAddressValidatorFactory, DerivedReceiveAddressValidatorFactory, SelfSignerValidator, TransactionTransfersValidatorFactory,
|
|
25
18
|
} from '@xyo-network/xl1-validation'
|
|
26
|
-
import { Semaphore } from 'async-mutex'
|
|
27
19
|
|
|
28
20
|
import {
|
|
29
|
-
|
|
21
|
+
initChainSubmissionsArchivist, initPendingBundledTransactionsArchivist, initRejectedTransactionsArchivist,
|
|
30
22
|
initStakeIntentStateArchivist,
|
|
31
23
|
} from './archivists/index.ts'
|
|
32
24
|
import type { ChainInitializableParams } from './ChainInitializableParams.ts'
|
|
33
25
|
import { initHealthEndpoints } from './health/index.ts'
|
|
34
26
|
import { initBalanceSummaryMap, initTransferSummaryMap } from './map/index.ts'
|
|
35
27
|
import {
|
|
36
|
-
initAccountBalanceService, initBlockProducer, initBlockRewardService,
|
|
37
|
-
initPendingTransactions, initTimeService,
|
|
28
|
+
initAccountBalanceService, initBlockProducer, initBlockRewardService, initBlockViewer, initChainService,
|
|
29
|
+
initPendingTransactions, initTimeService,
|
|
38
30
|
} from './services/index.ts'
|
|
39
31
|
import { RuntimeStatusMonitor } from './status/index.ts'
|
|
40
32
|
|
|
@@ -96,19 +88,13 @@ export const initServices = async (context: InitServicesContext): Promise<ChainS
|
|
|
96
88
|
|
|
97
89
|
// Archivists
|
|
98
90
|
const [
|
|
99
|
-
chainArchivist,
|
|
100
91
|
[pendingBundledTransactionsArchivist, pendingBundledTransactionsArchivistWrite],
|
|
101
92
|
rejectedTransactionsArchivist,
|
|
102
93
|
chainSubmissionsArchivistWrite,
|
|
103
94
|
stakeIntentStateArchivist,
|
|
104
95
|
chainService,
|
|
105
96
|
balanceSummaryMap,
|
|
106
|
-
transferSummaryMap,
|
|
107
97
|
] = await Promise.all([
|
|
108
|
-
startupSpanAsync(
|
|
109
|
-
'ChainFinalizedArchivist',
|
|
110
|
-
() => initChainFinalizedArchivist(initParams),
|
|
111
|
-
),
|
|
112
98
|
startupSpanAsync(
|
|
113
99
|
'PendingBundledTransactionsArchivist',
|
|
114
100
|
() => initPendingBundledTransactionsArchivist(initParams),
|
|
@@ -142,14 +128,10 @@ export const initServices = async (context: InitServicesContext): Promise<ChainS
|
|
|
142
128
|
),
|
|
143
129
|
])
|
|
144
130
|
|
|
145
|
-
const chainId = chainService.chainId
|
|
146
|
-
const chainMap = readPayloadMapFromStore<WithStorageMeta<Payload>>(chainArchivist)
|
|
131
|
+
const chainId = await chainService.chainId()
|
|
147
132
|
const chainContractViewer = chainService
|
|
148
133
|
const chainStakeViewer = chainService
|
|
149
134
|
const chainStaker = chainService
|
|
150
|
-
const head = await startupSpanAsync('initHead', () => initHead({
|
|
151
|
-
...initParams, account, chainArchivist, chainSubmissionsArchivistWrite, chainService,
|
|
152
|
-
}))
|
|
153
135
|
|
|
154
136
|
const additionalPendingTransactionValidators = [TransactionTransfersValidatorFactory(
|
|
155
137
|
[
|
|
@@ -162,16 +144,17 @@ export const initServices = async (context: InitServicesContext): Promise<ChainS
|
|
|
162
144
|
const [
|
|
163
145
|
pendingTransactionsService,
|
|
164
146
|
rewardService,
|
|
165
|
-
chainIterator,
|
|
166
147
|
] = await Promise.all([
|
|
167
148
|
startupSpanAsync('PendingTransactions', () => initPendingTransactions({
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
149
|
+
config,
|
|
150
|
+
params: {
|
|
151
|
+
name: 'PendingTransactionsService' as CreatableName,
|
|
152
|
+
chainId,
|
|
153
|
+
pendingBundledTransactionsArchivist,
|
|
154
|
+
rejectedTransactionsArchivist,
|
|
155
|
+
additionalPendingTransactionValidators,
|
|
156
|
+
...initParams,
|
|
157
|
+
},
|
|
175
158
|
})),
|
|
176
159
|
startupSpanAsync(
|
|
177
160
|
'RewardService',
|
|
@@ -182,76 +165,24 @@ export const initServices = async (context: InitServicesContext): Promise<ChainS
|
|
|
182
165
|
...initParams,
|
|
183
166
|
}),
|
|
184
167
|
),
|
|
185
|
-
startupSpanAsync(
|
|
186
|
-
'ChainIterator',
|
|
187
|
-
() => initChainIterator({
|
|
188
|
-
name: 'ChainIterator' as CreatableName,
|
|
189
|
-
chainMap,
|
|
190
|
-
head,
|
|
191
|
-
...initParams,
|
|
192
|
-
}),
|
|
193
|
-
),
|
|
194
168
|
])
|
|
195
169
|
|
|
196
|
-
const blockViewer =
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
store: { chainMap },
|
|
201
|
-
head: async () => {
|
|
202
|
-
const head = await chainIterator.head()
|
|
203
|
-
return [head._hash, head.block]
|
|
204
|
-
},
|
|
205
|
-
chainId,
|
|
206
|
-
summaryMap: balanceSummaryMap,
|
|
207
|
-
} satisfies BalanceStepSummaryContext
|
|
208
|
-
|
|
209
|
-
const transferContext = {
|
|
210
|
-
stepSemaphores: StepSizes.map(() => new Semaphore(20)),
|
|
211
|
-
store: { chainMap },
|
|
212
|
-
head: async () => {
|
|
213
|
-
const head = await chainIterator.head()
|
|
214
|
-
return [head._hash, head.block]
|
|
215
|
-
},
|
|
216
|
-
chainId,
|
|
217
|
-
summaryMap: transferSummaryMap,
|
|
218
|
-
} satisfies TransfersStepSummaryContext
|
|
170
|
+
const blockViewer = await startupSpanAsync(
|
|
171
|
+
'BlockViewer',
|
|
172
|
+
() => initBlockViewer({ ...initParams }),
|
|
173
|
+
)
|
|
219
174
|
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
'BalanceService',
|
|
225
|
-
() => initAccountBalanceService({
|
|
226
|
-
params: {
|
|
227
|
-
name: 'BalanceService' as CreatableName,
|
|
228
|
-
config: {},
|
|
229
|
-
context: balanceContext,
|
|
230
|
-
blockViewer,
|
|
231
|
-
chainArchivist,
|
|
232
|
-
chainIterator,
|
|
233
|
-
transferContext,
|
|
234
|
-
},
|
|
235
|
-
...initParams,
|
|
236
|
-
}),
|
|
237
|
-
),
|
|
238
|
-
startupSpanAsync(
|
|
239
|
-
'TransferService',
|
|
240
|
-
() => initTransferService({
|
|
241
|
-
name: 'TransferService' as CreatableName,
|
|
242
|
-
context: transferContext,
|
|
243
|
-
...initParams,
|
|
244
|
-
}),
|
|
245
|
-
),
|
|
246
|
-
])
|
|
175
|
+
const balanceService = await startupSpanAsync(
|
|
176
|
+
'BalanceService',
|
|
177
|
+
() => initAccountBalanceService({ ...initParams }),
|
|
178
|
+
)
|
|
247
179
|
|
|
248
180
|
const [stakeIntentService, time] = await Promise.all([
|
|
249
181
|
startupSpanAsync(
|
|
250
182
|
'StakeIntentService',
|
|
251
183
|
() => initStakeIntentService({
|
|
252
184
|
name: 'StakeIntentService' as CreatableName,
|
|
253
|
-
|
|
254
|
-
chainIterator,
|
|
185
|
+
blockViewer,
|
|
255
186
|
chainStakeViewer,
|
|
256
187
|
stakeIntentStateArchivist,
|
|
257
188
|
...initParams,
|
|
@@ -261,8 +192,7 @@ export const initServices = async (context: InitServicesContext): Promise<ChainS
|
|
|
261
192
|
'TimeService',
|
|
262
193
|
() => initTimeService({
|
|
263
194
|
name: 'TimeService' as CreatableName,
|
|
264
|
-
|
|
265
|
-
chainIterator,
|
|
195
|
+
blockViewer,
|
|
266
196
|
...initParams,
|
|
267
197
|
}),
|
|
268
198
|
),
|
|
@@ -272,7 +202,7 @@ export const initServices = async (context: InitServicesContext): Promise<ChainS
|
|
|
272
202
|
'ElectionService',
|
|
273
203
|
() => initElectionService({
|
|
274
204
|
name: 'ElectionService' as CreatableName,
|
|
275
|
-
|
|
205
|
+
blockViewer,
|
|
276
206
|
chainStakeViewer,
|
|
277
207
|
stakeIntentService,
|
|
278
208
|
...initParams,
|
|
@@ -284,7 +214,7 @@ export const initServices = async (context: InitServicesContext): Promise<ChainS
|
|
|
284
214
|
account,
|
|
285
215
|
chainId,
|
|
286
216
|
pendingBundledTransactionsArchivist,
|
|
287
|
-
|
|
217
|
+
blockViewer,
|
|
288
218
|
electionService,
|
|
289
219
|
rewardService,
|
|
290
220
|
stakeIntentService,
|
|
@@ -299,7 +229,7 @@ export const initServices = async (context: InitServicesContext): Promise<ChainS
|
|
|
299
229
|
...validatorParams,
|
|
300
230
|
name: 'Producer' as CreatableName,
|
|
301
231
|
balanceService,
|
|
302
|
-
|
|
232
|
+
blockViewer,
|
|
303
233
|
pendingBundledTransactionsArchivist,
|
|
304
234
|
pendingTransactionsService,
|
|
305
235
|
rejectedTransactionsArchivist,
|
|
@@ -312,9 +242,8 @@ export const initServices = async (context: InitServicesContext): Promise<ChainS
|
|
|
312
242
|
const services: ChainServiceCollectionV2 = {
|
|
313
243
|
account,
|
|
314
244
|
balance: balanceService,
|
|
315
|
-
chainArchivist,
|
|
316
245
|
chainContractViewer,
|
|
317
|
-
|
|
246
|
+
blockViewer,
|
|
318
247
|
chainStaker,
|
|
319
248
|
chainStakeViewer,
|
|
320
249
|
chainSubmissionsArchivistWrite,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { isDefined, type Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import { BaseAccountBalanceService, type BaseAccountBalanceServiceParams } from '@xyo-network/chain-services'
|
|
3
2
|
import type { Initializable, InitializableParams } from '@xyo-network/xl1-protocol'
|
|
4
3
|
import type { AccountBalanceViewer, Config } from '@xyo-network/xl1-protocol-sdk'
|
|
5
|
-
import { timeBudget } from '@xyo-network/xl1-protocol-sdk'
|
|
6
4
|
import {
|
|
7
5
|
AccountBalanceViewerRpcSchemas,
|
|
8
6
|
HttpRpcTransport,
|
|
@@ -13,24 +11,19 @@ let balanceServiceSingleton: Promisable<AccountBalanceViewer> | undefined
|
|
|
13
11
|
|
|
14
12
|
export type InitAccountBalanceServiceParams = InitializableParams<{
|
|
15
13
|
config: Config
|
|
16
|
-
params?: BaseAccountBalanceServiceParams
|
|
17
14
|
}>
|
|
18
15
|
|
|
19
16
|
export const initAccountBalanceService: Initializable<InitAccountBalanceServiceParams, AccountBalanceViewer>
|
|
20
|
-
=
|
|
17
|
+
= (params): Promisable<AccountBalanceViewer> => {
|
|
21
18
|
const { config, logger } = params
|
|
22
19
|
if (balanceServiceSingleton) return balanceServiceSingleton
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// balanceServiceSingleton = await BaseAccountBalanceService.create(params.params)
|
|
33
|
-
// }
|
|
34
|
-
return balanceServiceSingleton
|
|
35
|
-
}, 2000, true)
|
|
20
|
+
const endpoint = config.services?.accountBalanceViewerEndpoint ?? config.services?.apiEndpoint
|
|
21
|
+
if (isDefined(endpoint)) {
|
|
22
|
+
const transport = new HttpRpcTransport(endpoint, { ...AccountBalanceViewerRpcSchemas })
|
|
23
|
+
const viewer = new JsonRpcAccountBalanceViewer(transport)
|
|
24
|
+
logger?.log('Using AccountBalanceViewer RPC service at', endpoint)
|
|
25
|
+
return viewer
|
|
26
|
+
} else {
|
|
27
|
+
throw new Error('No AccountBalanceViewer endpoint configured')
|
|
28
|
+
}
|
|
36
29
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isDefined, type Promisable } from '@xylabs/sdk-js'
|
|
2
|
+
import type { Initializable, InitializableParams } from '@xyo-network/xl1-protocol'
|
|
3
|
+
import type { BlockViewer, Config } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
+
import {
|
|
5
|
+
BlockViewerRpcSchemas,
|
|
6
|
+
HttpRpcTransport,
|
|
7
|
+
JsonRpcBlockViewer,
|
|
8
|
+
} from '@xyo-network/xl1-rpc'
|
|
9
|
+
|
|
10
|
+
let blockViewerSingleton: Promisable<BlockViewer> | undefined
|
|
11
|
+
|
|
12
|
+
export type InitBlockViewerParams = InitializableParams<{
|
|
13
|
+
config: Config
|
|
14
|
+
}>
|
|
15
|
+
|
|
16
|
+
export const initBlockViewer: Initializable<InitBlockViewerParams, BlockViewer>
|
|
17
|
+
= (params): Promisable<BlockViewer> => {
|
|
18
|
+
const { config, logger } = params
|
|
19
|
+
if (blockViewerSingleton) return blockViewerSingleton
|
|
20
|
+
const endpoint = config.services?.apiEndpoint
|
|
21
|
+
if (isDefined(endpoint)) {
|
|
22
|
+
const transport = new HttpRpcTransport(endpoint, { ...BlockViewerRpcSchemas })
|
|
23
|
+
const viewer = new JsonRpcBlockViewer(transport)
|
|
24
|
+
logger?.log('Using BlockViewer RPC service at', endpoint)
|
|
25
|
+
return viewer
|
|
26
|
+
} else {
|
|
27
|
+
throw new Error('No BlockViewer endpoint configured')
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -6,7 +6,7 @@ import type { SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
|
6
6
|
import type { ChainService } from '@xyo-network/xl1-protocol-sdk'
|
|
7
7
|
|
|
8
8
|
export const createBootstrapHead = async (account: WalletInstance, chainService: ChainService): Promise<SignedHydratedBlockWithHashMeta[]> => {
|
|
9
|
-
const chainId = chainService.chainId
|
|
9
|
+
const chainId = await chainService.chainId()
|
|
10
10
|
const chain: SignedHydratedBlockWithHashMeta[] = []
|
|
11
11
|
|
|
12
12
|
// Create genesis block
|
|
@@ -4,16 +4,16 @@ import type { ChainService } from '@xyo-network/xl1-protocol-sdk'
|
|
|
4
4
|
|
|
5
5
|
import { getForkBlockRewardHex } from './getForkDetails.ts'
|
|
6
6
|
|
|
7
|
-
export const getBridgeSrcChainId = (chainService: ChainService) => chainService.chainId
|
|
7
|
+
export const getBridgeSrcChainId = (chainService: ChainService) => chainService.chainId()
|
|
8
8
|
export const getBridgeSrcAddress = (account: AccountInstance) => account.address
|
|
9
|
-
export const getBridgeSrcToken = (chainService: ChainService) => chainService.chainId
|
|
9
|
+
export const getBridgeSrcToken = (chainService: ChainService) => chainService.chainId()
|
|
10
10
|
export const getBridgeSrcAmount = () => getForkBlockRewardHex()
|
|
11
11
|
|
|
12
|
-
export const getBridgeSourceDetails = (account: AccountInstance, chainService: ChainService): BridgeDetailsSourceFields => {
|
|
12
|
+
export const getBridgeSourceDetails = async (account: AccountInstance, chainService: ChainService): Promise<BridgeDetailsSourceFields> => {
|
|
13
13
|
return {
|
|
14
|
-
src: getBridgeSrcChainId(chainService),
|
|
14
|
+
src: await getBridgeSrcChainId(chainService),
|
|
15
15
|
srcAddress: getBridgeSrcAddress(account),
|
|
16
|
-
srcToken: getBridgeSrcToken(chainService),
|
|
16
|
+
srcToken: await getBridgeSrcToken(chainService),
|
|
17
17
|
srcAmount: getBridgeSrcAmount(),
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -25,7 +25,7 @@ export const getBridgeDestinationObservation = async (
|
|
|
25
25
|
chainService: ChainService,
|
|
26
26
|
): Promise<SignedHydratedBlockWithHashMeta> => {
|
|
27
27
|
const bridgeDestinationObservationFields: BridgeDestinationObservationFields = {
|
|
28
|
-
...getBridgeSourceDetails(account, chainService),
|
|
28
|
+
...await getBridgeSourceDetails(account, chainService),
|
|
29
29
|
...getBridgeDestinationDetails(),
|
|
30
30
|
destConfirmation: getBridgeDestConfirmation(),
|
|
31
31
|
}
|
|
@@ -34,7 +34,7 @@ export const getBridgeIntent = async (
|
|
|
34
34
|
|
|
35
35
|
// Create Bridge Intent
|
|
36
36
|
const bridgeIntentFields: BridgeIntentFields = {
|
|
37
|
-
...getBridgeSourceDetails(account, chainService),
|
|
37
|
+
...await getBridgeSourceDetails(account, chainService),
|
|
38
38
|
...getBridgeDestinationDetails(),
|
|
39
39
|
nonce,
|
|
40
40
|
}
|
|
@@ -27,7 +27,7 @@ export const getBridgeSourceObservation = async (
|
|
|
27
27
|
const srcTxHash = previousBlock[0]._hash
|
|
28
28
|
|
|
29
29
|
const bridgeSourceObservationFields: BridgeSourceObservationFields = {
|
|
30
|
-
...getBridgeSourceDetails(account, chainService),
|
|
30
|
+
...await getBridgeSourceDetails(account, chainService),
|
|
31
31
|
...getBridgeDestinationDetails(),
|
|
32
32
|
// Observation
|
|
33
33
|
srcConfirmation: srcTxHash,
|
package/src/orchestration/services/implementation/head/createForkedHead/getFirstBlockForNewChain.ts
CHANGED
|
@@ -23,7 +23,7 @@ export const getFirstBlockForNewChain = async (
|
|
|
23
23
|
const {
|
|
24
24
|
_hash: previousBlockHash, block: previousBlockNumber, step_hashes: previousStepHashes = [], protocol,
|
|
25
25
|
} = forkBlock
|
|
26
|
-
const chainId = chainService.chainId
|
|
26
|
+
const chainId = await chainService.chainId()
|
|
27
27
|
const options: BuildNextBlockOptions = {
|
|
28
28
|
blockPayloads: [],
|
|
29
29
|
chainId,
|
|
@@ -20,7 +20,7 @@ export const getForkFromBlock = async (
|
|
|
20
20
|
chainArchivist: ArchivistInstance,
|
|
21
21
|
): Promise<SignedBlockBoundWitnessWithHashMeta | undefined> => {
|
|
22
22
|
// If the head's chain doesn't match our chainId, we may need to fork
|
|
23
|
-
if (head.chain !== chainService.chainId) {
|
|
23
|
+
if (head.chain !== await chainService.chainId()) {
|
|
24
24
|
// Get the forked at hash from the chain service
|
|
25
25
|
const forkedAtBigInt = await chainService.forkedAtHash()
|
|
26
26
|
const forkedAtHex = hexFromBigInt(forkedAtBigInt) // Validate it's a proper hex string
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { Promisable } from '@xylabs/sdk-js'
|
|
2
2
|
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
3
3
|
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
4
|
-
import { findMostRecentBlock } from '@xyo-network/chain-protocol'
|
|
5
4
|
import type { WalletInstance } from '@xyo-network/wallet-model'
|
|
6
5
|
import type { Initializable, SignedBlockBoundWitnessWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
7
|
-
import type
|
|
6
|
+
import { type ChainService, findMostRecentBlock } from '@xyo-network/xl1-protocol-sdk'
|
|
8
7
|
|
|
9
8
|
import { createBootstrapHead } from './createBootstrapHead.ts'
|
|
10
9
|
import { createForkedHead } from './createForkedHead/index.ts'
|