@xyo-network/xl1-cli 1.6.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/LICENSE +165 -0
- package/README.md +23 -0
- package/build/commands/api/index.d.ts +2 -0
- package/build/commands/api/index.d.ts.map +1 -0
- package/build/commands/api/runApi.d.ts +2 -0
- package/build/commands/api/runApi.d.ts.map +1 -0
- package/build/commands/index.d.ts +4 -0
- package/build/commands/index.d.ts.map +1 -0
- package/build/commands/producer/createDeclaration.d.ts +2 -0
- package/build/commands/producer/createDeclaration.d.ts.map +1 -0
- package/build/commands/producer/index.d.ts +3 -0
- package/build/commands/producer/index.d.ts.map +1 -0
- package/build/commands/producer/runProducer.d.ts +3 -0
- package/build/commands/producer/runProducer.d.ts.map +1 -0
- package/build/commands/validator/index.d.ts +2 -0
- package/build/commands/validator/index.d.ts.map +1 -0
- package/build/commands/validator/runValidator.d.ts +3 -0
- package/build/commands/validator/runValidator.d.ts.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -0
- package/build/initEnv.d.ts +2 -0
- package/build/initEnv.d.ts.map +1 -0
- package/build/node/index.mjs +1502 -0
- package/build/node/index.mjs.map +1 -0
- package/build/node/xl1.mjs +1474 -0
- package/build/node/xl1.mjs.map +1 -0
- package/build/orchestration/actor/implementation/BalanceActor.d.ts +17 -0
- package/build/orchestration/actor/implementation/BalanceActor.d.ts.map +1 -0
- package/build/orchestration/actor/implementation/ChainHeadUpdateActor.d.ts +16 -0
- package/build/orchestration/actor/implementation/ChainHeadUpdateActor.d.ts.map +1 -0
- package/build/orchestration/actor/implementation/ProducerActor.d.ts +25 -0
- package/build/orchestration/actor/implementation/ProducerActor.d.ts.map +1 -0
- package/build/orchestration/actor/implementation/index.d.ts +4 -0
- package/build/orchestration/actor/implementation/index.d.ts.map +1 -0
- package/build/orchestration/actor/index.d.ts +3 -0
- package/build/orchestration/actor/index.d.ts.map +1 -0
- package/build/orchestration/actor/model/Actor.d.ts +38 -0
- package/build/orchestration/actor/model/Actor.d.ts.map +1 -0
- package/build/orchestration/actor/model/Orchestrator.d.ts +24 -0
- package/build/orchestration/actor/model/Orchestrator.d.ts.map +1 -0
- package/build/orchestration/actor/model/index.d.ts +3 -0
- package/build/orchestration/actor/model/index.d.ts.map +1 -0
- package/build/orchestration/archivists/ChainFinalized/archivist.d.ts +4 -0
- package/build/orchestration/archivists/ChainFinalized/archivist.d.ts.map +1 -0
- package/build/orchestration/archivists/ChainFinalized/index.d.ts +2 -0
- package/build/orchestration/archivists/ChainFinalized/index.d.ts.map +1 -0
- package/build/orchestration/archivists/ChainFinalized/local.d.ts +4 -0
- package/build/orchestration/archivists/ChainFinalized/local.d.ts.map +1 -0
- package/build/orchestration/archivists/ChainFinalized/remote.d.ts +4 -0
- package/build/orchestration/archivists/ChainFinalized/remote.d.ts.map +1 -0
- package/build/orchestration/archivists/ChainSubmissions/archivist.d.ts +4 -0
- package/build/orchestration/archivists/ChainSubmissions/archivist.d.ts.map +1 -0
- package/build/orchestration/archivists/ChainSubmissions/index.d.ts +2 -0
- package/build/orchestration/archivists/ChainSubmissions/index.d.ts.map +1 -0
- package/build/orchestration/archivists/ChainSubmissions/remote.d.ts +4 -0
- package/build/orchestration/archivists/ChainSubmissions/remote.d.ts.map +1 -0
- package/build/orchestration/archivists/PendingTransactions/archivist.d.ts +4 -0
- package/build/orchestration/archivists/PendingTransactions/archivist.d.ts.map +1 -0
- package/build/orchestration/archivists/PendingTransactions/index.d.ts +2 -0
- package/build/orchestration/archivists/PendingTransactions/index.d.ts.map +1 -0
- package/build/orchestration/archivists/PendingTransactions/local.d.ts +4 -0
- package/build/orchestration/archivists/PendingTransactions/local.d.ts.map +1 -0
- package/build/orchestration/archivists/PendingTransactions/remote.d.ts +4 -0
- package/build/orchestration/archivists/PendingTransactions/remote.d.ts.map +1 -0
- package/build/orchestration/archivists/RejectedTransactions/archivist.d.ts +4 -0
- package/build/orchestration/archivists/RejectedTransactions/archivist.d.ts.map +1 -0
- package/build/orchestration/archivists/RejectedTransactions/index.d.ts +2 -0
- package/build/orchestration/archivists/RejectedTransactions/index.d.ts.map +1 -0
- package/build/orchestration/archivists/RejectedTransactions/local.d.ts +4 -0
- package/build/orchestration/archivists/RejectedTransactions/local.d.ts.map +1 -0
- package/build/orchestration/archivists/StakeIntentState/archivist.d.ts +4 -0
- package/build/orchestration/archivists/StakeIntentState/archivist.d.ts.map +1 -0
- package/build/orchestration/archivists/StakeIntentState/index.d.ts +2 -0
- package/build/orchestration/archivists/StakeIntentState/index.d.ts.map +1 -0
- package/build/orchestration/archivists/StakeIntentState/local.d.ts +4 -0
- package/build/orchestration/archivists/StakeIntentState/local.d.ts.map +1 -0
- package/build/orchestration/archivists/index.d.ts +6 -0
- package/build/orchestration/archivists/index.d.ts.map +1 -0
- package/build/orchestration/archivists/lib/index.d.ts +2 -0
- package/build/orchestration/archivists/lib/index.d.ts.map +1 -0
- package/build/orchestration/archivists/lib/localPersistentArchivist.d.ts +12 -0
- package/build/orchestration/archivists/lib/localPersistentArchivist.d.ts.map +1 -0
- package/build/orchestration/health/index.d.ts +2 -0
- package/build/orchestration/health/index.d.ts.map +1 -0
- package/build/orchestration/health/initHealthEndpoints.d.ts +7 -0
- package/build/orchestration/health/initHealthEndpoints.d.ts.map +1 -0
- package/build/orchestration/host/implementation/DefaultHost.d.ts +12 -0
- package/build/orchestration/host/implementation/DefaultHost.d.ts.map +1 -0
- package/build/orchestration/host/implementation/DefaultServiceCollection.d.ts +24 -0
- package/build/orchestration/host/implementation/DefaultServiceCollection.d.ts.map +1 -0
- package/build/orchestration/host/implementation/DefaultServiceProvider.d.ts +7 -0
- package/build/orchestration/host/implementation/DefaultServiceProvider.d.ts.map +1 -0
- package/build/orchestration/host/implementation/index.d.ts +3 -0
- package/build/orchestration/host/implementation/index.d.ts.map +1 -0
- package/build/orchestration/host/index.d.ts +3 -0
- package/build/orchestration/host/index.d.ts.map +1 -0
- package/build/orchestration/host/model/Host.d.ts +19 -0
- package/build/orchestration/host/model/Host.d.ts.map +1 -0
- package/build/orchestration/host/model/ServiceCollection.d.ts +20 -0
- package/build/orchestration/host/model/ServiceCollection.d.ts.map +1 -0
- package/build/orchestration/host/model/ServiceProvider.d.ts +4 -0
- package/build/orchestration/host/model/ServiceProvider.d.ts.map +1 -0
- package/build/orchestration/host/model/index.d.ts +4 -0
- package/build/orchestration/host/model/index.d.ts.map +1 -0
- package/build/orchestration/index.d.ts +6 -0
- package/build/orchestration/index.d.ts.map +1 -0
- package/build/orchestration/initServices.d.ts +4 -0
- package/build/orchestration/initServices.d.ts.map +1 -0
- package/build/orchestration/map/BalanceSummary/index.d.ts +2 -0
- package/build/orchestration/map/BalanceSummary/index.d.ts.map +1 -0
- package/build/orchestration/map/BalanceSummary/initBalanceSummaryMap.d.ts +7 -0
- package/build/orchestration/map/BalanceSummary/initBalanceSummaryMap.d.ts.map +1 -0
- package/build/orchestration/map/BalanceSummary/local.d.ts +6 -0
- package/build/orchestration/map/BalanceSummary/local.d.ts.map +1 -0
- package/build/orchestration/map/driver/index.d.ts +2 -0
- package/build/orchestration/map/driver/index.d.ts.map +1 -0
- package/build/orchestration/map/driver/lmdb/Params.d.ts +7 -0
- package/build/orchestration/map/driver/lmdb/Params.d.ts.map +1 -0
- package/build/orchestration/map/driver/lmdb/SynchronousLmdbMap.d.ts +32 -0
- package/build/orchestration/map/driver/lmdb/SynchronousLmdbMap.d.ts.map +1 -0
- package/build/orchestration/map/driver/lmdb/index.d.ts +2 -0
- package/build/orchestration/map/driver/lmdb/index.d.ts.map +1 -0
- package/build/orchestration/map/index.d.ts +3 -0
- package/build/orchestration/map/index.d.ts.map +1 -0
- package/build/orchestration/map/localPersistentMap.d.ts +12 -0
- package/build/orchestration/map/localPersistentMap.d.ts.map +1 -0
- package/build/orchestration/repository/index.d.ts +2 -0
- package/build/orchestration/repository/index.d.ts.map +1 -0
- package/build/orchestration/repository/lib/index.d.ts +2 -0
- package/build/orchestration/repository/lib/index.d.ts.map +1 -0
- package/build/orchestration/repository/lib/repositoryFromArchivist.d.ts +6 -0
- package/build/orchestration/repository/lib/repositoryFromArchivist.d.ts.map +1 -0
- package/build/orchestration/services/implementation/account.d.ts +4 -0
- package/build/orchestration/services/implementation/account.d.ts.map +1 -0
- package/build/orchestration/services/implementation/balance.d.ts +4 -0
- package/build/orchestration/services/implementation/balance.d.ts.map +1 -0
- package/build/orchestration/services/implementation/chain/evm.d.ts +6 -0
- package/build/orchestration/services/implementation/chain/evm.d.ts.map +1 -0
- package/build/orchestration/services/implementation/chain/index.d.ts +4 -0
- package/build/orchestration/services/implementation/chain/index.d.ts.map +1 -0
- package/build/orchestration/services/implementation/evm/index.d.ts +2 -0
- package/build/orchestration/services/implementation/evm/index.d.ts.map +1 -0
- package/build/orchestration/services/implementation/evm/initChainId.d.ts +3 -0
- package/build/orchestration/services/implementation/evm/initChainId.d.ts.map +1 -0
- package/build/orchestration/services/implementation/evm/initEvmProvider.d.ts +4 -0
- package/build/orchestration/services/implementation/evm/initEvmProvider.d.ts.map +1 -0
- package/build/orchestration/services/implementation/evm/initGanacheProvider.d.ts +5 -0
- package/build/orchestration/services/implementation/evm/initGanacheProvider.d.ts.map +1 -0
- package/build/orchestration/services/implementation/evm/initInfuraProvider.d.ts +5 -0
- package/build/orchestration/services/implementation/evm/initInfuraProvider.d.ts.map +1 -0
- package/build/orchestration/services/implementation/head.d.ts +10 -0
- package/build/orchestration/services/implementation/head.d.ts.map +1 -0
- package/build/orchestration/services/implementation/index.d.ts +11 -0
- package/build/orchestration/services/implementation/index.d.ts.map +1 -0
- package/build/orchestration/services/implementation/iterator.d.ts +6 -0
- package/build/orchestration/services/implementation/iterator.d.ts.map +1 -0
- package/build/orchestration/services/implementation/pendingTransactions.d.ts +4 -0
- package/build/orchestration/services/implementation/pendingTransactions.d.ts.map +1 -0
- package/build/orchestration/services/implementation/producer.d.ts +4 -0
- package/build/orchestration/services/implementation/producer.d.ts.map +1 -0
- package/build/orchestration/services/implementation/reward.d.ts +4 -0
- package/build/orchestration/services/implementation/reward.d.ts.map +1 -0
- package/build/orchestration/services/implementation/validator.d.ts +4 -0
- package/build/orchestration/services/implementation/validator.d.ts.map +1 -0
- package/build/orchestration/services/index.d.ts +2 -0
- package/build/orchestration/services/index.d.ts.map +1 -0
- package/build/orchestration/status/RuntimeStatusMonitor.d.ts +31 -0
- package/build/orchestration/status/RuntimeStatusMonitor.d.ts.map +1 -0
- package/build/orchestration/status/ServiceStatus.d.ts +9 -0
- package/build/orchestration/status/ServiceStatus.d.ts.map +1 -0
- package/build/orchestration/status/index.d.ts +3 -0
- package/build/orchestration/status/index.d.ts.map +1 -0
- package/build/orchestration/store/StoreKind.d.ts +2 -0
- package/build/orchestration/store/StoreKind.d.ts.map +1 -0
- package/build/orchestration/store/getStoreDirectory.d.ts +9 -0
- package/build/orchestration/store/getStoreDirectory.d.ts.map +1 -0
- package/build/orchestration/store/index.d.ts +3 -0
- package/build/orchestration/store/index.d.ts.map +1 -0
- package/build/runCLI.d.ts +3 -0
- package/build/runCLI.d.ts.map +1 -0
- package/build/start.d.ts +2 -0
- package/build/start.d.ts.map +1 -0
- package/build/xl1.d.ts +2 -0
- package/build/xl1.d.ts.map +1 -0
- package/dist/cli-min.mjs +400 -0
- package/nodemon.json +9 -0
- package/package.json +97 -0
- package/rollup.config.mjs +73 -0
- package/scripts/xl1.mjs +3 -0
- package/src/commands/api/index.ts +1 -0
- package/src/commands/api/runApi.ts +7 -0
- package/src/commands/index.ts +3 -0
- package/src/commands/producer/createDeclaration.ts +17 -0
- package/src/commands/producer/index.ts +2 -0
- package/src/commands/producer/runProducer.ts +25 -0
- package/src/commands/validator/index.ts +1 -0
- package/src/commands/validator/runValidator.ts +13 -0
- package/src/index.ts +3 -0
- package/src/initEnv.ts +8 -0
- package/src/orchestration/actor/implementation/BalanceActor.ts +51 -0
- package/src/orchestration/actor/implementation/ChainHeadUpdateActor.ts +65 -0
- package/src/orchestration/actor/implementation/ProducerActor.ts +250 -0
- package/src/orchestration/actor/implementation/index.ts +3 -0
- package/src/orchestration/actor/index.ts +2 -0
- package/src/orchestration/actor/model/Actor.ts +113 -0
- package/src/orchestration/actor/model/Orchestrator.ts +65 -0
- package/src/orchestration/actor/model/index.ts +2 -0
- package/src/orchestration/archivists/ChainFinalized/archivist.ts +27 -0
- package/src/orchestration/archivists/ChainFinalized/index.ts +1 -0
- package/src/orchestration/archivists/ChainFinalized/local.ts +16 -0
- package/src/orchestration/archivists/ChainFinalized/remote.ts +18 -0
- package/src/orchestration/archivists/ChainSubmissions/archivist.ts +19 -0
- package/src/orchestration/archivists/ChainSubmissions/index.ts +1 -0
- package/src/orchestration/archivists/ChainSubmissions/remote.ts +18 -0
- package/src/orchestration/archivists/PendingTransactions/archivist.ts +29 -0
- package/src/orchestration/archivists/PendingTransactions/index.ts +1 -0
- package/src/orchestration/archivists/PendingTransactions/local.ts +20 -0
- package/src/orchestration/archivists/PendingTransactions/remote.ts +18 -0
- package/src/orchestration/archivists/RejectedTransactions/archivist.ts +18 -0
- package/src/orchestration/archivists/RejectedTransactions/index.ts +1 -0
- package/src/orchestration/archivists/RejectedTransactions/local.ts +20 -0
- package/src/orchestration/archivists/StakeIntentState/archivist.ts +19 -0
- package/src/orchestration/archivists/StakeIntentState/index.ts +1 -0
- package/src/orchestration/archivists/StakeIntentState/local.ts +19 -0
- package/src/orchestration/archivists/index.ts +5 -0
- package/src/orchestration/archivists/lib/index.ts +1 -0
- package/src/orchestration/archivists/lib/localPersistentArchivist.ts +44 -0
- package/src/orchestration/health/index.ts +1 -0
- package/src/orchestration/health/initHealthEndpoints.ts +70 -0
- package/src/orchestration/host/implementation/DefaultHost.ts +25 -0
- package/src/orchestration/host/implementation/DefaultServiceCollection.ts +60 -0
- package/src/orchestration/host/implementation/DefaultServiceProvider.ts +12 -0
- package/src/orchestration/host/implementation/index.ts +2 -0
- package/src/orchestration/host/index.ts +2 -0
- package/src/orchestration/host/model/Host.ts +21 -0
- package/src/orchestration/host/model/ServiceCollection.ts +22 -0
- package/src/orchestration/host/model/ServiceProvider.ts +3 -0
- package/src/orchestration/host/model/index.ts +3 -0
- package/src/orchestration/index.ts +5 -0
- package/src/orchestration/initServices.ts +237 -0
- package/src/orchestration/map/BalanceSummary/index.ts +1 -0
- package/src/orchestration/map/BalanceSummary/initBalanceSummaryMap.ts +22 -0
- package/src/orchestration/map/BalanceSummary/local.ts +19 -0
- package/src/orchestration/map/driver/index.ts +1 -0
- package/src/orchestration/map/driver/lmdb/Params.ts +7 -0
- package/src/orchestration/map/driver/lmdb/SynchronousLmdbMap.ts +67 -0
- package/src/orchestration/map/driver/lmdb/index.ts +1 -0
- package/src/orchestration/map/index.ts +2 -0
- package/src/orchestration/map/localPersistentMap.ts +39 -0
- package/src/orchestration/repository/index.ts +1 -0
- package/src/orchestration/repository/lib/index.ts +1 -0
- package/src/orchestration/repository/lib/repositoryFromArchivist.ts +27 -0
- package/src/orchestration/services/implementation/account.ts +23 -0
- package/src/orchestration/services/implementation/balance.ts +13 -0
- package/src/orchestration/services/implementation/chain/evm.ts +35 -0
- package/src/orchestration/services/implementation/chain/index.ts +27 -0
- package/src/orchestration/services/implementation/evm/index.ts +1 -0
- package/src/orchestration/services/implementation/evm/initChainId.ts +18 -0
- package/src/orchestration/services/implementation/evm/initEvmProvider.ts +21 -0
- package/src/orchestration/services/implementation/evm/initGanacheProvider.ts +19 -0
- package/src/orchestration/services/implementation/evm/initInfuraProvider.ts +25 -0
- package/src/orchestration/services/implementation/head.ts +44 -0
- package/src/orchestration/services/implementation/index.ts +10 -0
- package/src/orchestration/services/implementation/iterator.ts +36 -0
- package/src/orchestration/services/implementation/pendingTransactions.ts +14 -0
- package/src/orchestration/services/implementation/producer.ts +13 -0
- package/src/orchestration/services/implementation/reward.ts +37 -0
- package/src/orchestration/services/implementation/validator.ts +14 -0
- package/src/orchestration/services/index.ts +1 -0
- package/src/orchestration/status/RuntimeStatusMonitor.ts +117 -0
- package/src/orchestration/status/ServiceStatus.ts +21 -0
- package/src/orchestration/status/index.ts +2 -0
- package/src/orchestration/store/StoreKind.ts +1 -0
- package/src/orchestration/store/getStoreDirectory.ts +15 -0
- package/src/orchestration/store/index.ts +2 -0
- package/src/runCLI.ts +96 -0
- package/src/spec/MultiProducer.ChainOutput.json +864 -0
- package/src/start.ts +26 -0
- package/src/xl1.ts +6 -0
- package/vitest.config.ts +11 -0
- package/xy.config.ts +11 -0
package/nodemon.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xyo-network/xl1-cli",
|
|
3
|
+
"version": "1.6.2",
|
|
4
|
+
"description": "XYO Layer One API",
|
|
5
|
+
"homepage": "https://xylabs.com",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "git+https://github.com/xylabs/xyo-chain/issues",
|
|
8
|
+
"email": "support@xylabs.com"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/xylabs/xyo-chain.git"
|
|
13
|
+
},
|
|
14
|
+
"license": "LGPL-3.0-only",
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "XY Labs Development Team",
|
|
17
|
+
"email": "support@xylabs.com",
|
|
18
|
+
"url": "https://xylabs.com"
|
|
19
|
+
},
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./build/index.d.ts",
|
|
25
|
+
"default": "./build/node/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./package.json": "./package.json",
|
|
28
|
+
"./README.md": "./README.md"
|
|
29
|
+
},
|
|
30
|
+
"module": "build/node/index.mjs",
|
|
31
|
+
"types": "build/index.d.ts",
|
|
32
|
+
"bin": {
|
|
33
|
+
"xl1": "./scripts/xl1.mjs"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build-tests": "tsc --noEmit --lib dom,esnext",
|
|
37
|
+
"bundle-cli": "rollup -c rollup.config.mjs",
|
|
38
|
+
"package-clean": "rimraf dist build",
|
|
39
|
+
"package-compile": "yarn package-compile-only && yarn package-compile-bundles",
|
|
40
|
+
"package-compile-bundles": "yarn bundle-cli"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"lmdb": "^3.4.1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@opentelemetry/api": "^1.9.0",
|
|
47
|
+
"@xylabs/array": "^4.12.44",
|
|
48
|
+
"@xylabs/assert": "^4.12.44",
|
|
49
|
+
"@xylabs/base": "^4.12.44",
|
|
50
|
+
"@xylabs/creatable": "^4.12.44",
|
|
51
|
+
"@xylabs/delay": "^4.12.44",
|
|
52
|
+
"@xylabs/events": "^4.12.44",
|
|
53
|
+
"@xylabs/forget": "^4.12.44",
|
|
54
|
+
"@xylabs/hex": "^4.12.44",
|
|
55
|
+
"@xylabs/logger": "^4.12.44",
|
|
56
|
+
"@xylabs/promise": "^4.12.44",
|
|
57
|
+
"@xylabs/telemetry": "^4.12.44",
|
|
58
|
+
"@xylabs/ts-scripts-yarn3": "^6.5.18",
|
|
59
|
+
"@xylabs/tsconfig": "^6.5.18",
|
|
60
|
+
"@xylabs/typeof": "^4.12.44",
|
|
61
|
+
"@xylabs/vitest-extended": "^4.12.44",
|
|
62
|
+
"@xyo-network/archivist-lmdb": "^4.0.2",
|
|
63
|
+
"@xyo-network/archivist-memory": "^4.0.2",
|
|
64
|
+
"@xyo-network/archivist-model": "^4.0.2",
|
|
65
|
+
"@xyo-network/chain-api": "^1.6.2",
|
|
66
|
+
"@xyo-network/chain-modules": "^1.6.2",
|
|
67
|
+
"@xyo-network/chain-orchestration": "^1.6.2",
|
|
68
|
+
"@xyo-network/chain-protocol": "^1.6.2",
|
|
69
|
+
"@xyo-network/chain-sdk": "^1.6.2",
|
|
70
|
+
"@xyo-network/chain-services": "^1.6.2",
|
|
71
|
+
"@xyo-network/chain-telemetry": "^1.6.2",
|
|
72
|
+
"@xyo-network/chain-utils": "^1.6.2",
|
|
73
|
+
"@xyo-network/chain-validation": "^1.6.2",
|
|
74
|
+
"@xyo-network/payload-builder": "^4.0.2",
|
|
75
|
+
"@xyo-network/payload-model": "^4.0.2",
|
|
76
|
+
"@xyo-network/wallet": "^4.0.2",
|
|
77
|
+
"@xyo-network/wallet-model": "^4.0.2",
|
|
78
|
+
"@xyo-network/xl1-protocol": "^1.6.1",
|
|
79
|
+
"@xyo-network/xl1-protocol-sdk": "^1.6.2",
|
|
80
|
+
"async-mutex": "^0.5.0",
|
|
81
|
+
"dotenv": "^17.2.0",
|
|
82
|
+
"ethers": "^6.15.0",
|
|
83
|
+
"nodemon": "^3.1.10",
|
|
84
|
+
"rollup": "^4.44.2",
|
|
85
|
+
"typescript": "^5.8.3",
|
|
86
|
+
"vitest": "^3.2.4",
|
|
87
|
+
"vitest-mock-extended": "^3.1.0",
|
|
88
|
+
"yargs": "^18.0.0"
|
|
89
|
+
},
|
|
90
|
+
"engines": {
|
|
91
|
+
"node": ">=22.3 <23"
|
|
92
|
+
},
|
|
93
|
+
"engineStrict": true,
|
|
94
|
+
"publishConfig": {
|
|
95
|
+
"access": "public"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import resolve from '@rollup/plugin-node-resolve'
|
|
2
|
+
import typescript from '@rollup/plugin-typescript'
|
|
3
|
+
import commonjs from '@rollup/plugin-commonjs'
|
|
4
|
+
import replace from '@rollup/plugin-replace'
|
|
5
|
+
import json from '@rollup/plugin-json'
|
|
6
|
+
|
|
7
|
+
import terser from '@rollup/plugin-terser'
|
|
8
|
+
|
|
9
|
+
import { fileURLToPath } from 'node:url'
|
|
10
|
+
import PATH from 'node:path'
|
|
11
|
+
import { builtinModules } from 'node:module'
|
|
12
|
+
|
|
13
|
+
const __dirnameReplacement = JSON.stringify(PATH.dirname(fileURLToPath(import.meta.url)))
|
|
14
|
+
|
|
15
|
+
const externalModules = new Set([
|
|
16
|
+
'lmdb',
|
|
17
|
+
])
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
input: './src/xl1.ts',
|
|
21
|
+
output: [
|
|
22
|
+
{
|
|
23
|
+
file: 'dist/cli-min.mjs',
|
|
24
|
+
format: 'esm',
|
|
25
|
+
inlineDynamicImports: true,
|
|
26
|
+
sourcemap: false,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
external: (id) => {
|
|
30
|
+
// Externalize all modules EXCEPT those starting with "my-lib-"
|
|
31
|
+
if (id.startsWith('@xylabs/')) {
|
|
32
|
+
return false // bundle it
|
|
33
|
+
}
|
|
34
|
+
if (id.startsWith('@xyo-network/')) {
|
|
35
|
+
return false // bundle it
|
|
36
|
+
}
|
|
37
|
+
if (id.startsWith('.')) {
|
|
38
|
+
return false // bundle it
|
|
39
|
+
}
|
|
40
|
+
if (id.startsWith('/')) {
|
|
41
|
+
return false // bundle it
|
|
42
|
+
}
|
|
43
|
+
if (builtinModules.includes(id)) {
|
|
44
|
+
return true // don't bundle it
|
|
45
|
+
}
|
|
46
|
+
if (id.startsWith('node:')) {
|
|
47
|
+
return true // don't bundle it
|
|
48
|
+
}
|
|
49
|
+
if (externalModules.has(id)) {
|
|
50
|
+
console.log(`Externalizing: ${id}`)
|
|
51
|
+
return true // don't bundle it
|
|
52
|
+
}
|
|
53
|
+
return false // bundle it
|
|
54
|
+
},
|
|
55
|
+
plugins: [
|
|
56
|
+
json(),
|
|
57
|
+
commonjs(),
|
|
58
|
+
resolve({
|
|
59
|
+
exportConditions: ['node'],
|
|
60
|
+
preferBuiltins: true,
|
|
61
|
+
}),
|
|
62
|
+
typescript(
|
|
63
|
+
{
|
|
64
|
+
outDir: './dist', declaration: false, declarationMap: false,
|
|
65
|
+
},
|
|
66
|
+
),
|
|
67
|
+
replace({
|
|
68
|
+
preventAssignment: true,
|
|
69
|
+
values: { __dirname: __dirnameReplacement },
|
|
70
|
+
}),
|
|
71
|
+
terser(),
|
|
72
|
+
],
|
|
73
|
+
}
|
package/scripts/xl1.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './runApi.ts'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createProducerChainStakeIntentTransaction } from '@xyo-network/chain-protocol'
|
|
2
|
+
import { XYO_ZERO_ADDRESS } from '@xyo-network/chain-utils'
|
|
3
|
+
|
|
4
|
+
import { initAccount } from '../../orchestration/index.ts'
|
|
5
|
+
|
|
6
|
+
export const createProducerDeclaration = async (): Promise<void> => {
|
|
7
|
+
const producerAccount = await initAccount()
|
|
8
|
+
const [tx, payloads] = await createProducerChainStakeIntentTransaction(
|
|
9
|
+
XYO_ZERO_ADDRESS,
|
|
10
|
+
[producerAccount],
|
|
11
|
+
producerAccount.address,
|
|
12
|
+
2_000_000_000,
|
|
13
|
+
0,
|
|
14
|
+
)
|
|
15
|
+
const intent = [tx, payloads]
|
|
16
|
+
console.log(JSON.stringify(intent, null, 2))
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Orchestrator } from '../../orchestration/index.ts'
|
|
2
|
+
import {
|
|
3
|
+
BalanceActor, ChainHeadUpdateActor, initServices, ProducerActor,
|
|
4
|
+
} from '../../orchestration/index.ts'
|
|
5
|
+
|
|
6
|
+
export const runProducer = async (orchestrator: Orchestrator) => {
|
|
7
|
+
// Initialize services
|
|
8
|
+
console.log('Services: Initializing...')
|
|
9
|
+
const services = await initServices()
|
|
10
|
+
console.log('Services: Initialized')
|
|
11
|
+
|
|
12
|
+
// Create actors
|
|
13
|
+
const chainHeadUpdate = await ChainHeadUpdateActor.create(services)
|
|
14
|
+
const producer = await ProducerActor.create(services)
|
|
15
|
+
const balances = await BalanceActor.create(services)
|
|
16
|
+
const actors = [chainHeadUpdate, producer, balances]
|
|
17
|
+
// const actors = [chainHeadUpdate, producer]
|
|
18
|
+
|
|
19
|
+
for (const actor of actors) {
|
|
20
|
+
// Register the actor with the orchestrator
|
|
21
|
+
await orchestrator.registerActor(actor)
|
|
22
|
+
}
|
|
23
|
+
// Start the orchestrator => automatically activates the actor
|
|
24
|
+
await orchestrator.start()
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './runValidator.ts'
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Orchestrator } from '../../orchestration/index.ts'
|
|
2
|
+
import { Actor } from '../../orchestration/index.ts'
|
|
3
|
+
|
|
4
|
+
export const runValidator = async (orchestrator: Orchestrator) => {
|
|
5
|
+
// Create a single actor
|
|
6
|
+
const myActor = new Actor('Validator', 'Validator', {})
|
|
7
|
+
|
|
8
|
+
// Register the actor with the orchestrator
|
|
9
|
+
await orchestrator.registerActor(myActor)
|
|
10
|
+
|
|
11
|
+
// Start the orchestrator => automatically activates the actor
|
|
12
|
+
await orchestrator.start()
|
|
13
|
+
}
|
package/src/index.ts
ADDED
package/src/initEnv.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { BaseParams } from '@xylabs/base'
|
|
3
|
+
import type { Promisable } from '@xylabs/promise'
|
|
4
|
+
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
5
|
+
import type { OpenTelemetryProviders } from '@xyo-network/xl1-protocol'
|
|
6
|
+
import type { ChainServiceCollectionV2 } from '@xyo-network/xl1-protocol-sdk'
|
|
7
|
+
import { Mutex } from 'async-mutex'
|
|
8
|
+
|
|
9
|
+
import { Actor } from '../model/index.ts'
|
|
10
|
+
|
|
11
|
+
export type BalanceActorParams = BaseParams<
|
|
12
|
+
Pick<ChainServiceCollectionV2, 'balanceService' | 'chainIterator'>
|
|
13
|
+
& OpenTelemetryProviders>
|
|
14
|
+
|
|
15
|
+
export class BalanceActor extends Actor<BalanceActorParams> {
|
|
16
|
+
protected _updateMutex = new Mutex()
|
|
17
|
+
|
|
18
|
+
protected constructor(params: BalanceActorParams) {
|
|
19
|
+
super('BalanceActor', 'Balance', params)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected get balanceService() {
|
|
23
|
+
return assertEx(this.params.balanceService, () => 'balanceService not set')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
protected get chainIterator() {
|
|
27
|
+
return assertEx(this.params.chainIterator, () => 'chainIterator not set')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static create(params: BalanceActorParams): Promisable<BalanceActor> {
|
|
31
|
+
return new BalanceActor(params)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override async start(): Promise<void> {
|
|
35
|
+
await super.start()
|
|
36
|
+
this.chainIterator.on('headUpdate', async () => {
|
|
37
|
+
await this.updateBalance()
|
|
38
|
+
})
|
|
39
|
+
this.registerTimer('BalanceTimer', async () => {
|
|
40
|
+
await this.updateBalance()
|
|
41
|
+
}, 1000, 1000)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protected async updateBalance(): Promise<void> {
|
|
45
|
+
if (this._updateMutex.isLocked()) return
|
|
46
|
+
await this._updateMutex.runExclusive(async () => {
|
|
47
|
+
const head = await PayloadBuilder.hash(await this.chainIterator.head())
|
|
48
|
+
await this.balanceService.balances(head, [])
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { filterAs } from '@xylabs/array'
|
|
2
|
+
import { assertEx } from '@xylabs/assert'
|
|
3
|
+
import type { BaseParams } from '@xylabs/base'
|
|
4
|
+
import { toHex } from '@xylabs/hex'
|
|
5
|
+
import { findMostRecentBlock, sortBlocks } from '@xyo-network/chain-protocol'
|
|
6
|
+
import type { Payload } from '@xyo-network/payload-model'
|
|
7
|
+
import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
|
|
8
|
+
import { asBlockBoundWitness } from '@xyo-network/xl1-protocol'
|
|
9
|
+
import type { ChainServiceCollection } from '@xyo-network/xl1-protocol-sdk'
|
|
10
|
+
|
|
11
|
+
import { Actor } from '../model/index.ts'
|
|
12
|
+
|
|
13
|
+
export type ChainHeadUpdateActorParams = BaseParams<Pick<ChainServiceCollection, 'chainIterator' | 'chainArchivist'>>
|
|
14
|
+
|
|
15
|
+
export class ChainHeadUpdateActor extends Actor<ChainHeadUpdateActorParams> {
|
|
16
|
+
protected constructor(params: ChainHeadUpdateActorParams) {
|
|
17
|
+
super('ChainHeadUpdate', 'ChainHeadUpdate', params)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
protected get chainFinalizedArchivist() {
|
|
21
|
+
return assertEx(this.params.chainArchivist, () => 'ChainArchivist not set')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
protected get chainIterator() {
|
|
25
|
+
return assertEx(this.params.chainIterator, () => 'chainIterator not set')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static async create(params: ChainHeadUpdateActorParams): Promise<ChainHeadUpdateActor> {
|
|
29
|
+
await Promise.resolve()
|
|
30
|
+
return new ChainHeadUpdateActor(params)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
override async start(): Promise<void> {
|
|
34
|
+
await super.start()
|
|
35
|
+
// Register event handler on all insert event to check for new head
|
|
36
|
+
this.chainFinalizedArchivist.on('inserted', async (data: { payloads: Payload[] }) => {
|
|
37
|
+
await this.checkInsertedForNewHead(data)
|
|
38
|
+
})
|
|
39
|
+
// Poll in case we missed an event
|
|
40
|
+
this.registerTimer('ChainHeadUpdateTimer', async () => await this.pollForNewHead(), 0, 250)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private async checkInsertedForNewHead(data: { payloads: Payload[] }) {
|
|
44
|
+
const candidateBlock = sortBlocks(filterAs(data.payloads, asBlockBoundWitness)).at(-1)
|
|
45
|
+
await this.updateHeadIfNewer(candidateBlock)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private async pollForNewHead() {
|
|
49
|
+
const candidateBlock = await findMostRecentBlock(this.chainFinalizedArchivist)
|
|
50
|
+
await this.updateHeadIfNewer(candidateBlock)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private async updateHeadIfNewer(candidateBlock?: BlockBoundWitness) {
|
|
54
|
+
if (!candidateBlock) return
|
|
55
|
+
const currentHead = await this.chainIterator.head()
|
|
56
|
+
const candidateBlockNumber = candidateBlock.block
|
|
57
|
+
const candidateBlockNumberDisplay = `0x${toHex(candidateBlockNumber)}`
|
|
58
|
+
const currentBlockNumber = currentHead?.block ?? -1
|
|
59
|
+
if (candidateBlockNumber > currentBlockNumber) {
|
|
60
|
+
this.logger?.log('Found more recent head:', candidateBlockNumberDisplay)
|
|
61
|
+
await this.chainIterator.updateHead(candidateBlock)
|
|
62
|
+
this.logger?.log('Updated head:', candidateBlockNumberDisplay)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { BaseParams } from '@xylabs/base'
|
|
3
|
+
import { toHex } from '@xylabs/hex'
|
|
4
|
+
import { isDefined, isUndefined } from '@xylabs/typeof'
|
|
5
|
+
import { createDeclarationIntent } from '@xyo-network/chain-protocol'
|
|
6
|
+
import { BaseBlockProducerService } from '@xyo-network/chain-services'
|
|
7
|
+
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
8
|
+
import type { PayloadBundle } from '@xyo-network/payload-model'
|
|
9
|
+
import { PayloadBundleSchema } from '@xyo-network/payload-model'
|
|
10
|
+
import type {
|
|
11
|
+
ChainStakeIntent,
|
|
12
|
+
HydratedBlock, OpenTelemetryProviders,
|
|
13
|
+
} from '@xyo-network/xl1-protocol'
|
|
14
|
+
import type { ChainServiceCollectionV2 } from '@xyo-network/xl1-protocol-sdk'
|
|
15
|
+
import {
|
|
16
|
+
buildTransaction, flattenHydratedBlock, flattenHydratedTransaction,
|
|
17
|
+
} from '@xyo-network/xl1-protocol-sdk'
|
|
18
|
+
|
|
19
|
+
import { Actor } from '../model/index.ts'
|
|
20
|
+
|
|
21
|
+
export type ProducerActorParams = BaseParams<
|
|
22
|
+
Pick<ChainServiceCollectionV2,
|
|
23
|
+
'account'
|
|
24
|
+
| 'balanceService'
|
|
25
|
+
| 'chainIterator'
|
|
26
|
+
| 'chainStakeViewer'
|
|
27
|
+
| 'chainSubmissionsArchivistWrite'
|
|
28
|
+
| 'pendingBundledTransactionsArchivistWrite'
|
|
29
|
+
| 'producer'
|
|
30
|
+
| 'stakeIntentService'
|
|
31
|
+
>
|
|
32
|
+
& OpenTelemetryProviders>
|
|
33
|
+
|
|
34
|
+
const SHOULD_REGISTER_REDECLARATION_INTENT_TIMER = true
|
|
35
|
+
const TEN_MINUTES = 10 * 60 * 1000 // 10 minutes in milliseconds
|
|
36
|
+
|
|
37
|
+
export class ProducerActor extends Actor<ProducerActorParams> {
|
|
38
|
+
protected _lastProducedBlock: HydratedBlock | undefined
|
|
39
|
+
protected _lastRedeclarationIntent: ChainStakeIntent | undefined
|
|
40
|
+
|
|
41
|
+
protected constructor(params: ProducerActorParams) {
|
|
42
|
+
super(assertEx(params.producer?.address, () => 'Missing producer in params'), 'Producer', params)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
protected get account() {
|
|
46
|
+
return assertEx(this.params.account, () => 'account not set')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected get balanceService() {
|
|
50
|
+
return assertEx(this.params.balanceService, () => 'balanceService not set')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected get chainIterator() {
|
|
54
|
+
return assertEx(this.params.chainIterator, () => 'chainIterator not set')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
protected get chainStakeViewer() {
|
|
58
|
+
return assertEx(this.params.chainStakeViewer, () => 'chainStakeViewer not set')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected get chainSubmissionsArchivistWrite() {
|
|
62
|
+
return assertEx(this.params.chainSubmissionsArchivistWrite, () => 'chainSubmissionsArchivistWrite not set')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected get pendingBundledTransactionsArchivistWrite() {
|
|
66
|
+
return assertEx(this.params.pendingBundledTransactionsArchivistWrite, () => 'pendingBundledTransactionsArchivistWrite not set')
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
protected get producer() {
|
|
70
|
+
return assertEx(this.params.producer, () => 'producer not set')
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
protected get stakeIntentService() {
|
|
74
|
+
return assertEx(this.params.stakeIntentService, () => 'stakeIntentService not set')
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static async create(params: ProducerActorParams): Promise<ProducerActor> {
|
|
78
|
+
await Promise.resolve()
|
|
79
|
+
return new ProducerActor(params)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
override async start(): Promise<void> {
|
|
83
|
+
await super.start()
|
|
84
|
+
// Register a timer to check if we should produce a block
|
|
85
|
+
this.registerTimer('BlockProductionTimer', async () => {
|
|
86
|
+
await this.spanAsync('produceBlock', async () => {
|
|
87
|
+
// Get the updated head
|
|
88
|
+
const head = await this.chainIterator.head()
|
|
89
|
+
// Check if we've already produced the next block for this head
|
|
90
|
+
const headHash = await PayloadBuilder.hash(head)
|
|
91
|
+
// If our last produced block was the next block for the current head, we do not
|
|
92
|
+
// need to produce another. This prevents duplicate blocks from being produced
|
|
93
|
+
if (this._lastProducedBlock && this._lastProducedBlock[0].previous === headHash) {
|
|
94
|
+
this.logger?.log('Block already produced:', `0x${toHex(this._lastProducedBlock[0].block)}`)
|
|
95
|
+
} else {
|
|
96
|
+
// Produce the next block
|
|
97
|
+
const nextBlock = await this.producer.next(head)
|
|
98
|
+
// If it was produced
|
|
99
|
+
if (nextBlock) {
|
|
100
|
+
const displayBlockNumber = `0x${toHex(nextBlock[0].block)}`
|
|
101
|
+
this.logger?.log('Produced block:', displayBlockNumber)
|
|
102
|
+
// Insert the block into the chain
|
|
103
|
+
await this.chainSubmissionsArchivistWrite.insert(flattenHydratedBlock(nextBlock))
|
|
104
|
+
this.logger?.log('Published block:', displayBlockNumber)
|
|
105
|
+
// Record that we have produced a block so we do not produce it again
|
|
106
|
+
this._lastProducedBlock = nextBlock
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
}, 100, 500)
|
|
111
|
+
|
|
112
|
+
if (SHOULD_REGISTER_REDECLARATION_INTENT_TIMER) {
|
|
113
|
+
// Register a timer to check if we should redeclare the producer
|
|
114
|
+
this.registerTimer('ProducerRedeclarationTimer', async () => {
|
|
115
|
+
await this.spanAsync('producerRedeclarationTimer', async () => {
|
|
116
|
+
// Decide if we should redeclare intent
|
|
117
|
+
if (!BaseBlockProducerService.RedeclareIntent) return
|
|
118
|
+
|
|
119
|
+
// Get the current block
|
|
120
|
+
const head = await this.chainIterator.head()
|
|
121
|
+
if (isUndefined(head)) return
|
|
122
|
+
const currentBlock = head.block
|
|
123
|
+
|
|
124
|
+
// Calculate the time until the producer's declaration expires
|
|
125
|
+
const blocksUntilExpiration = await this.calculateBlocksUntilProducerDeclarationExpiration(currentBlock)
|
|
126
|
+
|
|
127
|
+
// Allow the producer time to redeclare itself via block production
|
|
128
|
+
// (for free) before submitting a redeclaration intent transaction.
|
|
129
|
+
if (blocksUntilExpiration > BaseBlockProducerService.RedeclarationWindow * 0.1) {
|
|
130
|
+
// Clear any previous redeclaration intent
|
|
131
|
+
this._lastRedeclarationIntent = undefined
|
|
132
|
+
// No need to redeclare yet
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// If we already have a valid redeclaration intent, do not create another
|
|
137
|
+
// unless it has expired.
|
|
138
|
+
if (this._lastRedeclarationIntent) {
|
|
139
|
+
// Check if the last redeclaration intent is still valid
|
|
140
|
+
if (this._lastRedeclarationIntent.exp > currentBlock) return
|
|
141
|
+
// If it has expired, clear the last redeclaration intent
|
|
142
|
+
this._lastRedeclarationIntent = undefined
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Check if we have a valid balance before declaring intent
|
|
146
|
+
if (!await this.validateCurrentBalance()) {
|
|
147
|
+
this.logger?.error(
|
|
148
|
+
`Add balance to address ${this.account.address} for the producer to declare it's intent.`,
|
|
149
|
+
)
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Check if we have a valid stake before declaring intent
|
|
154
|
+
if (!(await this.validateCurrentStake())) {
|
|
155
|
+
this.logger?.error(
|
|
156
|
+
`Add stake to contract address ${process.env.XYO_EVM_STAKING_CONTRACT_ADDRESS}`
|
|
157
|
+
+ ' for the producer to declare it\'s intent.',
|
|
158
|
+
)
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Create a redeclaration intent
|
|
163
|
+
this.logger?.log('Creating redeclaration intent for producer:', this.account.address)
|
|
164
|
+
const redeclarationIntent = createDeclarationIntent(
|
|
165
|
+
this.account.address,
|
|
166
|
+
'producer',
|
|
167
|
+
currentBlock,
|
|
168
|
+
currentBlock + BaseBlockProducerService.RedeclarationDuration,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
// Submit the redeclaration intent
|
|
172
|
+
await this.submitRedeclarationIntent(currentBlock, redeclarationIntent)
|
|
173
|
+
|
|
174
|
+
// On successful submission, save the redeclaration intent
|
|
175
|
+
this._lastRedeclarationIntent = redeclarationIntent
|
|
176
|
+
})
|
|
177
|
+
}, 10_000, TEN_MINUTES)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
protected async calculateBlocksUntilProducerDeclarationExpiration(currentBlock: number): Promise<number> {
|
|
182
|
+
// Decide if we need to redeclare intent
|
|
183
|
+
const ranges = await this.stakeIntentService.getDeclaredCandidateRanges(this.account.address, 'producer')
|
|
184
|
+
// TODO: This doesn't handle the case where the producer had declared a range for the future
|
|
185
|
+
// but we're in a range that's not the future
|
|
186
|
+
// Sort in ascending order based on ending range to get range with highest ending block
|
|
187
|
+
const lastRange = ranges.toSorted((a, b) => a[1] > b[1] ? 1 : -1).at(-1)
|
|
188
|
+
|
|
189
|
+
// Use the most recent range's end block as the current declaration end OR
|
|
190
|
+
const [, currentDeclarationEnd] = lastRange
|
|
191
|
+
// If we have no ranges, we need to declare intent, so use the current block
|
|
192
|
+
|| [undefined, currentBlock]
|
|
193
|
+
|
|
194
|
+
// Calculate the time until the producer's declaration expires
|
|
195
|
+
const timeToProducerExpiration = currentDeclarationEnd - currentBlock
|
|
196
|
+
return timeToProducerExpiration
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
protected async submitRedeclarationIntent(currentBlock: number, redeclarationIntent: ChainStakeIntent): Promise<void> {
|
|
200
|
+
this.logger?.log('Submitting redeclaration intent for producer:', this.account.address)
|
|
201
|
+
// Create a transaction to submit the redeclaration intent
|
|
202
|
+
const tx = await buildTransaction(
|
|
203
|
+
this.chainIterator.chainId,
|
|
204
|
+
[redeclarationIntent],
|
|
205
|
+
[],
|
|
206
|
+
this.account,
|
|
207
|
+
currentBlock,
|
|
208
|
+
currentBlock + 1000,
|
|
209
|
+
)
|
|
210
|
+
const payloads = flattenHydratedTransaction(tx)
|
|
211
|
+
const root = tx[0]._hash
|
|
212
|
+
const payloadBundle = new PayloadBuilder<PayloadBundle>({ schema: PayloadBundleSchema }).fields({ payloads, root }).build()
|
|
213
|
+
|
|
214
|
+
// Submit the redeclaration intent
|
|
215
|
+
await this.pendingBundledTransactionsArchivistWrite.insert([payloadBundle])
|
|
216
|
+
|
|
217
|
+
this.logger?.log('Submitted redeclaration intent for producer:', this.account.address)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
protected async validateCurrentBalance(): Promise<boolean> {
|
|
221
|
+
// Check if we have a valid balance before declaring intent
|
|
222
|
+
const head = this._lastProducedBlock?.[0]._hash
|
|
223
|
+
if (isDefined(head)) {
|
|
224
|
+
const balances = await this.balanceService.balances(head, [this.account.address])
|
|
225
|
+
const currentBalance = balances[this.account.address] ?? 0n
|
|
226
|
+
if (currentBalance <= 0n) {
|
|
227
|
+
this.logger?.error(`Producer ${this.account.address} has no balance.`)
|
|
228
|
+
return false
|
|
229
|
+
}
|
|
230
|
+
return true
|
|
231
|
+
}
|
|
232
|
+
return true
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
protected async validateCurrentStake(): Promise<boolean> {
|
|
236
|
+
// TODO: Use StakeIntentService to get the required minimum stake for
|
|
237
|
+
// the intent once services is published
|
|
238
|
+
// const requiredMinimumStake = this.stakeIntentService.getRequiredMinimumStakeForIntent('producer')
|
|
239
|
+
const requiredMinimumStake = isDefined(process.env.XYO_PRODUCER_MIN_STAKE)
|
|
240
|
+
? BigInt(process.env.XYO_PRODUCER_MIN_STAKE)
|
|
241
|
+
: 1n
|
|
242
|
+
// Check if we have a valid stake before declaring intent
|
|
243
|
+
const currentStake = await this.chainStakeViewer.activeByAddressStaked(this.account.address)
|
|
244
|
+
if (currentStake < requiredMinimumStake) {
|
|
245
|
+
this.logger?.error(`Producer ${this.account.address} has insufficient stake.`)
|
|
246
|
+
return false
|
|
247
|
+
}
|
|
248
|
+
return true
|
|
249
|
+
}
|
|
250
|
+
}
|