Skip to content

Commit

Permalink
feat!: update CompactGenesis slotLength type to be Seconds
Browse files Browse the repository at this point in the history
CompactGenesis.slotLength unit is `seconds`.
Use the appropriate opaque type to make it clear.

BREAKING CHANGE: CompactGenesis.slotLength type changed
from `number` to `Seconds`
  • Loading branch information
mirceahasegan committed Jan 20, 2023
1 parent fb1f1a2 commit 82e63d6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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)
});

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/Cardano/types/Genesis.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -13,7 +14,7 @@ export interface CompactGenesis {
epochLength: number;
slotsPerKesPeriod: number;
maxKesEvolutions: number;
slotLength: number;
slotLength: Seconds;
updateQuorum: number;
maxLovelaceSupply: Lovelace;
}
2 changes: 1 addition & 1 deletion packages/e2e/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/ogmios/src/ogmiosToCore/genesis.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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)
});
2 changes: 1 addition & 1 deletion packages/wallet/src/services/TransactionReemitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]) =>
Expand Down
6 changes: 3 additions & 3 deletions packages/wallet/test/mocks/mockData.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -46,15 +46,15 @@ export const epochRewards = [
];
export const rewardsHistory: Map<Cardano.RewardAccount, EpochRewards[]> = new Map([[rewardAccount, epochRewards]]);

export const genesisParameters = {
export const genesisParameters: Cardano.CompactGenesis = {
activeSlotsCoefficient: 0.05,
epochLength: 432_000,
maxKesEvolutions: 62,
maxLovelaceSupply: 45_000_000_000_000_000n,
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
Expand Down

0 comments on commit 82e63d6

Please sign in to comment.