-
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
Implement ADR 18 #579
Implement ADR 18 #579
Conversation
a0a2154
to
128c156
Compare
hydra-node/src/Hydra/Chain.hs
Outdated
deriving instance IsTx tx => Eq (PostTxError tx) | ||
deriving instance IsTx tx => Show (PostTxError tx) | ||
-- TODO: document | ||
advanceSlot :: a -> a |
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 could/should be moved to a test-specific type class for chain states as it is only required in the simulatedChainAndNetwork
of the BehaviorSpec
(Alternative: make that SimpleTx
specific.)
@@ -362,7 +362,7 @@ estimateScriptsCost pparams systemStart epochInfo utxo tx = do | |||
Left translationError -> | |||
Left $ ErrTranslationError translationError | |||
Right units -> | |||
Map.traverseWithKey (\ptr -> left $ ErrScriptExecutionFailed . (ptr,)) units | |||
traverse (left ErrScriptExecutionFailed) units |
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.
Hahah.. @ffakenz, I happened to remove it here as well 😅. I should re-add the redeemer pointer.
0317dc2
to
1ccbe50
Compare
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 TransactionSome variation because of random mixture of still initial and already committed outputs.
Cost of FanOut TransactionInvolves spending head output and burning head tokens. Uses ada-only UTxO for better comparability.
|
1ccbe50
to
1027391
Compare
} | ||
readTVarIO headState >>= save | ||
mapM_ (callback . Observation) onChainTxs | ||
forM_ receivedTxs $ \tx -> |
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.
NOTE: previously these have been reversed
Just Observation{newChainState} -> atomically $ writeTVar stateVar newChainState | ||
let handler = chainSyncHandler nullTracer callback (pure timeHandle) | ||
-- Simulate some chain following | ||
run $ mapM_ (onRollForward handler) blocks |
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.
Could: not test roll forward when testing the roll backward (it's not needed by the implementation)
Test Results267 tests +2 261 ✔️ +2 16m 6s ⏱️ + 1m 36s Results for commit 3613cee. ± Comparison against base commit c8f99f9. This pull request removes 8 and adds 10 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
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.
🌶️
IsChainState tx | ||
where | ||
-- | Types of what to keep as L1 chain state. | ||
type ChainStateType tx = c | c -> tx |
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.
Nice, didn't know one can use functional dependencies here!
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 remembered it from having read something about injective type families. My first try was to use a data
family but the changes were much more involved and annoying, esp. with parameterised types.
…irectChain This is required to "tie the knot" in the main. We need a starting state before we can define the callback (which needs access to some state).
Also move the ledger directly into HydraNode
This is a bit annoying as we need to thread the chain state through postTx and waitCallback (or derivatives).
Only this way we can avoid orphan instances and cyclic module dependencies.
This pairs a ChainState with a slot. We need to know the latter to be able to rollback correctly.
It's sufficient that we check correct yielding of events now. The actual rollback logic is in the HeadLogic and tested there.
This is an interesting one. Should we have unit tests for this? i.e. asserting the chain state used on effects?
The ChainContext (in the chain state) needs to be consistent for correctly minting and distributing tokens on InitTx.
This is necessary to have the latest chainState when observing multiple transactions without processing events in HeadLogic, e.g. concurrent commits. It will also make chainState update redundant in the HeadLogic, which in turn increases complexity of "where things are happening".
Also clean up run options logging test
This would be quite awkward to define and means that either the simulatedChainAndNetwork is not correctly implemented to be used with real Tx (non-SimpleTx), or that we actually want to have a different test driver for the model based tests (we will also want to construct & validate real transactions).
We only use it in simulatedChainAndNetwork, hence moving it there.
Only relying on this modifyHeadState in 'Main' would mean that mocks like the simulatedChainAndNetwork would become even more complicated.
Instead of an (open) external type family I have turned it into an injective associated type family, using the TypeFamilyDependencies option. It seems to me this simplify the definition and the use by tying both the transactions and the state to the tx type.
ee45583
to
ed3bcdd
Compare
🍁 Based on previous work done with @ffakenz, @v0d1ch and @pgrange
🍁 Changed interface of
Hydra.Chain
by adding aChainStateType tx
andIsChainState
to modifychainState
in aheadState
abstractlyChainCallback
is taking a continuation now which will yield an event🍁 Removed chain-local persistence and in-memory TVar.
🍁 Rollbacks are now fully handled in the
HeadLogic
. The rollback event will contain a rollbackChainSlot
and we can get thechainStateSlot
viaIsChainState
to unwind theHeadState tx
accordingly.🍁 Tying the knot between chain state updates & providing the callback with the latest state in the
hydra-node
Main
module now (see TODO below)🍁 Needed to update the
simulatedChainAndNetwork
quite a bit. Not fully satisfied with the result, especially as chain states are something node-specific and they are shared between all testHydraNode
s in the simulation. This might be even problematic for theModel
tests should they ever usechainState
.🍁 Rewritten
DirectChainSpec
test driver. It needs to keep & updatechainState
now.🍁 Lowered scope of the
HandlersSpec
tests on rollbacks as they cannot cover full rollback behavior anymore. Only correct yielding ofRollback
events is in scope now.🍁 Clear chain state persistence in some E2E tests now as it would be loaded consistently with the heads state now.
🍁 Moved state & transaction generators from
Hydra.Chain.Direct.Context
intoHydra.Chain.Direct.State
to avoid orphan instances and additional modules to break cyclic dependencies (theIsChainState
is annoying).🍁 Consolidated
ReceivedTxs
intoRolledForward
log entry.🍁 Renamed the
HydraHead
handle toNodeState
TODO
simulatedChainAndNetwork
forModel
/ModelSpec
RemovechainState
fromChainEvent
,ChainEffect
& also not thread it throughHeadLogic
BehaviorSpec
even more..