Skip to content

Commit

Permalink
Merge pull request #352 from input-output-hk/erikd/pool-fixed-cost
Browse files Browse the repository at this point in the history
db-sync: Accept potentially nonsensical pool_update values
  • Loading branch information
erikd committed Oct 18, 2020
2 parents 2170e9c + 5f4c924 commit 27bc2df
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert.hs
Expand Up @@ -15,7 +15,7 @@ module Cardano.DbSync.Era.Shelley.Insert

import Cardano.Prelude

import Cardano.BM.Trace (Trace, logDebug, logError, logInfo, logWarning)
import Cardano.BM.Trace (Trace, logDebug, logInfo, logWarning)

import Cardano.Db (DbWord64 (..))

Expand Down Expand Up @@ -251,12 +251,19 @@ insertPoolRegister tracer (EpochNo epoch) txId idx params = do
rewardId <- insertStakeAddress txId $ Shelley._poolRAcnt params

when (fromIntegral (Shelley.unCoin $ Shelley._poolPledge params) > maxLovelace) $
liftIO . logError tracer $
liftIO . logWarning tracer $
mconcat
[ "Bad pledge amount: ", textShow (Shelley.unCoin $ Shelley._poolPledge params)
, " > maxLovelace. See https://github.com/input-output-hk/cardano-ledger-specs/issues/1551"
]

when (fromIntegral (Shelley.unCoin $ Shelley._poolCost params) > maxLovelace) $
liftIO . logWarning tracer $
mconcat
[ "Bad fixed cost amount: ", textShow (Shelley.unCoin $ Shelley._poolCost params)
, " > maxLovelace. See https://github.com/input-output-hk/cardano-db-sync/issues/351"
]

poolHashId <- insertPoolHash (Shelley._poolPubKey params)
poolUpdateId <- lift . DB.insertPoolUpdate $
DB.PoolUpdate
Expand All @@ -268,7 +275,7 @@ insertPoolRegister tracer (EpochNo epoch) txId idx params = do
, DB.poolUpdateActiveEpochNo = epoch + 2
, DB.poolUpdateMeta = mdId
, DB.poolUpdateMargin = realToFrac $ Shelley.intervalValue (Shelley._poolMargin params)
, DB.poolUpdateFixedCost = fromIntegral $ Shelley.unCoin (Shelley._poolCost params)
, DB.poolUpdateFixedCost = DbWord64 $ fromIntegral (Shelley.unCoin $ Shelley._poolCost params)
, DB.poolUpdateRegisteredTxId = txId
}

Expand Down
2 changes: 1 addition & 1 deletion cardano-db/src/Cardano/Db/Schema.hs
Expand Up @@ -176,7 +176,7 @@ share
activeEpochNo Word64
meta PoolMetaDataId Maybe
margin Double -- sqltype=percentage????
fixedCost Word64 sqltype=lovelace
fixedCost DbWord64 sqltype=word64type
registeredTxId TxId -- Slot number in which the pool was registered.
UniquePoolUpdate hashId registeredTxId

Expand Down
Expand Up @@ -30,7 +30,7 @@ BEGIN
EXECUTE 'CREATe TABLE "pool_meta_data"("id" SERIAL8 PRIMARY KEY UNIQUE,"url" VARCHAR NOT NULL,"hash" hash32type NOT NULL,"registered_tx_id" INT8 NOT NULL)' ;
EXECUTE 'ALTER TABLE "pool_meta_data" ADD CONSTRAINT "unique_pool_meta_data" UNIQUE("url","hash")' ;
EXECUTE 'ALTER TABLE "pool_meta_data" ADD CONSTRAINT "pool_meta_data_registered_tx_id_fkey" FOREIGN KEY("registered_tx_id") REFERENCES "tx"("id")' ;
EXECUTE 'CREATe TABLE "pool_update"("id" SERIAL8 PRIMARY KEY UNIQUE,"hash_id" INT8 NOT NULL,"cert_index" INT4 NOT NULL,"vrf_key" hash32type NOT NULL,"pledge" word64type NOT NULL,"reward_addr_id" INT8 NOT NULL,"active_epoch_no" INT8 NOT NULL,"meta" INT8 NULL,"margin" DOUBLE PRECISION NOT NULL,"fixed_cost" lovelace NOT NULL,"registered_tx_id" INT8 NOT NULL)' ;
EXECUTE 'CREATe TABLE "pool_update"("id" SERIAL8 PRIMARY KEY UNIQUE,"hash_id" INT8 NOT NULL,"cert_index" INT4 NOT NULL,"vrf_key" hash32type NOT NULL,"pledge" word64type NOT NULL,"reward_addr_id" INT8 NOT NULL,"active_epoch_no" INT8 NOT NULL,"meta" INT8 NULL,"margin" DOUBLE PRECISION NOT NULL,"fixed_cost" word64type NOT NULL,"registered_tx_id" INT8 NOT NULL)' ;
EXECUTE 'ALTER TABLE "pool_update" ADD CONSTRAINT "unique_pool_update" UNIQUE("hash_id","registered_tx_id")' ;
EXECUTE 'ALTER TABLE "pool_update" ADD CONSTRAINT "pool_update_hash_id_fkey" FOREIGN KEY("hash_id") REFERENCES "pool_hash"("id")' ;
EXECUTE 'ALTER TABLE "pool_update" ADD CONSTRAINT "pool_update_reward_addr_id_fkey" FOREIGN KEY("reward_addr_id") REFERENCES "stake_address"("id")' ;
Expand Down

0 comments on commit 27bc2df

Please sign in to comment.