Architecture of Marlowe Discovery #212
Replies: 6 comments 3 replies
-
Here is a first approximation of how the discovery component could work. Similar to the Below is a state transition diagram of the protocol. stateDiagram-v2
[*] --> Idle
Idle --> Intersect : MsgIntersect
Intersect --> Idle : MsgIntersectFound
Intersect --> Idle : MsgIntersectNotFound
Idle --> [*] : MsgDone
Idle --> Next : MsgRequestNext
Next --> Wait : MsgWait
Wait --> Next : MsgPoll
Wait --> Idle : MsgCancel
Next --> Idle : MsgRollForward
Next --> Idle : MsgRollBackward
The message payloads would all be very similar to data DiscoveryEvent
= RoleTokensTransfered TxOutRef Tokens Address
| V1ContractPublished V1ContractHeader
data V1ContractHeader = V1ContractHeaderV1
{ contractId :: ContractId
, rolesCurrency :: PolicyId
, initialRoleTokenDistribution :: Map TokenName Address
, metadata :: Map Int Aeson.Value
, marloweScriptHash :: ScriptHash
, marloweScriptAddress :: Address
, payoutScriptHash :: ScriptHash
} This functionality should provide enough information to implement a variety of Marlowe contract watchers, for example, something like the |
Beta Was this translation helpful? Give feedback.
-
Redundant with |
Beta Was this translation helpful? Give feedback.
-
data DiscoveryEvent
= RoleTokensTransfered TxOutRef Tokens Address
| V1ContractPublished V1ContractHeader Do we need Regarding burning role tokens, many users will not want to have permanent role tokens created for a Marlowe contract with temporary duration. (Personally, I will never use a role-based Marlowe contract on |
Beta Was this translation helpful? Give feedback.
-
Summarizing the outcome of our sidechain discussion: We are going to remove the role token distribution tracking from this component. The discovery component will now only offer: A) A synchronization API for subscribing to a stream of contract headers. The rationale for this is that the contract headers already include the policy ID, and a client can check to see if they have a matching role token in their wallet. Conversely, when a client receives a new token in their wallet, they can query the discovery service to see if there is a Marlowe contract that could use it as a role token. |
Beta Was this translation helpful? Give feedback.
-
Here is a typed-protocols definition for the synchronization protocol: {-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
module Language.Marlowe.Protocol.HeaderSync.Types
where
import Data.Map (Map)
import Data.Word (Word64)
import Language.Marlowe.Runtime.ChainSync.Api (Address, BlockHeader, Metadata, PolicyId, ScriptHash)
import Language.Marlowe.Runtime.Core.Api (ContractId, IsMarloweVersion(..), MarloweVersion, MarloweVersionTag)
import Network.TypedProtocol (Protocol(..))
data ContractHeader = forall (v :: MarloweVersionTag). ContractHeader
{ contractId :: ContractId
, rolesCurrency :: PolicyId
, metadata :: Map Word64 Metadata
, marloweScriptHash :: ScriptHash
, marloweScriptAddress :: Address
, payoutScriptHash :: ScriptHash
, payoutScriptAddress :: Address
, marloweVersion :: MarloweVersion v
, datum :: Datum v
}
data MarloweHeaderSync where
StIdle :: MarloweHeaderSync
StIntersect :: MarloweHeaderSync
StNext :: MarloweHeaderSync
StWait :: MarloweHeaderSync
StDone :: MarloweHeaderSync
instance Protocol MarloweHeaderSync where
data Message MarloweHeaderSync from to where
MsgIntersect :: [BlockHeader] -> Message MarloweHeaderSync
'StIdle
'StIntersect
MsgDone :: Message MarloweHeaderSync
'StIdle
'StDone
MsgRequestNext :: Message MarloweHeaderSync
'StIdle
'StNext
MsgNewHeaders :: BlockHeader -> [ContractHeader] -> Message MarloweHeaderSync
'StNext
'StIdle
MsgRollBackward :: BlockHeader -> Message MarloweHeaderSync
'StNext
'StIdle
MsgWait :: Message MarloweHeaderSync
'StNext
'StWait
MsgPoll :: Message MarloweHeaderSync
'StWait
'StNext
MsgCancel :: Message MarloweHeaderSync
'StWait
'StIdle
MsgIntersectFound :: BlockHeader -> Message MarloweHeaderSync
'StIntersect
'StIdle
MsgIntersectNotFound :: Message MarloweHeaderSync
'StIntersect
'StIdle
data ClientHasAgency st where
TokIdle :: ClientHasAgency 'StIdle
TokWait :: ClientHasAgency 'StWait
data ServerHasAgency st where
TokNext :: ServerHasAgency 'StNext
TokIntersect :: ServerHasAgency 'StIntersect
data NobodyHasAgency st where
TokDone :: NobodyHasAgency 'StDone
exclusionLemma_ClientAndServerHaveAgency TokIdle = \case
exclusionLemma_ClientAndServerHaveAgency TokWait = \case
exclusionLemma_NobodyAndClientHaveAgency TokDone = \case
exclusionLemma_NobodyAndServerHaveAgency TokDone = \case |
Beta Was this translation helpful? Give feedback.
-
For the initial version, going to remove the |
Beta Was this translation helpful? Give feedback.
-
The "Marlowe Discovery" component of Marlowe Runtime provides services for the discovery of Marlowe contracts on the blockchain and the interrogation of metadata (version, certification, etc.) about the contract.
Marlowe contracts are uniquely identified by the
TxOutRef
of their creation transaction. Metadata asserts the version of Marlowe Core used for the contract; such assertions are cryptographically verified.The discovery mechanism in
Language.Marlowe.Client
currently relies upon computing the Marlowe validator script address from a native token and seeing if that address has any transactions.Beta Was this translation helpful? Give feedback.
All reactions