@xyo-network/chain-orchestration 1.19.3 → 1.19.5
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/actor/BalanceActor.d.ts +8 -4
- package/dist/neutral/actor/BalanceActor.d.ts.map +1 -1
- package/dist/neutral/actor/MempoolActor.d.ts +41 -0
- package/dist/neutral/actor/MempoolActor.d.ts.map +1 -0
- package/dist/neutral/actor/ValidatorActor.d.ts +20 -5
- package/dist/neutral/actor/ValidatorActor.d.ts.map +1 -1
- package/dist/neutral/actor/index.d.ts +1 -0
- package/dist/neutral/actor/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +166 -76
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/actor/BalanceActor.ts +11 -7
- package/src/actor/MempoolActor.ts +105 -0
- package/src/actor/ValidatorActor.ts +25 -20
- package/src/actor/index.ts +1 -0
- package/src/init/initChainStakeViewer.ts +8 -8
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertEx,
|
|
3
|
+
creatable,
|
|
4
|
+
} from '@xylabs/sdk-js'
|
|
5
|
+
import { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
6
|
+
import {
|
|
7
|
+
Actor, ActorParams,
|
|
8
|
+
MempoolRunner,
|
|
9
|
+
} from '@xyo-network/xl1-sdk'
|
|
10
|
+
import { Mutex } from 'async-mutex'
|
|
11
|
+
|
|
12
|
+
export type MempoolActorParams = ActorParams<{
|
|
13
|
+
mempoolRunner: MempoolRunner
|
|
14
|
+
pendingBlocksArchivist: ArchivistInstance
|
|
15
|
+
pendingTransactionsArchivist: ArchivistInstance
|
|
16
|
+
}>
|
|
17
|
+
|
|
18
|
+
@creatable()
|
|
19
|
+
export class MempoolActor extends Actor<MempoolActorParams> {
|
|
20
|
+
private _blockTimerId: ReturnType<typeof setInterval> | null = null
|
|
21
|
+
private _blockTimerMutex = new Mutex()
|
|
22
|
+
|
|
23
|
+
private _transactionTimerId: ReturnType<typeof setInterval> | null = null
|
|
24
|
+
private _transactionTimerMutex = new Mutex()
|
|
25
|
+
|
|
26
|
+
protected get mempoolRunner() {
|
|
27
|
+
return this.params.mempoolRunner
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected get pendingBlocksArchivist() {
|
|
31
|
+
return this.params.pendingBlocksArchivist
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected get pendingTransactionsArchivist() {
|
|
35
|
+
return this.params.pendingTransactionsArchivist
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static override async paramsHandler(params?: Partial<MempoolActorParams>) {
|
|
39
|
+
return {
|
|
40
|
+
...await super.paramsHandler(params),
|
|
41
|
+
mempoolRunner: assertEx(
|
|
42
|
+
params?.mempoolRunner,
|
|
43
|
+
() => 'mempoolRunner is required for MempoolActor',
|
|
44
|
+
),
|
|
45
|
+
pendingBlocksArchivist: assertEx(
|
|
46
|
+
params?.pendingBlocksArchivist,
|
|
47
|
+
() => 'pendingBlocksArchivist is required for MempoolActor',
|
|
48
|
+
),
|
|
49
|
+
pendingTransactionsArchivist: assertEx(
|
|
50
|
+
params?.pendingTransactionsArchivist,
|
|
51
|
+
() => 'pendingTransactionsArchivist is required for MempoolActor',
|
|
52
|
+
),
|
|
53
|
+
} satisfies MempoolActorParams
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
override async startHandler() {
|
|
57
|
+
await super.startHandler()
|
|
58
|
+
// this.restartTransactionTimer()
|
|
59
|
+
this.restartBlockTimer()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
override async stopHandler() {
|
|
63
|
+
await super.stopHandler()
|
|
64
|
+
// this.stopTransactionTimer()
|
|
65
|
+
this.stopBlockTimer()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private restartBlockTimer() {
|
|
69
|
+
this.stopBlockTimer()
|
|
70
|
+
this._blockTimerId = setInterval(() => {
|
|
71
|
+
if (this._blockTimerMutex.isLocked()) {
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
void this._blockTimerMutex.runExclusive(async () => {
|
|
75
|
+
await this.mempoolRunner.prunePendingBlocks({ batchSize: 50 })
|
|
76
|
+
})
|
|
77
|
+
}, 1000)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private restartTransactionTimer() {
|
|
81
|
+
this.stopTransactionTimer()
|
|
82
|
+
this._transactionTimerId = setInterval(() => {
|
|
83
|
+
if (this._transactionTimerMutex.isLocked()) {
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
void this._transactionTimerMutex.runExclusive(async () => {
|
|
87
|
+
await this.mempoolRunner.prunePendingTransactions({ batchSize: 50 })
|
|
88
|
+
})
|
|
89
|
+
}, 1000)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private stopBlockTimer() {
|
|
93
|
+
if (this._blockTimerId !== null) {
|
|
94
|
+
clearInterval(this._blockTimerId)
|
|
95
|
+
}
|
|
96
|
+
this._blockTimerId = null
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private stopTransactionTimer() {
|
|
100
|
+
if (this._transactionTimerId !== null) {
|
|
101
|
+
clearInterval(this._transactionTimerId)
|
|
102
|
+
}
|
|
103
|
+
this._transactionTimerId = null
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -9,27 +9,24 @@ import {
|
|
|
9
9
|
Actor,
|
|
10
10
|
ActorParams,
|
|
11
11
|
BlockViewer,
|
|
12
|
-
|
|
13
|
-
MempoolViewer, MempoolViewerMoniker,
|
|
12
|
+
MempoolViewer,
|
|
14
13
|
} from '@xyo-network/xl1-sdk'
|
|
15
14
|
|
|
16
15
|
export type ValidatorActorParams = ActorParams<
|
|
17
16
|
{
|
|
18
17
|
account: AccountInstance
|
|
19
|
-
blockViewer
|
|
18
|
+
blockViewer: BlockViewer
|
|
20
19
|
finalizedArchivist: ArchivistInstance
|
|
21
|
-
mempoolViewer
|
|
20
|
+
mempoolViewer: MempoolViewer
|
|
22
21
|
}>
|
|
23
22
|
|
|
24
23
|
@creatable()
|
|
25
24
|
export class ValidatorActor extends Actor<ValidatorActorParams> {
|
|
26
|
-
protected _blockViewer: BlockViewer | undefined
|
|
27
25
|
protected _lastValidatedBlock: BlockBoundWitness | undefined
|
|
28
26
|
protected _lastValidatedBlockHash: Hash | undefined
|
|
29
|
-
protected _mempoolViewer: MempoolViewer | undefined
|
|
30
27
|
|
|
31
28
|
protected get blockViewer() {
|
|
32
|
-
return this.
|
|
29
|
+
return this.params.blockViewer
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
protected get finalizedArchivist() {
|
|
@@ -37,21 +34,29 @@ export class ValidatorActor extends Actor<ValidatorActorParams> {
|
|
|
37
34
|
}
|
|
38
35
|
|
|
39
36
|
protected get mempoolViewer() {
|
|
40
|
-
return this.
|
|
37
|
+
return this.params.mempoolViewer
|
|
41
38
|
}
|
|
42
39
|
|
|
43
|
-
override async
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
40
|
+
static override async paramsHandler(params?: Partial<ValidatorActorParams>) {
|
|
41
|
+
return {
|
|
42
|
+
...await super.paramsHandler(params),
|
|
43
|
+
mempoolViewer: assertEx(
|
|
44
|
+
params?.mempoolViewer,
|
|
45
|
+
() => 'mempoolViewer is required for ValidatorActor',
|
|
46
|
+
),
|
|
47
|
+
blockViewer: assertEx(
|
|
48
|
+
params?.blockViewer,
|
|
49
|
+
() => 'blockViewer is required for ValidatorActor',
|
|
50
|
+
),
|
|
51
|
+
finalizedArchivist: assertEx(
|
|
52
|
+
params?.finalizedArchivist,
|
|
53
|
+
() => 'finalizedArchivist is required for ValidatorActor',
|
|
54
|
+
),
|
|
55
|
+
account: assertEx(
|
|
56
|
+
params?.account,
|
|
57
|
+
() => 'account is required for ValidatorActor',
|
|
58
|
+
),
|
|
59
|
+
} satisfies ValidatorActorParams
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
override async startHandler(): Promise<void> {
|
package/src/actor/index.ts
CHANGED
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
asAddress,
|
|
3
3
|
assertEx, type Logger, toAddress, toEthAddress,
|
|
4
4
|
} from '@xylabs/sdk-js'
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
5
|
+
import type { EvmStakeEventsParams, EvmStakeViewerParams } from '@xyo-network/chain-sdk'
|
|
6
|
+
import { EvmStakeEventsViewer, EvmStakeViewer } from '@xyo-network/chain-sdk'
|
|
7
7
|
import { IStakedXyoChain__factory } from '@xyo-network/typechain'
|
|
8
8
|
import type {
|
|
9
9
|
ChainId,
|
|
@@ -18,14 +18,14 @@ export async function initEvmChainStakeViewer(context: CreatableProviderContext,
|
|
|
18
18
|
const provider = await initEvmProvider({ config, logger })
|
|
19
19
|
const contractAddress = assertEx(config.chain.id, () => 'Missing config.evm.chainId') as ChainId
|
|
20
20
|
const contract = IStakedXyoChain__factory.connect(toEthAddress(contractAddress), provider)
|
|
21
|
-
const stakeEventsViewer = await
|
|
21
|
+
const stakeEventsViewer = await EvmStakeEventsViewer.create({
|
|
22
22
|
contract, logger, context,
|
|
23
|
-
} satisfies
|
|
24
|
-
assertEx(await stakeEventsViewer.start(), () => 'Failed to start
|
|
25
|
-
const stakeChainViewer = await
|
|
23
|
+
} satisfies EvmStakeEventsParams)
|
|
24
|
+
assertEx(await stakeEventsViewer.start(), () => 'Failed to start EvmStakeEvents reader')
|
|
25
|
+
const stakeChainViewer = await EvmStakeViewer.create({
|
|
26
26
|
contract, stakeEventsViewer, logger, context,
|
|
27
|
-
} satisfies
|
|
28
|
-
assertEx(await stakeChainViewer.start(), () => 'Failed to start
|
|
27
|
+
} satisfies EvmStakeViewerParams)
|
|
28
|
+
assertEx(await stakeChainViewer.start(), () => 'Failed to start EvmStake viewer')
|
|
29
29
|
return stakeChainViewer
|
|
30
30
|
}
|
|
31
31
|
|