-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract communication independent parts from Direct chain #376
Conversation
Transactions CostsSizes and execution budgets for Hydra protocol transactions. Note that unlisted parameters are currently using
Cost of Init Transaction
Cost of Commit TransactionCurrently only one UTxO per commit allowed (this is about to change soon)
Cost of CollectCom Transaction
Cost of Close Transaction
Cost of Contest Transaction
Cost of Abort Transaction
Cost of FanOut TransactionInvolves spending head output and burning head tokens. Uses ada-only UTxO for better comparability.
|
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.
Not fully convinced on this "separation of concerns". Although you already gave a bit of context that you see it work out better in some testing scenario, can you point me to something enlightening having the cut done like this is particularly useful?
Maybe it's just the inner postTx
bits (fromPostChainTx + finalize) what you are seeking for?
I guess my hesitation is that the Handlers
' implementation of the Chain
handle does not actually "post" a tx?
hydra-node/src/Hydra/Chain/Direct.hs
Outdated
Nothing -> pure () | ||
Just err -> throwIO err | ||
} | ||
action $ mkChain tracer (queryTimeHandle networkId socketPath) cardanoKeys wallet headState queue |
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.
What a weird interface we have there with the queue
. I see it's unchanged in your refactor and it seems to be enqueuing the tx for submission and blocking on a response by the node. Hence, it should be the responsibility of this module.. not the Handlers
one?
I would propose to not use the Chain
interface in this Handlers
module, but have a function which returns the Tx
instead of the current Chain.postTx
interface and do the enqueuing / waiting for errors in this module up here. i.e. something like
action $ mkChain tracer (queryTimeHandle networkId socketPath) cardanoKeys wallet headState queue | |
action $ | |
Chain | |
{ postTx = \tx -> do | |
vtx <- Handlers.createTx tracer (queryTimeHandle networkId socketPath) cardanoKeys wallet headState tx | |
response <- newEmptyTMVar | |
writeTQueue queue (vtx, response) | |
atomically (takeTMVar response) >>= \case | |
Nothing -> pure () | |
Just err -> throwIO err | |
} |
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 would kind of agree but for the fact I really wanted to do this refactoring to be able to test this very function in an isolated way, or rather independently from the underlying network machinery.
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.
Ah so you mean it's important to you that a Chain
interface is exposed by the Handlers
module? I can live with this change overall, but want to state that while it moves things a bit out of the way, it certainly is not easier to understand with the TMVar
in the TQueue
.
I guess this would make more sense if I had implemented the mock chain I am envisioning that would use this module, but this would take more time and this change is self-contained and in my opinion improves on the current situation: At least, the "handlers" are now testable without requiring a full node. Perhaps expressing this kind of tests would help motivating it even more? |
Co-authored-by: Sebastian Nagel <[email protected]>
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 can live with this change overall, but want to state that while it moves things a bit out of the way, it certainly is not easier to understand with the TMVar in the TQueue.
I agree @ch1bo , I am thinking of enhancing the PR with a cleaner interface. Give me a couple hours |
Also add some documentation
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.
Already better, although I think it could still be made simpler. Still approved 🙂
-- This function can be synchronous or asynchronous. It `atomically` executes | ||
-- the given `STM` action and takes care of posting the resulting transaction to | ||
-- the chain. | ||
type TxPoster m = STM m (ValidatedTx Era) -> m () |
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 it could be made even simpler by just providing the ValidatedTx
? i.e. treat this thing as a callback: type TxPoster = ValidatedTx Era -> m ()
?
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 tried but this would be a larger change: The STM action is wrapped inside another STM action in the called in order to provide a synchronous interface, by creating and passing the TMVar
to hold the result. I tried to change this logic to something simpler but quite a few tests fail and did not want to spend the time to investigate.
This is a minor PR that splits the large
H.C.Direct
module in two: One part dealing with Ouroboros and node interaction through mini-protocols, another part which only takes care of transactions transformation from/to chain. This need arose while working on #375 in order to be able to implement a chain component that could emulate the actual behaviour of a chain without having to implement the protocol logic, so that it can be run withinIOSim
monad.