Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Andreabedini/plutus streaming #472

Closed
wants to merge 29 commits into from

Conversation

raduom
Copy link
Contributor

@raduom raduom commented May 23, 2022

Merge plutus-streaming at the point where we can synchronise with the main chain.

Pre-submit checklist:

  • Branch
    • Tests are provided (if possible)
    • Commit sequence broadly makes sense
    • Key commits have useful messages
    • Relevant tickets are mentioned in commit messages
    • Formatting, materialized Nix files, PNG optimization, etc. are updated
  • PR
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested

@raduom raduom self-assigned this May 23, 2022
@raduom raduom requested a review from koslambrou May 23, 2022 03:23
@raduom raduom requested a review from andreabedini May 23, 2022 03:23
@raduom raduom force-pushed the andreabedini/plutus-streaming branch from dc26cd4 to 73e7339 Compare May 23, 2022 03:31
@raduom raduom marked this pull request as ready for review May 23, 2022 03:32
Copy link
Contributor

@andreabedini andreabedini left a 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";
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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 (
Copy link
Contributor

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.

@raduom raduom closed this May 23, 2022
@raduom
Copy link
Contributor Author

raduom commented May 23, 2022

On second thought, we don't need the TxIdState merged since it is only an experiment to validate my assumptions about the memory usage of Indexers.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants