Skip to content

Commit 7b990ba

Browse files
committed
Fix wrong CBOR deserialisation in pool distribution query
1 parent ef9796d commit 7b990ba

File tree

4 files changed

+14
-36
lines changed

4 files changed

+14
-36
lines changed

cardano-api/src/Cardano/Api/LedgerState.hs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ import Cardano.Api.Ledger.Internal.Reexport qualified as Ledger
119119
import Cardano.Api.LedgerState.Internal.ConvertLedgerEvent
120120
import Cardano.Api.LedgerState.Internal.LedgerEvent
121121
import Cardano.Api.Monad.Error
122+
import Cardano.Api.Network (Serialised (..))
122123
import Cardano.Api.Network.IPC.Internal
123124
( LocalChainSyncClient (LocalChainSyncClientPipelined)
124125
, LocalNodeClientProtocols (..)
@@ -133,7 +134,6 @@ import Cardano.Api.Query.Internal.Type.QueryInMode
133134
, PoolDistribution (unPoolDistr)
134135
, ProtocolState
135136
, SerialisedCurrentEpochState (..)
136-
, SerialisedPoolDistribution
137137
, decodeCurrentEpochState
138138
, decodePoolDistribution
139139
, decodeProtocolState
@@ -1967,6 +1967,7 @@ data LeadershipError
19671967
= LeaderErrDecodeLedgerStateFailure
19681968
| LeaderErrDecodeProtocolStateFailure (LBS.ByteString, DecoderError)
19691969
| LeaderErrDecodeProtocolEpochStateFailure DecoderError
1970+
| LeaderErrDecodePoolDistributionFailure DecoderError
19701971
| LeaderErrGenesisSlot
19711972
| LeaderErrStakePoolHasNoStake PoolId
19721973
| LeaderErrStakeDistribUnstable
@@ -1995,6 +1996,8 @@ instance Api.Error LeadershipError where
19951996
"Leadership schedule currently cannot be calculated from genesis"
19961997
LeaderErrStakePoolHasNoStake poolId ->
19971998
"The stake pool: " <> pshow poolId <> " has no stake"
1999+
LeaderErrDecodePoolDistributionFailure decoderError ->
2000+
"Failed to successfully decode the pool stake distribution: " <> pshow decoderError
19982001
LeaderErrDecodeProtocolEpochStateFailure decoderError ->
19992002
"Failed to successfully decode the current epoch state: " <> pshow decoderError
20002003
LeaderErrStakeDistribUnstable curSlot stableAfterSlot stabWindow predictedLastSlot ->
@@ -2192,7 +2195,7 @@ currentEpochEligibleLeadershipSlots
21922195
-> ProtocolState era
21932196
-> PoolId
21942197
-> SigningKey VrfKey
2195-
-> SerialisedPoolDistribution era
2198+
-> Serialised (PoolDistribution era)
21962199
-> EpochNo
21972200
-- ^ Current EpochInfo
21982201
-> Either LeadershipError (Set SlotNo)
@@ -2211,9 +2214,10 @@ currentEpochEligibleLeadershipSlots sbe sGen eInfo pp ptclState poolid (VrfSigni
22112214
first LeaderErrSlotRangeCalculationFailure $
22122215
Slot.epochInfoRange eInfo currentEpoch
22132216

2217+
-- FUCKED UP HERE:
22142218
setSnapshotPoolDistr <-
2215-
first LeaderErrDecodeProtocolEpochStateFailure
2216-
. fmap (SL.unPoolDistr . fromConsensusPoolDistr . unPoolDistr)
2219+
first LeaderErrDecodePoolDistributionFailure
2220+
. fmap (SL.unPoolDistr . unPoolDistr)
22172221
$ decodePoolDistribution sbe serPoolDistr
22182222

22192223
let slotRangeOfInterest :: Core.EraPParams ledgerera => Core.PParams ledgerera -> Set SlotNo
@@ -2552,22 +2556,3 @@ handleExceptions = liftEither <=< liftIO . runExceptT . flip catches handlers
25522556
[ Handler $ throwError . FoldBlocksIOException
25532557
, Handler $ throwError . FoldBlocksMuxError
25542558
]
2555-
2556-
-- WARNING: Do NOT use this function anywhere else except in its current call sites.
2557-
-- This is a temporary work around.
2558-
fromConsensusPoolDistr :: Consensus.PoolDistr c -> SL.PoolDistr
2559-
fromConsensusPoolDistr cpd =
2560-
SL.PoolDistr
2561-
{ SL.unPoolDistr = Map.map toLedgerIndividualPoolStake $ Shelley.unPoolDistr cpd
2562-
, SL.pdTotalActiveStake = SL.CompactCoin 0
2563-
}
2564-
2565-
-- WARNING: Do NOT use this function anywhere else except in its current call sites.
2566-
-- This is a temporary work around.
2567-
toLedgerIndividualPoolStake :: Consensus.IndividualPoolStake c -> SL.IndividualPoolStake
2568-
toLedgerIndividualPoolStake ips =
2569-
SL.IndividualPoolStake
2570-
{ SL.individualPoolStake = Shelley.individualPoolStake ips
2571-
, SL.individualPoolStakeVrf = SL.toVRFVerKeyHash $ Shelley.individualPoolStakeVrf ips
2572-
, SL.individualTotalPoolStake = SL.CompactCoin 0
2573-
}

cardano-api/src/Cardano/Api/Query.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ module Cardano.Api.Query
2222
, SerialisedPoolState (..)
2323
, PoolState (..)
2424
, decodePoolState
25-
, SerialisedPoolDistribution (..)
2625
, PoolDistribution (..)
2726
, decodePoolDistribution
2827
, SerialisedStakeSnapshots (..)

cardano-api/src/Cardano/Api/Query/Internal/Expr.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ queryPoolDistribution
190190
QueryInMode
191191
r
192192
IO
193-
(Either UnsupportedNtcVersionError (Either EraMismatch (SerialisedPoolDistribution era)))
193+
(Either UnsupportedNtcVersionError (Either EraMismatch (Serialised (PoolDistribution era))))
194194
queryPoolDistribution eon = querySbe eon . QueryPoolDistribution
195195

196196
queryPoolState

cardano-api/src/Cardano/Api/Query/Internal/Type/QueryInMode.hs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ module Cardano.Api.Query.Internal.Type.QueryInMode
4242
, SerialisedPoolState (..)
4343
, PoolState (..)
4444
, decodePoolState
45-
, SerialisedPoolDistribution (..)
4645
, PoolDistribution (..)
4746
, decodePoolDistribution
4847
, SerialisedStakeSnapshots (..)
@@ -115,7 +114,6 @@ import Ouroboros.Consensus.HardFork.History.Qry qualified as Qry
115114
import Ouroboros.Consensus.Ledger.Query qualified as Consensus
116115
import Ouroboros.Consensus.Protocol.Abstract qualified as Consensus
117116
import Ouroboros.Consensus.Shelley.Ledger qualified as Consensus
118-
import Ouroboros.Consensus.Shelley.Ledger.Query.Types qualified as Consensus
119117
import Ouroboros.Network.Block (Serialised (..))
120118
import Ouroboros.Network.PeerSelection.LedgerPeers.Type
121119
import Ouroboros.Network.Protocol.LocalStateQuery.Client (Some (..))
@@ -277,7 +275,7 @@ data QueryInShelleyBasedEra era result where
277275
-> QueryInShelleyBasedEra era SerialisedPoolState
278276
QueryPoolDistribution
279277
:: Maybe (Set PoolId)
280-
-> QueryInShelleyBasedEra era (SerialisedPoolDistribution era)
278+
-> QueryInShelleyBasedEra era (Serialised (PoolDistribution era))
281279
QueryStakeSnapshot
282280
:: Maybe (Set PoolId)
283281
-> QueryInShelleyBasedEra era (SerialisedStakeSnapshots era)
@@ -402,20 +400,16 @@ decodePoolState sbe (SerialisedPoolState (Serialised ls)) =
402400
shelleyBasedEraConstraints sbe $
403401
PoolState <$> decodeFull (Core.eraProtVerLow @(ShelleyLedgerEra era)) ls
404402

405-
newtype SerialisedPoolDistribution era
406-
= SerialisedPoolDistribution
407-
(Serialised Shelley.PoolDistr)
408-
409403
newtype PoolDistribution era = PoolDistribution
410-
{ unPoolDistr :: Consensus.PoolDistr StandardCrypto
404+
{ unPoolDistr :: Shelley.PoolDistr
411405
}
412406

413407
decodePoolDistribution
414408
:: forall era
415409
. ShelleyBasedEra era
416-
-> SerialisedPoolDistribution era
410+
-> Serialised (PoolDistribution era)
417411
-> Either DecoderError (PoolDistribution era)
418-
decodePoolDistribution sbe (SerialisedPoolDistribution (Serialised ls)) =
412+
decodePoolDistribution sbe (Serialised ls) =
419413
PoolDistribution <$> decodeFull (eraProtVerLow sbe) ls
420414

421415
newtype SerialisedStakeSnapshots era
@@ -958,7 +952,7 @@ fromConsensusQueryResultShelleyBased sbe sbeQuery q' r' =
958952
QueryPoolDistribution{} ->
959953
case q' of
960954
Consensus.GetCBOR Consensus.GetPoolDistr2{} ->
961-
SerialisedPoolDistribution r'
955+
Serialised . unSerialised $ r'
962956
_ -> fromConsensusQueryResultMismatch
963957
QueryStakeSnapshot{} ->
964958
case q' of

0 commit comments

Comments
 (0)