Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
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
- maxMainnetLovelace :: Coin
- maximumNumberOfParties :: Int
- data PostChainTx tx
- = InitTx {
- participants :: [OnChainId]
- headParameters :: HeadParameters
- | AbortTx { }
- | CollectComTx {
- utxo :: UTxOType tx
- headId :: HeadId
- headParameters :: HeadParameters
- | DecrementTx {
- 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
- utxoToDecommit :: Maybe (UTxOType tx)
- headSeed :: HeadSeed
- contestationDeadline :: UTCTime
- = InitTx {
- data OnChainTx tx
- = OnInitTx {
- headId :: HeadId
- headSeed :: HeadSeed
- headParameters :: HeadParameters
- participants :: [OnChainId]
- | OnCommitTx { }
- | OnAbortTx {
- headId :: HeadId
- | OnCollectComTx {
- headId :: HeadId
- | OnDecrementTx {
- headId :: HeadId
- newVersion :: SnapshotVersion
- distributedOutputs :: [TxOutType tx]
- | OnCloseTx {
- headId :: HeadId
- snapshotNumber :: SnapshotNumber
- contestationDeadline :: UTCTime
- | OnContestTx {
- headId :: HeadId
- snapshotNumber :: SnapshotNumber
- contestationDeadline :: UTCTime
- | OnFanoutTx {
- headId :: HeadId
- = OnInitTx {
- data PostTxError tx
- = NoSeedInput
- | InvalidSeed {
- headSeed :: HeadSeed
- | InvalidHeadId {
- headId :: HeadId
- | CannotFindOwnInitial {
- knownUTxO :: UTxOType tx
- | UnsupportedLegacyOutput {
- byronAddress :: Address ByronAddr
- | InvalidStateToPost {
- txTried :: PostChainTx tx
- chainState :: ChainStateType tx
- | NotEnoughFuel
- | NoFuelUTXOFound
- | ScriptFailedInWallet {
- redeemerPtr :: Text
- failureReason :: Text
- | InternalWalletError { }
- | FailedToPostTx { }
- | PlutusValidationFailed { }
- | CommittedTooMuchADAForMainnet {
- userCommittedLovelace :: Coin
- mainnetLimitLovelace :: Coin
- | FailedToDraftTxNotInitializing
- | FailedToConstructAbortTx
- | FailedToConstructCloseTx
- | FailedToConstructContestTx
- | FailedToConstructCollectTx
- | FailedToConstructDecrementTx
- | FailedToConstructFanoutTx
- data ChainStateHistory tx = UnsafeChainStateHistory {
- history :: NonEmpty (ChainStateType tx)
- defaultChainState :: ChainStateType tx
- currentState :: ChainStateHistory tx -> ChainStateType tx
- pushNewState :: ChainStateType tx -> ChainStateHistory tx -> ChainStateHistory tx
- initHistory :: ChainStateType tx -> ChainStateHistory tx
- rollbackHistory :: IsChainState tx => ChainSlot -> ChainStateHistory tx -> ChainStateHistory tx
- data Chain tx m = Chain {
- postTx :: MonadThrow m => PostChainTx tx -> m ()
- draftCommitTx :: MonadThrow m => HeadId -> CommitBlueprintTx tx -> m (Either (PostTxError tx) tx)
- submitTx :: MonadThrow m => tx -> m ()
- data ChainEvent tx
- = Observation {
- observedTx :: OnChainTx tx
- newChainState :: ChainStateType tx
- | Rollback {
- rolledBackChainState :: ChainStateType tx
- | Tick { }
- | PostTxError {
- postChainTx :: PostChainTx tx
- postTxError :: PostTxError 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
maxMainnetLovelace :: Coin Source #
Hardcoded limit for commit tx on mainnet
maximumNumberOfParties :: Int Source #
Hardcoded limit for maximum number of parties in a head protocol
The value is obtained from calculating the costs of running the scripts
and on-chan validators (see computeCollectComCost
computeAbortCost
)
data PostChainTx tx Source #
Data type used to post transactions on chain. It holds everything to construct corresponding Head protocol transactions.
InitTx | |
| |
AbortTx | |
CollectComTx | |
| |
DecrementTx | |
| |
CloseTx | |
| |
ContestTx | |
| |
FanoutTx | |
|
Instances
Describes transactions as seen on chain. Holds as minimal information as possible to simplify observing the chain.
OnInitTx | |
| |
OnCommitTx | |
OnAbortTx | |
| |
OnCollectComTx | |
| |
OnDecrementTx | |
| |
OnCloseTx | |
| |
OnContestTx | |
| |
OnFanoutTx | |
|
Instances
data PostTxError tx Source #
Exceptions thrown by $sel:postTx:Chain
.
NoSeedInput | |
InvalidSeed | |
| |
InvalidHeadId | |
| |
CannotFindOwnInitial | |
| |
UnsupportedLegacyOutput | Comitting byron addresses is not supported. |
| |
InvalidStateToPost | |
| |
NotEnoughFuel | |
NoFuelUTXOFound | |
ScriptFailedInWallet | Script execution failed when finalizing a transaction in the wallet.
XXX: Ideally we want a cardano-api type with corresonding JSON instance
here. But the wallet still uses ledger types and we don't want to copy the
conversion from ledger |
| |
InternalWalletError | A generic error happened when finalizing a transction in the wallet. |
FailedToPostTx | An error occurred when submitting a transaction to the cardano-node. |
PlutusValidationFailed | A plutus script failed in a transaction submitted to the cardano-node. NOTE: PlutusDebugInfo does not have much available instances so we put it in Text form but it's lame |
| |
CommittedTooMuchADAForMainnet | User tried to commit more than |
| |
FailedToDraftTxNotInitializing | We can only draft commit tx for the user when in Initializing state |
FailedToConstructAbortTx | |
FailedToConstructCloseTx | |
FailedToConstructContestTx | |
FailedToConstructCollectTx | |
FailedToConstructDecrementTx | |
FailedToConstructFanoutTx |
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
.
UnsafeChainStateHistory | |
|
Instances
currentState :: ChainStateHistory tx -> ChainStateType tx Source #
pushNewState :: ChainStateType tx -> ChainStateHistory tx -> ChainStateHistory tx Source #
initHistory :: ChainStateType tx -> ChainStateHistory tx Source #
rollbackHistory :: IsChainState tx => ChainSlot -> ChainStateHistory tx -> ChainStateHistory tx Source #
Handle to interface with the main chain network
Chain | |
|
data ChainEvent tx Source #
Observation | Indicates a head protocol transaction has been observed. |
| |
Rollback | |
| |
Tick | Indicate time has advanced on the chain. NOTE: While the type does not guarantee that the UTCTime and ChainSlot 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. |
PostTxError | Event to re-ingest errors from |
|
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.