Skip to content

Commit 155bd42

Browse files
committed
consensus: remove capacity override from the forging functions
It's undesirable for a node to make blocks that aren't full.
1 parent 468ec24 commit 155bd42

File tree

26 files changed

+84
-265
lines changed

26 files changed

+84
-265
lines changed

ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ test-suite shelley-test
350350
constraints,
351351
containers,
352352
filepath,
353+
measures,
353354
microlens,
354355
ouroboros-consensus:{ouroboros-consensus, unstable-consensus-testlib},
355356
ouroboros-consensus-cardano,

ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Ledger/Forge.hs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,11 @@ import Ouroboros.Consensus.Config
4040
import Ouroboros.Consensus.Ledger.Abstract
4141
import Ouroboros.Consensus.Ledger.SupportsMempool
4242
(LedgerSupportsMempool (..), txForgetValidated)
43-
import qualified Ouroboros.Consensus.Mempool as Mempool
4443
import Ouroboros.Consensus.Protocol.PBFT
4544

4645
forgeByronBlock ::
4746
HasCallStack
4847
=> TopLevelConfig ByronBlock
49-
-> Mempool.TxOverrides ByronBlock -- ^ How to override max tx capacity
50-
-- defined by ledger
5148
-> BlockNo -- ^ Current block number
5249
-> SlotNo -- ^ Current slot number
5350
-> TickedLedgerState ByronBlock -- ^ Current ledger
@@ -123,15 +120,13 @@ initBlockPayloads = BlockPayloads
123120
forgeRegularBlock ::
124121
HasCallStack
125122
=> BlockConfig ByronBlock
126-
-> Mempool.TxOverrides ByronBlock -- ^ How to override max tx capacity
127-
-- defined by ledger
128123
-> BlockNo -- ^ Current block number
129124
-> SlotNo -- ^ Current slot number
130125
-> TickedLedgerState ByronBlock -- ^ Current ledger
131126
-> [Validated (GenTx ByronBlock)] -- ^ Txs to consider adding in the block
132127
-> PBftIsLeader PBftByronCrypto -- ^ Leader proof ('IsLeader')
133128
-> ByronBlock
134-
forgeRegularBlock cfg maxTxCapacityOverrides bno sno st txs isLeader =
129+
forgeRegularBlock cfg bno sno st txs isLeader =
135130
forge $
136131
forgePBftFields
137132
(mkByronContextDSIGN cfg)
@@ -146,7 +141,7 @@ forgeRegularBlock cfg maxTxCapacityOverrides bno sno st txs isLeader =
146141
foldr
147142
extendBlockPayloads
148143
initBlockPayloads
149-
(takeLargestPrefixThatFits maxTxCapacityOverrides st txs)
144+
(takeLargestPrefixThatFits st txs)
150145

151146
txPayload :: CC.UTxO.TxPayload
152147
txPayload = CC.UTxO.mkTxPayload (bpTxs blockPayloads)

ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Node.hs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import Ouroboros.Consensus.Config.SupportsNode
4949
import Ouroboros.Consensus.HeaderValidation
5050
import Ouroboros.Consensus.Ledger.Abstract
5151
import Ouroboros.Consensus.Ledger.Extended
52-
import qualified Ouroboros.Consensus.Mempool as Mempool
5352
import Ouroboros.Consensus.Node.InitStorage
5453
import Ouroboros.Consensus.Node.ProtocolInfo
5554
import Ouroboros.Consensus.Node.Run
@@ -128,10 +127,9 @@ type instance ForgeStateUpdateError ByronBlock = Void
128127

