-
Notifications
You must be signed in to change notification settings - Fork 213
Conversation
It can be implemented separately, as done in Plutus.Streaming.LedgerState.
The Stream of blocks never ends, move out-of-band communication to be exception based.
* You need to dup a broadcast channel in order to read. * Update dependencies.
dc26cd4
to
73e7339
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some changes I had made in my branch which you don't have here. Nothing too fundamental luckily.
I had written some functions for you, which are missing in your branch.
transactions ::
Cardano.Api.BlockInMode Cardano.Api.CardanoMode ->
[Ledger.CardanoTx]
transactions (Cardano.Api.BlockInMode (Cardano.Api.Block _ txs) eim) =
map (\tx -> Ledger.CardanoApiTx (workaround (Ledger.SomeTx tx) eim)) txs
-- Not needed after https://github.com/input-output-hk/cardano-node/pull/3665
workaround ::
(Cardano.Api.IsCardanoEra era => Cardano.Api.EraInMode era Cardano.Api.CardanoMode -> a) ->
Cardano.Api.EraInMode era Cardano.Api.CardanoMode ->
a
workaround k Cardano.Api.ByronEraInCardanoMode = k Cardano.Api.ByronEraInCardanoMode
workaround k Cardano.Api.ShelleyEraInCardanoMode = k Cardano.Api.ShelleyEraInCardanoMode
workaround k Cardano.Api.AllegraEraInCardanoMode = k Cardano.Api.AllegraEraInCardanoMode
workaround k Cardano.Api.MaryEraInCardanoMode = k Cardano.Api.MaryEraInCardanoMode
workaround k Cardano.Api.AlonzoEraInCardanoMode = k Cardano.Api.AlonzoEraInCardanoMode
txInsAndOuts ::
Ledger.CardanoTx ->
(Set Ledger.TxIn, [(Ledger.TxOut, Ledger.TxOutRef)])
txInsAndOuts tx =
(Ledger.getCardanoTxInputs tx, Ledger.getCardanoTxOutRefs tx)
txInsAndOuts' ::
Ledger.CardanoTx ->
(Ledger.TxId, [Ledger.TxOutRef], [Ledger.TxOutRef])
txInsAndOuts' tx = (txId, inRefs, outRefs)
where
txId = Ledger.getCardanoTxId tx
inRefs = map Ledger.txInRef $ Set.toList $ Ledger.getCardanoTxInputs tx
outRefs = map snd $ Ledger.getCardanoTxOutRefs tx
datums ::
Ledger.CardanoTx ->
[(Ledger.DatumHash, Ledger.Datum)]
datums tx = do
let txIns = Set.toList $ Ledger.getCardanoTxInputs tx
(Ledger.TxIn _ (Just (Ledger.ConsumeScriptAddress _validator _redeemer datum))) <- txIns
pure (Ledger.datumHash datum, datum)
There is some tidying up to do and more importantly to figure out where some code belongs.
@@ -16,4 +16,5 @@ | |||
"https://github.com/input-output-hk/servant-purescript"."44e7cacf109f84984cd99cd3faf185d161826963" = "10pb0yfp80jhb9ryn65a4rha2lxzsn2vlhcc6xphrrkf4x5lhzqc"; | |||
"https://github.com/input-output-hk/Win32-network"."3825d3abf75f83f406c1f7161883c438dac7277d" = "19wahfv726fa3mqajpqdqhnl9ica3xmf68i254q45iyjcpj1psqx"; | |||
"https://github.com/Quid2/flat"."ee59880f47ab835dbd73bea0847dab7869fc20d8" = "1lrzknw765pz2j97nvv9ip3l1mcpf2zr4n56hwlz0rk7wq7ls4cm"; | |||
"https://github.com/raduom/hysterical-screams"."e30c0f8e6e86e6f57249aa4437ac8cadc0d49420" = "1ayqxfk7d99mcir7syji2404vzz4s6yg56rmw9aj56djvd6804v2"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code should be included in the main repo.
improveBlockInMode (BlockInMode bl eim@ShelleyEraInCardanoMode) = ImprovedBlockInMode bl eim | ||
improveBlockInMode (BlockInMode bl eim@AllegraEraInCardanoMode) = ImprovedBlockInMode bl eim | ||
improveBlockInMode (BlockInMode bl eim@MaryEraInCardanoMode) = ImprovedBlockInMode bl eim | ||
improveBlockInMode (BlockInMode bl eim@AlonzoEraInCardanoMode) = ImprovedBlockInMode bl eim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be needed anymore (after IntersectMBO/cardano-node#3665)
fromCardanoBlockInMode (improveBlockInMode -> ImprovedBlockInMode (C.Block _ txs) eim) = map (flip SomeTx eim) txs | ||
|
||
_txs :: Fold (C.BlockInMode C.CardanoMode) SomeCardanoApiTx | ||
_txs = folding fromCardanoBlockInMode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not used anywhere.
|
||
-- FIXME orphan instance | ||
-- https://github.com/input-output-hk/cardano-node/pull/3608 | ||
instance IsString (Hash BlockHeader) where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This instance is in Cardano.Api
now IntersectMBO/cardano-node#3619
{-# LANGUAGE NamedFieldPuns #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Index.TxIdStatus where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You put this as part of plutus-streaming, should it be in a separate package? called marconi? @koslambrou what should we do here?
-- blocks have settled | ||
getTxs :: BlockInMode CardanoMode -> (BlockNo, [TxId]) | ||
getTxs (BlockInMode (Block header transactions) era) = | ||
case era of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you are reimplementing fromCardanoBlockInMode
above
@@ -0,0 +1,29 @@ | |||
# Plutus Streaming PoC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to cherrypick c9a67bb to fix the readme.
-- execute handle "UPDATE tx_state SET confirmations = confirmations + ?" (Only $ Map.size bufferedTxs) | ||
-- execute_ handle "COMMIT" | ||
|
||
getBlocks :: SimpleChainSyncEvent -> BlockInMode CardanoMode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not used anywhere
go :: (Int, Map TxId TxConfirmedState) | ||
-> (BlockNo, [TxId]) | ||
-> (Int, Map TxId TxConfirmedState) | ||
go (confirmations, acc) (_, []) = (confirmations, acc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to be careful about strictness here? Perhaps better to have a strict datatype
data GoArgs = GoArgs !Int !(Map TxId TxConfirmedState)`
so that go becomes go :: GoArgs -> (BlockNo, [TxId]) -> GoArgs
and pattern match with go !args ...
?
This might not be a problem but I'd like to be sure we won't have a space leak here.
@@ -0,0 +1,52 @@ | |||
module Plutus.Streaming.ChainIndex ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module and the following (Plutus.Streaming.LedgerState) where basically proof-of-concept indexers. I don't think they belong to the streaming package.
On second thought, we don't need the |
Merge plutus-streaming at the point where we can synchronise with the main chain.
Pre-submit checklist: