@xyo-network/chain-services 1.16.21 → 1.16.23
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/AccountBalance/BaseAccountBalanceService.d.ts +8 -7
- package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts.map +1 -1
- package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts +2 -2
- package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
- package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts +3 -3
- package/dist/neutral/BlockProducer/BaseBlockProducerService.d.ts.map +1 -1
- package/dist/neutral/ChainService/Memory/Memory.d.ts +3 -0
- package/dist/neutral/ChainService/Memory/Memory.d.ts.map +1 -1
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts.map +1 -1
- package/dist/neutral/Schemas/BaseSchemasService.d.ts +13 -0
- package/dist/neutral/Schemas/BaseSchemasService.d.ts.map +1 -0
- package/dist/neutral/Schemas/index.d.ts +2 -0
- package/dist/neutral/Schemas/index.d.ts.map +1 -0
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +1 -0
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +151 -95
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +14 -14
- package/src/AccountBalance/BaseAccountBalanceService.ts +13 -8
- package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +2 -2
- package/src/BlockProducer/BaseBlockProducerService.ts +4 -4
- package/src/ChainService/Memory/Memory.ts +14 -4
- package/src/PendingTransactions/BasePendingTransactions.ts +12 -0
- package/src/Schemas/BaseSchemasService.ts +34 -0
- package/src/Schemas/index.ts +1 -0
- package/src/StakeIntent/XyoStakeIntentService.ts +47 -42
- package/src/index.ts +1 -0
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-services",
|
|
4
|
-
"version": "1.16.
|
|
4
|
+
"version": "1.16.23",
|
|
5
5
|
"description": "XYO Layer One SDK Services",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -40,38 +40,38 @@
|
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@opentelemetry/api": "~1.9.0",
|
|
43
|
-
"@xylabs/sdk-js": "~5.0.
|
|
44
|
-
"@xylabs/telemetry": "~5.0.
|
|
43
|
+
"@xylabs/sdk-js": "~5.0.39",
|
|
44
|
+
"@xylabs/telemetry": "~5.0.39",
|
|
45
45
|
"@xyo-network/account-model": "~5.1.24",
|
|
46
46
|
"@xyo-network/archivist-memory": "~5.1.24",
|
|
47
47
|
"@xyo-network/archivist-model": "~5.1.24",
|
|
48
48
|
"@xyo-network/boundwitness-model": "~5.1.24",
|
|
49
49
|
"@xyo-network/boundwitness-validator": "~5.1.24",
|
|
50
50
|
"@xyo-network/boundwitness-wrapper": "~5.1.24",
|
|
51
|
-
"@xyo-network/chain-analyze": "~1.16.
|
|
52
|
-
"@xyo-network/chain-modules": "~1.16.
|
|
53
|
-
"@xyo-network/chain-protocol": "~1.16.
|
|
54
|
-
"@xyo-network/chain-utils": "~1.16.
|
|
51
|
+
"@xyo-network/chain-analyze": "~1.16.23",
|
|
52
|
+
"@xyo-network/chain-modules": "~1.16.23",
|
|
53
|
+
"@xyo-network/chain-protocol": "~1.16.23",
|
|
54
|
+
"@xyo-network/chain-utils": "~1.16.23",
|
|
55
55
|
"@xyo-network/payload-builder": "~5.1.24",
|
|
56
56
|
"@xyo-network/payload-model": "~5.1.24",
|
|
57
57
|
"@xyo-network/typechain": "~4.0.10",
|
|
58
|
-
"@xyo-network/xl1-protocol": "~1.13.
|
|
59
|
-
"@xyo-network/xl1-protocol-sdk": "~1.16.
|
|
60
|
-
"@xyo-network/xl1-validation": "~1.16.
|
|
61
|
-
"@xyo-network/xl1-wrappers": "~1.16.
|
|
58
|
+
"@xyo-network/xl1-protocol": "~1.13.13",
|
|
59
|
+
"@xyo-network/xl1-protocol-sdk": "~1.16.23",
|
|
60
|
+
"@xyo-network/xl1-validation": "~1.16.23",
|
|
61
|
+
"@xyo-network/xl1-wrappers": "~1.16.23",
|
|
62
62
|
"async-mutex": "~0.5.0",
|
|
63
63
|
"ethers": "6.15.0",
|
|
64
64
|
"lru-cache": "~11.2.2"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@types/node": "~24.10.1",
|
|
68
|
-
"@xylabs/sdk-js": "~5.0.
|
|
68
|
+
"@xylabs/sdk-js": "~5.0.39",
|
|
69
69
|
"@xylabs/ts-scripts-yarn3": "~7.2.8",
|
|
70
70
|
"@xylabs/tsconfig": "~7.2.8",
|
|
71
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
71
|
+
"@xylabs/vitest-extended": "~5.0.39",
|
|
72
72
|
"@xyo-network/account": "~5.1.24",
|
|
73
73
|
"@xyo-network/account-model": "~5.1.24",
|
|
74
|
-
"@xyo-network/chain-validation": "~1.16.
|
|
74
|
+
"@xyo-network/chain-validation": "~1.16.23",
|
|
75
75
|
"@xyo-network/wallet": "~5.1.24",
|
|
76
76
|
"eslint": "^9.39.1",
|
|
77
77
|
"tslib": "~2.8.1",
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Address, creatable, Hash,
|
|
3
|
+
Promisable,
|
|
3
4
|
} from '@xylabs/sdk-js'
|
|
4
5
|
import { spanRootAsync } from '@xylabs/telemetry'
|
|
5
6
|
import { ReadArchivist } from '@xyo-network/archivist-model'
|
|
6
7
|
import { AttoXL1, XL1BlockRange } from '@xyo-network/xl1-protocol'
|
|
7
8
|
import {
|
|
8
9
|
AccountBalanceHistoryItem,
|
|
9
|
-
|
|
10
|
+
AccountBalanceViewer,
|
|
10
11
|
balancesSummary,
|
|
11
12
|
BalanceStepSummaryContext,
|
|
12
13
|
BlockViewer,
|
|
@@ -27,8 +28,8 @@ export interface BaseAccountBalanceServiceParams extends BaseServiceParams {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
@creatable()
|
|
30
|
-
export class BaseAccountBalanceService extends BaseService<BaseAccountBalanceServiceParams> implements
|
|
31
|
-
protected accountBalanceViewer!:
|
|
31
|
+
export class BaseAccountBalanceService extends BaseService<BaseAccountBalanceServiceParams> implements AccountBalanceViewer {
|
|
32
|
+
protected accountBalanceViewer!: AccountBalanceViewer
|
|
32
33
|
protected blockViewer!: BlockViewer
|
|
33
34
|
|
|
34
35
|
async accountBalance(address: Address, headOrRange?: XL1BlockRange | Hash): Promise<AttoXL1> {
|
|
@@ -57,11 +58,15 @@ export class BaseAccountBalanceService extends BaseService<BaseAccountBalanceSer
|
|
|
57
58
|
})
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
accountsBalances(address: Address[], headOrRange?: Hash | XL1BlockRange): Promisable<Partial<Record<Address, AttoXL1>>> {
|
|
62
|
+
throw new Error('Method not implemented.')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async accountsBalancesHistory(addresses: Address[]): Promise<Partial<Record<Address, AccountBalanceHistoryItem[]>>>
|
|
66
|
+
async accountsBalancesHistory(addresses: Address[], head: Hash): Promise<Partial<Record<Address, AccountBalanceHistoryItem[]>>>
|
|
67
|
+
async accountsBalancesHistory(addresses: Address[], range: XL1BlockRange): Promise<Partial<Record<Address, AccountBalanceHistoryItem[]>>>
|
|
68
|
+
async accountsBalancesHistory(addresses: Address[], headOrRange?: Hash | XL1BlockRange): Promise<Partial<Record<Address, AccountBalanceHistoryItem[]>>> {
|
|
69
|
+
return await this.accountBalanceViewer.accountsBalancesHistory(addresses, headOrRange)
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
override createHandler() {
|
|
@@ -5,7 +5,7 @@ import { findMostRecentBlock } from '@xyo-network/chain-protocol'
|
|
|
5
5
|
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
6
6
|
import type { ChainId } from '@xyo-network/xl1-protocol'
|
|
7
7
|
import { StepSizes } from '@xyo-network/xl1-protocol'
|
|
8
|
-
import type {
|
|
8
|
+
import type { AccountBalanceViewer, BalancesStepSummary } from '@xyo-network/xl1-protocol-sdk'
|
|
9
9
|
import { LruCacheMap, readPayloadMapFromStore } from '@xyo-network/xl1-protocol-sdk'
|
|
10
10
|
import { Semaphore } from 'async-mutex'
|
|
11
11
|
|
|
@@ -15,7 +15,7 @@ import { BaseAccountBalanceService } from './BaseAccountBalanceService.ts'
|
|
|
15
15
|
export const accountBalancesServiceFromArchivist = async (
|
|
16
16
|
chainId: ChainId,
|
|
17
17
|
archivist: ReadArchivist<WithStorageMeta<Payload>>,
|
|
18
|
-
): Promise<
|
|
18
|
+
): Promise<AccountBalanceViewer> => {
|
|
19
19
|
const summaryMap = new LruCacheMap<string, BalancesStepSummary>({
|
|
20
20
|
max: 100_000,
|
|
21
21
|
allowStale: true,
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
Transfer, XYO_STEP_REWARD_ADDRESS,
|
|
22
22
|
} from '@xyo-network/xl1-protocol'
|
|
23
23
|
import {
|
|
24
|
-
|
|
24
|
+
AccountBalanceViewer, BlockProducerService, Config, PendingTransactionsService, StakeIntentService, TimeSyncViewer,
|
|
25
25
|
} from '@xyo-network/xl1-protocol-sdk'
|
|
26
26
|
|
|
27
27
|
import { BaseService } from '../BaseService.ts'
|
|
@@ -45,7 +45,7 @@ export const XYO_PRODUCER_REDECLARATION_DURATION = 10_000
|
|
|
45
45
|
export const XYO_PRODUCER_REDECLARATION_WINDOW = 500
|
|
46
46
|
|
|
47
47
|
export interface BaseBlockProducerServiceParams extends XyoValidatorParams<Pick<Config, 'producer'>> {
|
|
48
|
-
balanceService:
|
|
48
|
+
balanceService: AccountBalanceViewer
|
|
49
49
|
pendingTransactionsService: PendingTransactionsService
|
|
50
50
|
rejectedTransactionsArchivist: ArchivistInstance
|
|
51
51
|
rewardAddress: Address
|
|
@@ -228,7 +228,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
228
228
|
// Build the block
|
|
229
229
|
this.logger?.info(`Building block ${head.block + 1}`)
|
|
230
230
|
const startBuild = Date.now()
|
|
231
|
-
const stepRewardPoolBalance = (await this.balanceService.
|
|
231
|
+
const stepRewardPoolBalance = (await this.balanceService.accountsBalances([XYO_STEP_REWARD_ADDRESS]))[XYO_STEP_REWARD_ADDRESS]
|
|
232
232
|
const block = await buildNextBlock(head, fundedNextBlockTransactions, blockPayloads, [this.account], XYO_STEP_REWARD_ADDRESS, stepRewardPoolBalance)
|
|
233
233
|
|
|
234
234
|
this.logger?.info(
|
|
@@ -263,7 +263,7 @@ export class BaseBlockProducerService extends BaseService<BaseBlockProducerServi
|
|
|
263
263
|
if (!transfer) return
|
|
264
264
|
const totalTransferCost = Object.values(transfer?.transfers).reduce((acc, t) => acc + hexToBigInt(t ?? '00' as Hex), 0n)
|
|
265
265
|
if (validateBalances) {
|
|
266
|
-
const balance = (await this.balanceService.
|
|
266
|
+
const balance = (await this.balanceService.accountsBalances([transfer.from]))[transfer.from] ?? AttoXL1(0n)
|
|
267
267
|
if (balance >= totalTransferCost) {
|
|
268
268
|
fundedTransfers.push(transfer)
|
|
269
269
|
return tx
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import type { Address } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
assertEx, toAddress, ZERO_ADDRESS,
|
|
4
|
+
} from '@xylabs/sdk-js'
|
|
3
5
|
import type { ChainService, Config } from '@xyo-network/xl1-protocol-sdk'
|
|
4
6
|
|
|
5
7
|
import { BaseService } from '../../BaseService.ts'
|
|
6
8
|
import type { BaseServiceParams } from '../../model/index.ts'
|
|
7
9
|
|
|
8
|
-
export interface MemoryChainServiceParams extends BaseServiceParams<Pick<Config, 'producer'>> {
|
|
10
|
+
export interface MemoryChainServiceParams extends BaseServiceParams<Pick<Config, 'producer'>> {
|
|
11
|
+
chainId: Address
|
|
12
|
+
}
|
|
9
13
|
|
|
10
14
|
/**
|
|
11
15
|
* A class that represents a chain stake as backed in memory
|
|
12
16
|
*/
|
|
13
17
|
export class MemoryChainService extends BaseService<MemoryChainServiceParams> implements ChainService {
|
|
18
|
+
protected _chainId: Address | undefined
|
|
14
19
|
protected _simulatedStake: bigint = 1n
|
|
15
20
|
|
|
16
21
|
get chainId(): Address {
|
|
17
|
-
return
|
|
22
|
+
return assertEx(this._chainId, () => 'Chain ID not set')
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
async active(): Promise<bigint> {
|
|
@@ -34,7 +39,7 @@ export class MemoryChainService extends BaseService<MemoryChainServiceParams> im
|
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
override createHandler(): void {
|
|
37
|
-
const { minStake } = this.params.config.producer
|
|
42
|
+
const { minStake = 1 } = this.params.config.producer ?? {}
|
|
38
43
|
this._simulatedStake = BigInt(minStake)
|
|
39
44
|
}
|
|
40
45
|
|
|
@@ -85,4 +90,9 @@ export class MemoryChainService extends BaseService<MemoryChainServiceParams> im
|
|
|
85
90
|
async withdrawnByStaker(_staker: string): Promise<bigint> {
|
|
86
91
|
return await Promise.resolve(0n)
|
|
87
92
|
}
|
|
93
|
+
|
|
94
|
+
protected override async startHandler(): Promise<void> {
|
|
95
|
+
await super.startHandler()
|
|
96
|
+
this._chainId = this.params.chainId ?? toAddress(1n)
|
|
97
|
+
}
|
|
88
98
|
}
|
|
@@ -186,10 +186,22 @@ export class BasePendingTransactionsService extends BaseService<BasePendingTrans
|
|
|
186
186
|
{ chainId: this.chainId },
|
|
187
187
|
this.additionalPendingTransactionValidators,
|
|
188
188
|
)])))
|
|
189
|
+
|
|
189
190
|
const validTransactions = txValidationResults.filter((
|
|
190
191
|
[, errors],
|
|
191
192
|
) => errors.length === 0).map(([tx]) => tx) as SignedHydratedTransactionWithStorageMeta[]
|
|
192
193
|
|
|
194
|
+
const invalidTransactions = txValidationResults.filter((
|
|
195
|
+
[, errors],
|
|
196
|
+
) => errors.length > 0).map(([tx]) => tx) as SignedHydratedTransactionWithStorageMeta[]
|
|
197
|
+
|
|
198
|
+
if (invalidTransactions.length > 0) {
|
|
199
|
+
this.logger?.warn(`getPendingTransactions: Found ${invalidTransactions.length} invalid pending transactions`)
|
|
200
|
+
for (const tx of invalidTransactions) {
|
|
201
|
+
this.logger?.warn(tx[0]._hash)
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
193
205
|
// Add the valid hydrated transactions to the result set.
|
|
194
206
|
foundPendingTransactions.push(...validTransactions)
|
|
195
207
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { creatable, Hash } from '@xylabs/sdk-js'
|
|
2
|
+
import { spanRootAsync } from '@xylabs/telemetry'
|
|
3
|
+
import { Schema } from '@xyo-network/payload-model'
|
|
4
|
+
import {
|
|
5
|
+
SchemasService,
|
|
6
|
+
SchemasStepSummaryContext,
|
|
7
|
+
schemasSummary,
|
|
8
|
+
} from '@xyo-network/xl1-protocol-sdk'
|
|
9
|
+
|
|
10
|
+
import { BaseService } from '../BaseService.ts'
|
|
11
|
+
import { BaseServiceParams } from '../model/index.ts'
|
|
12
|
+
|
|
13
|
+
export interface BaseSchemasServiceParams extends BaseServiceParams {
|
|
14
|
+
context: SchemasStepSummaryContext
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@creatable()
|
|
18
|
+
export class BaseSchemasService extends BaseService<BaseSchemasServiceParams> implements SchemasService {
|
|
19
|
+
async schema(head: Hash, schema: Schema): Promise<number> {
|
|
20
|
+
return (await this.schemas(head, [schema]))[schema] ?? 0
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async schemas(head: Hash, schemas: Schema[]): Promise<Partial<Record<Schema, number>>> {
|
|
24
|
+
return await spanRootAsync('transfers', async () => {
|
|
25
|
+
const summary = await schemasSummary(this.params.context)
|
|
26
|
+
const result: Record<Schema, number> = {}
|
|
27
|
+
for (const schema of schemas) {
|
|
28
|
+
const count = summary[schema] ?? 0
|
|
29
|
+
result[schema] = count
|
|
30
|
+
}
|
|
31
|
+
return result
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './BaseSchemasService.ts'
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
isChainIndexingServiceState,
|
|
26
26
|
readPayloadMapFromStore,
|
|
27
27
|
StakeIntentService,
|
|
28
|
+
timeBudget,
|
|
28
29
|
} from '@xyo-network/xl1-protocol-sdk'
|
|
29
30
|
import { Mutex } from 'async-mutex'
|
|
30
31
|
import { LRUCache } from 'lru-cache'
|
|
@@ -169,34 +170,36 @@ export class XyoStakeIntentService extends BaseService<XyoStakeIntentServicePara
|
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
private async recoverState(current: Hash): Promise<void> {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const state = await findFirstMatching(this.stakeIntentStateArchivist, predicate, opts)
|
|
182
|
-
if (isChainIndexingServiceState<SerializedIntervalMap>(state)) {
|
|
183
|
-
const indexed = (await this.chainArchivist.get([state.endBlockHash]))?.[0]
|
|
184
|
-
const indexedBlock = asBlockBoundWitnessWithStorageMeta(indexed)
|
|
185
|
-
if (indexedBlock) {
|
|
186
|
-
const indexedBlockNum = indexedBlock.block
|
|
187
|
-
if (indexedBlockNum <= currentBlockNum) {
|
|
188
|
-
const data = state.state as SerializedIntervalMap
|
|
189
|
-
this._producers = new IntervalMap(data)
|
|
190
|
-
this._lastIndexedBlockHash = indexedBlock._hash
|
|
191
|
-
break
|
|
192
|
-
}
|
|
173
|
+
return await timeBudget('XyoStakeIntentService.recoverState', console, async () => {
|
|
174
|
+
const currentBlock = assertEx(asBlockBoundWitness((await this.chainArchivist.get([current]))?.[0]), () => `Block ${current} not found`)
|
|
175
|
+
const currentBlockNum = currentBlock.block
|
|
176
|
+
// Find last state before current head (in case of rollback, we indexed past it on an uncle chain, etc.)
|
|
177
|
+
const opts: ArchivistNextOptions = { ...DEFAULT_FIND_FIRST_MATCHING_NEXT_OPTIONS }
|
|
178
|
+
while (true) {
|
|
179
|
+
const predicate = (p: WithStorageMeta<Payload>) => {
|
|
180
|
+
const state = asChainIndexingServiceStateWithStorageMeta(p)
|
|
181
|
+
return state ? true : false
|
|
193
182
|
}
|
|
194
|
-
|
|
183
|
+
const state = await findFirstMatching(this.stakeIntentStateArchivist, predicate, opts)
|
|
184
|
+
if (isChainIndexingServiceState<SerializedIntervalMap>(state)) {
|
|
185
|
+
const indexed = (await this.chainArchivist.get([state.endBlockHash]))?.[0]
|
|
186
|
+
const indexedBlock = asBlockBoundWitnessWithStorageMeta(indexed)
|
|
187
|
+
if (indexedBlock) {
|
|
188
|
+
const indexedBlockNum = indexedBlock.block
|
|
189
|
+
if (indexedBlockNum <= currentBlockNum) {
|
|
190
|
+
const data = state.state as SerializedIntervalMap
|
|
191
|
+
this._producers = new IntervalMap(data)
|
|
192
|
+
this._lastIndexedBlockHash = indexedBlock._hash
|
|
193
|
+
break
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
195
197
|
// No state found, start from genesis
|
|
196
|
-
|
|
198
|
+
break
|
|
199
|
+
}
|
|
200
|
+
opts.open = true
|
|
197
201
|
}
|
|
198
|
-
|
|
199
|
-
}
|
|
202
|
+
}, 2000, true)
|
|
200
203
|
}
|
|
201
204
|
|
|
202
205
|
private async updateIndex(displayProgress = false): Promise<void> {
|
|
@@ -207,29 +210,31 @@ export class XyoStakeIntentService extends BaseService<XyoStakeIntentServicePara
|
|
|
207
210
|
return await this.spanAsync('updateIndex', async () => {
|
|
208
211
|
const currentHead = await this.chainIterator.head()
|
|
209
212
|
if (isUndefined(currentHead)) return
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
213
|
+
return await timeBudget('XyoStakeIntentService.updateIndex', console, async () => {
|
|
214
|
+
const currentHeadHash = currentHead._hash
|
|
215
|
+
const chainMap = readPayloadMapFromStore<WithStorageMeta<Payload>>(this.chainArchivist)
|
|
216
|
+
const result = await analyzeChain({ chainMap }, [new ChainStakeIntentAnalyzer('producer')], currentHeadHash, this._lastIndexedBlockHash)
|
|
217
|
+
const signedDeclarations = filterAs(result.find(isChainSummaryStakeIntent)?.intents ?? [], asChainStakeIntent)
|
|
218
|
+
if (currentHead.block === undefined) return
|
|
219
|
+
const currentHeadBlockNum = currentHead.block
|
|
220
|
+
if (displayProgress) this.logger?.log(`Updating index through 0x${currentHeadBlockNum}`)
|
|
221
|
+
for (const signedDeclaration of signedDeclarations) {
|
|
222
|
+
const { exp, nbf } = signedDeclaration
|
|
223
|
+
const start = nbf
|
|
224
|
+
const stop = exp
|
|
225
|
+
const address = asAddress(signedDeclaration?.from)
|
|
226
|
+
if (start !== undefined && stop !== undefined && address !== undefined) {
|
|
227
|
+
this._producers.insert(address, start, stop)
|
|
228
|
+
}
|
|
224
229
|
}
|
|
225
|
-
|
|
226
|
-
/*
|
|
230
|
+
/*
|
|
227
231
|
if (index % STATE_PERSISTENCE_INTERVAL === 0n) {
|
|
228
232
|
if (displayProgress) this.logger?.info(`Persisting state at block ${index}`)
|
|
229
233
|
await this.persistState(await PayloadBuilder.hash(block))
|
|
230
234
|
}
|
|
231
235
|
*/
|
|
232
|
-
|
|
236
|
+
this._lastIndexedBlockHash = currentHeadHash
|
|
237
|
+
}, 2000, true)
|
|
233
238
|
})
|
|
234
239
|
})
|
|
235
240
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './Election/index.ts'
|
|
|
10
10
|
export * from './model/index.ts'
|
|
11
11
|
export * from './NetworkStakeStepReward/index.ts'
|
|
12
12
|
export * from './PendingTransactions/index.ts'
|
|
13
|
+
export * from './Schemas/index.ts'
|
|
13
14
|
export * from './StakeIntent/index.ts'
|
|
14
15
|
export * from './StepStake/index.ts'
|
|
15
16
|
export * from './Time/index.ts'
|