@xyo-network/chain-services 1.17.7 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts +3 -3
- package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
- package/dist/neutral/BaseService.d.ts +2 -2
- package/dist/neutral/BaseService.d.ts.map +1 -1
- package/dist/neutral/ChainService/Evm/Evm.d.ts +3 -4
- package/dist/neutral/ChainService/Evm/Evm.d.ts.map +1 -1
- package/dist/neutral/ChainService/Memory/Memory.d.ts +3 -4
- package/dist/neutral/ChainService/Memory/Memory.d.ts.map +1 -1
- package/dist/neutral/ChainValidator/XyoValidator.d.ts +4 -2
- package/dist/neutral/ChainValidator/XyoValidator.d.ts.map +1 -1
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts +0 -1
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts.map +1 -1
- package/dist/neutral/Schemas/BaseSchemasService.d.ts +1 -1
- package/dist/neutral/Schemas/BaseSchemasService.d.ts.map +1 -1
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts +5 -3
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
- package/dist/neutral/blockViewerFromChainIteratorAndArchivist.d.ts.map +1 -1
- package/dist/neutral/implementation/chain/evm.d.ts +2 -2
- package/dist/neutral/implementation/chain/evm.d.ts.map +1 -1
- package/dist/neutral/implementation/chain/index.d.ts +2 -3
- package/dist/neutral/implementation/chain/index.d.ts.map +1 -1
- package/dist/neutral/implementation/head/createBootstrapHead.d.ts +3 -3
- package/dist/neutral/implementation/head/createBootstrapHead.d.ts.map +1 -1
- package/dist/neutral/implementation/head/index.d.ts +1 -1
- package/dist/neutral/implementation/head/index.d.ts.map +1 -1
- package/dist/neutral/implementation/index.d.ts +0 -9
- package/dist/neutral/implementation/index.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +0 -2
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +378 -997
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/model/Params.d.ts +3 -4
- package/dist/neutral/model/Params.d.ts.map +1 -1
- package/dist/neutral/simple/block/runner/SimpleBlockRunner.d.ts +25 -33
- package/dist/neutral/simple/block/runner/SimpleBlockRunner.d.ts.map +1 -1
- package/package.json +15 -17
- package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +10 -16
- package/src/BaseService.ts +3 -2
- package/src/ChainService/Evm/Evm.ts +24 -37
- package/src/ChainService/Memory/Memory.ts +6 -12
- package/src/ChainValidator/XyoValidator.ts +11 -4
- package/src/PendingTransactions/BasePendingTransactions.ts +2 -6
- package/src/Schemas/BaseSchemasService.ts +2 -2
- package/src/StakeIntent/XyoStakeIntentService.ts +12 -8
- package/src/blockViewerFromChainIteratorAndArchivist.ts +9 -0
- package/src/implementation/chain/evm.ts +5 -5
- package/src/implementation/chain/index.ts +12 -14
- package/src/implementation/head/createBootstrapHead.ts +13 -8
- package/src/implementation/head/index.ts +1 -1
- package/src/implementation/index.ts +0 -9
- package/src/index.ts +0 -2
- package/src/model/Params.ts +4 -4
- package/src/simple/block/runner/SimpleBlockRunner.ts +122 -122
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts +0 -50
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts.map +0 -1
- package/dist/neutral/ChainBlockNumberIteration/index.d.ts +0 -3
- package/dist/neutral/ChainBlockNumberIteration/index.d.ts.map +0 -1
- package/dist/neutral/ChainBlockNumberIteration/model/BlockNumberIteration.d.ts +0 -7
- package/dist/neutral/ChainBlockNumberIteration/model/BlockNumberIteration.d.ts.map +0 -1
- package/dist/neutral/ChainBlockNumberIteration/model/Params.d.ts +0 -9
- package/dist/neutral/ChainBlockNumberIteration/model/Params.d.ts.map +0 -1
- package/dist/neutral/ChainBlockNumberIteration/model/index.d.ts +0 -3
- package/dist/neutral/ChainBlockNumberIteration/model/index.d.ts.map +0 -1
- package/dist/neutral/Time/BaseTimeSyncService.d.ts +0 -24
- package/dist/neutral/Time/BaseTimeSyncService.d.ts.map +0 -1
- package/dist/neutral/Time/index.d.ts +0 -2
- package/dist/neutral/Time/index.d.ts.map +0 -1
- package/dist/neutral/implementation/accountBalance.d.ts +0 -7
- package/dist/neutral/implementation/accountBalance.d.ts.map +0 -1
- package/dist/neutral/implementation/blockViewer.d.ts +0 -7
- package/dist/neutral/implementation/blockViewer.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/config/getBridgeDestinationDetails.d.ts +0 -8
- package/dist/neutral/implementation/head/createForkedHead/config/getBridgeDestinationDetails.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/config/getBridgeSourceDetails.d.ts +0 -9
- package/dist/neutral/implementation/head/createForkedHead/config/getBridgeSourceDetails.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/config/getForkDetails.d.ts +0 -4
- package/dist/neutral/implementation/head/createForkedHead/config/getForkDetails.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/config/index.d.ts +0 -4
- package/dist/neutral/implementation/head/createForkedHead/config/index.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/createForkedHead.d.ts +0 -5
- package/dist/neutral/implementation/head/createForkedHead/createForkedHead.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/getBridgeDestinationObservation.d.ts +0 -11
- package/dist/neutral/implementation/head/createForkedHead/getBridgeDestinationObservation.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/getBridgeIntent.d.ts +0 -11
- package/dist/neutral/implementation/head/createForkedHead/getBridgeIntent.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/getBridgeSourceObservation.d.ts +0 -11
- package/dist/neutral/implementation/head/createForkedHead/getBridgeSourceObservation.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/getFirstBlockForNewChain.d.ts +0 -13
- package/dist/neutral/implementation/head/createForkedHead/getFirstBlockForNewChain.d.ts.map +0 -1
- package/dist/neutral/implementation/head/createForkedHead/index.d.ts +0 -2
- package/dist/neutral/implementation/head/createForkedHead/index.d.ts.map +0 -1
- package/dist/neutral/implementation/head/getForkFromBlock.d.ts +0 -12
- package/dist/neutral/implementation/head/getForkFromBlock.d.ts.map +0 -1
- package/dist/neutral/implementation/head/head.d.ts +0 -11
- package/dist/neutral/implementation/head/head.d.ts.map +0 -1
- package/dist/neutral/implementation/head/submitNewChain.d.ts +0 -10
- package/dist/neutral/implementation/head/submitNewChain.d.ts.map +0 -1
- package/dist/neutral/implementation/mempoolRunner.d.ts +0 -7
- package/dist/neutral/implementation/mempoolRunner.d.ts.map +0 -1
- package/dist/neutral/implementation/mempoolViewer.d.ts +0 -7
- package/dist/neutral/implementation/mempoolViewer.d.ts.map +0 -1
- package/dist/neutral/implementation/pendingTransactions.d.ts +0 -9
- package/dist/neutral/implementation/pendingTransactions.d.ts.map +0 -1
- package/dist/neutral/implementation/producer.d.ts +0 -5
- package/dist/neutral/implementation/producer.d.ts.map +0 -1
- package/dist/neutral/implementation/reward.d.ts +0 -14
- package/dist/neutral/implementation/reward.d.ts.map +0 -1
- package/dist/neutral/implementation/time.d.ts +0 -6
- package/dist/neutral/implementation/time.d.ts.map +0 -1
- package/dist/neutral/implementation/validator.d.ts +0 -5
- package/dist/neutral/implementation/validator.d.ts.map +0 -1
- package/dist/neutral/simple/block/runner/spec/SimpleBlockRunner.d.ts +0 -2
- package/dist/neutral/simple/block/runner/spec/SimpleBlockRunner.d.ts.map +0 -1
- package/src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts +0 -176
- package/src/ChainBlockNumberIteration/index.ts +0 -2
- package/src/ChainBlockNumberIteration/model/BlockNumberIteration.ts +0 -7
- package/src/ChainBlockNumberIteration/model/Params.ts +0 -10
- package/src/ChainBlockNumberIteration/model/index.ts +0 -2
- package/src/Time/BaseTimeSyncService.ts +0 -54
- package/src/Time/index.ts +0 -1
- package/src/implementation/accountBalance.ts +0 -29
- package/src/implementation/blockViewer.ts +0 -29
- package/src/implementation/head/createForkedHead/config/getBridgeDestinationDetails.ts +0 -27
- package/src/implementation/head/createForkedHead/config/getBridgeSourceDetails.ts +0 -19
- package/src/implementation/head/createForkedHead/config/getForkDetails.ts +0 -10
- package/src/implementation/head/createForkedHead/config/index.ts +0 -3
- package/src/implementation/head/createForkedHead/createForkedHead.ts +0 -29
- package/src/implementation/head/createForkedHead/getBridgeDestinationObservation.ts +0 -42
- package/src/implementation/head/createForkedHead/getBridgeIntent.ts +0 -51
- package/src/implementation/head/createForkedHead/getBridgeSourceObservation.ts +0 -46
- package/src/implementation/head/createForkedHead/getFirstBlockForNewChain.ts +0 -41
- package/src/implementation/head/createForkedHead/index.ts +0 -1
- package/src/implementation/head/getForkFromBlock.ts +0 -43
- package/src/implementation/head/head.ts +0 -49
- package/src/implementation/head/submitNewChain.ts +0 -27
- package/src/implementation/mempoolRunner.ts +0 -29
- package/src/implementation/mempoolViewer.ts +0 -29
- package/src/implementation/pendingTransactions.ts +0 -36
- package/src/implementation/producer.ts +0 -16
- package/src/implementation/reward.ts +0 -53
- package/src/implementation/time.ts +0 -26
- package/src/implementation/validator.ts +0 -15
- package/src/simple/block/runner/spec/SimpleBlockRunner.ts +0 -418
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { Logger } from '@xylabs/sdk-js'
|
|
2
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
3
|
-
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
4
|
-
import type {
|
|
5
|
-
BlockRewardViewer, ChainContractViewer, Config, SimpleBlockRewardViewerParams,
|
|
6
|
-
} from '@xyo-network/xl1-protocol-sdk'
|
|
7
|
-
import { SimpleBlockRewardViewer, timeBudget } from '@xyo-network/xl1-protocol-sdk'
|
|
8
|
-
|
|
9
|
-
import { EvmBlockRewardViewer, type EvmBlockRewardViewerParams } from '../BlockReward/index.ts'
|
|
10
|
-
import { canUseEvmProvider, initEvmProvider } from './evm/index.ts'
|
|
11
|
-
|
|
12
|
-
let rewardServiceSingleton: Promise<BlockRewardViewer> | undefined
|
|
13
|
-
|
|
14
|
-
export const initBlockRewardViewer: Initializable<
|
|
15
|
-
Partial<SimpleBlockRewardViewerParams> & {
|
|
16
|
-
chainContractViewer: ChainContractViewer
|
|
17
|
-
config: Pick<Config, 'evm'>
|
|
18
|
-
},
|
|
19
|
-
BlockRewardViewer
|
|
20
|
-
> = (params): Promise<BlockRewardViewer> => {
|
|
21
|
-
if (rewardServiceSingleton) return rewardServiceSingleton
|
|
22
|
-
return timeBudget('initBlockRewardViewer', params.logger, () => {
|
|
23
|
-
const { config } = params
|
|
24
|
-
rewardServiceSingleton = canUseEvmBlockRewardViewer({ config })
|
|
25
|
-
? initEvmBlockRewardViewer(params)
|
|
26
|
-
: initXyoBlockRewardViewer(params as SimpleBlockRewardViewerParams)
|
|
27
|
-
return rewardServiceSingleton
|
|
28
|
-
}, 2000, true)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const initXyoBlockRewardViewer = (params: SimpleBlockRewardViewerParams): Promise<BlockRewardViewer> => {
|
|
32
|
-
if (rewardServiceSingleton) return rewardServiceSingleton
|
|
33
|
-
return timeBudget('initXyoBlockRewardViewer', params.logger, () => {
|
|
34
|
-
rewardServiceSingleton = SimpleBlockRewardViewer.create(params)
|
|
35
|
-
return rewardServiceSingleton
|
|
36
|
-
}, 2000, true)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const canUseEvmBlockRewardViewer = (params: { config: Pick<Config, 'evm'> }) => canUseEvmProvider({ config: params.config })
|
|
40
|
-
|
|
41
|
-
export const initEvmBlockRewardViewer = async (params: ({
|
|
42
|
-
chainContractViewer: ChainContractViewer
|
|
43
|
-
config: Pick<Config, 'evm'>
|
|
44
|
-
logger?: Logger
|
|
45
|
-
})): Promise<BlockRewardViewer> => {
|
|
46
|
-
if (rewardServiceSingleton) return rewardServiceSingleton
|
|
47
|
-
return await timeBudget('initEvmBlockRewardViewer', params.logger, async () => {
|
|
48
|
-
const provider = assertEx(await initEvmProvider(params))
|
|
49
|
-
const evmBlockRewardViewerParams: EvmBlockRewardViewerParams = { ...params, provider }
|
|
50
|
-
rewardServiceSingleton = EvmBlockRewardViewer.create(evmBlockRewardViewerParams)
|
|
51
|
-
return rewardServiceSingleton
|
|
52
|
-
}, 2000, true)
|
|
53
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import { timeBudget, type TimeSyncViewer } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
import type { Config } from 'cosmiconfig'
|
|
5
|
-
|
|
6
|
-
import { type BaseTimeServiceParams, BaseTimeSyncService } from '../Time/index.ts'
|
|
7
|
-
import { canUseEvmProvider, initEvmProvider } from './evm/index.ts'
|
|
8
|
-
|
|
9
|
-
let timeSyncServiceSingleton: Promisable<TimeSyncViewer> | undefined
|
|
10
|
-
|
|
11
|
-
export const initTimeService: Initializable<BaseTimeServiceParams<Pick<Config, 'evm'>>, TimeSyncViewer> = async ({
|
|
12
|
-
blockViewer, config, logger, meterProvider, traceProvider,
|
|
13
|
-
}) => {
|
|
14
|
-
if (timeSyncServiceSingleton) return timeSyncServiceSingleton
|
|
15
|
-
|
|
16
|
-
return await timeBudget('initTimeService', logger, async () => {
|
|
17
|
-
// Configure provider for optional Ethereum time sync
|
|
18
|
-
const ethProvider = canUseEvmProvider({ config }) ? await initEvmProvider({ config }) : undefined
|
|
19
|
-
|
|
20
|
-
// Create service
|
|
21
|
-
timeSyncServiceSingleton = BaseTimeSyncService.create({
|
|
22
|
-
blockViewer, ethProvider, logger, meterProvider, traceProvider,
|
|
23
|
-
})
|
|
24
|
-
return await timeSyncServiceSingleton
|
|
25
|
-
}, 2000, true)
|
|
26
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import type { BlockProducerService } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
-
|
|
5
|
-
import type { SimpleBlockRunnerParams } from '../simple/index.ts'
|
|
6
|
-
import { initBlockProducer } from './producer.ts'
|
|
7
|
-
|
|
8
|
-
let serviceSingleton: Promisable<BlockProducerService> | undefined
|
|
9
|
-
|
|
10
|
-
export const initValidator: Initializable<SimpleBlockRunnerParams, BlockProducerService>
|
|
11
|
-
= (params: SimpleBlockRunnerParams): Promisable<BlockProducerService> => {
|
|
12
|
-
if (serviceSingleton) return serviceSingleton
|
|
13
|
-
serviceSingleton = initBlockProducer(params)
|
|
14
|
-
return serviceSingleton
|
|
15
|
-
}
|
|
@@ -1,418 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
Address, CreatableName, Hash, Promisable,
|
|
5
|
-
} from '@xylabs/sdk-js'
|
|
6
|
-
import {
|
|
7
|
-
asAddress, assertEx,
|
|
8
|
-
delay,
|
|
9
|
-
exists,
|
|
10
|
-
filterAs,
|
|
11
|
-
hexToBigInt, ZERO_HASH,
|
|
12
|
-
} from '@xylabs/sdk-js'
|
|
13
|
-
import { Account } from '@xyo-network/account'
|
|
14
|
-
import type { AccountInstance } from '@xyo-network/account-model'
|
|
15
|
-
import { MemoryArchivist } from '@xyo-network/archivist-memory'
|
|
16
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
17
|
-
import {
|
|
18
|
-
buildRandomChain, buildRandomTransaction, createGenesisBlock,
|
|
19
|
-
} from '@xyo-network/chain-protocol'
|
|
20
|
-
import { validateHydratedBlockState } from '@xyo-network/chain-validation'
|
|
21
|
-
import type { PayloadBundle, WithHashMeta } from '@xyo-network/payload-model'
|
|
22
|
-
import { PayloadBundleSchema } from '@xyo-network/payload-model'
|
|
23
|
-
import { HDWallet } from '@xyo-network/wallet'
|
|
24
|
-
import type {
|
|
25
|
-
BlockBoundWitness, ChainId,
|
|
26
|
-
HydratedBlock,
|
|
27
|
-
TimeDomain, TimePayload,
|
|
28
|
-
} from '@xyo-network/xl1-protocol'
|
|
29
|
-
import {
|
|
30
|
-
asBlockBoundWitness,
|
|
31
|
-
asTransfer,
|
|
32
|
-
isTransactionBoundWitness,
|
|
33
|
-
TimeSchema,
|
|
34
|
-
XYO_ZERO_ADDRESS,
|
|
35
|
-
} from '@xyo-network/xl1-protocol'
|
|
36
|
-
import type {
|
|
37
|
-
BlockRewardViewer,
|
|
38
|
-
Config, ElectionService,
|
|
39
|
-
HydratedBlockStateValidationFunction, MempoolRunner, MempoolViewer, StakeIntentService,
|
|
40
|
-
TimeSyncViewer,
|
|
41
|
-
} from '@xyo-network/xl1-protocol-sdk'
|
|
42
|
-
import {
|
|
43
|
-
flattenHydratedBlock, flattenHydratedTransaction, getDefaultConfig,
|
|
44
|
-
HydratedBlockStateValidationError,
|
|
45
|
-
SimpleBlockRewardViewer,
|
|
46
|
-
SimpleMempoolRunner,
|
|
47
|
-
SimpleMempoolViewer,
|
|
48
|
-
TimeSyncViewerMoniker,
|
|
49
|
-
} from '@xyo-network/xl1-protocol-sdk'
|
|
50
|
-
import {
|
|
51
|
-
beforeAll, beforeEach, describe, expect, it,
|
|
52
|
-
} from 'vitest'
|
|
53
|
-
import { mock } from 'vitest-mock-extended'
|
|
54
|
-
|
|
55
|
-
import { accountBalancesViewerFromArchivist } from '../../../../AccountBalance/index.ts'
|
|
56
|
-
import type { SimpleBlockRunnerParams } from '../SimpleBlockRunner.ts'
|
|
57
|
-
import { SimpleBlockRunner } from '../SimpleBlockRunner.ts'
|
|
58
|
-
|
|
59
|
-
describe('SimpleBlockRunner', () => {
|
|
60
|
-
const leaderCount = 3
|
|
61
|
-
let mempoolViewer: MempoolViewer
|
|
62
|
-
let mempoolRunner: MempoolRunner
|
|
63
|
-
let account: AccountInstance
|
|
64
|
-
let blockProducer: SimpleBlockRunner
|
|
65
|
-
let chainArchivist: ArchivistInstance
|
|
66
|
-
// let chainIterator: EventingChainBlockNumberIteratorService
|
|
67
|
-
let electionService: ReturnType<typeof mock<ElectionService>>
|
|
68
|
-
let pendingTransactionsArchivist: ArchivistInstance
|
|
69
|
-
let pendingBlocksArchivist: ArchivistInstance
|
|
70
|
-
let rejectedTransactionsArchivist: ArchivistInstance
|
|
71
|
-
let rewardAddress = '1111111111111111111111111111111111111111' as Address
|
|
72
|
-
let blockRewardViewer: BlockRewardViewer
|
|
73
|
-
let stakeIntentService: ReturnType<typeof mock<StakeIntentService>>
|
|
74
|
-
let time: TimeSyncViewer
|
|
75
|
-
let transactionAccount: AccountInstance
|
|
76
|
-
const validPendingTransactions = Math.ceil(SimpleBlockRunner.DefaultBlockSize)
|
|
77
|
-
let config: Config
|
|
78
|
-
|
|
79
|
-
let currentBlock: WithHashMeta<BlockBoundWitness>
|
|
80
|
-
|
|
81
|
-
const chainId = assertEx(asAddress('Be17531fec6fEc55f3EAc3f1c187c87e4C47F81E'))
|
|
82
|
-
|
|
83
|
-
beforeAll(async () => {
|
|
84
|
-
account = await Account.random()
|
|
85
|
-
transactionAccount = await HDWallet.fromPhrase('room maximum palace fragile man pyramid school indoor base business want bronze assume marble report')
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
beforeEach(async () => {
|
|
89
|
-
config = getDefaultConfig()
|
|
90
|
-
config.producer.disableIntentRedeclaration = false
|
|
91
|
-
chainArchivist = await MemoryArchivist.create({ account: 'random' })
|
|
92
|
-
const genesisBlock = await createGenesisBlock(account, chainId, 0n, account.address)
|
|
93
|
-
await chainArchivist.insert([...genesisBlock[1], genesisBlock[0]])
|
|
94
|
-
// const chainMap = readPayloadMapFromStore<WithStorageMeta<Payload>>(chainArchivist)
|
|
95
|
-
// chainIterator = await ChainBlockNumberIterationService.create({
|
|
96
|
-
// chainMap,
|
|
97
|
-
// config,
|
|
98
|
-
// })
|
|
99
|
-
rejectedTransactionsArchivist = await MemoryArchivist.create({ account: 'random' })
|
|
100
|
-
electionService = mock<ElectionService>()
|
|
101
|
-
pendingTransactionsArchivist = await MemoryArchivist.create({ account: 'random' })
|
|
102
|
-
pendingBlocksArchivist = await MemoryArchivist.create({ account: 'random' })
|
|
103
|
-
mempoolViewer = await SimpleMempoolViewer.create({ pendingBlocksArchivist, pendingTransactionsArchivist })
|
|
104
|
-
mempoolRunner = await SimpleMempoolRunner.create({ pendingBlocksArchivist, pendingTransactionsArchivist })
|
|
105
|
-
// const BasePendingTransactionsServiceParams = {
|
|
106
|
-
// name: 'TestBasePendingTransactionsServiceParams' as CreatableName,
|
|
107
|
-
// chainArchivist,
|
|
108
|
-
// chainId,
|
|
109
|
-
// config,
|
|
110
|
-
// pendingTransactionsArchivist,
|
|
111
|
-
// rejectedTransactionsArchivist,
|
|
112
|
-
// } satisfies BasePendingTransactionsServiceParams
|
|
113
|
-
// pendingTransactionsService = await BasePendingTransactionsService.create(BasePendingTransactionsServiceParams)
|
|
114
|
-
// await addPendingTransactions(validPendingTransactions)
|
|
115
|
-
|
|
116
|
-
stakeIntentService = mock<StakeIntentService>()
|
|
117
|
-
stakeIntentService.getDeclaredCandidateRanges.mockResolvedValue([])
|
|
118
|
-
time = {
|
|
119
|
-
currentTimeAndHash(domain: TimeDomain): Promisable<[number, Hash | null]> {
|
|
120
|
-
switch (domain) {
|
|
121
|
-
case 'epoch': {
|
|
122
|
-
return [Date.now(), null]
|
|
123
|
-
}
|
|
124
|
-
case 'xl1': {
|
|
125
|
-
return [1, '00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff' as Hash]
|
|
126
|
-
}
|
|
127
|
-
case 'ethereum': {
|
|
128
|
-
return [1, '00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff' as Hash]
|
|
129
|
-
}
|
|
130
|
-
// No default
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
currentTime(domain: TimeDomain): Promisable<[string, number]> {
|
|
134
|
-
switch (domain) {
|
|
135
|
-
case 'epoch': {
|
|
136
|
-
return ['epoch', Date.now()]
|
|
137
|
-
}
|
|
138
|
-
case 'xl1': {
|
|
139
|
-
return ['xl1', 1]
|
|
140
|
-
}
|
|
141
|
-
case 'ethereum': {
|
|
142
|
-
return ['ethereum', 1]
|
|
143
|
-
}
|
|
144
|
-
// No default
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
currentTimePayload(): Promisable<TimePayload> {
|
|
148
|
-
return {
|
|
149
|
-
schema: TimeSchema, epoch: Date.now(), xl1: 1,
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
/** Convert time between different domains */
|
|
153
|
-
convertTime(fromDomain: TimeDomain, toDomain: TimeDomain, from: number): Promisable<number> {
|
|
154
|
-
if (fromDomain === toDomain) {
|
|
155
|
-
return from
|
|
156
|
-
}
|
|
157
|
-
if (fromDomain === 'epoch' && toDomain === 'xl1') {
|
|
158
|
-
return 1
|
|
159
|
-
}
|
|
160
|
-
if (fromDomain === 'xl1' && toDomain === 'epoch') {
|
|
161
|
-
return Date.now()
|
|
162
|
-
}
|
|
163
|
-
return from
|
|
164
|
-
},
|
|
165
|
-
moniker: TimeSyncViewerMoniker,
|
|
166
|
-
}
|
|
167
|
-
blockRewardViewer = await SimpleBlockRewardViewer.create()
|
|
168
|
-
const payloads = await chainArchivist.next({ limit: 1000 })
|
|
169
|
-
expect(payloads.length).toBe(9)
|
|
170
|
-
const balanceViewer = await accountBalancesViewerFromArchivist(chainId, chainArchivist)
|
|
171
|
-
const params: SimpleBlockRunnerParams = {
|
|
172
|
-
name: 'TestXyoBlockProducerParams' as CreatableName,
|
|
173
|
-
account,
|
|
174
|
-
balanceViewer,
|
|
175
|
-
chainId,
|
|
176
|
-
config,
|
|
177
|
-
mempoolRunner,
|
|
178
|
-
mempoolViewer,
|
|
179
|
-
// electionService,
|
|
180
|
-
// pendingTransactionsService,
|
|
181
|
-
// pendingBundledTransactionsArchivist,
|
|
182
|
-
rejectedTransactionsArchivist,
|
|
183
|
-
rewardAddress,
|
|
184
|
-
blockRewardViewer,
|
|
185
|
-
// stakeIntentService,
|
|
186
|
-
time,
|
|
187
|
-
validateHydratedBlockState,
|
|
188
|
-
}
|
|
189
|
-
blockProducer = await SimpleBlockRunner.create(params)
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
const addPendingTransactions = async (count: number = validPendingTransactions) => {
|
|
193
|
-
for (let i = 0; i < count; i++) {
|
|
194
|
-
const transaction = await buildRandomTransaction(chainId, [], transactionAccount)
|
|
195
|
-
const bundledPayload: PayloadBundle = {
|
|
196
|
-
schema: PayloadBundleSchema, payloads: flattenHydratedTransaction(transaction), root: transaction[0]._hash,
|
|
197
|
-
}
|
|
198
|
-
await pendingTransactionsArchivist.insert([bundledPayload])
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
describe('next', () => {
|
|
203
|
-
describe('block production', () => {
|
|
204
|
-
describe('when not current block leader', () => {
|
|
205
|
-
beforeEach(async () => {
|
|
206
|
-
const [hydratedBlock] = await buildRandomChain(account, 1, undefined, chainId, transactionAccount)
|
|
207
|
-
currentBlock = hydratedBlock[0]
|
|
208
|
-
await chainArchivist.insert(flattenHydratedBlock(hydratedBlock))
|
|
209
|
-
const leaders = await Promise.all(Array.from({ length: leaderCount }, async () => (await Account.random()).address))
|
|
210
|
-
electionService.getCreatorCommitteeForNextBlock.mockResolvedValue(leaders)
|
|
211
|
-
stakeIntentService.getDeclaredCandidateRanges.mockResolvedValue([])
|
|
212
|
-
})
|
|
213
|
-
it('should return undefined', async () => {
|
|
214
|
-
// Arrange
|
|
215
|
-
|
|
216
|
-
// Act
|
|
217
|
-
const result = await blockProducer.next(currentBlock)
|
|
218
|
-
|
|
219
|
-
// Assert
|
|
220
|
-
expect(result).toBeUndefined()
|
|
221
|
-
})
|
|
222
|
-
})
|
|
223
|
-
describe('when current block leader', () => {
|
|
224
|
-
beforeEach(async () => {
|
|
225
|
-
const [hydratedBlock] = await buildRandomChain(account, 1, undefined, chainId, transactionAccount)
|
|
226
|
-
currentBlock = hydratedBlock[0]
|
|
227
|
-
await chainArchivist.insert(flattenHydratedBlock(hydratedBlock))
|
|
228
|
-
await delay(1000)
|
|
229
|
-
electionService.getCreatorCommitteeForNextBlock.mockResolvedValue([account.address])
|
|
230
|
-
})
|
|
231
|
-
it('should return a valid block', async () => {
|
|
232
|
-
// Arrange
|
|
233
|
-
await addPendingTransactions(validPendingTransactions)
|
|
234
|
-
|
|
235
|
-
// Act
|
|
236
|
-
const result = await blockProducer.next(currentBlock)
|
|
237
|
-
|
|
238
|
-
// Assert
|
|
239
|
-
expect(result).toBeDefined()
|
|
240
|
-
expect(result).toBeArrayOfSize(2)
|
|
241
|
-
const [block, transactionsAndData] = result ?? []
|
|
242
|
-
expect(block).toBeDefined()
|
|
243
|
-
expect(asBlockBoundWitness(block)).toBeDefined()
|
|
244
|
-
expect(transactionsAndData).toBeDefined()
|
|
245
|
-
expect(transactionsAndData).toBeArray()
|
|
246
|
-
const transactions = transactionsAndData?.filter(isTransactionBoundWitness).filter(exists)
|
|
247
|
-
expect(transactions).toBeArrayOfSize(validPendingTransactions)
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
it('should remove invalid transactions', async () => {
|
|
251
|
-
// Arrange
|
|
252
|
-
let rejectBlock = true
|
|
253
|
-
const validateHydratedBlockState: HydratedBlockStateValidationFunction = async (
|
|
254
|
-
hydratedBlock: HydratedBlock,
|
|
255
|
-
chainId: ChainId,
|
|
256
|
-
) => {
|
|
257
|
-
return rejectBlock ? [await Promise.resolve(new HydratedBlockStateValidationError(ZERO_HASH, chainId, hydratedBlock, 'Invalid block'))] : []
|
|
258
|
-
}
|
|
259
|
-
// const blockViewer = blockViewerFromChainIteratorAndArchivist(chainIterator, chainArchivist)
|
|
260
|
-
const balanceViewer = await accountBalancesViewerFromArchivist(chainId, chainArchivist)
|
|
261
|
-
const params: SimpleBlockRunnerParams = {
|
|
262
|
-
name: 'TestXyoBlockProducerParams' as CreatableName,
|
|
263
|
-
account,
|
|
264
|
-
balanceViewer,
|
|
265
|
-
chainId,
|
|
266
|
-
config,
|
|
267
|
-
// electionService,
|
|
268
|
-
mempoolRunner,
|
|
269
|
-
mempoolViewer,
|
|
270
|
-
// pendingBundledTransactionsArchivist,
|
|
271
|
-
// pendingTransactionsService,
|
|
272
|
-
rejectedTransactionsArchivist,
|
|
273
|
-
rewardAddress,
|
|
274
|
-
blockRewardViewer,
|
|
275
|
-
// stakeIntentService,
|
|
276
|
-
time,
|
|
277
|
-
validateHydratedBlockState,
|
|
278
|
-
}
|
|
279
|
-
blockProducer = await SimpleBlockRunner.create(params)
|
|
280
|
-
|
|
281
|
-
// Act
|
|
282
|
-
// Force producer to reject first block
|
|
283
|
-
rejectBlock = true
|
|
284
|
-
// const invalidTransactionCount = Math.floor(validPendingTransactions / 2)
|
|
285
|
-
// await addPendingTransactions(invalidTransactionCount)
|
|
286
|
-
|
|
287
|
-
// Ensure bad block is not produced
|
|
288
|
-
const firstResult = await blockProducer.next(currentBlock)
|
|
289
|
-
expect(firstResult).toBeUndefined()
|
|
290
|
-
// Do not reject second block
|
|
291
|
-
rejectBlock = false
|
|
292
|
-
// Add more pending transactions
|
|
293
|
-
const newTransactionCount = Math.floor(validPendingTransactions / 2)
|
|
294
|
-
await addPendingTransactions(newTransactionCount)
|
|
295
|
-
// Ensure producer recovers from bad block
|
|
296
|
-
const result = await blockProducer.next(currentBlock)
|
|
297
|
-
|
|
298
|
-
// Assert
|
|
299
|
-
expect(result).toBeDefined()
|
|
300
|
-
expect(result).toBeArrayOfSize(2)
|
|
301
|
-
const [block, transactionsAndData] = result ?? []
|
|
302
|
-
expect(block).toBeDefined()
|
|
303
|
-
if (block) {
|
|
304
|
-
expect(asBlockBoundWitness(block)).toBeDefined()
|
|
305
|
-
expect(transactionsAndData).toBeDefined()
|
|
306
|
-
expect(transactionsAndData).toBeArray()
|
|
307
|
-
const transactions = transactionsAndData?.filter(isTransactionBoundWitness).filter(exists) ?? []
|
|
308
|
-
expect(transactions).toBeArrayOfSize(newTransactionCount)
|
|
309
|
-
const transfers = filterAs(assertEx(transactionsAndData), asTransfer)
|
|
310
|
-
const blockRewardTransfer = transfers.find(transfer => transfer.from === XYO_ZERO_ADDRESS)
|
|
311
|
-
expect(blockRewardTransfer).toBeDefined()
|
|
312
|
-
let totalTransfer = 0n
|
|
313
|
-
for (const value of Object.values(blockRewardTransfer?.transfers ?? {})) {
|
|
314
|
-
const bigIntValue = hexToBigInt(value)
|
|
315
|
-
totalTransfer += bigIntValue
|
|
316
|
-
}
|
|
317
|
-
expect(hexToBigInt(Object.values(blockRewardTransfer!.transfers ?? {})[0])).toBe(25_000_000_000_000_000_000n)
|
|
318
|
-
expect(hexToBigInt(Object.values(blockRewardTransfer!.transfers ?? {})[1])).toBe(475_000_000_000_000_000_000n)
|
|
319
|
-
expect(totalTransfer).toEqual(500_000_000_000_000_000_000n)
|
|
320
|
-
}
|
|
321
|
-
})
|
|
322
|
-
})
|
|
323
|
-
})
|
|
324
|
-
// describe('producer re-declare intent', () => {
|
|
325
|
-
// describe('when within re-declare intent window', () => {
|
|
326
|
-
// beforeEach(async () => {
|
|
327
|
-
// const [hydratedBlock] = await buildRandomChain(account, 1, undefined, chainId, transactionAccount)
|
|
328
|
-
// currentBlock = hydratedBlock[0]
|
|
329
|
-
// await chainArchivist.insert(flattenHydratedBlock(hydratedBlock))
|
|
330
|
-
// electionService.getCreatorCommitteeForNextBlock.mockResolvedValue([account.address])
|
|
331
|
-
// stakeIntentService.getDeclaredCandidateRanges.mockResolvedValue([[0, 10]])
|
|
332
|
-
// })
|
|
333
|
-
// it('should re-declare intent if configured for re-declaration', async () => {
|
|
334
|
-
// // Arrange
|
|
335
|
-
// config.producer.disableIntentRedeclaration = false
|
|
336
|
-
|
|
337
|
-
// // Act
|
|
338
|
-
// const result = await blockProducer.next(currentBlock)
|
|
339
|
-
|
|
340
|
-
// // Assert
|
|
341
|
-
// expect(result).toBeDefined()
|
|
342
|
-
// expect(result).toBeArrayOfSize(2)
|
|
343
|
-
// const [block, payloads] = result ?? []
|
|
344
|
-
// expect(block).toBeDefined()
|
|
345
|
-
// expect(asBlockBoundWitness(block)).toBeDefined()
|
|
346
|
-
// expect(payloads).toBeArray()
|
|
347
|
-
// const allData = flattenHydratedBlock(assertEx(result))
|
|
348
|
-
// const declaration = filterAs(allData, asChainStakeIntent).at(0)
|
|
349
|
-
// expect(declaration).toBeDefined()
|
|
350
|
-
// expect(declaration?.from).toEqual(blockProducer.address)
|
|
351
|
-
// })
|
|
352
|
-
// it('should not re-declare intent if not configured for re-declaration', async () => {
|
|
353
|
-
// // Arrange
|
|
354
|
-
// config.producer.disableIntentRedeclaration = true
|
|
355
|
-
|
|
356
|
-
// // Act
|
|
357
|
-
// const result = await blockProducer.next(currentBlock)
|
|
358
|
-
|
|
359
|
-
// // Assert
|
|
360
|
-
// expect(result).toBeDefined()
|
|
361
|
-
// expect(result).toBeArrayOfSize(2)
|
|
362
|
-
// const [block, payloads] = result ?? []
|
|
363
|
-
// expect(block).toBeDefined()
|
|
364
|
-
// expect(asBlockBoundWitness(block)).toBeDefined()
|
|
365
|
-
// expect(payloads).toBeArray()
|
|
366
|
-
// const allData = flattenHydratedBlock(assertEx(result))
|
|
367
|
-
// const declaration = filterAs(allData, asChainStakeIntent).at(0)
|
|
368
|
-
// expect(declaration).toBeUndefined()
|
|
369
|
-
// })
|
|
370
|
-
// })
|
|
371
|
-
// describe('when not within re-declare intent window', () => {
|
|
372
|
-
// beforeEach(async () => {
|
|
373
|
-
// const [hydratedBlock] = await buildRandomChain(account, 1, undefined, chainId, transactionAccount)
|
|
374
|
-
// currentBlock = hydratedBlock[0]
|
|
375
|
-
// await chainArchivist.insert(flattenHydratedBlock(hydratedBlock))
|
|
376
|
-
// electionService.getCreatorCommitteeForNextBlock.mockResolvedValue([account.address])
|
|
377
|
-
// stakeIntentService.getDeclaredCandidateRanges.mockResolvedValue([[0, 1_000_000_000]])
|
|
378
|
-
// })
|
|
379
|
-
// it('should not re-declare intent if configured for re-declaration', async () => {
|
|
380
|
-
// // Arrange
|
|
381
|
-
// config.producer.disableIntentRedeclaration = false
|
|
382
|
-
|
|
383
|
-
// // Act
|
|
384
|
-
// const result = await blockProducer.next(currentBlock)
|
|
385
|
-
|
|
386
|
-
// // Assert
|
|
387
|
-
// expect(result).toBeDefined()
|
|
388
|
-
// expect(result).toBeArrayOfSize(2)
|
|
389
|
-
// const [block, payloads] = result ?? []
|
|
390
|
-
// expect(block).toBeDefined()
|
|
391
|
-
// expect(asBlockBoundWitness(block)).toBeDefined()
|
|
392
|
-
// expect(payloads).toBeArray()
|
|
393
|
-
// const allData = flattenHydratedBlock(assertEx(result))
|
|
394
|
-
// const declaration = filterAs(allData, asChainStakeIntent).at(0)
|
|
395
|
-
// expect(declaration).toBeUndefined()
|
|
396
|
-
// })
|
|
397
|
-
// it('should not re-declare intent if not configured for re-declaration', async () => {
|
|
398
|
-
// // Arrange
|
|
399
|
-
// config.producer.disableIntentRedeclaration = true
|
|
400
|
-
|
|
401
|
-
// // Act
|
|
402
|
-
// const result = await blockProducer.next(currentBlock)
|
|
403
|
-
|
|
404
|
-
// // Assert
|
|
405
|
-
// expect(result).toBeDefined()
|
|
406
|
-
// expect(result).toBeArrayOfSize(2)
|
|
407
|
-
// const [block, payloads] = result ?? []
|
|
408
|
-
// expect(block).toBeDefined()
|
|
409
|
-
// expect(asBlockBoundWitness(block)).toBeDefined()
|
|
410
|
-
// expect(payloads).toBeArray()
|
|
411
|
-
// const allData = flattenHydratedBlock(assertEx(result))
|
|
412
|
-
// const declaration = filterAs(allData, asChainStakeIntent).at(0)
|
|
413
|
-
// expect(declaration).toBeUndefined()
|
|
414
|
-
// })
|
|
415
|
-
// })
|
|
416
|
-
// })
|
|
417
|
-
})
|
|
418
|
-
})
|