@xyo-network/xl1-protocol-sdk 1.18.0 → 1.18.2
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/CreatableProvider/AbstractCreatableProvider.d.ts +52 -21
- package/dist/neutral/CreatableProvider/AbstractCreatableProvider.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/CreatableProvider.d.ts +13 -8
- package/dist/neutral/CreatableProvider/CreatableProvider.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/CreatableProviderRegistry.d.ts +2 -4
- package/dist/neutral/CreatableProvider/CreatableProviderRegistry.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/ProviderFactory.d.ts +6 -4
- package/dist/neutral/CreatableProvider/ProviderFactory.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/ProviderFactoryLocator.d.ts +7 -7
- package/dist/neutral/CreatableProvider/ProviderFactoryLocator.d.ts.map +1 -1
- package/dist/neutral/CreatableProvider/ProviderFactoryLocatorInstance.d.ts +3 -2
- package/dist/neutral/CreatableProvider/ProviderFactoryLocatorInstance.d.ts.map +1 -1
- package/dist/neutral/actor/Actor.d.ts +176 -0
- package/dist/neutral/actor/Actor.d.ts.map +1 -0
- package/dist/neutral/actor/index.d.ts +2 -0
- package/dist/neutral/actor/index.d.ts.map +1 -0
- package/dist/neutral/block/hydrate/allHashesPresent.d.ts +2 -2
- package/dist/neutral/block/hydrate/allHashesPresent.d.ts.map +1 -1
- package/dist/neutral/block/hydrate/hydrateBlock.d.ts +2 -2
- package/dist/neutral/block/hydrate/hydrateBlock.d.ts.map +1 -1
- package/dist/neutral/config/Api.d.ts +1 -1
- package/dist/neutral/config/Api.d.ts.map +1 -1
- package/dist/neutral/config/Bridge.d.ts +41 -21
- package/dist/neutral/config/Bridge.d.ts.map +1 -1
- package/dist/neutral/config/Chain.d.ts +7 -3
- package/dist/neutral/config/Chain.d.ts.map +1 -1
- package/dist/neutral/config/Config.d.ts +48 -20
- package/dist/neutral/config/Config.d.ts.map +1 -1
- package/dist/neutral/config/Evm.d.ts +1 -1
- package/dist/neutral/config/Evm.d.ts.map +1 -1
- package/dist/neutral/config/Log.d.ts +2 -2
- package/dist/neutral/config/Log.d.ts.map +1 -1
- package/dist/neutral/config/Mempool.d.ts +1 -1
- package/dist/neutral/config/Mempool.d.ts.map +1 -1
- package/dist/neutral/config/Producer.d.ts +6 -2
- package/dist/neutral/config/Producer.d.ts.map +1 -1
- package/dist/neutral/config/RewardRedemptionApi.d.ts +1 -1
- package/dist/neutral/config/RewardRedemptionApi.d.ts.map +1 -1
- package/dist/neutral/config/Services.d.ts +1 -1
- package/dist/neutral/config/Services.d.ts.map +1 -1
- package/dist/neutral/config/Telemetry.d.ts +11 -4
- package/dist/neutral/config/Telemetry.d.ts.map +1 -1
- package/dist/neutral/config/UsageMeta.d.ts +1 -1
- package/dist/neutral/config/UsageMeta.d.ts.map +1 -1
- package/dist/neutral/config/Validation.d.ts +11 -3
- package/dist/neutral/config/Validation.d.ts.map +1 -1
- package/dist/neutral/config/index.d.ts +1 -0
- package/dist/neutral/config/index.d.ts.map +1 -1
- package/dist/neutral/config/storage/Storage.d.ts +1 -1
- package/dist/neutral/config/storage/Storage.d.ts.map +1 -1
- package/dist/neutral/config/storage/driver/Mongo.d.ts +1 -1
- package/dist/neutral/config/storage/driver/Mongo.d.ts.map +1 -1
- package/dist/neutral/eip-712/Payloads/EIP712Data.d.ts +4 -4
- package/dist/neutral/eip-712/Payloads/EIP712Data.d.ts.map +1 -1
- package/dist/neutral/eip-712/Payloads/EIP712Signature.d.ts +3 -3
- package/dist/neutral/eip-712/Payloads/EIP712Signature.d.ts.map +1 -1
- package/dist/neutral/eip-712/Types.d.ts +4 -4
- package/dist/neutral/eip-712/Types.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 +3271 -3246
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/model/ChainQualification.d.ts +15 -15
- package/dist/neutral/model/ChainQualification.d.ts.map +1 -1
- package/dist/neutral/payloads/netBalancesForPayloads.d.ts +5 -2
- package/dist/neutral/payloads/netBalancesForPayloads.d.ts.map +1 -1
- package/dist/neutral/payloads/netSchemasForPayloads.d.ts +5 -2
- package/dist/neutral/payloads/netSchemasForPayloads.d.ts.map +1 -1
- package/dist/neutral/primitives/chain/getWindowedChain.d.ts +8 -23
- package/dist/neutral/primitives/chain/getWindowedChain.d.ts.map +1 -1
- package/dist/neutral/primitives/rewards/networkStakeStepRewardPositionWeight.d.ts.map +1 -1
- package/dist/neutral/primitives/stake/weightedStakeForRangeByPosition.d.ts +2 -1
- package/dist/neutral/primitives/stake/weightedStakeForRangeByPosition.d.ts.map +1 -1
- package/dist/neutral/primitives/uncle/findBestUncle.d.ts +21 -13
- package/dist/neutral/primitives/uncle/findBestUncle.d.ts.map +1 -1
- package/dist/neutral/primitives/uncle/findUncles.d.ts +21 -14
- package/dist/neutral/primitives/uncle/findUncles.d.ts.map +1 -1
- package/dist/neutral/provider/signer/XyoSigner.d.ts +2 -0
- package/dist/neutral/provider/signer/XyoSigner.d.ts.map +1 -1
- package/dist/neutral/runners/Finalization.d.ts +12 -0
- package/dist/neutral/runners/Finalization.d.ts.map +1 -0
- package/dist/neutral/runners/index.d.ts +1 -0
- package/dist/neutral/runners/index.d.ts.map +1 -1
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +66 -33
- package/dist/neutral/simple/accountBalance/SimpleAccountBalanceViewer.d.ts.map +1 -1
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts +9 -25
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts.map +1 -1
- package/dist/neutral/simple/blockReward/SimpleBlockRewardViewer.d.ts +1 -0
- package/dist/neutral/simple/blockReward/SimpleBlockRewardViewer.d.ts.map +1 -1
- package/dist/neutral/simple/blockValidation/SimpleBlockValidationViewer.d.ts +4 -3
- package/dist/neutral/simple/blockValidation/SimpleBlockValidationViewer.d.ts.map +1 -1
- package/dist/neutral/simple/chainStake/SimpleStakeViewer.d.ts +1 -0
- package/dist/neutral/simple/chainStake/SimpleStakeViewer.d.ts.map +1 -1
- package/dist/neutral/simple/datalake/SimpleDataLakeRunner.d.ts +1 -0
- package/dist/neutral/simple/datalake/SimpleDataLakeRunner.d.ts.map +1 -1
- package/dist/neutral/simple/datalake/SimpleDataLakeViewer.d.ts +1 -0
- package/dist/neutral/simple/datalake/SimpleDataLakeViewer.d.ts.map +1 -1
- package/dist/neutral/simple/finalization/SimpleFinalizationRunner.d.ts +21 -0
- package/dist/neutral/simple/finalization/SimpleFinalizationRunner.d.ts.map +1 -0
- package/dist/neutral/simple/finalization/SimpleFinalizationViewer.d.ts +61 -0
- package/dist/neutral/simple/finalization/SimpleFinalizationViewer.d.ts.map +1 -0
- package/dist/neutral/simple/finalization/index.d.ts +3 -0
- package/dist/neutral/simple/finalization/index.d.ts.map +1 -0
- package/dist/neutral/simple/index.d.ts +2 -0
- package/dist/neutral/simple/index.d.ts.map +1 -1
- package/dist/neutral/simple/mempool/SimpleMempoolRunner.d.ts +2 -0
- package/dist/neutral/simple/mempool/SimpleMempoolRunner.d.ts.map +1 -1
- package/dist/neutral/simple/mempool/SimpleMempoolViewer.d.ts +7 -2
- package/dist/neutral/simple/mempool/SimpleMempoolViewer.d.ts.map +1 -1
- package/dist/neutral/simple/runner/SimpleXyoRunner.d.ts +1 -0
- package/dist/neutral/simple/runner/SimpleXyoRunner.d.ts.map +1 -1
- package/dist/neutral/simple/signer/SimpleXyoSigner.d.ts +19 -3
- package/dist/neutral/simple/signer/SimpleXyoSigner.d.ts.map +1 -1
- package/dist/neutral/simple/stakeEvents/SimpleStakeEventsViewer.d.ts +1 -0
- package/dist/neutral/simple/stakeEvents/SimpleStakeEventsViewer.d.ts.map +1 -1
- package/dist/neutral/simple/timesync/SimpleTimeSyncViewer.d.ts +2 -1
- package/dist/neutral/simple/timesync/SimpleTimeSyncViewer.d.ts.map +1 -1
- package/dist/neutral/simple/windowedBlock/SimpleWindowedBlockViewer.d.ts +191 -0
- package/dist/neutral/simple/windowedBlock/SimpleWindowedBlockViewer.d.ts.map +1 -0
- package/dist/neutral/simple/windowedBlock/index.d.ts +2 -0
- package/dist/neutral/simple/windowedBlock/index.d.ts.map +1 -0
- package/dist/neutral/summary/model/summary.d.ts +3 -1
- package/dist/neutral/summary/model/summary.d.ts.map +1 -1
- package/dist/neutral/summary/primitives/transfers/transfersSummary.d.ts +1 -1
- package/dist/neutral/summary/primitives/transfers/transfersSummary.d.ts.map +1 -1
- package/dist/neutral/transaction/TransactionBuilder.d.ts +56 -33
- package/dist/neutral/transaction/TransactionBuilder.d.ts.map +1 -1
- package/dist/neutral/transaction/signTransaction.d.ts +24 -12
- package/dist/neutral/transaction/signTransaction.d.ts.map +1 -1
- package/dist/neutral/utils/isZodError.d.ts +1 -1
- package/dist/neutral/utils/isZodError.d.ts.map +1 -1
- package/dist/neutral/validation/schema/Mnemonic.d.ts +1 -1
- package/dist/neutral/validation/schema/Mnemonic.d.ts.map +1 -1
- package/dist/neutral/viewers/AccountBalance.d.ts +70 -42
- package/dist/neutral/viewers/AccountBalance.d.ts.map +1 -1
- package/dist/neutral/viewers/Block.d.ts +2 -2
- package/dist/neutral/viewers/Block.d.ts.map +1 -1
- package/dist/neutral/viewers/BlockValidation.d.ts +10 -10
- package/dist/neutral/viewers/BlockValidation.d.ts.map +1 -1
- package/dist/neutral/viewers/Finalization.d.ts +14 -0
- package/dist/neutral/viewers/Finalization.d.ts.map +1 -0
- package/dist/neutral/viewers/Mempool.d.ts +5 -5
- package/dist/neutral/viewers/Mempool.d.ts.map +1 -1
- package/dist/neutral/viewers/TransactionValidation.d.ts +8 -8
- package/dist/neutral/viewers/TransactionValidation.d.ts.map +1 -1
- package/dist/neutral/viewers/WindowedBlock.d.ts +14 -0
- package/dist/neutral/viewers/WindowedBlock.d.ts.map +1 -0
- package/dist/neutral/viewers/index.d.ts +2 -0
- package/dist/neutral/viewers/index.d.ts.map +1 -1
- package/package.json +24 -22
- package/src/CreatableProvider/AbstractCreatableProvider.ts +12 -6
- package/src/CreatableProvider/CreatableProvider.ts +21 -9
- package/src/CreatableProvider/CreatableProviderRegistry.ts +3 -3
- package/src/CreatableProvider/ProviderFactory.ts +18 -10
- package/src/CreatableProvider/ProviderFactoryLocator.ts +6 -5
- package/src/CreatableProvider/ProviderFactoryLocatorInstance.ts +6 -2
- package/src/actor/Actor.ts +209 -0
- package/src/actor/index.ts +1 -0
- package/src/block/hydrate/allHashesPresent.ts +2 -2
- package/src/block/hydrate/hydrateBlock.ts +2 -2
- package/src/config/Api.ts +1 -2
- package/src/config/Bridge.ts +1 -2
- package/src/config/Chain.ts +1 -2
- package/src/config/Config.ts +1 -1
- package/src/config/Evm.ts +1 -2
- package/src/config/Log.ts +1 -2
- package/src/config/Mempool.ts +1 -2
- package/src/config/Producer.ts +1 -2
- package/src/config/RewardRedemptionApi.ts +1 -2
- package/src/config/Services.ts +1 -2
- package/src/config/Telemetry.ts +10 -4
- package/src/config/UsageMeta.ts +1 -1
- package/src/config/Validation.ts +1 -2
- package/src/config/index.ts +1 -0
- package/src/config/storage/Storage.ts +1 -2
- package/src/config/storage/driver/Mongo.ts +1 -2
- package/src/eip-712/Payloads/EIP712Data.ts +1 -1
- package/src/eip-712/Payloads/EIP712Signature.ts +1 -1
- package/src/eip-712/Types.ts +1 -1
- package/src/index.ts +1 -0
- package/src/model/ChainQualification.ts +1 -1
- package/src/primitives/chain/getWindowedChain.ts +33 -14
- package/src/primitives/rewards/networkStakeStepRewardPositionWeight.ts +3 -2
- package/src/primitives/stake/allStakersForStep.ts +1 -1
- package/src/primitives/stake/weightedStakeForRangeByPosition.ts +10 -2
- package/src/provider/signer/XyoSigner.ts +3 -0
- package/src/runners/Finalization.ts +15 -0
- package/src/runners/index.ts +1 -0
- package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +1 -0
- package/src/simple/block/SimpleBlockViewer.ts +23 -37
- package/src/simple/blockReward/SimpleBlockRewardViewer.ts +1 -0
- package/src/simple/blockValidation/SimpleBlockValidationViewer.ts +16 -13
- package/src/simple/chainStake/SimpleStakeViewer.ts +1 -0
- package/src/simple/datalake/SimpleDataLakeRunner.ts +1 -0
- package/src/simple/datalake/SimpleDataLakeViewer.ts +1 -0
- package/src/simple/finalization/SimpleFinalizationRunner.ts +45 -0
- package/src/simple/finalization/SimpleFinalizationViewer.ts +101 -0
- package/src/simple/finalization/index.ts +2 -0
- package/src/simple/index.ts +2 -0
- package/src/simple/mempool/SimpleMempoolRunner.ts +11 -1
- package/src/simple/mempool/SimpleMempoolViewer.ts +41 -8
- package/src/simple/runner/SimpleXyoRunner.ts +3 -1
- package/src/simple/signer/SimpleXyoSigner.ts +26 -5
- package/src/simple/stakeEvents/SimpleStakeEventsViewer.ts +1 -0
- package/src/simple/timesync/SimpleTimeSyncViewer.ts +3 -1
- package/src/simple/windowedBlock/SimpleWindowedBlockViewer.ts +208 -0
- package/src/simple/windowedBlock/index.ts +1 -0
- package/src/summary/model/summary.ts +3 -3
- package/src/summary/primitives/transfers/transfersSummary.ts +1 -1
- package/src/utils/isZodError.ts +1 -1
- package/src/validation/schema/Mnemonic.ts +1 -1
- package/src/viewers/AccountBalance.ts +1 -1
- package/src/viewers/Block.ts +2 -2
- package/src/viewers/BlockValidation.ts +1 -1
- package/src/viewers/Finalization.ts +19 -0
- package/src/viewers/Mempool.ts +1 -1
- package/src/viewers/TransactionValidation.ts +1 -1
- package/src/viewers/WindowedBlock.ts +17 -0
- package/src/viewers/index.ts +2 -0
package/src/config/Telemetry.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import { globalRegistry } from 'zod'
|
|
2
|
-
|
|
1
|
+
import { globalRegistry, z } from 'zod'
|
|
2
|
+
|
|
3
|
+
export const DefaultMetricsScrapePorts = {
|
|
4
|
+
api: 9465,
|
|
5
|
+
bridge: 9468,
|
|
6
|
+
mempool: 9466,
|
|
7
|
+
producer: 9464,
|
|
8
|
+
rewardRedemptionApi: 9467,
|
|
9
|
+
}
|
|
3
10
|
|
|
4
11
|
export const MetricsScrapeConfigZod = z.object({
|
|
5
12
|
path: z.string().default('/metrics').register(globalRegistry, {
|
|
@@ -8,8 +15,7 @@ export const MetricsScrapeConfigZod = z.object({
|
|
|
8
15
|
title: 'telemetry.metrics.scrape.path',
|
|
9
16
|
type: 'string',
|
|
10
17
|
}),
|
|
11
|
-
port: z.coerce.number().
|
|
12
|
-
default: 9464,
|
|
18
|
+
port: z.coerce.number().int().positive().optional().register(globalRegistry, {
|
|
13
19
|
description: 'Port for the metrics scrape endpoint',
|
|
14
20
|
title: 'telemetry.metrics.scrape.port',
|
|
15
21
|
type: 'number',
|
package/src/config/UsageMeta.ts
CHANGED
package/src/config/Validation.ts
CHANGED
package/src/config/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsObjectFactory, HashZod } from '@xylabs/sdk-js'
|
|
2
2
|
import { isPayloadOfZodType, type Payload } from '@xyo-network/payload-model'
|
|
3
|
-
import z from 'zod'
|
|
3
|
+
import { z } from 'zod'
|
|
4
4
|
|
|
5
5
|
export const EIP712SignaturePayloadFieldsZod = z.object({
|
|
6
6
|
address: z.string(),
|
package/src/eip-712/Types.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HashZod } from '@xylabs/hex'
|
|
2
2
|
import { zodIsFactory } from '@xylabs/zod'
|
|
3
3
|
import { XL1BlockRangeZod } from '@xyo-network/xl1-protocol'
|
|
4
|
-
import z from 'zod'
|
|
4
|
+
import { z } from 'zod'
|
|
5
5
|
|
|
6
6
|
export const ChainQualificationZod = z.object({ head: HashZod, range: XL1BlockRangeZod })
|
|
7
7
|
export type ChainQualification = z.infer<typeof ChainQualificationZod>
|
|
@@ -1,23 +1,42 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
assertEx, type Hash, isDefined, isNull,
|
|
3
|
+
} from '@xylabs/sdk-js'
|
|
2
4
|
import type { SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
3
5
|
|
|
4
6
|
import type { BlockViewer } from '../../viewers/index.ts'
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Constructs a bounded, contiguous canonical chain ending at the current head.
|
|
10
|
+
* @param blockViewer The BlockViewer to fetch blocks from
|
|
11
|
+
* @param maxWindowSize The maximum size of the windowed chain
|
|
12
|
+
* @param previousChain An optional previous chain to build upon
|
|
13
|
+
* @returns A promise that resolves to the windowed chain of blocks
|
|
14
|
+
*/
|
|
15
|
+
export async function getWindowedChain(blockViewer: BlockViewer, maxWindowSize: number, previousChain: SignedHydratedBlockWithHashMeta[] = []):
|
|
16
|
+
Promise<SignedHydratedBlockWithHashMeta[]> {
|
|
17
|
+
const newChain: SignedHydratedBlockWithHashMeta[] = []
|
|
18
|
+
const previousChainByHash = new Map<Hash, SignedHydratedBlockWithHashMeta>(previousChain.map(block => [block[0]._hash, block]))
|
|
19
|
+
const head = await blockViewer.currentBlock()
|
|
20
|
+
let currentBlock: SignedHydratedBlockWithHashMeta | null = head
|
|
9
21
|
console.log('[getWindowedChain] Current Block:', currentBlock?.[0]._hash)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
22
|
+
while (currentBlock !== null && newChain.length < maxWindowSize) {
|
|
23
|
+
const currentBlockNumber = currentBlock[0].block
|
|
24
|
+
const nextBlock = newChain[0]
|
|
25
|
+
if (isDefined(nextBlock)) {
|
|
26
|
+
const nextBlockNumber = nextBlock[0].block
|
|
27
|
+
assertEx(
|
|
28
|
+
currentBlockNumber === nextBlockNumber - 1,
|
|
29
|
+
() => `[getWindowedChain] Non-monotonic block sequence detected: current=${currentBlockNumber}, next=${nextBlockNumber}`,
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
assertEx(
|
|
33
|
+
currentBlockNumber <= head[0].block,
|
|
34
|
+
() => `[getWindowedChain] Current block number (${currentBlockNumber}) exceeds head block number (${head[0].block})`,
|
|
35
|
+
)
|
|
36
|
+
newChain.unshift(currentBlock)
|
|
13
37
|
const previousBlockHash: Hash | null = currentBlock[0].previous
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const newChain = [...previousChain, ...newBlocks].slice(-maxWindowSize)
|
|
17
|
-
while (newChain.length > 0 && newChain.length < maxWindowSize && newChain[0][0].previous !== null) {
|
|
18
|
-
const block = await blockViewer.blockByHash(newChain[0][0].previous!)
|
|
19
|
-
if (block === null) break
|
|
20
|
-
newChain.unshift(block)
|
|
38
|
+
if (isNull(previousBlockHash)) break
|
|
39
|
+
currentBlock = previousChainByHash.get(previousBlockHash) ?? await blockViewer.blockByHash(previousBlockHash)
|
|
21
40
|
}
|
|
22
41
|
return newChain
|
|
23
42
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type StepIdentity } from '@xyo-network/xl1-protocol'
|
|
1
|
+
import { type StepIdentity, XYO_NETWORK_STAKING_ADDRESS } from '@xyo-network/xl1-protocol'
|
|
2
2
|
|
|
3
3
|
import type { StakedChainContextRead } from '../../model/index.ts'
|
|
4
4
|
import type { BlockViewer } from '../../viewers/index.ts'
|
|
5
|
-
import { externalBlockRangeFromStep } from '../chain/
|
|
5
|
+
import { externalBlockRangeFromStep } from '../chain/index.ts'
|
|
6
6
|
import { weightedStakeForRangeByPosition } from '../stake/index.ts'
|
|
7
7
|
|
|
8
8
|
export async function networkStakeStepRewardPositionWeight(
|
|
@@ -15,6 +15,7 @@ export async function networkStakeStepRewardPositionWeight(
|
|
|
15
15
|
context,
|
|
16
16
|
blockViewer,
|
|
17
17
|
await externalBlockRangeFromStep(context, blockViewer, stepContext),
|
|
18
|
+
XYO_NETWORK_STAKING_ADDRESS,
|
|
18
19
|
position,
|
|
19
20
|
)
|
|
20
21
|
return result
|
|
@@ -3,7 +3,7 @@ import type { StepIdentity } from '@xyo-network/xl1-protocol'
|
|
|
3
3
|
|
|
4
4
|
import type { StakedChainContextRead } from '../../model/index.ts'
|
|
5
5
|
import type { BlockViewer } from '../../viewers/index.ts'
|
|
6
|
-
import { externalBlockRangeFromXL1BlockRange } from '../chain/
|
|
6
|
+
import { externalBlockRangeFromXL1BlockRange } from '../chain/index.ts'
|
|
7
7
|
import { stepBlockRange } from '../step/index.ts'
|
|
8
8
|
import { allStakersForRange } from './allStakersForRange.ts'
|
|
9
9
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Address } from '@xylabs/sdk-js'
|
|
1
2
|
import { isDefined } from '@xylabs/sdk-js'
|
|
2
3
|
import { asBlockNumber, type BlockRange } from '@xyo-network/xl1-protocol'
|
|
3
4
|
|
|
@@ -9,6 +10,7 @@ export async function weightedStakeForRangeByPosition(
|
|
|
9
10
|
context: StakedChainContextRead,
|
|
10
11
|
blockViewer: BlockViewer,
|
|
11
12
|
externalRange: BlockRange, // first to last block of step
|
|
13
|
+
staked?: Address,
|
|
12
14
|
positionId?: number,
|
|
13
15
|
): Promise<bigint> {
|
|
14
16
|
const cacheKey = isDefined(positionId) ? `${externalRange[0]}-${externalRange[1]}-${positionId}` : `${externalRange[0]}-${externalRange[1]}-all`
|
|
@@ -22,6 +24,12 @@ export async function weightedStakeForRangeByPosition(
|
|
|
22
24
|
)).toSorted((a, b) => a.time - b.time)
|
|
23
25
|
let currentTime = externalRange[0]
|
|
24
26
|
let currentStake = 0n // await activeStakeAtTimeByPosition(chainEvents, pos.staked, currentTime - 1, position)
|
|
27
|
+
|
|
28
|
+
// if not staking the desired address, return 0n
|
|
29
|
+
if (isDefined(staked) && mergedEvents[0].args.staked !== staked) {
|
|
30
|
+
return 0n
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
for (const event of mergedEvents) {
|
|
26
34
|
if (event.time > currentTime) {
|
|
27
35
|
// Add the weighted stake for the period between the range start or previous event and this event
|
|
@@ -44,9 +52,9 @@ export async function weightedStakeForRangeByPosition(
|
|
|
44
52
|
weightedStakeSum += currentStake * BigInt(externalRange[1] - currentTime)
|
|
45
53
|
}
|
|
46
54
|
} else {
|
|
47
|
-
const positionCount = await context.stake.stakeEvents.positionCount(externalRange)
|
|
55
|
+
const positionCount = await context.stake.stakeEvents.positionCount([0, externalRange[1]])
|
|
48
56
|
for (let pos = 0; pos < positionCount; pos++) {
|
|
49
|
-
weightedStakeSum += await weightedStakeForRangeByPosition(context, blockViewer, externalRange, pos)
|
|
57
|
+
weightedStakeSum += await weightedStakeForRangeByPosition(context, blockViewer, externalRange, staked, pos)
|
|
50
58
|
}
|
|
51
59
|
}
|
|
52
60
|
return weightedStakeSum
|
|
@@ -7,6 +7,9 @@ import type {
|
|
|
7
7
|
TransactionFeesBigInt,
|
|
8
8
|
} from '@xyo-network/xl1-protocol'
|
|
9
9
|
|
|
10
|
+
export const XyoSignerMoniker = 'XyoSigner' as const
|
|
11
|
+
export type XyoSignerMoniker = typeof XyoSignerMoniker
|
|
12
|
+
|
|
10
13
|
export interface XyoSigner {
|
|
11
14
|
address(): Promisable<Address>
|
|
12
15
|
// The tx passed in must have all the payloads (on and off chain) in the payloads array
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
+
import type { SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
3
|
+
|
|
4
|
+
import type { Provider } from '../model/index.ts'
|
|
5
|
+
|
|
6
|
+
export interface FinalizationRunnerMethods {
|
|
7
|
+
finalizeBlocks(blocks: SignedHydratedBlockWithHashMeta[]): Promise<Hash[]>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const FinalizationRunnerMoniker = 'FinalizationRunner' as const
|
|
11
|
+
export type FinalizationRunnerMoniker = typeof FinalizationRunnerMoniker
|
|
12
|
+
|
|
13
|
+
export interface FinalizationRunner extends FinalizationRunnerMethods, Provider<FinalizationRunnerMoniker> {
|
|
14
|
+
finalizeBlock(block: SignedHydratedBlockWithHashMeta): Promise<Hash>
|
|
15
|
+
}
|
package/src/runners/index.ts
CHANGED
|
@@ -44,6 +44,7 @@ export interface SimpleAccountBalanceViewerParams extends CreatableProviderParam
|
|
|
44
44
|
@creatableProvider()
|
|
45
45
|
export class SimpleAccountBalanceViewer extends AbstractCreatableProvider<SimpleAccountBalanceViewerParams> implements AccountBalanceViewer {
|
|
46
46
|
static readonly defaultMoniker = AccountBalanceViewerMoniker
|
|
47
|
+
static readonly dependencies = [BlockViewerMoniker]
|
|
47
48
|
static readonly monikers = [AccountBalanceViewerMoniker]
|
|
48
49
|
moniker = SimpleAccountBalanceViewer.defaultMoniker
|
|
49
50
|
|
|
@@ -7,12 +7,14 @@ import {
|
|
|
7
7
|
spanRootAsync,
|
|
8
8
|
} from '@xylabs/sdk-js'
|
|
9
9
|
import type { ReadArchivist } from '@xyo-network/archivist-model'
|
|
10
|
-
import type { Payload,
|
|
10
|
+
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
11
11
|
import {
|
|
12
12
|
asSignedHydratedBlockWithHashMeta,
|
|
13
|
+
asSignedHydratedBlockWithStorageMeta,
|
|
13
14
|
asXL1BlockNumber,
|
|
14
15
|
ChainId,
|
|
15
16
|
type SignedHydratedBlockWithHashMeta,
|
|
17
|
+
SignedHydratedBlockWithStorageMeta,
|
|
16
18
|
type XL1BlockNumber,
|
|
17
19
|
} from '@xyo-network/xl1-protocol'
|
|
18
20
|
|
|
@@ -24,11 +26,11 @@ import type {
|
|
|
24
26
|
ChainContextRead,
|
|
25
27
|
ChainStoreRead, PayloadMap,
|
|
26
28
|
} from '../../model/index.ts'
|
|
27
|
-
import {
|
|
28
|
-
findMostRecentBlock, hydratedBlockByNumber, readPayloadMapFromStore,
|
|
29
|
-
} from '../../primitives/index.ts'
|
|
29
|
+
import { hydratedBlockByNumber, readPayloadMapFromStore } from '../../primitives/index.ts'
|
|
30
30
|
import { HydratedCache } from '../../utils/index.ts'
|
|
31
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
type BlockViewer, BlockViewerMoniker, FinalizationViewer, FinalizationViewerMoniker,
|
|
33
|
+
} from '../../viewers/index.ts'
|
|
32
34
|
|
|
33
35
|
export interface SimpleBlockViewerParams extends CreatableProviderParams {
|
|
34
36
|
finalizedArchivist: ReadArchivist
|
|
@@ -37,36 +39,38 @@ export interface SimpleBlockViewerParams extends CreatableProviderParams {
|
|
|
37
39
|
@creatableProvider()
|
|
38
40
|
export class SimpleBlockViewer extends AbstractCreatableProvider<SimpleBlockViewerParams> implements BlockViewer {
|
|
39
41
|
static readonly defaultMoniker = BlockViewerMoniker
|
|
42
|
+
static readonly dependencies = [FinalizationViewerMoniker]
|
|
40
43
|
static readonly monikers = [BlockViewerMoniker]
|
|
41
44
|
moniker = SimpleBlockViewer.defaultMoniker
|
|
42
45
|
|
|
43
46
|
protected _store: ChainStoreRead | undefined
|
|
47
|
+
protected finalizationViewer!: FinalizationViewer
|
|
44
48
|
|
|
45
|
-
private _payloadCache: PayloadMap<
|
|
46
|
-
private _signedHydratedBlockCache: HydratedCache<
|
|
49
|
+
private _payloadCache: PayloadMap<WithStorageMeta<Payload>> | undefined
|
|
50
|
+
private _signedHydratedBlockCache: HydratedCache<SignedHydratedBlockWithStorageMeta> | undefined
|
|
47
51
|
|
|
48
52
|
get finalizedArchivist(): ReadArchivist {
|
|
49
53
|
return this.params.finalizedArchivist!
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
protected get hydratedBlockCache(): HydratedCache<
|
|
56
|
+
protected get hydratedBlockCache(): HydratedCache<SignedHydratedBlockWithStorageMeta> {
|
|
53
57
|
if (this._signedHydratedBlockCache) return this._signedHydratedBlockCache
|
|
54
58
|
const chainMap = this.store.chainMap
|
|
55
|
-
this._signedHydratedBlockCache = new HydratedCache<
|
|
59
|
+
this._signedHydratedBlockCache = new HydratedCache<SignedHydratedBlockWithStorageMeta>(chainMap, async (
|
|
56
60
|
store: ChainStoreRead,
|
|
57
61
|
hash: Hash,
|
|
58
62
|
maxDepth?: number,
|
|
59
63
|
minDepth?: number,
|
|
60
64
|
) => {
|
|
61
65
|
const result = await hydrateBlock(store, hash, maxDepth, minDepth)
|
|
62
|
-
return
|
|
66
|
+
return asSignedHydratedBlockWithStorageMeta(result, true)
|
|
63
67
|
}, 200)
|
|
64
68
|
return this._signedHydratedBlockCache
|
|
65
69
|
}
|
|
66
70
|
|
|
67
|
-
protected get payloadCache(): PayloadMap<
|
|
71
|
+
protected get payloadCache(): PayloadMap<WithStorageMeta<Payload>> {
|
|
68
72
|
if (this._payloadCache) return this._payloadCache
|
|
69
|
-
this._payloadCache = new LruCacheMap<Hash,
|
|
73
|
+
this._payloadCache = new LruCacheMap<Hash, WithStorageMeta<Payload>>({ max: 10_000 })
|
|
70
74
|
return this._payloadCache
|
|
71
75
|
}
|
|
72
76
|
|
|
@@ -89,7 +93,7 @@ export class SimpleBlockViewer extends AbstractCreatableProvider<SimpleBlockView
|
|
|
89
93
|
|
|
90
94
|
async blockByNumber(blockNumber: XL1BlockNumber): Promise<SignedHydratedBlockWithHashMeta | null> {
|
|
91
95
|
return await spanRootAsync('blockByNumber', async () => {
|
|
92
|
-
const head = await this.
|
|
96
|
+
const [head] = await this.currentBlock()
|
|
93
97
|
if (isUndefined(head)) {
|
|
94
98
|
return null
|
|
95
99
|
}
|
|
@@ -151,36 +155,23 @@ export class SimpleBlockViewer extends AbstractCreatableProvider<SimpleBlockView
|
|
|
151
155
|
|
|
152
156
|
override async createHandler() {
|
|
153
157
|
await super.createHandler()
|
|
158
|
+
this.finalizationViewer = await this.locator.getInstance<FinalizationViewer>(FinalizationViewerMoniker)
|
|
154
159
|
this._store = { chainMap: readPayloadMapFromStore(this.params.finalizedArchivist) }
|
|
155
160
|
}
|
|
156
161
|
|
|
157
162
|
async currentBlock(): Promise<SignedHydratedBlockWithHashMeta> {
|
|
158
|
-
return await
|
|
159
|
-
const currentHead = assertEx(await this.getCurrentHead(), () => 'Could not find most recent block [currentBlock]')
|
|
160
|
-
const cache = this.hydratedBlockCache
|
|
161
|
-
const block = await cache.get(currentHead._hash)
|
|
162
|
-
if (!block) {
|
|
163
|
-
console.log(`Could not find current block with hash ${currentHead!._hash}`)
|
|
164
|
-
}
|
|
165
|
-
return assertEx(block, () => 'Could not find current block')
|
|
166
|
-
}, this.tracer)
|
|
163
|
+
return await this.finalizationViewer.head()
|
|
167
164
|
}
|
|
168
165
|
|
|
169
166
|
async currentBlockHash(): Promise<Hash> {
|
|
170
|
-
return await
|
|
171
|
-
const currentHead = assertEx(await this.getCurrentHead(), () => 'Could not find most recent block [currentBlockHash]')
|
|
172
|
-
return currentHead._hash
|
|
173
|
-
}, this.tracer)
|
|
167
|
+
return await this.finalizationViewer.headHash()
|
|
174
168
|
}
|
|
175
169
|
|
|
176
170
|
async currentBlockNumber(): Promise<XL1BlockNumber> {
|
|
177
|
-
return await
|
|
178
|
-
const currentHead = assertEx(await this.getCurrentHead(), () => 'Could not find most recent block [currentBlockNumber]')
|
|
179
|
-
return asXL1BlockNumber(currentHead.block, { name: 'currentBlockNumber' })
|
|
180
|
-
}, this.tracer)
|
|
171
|
+
return await this.finalizationViewer.headNumber()
|
|
181
172
|
}
|
|
182
173
|
|
|
183
|
-
async payloadByHash(hash: Hash): Promise<
|
|
174
|
+
async payloadByHash(hash: Hash): Promise<WithStorageMeta<Payload> | null> {
|
|
184
175
|
const cachedPayload = await this.payloadCache.get(hash)
|
|
185
176
|
if (cachedPayload) {
|
|
186
177
|
return cachedPayload
|
|
@@ -193,7 +184,7 @@ export class SimpleBlockViewer extends AbstractCreatableProvider<SimpleBlockView
|
|
|
193
184
|
}
|
|
194
185
|
}
|
|
195
186
|
|
|
196
|
-
async payloadsByHash(hashes: Hash[]): Promise<
|
|
187
|
+
async payloadsByHash(hashes: Hash[]): Promise<WithStorageMeta<Payload>[]> {
|
|
197
188
|
let remainingHashes = [...hashes]
|
|
198
189
|
const cachedPayloads = await this.payloadCache.getMany(remainingHashes)
|
|
199
190
|
const cachedHashes = new Set(cachedPayloads.map(p => p._hash))
|
|
@@ -203,9 +194,4 @@ export class SimpleBlockViewer extends AbstractCreatableProvider<SimpleBlockView
|
|
|
203
194
|
: []
|
|
204
195
|
return [...cachedPayloads, ...remainingPayloads.filter(exists)]
|
|
205
196
|
}
|
|
206
|
-
|
|
207
|
-
protected async getCurrentHead() {
|
|
208
|
-
const chainArchivist = this.finalizedArchivist
|
|
209
|
-
return await findMostRecentBlock(chainArchivist)
|
|
210
|
-
}
|
|
211
197
|
}
|
|
@@ -19,6 +19,7 @@ export interface SimpleBlockRewardViewerParams extends CreatableProviderParams {
|
|
|
19
19
|
@creatableProvider()
|
|
20
20
|
export class SimpleBlockRewardViewer extends AbstractCreatableProvider<SimpleBlockRewardViewerParams> implements BlockRewardViewer {
|
|
21
21
|
static readonly defaultMoniker = BlockRewardViewerMoniker
|
|
22
|
+
static readonly dependencies = []
|
|
22
23
|
static readonly monikers = [BlockRewardViewerMoniker]
|
|
23
24
|
moniker = SimpleBlockRewardViewer.defaultMoniker
|
|
24
25
|
|
|
@@ -24,13 +24,14 @@ import {
|
|
|
24
24
|
|
|
25
25
|
export interface SimpleBlockValidationViewerParams extends CreatableProviderParams {
|
|
26
26
|
maxUncleWindowSize: number
|
|
27
|
+
protocol?: HydratedBlockValidationFunction
|
|
27
28
|
state?: HydratedBlockStateValidationFunction
|
|
28
|
-
value?: HydratedBlockValidationFunction
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
@creatableProvider()
|
|
32
32
|
export class SimpleBlockValidationViewer extends AbstractCreatableProvider<SimpleBlockValidationViewerParams> implements BlockValidationViewer {
|
|
33
33
|
static readonly defaultMoniker = BlockValidationViewerMoniker
|
|
34
|
+
static readonly dependencies = [AccountBalanceViewerMoniker, BlockViewerMoniker]
|
|
34
35
|
static readonly monikers = [BlockValidationViewerMoniker]
|
|
35
36
|
moniker = SimpleBlockValidationViewer.defaultMoniker
|
|
36
37
|
|
|
@@ -77,11 +78,11 @@ export class SimpleBlockValidationViewer extends AbstractCreatableProvider<Simpl
|
|
|
77
78
|
const [headBlock] = await this.blockViewer.currentBlock()
|
|
78
79
|
const chainId = headBlock.chain
|
|
79
80
|
|
|
80
|
-
const
|
|
81
|
+
const validateProtocol = value ? this.doValidateProtocol.bind(this) : undefined
|
|
81
82
|
const validateState = state ? this.doValidateState.bind(this) : undefined
|
|
82
83
|
|
|
83
84
|
return [(await Promise.all([
|
|
84
|
-
|
|
85
|
+
validateProtocol?.(blocks, chainId), validateState?.(blocks, chainId),
|
|
85
86
|
].filter(exists))).flat(), { head: headBlock._hash, range: asXL1BlockRange([0, headBlock.block], true) }]
|
|
86
87
|
}
|
|
87
88
|
|
|
@@ -93,13 +94,24 @@ export class SimpleBlockValidationViewer extends AbstractCreatableProvider<Simpl
|
|
|
93
94
|
return (await this.qualifiedValidateBlocks(blocks, config))[0]
|
|
94
95
|
}
|
|
95
96
|
|
|
97
|
+
private async doValidateProtocol(blocks: SignedHydratedBlockWithHashMeta[], chainId: ChainId): Promise<HydratedBlockValidationError[]> {
|
|
98
|
+
return (await Promise.all(blocks.map(async (block) => {
|
|
99
|
+
return await this.params.protocol!(
|
|
100
|
+
block,
|
|
101
|
+
chainId,
|
|
102
|
+
)
|
|
103
|
+
}))).flat()
|
|
104
|
+
}
|
|
105
|
+
|
|
96
106
|
private async doValidateState(blocks: SignedHydratedBlockWithHashMeta[], chainId: ChainId): Promise<HydratedBlockValidationError[]> {
|
|
97
107
|
const windowedUncleChain = await this.updateWindowedChainCache()
|
|
98
108
|
|
|
99
109
|
const uncles = findUncles(this.context, windowedUncleChain, blocks)
|
|
100
110
|
|
|
101
111
|
if (uncles.length !== 1) {
|
|
102
|
-
|
|
112
|
+
this.logger?.warn(JSON.stringify({ uncles, blocks }, null, 2))
|
|
113
|
+
this.logger?.warn(JSON.stringify(windowedUncleChain, null, 2))
|
|
114
|
+
throw new Error(`No uncles or greater than one uncle found in block validation, which is not supported [${uncles.length}, ${blocks.length}]`)
|
|
103
115
|
}
|
|
104
116
|
return (await Promise.all(uncles[0].map(async (block) => {
|
|
105
117
|
return await this.params.state!(
|
|
@@ -110,15 +122,6 @@ export class SimpleBlockValidationViewer extends AbstractCreatableProvider<Simpl
|
|
|
110
122
|
}))).flat()
|
|
111
123
|
}
|
|
112
124
|
|
|
113
|
-
private async doValidateValue(blocks: SignedHydratedBlockWithHashMeta[], chainId: ChainId): Promise<HydratedBlockValidationError[]> {
|
|
114
|
-
return (await Promise.all(blocks.map(async (block) => {
|
|
115
|
-
return await this.params.value!(
|
|
116
|
-
block,
|
|
117
|
-
chainId,
|
|
118
|
-
)
|
|
119
|
-
}))).flat()
|
|
120
|
-
}
|
|
121
|
-
|
|
122
125
|
private async updateWindowedChainCache() {
|
|
123
126
|
this._uncleWindowedChainCache = await getWindowedChain(this.blockViewer, this.maxUncleWindowSize, this._uncleWindowedChainCache ?? [])
|
|
124
127
|
return [...this._uncleWindowedChainCache]
|
|
@@ -21,6 +21,7 @@ export interface SimpleChainStakeParams extends CreatableProviderParams {
|
|
|
21
21
|
@creatableProvider()
|
|
22
22
|
export class SimpleStakeViewer extends AbstractCreatableProvider<SimpleChainStakeParams> implements StakeViewer {
|
|
23
23
|
static readonly defaultMoniker = StakeViewerMoniker
|
|
24
|
+
static readonly dependencies = [StakeEventsViewerMoniker]
|
|
24
25
|
static readonly monikers = [StakeViewerMoniker]
|
|
25
26
|
moniker = SimpleStakeViewer.defaultMoniker
|
|
26
27
|
|
|
@@ -16,6 +16,7 @@ export interface DataLakeRunnerParams extends DataLakeViewerParams<MapType<Hash,
|
|
|
16
16
|
export class SimpleDataLakeRunner<TParams extends DataLakeRunnerParams> extends
|
|
17
17
|
AbstractSimpleDataLake<TParams> implements DataLakeRunner {
|
|
18
18
|
static readonly defaultMoniker = DataLakeRunnerMoniker
|
|
19
|
+
static readonly dependencies = []
|
|
19
20
|
static readonly monikers = [DataLakeRunnerMoniker]
|
|
20
21
|
moniker = SimpleDataLakeRunner.defaultMoniker
|
|
21
22
|
|
|
@@ -17,6 +17,7 @@ export interface DataLakeViewerParams<TMap extends MapTypeRead<Hash, DataLakeDat
|
|
|
17
17
|
export class SimpleDataLakeViewer<TParams extends DataLakeViewerParams = DataLakeViewerParams>
|
|
18
18
|
extends AbstractSimpleDataLake<TParams> implements DataLakeViewer {
|
|
19
19
|
static readonly defaultMoniker = DataLakeViewerMoniker
|
|
20
|
+
static readonly dependencies = []
|
|
20
21
|
static readonly monikers = [DataLakeViewerMoniker]
|
|
21
22
|
moniker = SimpleDataLakeViewer.defaultMoniker
|
|
22
23
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type Hash } from '@xylabs/sdk-js'
|
|
2
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
+
import { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
4
|
+
import { type SignedHydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
AbstractCreatableProvider, creatableProvider, CreatableProviderParams,
|
|
8
|
+
} from '../../CreatableProvider/index.ts'
|
|
9
|
+
import { ChainStoreWrite } from '../../model/index.ts'
|
|
10
|
+
import { payloadMapFromStore } from '../../primitives/index.ts'
|
|
11
|
+
import { type FinalizationRunner, FinalizationRunnerMoniker } from '../../runners/index.ts'
|
|
12
|
+
|
|
13
|
+
export interface SimpleFinalizationRunnerParams extends CreatableProviderParams {
|
|
14
|
+
finalizedArchivist: ArchivistInstance
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@creatableProvider()
|
|
18
|
+
export class SimpleFinalizationRunner extends AbstractCreatableProvider<SimpleFinalizationRunnerParams> implements FinalizationRunner {
|
|
19
|
+
static readonly defaultMoniker = FinalizationRunnerMoniker
|
|
20
|
+
static readonly dependencies = []
|
|
21
|
+
static readonly monikers = [FinalizationRunnerMoniker]
|
|
22
|
+
moniker = SimpleFinalizationRunner.defaultMoniker
|
|
23
|
+
|
|
24
|
+
protected _store: ChainStoreWrite | undefined
|
|
25
|
+
|
|
26
|
+
protected get store() {
|
|
27
|
+
return this._store!
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override async createHandler() {
|
|
31
|
+
await super.createHandler()
|
|
32
|
+
this._store = { chainMap: payloadMapFromStore(this.params.finalizedArchivist) }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async finalizeBlock(block: SignedHydratedBlockWithHashMeta): Promise<Hash> {
|
|
36
|
+
return (await this.finalizeBlocks([block]))[0]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async finalizeBlocks(blocks: SignedHydratedBlockWithHashMeta[]): Promise<Hash[]> {
|
|
40
|
+
const sortedBlocks = blocks.toSorted((a, b) => a[0].block - b[0].block)
|
|
41
|
+
const payloads = sortedBlocks.flatMap(block => [...block[1], block[0]].map(p => ([p._hash, p] as [Hash, WithStorageMeta<Payload>])))
|
|
42
|
+
await this.store.chainMap.setMany(payloads)
|
|
43
|
+
return sortedBlocks.map(b => b[0]._hash)
|
|
44
|
+
}
|
|
45
|
+
}
|