129128
byronBlockForging ::
130129
Monad m
131-
=> Mempool.TxOverrides ByronBlock
132-
-> ByronLeaderCredentials
130+
=> ByronLeaderCredentials
133131
-> BlockForging m ByronBlock
134-
byronBlockForging maxTxCapacityOverrides creds = BlockForging {
132+
byronBlockForging creds = BlockForging {
135133
forgeLabel = blcLabel creds
136134
, canBeLeader
137135
, updateForgeState = \_ _ _ -> return $ ForgeStateUpdated ()
@@ -141,7 +139,7 @@ byronBlockForging maxTxCapacityOverrides creds = BlockForging {
141139
canBeLeader
142140
slot
143141
tickedPBftState
144-
, forgeBlock = \cfg -> return ....: forgeByronBlock cfg maxTxCapacityOverrides
142+
, forgeBlock = \cfg -> return ....: forgeByronBlock cfg
145143
}
146144
where
147145
canBeLeader = mkPBftCanBeLeader creds
@@ -156,10 +154,9 @@ mkPBftCanBeLeader (ByronLeaderCredentials sk cert nid _) = PBftCanBeLeader {
156154
blockForgingByron :: Monad m
157155
=> ProtocolParams ByronBlock
158156
-> [BlockForging m ByronBlock]
159-
blockForgingByron ProtocolParamsByron { byronLeaderCredentials = mLeaderCreds
160-
, byronMaxTxCapacityOverrides = maxTxCapacityOverrides
157+
blockForgingByron ProtocolParamsByron { byronLeaderCredentials = mLeaderCreds
161158
} =
162-
byronBlockForging maxTxCapacityOverrides
159+
byronBlockForging
163160
<$> maybeToList mLeaderCreds
164161

165162
{-------------------------------------------------------------------------------
@@ -178,7 +175,6 @@ data instance ProtocolParams ByronBlock = ProtocolParamsByron {
178175
, byronProtocolVersion :: Update.ProtocolVersion
179176
, byronSoftwareVersion :: Update.SoftwareVersion
180177
, byronLeaderCredentials :: Maybe ByronLeaderCredentials
181-
, byronMaxTxCapacityOverrides :: Mempool.TxOverrides ByronBlock
182178
}
183179

184180
protocolInfoByron :: ProtocolParams ByronBlock

ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/Node.hs

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ import Ouroboros.Consensus.HardFork.Combinator.Serialisation
100100
import qualified Ouroboros.Consensus.HardFork.History as History
101101
import Ouroboros.Consensus.HeaderValidation
102102
import Ouroboros.Consensus.Ledger.Extended
103-
import qualified Ouroboros.Consensus.Mempool as Mempool
104103
import Ouroboros.Consensus.Node.NetworkProtocolVersion
105104
import Ouroboros.Consensus.Node.ProtocolInfo
106105
import Ouroboros.Consensus.Node.Run
@@ -631,37 +630,30 @@ protocolInfoCardano paramsCardano
631630
genesisShelley = ledgerTransitionConfig ^. L.tcShelleyGenesisL
632631

633632
ProtocolParamsByron {
634-
byronGenesis = genesisByron
635-
, byronLeaderCredentials = mCredsByron
636-
, byronMaxTxCapacityOverrides = maxTxCapacityOverridesByron
633+
byronGenesis = genesisByron
634+
, byronLeaderCredentials = mCredsByron
637635
} = paramsByron
638636
ProtocolParamsShelleyBased {
639637
shelleyBasedInitialNonce = initialNonceShelley
640638
, shelleyBasedLeaderCredentials = credssShelleyBased
641639
} = paramsShelleyBased
642640
ProtocolParamsShelley {
643-
shelleyProtVer = protVerShelley
644-
, shelleyMaxTxCapacityOverrides = maxTxCapacityOverridesShelley
641+
shelleyProtVer = protVerShelley
645642
} = paramsShelley
646643
ProtocolParamsAllegra {
647-
allegraProtVer = protVerAllegra
648-
, allegraMaxTxCapacityOverrides = maxTxCapacityOverridesAllegra
644+
allegraProtVer = protVerAllegra
649645
} = paramsAllegra
650646
ProtocolParamsMary {
651-
maryProtVer = protVerMary
652-
, maryMaxTxCapacityOverrides = maxTxCapacityOverridesMary
647+
maryProtVer = protVerMary
653648
} = paramsMary
654649
ProtocolParamsAlonzo {
655-
alonzoProtVer = protVerAlonzo
656-
, alonzoMaxTxCapacityOverrides = maxTxCapacityOverridesAlonzo
650+
alonzoProtVer = protVerAlonzo
657651
} = paramsAlonzo
658652
ProtocolParamsBabbage {
659-
babbageProtVer = protVerBabbage
660-
, babbageMaxTxCapacityOverrides = maxTxCapacityOverridesBabbage
653+
babbageProtVer = protVerBabbage
661654
} = paramsBabbage
662655
ProtocolParamsConway {
663-
conwayProtVer = protVerConway
664-
, conwayMaxTxCapacityOverrides = maxTxCapacityOverridesConway
656+
conwayProtVer = protVerConway
665657
} = paramsConway
666658

667659
transitionConfigShelley = transitionConfigAllegra ^. L.tcPreviousEraConfigL
@@ -1033,7 +1025,7 @@ protocolInfoCardano paramsCardano
10331025
mBlockForgingByron :: Maybe (NonEmptyOptNP (BlockForging m) (CardanoEras c))
10341026
mBlockForgingByron = do
10351027
creds <- mCredsByron
1036-
return $ byronBlockForging maxTxCapacityOverridesByron creds `OptNP.at` IZ
1028+
return $ byronBlockForging creds `OptNP.at` IZ
10371029

10381030
blockForgingShelleyBased ::
10391031
ShelleyLeaderCredentials c
@@ -1058,28 +1050,26 @@ protocolInfoCardano paramsCardano
10581050
Absolute.KESPeriod $ fromIntegral $ slot `div` praosSlotsPerKESPeriod
10591051

10601052
let tpraos :: forall era.
1061-
ShelleyEraWithCrypto c (TPraos c) era
1062-
=> Mempool.TxOverrides (ShelleyBlock (TPraos c) era)
1063-
-> BlockForging m (ShelleyBlock (TPraos c) era)
1064-
tpraos maxTxCapacityOverrides =
1065-
TPraos.shelleySharedBlockForging hotKey slotToPeriod credentials maxTxCapacityOverrides
1053+
ShelleyEraWithCrypto c (TPraos c) era
1054+
=> BlockForging m (ShelleyBlock (TPraos c) era)
1055+
tpraos =
1056+
TPraos.shelleySharedBlockForging hotKey slotToPeriod credentials
10661057

10671058
let praos :: forall era.
1068-
ShelleyEraWithCrypto c (Praos c) era
1069-
=> Mempool.TxOverrides (ShelleyBlock (Praos c) era)
1070-
-> BlockForging m (ShelleyBlock (Praos c) era)
1071-
praos maxTxCapacityOverrides =
1072-
Praos.praosSharedBlockForging hotKey slotToPeriod credentials maxTxCapacityOverrides
1059+
ShelleyEraWithCrypto c (Praos c) era
1060+
=> BlockForging m (ShelleyBlock (Praos c) era)
1061+
praos =
1062+
Praos.praosSharedBlockForging hotKey slotToPeriod credentials
10731063

10741064
pure
10751065
$ OptSkip -- Byron
10761066
$ OptNP.fromNonEmptyNP $
1077-
tpraos maxTxCapacityOverridesShelley :*
1078-
tpraos maxTxCapacityOverridesAllegra :*
1079-
tpraos maxTxCapacityOverridesMary :*
1080-
tpraos maxTxCapacityOverridesAlonzo :*
1081-
praos maxTxCapacityOverridesBabbage :*
1082-
praos maxTxCapacityOverridesConway :*
1067+
tpraos :*
1068+
tpraos :*
1069+
tpraos :*
1070+
tpraos :*
1071+
praos :*
1072+
praos :*
10831073
Nil
10841074

10851075
protocolClientInfoCardano ::

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Forge.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import Ouroboros.Consensus.Config
2121
import Ouroboros.Consensus.Ledger.Abstract
2222
import Ouroboros.Consensus.Ledger.SupportsMempool
2323
import Ouroboros.Consensus.Mempool (TxLimits)
24-
import qualified Ouroboros.Consensus.Mempool as Mempool
2524
import Ouroboros.Consensus.Protocol.Abstract (CanBeLeader, IsLeader)
2625
import Ouroboros.Consensus.Protocol.Ledger.HotKey (HotKey)
2726
import Ouroboros.Consensus.Shelley.Eras (EraCrypto)
@@ -45,8 +44,6 @@ forgeShelleyBlock ::
4544
=> HotKey (EraCrypto era) m
4645
-> CanBeLeader proto
4746
-> TopLevelConfig (ShelleyBlock proto era)
48-
-> Mempool.TxOverrides (ShelleyBlock proto era) -- ^ How to override max tx
49-
-- capacity defined by ledger
5047
-> BlockNo -- ^ Current block number
5148
-> SlotNo -- ^ Current slot number
5249
-> TickedLedgerState (ShelleyBlock proto era) -- ^ Current ledger
@@ -57,7 +54,6 @@ forgeShelleyBlock
5754
hotKey
5855
cbl
5956
cfg
60-
maxTxCapacityOverrides
6157
curNo
6258
curSlot
6359
tickedLedger
@@ -76,7 +72,7 @@ forgeShelleyBlock
7672
SL.toTxSeq @era
7773
. Seq.fromList
7874
. fmap extractTx
79-
$ takeLargestPrefixThatFits maxTxCapacityOverrides tickedLedger txs
75+
$ takeLargestPrefixThatFits tickedLedger txs
8076

8177
extractTx :: Validated (GenTx (ShelleyBlock proto era)) -> Core.Tx era
8278
extractTx (ShelleyValidatedTx _txid vtx) = SL.extractTx vtx

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/Praos.hs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ praosBlockForging ::
5656
, IOLike m
5757
)
5858
=> PraosParams
59-
-> Mempool.TxOverrides (ShelleyBlock (Praos c) era)
6059
-> ShelleyLeaderCredentials (EraCrypto era)
6160
-> m (BlockForging m (ShelleyBlock (Praos c) era))
62-
praosBlockForging praosParams maxTxCapacityOverrides credentials = do
61+
praosBlockForging praosParams credentials = do
6362
hotKey <- HotKey.mkHotKey @m @c initSignKey startPeriod praosMaxKESEvo
64-
pure $ praosSharedBlockForging hotKey slotToPeriod credentials maxTxCapacityOverrides
63+
pure $ praosSharedBlockForging hotKey slotToPeriod credentials
6564
where
6665
PraosParams {praosMaxKESEvo, praosSlotsPerKESPeriod} = praosParams
6766

@@ -89,16 +88,14 @@ praosSharedBlockForging ::
8988
=> HotKey.HotKey c m
9089
-> (SlotNo -> Absolute.KESPeriod)
9190
-> ShelleyLeaderCredentials c
92-
-> Mempool.TxOverrides (ShelleyBlock (Praos c) era)
93-
-> BlockForging m (ShelleyBlock (Praos c) era)
91+
-> BlockForging m (ShelleyBlock (Praos c) era)
9492
praosSharedBlockForging
9593
hotKey
9694
slotToPeriod
9795
ShelleyLeaderCredentials {
9896
shelleyLeaderCredentialsCanBeLeader = canBeLeader
9997
, shelleyLeaderCredentialsLabel = label
100-
}
101-
maxTxCapacityOverrides = do
98+
} = do
10299
BlockForging
103100
{ forgeLabel = label <> "_" <> T.pack (L.eraName @era),
104101
canBeLeader = canBeLeader,
@@ -114,21 +111,18 @@ praosSharedBlockForging
114111
hotKey
115112
canBeLeader
116113
cfg
117-
maxTxCapacityOverrides
118114
}
119115

120116
{-------------------------------------------------------------------------------
121117
ProtocolInfo
122118
-------------------------------------------------------------------------------}
123119

124120
data instance ProtocolParams (ShelleyBlock (Praos c) (BabbageEra c)) = ProtocolParamsBabbage {
125-
babbageProtVer :: SL.ProtVer
121+
babbageProtVer :: SL.ProtVer
126122
-- ^ see 'Ouroboros.Consensus.Shelley.Node.TPraos.shelleyProtVer', mutatis mutandi
127-
, babbageMaxTxCapacityOverrides :: Mempool.TxOverrides (ShelleyBlock (Praos c) (BabbageEra c))
128123
}
129124

130125
data instance ProtocolParams (ShelleyBlock (Praos c) (ConwayEra c)) = ProtocolParamsConway {
131-
conwayProtVer :: SL.ProtVer
126+
conwayProtVer :: SL.ProtVer
132127
-- ^ see 'Ouroboros.Consensus.Shelley.Node.TPraos.shelleyProtVer', mutatis mutandi
133-
, conwayMaxTxCapacityOverrides :: Mempool.TxOverrides (ShelleyBlock (Praos c) (ConwayEra c))
134128
}

0 commit comments

Comments
 (0)