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

SCP-3127: Chain index as a library #186

Merged
merged 6 commits into from
Dec 14, 2021
Merged

Conversation

sjoerdvisscher
Copy link
Contributor

@sjoerdvisscher sjoerdvisscher commented Dec 10, 2021

Refactoring so the chain index can be used more easily as a library, with the following goals.

  • Clear entry point Plutus.ChainIndex.Lib which collects and documents what's needed to run a chain index.
  • Separated out functions in a more modular way so:
    • a user can select the parts they do and don't want to use
    • there are clear extension points for custom code.
  • Allow for custom effects when executing the chain index effects.

The main focus in this PR is on ChainSyncHandlers, since customising what to sync and store is the biggest request (see filterTxs), and to make it easy to run the syncing once you have built such a handler.

This is just a first step, we expect to be building this out over the coming months.

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

@sjoerdvisscher sjoerdvisscher force-pushed the SCP-3127-chain-index-library branch from fae65c8 to 1ea4283 Compare December 10, 2021 14:09
@sjoerdvisscher sjoerdvisscher force-pushed the SCP-3127-chain-index-library branch from cf9d84a to 0df9c03 Compare December 10, 2021 16:05
@sjoerdvisscher sjoerdvisscher changed the title SCP-3127: Chain index library SCP-3127: Chain index as a library Dec 13, 2021
Copy link
Contributor

@raduom raduom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some refactorings, but I don't see why it can now be a library, whereas before it couldn't. I think it would be nice to have a list of the refactorings that you did and why you did them in the description.

-> Eff (ChainIndexQueryEffect ': ChainIndexControlEffect ': BeamEffect ': effs) a
-> Eff effs (Either ChainIndexError a)
handleChainIndexEffects RunRequirements{trace, stateTVar, conn, securityParam} action = do
state <- liftIO $ STM.readTVarIO stateTVar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this safe? You are reading the state in a transaction, then doing some computation, then saving the state in a transaction, what if some other thread reads the old state while you are doing the computation? Shouldn't there be an atomic block around all this section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. It was already like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the TVar to an MVar since this basically means we can't handle chain index effects concurrently.

@@ -102,6 +102,7 @@ runChainSync socketPath trace slotConfig networkId resumePoints chainSyncEventHa

pure handle
where
chainSyncEventHandler evt _ = onChainSyncEvent evt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are ignoring the second argument for all our handlers. Can we just remove it from ChainSyncCallback? This is I guess the computed slot number (computed given local time and slotting information) which we don't need to send to a client since it can compute it itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had that at first, but then ran into an issue with the mock implementation in the PAB that still used it.

@sjoerdvisscher sjoerdvisscher force-pushed the SCP-3127-chain-index-library branch from 8b764bc to 8e63d55 Compare December 14, 2021 08:27
@sjoerdvisscher sjoerdvisscher merged commit 835ce24 into main Dec 14, 2021
@sjoerdvisscher sjoerdvisscher deleted the SCP-3127-chain-index-library branch December 14, 2021 10:19
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.

3 participants