From 47ee54dd94fbbdd7cc15053947e4b4c105d82dd1 Mon Sep 17 00:00:00 2001 From: Kostas Dermentzis Date: Wed, 17 Apr 2024 14:22:12 +0300 Subject: [PATCH] Add new field min fee ref script --- .../Cardano/Db/Mock/Unit/Alonzo/Reward.hs | 2 +- .../Cardano/Db/Mock/Unit/Babbage/Reward.hs | 2 +- .../genesis.conway.json | 1 + .../genesis.conway.json | 1 + .../genesis.conway.json | 1 + .../genesis.conway.json | 1 + .../genesis.conway.json | 1 + .../config-conway/genesis.conway.json | 1 + .../test/testfiles/config/genesis.conway.json | 1 + .../Era/Shelley/Generic/ParamProposal.hs | 6 ++++++ .../DbSync/Era/Shelley/Generic/ProtoParams.hs | 6 ++++++ .../src/Cardano/DbSync/Era/Universal/Epoch.hs | 5 +++-- .../DbSync/Era/Universal/Insert/GovAction.hs | 1 + .../Era/Universal/Insert/LedgerEvent.hs | 4 ++-- cardano-db/src/Cardano/Db/Schema.hs | 7 +++++-- schema/migration-2-0039-20240417.sql | 20 +++++++++++++++++++ 16 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 schema/migration-2-0039-20240417.sql diff --git a/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Alonzo/Reward.hs b/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Alonzo/Reward.hs index 5d8a7269c..9f8067e04 100644 --- a/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Alonzo/Reward.hs +++ b/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Alonzo/Reward.hs @@ -52,7 +52,7 @@ import Test.Cardano.Db.Mock.UnifiedApi ( withAlonzoFindLeaderAndSubmit, withAlonzoFindLeaderAndSubmitTx, ) -import Test.Cardano.Db.Mock.Validate (assertBlockNoBackoff, assertRewardRestCount, assertRewardCount, assertRewardCounts) +import Test.Cardano.Db.Mock.Validate (assertBlockNoBackoff, assertRewardCount, assertRewardCounts, assertRewardRestCount) import Test.Tasty.HUnit (Assertion) simpleRewards :: IOManager -> [(Text, Text)] -> Assertion diff --git a/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage/Reward.hs b/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage/Reward.hs index 7daa1a243..792ba4c05 100644 --- a/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage/Reward.hs +++ b/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage/Reward.hs @@ -51,9 +51,9 @@ import Test.Cardano.Db.Mock.UnifiedApi ( import Test.Cardano.Db.Mock.Validate ( assertBlockNoBackoff, assertCurrentEpoch, - assertRewardRestCount, assertRewardCount, assertRewardCounts, + assertRewardRestCount, ) import Test.Tasty.HUnit (Assertion) diff --git a/cardano-chain-gen/test/testfiles/config-babbage-insert-options/genesis.conway.json b/cardano-chain-gen/test/testfiles/config-babbage-insert-options/genesis.conway.json index 3b889c372..25462de9c 100644 --- a/cardano-chain-gen/test/testfiles/config-babbage-insert-options/genesis.conway.json +++ b/cardano-chain-gen/test/testfiles/config-babbage-insert-options/genesis.conway.json @@ -24,6 +24,7 @@ "govActionDeposit": 1000000000, "dRepDeposit": 2000000, "dRepActivity": 20, + "minFeeRefScriptCostPerByte": 44, "constitution": { "anchor": { "url": "", diff --git a/cardano-chain-gen/test/testfiles/config-conway-hf-epoch1/genesis.conway.json b/cardano-chain-gen/test/testfiles/config-conway-hf-epoch1/genesis.conway.json index e690f455f..c9ea6ef11 100644 --- a/cardano-chain-gen/test/testfiles/config-conway-hf-epoch1/genesis.conway.json +++ b/cardano-chain-gen/test/testfiles/config-conway-hf-epoch1/genesis.conway.json @@ -24,6 +24,7 @@ "govActionDeposit": 1000000000, "dRepDeposit": 2000000, "dRepActivity": 20, + "minFeeRefScriptCostPerByte": 44, "constitution": { "anchor": { "url": "", diff --git a/cardano-chain-gen/test/testfiles/config-conway-insert-options/genesis.conway.json b/cardano-chain-gen/test/testfiles/config-conway-insert-options/genesis.conway.json index e690f455f..c9ea6ef11 100644 --- a/cardano-chain-gen/test/testfiles/config-conway-insert-options/genesis.conway.json +++ b/cardano-chain-gen/test/testfiles/config-conway-insert-options/genesis.conway.json @@ -24,6 +24,7 @@ "govActionDeposit": 1000000000, "dRepDeposit": 2000000, "dRepActivity": 20, + "minFeeRefScriptCostPerByte": 44, "constitution": { "anchor": { "url": "", diff --git a/cardano-chain-gen/test/testfiles/config-conway-no-pools/genesis.conway.json b/cardano-chain-gen/test/testfiles/config-conway-no-pools/genesis.conway.json index e690f455f..c9ea6ef11 100644 --- a/cardano-chain-gen/test/testfiles/config-conway-no-pools/genesis.conway.json +++ b/cardano-chain-gen/test/testfiles/config-conway-no-pools/genesis.conway.json @@ -24,6 +24,7 @@ "govActionDeposit": 1000000000, "dRepDeposit": 2000000, "dRepActivity": 20, + "minFeeRefScriptCostPerByte": 44, "constitution": { "anchor": { "url": "", diff --git a/cardano-chain-gen/test/testfiles/config-conway-no-stakes/genesis.conway.json b/cardano-chain-gen/test/testfiles/config-conway-no-stakes/genesis.conway.json index e690f455f..c9ea6ef11 100644 --- a/cardano-chain-gen/test/testfiles/config-conway-no-stakes/genesis.conway.json +++ b/cardano-chain-gen/test/testfiles/config-conway-no-stakes/genesis.conway.json @@ -24,6 +24,7 @@ "govActionDeposit": 1000000000, "dRepDeposit": 2000000, "dRepActivity": 20, + "minFeeRefScriptCostPerByte": 44, "constitution": { "anchor": { "url": "", diff --git a/cardano-chain-gen/test/testfiles/config-conway/genesis.conway.json b/cardano-chain-gen/test/testfiles/config-conway/genesis.conway.json index e690f455f..c9ea6ef11 100644 --- a/cardano-chain-gen/test/testfiles/config-conway/genesis.conway.json +++ b/cardano-chain-gen/test/testfiles/config-conway/genesis.conway.json @@ -24,6 +24,7 @@ "govActionDeposit": 1000000000, "dRepDeposit": 2000000, "dRepActivity": 20, + "minFeeRefScriptCostPerByte": 44, "constitution": { "anchor": { "url": "", diff --git a/cardano-chain-gen/test/testfiles/config/genesis.conway.json b/cardano-chain-gen/test/testfiles/config/genesis.conway.json index 3b889c372..25462de9c 100644 --- a/cardano-chain-gen/test/testfiles/config/genesis.conway.json +++ b/cardano-chain-gen/test/testfiles/config/genesis.conway.json @@ -24,6 +24,7 @@ "govActionDeposit": 1000000000, "dRepDeposit": 2000000, "dRepActivity": 20, + "minFeeRefScriptCostPerByte": 44, "constitution": { "anchor": { "url": "", diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ParamProposal.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ParamProposal.hs index 76501bc17..2a2960423 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ParamProposal.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ParamProposal.hs @@ -19,6 +19,7 @@ import Cardano.Ledger.BaseTypes (EpochInterval, UnitInterval, strictMaybeToMaybe import qualified Cardano.Ledger.BaseTypes as Ledger import Cardano.Ledger.Coin (Coin, unCoin) import Cardano.Ledger.Conway.Core +import Cardano.Ledger.Conway.PParams (ppuMinFeeRefScriptCostPerByteL) import Cardano.Ledger.Crypto import qualified Cardano.Ledger.Keys as Ledger import Cardano.Ledger.Plutus.Language (Language) @@ -70,6 +71,7 @@ data ParamProposal = ParamProposal , pppGovActionDeposit :: !(Maybe Natural) , pppDRepDeposit :: !(Maybe Natural) , pppDRepActivity :: !(Maybe EpochInterval) + , pppMinFeeRefScriptCostPerByte :: !(Maybe Rational) } convertParamProposal :: EraCrypto era ~ StandardCrypto => Witness era -> Shelley.Update era -> [ParamProposal] @@ -139,6 +141,7 @@ convertConwayParamProposal pmap = , pppGovActionDeposit = fromIntegral . unCoin <$> strictMaybeToMaybe (pmap ^. ppuGovActionDepositL) , pppDRepDeposit = fromIntegral . unCoin <$> strictMaybeToMaybe (pmap ^. ppuDRepDepositL) , pppDRepActivity = strictMaybeToMaybe (pmap ^. ppuDRepActivityL) + , pppMinFeeRefScriptCostPerByte = Ledger.unboundRational <$> strictMaybeToMaybe (pmap ^. ppuMinFeeRefScriptCostPerByteL) } convertBabbageParamProposal :: EpochNo -> (Ledger.KeyHash genesis StandardCrypto, PParamsUpdate StandardBabbage) -> ParamProposal @@ -182,6 +185,7 @@ convertBabbageParamProposal epochNo (key, pmap) = , pppGovActionDeposit = Nothing , pppDRepDeposit = Nothing , pppDRepActivity = Nothing + , pppMinFeeRefScriptCostPerByte = Nothing } convertAlonzoParamProposal :: EpochNo -> (Ledger.KeyHash genesis crypto, PParamsUpdate StandardAlonzo) -> ParamProposal @@ -226,6 +230,7 @@ convertAlonzoParamProposal epochNo (key, pmap) = , pppGovActionDeposit = Nothing , pppDRepDeposit = Nothing , pppDRepActivity = Nothing + , pppMinFeeRefScriptCostPerByte = Nothing } -- | This works fine from Shelley to Mary. Not for Alonzo since 'ppuMinUTxOValueL' was removed @@ -271,4 +276,5 @@ convertShelleyParamProposal epochNo (key, pmap) = , pppGovActionDeposit = Nothing , pppDRepDeposit = Nothing , pppDRepActivity = Nothing + , pppMinFeeRefScriptCostPerByte = Nothing } diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ProtoParams.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ProtoParams.hs index 4bcf8ff4f..1b85b3b49 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ProtoParams.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/ProtoParams.hs @@ -17,6 +17,7 @@ import Cardano.Ledger.BaseTypes (EpochInterval, UnitInterval) import qualified Cardano.Ledger.BaseTypes as Ledger import Cardano.Ledger.Coin (Coin (..)) import Cardano.Ledger.Conway.Core +import Cardano.Ledger.Conway.PParams (ppMinFeeRefScriptCostPerByteL) import Cardano.Ledger.Plutus.Language (Language) import qualified Cardano.Ledger.Shelley.LedgerState as Shelley import Cardano.Prelude @@ -66,6 +67,7 @@ data ProtoParams = ProtoParams , ppGovActionDeposit :: !(Maybe Natural) , ppDRepDeposit :: !(Maybe Natural) , ppDRepActivity :: !(Maybe EpochInterval) + , ppMinFeeRefScriptCostPerByte :: !(Maybe Rational) } data Deposits = Deposits @@ -149,6 +151,7 @@ fromConwayParams params = , ppGovActionDeposit = Just . fromIntegral . unCoin $ params ^. ppGovActionDepositL , ppDRepDeposit = Just . fromIntegral . unCoin $ params ^. ppDRepDepositL , ppDRepActivity = Just $ params ^. ppDRepActivityL + , ppMinFeeRefScriptCostPerByte = Just $ Ledger.unboundRational $ params ^. ppMinFeeRefScriptCostPerByteL } fromBabbageParams :: PParams StandardBabbage -> ProtoParams @@ -190,6 +193,7 @@ fromBabbageParams params = , ppGovActionDeposit = Nothing , ppDRepDeposit = Nothing , ppDRepActivity = Nothing + , ppMinFeeRefScriptCostPerByte = Nothing } fromAlonzoParams :: PParams StandardAlonzo -> ProtoParams @@ -231,6 +235,7 @@ fromAlonzoParams params = , ppGovActionDeposit = Nothing , ppDRepDeposit = Nothing , ppDRepActivity = Nothing + , ppMinFeeRefScriptCostPerByte = Nothing } fromShelleyParams :: (ProtVerAtMost era 6, ProtVerAtMost era 4, EraPParams era) => PParams era -> ProtoParams @@ -272,4 +277,5 @@ fromShelleyParams params = , ppGovActionDeposit = Nothing , ppDRepDeposit = Nothing , ppDRepActivity = Nothing + , ppMinFeeRefScriptCostPerByte = Nothing } diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Epoch.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Epoch.hs index 834821520..326a50d72 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Epoch.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Epoch.hs @@ -32,9 +32,11 @@ import Cardano.DbSync.Era.Universal.Insert.Certificate (insertPots) import Cardano.DbSync.Era.Universal.Insert.GovAction (insertCostModel, insertDrepDistr, updateEnacted, updateExpired, updateRatified) import Cardano.DbSync.Era.Universal.Insert.Other (toDouble) import Cardano.DbSync.Error +import Cardano.DbSync.Ledger.Event import Cardano.DbSync.Types import Cardano.DbSync.Util (whenStrictJust) import Cardano.DbSync.Util.Constraint (constraintNameEpochStake, constraintNameReward) +import Cardano.Ledger.Address (RewardAccount (..)) import Cardano.Ledger.BaseTypes (Network, unEpochInterval) import qualified Cardano.Ledger.BaseTypes as Ledger import Cardano.Ledger.Binary.Version (getVersion) @@ -50,8 +52,6 @@ import Control.Monad.Trans.Control (MonadBaseControl) import qualified Data.Map.Strict as Map import qualified Data.Set as Set import Database.Persist.Sql (SqlBackend) -import Cardano.DbSync.Ledger.Event -import Cardano.Ledger.Address (RewardAccount (..)) {- HLINT ignore "Use readTVarIO" -} @@ -149,6 +149,7 @@ insertEpochParam _tracer blkId (EpochNo epoch) params nonce = do , DB.epochParamGovActionDeposit = DB.DbWord64 . fromIntegral <$> Generic.ppGovActionDeposit params , DB.epochParamDrepDeposit = DB.DbWord64 . fromIntegral <$> Generic.ppDRepDeposit params , DB.epochParamDrepActivity = fromIntegral . unEpochInterval <$> Generic.ppDRepActivity params + , DB.epochParamMinFeeRefScriptCostPerByte = fromRational <$> Generic.ppMinFeeRefScriptCostPerByte params , DB.epochParamBlockId = blkId } diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/GovAction.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/GovAction.hs index b3a1be8de..0a31e625e 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/GovAction.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/GovAction.hs @@ -246,6 +246,7 @@ insertParamProposal blkId txId pp = do , DB.paramProposalGovActionDeposit = DbWord64 . fromIntegral <$> pppGovActionDeposit pp , DB.paramProposalDrepDeposit = DbWord64 . fromIntegral <$> pppDRepDeposit pp , DB.paramProposalDrepActivity = fromIntegral . unEpochInterval <$> pppDRepActivity pp + , DB.paramProposalMinFeeRefScriptCostPerByte = fromRational <$> pppMinFeeRefScriptCostPerByte pp } insertConstitution :: (MonadIO m, MonadBaseControl IO m) => DB.TxId -> DB.GovActionProposalId -> Constitution StandardConway -> ReaderT SqlBackend m () diff --git a/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/LedgerEvent.hs b/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/LedgerEvent.hs index 5abd0584e..c8c38f443 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/LedgerEvent.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/LedgerEvent.hs @@ -18,7 +18,8 @@ import Cardano.DbSync.Cache.Types (textShowStats) import Cardano.DbSync.Era.Cardano.Insert (insertEpochSyncTime) import qualified Cardano.DbSync.Era.Shelley.Generic as Generic import Cardano.DbSync.Era.Universal.Adjust (adjustEpochRewards) -import Cardano.DbSync.Era.Universal.Epoch (insertRewardRests, insertPoolDepositRefunds, insertRewards, insertProposalRefunds) +import Cardano.DbSync.Era.Universal.Epoch (insertPoolDepositRefunds, insertProposalRefunds, insertRewardRests, insertRewards) +import Cardano.DbSync.Era.Universal.Insert.GovAction (updateDropped) import Cardano.DbSync.Era.Universal.Validate (validateEpochRewards) import Cardano.DbSync.Error import Cardano.DbSync.Ledger.Event @@ -31,7 +32,6 @@ import qualified Data.Map.Strict as Map import qualified Data.Set as Set import Database.Persist.SqlBackend.Internal import Database.Persist.SqlBackend.Internal.StatementCache -import Cardano.DbSync.Era.Universal.Insert.GovAction (updateDropped) -------------------------------------------------------------------------------------------- -- Insert LedgerEvents diff --git a/cardano-db/src/Cardano/Db/Schema.hs b/cardano-db/src/Cardano/Db/Schema.hs index 8fe78c05a..bd7e3ad46 100644 --- a/cardano-db/src/Cardano/Db/Schema.hs +++ b/cardano-db/src/Cardano/Db/Schema.hs @@ -483,6 +483,7 @@ share govActionDeposit DbWord64 Maybe sqltype=word64type drepDeposit DbWord64 Maybe sqltype=word64type drepActivity Word64 Maybe sqltype=word64type + minFeeRefScriptCostPerByte Double Maybe -- sqltype=rational registeredTxId TxId noreference @@ -543,6 +544,7 @@ share govActionDeposit DbWord64 Maybe sqltype=word64type drepDeposit DbWord64 Maybe sqltype=word64type drepActivity Word64 Maybe sqltype=word64type + minFeeRefScriptCostPerByte Double Maybe -- sqltype=rational blockId BlockId noreference -- The first block where these parameters are valid. @@ -1290,8 +1292,9 @@ schemaDocs = GovActionProposalRatifiedEpoch # "If not null, then this proposal has been ratified at the specfied epoch." GovActionProposalEnactedEpoch # "If not null, then this proposal has been enacted at the specfied epoch." GovActionProposalExpiredEpoch # "If not null, then this proposal has been expired at the specfied epoch." - GovActionProposalDroppedEpoch # "If not null, then this proposal has been dropped at the specfied epoch. A proposal is dropped when it's \ - \expired or enacted or when one of its dependencies is expired." + GovActionProposalDroppedEpoch + # "If not null, then this proposal has been dropped at the specfied epoch. A proposal is dropped when it's \ + \expired or enacted or when one of its dependencies is expired." GovActionProposalExpiration # "Shows the epoch at which this governance action will expire." TreasuryWithdrawal --^ do diff --git a/schema/migration-2-0039-20240417.sql b/schema/migration-2-0039-20240417.sql new file mode 100644 index 000000000..9dfa7b019 --- /dev/null +++ b/schema/migration-2-0039-20240417.sql @@ -0,0 +1,20 @@ +-- Persistent generated migration. + +CREATE FUNCTION migrate() RETURNS void AS $$ +DECLARE + next_version int ; +BEGIN + SELECT stage_two + 1 INTO next_version FROM schema_version ; + IF next_version = 39 THEN + EXECUTE 'ALTER TABLE "param_proposal" ADD COLUMN "min_fee_ref_script_cost_per_byte" DOUBLE PRECISION NULL' ; + EXECUTE 'ALTER TABLE "epoch_param" ADD COLUMN "min_fee_ref_script_cost_per_byte" DOUBLE PRECISION NULL' ; + -- Hand written SQL statements can be added here. + UPDATE schema_version SET stage_two = next_version ; + RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ; + END IF ; +END ; +$$ LANGUAGE plpgsql ; + +SELECT migrate() ; + +DROP FUNCTION migrate() ;