Skip to content

Commit

Permalink
Rename sqlite slot fields to slot_no forcing migration
Browse files Browse the repository at this point in the history
We previously encoded
    SlotId = (epoch, slotInEpoch)
in the `slot` tables as a single, flat integer (using an artificial
epoch length)

We are now storing the SlotNos.

It would be VERY BAD if a new wallet would read re-interpret the old
wallet data incorrectly.

Renaming the fields should trigger the automatic DB migration.
  • Loading branch information
Anviking committed Jul 16, 2020
1 parent 3fc013b commit 9eb843b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ share
[persistLowerCase|
AnyAddressState
anyAddressStateWalletId W.WalletId sql=wallet_id
anyAddressStateCheckpointSlot W.SlotNo sql=slot
anyAddressStateCheckpointSlot W.SlotNo sql=slot_no
anyAddressStateProportion Double sql=proportion
|]
14 changes: 7 additions & 7 deletions lib/core/src/Cardano/Pool/DB/Sqlite/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ArbitrarySeed sql=arbitrary_seed
-- The set of stake pools that produced a given block
PoolProduction sql=pool_production
poolProductionPoolId W.PoolId sql=pool_id
poolProductionSlot SlotNo sql=slot
poolProductionSlot SlotNo sql=slot_no
poolProductionHeaderHash W.BlockId sql=header_hash
poolProductionParentHash W.BlockId sql=parent_header_hash
poolProductionBlockHeight Word32 sql=block_height
Expand All @@ -78,8 +78,8 @@ StakeDistribution sql=stake_distribution
-- Mapping from pool id to owner.
PoolOwner sql=pool_owner
poolOwnerPoolId W.PoolId sql=pool_id
poolOwnerSlot W.SlotNo sql=slot
poolOwnerSlotInternalIndex Word64 sql=slot_internal_index
poolOwnerSlot W.SlotNo sql=slot_no
poolOwnerSlotInternalIndex Word64 sql=slot_no_internal_index
poolOwnerOwner W.PoolOwner sql=pool_owner
poolOwnerIndex Word8 sql=pool_owner_index

Expand All @@ -90,8 +90,8 @@ PoolOwner sql=pool_owner
-- Mapping of registration certificate to pool
PoolRegistration sql=pool_registration
poolRegistrationPoolId W.PoolId sql=pool_id
poolRegistrationSlot W.SlotNo sql=slot
poolRegistrationSlotInternalIndex Word64 sql=slot_internal_index
poolRegistrationSlot W.SlotNo sql=slot_no
poolRegistrationSlotInternalIndex Word64 sql=slot_no_internal_index
poolRegistrationMarginNumerator Word64 sql=margin_numerator
poolRegistrationMarginDenominator Word64 sql=margin_denominator
poolRegistrationCost Word64 sql=cost
Expand All @@ -105,8 +105,8 @@ PoolRegistration sql=pool_registration
-- Mapping of retirement certificates to pools
PoolRetirement sql=pool_retirement
poolRetirementPoolId W.PoolId sql=pool_id
poolRetirementSlot W.SlotNo sql=slot
poolRetirementSlotInternalIndex Word64 sql=slot_internal_index
poolRetirementSlot W.SlotNo sql=slot_no
poolRetirementSlotInternalIndex Word64 sql=slot_no_internal_index
poolRetirementEpoch Word64 sql=epoch

Primary poolRetirementPoolId poolRetirementSlot poolRetirementSlotInternalIndex
Expand Down
14 changes: 7 additions & 7 deletions lib/core/src/Cardano/Wallet/DB/Sqlite/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ TxMeta
txMetaWalletId W.WalletId sql=wallet_id
txMetaStatus W.TxStatus sql=status
txMetaDirection W.Direction sql=direction
txMetaSlot SlotNo sql=slot
txMetaSlot SlotNo sql=slot_no
txMetaBlockHeight Word32 sql=block_height
txMetaAmount Natural sql=amount

Expand Down Expand Up @@ -143,7 +143,7 @@ TxWithdrawal
-- Volatile checkpoint data such as AD state will refer to this table.
Checkpoint
checkpointWalletId W.WalletId sql=wallet_id
checkpointSlot SlotNo sql=slot
checkpointSlot SlotNo sql=slot_no
checkpointHeaderHash BlockId sql=header_hash
checkpointParentHash BlockId sql=parent_header_hash
checkpointBlockHeight Word32 sql=block_height
Expand Down Expand Up @@ -174,7 +174,7 @@ ProtocolParameters
-- Track whether the wallet's stake key is registered or not.
StakeKeyCertificate
stakeKeyCertWalletId W.WalletId sql=wallet_id
stakeKeyCertSlot SlotNo sql=slot
stakeKeyCertSlot SlotNo sql=slot_no
stakeKeyCertType W.StakeKeyCertificate sql=type

Primary stakeKeyCertWalletId stakeKeyCertSlot
Expand All @@ -184,7 +184,7 @@ StakeKeyCertificate
-- Store known delegation certificates for a particular wallet
DelegationCertificate
certWalletId W.WalletId sql=wallet_id
certSlot SlotNo sql=slot
certSlot SlotNo sql=slot_no
certPoolId W.PoolId Maybe sql=delegation

Primary certWalletId certSlot
Expand All @@ -208,7 +208,7 @@ UTxO sql=utxo

-- The wallet checkpoint (wallet_id, slot)
utxoWalletId W.WalletId sql=wallet_id
utxoSlot SlotNo sql=slot
utxoSlot SlotNo sql=slot_no

-- TxIn
utxoInputId TxId sql=input_tx_id
Expand Down Expand Up @@ -239,7 +239,7 @@ SeqState
-- when they were discovered.
SeqStateAddress
seqStateAddressWalletId W.WalletId sql=wallet_id
seqStateAddressSlot SlotNo sql=slot
seqStateAddressSlot SlotNo sql=slot_no
seqStateAddressAddress W.Address sql=address
seqStateAddressIndex Word32 sql=address_ix
seqStateAddressAccountingStyle W.AccountingStyle sql=accounting_style
Expand Down Expand Up @@ -277,7 +277,7 @@ RndState
-- The set of discovered addresses.
RndStateAddress
rndStateAddressWalletId W.WalletId sql=wallet_id
rndStateAddressSlot SlotNo sql=slot
rndStateAddressSlot SlotNo sql=slot_no
rndStateAddressAccountIndex Word32 sql=account_ix
rndStateAddressIndex Word32 sql=address_ix
rndStateAddressAddress W.Address sql=address
Expand Down

0 comments on commit 9eb843b

Please sign in to comment.