@xyo-network/xl1-protocol-sdk 1.26.12 → 1.26.13
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/simple/accountBalance/SimpleAccountBalanceViewer.d.ts +2 -2
- package/dist/neutral/simple/block/SimpleBlockViewer.d.ts +2 -2
- package/dist/neutral/simple/datalake/SimpleDataLakeRunner.d.ts +1 -1
- package/dist/neutral/simple/finalization/SimpleFinalizationViewer.d.ts +1 -1
- package/dist/neutral/simple/windowedBlock/SimpleWindowedBlockViewer.d.ts +10 -10
- package/dist/neutral/transaction/TransactionBuilder.d.ts +4 -4
- package/dist/neutral/transaction/signTransaction.d.ts +1 -1
- package/package.json +24 -14
- package/src/ChainContextHelpers.ts +0 -50
- package/src/CreatableProvider/AbstractCreatableProvider.ts +0 -97
- package/src/CreatableProvider/CreatableProvider.ts +0 -102
- package/src/CreatableProvider/CreatableProviderRegistry.ts +0 -94
- package/src/CreatableProvider/GetInstanceOptions.ts +0 -11
- package/src/CreatableProvider/LabeledCreatableProviderFactory.ts +0 -24
- package/src/CreatableProvider/ProviderFactory.ts +0 -138
- package/src/CreatableProvider/ProviderFactoryLocator.ts +0 -170
- package/src/CreatableProvider/ProviderFactoryLocatorInstance.ts +0 -70
- package/src/CreatableProvider/index.ts +0 -8
- package/src/SignedBigInt.ts +0 -59
- package/src/_internal/context/getTestProviderContext.ts +0 -13
- package/src/_internal/context/index.ts +0 -1
- package/src/_internal/index.ts +0 -2
- package/src/actor/ActorV3.ts +0 -177
- package/src/actor/index.ts +0 -1
- package/src/amount/ShiftedBigInt.ts +0 -73
- package/src/amount/XL1Amount.ts +0 -103
- package/src/amount/index.ts +0 -4
- package/src/amount/splitOnDecimal.ts +0 -6
- package/src/amount/splitOnDecimalToString.ts +0 -40
- package/src/block/hydrate/allHashesPresent.ts +0 -8
- package/src/block/hydrate/blockPayloadsFromHydratedBlock.ts +0 -12
- package/src/block/hydrate/flattenHydratedBlock.ts +0 -28
- package/src/block/hydrate/flattenHydratedBlocks.ts +0 -7
- package/src/block/hydrate/hydrateBlock.ts +0 -43
- package/src/block/hydrate/index.ts +0 -7
- package/src/block/hydrate/transactionsFromHydratedBlock.ts +0 -7
- package/src/block/hydrate/tryHydrateBlock.ts +0 -26
- package/src/block/index.ts +0 -2
- package/src/block/primitives/blockFromBlockNumber.ts +0 -69
- package/src/block/primitives/frames/calculateFramesFromRange.ts +0 -30
- package/src/block/primitives/frames/deepCalculateFramesFromRange.ts +0 -28
- package/src/block/primitives/frames/index.ts +0 -2
- package/src/block/primitives/hashFromBlockNumber.ts +0 -9
- package/src/block/primitives/index.ts +0 -7
- package/src/block/primitives/model.ts +0 -18
- package/src/block/primitives/payloads/ChainWindow.ts +0 -7
- package/src/block/primitives/payloads/index.ts +0 -1
- package/src/block/primitives/toStepIdentityString.ts +0 -6
- package/src/block/primitives/validateTransactionOpcodes.ts +0 -45
- package/src/config/Actor.ts +0 -32
- package/src/config/Actors.ts +0 -9
- package/src/config/Base.ts +0 -27
- package/src/config/Chain.ts +0 -23
- package/src/config/Config.ts +0 -24
- package/src/config/DataLake/DataLake.ts +0 -12
- package/src/config/DataLake/DataLakeRemoteConfig.ts +0 -11
- package/src/config/DataLake/RestDataLakeConfig.ts +0 -18
- package/src/config/DataLake/RouterDataLakeConfig.ts +0 -22
- package/src/config/DataLake/index.ts +0 -4
- package/src/config/DeepPartial.ts +0 -4
- package/src/config/Evm.ts +0 -38
- package/src/config/HostActor.ts +0 -32
- package/src/config/Log.ts +0 -25
- package/src/config/Provider.ts +0 -20
- package/src/config/Providers.ts +0 -9
- package/src/config/Remote.ts +0 -59
- package/src/config/Telemetry.ts +0 -49
- package/src/config/UsageMeta.ts +0 -46
- package/src/config/Validation.ts +0 -29
- package/src/config/index.ts +0 -12
- package/src/config/storage/Storage.ts +0 -16
- package/src/config/storage/driver/Mongo.ts +0 -53
- package/src/config/storage/driver/index.ts +0 -1
- package/src/config/storage/index.ts +0 -2
- package/src/constants.ts +0 -4
- package/src/context/Actor.ts +0 -20
- package/src/context/HostActor.ts +0 -20
- package/src/context/getEmptyProviderContext.ts +0 -19
- package/src/context/index.ts +0 -3
- package/src/createDeclarationPayload.ts +0 -15
- package/src/createTransferPayload.ts +0 -16
- package/src/driver/cache/LruCacheMap.ts +0 -48
- package/src/driver/cache/index.ts +0 -1
- package/src/driver/index.ts +0 -2
- package/src/driver/memory/MemoryMap.ts +0 -48
- package/src/driver/memory/index.ts +0 -1
- package/src/eip-712/Payloads/EIP712Data.ts +0 -35
- package/src/eip-712/Payloads/EIP712Signature.ts +0 -32
- package/src/eip-712/Payloads/index.ts +0 -2
- package/src/eip-712/Types.ts +0 -41
- package/src/eip-712/index.ts +0 -4
- package/src/eip-712/sign.ts +0 -19
- package/src/eip-712/spec/fixtures.ts +0 -27
- package/src/eip-712/verify.ts +0 -20
- package/src/getFileConfig.ts +0 -36
- package/src/index.ts +0 -27
- package/src/instances/Address.ts +0 -16
- package/src/instances/BoundWitness.ts +0 -13
- package/src/instances/Data.ts +0 -4
- package/src/instances/Fees.ts +0 -9
- package/src/instances/HydratedBoundWitness.ts +0 -16
- package/src/instances/Object.ts +0 -6
- package/src/instances/Payload.ts +0 -7
- package/src/instances/Signature.ts +0 -12
- package/src/instances/block/BlockFields.ts +0 -18
- package/src/instances/block/HydratedBlock.ts +0 -10
- package/src/instances/block/index.ts +0 -1
- package/src/instances/index.ts +0 -10
- package/src/instances/modifiers/BlockWindowInstance.ts +0 -8
- package/src/instances/modifiers/BlockWindowState.ts +0 -6
- package/src/instances/modifiers/Signed.ts +0 -9
- package/src/instances/modifiers/Validatable.ts +0 -6
- package/src/instances/modifiers/index.ts +0 -4
- package/src/instances/transaction/HydratedTransaction.ts +0 -9
- package/src/instances/transaction/TransactionFields.ts +0 -22
- package/src/instances/transaction/index.ts +0 -1
- package/src/isInternetAvailable.ts +0 -11
- package/src/model/ChainFork/ChainForkStatic.ts +0 -9
- package/src/model/ChainFork/index.ts +0 -1
- package/src/model/ChainIdentity.ts +0 -6
- package/src/model/ChainStore.ts +0 -16
- package/src/model/CreatableProviderContext.ts +0 -6
- package/src/model/CreatableProviderContext.zod.ts +0 -55
- package/src/model/PayloadBundle/bundledPayloadToHydratedBlock.ts +0 -15
- package/src/model/PayloadBundle/bundledPayloadToHydratedTransaction.ts +0 -15
- package/src/model/PayloadBundle/hydratedBlockToPayloadBundle.ts +0 -19
- package/src/model/PayloadBundle/hydratedTransactionToPayloadBundle.ts +0 -19
- package/src/model/PayloadBundle/index.ts +0 -4
- package/src/model/index.ts +0 -6
- package/src/multipliers.ts +0 -18
- package/src/payloads/AddressPairPayload.ts +0 -27
- package/src/payloads/index.ts +0 -4
- package/src/payloads/netBalancesForPayloads.ts +0 -24
- package/src/payloads/netSchemasForPayloads.ts +0 -24
- package/src/payloads/netTransfersForPayloads.ts +0 -27
- package/src/primitives/block/index.ts +0 -2
- package/src/primitives/block/range/blockRangeSteps.ts +0 -23
- package/src/primitives/block/range/index.ts +0 -1
- package/src/primitives/block/rate/blockRate.ts +0 -77
- package/src/primitives/block/rate/index.ts +0 -4
- package/src/primitives/block/rate/stepRate.ts +0 -37
- package/src/primitives/block/rate/timeHelpers.ts +0 -61
- package/src/primitives/block/rate/timeRate.ts +0 -121
- package/src/primitives/chain/getWindowedChain.ts +0 -50
- package/src/primitives/chain/index.ts +0 -3
- package/src/primitives/chain/step/chainStepRewardAddress.ts +0 -30
- package/src/primitives/chain/step/index.ts +0 -4
- package/src/primitives/chain/step/stepRewardBlock.ts +0 -13
- package/src/primitives/chain/step/stepRewardTotal.ts +0 -46
- package/src/primitives/chain/step/stepsRewardTotal.ts +0 -37
- package/src/primitives/chain/time/externalBlockNumberFromXL1BlockNumber.ts +0 -32
- package/src/primitives/chain/time/externalBlockRangeFromStep.ts +0 -21
- package/src/primitives/chain/time/externalBlockRangeFromXL1BlockRange.ts +0 -17
- package/src/primitives/chain/time/index.ts +0 -3
- package/src/primitives/datalake/addDataLakePayloads.ts +0 -18
- package/src/primitives/datalake/addDataLakePayloadsToPayloads.ts +0 -24
- package/src/primitives/datalake/index.ts +0 -2
- package/src/primitives/index.ts +0 -13
- package/src/primitives/mapToMapType.ts +0 -35
- package/src/primitives/payload/index.ts +0 -1
- package/src/primitives/payload/mergeTransfers.ts +0 -16
- package/src/primitives/readPayloadMapFromStore.ts +0 -58
- package/src/primitives/rewardFromBlockNumber.ts +0 -19
- package/src/primitives/rewards/index.ts +0 -1
- package/src/primitives/rewards/networkStakeStepRewardPositionWeight.ts +0 -26
- package/src/primitives/stake/activeStakeAtTimeByAddress.ts +0 -27
- package/src/primitives/stake/activeStakeAtTimeByPosition.ts +0 -25
- package/src/primitives/stake/allStakersForRange.ts +0 -32
- package/src/primitives/stake/allStakersForStep.ts +0 -24
- package/src/primitives/stake/index.ts +0 -6
- package/src/primitives/stake/mergedAddRemoveStakeEventsByPosition.ts +0 -15
- package/src/primitives/stake/mergedAddRemoveStakeEventsByStaker.ts +0 -17
- package/src/primitives/stake/weightedStakeForRangeByPosition.ts +0 -69
- package/src/primitives/state/findMostRecentBlock.ts +0 -44
- package/src/primitives/state/hydratedBlockByNumber.ts +0 -25
- package/src/primitives/state/index.ts +0 -2
- package/src/primitives/step/completedStepRewardAddress.ts +0 -10
- package/src/primitives/step/derivedReceiveAddress.ts +0 -9
- package/src/primitives/step/index.ts +0 -4
- package/src/primitives/step/stepBlockRange.ts +0 -9
- package/src/primitives/step/stepTransferIndex.ts +0 -19
- package/src/primitives/transaction/elevatedPayloads.ts +0 -24
- package/src/primitives/transaction/index.ts +0 -1
- package/src/primitives/uncle/findBestUncle.ts +0 -9
- package/src/primitives/uncle/findUncles.ts +0 -75
- package/src/primitives/uncle/index.ts +0 -3
- package/src/primitives/uncle/scoreUncle.ts +0 -7
- package/src/services/AccountTransfersService.ts +0 -13
- package/src/services/BlockProducerService.ts +0 -11
- package/src/services/Chain/BaseChainService.ts +0 -4
- package/src/services/Chain/ChainHeadService.ts +0 -8
- package/src/services/Chain/ChainService.ts +0 -6
- package/src/services/Chain/index.ts +0 -3
- package/src/services/Election.ts +0 -14
- package/src/services/NetworkStakeService.ts +0 -4
- package/src/services/Params.ts +0 -13
- package/src/services/PendingTransactionsService.ts +0 -7
- package/src/services/SchemasService.ts +0 -11
- package/src/services/StakeIntentService/ChainIndexingServiceStateSchema.ts +0 -50
- package/src/services/StakeIntentService/StakeIntentService.ts +0 -35
- package/src/services/StakeIntentService/index.ts +0 -2
- package/src/services/index.ts +0 -8
- package/src/simple/StakeEventsViewer/SimpleStakeEventsViewer.ts +0 -93
- package/src/simple/StakeEventsViewer/index.ts +0 -1
- package/src/simple/StakeTotalsViewer/SimpleStakeTotalsViewer.ts +0 -116
- package/src/simple/StakeTotalsViewer/index.ts +0 -1
- package/src/simple/StakeViewer/SimpleStakeViewer.ts +0 -164
- package/src/simple/StakeViewer/index.ts +0 -1
- package/src/simple/TransactionViewer/SimpleTransactionViewer.ts +0 -100
- package/src/simple/TransactionViewer/index.ts +0 -1
- package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +0 -271
- package/src/simple/accountBalance/index.ts +0 -1
- package/src/simple/block/SimpleBlockViewer.ts +0 -231
- package/src/simple/block/index.ts +0 -1
- package/src/simple/blockInvalidation/SimpleBlockInvalidationViewer.ts +0 -197
- package/src/simple/blockInvalidation/index.ts +0 -1
- package/src/simple/blockReward/SimpleBlockRewardViewer.ts +0 -27
- package/src/simple/blockReward/index.ts +0 -1
- package/src/simple/blockValidation/SimpleBlockValidationViewer.ts +0 -194
- package/src/simple/blockValidation/index.ts +0 -1
- package/src/simple/chainContractViewer/SimpleChainContractViewer.ts +0 -92
- package/src/simple/chainContractViewer/index.ts +0 -1
- package/src/simple/client/SimpleXyoClient.ts +0 -14
- package/src/simple/client/index.ts +0 -1
- package/src/simple/datalake/AbstractRestDataLake.ts +0 -70
- package/src/simple/datalake/AbstractSimpleDataLake.ts +0 -62
- package/src/simple/datalake/RestDataLakeRunner.ts +0 -54
- package/src/simple/datalake/RestDataLakeViewer.ts +0 -22
- package/src/simple/datalake/SimpleDataLakeRunner.ts +0 -44
- package/src/simple/datalake/SimpleDataLakeViewer.ts +0 -24
- package/src/simple/datalake/index.ts +0 -4
- package/src/simple/finalization/SimpleFinalizationRunner.ts +0 -45
- package/src/simple/finalization/SimpleFinalizationViewer.ts +0 -123
- package/src/simple/finalization/index.ts +0 -2
- package/src/simple/gateway/SimpleXyoGateway.ts +0 -30
- package/src/simple/gateway/SimpleXyoGatewayRunner.ts +0 -137
- package/src/simple/gateway/index.ts +0 -2
- package/src/simple/index.ts +0 -22
- package/src/simple/mempool/SimpleMempoolRunner.ts +0 -390
- package/src/simple/mempool/SimpleMempoolViewer.ts +0 -215
- package/src/simple/mempool/index.ts +0 -2
- package/src/simple/network/SimpleXyoNetwork.ts +0 -48
- package/src/simple/network/index.ts +0 -1
- package/src/simple/network/lib/FailedNetworkStatusPayloads.ts +0 -16
- package/src/simple/network/lib/StatusNetworks.ts +0 -32
- package/src/simple/network/lib/index.ts +0 -2
- package/src/simple/permissions/SimpleXyoPermissions.ts +0 -82
- package/src/simple/permissions/index.ts +0 -2
- package/src/simple/permissions/store/MemoryPermissions.ts +0 -32
- package/src/simple/permissions/store/PermissionsStore.ts +0 -17
- package/src/simple/permissions/store/index.ts +0 -2
- package/src/simple/runner/SimpleXyoRunner.ts +0 -41
- package/src/simple/runner/index.ts +0 -1
- package/src/simple/signer/SimpleXyoSigner.ts +0 -78
- package/src/simple/signer/index.ts +0 -1
- package/src/simple/timeSync2/SimpleTimeSyncViewer.ts +0 -132
- package/src/simple/timeSync2/index.ts +0 -1
- package/src/simple/transactionInvalidation/SimpleTransactionInvalidationViewer.ts +0 -197
- package/src/simple/transactionInvalidation/index.ts +0 -1
- package/src/simple/transactionValidation/SimpleTransactionValidationViewer.ts +0 -173
- package/src/simple/transactionValidation/index.ts +0 -1
- package/src/simple/windowedBlock/SimpleWindowedBlockViewer.ts +0 -207
- package/src/simple/windowedBlock/index.ts +0 -1
- package/src/status/RuntimeStatusMonitor.ts +0 -120
- package/src/status/ServiceStatus.ts +0 -21
- package/src/status/index.ts +0 -2
- package/src/summary/index.ts +0 -2
- package/src/summary/model/BalancesStepSummary.ts +0 -35
- package/src/summary/model/SchemasStepSummary.ts +0 -33
- package/src/summary/model/StepSummary.ts +0 -20
- package/src/summary/model/TransfersSummary.ts +0 -36
- package/src/summary/model/index.ts +0 -4
- package/src/summary/primitives/balances/balancesStepSummaryFromRange.ts +0 -94
- package/src/summary/primitives/balances/balancesSummary.ts +0 -48
- package/src/summary/primitives/balances/index.ts +0 -2
- package/src/summary/primitives/index.ts +0 -3
- package/src/summary/primitives/schemas/index.ts +0 -2
- package/src/summary/primitives/schemas/schemasStepSummaryFromRange.ts +0 -86
- package/src/summary/primitives/schemas/schemasSummary.ts +0 -44
- package/src/summary/primitives/transfers/index.ts +0 -2
- package/src/summary/primitives/transfers/transfersStepSummaryFromRange.ts +0 -109
- package/src/summary/primitives/transfers/transfersSummary.ts +0 -52
- package/src/test/BuildBlockOptions.ts +0 -81
- package/src/test/buildBlock.ts +0 -105
- package/src/test/buildGenesisBlock.ts +0 -29
- package/src/test/buildNextBlock.ts +0 -37
- package/src/test/buildRandomChain.ts +0 -92
- package/src/test/buildRandomGenesisBlock.ts +0 -47
- package/src/test/createGenesisBlock.ts +0 -41
- package/src/test/createProducerChainStakeIntentTransaction.ts +0 -48
- package/src/test/getSimpleBlockViewerLocator.ts +0 -41
- package/src/test/getTestProviderContext.ts +0 -8
- package/src/test/index.ts +0 -2
- package/src/time/index.ts +0 -1
- package/src/time/primitives/index.ts +0 -1
- package/src/time/primitives/xl1BlockNumberToEthBlockNumber.ts +0 -13
- package/src/transaction/TransactionBuilder.ts +0 -164
- package/src/transaction/buildRandomTransaction.ts +0 -38
- package/src/transaction/buildTransaction.ts +0 -68
- package/src/transaction/buildUnsignedTransaction.ts +0 -56
- package/src/transaction/confirmSubmittedTransaction.ts +0 -42
- package/src/transaction/hydrateTransaction.ts +0 -117
- package/src/transaction/index.ts +0 -9
- package/src/transaction/primitives/index.ts +0 -4
- package/src/transaction/primitives/transactionBlockByteCount.ts +0 -10
- package/src/transaction/primitives/transactionElevatedPayloads.ts +0 -18
- package/src/transaction/primitives/transactionOperations.ts +0 -13
- package/src/transaction/primitives/transactionRequiredGas.ts +0 -22
- package/src/transaction/script.ts +0 -48
- package/src/transaction/signTransaction.ts +0 -32
- package/src/utils/HydratedCache.ts +0 -39
- package/src/utils/index.ts +0 -2
- package/src/utils/isZodError.ts +0 -11
- package/src/validation/index.ts +0 -2
- package/src/validation/lib/getUrl.ts +0 -7
- package/src/validation/lib/index.ts +0 -2
- package/src/validation/lib/isLocalhost.ts +0 -9
- package/src/validation/schema/Address.ts +0 -2
- package/src/validation/schema/Mnemonic.ts +0 -21
- package/src/validation/schema/index.ts +0 -2
- package/src/wallet/generateXyoBaseWalletFromPhrase.ts +0 -13
- package/src/wallet/index.ts +0 -2
- package/src/wallet/paths.ts +0 -17
|
@@ -1,390 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertEx, exists, type Hash,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import type { ArchivistInstance } from '@xyo-network/sdk-js'
|
|
5
|
-
import {
|
|
6
|
-
isPayloadBundle, Payload, PayloadBuilder,
|
|
7
|
-
Sequence,
|
|
8
|
-
WithHashMeta,
|
|
9
|
-
} from '@xyo-network/sdk-js'
|
|
10
|
-
import {
|
|
11
|
-
BlockValidationViewer,
|
|
12
|
-
BlockValidationViewerMoniker,
|
|
13
|
-
ChainContractViewer,
|
|
14
|
-
ChainContractViewerMoniker,
|
|
15
|
-
DEFAULT_MAX_EXP_AHEAD,
|
|
16
|
-
FinalizationViewer,
|
|
17
|
-
FinalizationViewerMoniker,
|
|
18
|
-
isSignedHydratedBlockWithHashMeta, isSignedHydratedTransactionWithHashMeta, MempoolPruneOptions, MempoolRunner,
|
|
19
|
-
MempoolRunnerMoniker, type MempoolViewer, type SignedHydratedBlock, SignedHydratedBlockWithHashMeta, type SignedHydratedTransaction,
|
|
20
|
-
SignedHydratedTransactionWithHashMeta,
|
|
21
|
-
TransactionValidationViewer,
|
|
22
|
-
TransactionValidationViewerMoniker,
|
|
23
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
24
|
-
import { Mutex } from 'async-mutex'
|
|
25
|
-
|
|
26
|
-
import { validateTransactionsOpcodes } from '../../block/index.ts'
|
|
27
|
-
import {
|
|
28
|
-
AbstractCreatableProvider, creatableProvider, CreatableProviderParams,
|
|
29
|
-
} from '../../CreatableProvider/index.ts'
|
|
30
|
-
import {
|
|
31
|
-
bundledPayloadToHydratedBlock,
|
|
32
|
-
bundledPayloadToHydratedTransaction,
|
|
33
|
-
hydratedBlockToPayloadBundle, hydratedTransactionToPayloadBundle,
|
|
34
|
-
} from '../../model/index.ts'
|
|
35
|
-
|
|
36
|
-
const DEFAULT_SYNC_INTERVAL = 30_000
|
|
37
|
-
const DEFAULT_SYNC_LIMIT = 100
|
|
38
|
-
|
|
39
|
-
/** Parameters for SimpleMempoolRunner. */
|
|
40
|
-
export interface SimpleMempoolRunnerParams extends CreatableProviderParams {
|
|
41
|
-
externalMempools?: MempoolViewer[]
|
|
42
|
-
maxExpAhead?: number
|
|
43
|
-
pendingBlocksArchivist: ArchivistInstance
|
|
44
|
-
pendingTransactionsArchivist: ArchivistInstance
|
|
45
|
-
syncInterval?: number
|
|
46
|
-
syncLimit?: number
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** SimpleMempoolRunner implementation. */
|
|
50
|
-
@creatableProvider()
|
|
51
|
-
export class SimpleMempoolRunner extends AbstractCreatableProvider<SimpleMempoolRunnerParams> implements MempoolRunner {
|
|
52
|
-
static readonly defaultMoniker = MempoolRunnerMoniker
|
|
53
|
-
static readonly dependencies = [FinalizationViewerMoniker, BlockValidationViewerMoniker, TransactionValidationViewerMoniker, ChainContractViewerMoniker]
|
|
54
|
-
static readonly monikers = [MempoolRunnerMoniker]
|
|
55
|
-
moniker = SimpleMempoolRunner.defaultMoniker
|
|
56
|
-
|
|
57
|
-
protected _blockValidationViewer!: BlockValidationViewer
|
|
58
|
-
protected _chainContractViewer!: ChainContractViewer
|
|
59
|
-
protected _finalizationViewer!: FinalizationViewer
|
|
60
|
-
protected _transactionValidationViewer!: TransactionValidationViewer
|
|
61
|
-
|
|
62
|
-
private _syncMutex = new Mutex()
|
|
63
|
-
private _syncTimerId: ReturnType<typeof setInterval> | null = null
|
|
64
|
-
|
|
65
|
-
protected get blockValidationViewer() {
|
|
66
|
-
return this._blockValidationViewer!
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
protected get chainContractViewer() {
|
|
70
|
-
return this._chainContractViewer!
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
protected get externalMempools(): MempoolViewer[] {
|
|
74
|
-
return this.params.externalMempools ?? []
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
protected get finalizationViewer() {
|
|
78
|
-
return this._finalizationViewer!
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
protected get maxExpAhead() {
|
|
82
|
-
return this.params.maxExpAhead ?? DEFAULT_MAX_EXP_AHEAD
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
protected get pendingBlocksArchivist() {
|
|
86
|
-
return this.params.pendingBlocksArchivist
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
protected get pendingTransactionsArchivist() {
|
|
90
|
-
return this.params.pendingTransactionsArchivist
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
protected get syncInterval(): number {
|
|
94
|
-
return this.params.syncInterval ?? DEFAULT_SYNC_INTERVAL
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
protected get syncLimit(): number {
|
|
98
|
-
return this.params.syncLimit ?? DEFAULT_SYNC_LIMIT
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
protected get transactionValidationViewer() {
|
|
102
|
-
return this._transactionValidationViewer!
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
static override async paramsHandler(params?: Partial<SimpleMempoolRunnerParams>): Promise<SimpleMempoolRunnerParams> {
|
|
106
|
-
return {
|
|
107
|
-
...await super.paramsHandler(params),
|
|
108
|
-
pendingBlocksArchivist: assertEx(params?.pendingBlocksArchivist, () => 'pendingBlocksArchivist is required'),
|
|
109
|
-
pendingTransactionsArchivist: assertEx(params?.pendingTransactionsArchivist, () => 'pendingTransactionsArchivist is required'),
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
override async createHandler() {
|
|
114
|
-
await super.createHandler()
|
|
115
|
-
this._blockValidationViewer = await this.locator.getInstance<BlockValidationViewer>(BlockValidationViewerMoniker)
|
|
116
|
-
this._chainContractViewer = await this.locator.getInstance<ChainContractViewer>(ChainContractViewerMoniker)
|
|
117
|
-
this._finalizationViewer = await this.locator.getInstance<FinalizationViewer>(FinalizationViewerMoniker)
|
|
118
|
-
this._transactionValidationViewer = await this.locator.getInstance<TransactionValidationViewer>(TransactionValidationViewerMoniker)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async prunePendingBlocks({
|
|
122
|
-
batchSize = 10, maxPrune = 1000, maxCheck = 1000,
|
|
123
|
-
}: MempoolPruneOptions = {}): Promise<[number, number]> {
|
|
124
|
-
let total = 0
|
|
125
|
-
let pruned = 0
|
|
126
|
-
let cursor: Sequence | undefined
|
|
127
|
-
let batch = await this.pendingBlocksArchivist.next({
|
|
128
|
-
limit: batchSize, cursor, order: 'desc',
|
|
129
|
-
})
|
|
130
|
-
this.logger?.info(`Starting prunePendingBlocks with batchSize=${batchSize}, maxPrune=${maxPrune}, maxCheck=${maxCheck}`)
|
|
131
|
-
while (batch.length > 0 && pruned < maxPrune && total < maxCheck) {
|
|
132
|
-
const blocksAndBundles = await this.simpleBlockValidationCheck(batch)
|
|
133
|
-
const blocks = blocksAndBundles.map(([b]) => b)
|
|
134
|
-
const bundles = blocksAndBundles.map(([_, p]) => p)
|
|
135
|
-
let valid = blocks.map(b => !!b)
|
|
136
|
-
let remainingBlockMap: number[] = []
|
|
137
|
-
let remainingBlocks = blocks.map((b, i) => {
|
|
138
|
-
if (b) {
|
|
139
|
-
remainingBlockMap.push(i)
|
|
140
|
-
return b
|
|
141
|
-
}
|
|
142
|
-
}).filter(exists)
|
|
143
|
-
|
|
144
|
-
assertEx(
|
|
145
|
-
remainingBlockMap.length === remainingBlocks.length,
|
|
146
|
-
() => `remainingBlockMap length should match remainingBlocks length [${remainingBlockMap.length}/${remainingBlocks.length}]`,
|
|
147
|
-
)
|
|
148
|
-
const validationResults = await Promise.all(remainingBlocks.map(remainingBlock => this.blockValidationViewer.validateBlock(
|
|
149
|
-
remainingBlock,
|
|
150
|
-
{ value: true, state: true },
|
|
151
|
-
)))
|
|
152
|
-
for (const [i, r] of validationResults.entries()) {
|
|
153
|
-
const validated = isSignedHydratedBlockWithHashMeta(r)
|
|
154
|
-
if (!validated) {
|
|
155
|
-
this.logger?.info(`Pruning block ${bundles[remainingBlockMap[i]]._hash} during block validation`)
|
|
156
|
-
this.logger?.info(` - validation result: ${JSON.stringify(r, null, 2)}`)
|
|
157
|
-
}
|
|
158
|
-
valid[remainingBlockMap[i]] = validated
|
|
159
|
-
}
|
|
160
|
-
const pruneHashes = bundles.map((p, i) => {
|
|
161
|
-
if (!valid[i]) {
|
|
162
|
-
return p._hash
|
|
163
|
-
}
|
|
164
|
-
}).filter(exists)
|
|
165
|
-
|
|
166
|
-
pruned += pruneHashes.length
|
|
167
|
-
total += batch.length
|
|
168
|
-
await this.pendingBlocksArchivist.delete(pruneHashes)
|
|
169
|
-
|
|
170
|
-
cursor = batch.at(-1)?._sequence
|
|
171
|
-
|
|
172
|
-
batch = cursor
|
|
173
|
-
? await this.pendingBlocksArchivist.next({
|
|
174
|
-
limit: batchSize, cursor, order: 'desc',
|
|
175
|
-
})
|
|
176
|
-
: []
|
|
177
|
-
}
|
|
178
|
-
this.logger?.info(`prunePendingBlocks completed: pruned=${pruned}, totalChecked=${total}`)
|
|
179
|
-
return [pruned, total]
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async prunePendingTransactions({
|
|
183
|
-
batchSize = 10, maxPrune = 1000, maxCheck = 1000,
|
|
184
|
-
}: MempoolPruneOptions = {}): Promise<[number, number]> {
|
|
185
|
-
let total = 0
|
|
186
|
-
let pruned = 0
|
|
187
|
-
let cursor: Sequence | undefined
|
|
188
|
-
let batch = await this.pendingTransactionsArchivist.next({
|
|
189
|
-
limit: batchSize, cursor, order: 'desc',
|
|
190
|
-
})
|
|
191
|
-
this.logger?.info(`Starting prunePendingTransactions with batchSize=${batchSize}, maxPrune=${maxPrune}, maxCheck=${maxCheck}`)
|
|
192
|
-
while (batch.length > 0 && pruned < maxPrune && total < maxCheck) {
|
|
193
|
-
const transactionsAndBundles = await this.simpleTransactionValidationCheck(batch)
|
|
194
|
-
const transactions = transactionsAndBundles.map(([t]) => t)
|
|
195
|
-
const bundles = transactionsAndBundles.map(([_, p]) => p)
|
|
196
|
-
let valid = transactions.map(t => !!t)
|
|
197
|
-
let remainingTransactionMap: number[] = []
|
|
198
|
-
let remainingTransactions = transactions.map((t, i) => {
|
|
199
|
-
if (t) {
|
|
200
|
-
remainingTransactionMap.push(i)
|
|
201
|
-
return t
|
|
202
|
-
}
|
|
203
|
-
}).filter(exists)
|
|
204
|
-
|
|
205
|
-
assertEx(
|
|
206
|
-
remainingTransactionMap.length === remainingTransactions.length,
|
|
207
|
-
() => `remainingTransactionMap length should match remainingTransactions length [${remainingTransactionMap.length}/${remainingTransactions.length}]`,
|
|
208
|
-
)
|
|
209
|
-
|
|
210
|
-
const validationResults = await Promise.all(remainingTransactions.map(remainingTransaction => this.transactionValidationViewer.validateTransaction(
|
|
211
|
-
remainingTransaction,
|
|
212
|
-
{ value: true, state: true },
|
|
213
|
-
)))
|
|
214
|
-
for (const [i, r] of validationResults.entries()) {
|
|
215
|
-
const validated = isSignedHydratedTransactionWithHashMeta(r)
|
|
216
|
-
if (!validated) {
|
|
217
|
-
this.logger?.info(`Pruning transaction ${bundles[remainingTransactionMap[i]]._hash} during transaction validation`)
|
|
218
|
-
this.logger?.info(` - validation result: ${JSON.stringify(r, null, 2)}`)
|
|
219
|
-
}
|
|
220
|
-
valid[remainingTransactionMap[i]] = validated
|
|
221
|
-
}
|
|
222
|
-
const pruneHashes = bundles.map((p, i) => {
|
|
223
|
-
if (!valid[i]) {
|
|
224
|
-
return p._hash
|
|
225
|
-
}
|
|
226
|
-
}).filter(exists)
|
|
227
|
-
|
|
228
|
-
pruned += pruneHashes.length
|
|
229
|
-
total += batch.length
|
|
230
|
-
await this.pendingTransactionsArchivist.delete(pruneHashes)
|
|
231
|
-
|
|
232
|
-
cursor = batch.at(-1)?._sequence
|
|
233
|
-
|
|
234
|
-
batch = cursor
|
|
235
|
-
? await this.pendingTransactionsArchivist.next({
|
|
236
|
-
limit: batchSize, cursor, order: 'desc',
|
|
237
|
-
})
|
|
238
|
-
: []
|
|
239
|
-
}
|
|
240
|
-
this.logger?.info(`prunePendingTransactions completed: pruned=${pruned}, totalChecked=${total}`)
|
|
241
|
-
return [pruned, total]
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
async submitBlocks(blocks: SignedHydratedBlock[]): Promise<Hash[]> {
|
|
245
|
-
const bundles = await Promise.all(blocks.map(async ([bw, payloads]) => {
|
|
246
|
-
return hydratedBlockToPayloadBundle([
|
|
247
|
-
await PayloadBuilder.addHashMeta(bw),
|
|
248
|
-
await PayloadBuilder.addHashMeta(payloads),
|
|
249
|
-
])
|
|
250
|
-
}))
|
|
251
|
-
const inserted = await this.pendingBlocksArchivist.insert(bundles)
|
|
252
|
-
return inserted.map(p => p._hash)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
async submitTransactions(transactions: SignedHydratedTransaction[]): Promise<Hash[]> {
|
|
256
|
-
const headNumber = await this.finalizationViewer.headNumber()
|
|
257
|
-
const maxExp = headNumber + this.maxExpAhead
|
|
258
|
-
|
|
259
|
-
const validTransactions = transactions.filter(([tx]) => {
|
|
260
|
-
if (tx.exp > maxExp) {
|
|
261
|
-
this.logger?.info(`Rejecting transaction with exp ${tx.exp} exceeding max allowed ${maxExp}`)
|
|
262
|
-
return false
|
|
263
|
-
}
|
|
264
|
-
return true
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
const bundles = await Promise.all(validTransactions.map(async ([tx, payloads]) => {
|
|
268
|
-
return hydratedTransactionToPayloadBundle([
|
|
269
|
-
await PayloadBuilder.addHashMeta(tx),
|
|
270
|
-
await PayloadBuilder.addHashMeta(payloads),
|
|
271
|
-
])
|
|
272
|
-
}))
|
|
273
|
-
const inserted = await this.pendingTransactionsArchivist.insert(bundles)
|
|
274
|
-
return inserted.map(p => p._hash)
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
protected override async startHandler(): Promise<void> {
|
|
278
|
-
await super.startHandler()
|
|
279
|
-
if (this.externalMempools.length > 0) {
|
|
280
|
-
await this.syncFromExternal()
|
|
281
|
-
this._syncTimerId = setInterval(() => {
|
|
282
|
-
void this.syncFromExternal()
|
|
283
|
-
}, this.syncInterval)
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
protected override async stopHandler(): Promise<void> {
|
|
288
|
-
await super.stopHandler()
|
|
289
|
-
if (this._syncTimerId) {
|
|
290
|
-
clearInterval(this._syncTimerId)
|
|
291
|
-
this._syncTimerId = null
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
private async simpleBlockValidationCheck(payloads: WithHashMeta<Payload>[]): Promise<[(SignedHydratedBlockWithHashMeta | undefined), WithHashMeta<Payload>][]> {
|
|
296
|
-
const headNumber = await this.finalizationViewer.headNumber()
|
|
297
|
-
const chainId = await this.chainContractViewer.chainId()
|
|
298
|
-
|
|
299
|
-
const blockBundles: [SignedHydratedBlockWithHashMeta | undefined, WithHashMeta<Payload>][] = await Promise.all(payloads.map(async (p) => {
|
|
300
|
-
return [isPayloadBundle(p) ? await bundledPayloadToHydratedBlock(p) : undefined, p]
|
|
301
|
-
}))
|
|
302
|
-
|
|
303
|
-
return blockBundles.map(([block, bundle]) => {
|
|
304
|
-
const blockCheckPassed = !!block
|
|
305
|
-
const chainIdPassed = blockCheckPassed ? block[0].chain === chainId : false
|
|
306
|
-
const blockNumberPassed = blockCheckPassed ? block[0].block > headNumber : false
|
|
307
|
-
const typeCheckPassed = blockCheckPassed ? isSignedHydratedBlockWithHashMeta(block) : false
|
|
308
|
-
const validationPassed = blockCheckPassed && chainIdPassed && blockNumberPassed && typeCheckPassed
|
|
309
|
-
const validatedBlock = validationPassed ? block : undefined
|
|
310
|
-
if (!validationPassed) {
|
|
311
|
-
this.logger?.info(`Pruning block bundle ${bundle._hash} during simpleValidationCheck`)
|
|
312
|
-
this.logger?.info(` - chainId match: ${chainIdPassed}`)
|
|
313
|
-
this.logger?.info(` - blockNumber check: ${blockNumberPassed}`)
|
|
314
|
-
this.logger?.info(` - typeCheck: ${typeCheckPassed}`)
|
|
315
|
-
this.logger?.info(` - bundle hash: ${bundle._hash}`)
|
|
316
|
-
}
|
|
317
|
-
return [validatedBlock, bundle]
|
|
318
|
-
})
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
private async simpleTransactionValidationCheck(payloads: WithHashMeta<Payload>[]): Promise<[(SignedHydratedTransactionWithHashMeta | undefined), WithHashMeta<Payload>][]> {
|
|
322
|
-
const headNumber = await this.finalizationViewer.headNumber()
|
|
323
|
-
const chainId = await this.chainContractViewer.chainId()
|
|
324
|
-
|
|
325
|
-
const transactionBundles: [SignedHydratedTransactionWithHashMeta | undefined, WithHashMeta<Payload>][] = await Promise.all(payloads.map(async (p) => {
|
|
326
|
-
return [isPayloadBundle(p) ? await bundledPayloadToHydratedTransaction(p) : undefined, p]
|
|
327
|
-
}))
|
|
328
|
-
|
|
329
|
-
// eslint-disable-next-line complexity
|
|
330
|
-
return await Promise.all(transactionBundles.map(async ([transaction, bundle]) => {
|
|
331
|
-
const transactionCheckPassed = !!transaction
|
|
332
|
-
const chainIdPassed = transactionCheckPassed ? transaction[0].chain === chainId : false
|
|
333
|
-
const expPassed = transactionCheckPassed
|
|
334
|
-
? transaction[0].exp > headNumber && transaction[0].exp <= headNumber + this.maxExpAhead
|
|
335
|
-
: false
|
|
336
|
-
const typeCheckPassed = transactionCheckPassed ? isSignedHydratedTransactionWithHashMeta(transaction) : false
|
|
337
|
-
let opcodeCheckPassed = false
|
|
338
|
-
try {
|
|
339
|
-
await validateTransactionsOpcodes(transaction ? [transaction] : [])
|
|
340
|
-
opcodeCheckPassed = true
|
|
341
|
-
} catch (e) {
|
|
342
|
-
this.logger?.info(`Opcode validation failed for transaction ${bundle._hash} during simpleValidationCheck`)
|
|
343
|
-
this.logger?.info(` - error: ${(e as Error).message}`)
|
|
344
|
-
}
|
|
345
|
-
const validationPassed = transactionCheckPassed && chainIdPassed && expPassed && typeCheckPassed && opcodeCheckPassed
|
|
346
|
-
const validatedTransaction = validationPassed ? transaction : undefined
|
|
347
|
-
if (!validationPassed) {
|
|
348
|
-
this.logger?.info(`Pruning block bundle ${bundle._hash} during simpleValidationCheck`)
|
|
349
|
-
this.logger?.info(` - chainId match: ${chainIdPassed}`)
|
|
350
|
-
this.logger?.info(` - exp check: ${expPassed}`)
|
|
351
|
-
this.logger?.info(` - opcode check: ${opcodeCheckPassed}`)
|
|
352
|
-
this.logger?.info(` - typeCheck: ${typeCheckPassed}`)
|
|
353
|
-
this.logger?.info(` - bundle hash: ${bundle._hash}`)
|
|
354
|
-
}
|
|
355
|
-
return [validatedTransaction, bundle]
|
|
356
|
-
}))
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
private async syncBlocksFrom(external: MempoolViewer): Promise<void> {
|
|
360
|
-
const externalBlocks = await external.pendingBlocks({ limit: this.syncLimit })
|
|
361
|
-
if (externalBlocks.length === 0) return
|
|
362
|
-
|
|
363
|
-
const bundles = externalBlocks.map(block => hydratedBlockToPayloadBundle(block))
|
|
364
|
-
await this.pendingBlocksArchivist.insert(bundles)
|
|
365
|
-
this.logger?.info(`Synced ${externalBlocks.length} blocks from external mempool`)
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
private async syncFromExternal(): Promise<void> {
|
|
369
|
-
if (this._syncMutex.isLocked()) return
|
|
370
|
-
await this._syncMutex.runExclusive(async () => {
|
|
371
|
-
for (const external of this.externalMempools) {
|
|
372
|
-
try {
|
|
373
|
-
await this.syncTransactionsFrom(external)
|
|
374
|
-
await this.syncBlocksFrom(external)
|
|
375
|
-
} catch (ex) {
|
|
376
|
-
this.logger?.error(`Error syncing from external mempool: ${ex}`)
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
})
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
private async syncTransactionsFrom(external: MempoolViewer): Promise<void> {
|
|
383
|
-
const externalTxs = await external.pendingTransactions({ limit: this.syncLimit })
|
|
384
|
-
if (externalTxs.length === 0) return
|
|
385
|
-
|
|
386
|
-
const bundles = externalTxs.map(tx => hydratedTransactionToPayloadBundle(tx))
|
|
387
|
-
await this.pendingTransactionsArchivist.insert(bundles)
|
|
388
|
-
this.logger?.info(`Synced ${externalTxs.length} transactions from external mempool`)
|
|
389
|
-
}
|
|
390
|
-
}
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
exists, isDefined, isHash,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import type {
|
|
5
|
-
ArchivistInstance,
|
|
6
|
-
HashMeta,
|
|
7
|
-
PayloadBundle, Sequence,
|
|
8
|
-
} from '@xyo-network/sdk-js'
|
|
9
|
-
import { isHashMeta, isPayloadBundle } from '@xyo-network/sdk-js'
|
|
10
|
-
import {
|
|
11
|
-
type HydratedTransactionWithHashMeta, type MempoolViewer, MempoolViewerMoniker,
|
|
12
|
-
PendingTransactionsOptions,
|
|
13
|
-
type SignedHydratedBlockWithHashMeta, type SignedHydratedTransactionWithHashMeta,
|
|
14
|
-
WindowedBlockViewer,
|
|
15
|
-
WindowedBlockViewerMoniker,
|
|
16
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
AbstractCreatableProvider, creatableProvider, CreatableProviderParams,
|
|
20
|
-
} from '../../CreatableProvider/index.ts'
|
|
21
|
-
import { bundledPayloadToHydratedBlock, bundledPayloadToHydratedTransaction } from '../../model/index.ts'
|
|
22
|
-
|
|
23
|
-
type PayloadBundleWithHashMeta = PayloadBundle & HashMeta
|
|
24
|
-
|
|
25
|
-
type HydratedTxWithBundle = {
|
|
26
|
-
bundle: PayloadBundleWithHashMeta
|
|
27
|
-
tx: SignedHydratedTransactionWithHashMeta
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Default maximum fraction of mempool transactions to return. */
|
|
31
|
-
const DEFAULT_MEMPOOL_SELECTION_RATIO = 0.66
|
|
32
|
-
|
|
33
|
-
/** Parameters for SimpleMempoolViewer. */
|
|
34
|
-
export interface SimpleMempoolViewerParams extends CreatableProviderParams {
|
|
35
|
-
/** External mempool viewers (reserved for future use). */
|
|
36
|
-
externalMempools?: MempoolViewer[]
|
|
37
|
-
/** Maximum fraction (0–1) of mempool inclusion candidates to return. Defaults to 0.66. */
|
|
38
|
-
mempoolSelectionRatio?: number
|
|
39
|
-
pendingBlocksArchivist: ArchivistInstance
|
|
40
|
-
pendingTransactionsArchivist: ArchivistInstance
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** SimpleMempoolViewer implementation. */
|
|
44
|
-
@creatableProvider()
|
|
45
|
-
export class SimpleMempoolViewer extends AbstractCreatableProvider<SimpleMempoolViewerParams> implements MempoolViewer {
|
|
46
|
-
static readonly defaultMoniker = MempoolViewerMoniker
|
|
47
|
-
static readonly dependencies = [WindowedBlockViewerMoniker]
|
|
48
|
-
static readonly monikers = [MempoolViewerMoniker]
|
|
49
|
-
moniker = SimpleMempoolViewer.defaultMoniker
|
|
50
|
-
|
|
51
|
-
private _windowedBlockViewer?: WindowedBlockViewer
|
|
52
|
-
|
|
53
|
-
protected get pendingBlocksArchivist() {
|
|
54
|
-
return this.params.pendingBlocksArchivist
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
protected get pendingTransactionsArchivist() {
|
|
58
|
-
return this.params.pendingTransactionsArchivist
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
protected get windowedBlockViewer() {
|
|
62
|
-
return this._windowedBlockViewer!
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
override async createHandler() {
|
|
66
|
-
await super.createHandler()
|
|
67
|
-
this._windowedBlockViewer = await this.locator.getInstance<WindowedBlockViewer>(WindowedBlockViewerMoniker)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async pendingBlocks({ cursor: providedCursor }: PendingTransactionsOptions = {}): Promise<SignedHydratedBlockWithHashMeta[]> {
|
|
71
|
-
let cursor: Sequence | undefined = undefined
|
|
72
|
-
if (isHash(providedCursor)) {
|
|
73
|
-
const [p] = await this.pendingBlocksArchivist.get([providedCursor])
|
|
74
|
-
if (isDefined(p)) {
|
|
75
|
-
cursor = p._sequence
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const bundles = await this.pendingBlocksArchivist.next({
|
|
79
|
-
order: 'desc', limit: 100, cursor,
|
|
80
|
-
})
|
|
81
|
-
const filteredBundles = bundles.filter(isPayloadBundle).filter(isHashMeta)
|
|
82
|
-
return (await Promise.all(filteredBundles.map(async bundle => await bundledPayloadToHydratedBlock(bundle)))).filter(exists)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async pendingTransactions({
|
|
86
|
-
cursor: providedCursor,
|
|
87
|
-
limit = 100,
|
|
88
|
-
}: PendingTransactionsOptions = {}): Promise<SignedHydratedTransactionWithHashMeta[]> {
|
|
89
|
-
let cursor: Sequence | undefined = undefined
|
|
90
|
-
if (isHash(providedCursor)) {
|
|
91
|
-
const [p] = await this.pendingTransactionsArchivist.get([providedCursor])
|
|
92
|
-
if (isDefined(p)) {
|
|
93
|
-
cursor = p._sequence
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
this.logger?.info(`Fetching pending transactions from cursor: ${cursor}`)
|
|
97
|
-
const bundles = (await this.pendingTransactionsArchivist.next({
|
|
98
|
-
order: 'asc', limit: limit * 5, cursor,
|
|
99
|
-
}))
|
|
100
|
-
|
|
101
|
-
this.logger?.info(`Fetched pending transactions: ${bundles.length} bundles`)
|
|
102
|
-
|
|
103
|
-
const filteredBundles: PayloadBundleWithHashMeta[] = bundles.filter(isPayloadBundle).filter(isHashMeta)
|
|
104
|
-
// this.logger?.info(`Filtered pending transactions: ${JSON.stringify(filteredBundles, null, 2)} filteredBundles`)
|
|
105
|
-
|
|
106
|
-
const hydratedWithBundle: HydratedTxWithBundle[] = (await Promise.all(
|
|
107
|
-
filteredBundles.map(async (bundle) => {
|
|
108
|
-
const tx = await bundledPayloadToHydratedTransaction(bundle)
|
|
109
|
-
return isDefined(tx) ? { bundle, tx } : undefined
|
|
110
|
-
}),
|
|
111
|
-
)).filter(exists)
|
|
112
|
-
// this.logger?.info(`Converted pending transactions: ${JSON.stringify(hydratedWithBundle.map(x => x.tx), null, 2)} results`)
|
|
113
|
-
|
|
114
|
-
const currentBlock = await this.windowedBlockViewer.currentBlock()
|
|
115
|
-
const evaluated = await Promise.all(
|
|
116
|
-
hydratedWithBundle.map(async ({ bundle, tx }) => ({
|
|
117
|
-
bundle, tx, deletable: await this.isDeletable(tx, currentBlock),
|
|
118
|
-
})),
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
const validTransactions = evaluated.filter(x => !x.deletable)
|
|
122
|
-
const deletionCandidates = evaluated.filter(x => x.deletable)
|
|
123
|
-
this.logger?.info(`Pending transactions: ${validTransactions.length} valid, ${deletionCandidates.length} not deletable`)
|
|
124
|
-
|
|
125
|
-
// Delete the invalid transactions that should not remain in the mempool.
|
|
126
|
-
await Promise.all(
|
|
127
|
-
deletionCandidates.map(async ({ bundle, tx }) => {
|
|
128
|
-
await this.deleteBundledTransaction(bundle)
|
|
129
|
-
this.logger?.info(`Purged completed/expired bundled transaction: ${bundle._hash}/${tx[0]._hash}`)
|
|
130
|
-
}),
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
const inclusionCandidates = (await Promise.all(validTransactions.map(x => x.tx).map(async (tx) => {
|
|
134
|
-
// Check if it's a candidate for inclusion (skip deletable check as we've already done that)
|
|
135
|
-
if (await this.isInclusionCandidate(tx, currentBlock, false)) return tx
|
|
136
|
-
}))).filter(exists)
|
|
137
|
-
|
|
138
|
-
const selectionRatio = this.params.mempoolSelectionRatio ?? DEFAULT_MEMPOOL_SELECTION_RATIO
|
|
139
|
-
const maxByRatio = Math.ceil(inclusionCandidates.length * selectionRatio)
|
|
140
|
-
const effectiveLimit = Math.min(limit, maxByRatio)
|
|
141
|
-
|
|
142
|
-
const randomInclusionCandidates = deduplicateBySigner(
|
|
143
|
-
inclusionCandidates.filter(() => Math.random() < selectionRatio),
|
|
144
|
-
).slice(0, effectiveLimit)
|
|
145
|
-
|
|
146
|
-
// if the random filter resulted in 0 bundles, we fallback to just taking the first bundle to ensure we return something
|
|
147
|
-
const result = randomInclusionCandidates.length > 0 ? randomInclusionCandidates : deduplicateBySigner(inclusionCandidates).slice(0, 1)
|
|
148
|
-
|
|
149
|
-
this.logger?.info(`Inclusion candidates: ${inclusionCandidates.length}`)
|
|
150
|
-
return result
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
private async deleteBundledTransaction(bundle: PayloadBundleWithHashMeta): Promise<void> {
|
|
154
|
-
await this.pendingTransactionsArchivist.delete([bundle._hash])
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Evaluates a transaction to determine if it should be purged from the mempool.
|
|
159
|
-
* @param tx The transaction to evaluate
|
|
160
|
-
* @param currentBlock The current block to use for evaluation
|
|
161
|
-
* @returns True if the transaction should be purged, false otherwise
|
|
162
|
-
*/
|
|
163
|
-
private async isDeletable(tx: HydratedTransactionWithHashMeta, currentBlock: SignedHydratedBlockWithHashMeta): Promise<boolean> {
|
|
164
|
-
const currentBlockNumber = currentBlock[0].block
|
|
165
|
-
const nextBlockNumber = currentBlockNumber + 1
|
|
166
|
-
const { exp } = tx[0]
|
|
167
|
-
|
|
168
|
-
// If it's expired
|
|
169
|
-
if (nextBlockNumber > exp) return true
|
|
170
|
-
|
|
171
|
-
// If it's already included in a block
|
|
172
|
-
const existingBlock = await this.windowedBlockViewer.blockByTransactionHash(tx[0]._hash)
|
|
173
|
-
if (existingBlock) return true
|
|
174
|
-
|
|
175
|
-
return false
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Evaluates a transaction to determine if is valid for inclusion in the next block. A transaction is invalid if:
|
|
180
|
-
* - The transaction is too early/expired
|
|
181
|
-
* - The transaction has already been included in a block
|
|
182
|
-
* @param tx The transaction to evaluate
|
|
183
|
-
* @param currentBlock The current block to use for evaluation
|
|
184
|
-
* @param checkForDeletable Whether to check if the transaction is deletable (default: true)
|
|
185
|
-
* @returns True if the transaction is valid for inclusion in the next block, false otherwise
|
|
186
|
-
*/
|
|
187
|
-
private async isInclusionCandidate(
|
|
188
|
-
tx: HydratedTransactionWithHashMeta,
|
|
189
|
-
currentBlock: SignedHydratedBlockWithHashMeta,
|
|
190
|
-
checkForDeletable: boolean = true,
|
|
191
|
-
): Promise<boolean> {
|
|
192
|
-
const currentBlockNumber = currentBlock[0].block
|
|
193
|
-
const nextBlockNumber = currentBlockNumber + 1
|
|
194
|
-
const { nbf } = tx[0]
|
|
195
|
-
|
|
196
|
-
// If it's not time yet
|
|
197
|
-
if (nextBlockNumber < nbf) return false
|
|
198
|
-
|
|
199
|
-
// If it's deletable
|
|
200
|
-
if (checkForDeletable && await this.isDeletable(tx, currentBlock)) return false
|
|
201
|
-
|
|
202
|
-
return true
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/** Remove transactions that share the same signer set, keeping the first occurrence. */
|
|
207
|
-
function deduplicateBySigner(txs: SignedHydratedTransactionWithHashMeta[]): SignedHydratedTransactionWithHashMeta[] {
|
|
208
|
-
const seen = new Set<string>()
|
|
209
|
-
return txs.filter((tx) => {
|
|
210
|
-
const key = tx[0].addresses.toSorted().join(',')
|
|
211
|
-
if (seen.has(key)) return false
|
|
212
|
-
seen.add(key)
|
|
213
|
-
return true
|
|
214
|
-
})
|
|
215
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { isUndefined } from '@xylabs/sdk-js'
|
|
2
|
-
import type {
|
|
3
|
-
GatewayName,
|
|
4
|
-
NetworkStatus, XyoNetwork,
|
|
5
|
-
} from '@xyo-network/xl1-protocol-lib'
|
|
6
|
-
import { isNetworkStatus } from '@xyo-network/xl1-protocol-lib'
|
|
7
|
-
import axios from 'axios'
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
errorStatus, StatusNetworks, unknownStatus,
|
|
11
|
-
} from './lib/index.ts'
|
|
12
|
-
|
|
13
|
-
/** SimpleXyoNetwork implementation. */
|
|
14
|
-
export class SimpleXyoNetwork implements XyoNetwork {
|
|
15
|
-
protected readonly _networkId: GatewayName
|
|
16
|
-
|
|
17
|
-
constructor(networkId: GatewayName) {
|
|
18
|
-
this._networkId = networkId
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async status(): Promise<NetworkStatus> {
|
|
22
|
-
const statusNetwork = StatusNetworks[this._networkId]
|
|
23
|
-
if (isUndefined(statusNetwork)) {
|
|
24
|
-
throw new Error(`Unknown status network ID: ${this._networkId}`)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return await this.makeRequest(statusNetwork.statusUrl)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
private async makeRequest(url: string): Promise<NetworkStatus> {
|
|
31
|
-
try {
|
|
32
|
-
const response = await axios.get(url)
|
|
33
|
-
if (isNetworkStatus(response.data)) {
|
|
34
|
-
return response.data
|
|
35
|
-
} else {
|
|
36
|
-
if (response.status === 200) {
|
|
37
|
-
console.error('Unknown network status response:', response.data)
|
|
38
|
-
|
|
39
|
-
return unknownStatus
|
|
40
|
-
}
|
|
41
|
-
return errorStatus
|
|
42
|
-
}
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.error('Error fetching network status:', error)
|
|
45
|
-
return errorStatus
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './SimpleXyoNetwork.ts'
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { NetworkStatus } from '@xyo-network/xl1-protocol-lib'
|
|
2
|
-
import { NetworkStatusSchema } from '@xyo-network/xl1-protocol-lib'
|
|
3
|
-
|
|
4
|
-
/** unknownStatus constant. */
|
|
5
|
-
export const unknownStatus: NetworkStatus = {
|
|
6
|
-
description: 'Unknown Network Status',
|
|
7
|
-
schema: NetworkStatusSchema,
|
|
8
|
-
state: 'unknown',
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** errorStatus constant. */
|
|
12
|
-
export const errorStatus: NetworkStatus = {
|
|
13
|
-
description: 'Error Fetching Network Status',
|
|
14
|
-
schema: NetworkStatusSchema,
|
|
15
|
-
state: 'unknown',
|
|
16
|
-
}
|