Skip to content

Commit

Permalink
Add new field min fee ref script
Browse files Browse the repository at this point in the history
  • Loading branch information
kderme committed Apr 17, 2024
1 parent f8c4686 commit 47ee54d
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 8 deletions.
Expand Up @@ -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
Expand Down
Expand Up @@ -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)

Expand Down
Expand Up @@ -24,6 +24,7 @@
"govActionDeposit": 1000000000,
"dRepDeposit": 2000000,
"dRepActivity": 20,
"minFeeRefScriptCostPerByte": 44,
"constitution": {
"anchor": {
"url": "",
Expand Down
Expand Up @@ -24,6 +24,7 @@
"govActionDeposit": 1000000000,
"dRepDeposit": 2000000,
"dRepActivity": 20,
"minFeeRefScriptCostPerByte": 44,
"constitution": {
"anchor": {
"url": "",
Expand Down
Expand Up @@ -24,6 +24,7 @@
"govActionDeposit": 1000000000,
"dRepDeposit": 2000000,
"dRepActivity": 20,
"minFeeRefScriptCostPerByte": 44,
"constitution": {
"anchor": {
"url": "",
Expand Down
Expand Up @@ -24,6 +24,7 @@
"govActionDeposit": 1000000000,
"dRepDeposit": 2000000,
"dRepActivity": 20,
"minFeeRefScriptCostPerByte": 44,
"constitution": {
"anchor": {
"url": "",
Expand Down
Expand Up @@ -24,6 +24,7 @@
"govActionDeposit": 1000000000,
"dRepDeposit": 2000000,
"dRepActivity": 20,
"minFeeRefScriptCostPerByte": 44,
"constitution": {
"anchor": {
"url": "",
Expand Down
Expand Up @@ -24,6 +24,7 @@
"govActionDeposit": 1000000000,
"dRepDeposit": 2000000,
"dRepActivity": 20,
"minFeeRefScriptCostPerByte": 44,
"constitution": {
"anchor": {
"url": "",
Expand Down
Expand Up @@ -24,6 +24,7 @@
"govActionDeposit": 1000000000,
"dRepDeposit": 2000000,
"dRepActivity": 20,
"minFeeRefScriptCostPerByte": 44,
"constitution": {
"anchor": {
"url": "",
Expand Down
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -271,4 +276,5 @@ convertShelleyParamProposal epochNo (key, pmap) =
, pppGovActionDeposit = Nothing
, pppDRepDeposit = Nothing
, pppDRepActivity = Nothing
, pppMinFeeRefScriptCostPerByte = Nothing
}
Expand Up @@ -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
Expand Down Expand Up @@ -66,6 +67,7 @@ data ProtoParams = ProtoParams
, ppGovActionDeposit :: !(Maybe Natural)
, ppDRepDeposit :: !(Maybe Natural)
, ppDRepActivity :: !(Maybe EpochInterval)
, ppMinFeeRefScriptCostPerByte :: !(Maybe Rational)
}

data Deposits = Deposits
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -190,6 +193,7 @@ fromBabbageParams params =
, ppGovActionDeposit = Nothing
, ppDRepDeposit = Nothing
, ppDRepActivity = Nothing
, ppMinFeeRefScriptCostPerByte = Nothing
}

fromAlonzoParams :: PParams StandardAlonzo -> ProtoParams
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -272,4 +277,5 @@ fromShelleyParams params =
, ppGovActionDeposit = Nothing
, ppDRepDeposit = Nothing
, ppDRepActivity = Nothing
, ppMinFeeRefScriptCostPerByte = Nothing
}
5 changes: 3 additions & 2 deletions cardano-db-sync/src/Cardano/DbSync/Era/Universal/Epoch.hs
Expand Up @@ -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)
Expand All @@ -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" -}

Expand Down Expand Up @@ -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
}

Expand Down
Expand Up @@ -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 ()
Expand Down
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions cardano-db/src/Cardano/Db/Schema.hs
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions 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() ;

0 comments on commit 47ee54d

Please sign in to comment.