@xyo-network/chain-services 1.15.2 → 1.15.4
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/README.md +5302 -2235
- package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts +3 -5
- package/dist/neutral/AccountBalance/BaseAccountBalanceService.d.ts.map +1 -1
- package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts +3 -2
- package/dist/neutral/AccountBalance/accountBalanceServiceFromArchivist.d.ts.map +1 -1
- package/dist/neutral/AccountTransfers/BaseAccountTransfersService.d.ts +3 -6
- package/dist/neutral/AccountTransfers/BaseAccountTransfersService.d.ts.map +1 -1
- package/dist/neutral/AccountTransfers/accountTransfersServiceFromArchivist.d.ts +3 -3
- package/dist/neutral/AccountTransfers/accountTransfersServiceFromArchivist.d.ts.map +1 -1
- package/dist/neutral/BlockProducer/spec/BaseBlockProducerService.spec.d.ts.map +1 -1
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts +3 -3
- package/dist/neutral/ChainBlockNumberIteration/ChainBlockNumberIterationService.d.ts.map +1 -1
- package/dist/neutral/ChainBlockNumberIteration/model/Params.d.ts +3 -2
- package/dist/neutral/ChainBlockNumberIteration/model/Params.d.ts.map +1 -1
- package/dist/neutral/ChainService/Evm/Evm.d.ts +4 -4
- package/dist/neutral/ChainService/Evm/Evm.d.ts.map +1 -1
- package/dist/neutral/ChainService/Memory/Memory.d.ts +1 -1
- package/dist/neutral/ChainService/Memory/Memory.d.ts.map +1 -1
- package/dist/neutral/ChainValidator/XyoValidator.d.ts +2 -2
- package/dist/neutral/ChainValidator/XyoValidator.d.ts.map +1 -1
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts +15 -13
- package/dist/neutral/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.d.ts.map +1 -1
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts +2 -2
- package/dist/neutral/PendingTransactions/BasePendingTransactions.d.ts.map +1 -1
- package/dist/neutral/StakeIntent/XyoStakeIntentService.d.ts.map +1 -1
- package/dist/neutral/StepStake/BaseStepStakeService.d.ts +3 -3
- package/dist/neutral/StepStake/BaseStepStakeService.d.ts.map +1 -1
- package/dist/neutral/index.mjs +118 -151
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +40 -40
- package/src/AccountBalance/BaseAccountBalanceService.ts +6 -8
- package/src/AccountBalance/accountBalanceServiceFromArchivist.ts +22 -33
- package/src/AccountTransfers/BaseAccountTransfersService.ts +4 -12
- package/src/AccountTransfers/accountTransfersServiceFromArchivist.ts +22 -35
- package/src/BlockProducer/spec/BaseBlockProducerService.spec.ts +62 -8
- package/src/ChainBlockNumberIteration/ChainBlockNumberIterationService.ts +11 -11
- package/src/ChainBlockNumberIteration/model/Params.ts +3 -2
- package/src/ChainService/Evm/Evm.ts +8 -8
- package/src/ChainService/Memory/Memory.ts +1 -1
- package/src/ChainValidator/XyoValidator.ts +2 -2
- package/src/NetworkStakeStepReward/BaseNetworkStakeStepRewardService.ts +24 -14
- package/src/PendingTransactions/BasePendingTransactions.ts +2 -2
- package/src/StakeIntent/XyoStakeIntentService.ts +4 -2
- package/src/StepStake/BaseStepStakeService.ts +3 -3
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.15.
|
|
4
|
+
"version": "1.15.4",
|
|
5
5
|
"description": "XYO Layer One SDK Services",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -37,51 +37,51 @@
|
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@opentelemetry/api": "~1.9.0",
|
|
40
|
-
"@xylabs/array": "~5.0.
|
|
41
|
-
"@xylabs/assert": "~5.0.
|
|
42
|
-
"@xylabs/creatable": "~5.0.
|
|
43
|
-
"@xylabs/decimal-precision": "~5.0.
|
|
44
|
-
"@xylabs/events": "~5.0.
|
|
45
|
-
"@xylabs/exists": "~5.0.
|
|
46
|
-
"@xylabs/forget": "~5.0.
|
|
47
|
-
"@xylabs/hex": "~5.0.
|
|
48
|
-
"@xylabs/promise": "~5.0.
|
|
49
|
-
"@xylabs/telemetry": "~5.0.
|
|
50
|
-
"@xylabs/typeof": "~5.0.
|
|
51
|
-
"@xyo-network/account-model": "~5.1.
|
|
52
|
-
"@xyo-network/archivist-memory": "~5.1.
|
|
53
|
-
"@xyo-network/archivist-model": "~5.1.
|
|
54
|
-
"@xyo-network/boundwitness-model": "~5.1.
|
|
55
|
-
"@xyo-network/boundwitness-validator": "~5.1.
|
|
56
|
-
"@xyo-network/boundwitness-wrapper": "~5.1.
|
|
57
|
-
"@xyo-network/chain-analyze": "~1.15.
|
|
58
|
-
"@xyo-network/chain-modules": "~1.15.
|
|
59
|
-
"@xyo-network/chain-protocol": "~1.15.
|
|
60
|
-
"@xyo-network/chain-utils": "~1.15.
|
|
61
|
-
"@xyo-network/payload-builder": "~5.1.
|
|
62
|
-
"@xyo-network/payload-model": "~5.1.
|
|
63
|
-
"@xyo-network/typechain": "~4.0.
|
|
64
|
-
"@xyo-network/xl1-protocol": "~1.12.
|
|
65
|
-
"@xyo-network/xl1-protocol-sdk": "~1.15.
|
|
66
|
-
"@xyo-network/xl1-validation": "~1.15.
|
|
67
|
-
"@xyo-network/xl1-wrappers": "~1.15.
|
|
40
|
+
"@xylabs/array": "~5.0.12",
|
|
41
|
+
"@xylabs/assert": "~5.0.12",
|
|
42
|
+
"@xylabs/creatable": "~5.0.12",
|
|
43
|
+
"@xylabs/decimal-precision": "~5.0.12",
|
|
44
|
+
"@xylabs/events": "~5.0.12",
|
|
45
|
+
"@xylabs/exists": "~5.0.12",
|
|
46
|
+
"@xylabs/forget": "~5.0.12",
|
|
47
|
+
"@xylabs/hex": "~5.0.12",
|
|
48
|
+
"@xylabs/promise": "~5.0.12",
|
|
49
|
+
"@xylabs/telemetry": "~5.0.12",
|
|
50
|
+
"@xylabs/typeof": "~5.0.12",
|
|
51
|
+
"@xyo-network/account-model": "~5.1.6",
|
|
52
|
+
"@xyo-network/archivist-memory": "~5.1.6",
|
|
53
|
+
"@xyo-network/archivist-model": "~5.1.6",
|
|
54
|
+
"@xyo-network/boundwitness-model": "~5.1.6",
|
|
55
|
+
"@xyo-network/boundwitness-validator": "~5.1.6",
|
|
56
|
+
"@xyo-network/boundwitness-wrapper": "~5.1.6",
|
|
57
|
+
"@xyo-network/chain-analyze": "~1.15.4",
|
|
58
|
+
"@xyo-network/chain-modules": "~1.15.4",
|
|
59
|
+
"@xyo-network/chain-protocol": "~1.15.4",
|
|
60
|
+
"@xyo-network/chain-utils": "~1.15.4",
|
|
61
|
+
"@xyo-network/payload-builder": "~5.1.6",
|
|
62
|
+
"@xyo-network/payload-model": "~5.1.6",
|
|
63
|
+
"@xyo-network/typechain": "~4.0.10",
|
|
64
|
+
"@xyo-network/xl1-protocol": "~1.12.69",
|
|
65
|
+
"@xyo-network/xl1-protocol-sdk": "~1.15.4",
|
|
66
|
+
"@xyo-network/xl1-validation": "~1.15.4",
|
|
67
|
+
"@xyo-network/xl1-wrappers": "~1.15.4",
|
|
68
68
|
"async-mutex": "~0.5.0",
|
|
69
69
|
"ethers": "6.15.0",
|
|
70
70
|
"lru-cache": "~11.2.2"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@types/node": "~24.
|
|
74
|
-
"@xylabs/delay": "~5.0.
|
|
75
|
-
"@xylabs/ts-scripts-yarn3": "~7.1.
|
|
76
|
-
"@xylabs/tsconfig": "~7.1.
|
|
77
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
78
|
-
"@xyo-network/account": "~5.1.
|
|
79
|
-
"@xyo-network/account-model": "~5.1.
|
|
80
|
-
"@xyo-network/chain-validation": "~1.15.
|
|
81
|
-
"@xyo-network/wallet": "~5.1.
|
|
82
|
-
"eslint": "^9.
|
|
73
|
+
"@types/node": "~24.7.2",
|
|
74
|
+
"@xylabs/delay": "~5.0.12",
|
|
75
|
+
"@xylabs/ts-scripts-yarn3": "~7.1.8",
|
|
76
|
+
"@xylabs/tsconfig": "~7.1.8",
|
|
77
|
+
"@xylabs/vitest-extended": "~5.0.12",
|
|
78
|
+
"@xyo-network/account": "~5.1.6",
|
|
79
|
+
"@xyo-network/account-model": "~5.1.6",
|
|
80
|
+
"@xyo-network/chain-validation": "~1.15.4",
|
|
81
|
+
"@xyo-network/wallet": "~5.1.6",
|
|
82
|
+
"eslint": "^9.37.0",
|
|
83
83
|
"tslib": "~2.8.1",
|
|
84
|
-
"typescript": "~5.9.
|
|
84
|
+
"typescript": "~5.9.3",
|
|
85
85
|
"vitest": "~3.2.4",
|
|
86
86
|
"vitest-mock-extended": "~3.1.0",
|
|
87
87
|
"web3-types": "~1.10.0"
|
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
import { creatable } from '@xylabs/creatable'
|
|
2
2
|
import { Address, Hash } from '@xylabs/hex'
|
|
3
3
|
import { spanRootAsync } from '@xylabs/telemetry'
|
|
4
|
-
import { ReadArchivist } from '@xyo-network/archivist-model'
|
|
5
4
|
import {
|
|
6
5
|
AccountBalanceServiceV2,
|
|
7
|
-
AttoXL1,
|
|
6
|
+
AttoXL1,
|
|
8
7
|
} from '@xyo-network/xl1-protocol'
|
|
9
8
|
import {
|
|
10
|
-
BalancesStepSummary,
|
|
11
9
|
balancesSummary,
|
|
10
|
+
BalanceStepSummaryContext,
|
|
12
11
|
} from '@xyo-network/xl1-protocol-sdk'
|
|
13
12
|
|
|
14
13
|
import { BaseService } from '../BaseService.ts'
|
|
15
14
|
import { BaseServiceParams } from '../model/index.ts'
|
|
16
15
|
|
|
17
16
|
export interface BaseAccountBalanceServiceParams extends BaseServiceParams {
|
|
18
|
-
|
|
19
|
-
summaryRepository: PayloadRepository<Hash, BalancesStepSummary>
|
|
17
|
+
context: BalanceStepSummaryContext
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
@creatable()
|
|
23
21
|
export class BaseAccountBalanceService extends BaseService<BaseAccountBalanceServiceParams> implements AccountBalanceServiceV2 {
|
|
24
22
|
async balances(head: Hash, address: Address[]): Promise<Partial<Record<Address, AttoXL1>>> {
|
|
25
23
|
return await spanRootAsync('balances', async () => {
|
|
26
|
-
const summary = await balancesSummary(
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
const summary = await balancesSummary(
|
|
25
|
+
this.params.context,
|
|
26
|
+
)
|
|
29
27
|
const result: Record<Address, AttoXL1> = {}
|
|
30
28
|
for (const addr of address) {
|
|
31
29
|
const summaryBalance = summary[addr] ?? 0n
|
|
@@ -1,45 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
asHash, type Hash,
|
|
4
|
-
isHash,
|
|
5
|
-
} from '@xylabs/hex'
|
|
1
|
+
import { ZERO_HASH } from '@xylabs/hex'
|
|
6
2
|
import type { ReadArchivist } from '@xyo-network/archivist-model'
|
|
7
|
-
import {
|
|
8
|
-
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
import { LruCacheMap } from '@xyo-network/chain-protocol'
|
|
4
|
+
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
5
|
+
import {
|
|
6
|
+
type AccountBalanceServiceV2, type ChainId, StepSizes,
|
|
7
|
+
} from '@xyo-network/xl1-protocol'
|
|
8
|
+
import { type BalancesStepSummary, readPayloadMapFromStore } from '@xyo-network/xl1-protocol-sdk'
|
|
9
|
+
import { Semaphore } from 'async-mutex'
|
|
12
10
|
|
|
13
11
|
import { BaseAccountBalanceService } from './BaseAccountBalanceService.ts'
|
|
14
12
|
|
|
15
|
-
export const
|
|
16
|
-
|
|
13
|
+
export const accountBalancesServiceFromArchivist = async (
|
|
14
|
+
chainId: ChainId,
|
|
15
|
+
archivist: ReadArchivist<WithStorageMeta<Payload>>,
|
|
16
|
+
): Promise<AccountBalanceServiceV2> => {
|
|
17
|
+
const summaryMap = new LruCacheMap<string, BalancesStepSummary>({
|
|
17
18
|
max: 100_000,
|
|
18
19
|
allowStale: true,
|
|
19
20
|
noDisposeOnSet: false,
|
|
20
21
|
updateAgeOnGet: true,
|
|
21
22
|
})
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const results = (await PayloadBuilder.addStorageMeta(payloads)).map((payload) => {
|
|
31
|
-
const hash = asHash((payload as WithStorageMeta<StepSummary>).hash)
|
|
32
|
-
if (isHash(hash)) {
|
|
33
|
-
summaryArchivistCache.set(hash, payload)
|
|
34
|
-
return payload
|
|
35
|
-
}
|
|
36
|
-
}).filter(exists)
|
|
37
|
-
return results
|
|
23
|
+
const chainMap = readPayloadMapFromStore<WithStorageMeta<Payload>>(archivist)
|
|
24
|
+
const service = await BaseAccountBalanceService.create({
|
|
25
|
+
context: {
|
|
26
|
+
chainId,
|
|
27
|
+
store: { chainMap },
|
|
28
|
+
stepSemaphores: StepSizes.map(() => new Semaphore(20)),
|
|
29
|
+
summaryMap,
|
|
30
|
+
head: () => ZERO_HASH,
|
|
38
31
|
},
|
|
39
|
-
|
|
40
|
-
throw new Error('Not implemented')
|
|
41
|
-
},
|
|
42
|
-
}
|
|
43
|
-
const service = await BaseAccountBalanceService.create({ chainArchivist: archivist, summaryRepository })
|
|
32
|
+
})
|
|
44
33
|
return service
|
|
45
34
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { creatable } from '@xylabs/creatable'
|
|
2
2
|
import { Address, Hash } from '@xylabs/hex'
|
|
3
3
|
import { spanRootAsync } from '@xylabs/telemetry'
|
|
4
|
-
import { ReadArchivist } from '@xyo-network/archivist-model'
|
|
5
4
|
import {
|
|
6
5
|
AccountTransfersService,
|
|
7
|
-
AttoXL1,
|
|
6
|
+
AttoXL1,
|
|
8
7
|
} from '@xyo-network/xl1-protocol'
|
|
9
8
|
import {
|
|
10
|
-
|
|
9
|
+
TransfersStepSummaryContext,
|
|
11
10
|
transfersSummary,
|
|
12
11
|
} from '@xyo-network/xl1-protocol-sdk'
|
|
13
12
|
|
|
@@ -15,9 +14,7 @@ import { BaseService } from '../BaseService.ts'
|
|
|
15
14
|
import { BaseServiceParams } from '../model/index.ts'
|
|
16
15
|
|
|
17
16
|
export interface BaseAccountTransferServiceParams extends BaseServiceParams {
|
|
18
|
-
|
|
19
|
-
chainArchivist: ReadArchivist
|
|
20
|
-
summaryRepository: PayloadRepository<Hash, TransfersStepSummary>
|
|
17
|
+
context: TransfersStepSummaryContext
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
@creatable()
|
|
@@ -28,12 +25,7 @@ export class BaseAccountTransfersService extends BaseService<BaseAccountTransfer
|
|
|
28
25
|
|
|
29
26
|
async transfers(head: Hash, addresses: Address[]): Promise<Partial<Record<Address, AttoXL1>>> {
|
|
30
27
|
return await spanRootAsync('transfers', async () => {
|
|
31
|
-
const
|
|
32
|
-
chainArchivist, summaryRepository, account,
|
|
33
|
-
} = this.params
|
|
34
|
-
const summary = await transfersSummary({
|
|
35
|
-
chainArchivist, summaryRepository, head, account,
|
|
36
|
-
})
|
|
28
|
+
const summary = await transfersSummary(this.params.context)
|
|
37
29
|
const result: Record<Address, AttoXL1> = {}
|
|
38
30
|
for (const addr of addresses) {
|
|
39
31
|
const summaryBalance = summary[addr] ?? 0n
|
|
@@ -1,48 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Address, Hash } from '@xylabs/hex'
|
|
3
|
-
import {
|
|
4
|
-
asHash,
|
|
5
|
-
isHash,
|
|
6
|
-
} from '@xylabs/hex'
|
|
1
|
+
import { ZERO_HASH } from '@xylabs/hex'
|
|
7
2
|
import type { ReadArchivist } from '@xyo-network/archivist-model'
|
|
8
|
-
import {
|
|
9
|
-
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
import { LruCacheMap } from '@xyo-network/chain-protocol'
|
|
4
|
+
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
5
|
+
import {
|
|
6
|
+
type AccountTransfersService, type ChainId, StepSizes,
|
|
7
|
+
} from '@xyo-network/xl1-protocol'
|
|
8
|
+
import type { TransfersStepSummary } from '@xyo-network/xl1-protocol-sdk'
|
|
9
|
+
import { readPayloadMapFromStore } from '@xyo-network/xl1-protocol-sdk'
|
|
10
|
+
import { Semaphore } from 'async-mutex'
|
|
13
11
|
|
|
14
12
|
import { BaseAccountTransfersService } from './BaseAccountTransfersService.ts'
|
|
15
13
|
|
|
16
|
-
export const
|
|
17
|
-
|
|
14
|
+
export const accountTransfersServiceFromArchivist = async (
|
|
15
|
+
chainId: ChainId,
|
|
16
|
+
archivist: ReadArchivist<WithStorageMeta<Payload>>,
|
|
17
|
+
): Promise<AccountTransfersService> => {
|
|
18
|
+
const summaryMap = new LruCacheMap<string, TransfersStepSummary>({
|
|
18
19
|
max: 100_000,
|
|
19
20
|
allowStale: true,
|
|
20
21
|
noDisposeOnSet: false,
|
|
21
22
|
updateAgeOnGet: true,
|
|
22
23
|
})
|
|
23
|
-
const
|
|
24
|
-
get: (hashes: Hash[]) => {
|
|
25
|
-
const results = hashes.map((hash) => {
|
|
26
|
-
return summaryArchivistCache.get(hash)
|
|
27
|
-
}).filter(exists)
|
|
28
|
-
return results
|
|
29
|
-
},
|
|
30
|
-
insert: async (payloads: TransfersStepSummary[]) => {
|
|
31
|
-
const results = (await PayloadBuilder.addStorageMeta(payloads)).map((payload) => {
|
|
32
|
-
const hash = asHash((payload as WithStorageMeta<StepSummary>).hash)
|
|
33
|
-
if (isHash(hash)) {
|
|
34
|
-
summaryArchivistCache.set(hash, payload)
|
|
35
|
-
return payload
|
|
36
|
-
}
|
|
37
|
-
}).filter(exists)
|
|
38
|
-
return results
|
|
39
|
-
},
|
|
40
|
-
next: () => {
|
|
41
|
-
throw new Error('Not implemented')
|
|
42
|
-
},
|
|
43
|
-
}
|
|
24
|
+
const chainMap = readPayloadMapFromStore<WithStorageMeta<Payload>>(archivist)
|
|
44
25
|
const service = await BaseAccountTransfersService.create({
|
|
45
|
-
|
|
26
|
+
context: {
|
|
27
|
+
chainId,
|
|
28
|
+
store: { chainMap },
|
|
29
|
+
stepSemaphores: StepSizes.map(() => new Semaphore(20)),
|
|
30
|
+
summaryMap,
|
|
31
|
+
head: () => ZERO_HASH,
|
|
32
|
+
},
|
|
46
33
|
})
|
|
47
34
|
return service
|
|
48
35
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
/* eslint-disable max-statements */
|
|
1
2
|
import '@xylabs/vitest-extended'
|
|
2
3
|
|
|
3
4
|
import { filterAs } from '@xylabs/array'
|
|
4
5
|
import { assertEx } from '@xylabs/assert'
|
|
5
6
|
import type { CreatableName } from '@xylabs/creatable'
|
|
6
7
|
import { delay } from '@xylabs/delay'
|
|
7
|
-
import type { Address } from '@xylabs/hex'
|
|
8
|
+
import type { Address, Hash } from '@xylabs/hex'
|
|
8
9
|
import {
|
|
9
10
|
asAddress, hexToBigInt, ZERO_HASH,
|
|
10
11
|
} from '@xylabs/hex'
|
|
12
|
+
import type { Promisable } from '@xylabs/promise'
|
|
11
13
|
import { Account } from '@xyo-network/account'
|
|
12
14
|
import type { AccountInstance } from '@xyo-network/account-model'
|
|
13
15
|
import { MemoryArchivist } from '@xyo-network/archivist-memory'
|
|
@@ -19,10 +21,11 @@ import {
|
|
|
19
21
|
} from '@xyo-network/payload-model'
|
|
20
22
|
import { HDWallet } from '@xyo-network/wallet'
|
|
21
23
|
import type {
|
|
22
|
-
BlockBoundWitness, BlockRewardService,
|
|
24
|
+
BlockBoundWitness, BlockRewardService, ChainId, ElectionService,
|
|
23
25
|
HydratedBlock,
|
|
24
26
|
HydratedBlockStateValidationFunctionV2,
|
|
25
27
|
StakeIntentService,
|
|
28
|
+
TimeDomain, TimePayload,
|
|
26
29
|
TimeSyncViewInterfaceV2,
|
|
27
30
|
} from '@xyo-network/xl1-protocol'
|
|
28
31
|
import {
|
|
@@ -31,6 +34,7 @@ import {
|
|
|
31
34
|
asTransactionBoundWitness,
|
|
32
35
|
asTransfer,
|
|
33
36
|
HydratedBlockStateValidationError,
|
|
37
|
+
TimeSchema,
|
|
34
38
|
XYO_ZERO_ADDRESS,
|
|
35
39
|
} from '@xyo-network/xl1-protocol'
|
|
36
40
|
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
@@ -42,7 +46,7 @@ import {
|
|
|
42
46
|
} from 'vitest'
|
|
43
47
|
import { mock } from 'vitest-mock-extended'
|
|
44
48
|
|
|
45
|
-
import {
|
|
49
|
+
import { accountBalancesServiceFromArchivist } from '../../AccountBalance/index.ts'
|
|
46
50
|
import { MemoryBlockRewardService } from '../../BlockReward/index.ts'
|
|
47
51
|
import type { BasePendingTransactionsServiceParams } from '../../PendingTransactions/index.ts'
|
|
48
52
|
import { BasePendingTransactionsService } from '../../PendingTransactions/index.ts'
|
|
@@ -95,9 +99,56 @@ describe('XyoBlockProducer', () => {
|
|
|
95
99
|
|
|
96
100
|
stakeIntentService = mock<StakeIntentService>()
|
|
97
101
|
stakeIntentService.getDeclaredCandidateRanges.mockResolvedValue([])
|
|
98
|
-
time =
|
|
102
|
+
time = {
|
|
103
|
+
currentTimeAndHash(domain: TimeDomain): Promisable<[number, Hash | null]> {
|
|
104
|
+
switch (domain) {
|
|
105
|
+
case 'epoch': {
|
|
106
|
+
return [Date.now(), null]
|
|
107
|
+
}
|
|
108
|
+
case 'xl1': {
|
|
109
|
+
return [1, '00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff' as Hash]
|
|
110
|
+
}
|
|
111
|
+
case 'ethereum': {
|
|
112
|
+
return [1, '00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff' as Hash]
|
|
113
|
+
}
|
|
114
|
+
// No default
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
currentTime(domain: TimeDomain): Promisable<[string, number]> {
|
|
118
|
+
switch (domain) {
|
|
119
|
+
case 'epoch': {
|
|
120
|
+
return ['epoch', Date.now()]
|
|
121
|
+
}
|
|
122
|
+
case 'xl1': {
|
|
123
|
+
return ['xl1', 1]
|
|
124
|
+
}
|
|
125
|
+
case 'ethereum': {
|
|
126
|
+
return ['ethereum', 1]
|
|
127
|
+
}
|
|
128
|
+
// No default
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
currentTimePayload(): Promisable<TimePayload> {
|
|
132
|
+
return {
|
|
133
|
+
schema: TimeSchema, epoch: Date.now(), xl1: 1,
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
/** Convert time between different domains */
|
|
137
|
+
convertTime(fromDomain: TimeDomain, toDomain: TimeDomain, from: number): Promisable<number> {
|
|
138
|
+
if (fromDomain === toDomain) {
|
|
139
|
+
return from
|
|
140
|
+
}
|
|
141
|
+
if (fromDomain === 'epoch' && toDomain === 'xl1') {
|
|
142
|
+
return 1
|
|
143
|
+
}
|
|
144
|
+
if (fromDomain === 'xl1' && toDomain === 'epoch') {
|
|
145
|
+
return Date.now()
|
|
146
|
+
}
|
|
147
|
+
return from
|
|
148
|
+
},
|
|
149
|
+
}
|
|
99
150
|
rewardService = await MemoryBlockRewardService.create()
|
|
100
|
-
const balanceService = await
|
|
151
|
+
const balanceService = await accountBalancesServiceFromArchivist(chainId, chainArchivist)
|
|
101
152
|
const params: BaseBlockProducerServiceParams = {
|
|
102
153
|
name: 'TestXyoBlockProducerParams' as CreatableName,
|
|
103
154
|
account,
|
|
@@ -179,11 +230,11 @@ describe('XyoBlockProducer', () => {
|
|
|
179
230
|
let rejectBlock = true
|
|
180
231
|
const validateHydratedBlockState: HydratedBlockStateValidationFunctionV2 = async (
|
|
181
232
|
hydratedBlock: HydratedBlock,
|
|
182
|
-
chainId:
|
|
233
|
+
chainId: ChainId,
|
|
183
234
|
) => {
|
|
184
235
|
return rejectBlock ? [await Promise.resolve(new HydratedBlockStateValidationError(ZERO_HASH, chainId, hydratedBlock, 'Invalid block'))] : []
|
|
185
236
|
}
|
|
186
|
-
const balanceService = await
|
|
237
|
+
const balanceService = await accountBalancesServiceFromArchivist(chainId, chainArchivist)
|
|
187
238
|
const params: BaseBlockProducerServiceParams = {
|
|
188
239
|
name: 'TestXyoBlockProducerParams' as CreatableName,
|
|
189
240
|
account,
|
|
@@ -234,11 +285,14 @@ describe('XyoBlockProducer', () => {
|
|
|
234
285
|
const transfers = filterAs(assertEx(transactionsAndData), asTransfer)
|
|
235
286
|
const blockRewardTransfer = transfers.find(transfer => transfer.from === XYO_ZERO_ADDRESS)
|
|
236
287
|
expect(blockRewardTransfer).toBeDefined()
|
|
288
|
+
let totalTransfer = 0n
|
|
237
289
|
for (const value of Object.values(blockRewardTransfer?.transfers ?? {})) {
|
|
238
290
|
if (value) {
|
|
239
|
-
|
|
291
|
+
const bigIntValue = hexToBigInt(value)
|
|
292
|
+
totalTransfer += bigIntValue
|
|
240
293
|
}
|
|
241
294
|
}
|
|
295
|
+
expect(totalTransfer).toEqual(3_000_000_000_000_000_000_000n)
|
|
242
296
|
}
|
|
243
297
|
})
|
|
244
298
|
})
|
|
@@ -3,15 +3,15 @@ import type { Hex } from '@xylabs/hex'
|
|
|
3
3
|
import {
|
|
4
4
|
isDefined, isNull, isUndefined,
|
|
5
5
|
} from '@xylabs/typeof'
|
|
6
|
-
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
7
6
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
8
|
-
import type { WithStorageMeta } from '@xyo-network/payload-model'
|
|
7
|
+
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
9
8
|
import type {
|
|
10
9
|
BlockBoundWitness, ChainIteratorServiceEventData, EventingChainBlockNumberIteratorService,
|
|
11
10
|
} from '@xyo-network/xl1-protocol'
|
|
12
11
|
import {
|
|
13
12
|
asBlockBoundWitness, asBlockBoundWitnessWithStorageMeta, isBlockBoundWitnessWithHashStorageMeta,
|
|
14
13
|
} from '@xyo-network/xl1-protocol'
|
|
14
|
+
import type { PayloadMapRead } from '@xyo-network/xl1-protocol-sdk'
|
|
15
15
|
import { LRUCache } from 'lru-cache'
|
|
16
16
|
|
|
17
17
|
import { BaseService } from '../BaseService.ts'
|
|
@@ -22,10 +22,10 @@ export class ChainBlockNumberIterationService extends BaseService<XyoChainIterat
|
|
|
22
22
|
protected _blocksByBlockNumber = new LRUCache<number, WithStorageMeta<BlockBoundWitness>>({ max: 10_000 })
|
|
23
23
|
protected _currentHead: WithStorageMeta<BlockBoundWitness> | undefined
|
|
24
24
|
|
|
25
|
-
get chainArchivist(): ArchivistInstance { return assertEx(this.params.chainArchivist) }
|
|
26
|
-
|
|
27
25
|
get chainId(): Hex { return assertEx(this._currentHead?.chain ?? this.params?.head?.chain, () => 'Current head is not set') }
|
|
28
26
|
|
|
27
|
+
get chainMap(): PayloadMapRead<WithStorageMeta<Payload>> { return assertEx(this.params.chainMap) }
|
|
28
|
+
|
|
29
29
|
async get(block: number): Promise<WithStorageMeta<BlockBoundWitness>> {
|
|
30
30
|
const head = await this.head()
|
|
31
31
|
// if(isUndefined(head)) return undefined
|
|
@@ -36,7 +36,7 @@ export class ChainBlockNumberIterationService extends BaseService<XyoChainIterat
|
|
|
36
36
|
// Start at the current head and traverse backwards until the requested block is found
|
|
37
37
|
const startingBlock = head
|
|
38
38
|
const currentBlockHash = await PayloadBuilder.hash(startingBlock)
|
|
39
|
-
let currentBlock = (await this.
|
|
39
|
+
let currentBlock = (await this.chainMap.get(currentBlockHash))
|
|
40
40
|
while (isDefined(currentBlock)) {
|
|
41
41
|
assertEx(asBlockBoundWitness(currentBlock), () => `Expected hash to be a block bound witness [${currentBlock?._hash}]`)
|
|
42
42
|
if (isBlockBoundWitnessWithHashStorageMeta(currentBlock)) {
|
|
@@ -46,7 +46,7 @@ export class ChainBlockNumberIterationService extends BaseService<XyoChainIterat
|
|
|
46
46
|
}
|
|
47
47
|
const { previous } = currentBlock
|
|
48
48
|
if (isNull(previous)) break
|
|
49
|
-
currentBlock = (await this.
|
|
49
|
+
currentBlock = (await this.chainMap.get(previous))
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
throw new Error(`Block not found: ${block}`)
|
|
@@ -73,13 +73,13 @@ export class ChainBlockNumberIterationService extends BaseService<XyoChainIterat
|
|
|
73
73
|
async previous(block: number | undefined = undefined, count: number = 1): Promise<WithStorageMeta<BlockBoundWitness>[]> {
|
|
74
74
|
const results: WithStorageMeta<BlockBoundWitness>[] = []
|
|
75
75
|
let currentBlock: WithStorageMeta<BlockBoundWitness> | undefined = isDefined(block) ? (await this.get(block)) : await this.head()
|
|
76
|
-
while (currentBlock && results.length < count) {
|
|
76
|
+
while (isDefined(currentBlock) && (results.length < count)) {
|
|
77
77
|
if (isBlockBoundWitnessWithHashStorageMeta(currentBlock)) {
|
|
78
78
|
results.push(currentBlock)
|
|
79
|
-
const { previous } = currentBlock
|
|
79
|
+
const { previous } = currentBlock as BlockBoundWitness
|
|
80
80
|
if (isNull(previous)) break
|
|
81
|
-
const nextBlock = await this.
|
|
82
|
-
currentBlock = asBlockBoundWitnessWithStorageMeta(nextBlock
|
|
81
|
+
const nextBlock = await this.chainMap.get(previous)
|
|
82
|
+
currentBlock = asBlockBoundWitnessWithStorageMeta(nextBlock)
|
|
83
83
|
} else {
|
|
84
84
|
const hash = PayloadBuilder.hash(currentBlock)
|
|
85
85
|
assertEx(asBlockBoundWitnessWithStorageMeta(currentBlock), () => `Expected hash to be a block bound witness [${hash}]`)
|
|
@@ -96,7 +96,7 @@ export class ChainBlockNumberIterationService extends BaseService<XyoChainIterat
|
|
|
96
96
|
|
|
97
97
|
private async getBoundWitnessAsBlockBoundWitnessWithStorageMeta(head: BlockBoundWitness): Promise<WithStorageMeta<BlockBoundWitness>> {
|
|
98
98
|
const hash = await PayloadBuilder.hash(head)
|
|
99
|
-
const stored = (await this.
|
|
99
|
+
const stored = (await this.chainMap.get(hash))
|
|
100
100
|
const newHead = asBlockBoundWitnessWithStorageMeta(stored)
|
|
101
101
|
if (isUndefined(newHead)) throw new Error(`Head block not found in archivist [${hash}]`)
|
|
102
102
|
return newHead
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
2
2
|
import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
|
|
3
|
+
import type { PayloadMapRead } from '@xyo-network/xl1-protocol-sdk'
|
|
3
4
|
|
|
4
5
|
import type { BaseServiceParams } from '../../model/index.ts'
|
|
5
6
|
|
|
6
7
|
export interface XyoChainIteratorParams extends BaseServiceParams {
|
|
7
|
-
|
|
8
|
+
chainMap: PayloadMapRead<WithStorageMeta<Payload>>
|
|
8
9
|
head: BlockBoundWitness
|
|
9
10
|
}
|
|
@@ -42,16 +42,16 @@ export class EvmChainService extends BaseService<EvmChainServiceParams> implemen
|
|
|
42
42
|
return await this.contract.active()
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
async
|
|
46
|
-
return await this.contract.activeByAddressStaked(getAddress(
|
|
45
|
+
async activeByStaked(staked: Address): Promise<bigint> {
|
|
46
|
+
return await this.contract.activeByAddressStaked(getAddress(toEthAddress(staked)))
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
async activeByStaker(address:
|
|
50
|
-
return await this.contract.activeByStaker(getAddress(address))
|
|
49
|
+
async activeByStaker(address: Address): Promise<bigint> {
|
|
50
|
+
return await this.contract.activeByStaker(getAddress(toEthAddress(address)))
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
async addStake(staked:
|
|
54
|
-
const result = await this.contract.addStake(getAddress(staked), amount)
|
|
53
|
+
async addStake(staked: Address, amount: bigint): Promise<boolean> {
|
|
54
|
+
const result = await this.contract.addStake(getAddress(toEthAddress(staked)), amount)
|
|
55
55
|
await result.wait()
|
|
56
56
|
return true
|
|
57
57
|
}
|
|
@@ -76,8 +76,8 @@ export class EvmChainService extends BaseService<EvmChainServiceParams> implemen
|
|
|
76
76
|
return await this.contract.pending()
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
async pendingByStaker(staker:
|
|
80
|
-
return await this.contract.pendingByStaker(getAddress(staker))
|
|
79
|
+
async pendingByStaker(staker: Address): Promise<bigint> {
|
|
80
|
+
return await this.contract.pendingByStaker(getAddress(toEthAddress(staker)))
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
async removeStake(slot: bigint): Promise<boolean> {
|
|
@@ -21,7 +21,7 @@ export class MemoryChainService extends BaseService<MemoryChainServiceParams> im
|
|
|
21
21
|
return await Promise.resolve(this._simulatedStake)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async
|
|
24
|
+
async activeByStaked(_staked: Address): Promise<bigint> {
|
|
25
25
|
return await Promise.resolve(this._simulatedStake)
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -6,7 +6,7 @@ import { ArchivistInstance, ReadArchivist } from '@xyo-network/archivist-model'
|
|
|
6
6
|
import {
|
|
7
7
|
BlockBoundWitness,
|
|
8
8
|
BlockRewardService,
|
|
9
|
-
|
|
9
|
+
ChainId,
|
|
10
10
|
ElectionService,
|
|
11
11
|
HydratedBlockStateValidationFunctionV2,
|
|
12
12
|
SignedHydratedTransactionWithStorageMeta,
|
|
@@ -20,7 +20,7 @@ import { Validator } from './model/index.ts'
|
|
|
20
20
|
export interface XyoValidatorParams extends BaseServiceParams {
|
|
21
21
|
account: AccountInstance
|
|
22
22
|
chainArchivist: ReadArchivist
|
|
23
|
-
chainId:
|
|
23
|
+
chainId: ChainId
|
|
24
24
|
electionService: ElectionService
|
|
25
25
|
pendingBundledTransactionsArchivist: ArchivistInstance
|
|
26
26
|
rewardService: BlockRewardService
|