| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Hydra.Chain
Description
Specifies the Head-Chain Interaction part of the protocol
Incoming and outgoing on-chain transactions are modelled respectively as OnChainTx
and PostChainTx which are data type that abstracts away the details of the structure
of the transaction.
Synopsis
- maximumNumberOfParties :: Int
- data PostChainTx tx
- = InitTx {
- participants :: [OnChainId]
- headParameters :: HeadParameters
- | IncrementTx {
- headSeed :: HeadSeed
- headId :: HeadId
- headParameters :: HeadParameters
- incrementingSnapshot :: ConfirmedSnapshot tx
- depositTxId :: TxIdType tx
- | RecoverTx {
- headId :: HeadId
- recoverTxId :: TxIdType tx
- deadline :: ChainSlot
- recoverUTxO :: UTxOType tx
- | DecrementTx {
- headSeed :: HeadSeed
- headId :: HeadId
- headParameters :: HeadParameters
- decrementingSnapshot :: ConfirmedSnapshot tx
- | CloseTx {
- headId :: HeadId
- headParameters :: HeadParameters
- openVersion :: SnapshotVersion
- closingSnapshot :: ConfirmedSnapshot tx
- | ContestTx {
- headId :: HeadId
- headParameters :: HeadParameters
- openVersion :: SnapshotVersion
- contestingSnapshot :: ConfirmedSnapshot tx
- | FanoutTx {
- utxo :: UTxOType tx
- utxoToCommit :: Maybe (UTxOType tx)
- utxoToDecommit :: Maybe (UTxOType tx)
- utxoForProof :: UTxOType tx
- headSeed :: HeadSeed
- contestationDeadline :: UTCTime
- | PartialFanoutTx {
- utxoToDistribute :: UTxOType tx
- utxoForProof :: UTxOType tx
- headSeed :: HeadSeed
- contestationDeadline :: UTCTime
- | FinalPartialFanoutTx {
- utxoToDistribute :: UTxOType tx
- presettledUTxO :: UTxOType tx
- headSeed :: HeadSeed
- contestationDeadline :: UTCTime
- = InitTx {
- data OnChainTx tx
- = OnInitTx {
- headId :: HeadId
- headSeed :: HeadSeed
- headParameters :: HeadParameters
- participants :: [OnChainId]
- | OnDepositTx { }
- | OnRecoverTx {
- headId :: HeadId
- recoveredTxId :: TxIdType tx
- recoveredUTxO :: UTxOType tx
- | OnIncrementTx {
- headId :: HeadId
- newVersion :: SnapshotVersion
- depositTxId :: TxIdType tx
- | OnDecrementTx {
- headId :: HeadId
- newVersion :: SnapshotVersion
- distributedUTxO :: UTxOType tx
- | OnCloseTx {
- headId :: HeadId
- snapshotNumber :: SnapshotNumber
- contestationDeadline :: UTCTime
- | OnContestTx {
- headId :: HeadId
- snapshotNumber :: SnapshotNumber
- contestationDeadline :: UTCTime
- | OnFanoutTx {
- headId :: HeadId
- fanoutUTxO :: UTxOType tx
- | OnPartialFanoutTx {
- headId :: HeadId
- distributedOutputs :: UTxOType tx
- = OnInitTx {
- data PostTxError tx
- = NoSeedInput
- | InvalidSeed {
- headSeed :: HeadSeed
- | InvalidHeadId {
- headId :: HeadId
- | UnsupportedLegacyOutput {
- byronAddress :: Address ByronAddr
- | DepositTooLow {
- providedValue :: Coin
- minimumValue :: Coin
- | DepositTooLarge { }
- | InvalidStateToPost {
- txTried :: PostChainTx tx
- chainState :: ChainStateType tx
- | NotEnoughFuel {
- failingTx :: tx
- | NoFuelUTXOFound {
- failingTx :: tx
- | ScriptFailedInWallet {
- redeemerPtr :: Text
- failureReason :: Text
- failingTx :: tx
- | InternalWalletError { }
- | FailedToPostTx {
- failureReason :: Text
- failingTx :: tx
- | FailedToConstructCloseTx
- | FailedToConstructContestTx
- | FailedToConstructDepositTx {
- failureReason :: Text
- | FailedToConstructRecoverTx {
- failureReason :: Text
- | FailedToConstructIncrementTx {
- failureReason :: Text
- | FailedToConstructDecrementTx {
- failureReason :: Text
- | FailedToConstructFanoutTx
- | FailedToConstructPartialFanoutTx
- | StalePartialFanoutTx
- | ContestationDeadlineOutsideTimeHorizon {
- failureReason :: Text
- | InvalidTokenRequest [(PolicyId, PolicyAssets)]
- data ChainStateHistory tx = UnsafeChainStateHistory {
- history :: NonEmpty (ChainStateType tx)
- lastKnown :: ChainPointType tx
- defaultChainState :: ChainStateType tx
- currentState :: ChainStateHistory tx -> ChainStateType tx
- pushNewState :: IsChainState tx => ChainStateType tx -> ChainStateHistory tx -> ChainStateHistory tx
- setLastKnown :: ChainPointType tx -> ChainStateHistory tx -> ChainStateHistory tx
- initHistory :: IsChainState tx => ChainStateType tx -> ChainStateHistory tx
- rollbackHistory :: IsChainState tx => ChainSlot -> ChainStateHistory tx -> ChainStateHistory tx
- prefixOf :: IsChainState tx => ChainStateHistory tx -> NonEmpty (ChainPointType tx)
- data Chain tx m = Chain {
- postTx :: MonadThrow m => PostChainTx tx -> m ()
- draftDepositTx :: MonadThrow m => HeadId -> PParams LedgerEra -> ConfirmedSnapshot tx -> CommitBlueprintTx tx -> UTCTime -> Maybe AddressInEra -> m (Either (PostTxError tx) tx)
- submitTx :: MonadThrow m => tx -> m ()
- checkNonADAAssets :: ConfirmedSnapshot tx -> Either Value ()
- data ChainEvent tx
- = Observation {
- observedTx :: OnChainTx tx
- newChainState :: ChainStateType tx
- | Rollback {
- chainTime :: UTCTime
- rolledBackChainState :: ChainStateType tx
- | Tick {
- chainTime :: UTCTime
- chainPoint :: ChainPointType tx
- | PostTxError {
- postChainTx :: PostChainTx tx
- postTxError :: PostTxError tx
- failingTx :: Maybe tx
- = Observation {
- type ChainCallback tx m = ChainEvent tx -> m ()
- type ChainComponent tx m a = ChainCallback tx m -> (Chain tx m -> m a) -> m a
Documentation
maximumNumberOfParties :: Int Source #
Hardcoded limit for maximum number of parties in a head protocol. A too high number would be detected by property and acceptance tests.
data PostChainTx tx Source #
Data type used to post transactions on chain. It holds everything to construct corresponding Head protocol transactions. TODO: somehow merge HeadSeed/HeadId
Constructors
| InitTx | |
Fields
| |
| IncrementTx | |
Fields
| |
| RecoverTx | |
Fields
| |
| DecrementTx | |
Fields
| |
| CloseTx | |
Fields
| |
| ContestTx | |
Fields
| |
| FanoutTx | |
Fields
| |
| PartialFanoutTx | Non-final partial fanout of a user-selected subset. Distributes
|
Fields
| |
| FinalPartialFanoutTx | |
Fields
| |
Instances
Describes transactions as seen on chain. Holds as minimal information as possible to simplify observing the chain.
Constructors
| OnInitTx | |
Fields
| |
| OnDepositTx | |
| OnRecoverTx | |
Fields
| |
| OnIncrementTx | |
Fields
| |
| OnDecrementTx | |
Fields
| |
| OnCloseTx | |
Fields
| |
| OnContestTx | |
Fields
| |
| OnFanoutTx | |
Fields
| |
| OnPartialFanoutTx | |
Fields
| |
Instances
data PostTxError tx Source #
Exceptions thrown by $sel:postTx:Chain.
Constructors
| NoSeedInput | |
| InvalidSeed | |
Fields
| |
| InvalidHeadId | |
Fields
| |
| UnsupportedLegacyOutput | Committing byron addresses is not supported. |
Fields
| |
| DepositTooLow | |
Fields
| |
| DepositTooLarge | The deposit is too large: the increment transaction claiming it would exceed layer 1 ledger limits (estimated sizes include a balancing margin). |
Fields | |
| InvalidStateToPost | |
Fields
| |
| NotEnoughFuel | |
Fields
| |
| NoFuelUTXOFound | |
Fields
| |
| ScriptFailedInWallet | Script execution failed when finalizing a transaction in the wallet.
XXX: Ideally we want a cardano-api type with corresponding JSON instance
here. But the wallet still uses ledger types and we don't want to copy the
conversion from ledger |
Fields
| |
| InternalWalletError | A generic error happened when finalizing a transaction in the wallet. |
| FailedToPostTx | An error occurred when submitting a transaction to the cardano-node. |
Fields
| |
| FailedToConstructCloseTx | |
| FailedToConstructContestTx | |
| FailedToConstructDepositTx | |
Fields
| |
| FailedToConstructRecoverTx | |
Fields
| |
| FailedToConstructIncrementTx | |
Fields
| |
| FailedToConstructDecrementTx | |
Fields
| |
| FailedToConstructFanoutTx | |
| FailedToConstructPartialFanoutTx | |
| StalePartialFanoutTx | Another node already posted this partial fanout step; the chain observation loop will emit the correct next step automatically. |
| ContestationDeadlineOutsideTimeHorizon | |
Fields
| |
| InvalidTokenRequest [(PolicyId, PolicyAssets)] | |
Instances
data ChainStateHistory tx Source #
A non empty sequence of chain states that can be rolled back.
This is expected to be constructed by using the smart constructor
initHistory.
Constructors
| UnsafeChainStateHistory | |
Fields
| |
Instances
currentState :: ChainStateHistory tx -> ChainStateType tx Source #
pushNewState :: IsChainState tx => ChainStateType tx -> ChainStateHistory tx -> ChainStateHistory tx Source #
Record a new chain state in history. Also ensures the $sel:lastKnown:UnsafeChainStateHistory point is
updated accordingly.
setLastKnown :: ChainPointType tx -> ChainStateHistory tx -> ChainStateHistory tx Source #
Update the last known chain point. Use pushNewState if you have a full 'ChainStateType tx'.
initHistory :: IsChainState tx => ChainStateType tx -> ChainStateHistory tx Source #
rollbackHistory :: IsChainState tx => ChainSlot -> ChainStateHistory tx -> ChainStateHistory tx Source #
prefixOf :: IsChainState tx => ChainStateHistory tx -> NonEmpty (ChainPointType tx) Source #
Get the known prefix of all the ChainStateHistory.
Handle to interface with the main chain network
Constructors
| Chain | |
Fields
| |
data ChainEvent tx Source #
Constructors
| Observation | Indicates a head protocol transaction has been observed. |
Fields
| |
| Rollback | |
Fields
| |
| Tick | Indicate time has advanced on the chain. This is deliberately not a
ChainStateType because state updates are only expected upon NOTE: While the type does not guarantee that the UTCTime and the slot in ChainPointType tx are consistent the alternative would be provide the means to do the conversion. For Cardano, this would be a systemStart and eraHistory.. which is annoying and if it's kept in the chain layer, it would mean another round trip / state to keep there. |
Fields
| |
| PostTxError | Event to re-ingest errors from |
Fields
| |
Instances
type ChainCallback tx m = ChainEvent tx -> m () Source #
A callback indicating a 'ChainEvent tx' happened. Most importantly the
Observation of a relevant Hydra transaction.
type ChainComponent tx m a = ChainCallback tx m -> (Chain tx m -> m a) -> m a Source #
A type tying both posting and observing transactions into a single Component.