Skip to content

Commit a1d1b46

Browse files
johnalotoskiclaude
andcommitted
fix: reorder transaction deserialization and fix mempool UTxO era
utxoFromMempool initialized with UTxOInBabbageEra, causing all evaluations to hit the Babbage rejection branch even for Conway transactions. Changed to UTxOInConwayEra. Reorder deserialiseCBOR to try Conway and Dijkstra before Babbage. Conway transactions can successfully deserialize as Babbage (the Babbage decoder accepts Conway-era CBOR), wrapping them as GenTxBabbage and rejecting them as "unsupported era". Older eras kept as fallbacks for specific diagnostics. Use eraProtVerHigh in transaction deserialization to accept transactions from any protocol version within an era (e.g. Conway PV9 through PV11). Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 87f21a2 commit a1d1b46

2 files changed

Lines changed: 28 additions & 22 deletions

File tree

server/src/Ogmios/Data/Json/Query.hs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,19 +2638,19 @@ decodeSerializedTransaction
26382638
decodeSerializedTransaction = Json.withText "Transaction" $ \(encodeUtf8 -> utf8) -> do
26392639
bytes <- decodeBase16 utf8 <|> invalidEncodingError
26402640
-- NOTE (1):
2641-
-- The order in which we parser matters! Older eras first. formats
2642-
-- are forward-compatible, and near hard-forks, there's a period where the
2643-
-- software can understand the next era but, that era isn't available yet.
2644-
--
2645-
-- Therefore, we need to favor parsing older eras so that existing code keep
2646-
-- working. Transactions are only decoded in the new era when they are using
2647-
-- features not available in older ones.
2641+
-- The order in which we parse matters! Conway transactions can successfully
2642+
-- deserialize as Babbage (the Babbage decoder accepts Conway-era CBOR).
2643+
-- Since Babbage evaluation was dropped (per era rotation policy), this would
2644+
-- wrap Conway transactions as GenTxBabbage and reject them as "unsupported
2645+
-- era". We try Conway and Dijkstra first so transactions are evaluated in
2646+
-- the current era. Older eras are kept as fallbacks to provide specific
2647+
-- "unsupported era" diagnostics rather than generic deserialization errors.
26482648
--
26492649
-- NOTE (2):
26502650
-- Avoiding 'asum' here because it generates poor errors on failures.
2651-
pure $ deserialiseCBOR @BabbageEra GenTxBabbage bytes
2651+
pure $ deserialiseCBOR @ConwayEra GenTxConway bytes
26522652
<|> deserialiseCBOR @DijkstraEra GenTxDijkstra bytes
2653-
<|> deserialiseCBOR @ConwayEra GenTxConway bytes
2653+
<|> deserialiseCBOR @BabbageEra GenTxBabbage bytes
26542654
<|> deserialiseCBOR @AlonzoEra GenTxAlonzo bytes
26552655
<|> deserialiseCBOR @MaryEra GenTxMary bytes
26562656
<|> deserialiseCBOR @AllegraEra GenTxAllegra bytes
@@ -2683,20 +2683,26 @@ decodeSerializedTransaction = Json.withText "Transaction" $ \(encodeUtf8 -> utf8
26832683
-> ByteString
26842684
-> MultiEraDecoder (GenTx (CardanoBlock crypto))
26852685
deserialiseCBOR mk bytes =
2686-
mk <$> decodeCborWith @era "Transaction"
2687-
(\e -> MultiEraDecoderErrors
2688-
[ ( SomeShelleyEra (shelleyBasedEra @era)
2689-
, e
2690-
, fromIntegral $ BS.length bytes
2691-
)
2692-
]
2693-
)
2694-
(Binary.fromPlainDecoder fromCBOR)
2695-
(if wrapper `BS.isPrefixOf` bytes
2696-
then fromStrict bytes
2697-
else wrap bytes
2686+
mk <$> either reject pure
2687+
(Binary.decodeFullDecoder version "Transaction"
2688+
(Binary.fromPlainDecoder fromCBOR)
2689+
(if wrapper `BS.isPrefixOf` bytes
2690+
then fromStrict bytes
2691+
else wrap bytes
2692+
)
26982693
)
26992694
where
2695+
-- Use eraProtVerHigh to accept transactions from any protocol
2696+
-- version within the era (e.g. Conway PV9, PV10, PV11).
2697+
version = Ledger.eraProtVerHigh @era
2698+
2699+
reject e = MultiEraDecoderErrors
2700+
[ ( SomeShelleyEra (shelleyBasedEra @era)
2701+
, e
2702+
, fromIntegral $ BS.length bytes
2703+
)
2704+
]
2705+
27002706
wrapper = BS.pack [216, 24] -- D818...
27012707

27022708
-- Cardano tools have a tendency to wrap cbor in cbor (e.g cardano-cli).

server/src/Ogmios/Data/Protocol/TxSubmission.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ utxoFromMempool
476476
=> [GenTx block]
477477
-> MultiEraUTxO block
478478
utxoFromMempool =
479-
go $ UTxOInBabbageEra mempty
479+
go $ UTxOInConwayEra mempty
480480
where
481481
go :: MultiEraUTxO block -> [GenTx block] -> MultiEraUTxO block
482482
go utxo = \case

0 commit comments

Comments
 (0)