From 82e63d6cacedbab5ecf8491dfd37749bfeddbc22 Mon Sep 17 00:00:00 2001 From: Mircea Hasegan Date: Thu, 12 Jan 2023 20:02:09 +0100 Subject: [PATCH] feat!: update CompactGenesis slotLength type to be Seconds CompactGenesis.slotLength unit is `seconds`. Use the appropriate opaque type to make it clear. BREAKING CHANGE: CompactGenesis.slotLength type changed from `number` to `Seconds` --- .../src/NetworkInfo/DbSyncNetworkInfoProvider/mappers.ts | 3 ++- packages/core/src/Cardano/types/Genesis.ts | 3 ++- packages/e2e/test/util.ts | 2 +- packages/ogmios/src/ogmiosToCore/genesis.ts | 3 ++- packages/wallet/src/services/TransactionReemitter.ts | 2 +- packages/wallet/test/mocks/mockData.ts | 6 +++--- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/cardano-services/src/NetworkInfo/DbSyncNetworkInfoProvider/mappers.ts b/packages/cardano-services/src/NetworkInfo/DbSyncNetworkInfoProvider/mappers.ts index 64bf9d7127a..bb494a6000c 100644 --- a/packages/cardano-services/src/NetworkInfo/DbSyncNetworkInfoProvider/mappers.ts +++ b/packages/cardano-services/src/NetworkInfo/DbSyncNetworkInfoProvider/mappers.ts @@ -1,4 +1,4 @@ -import { Cardano, ProviderError, ProviderFailure, SupplySummary } from '@cardano-sdk/core'; +import { Cardano, ProviderError, ProviderFailure, Seconds, SupplySummary } from '@cardano-sdk/core'; import { CostModelsParamModel, GenesisData, ProtocolParamsModel } from './types'; import { LedgerTipModel } from '../../util/DbSyncProvider'; import JSONbig from 'json-bigint'; @@ -102,6 +102,7 @@ export const toProtocolParams = ({ export const toGenesisParams = (genesis: GenesisData): Cardano.CompactGenesis => ({ ...genesis, networkId: networkIdMap[genesis.networkId], + slotLength: Seconds(genesis.slotLength), systemStart: new Date(genesis.systemStart) }); diff --git a/packages/core/src/Cardano/types/Genesis.ts b/packages/core/src/Cardano/types/Genesis.ts index 4c5d2e7d4eb..bc5a282ee28 100644 --- a/packages/core/src/Cardano/types/Genesis.ts +++ b/packages/core/src/Cardano/types/Genesis.ts @@ -1,5 +1,6 @@ import { Lovelace } from './Value'; import { NetworkId, NetworkMagic } from '../ChainId'; +import { Seconds } from '../../util'; /** * A compact (without genesis UTxO) representation of the genesis configuration. @@ -13,7 +14,7 @@ export interface CompactGenesis { epochLength: number; slotsPerKesPeriod: number; maxKesEvolutions: number; - slotLength: number; + slotLength: Seconds; updateQuorum: number; maxLovelaceSupply: Lovelace; } diff --git a/packages/e2e/test/util.ts b/packages/e2e/test/util.ts index 17bf2583eac..96e7ccb03bf 100644 --- a/packages/e2e/test/util.ts +++ b/packages/e2e/test/util.ts @@ -189,7 +189,7 @@ export const runningAgainstLocalNetwork = async () => { const estimatedTestDurationInEpochs = 4; const localNetworkEpochDuration = 1000 * 0.2; - const estimatedTestDuration = epochLength * slotLength * estimatedTestDurationInEpochs; + const estimatedTestDuration = epochLength * slotLength.valueOf() * estimatedTestDurationInEpochs; if (estimatedTestDuration > localNetworkEpochDuration * estimatedTestDurationInEpochs) { return false; } diff --git a/packages/ogmios/src/ogmiosToCore/genesis.ts b/packages/ogmios/src/ogmiosToCore/genesis.ts index 006168ce93f..a0db2635193 100644 --- a/packages/ogmios/src/ogmiosToCore/genesis.ts +++ b/packages/ogmios/src/ogmiosToCore/genesis.ts @@ -1,4 +1,4 @@ -import { Cardano } from '@cardano-sdk/core'; +import { Cardano, Seconds } from '@cardano-sdk/core'; import { Schema } from '@cardano-ogmios/client'; import omit from 'lodash/omit'; @@ -10,5 +10,6 @@ export const genesis = (ogmiosGenesis: Schema.CompactGenesis): Cardano.CompactGe })(), maxLovelaceSupply: BigInt(ogmiosGenesis.maxLovelaceSupply), networkId: ogmiosGenesis.network === 'mainnet' ? Cardano.NetworkId.Mainnet : Cardano.NetworkId.Testnet, + slotLength: Seconds(ogmiosGenesis.slotLength), systemStart: new Date(ogmiosGenesis.systemStart) }); diff --git a/packages/wallet/src/services/TransactionReemitter.ts b/packages/wallet/src/services/TransactionReemitter.ts index f5ab09852da..262893613e8 100644 --- a/packages/wallet/src/services/TransactionReemitter.ts +++ b/packages/wallet/src/services/TransactionReemitter.ts @@ -146,7 +146,7 @@ export const createTransactionReemitter = ({ const reemitSubmittedBefore$ = tipSlot$.pipe( withLatestFrom(genesisParameters$), - map(([tip, { slotLength }]) => tip.valueOf() - maxInterval / (slotLength * 1000)) + map(([tip, { slotLength }]) => tip.valueOf() - maxInterval / (slotLength.valueOf() * 1000)) ); const reemitUnconfirmed$ = combineLatest([reemitSubmittedBefore$, inFlight$]).pipe( mergeMap(([reemitSubmittedBefore, inFlight]) => diff --git a/packages/wallet/test/mocks/mockData.ts b/packages/wallet/test/mocks/mockData.ts index f89d57fd76c..fcb87c99592 100644 --- a/packages/wallet/test/mocks/mockData.ts +++ b/packages/wallet/test/mocks/mockData.ts @@ -1,4 +1,4 @@ -import { Cardano, EpochRewards } from '@cardano-sdk/core'; +import { Cardano, EpochRewards, Seconds } from '@cardano-sdk/core'; import { KeyRole } from '@cardano-sdk/key-management'; export const rewardAccount = Cardano.RewardAccount('stake_test1up7pvfq8zn4quy45r2g572290p9vf99mr9tn7r9xrgy2l2qdsf58d'); @@ -46,7 +46,7 @@ export const epochRewards = [ ]; export const rewardsHistory: Map = new Map([[rewardAccount, epochRewards]]); -export const genesisParameters = { +export const genesisParameters: Cardano.CompactGenesis = { activeSlotsCoefficient: 0.05, epochLength: 432_000, maxKesEvolutions: 62, @@ -54,7 +54,7 @@ export const genesisParameters = { networkId: 0, networkMagic: 764_824_073, securityParameter: 2160, - slotLength: 1, + slotLength: Seconds(1), slotsPerKesPeriod: 129_600, systemStart: new Date(1_506_203_091_000), updateQuorum: 5