-
Notifications
You must be signed in to change notification settings - Fork 46
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
PLT-7111 PLT-7682 PLT-7684 PLT-7685 PLT-7683 Open roles #726
Conversation
6740534
to
23e1e79
Compare
dbac6ec
to
04da471
Compare
WalkthroughThe changes primarily revolve around the introduction of "open roles" in Marlowe contracts, which allow parties not identified by address at the time of contract instantiation to later participate in the contract. This feature is implemented across various modules, with significant changes to the handling of role tokens, minting, and transaction safety. Additionally, the concept of "helper scripts" is introduced to manage these open roles. Changes
TipsChat with CodeRabbit Bot (
|
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.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files ignored due to filter (3)
- marlowe-runtime/doc/open-roles-contract.png
- marlowe-runtime/doc/open-roles-interaction.png
- marlowe-runtime/gen/Language/Marlowe/Runtime/Transaction/Gen.hs
Files selected for processing (45)
- marlowe-apps/src/Language/Marlowe/Runtime/App/Build.hs (2 hunks)
- marlowe-cli/src/Language/Marlowe/CLI/Analyze.hs (11 hunks)
- marlowe-cli/tests/Spec/Analysis.hs (2 hunks)
- marlowe-integration-tests/marlowe-integration-tests.cabal (1 hunks)
- marlowe-integration-tests/test/Language/Marlowe/Runtime/CliSpec.hs (6 hunks)
- marlowe-integration-tests/test/Language/Marlowe/Runtime/Integration/ApplyInputs.hs (1 hunks)
- marlowe-integration-tests/test/Language/Marlowe/Runtime/Integration/Basic.hs (2 hunks)
- marlowe-integration-tests/test/Language/Marlowe/Runtime/Integration/Create.hs (1 hunks)
- marlowe-integration-tests/test/Language/Marlowe/Runtime/Integration/OpenRoles.hs (1 hunks)
- marlowe-integration-tests/test/Language/Marlowe/Runtime/Integration/StandardContract.hs (3 hunks)
- marlowe-integration-tests/test/Language/Marlowe/Runtime/IntegrationSpec.hs (2 hunks)
- marlowe-integration-tests/test/Language/Marlowe/Runtime/Web/Contracts/Contract/Post.hs (2 hunks)
- marlowe-integration/src/Test/Integration/Marlowe/Local.hs (3 hunks)
- marlowe-runtime-cli/app/Language/Marlowe/Runtime/CLI/Command/Create.hs (2 hunks)
- marlowe-runtime-web/.golden/OpenApi/golden (1 hunks)
- marlowe-runtime-web/changelog.d/20231024_132059_brian.bush_PLT_7111.md (1 hunks)
- marlowe-runtime-web/server/Language/Marlowe/Runtime/Web/Server/DTO.hs (3 hunks)
- marlowe-runtime-web/server/Language/Marlowe/Runtime/Web/Server/REST/ApiError.hs (5 hunks)
- marlowe-runtime-web/src/Language/Marlowe/Runtime/Web/Orphans.hs (2 hunks)
- marlowe-runtime-web/src/Language/Marlowe/Runtime/Web/Types.hs (5 hunks)
- marlowe-runtime/changelog.d/20231024_132111_brian.bush_PLT_7111.md (1 hunks)
- marlowe-runtime/changelog.d/20231102_170110_brian.bush_PLT_7683.md (1 hunks)
- marlowe-runtime/doc/open-roles.md (1 hunks)
- marlowe-runtime/marlowe-runtime.cabal (1 hunks)
- marlowe-runtime/marlowe-runtime/Logging.hs (4 hunks)
- marlowe-runtime/marlowe-tx/Logging.hs (4 hunks)
- marlowe-runtime/marlowe-tx/Main.hs (2 hunks)
- marlowe-runtime/runtime/Language/Marlowe/Runtime.hs (3 hunks)
- marlowe-runtime/src/Language/Marlowe/Runtime/Core/Api.hs (1 hunks)
- marlowe-runtime/src/Language/Marlowe/Runtime/Core/ScriptRegistry.hs (24 hunks)
- marlowe-runtime/test/Language/Marlowe/Runtime/Core/ScriptRegistrySpec.hs (3 hunks)
- marlowe-runtime/test/Language/Marlowe/Runtime/Transaction/BuildConstraintsSpec.hs (11 hunks)
- marlowe-runtime/test/Language/Marlowe/Runtime/Transaction/ConstraintsSpec.hs (12 hunks)
- marlowe-runtime/test/Language/Marlowe/Runtime/Transaction/SafetySpec.hs (8 hunks)
- marlowe-runtime/tx-api/Language/Marlowe/Runtime/Transaction/Api.hs (10 hunks)
- marlowe-runtime/tx/Language/Marlowe/Runtime/Transaction.hs (3 hunks)
- marlowe-runtime/tx/Language/Marlowe/Runtime/Transaction/BuildConstraints.hs (10 hunks)
- marlowe-runtime/tx/Language/Marlowe/Runtime/Transaction/Constraints.hs (28 hunks)
- marlowe-runtime/tx/Language/Marlowe/Runtime/Transaction/Query/Helper.hs (1 hunks)
- marlowe-runtime/tx/Language/Marlowe/Runtime/Transaction/Safety.hs (12 hunks)
- marlowe-runtime/tx/Language/Marlowe/Runtime/Transaction/Server.hs (19 hunks)
- marlowe-test/src/Spec/Marlowe/Semantics/Arbitrary.hs (1 hunks)
- marlowe/src/Language/Marlowe/Analysis/Safety/Ledger.hs (1 hunks)
- marlowe/src/Language/Marlowe/Analysis/Safety/Transaction.hs (10 hunks)
- marlowe/src/Language/Marlowe/Analysis/Safety/Types.hs (6 hunks)
Files not reviewed due to errors (1)
- marlowe-runtime/doc/open-roles.md (Error: diff too large)
Files skipped from review due to trivial changes (8)
- marlowe-integration-tests/marlowe-integration-tests.cabal
- marlowe-integration-tests/test/Language/Marlowe/Runtime/Integration/Basic.hs
- marlowe-integration-tests/test/Language/Marlowe/Runtime/Integration/Create.hs
- marlowe-integration-tests/test/Language/Marlowe/Runtime/IntegrationSpec.hs
- marlowe-runtime-web/.golden/OpenApi/golden
- marlowe-runtime/changelog.d/20231102_170110_brian.bush_PLT_7683.md
- marlowe-runtime/marlowe-tx/Logging.hs
- marlowe-test/src/Spec/Marlowe/Semantics/Arbitrary.hs
Additional comments: 153
marlowe-integration-tests/test/Language/Marlowe/Runtime/Integration/OpenRoles.hs (1)
- 1-20: The new test module for open roles seems to be well-structured and imports the necessary modules for the test. The
spec
function is correctly defined and uses thedescribe
function fromTest.Hspec
to describe the test scenario. The test scenario is created using thebasicScenarioWithCreator
,createStandardContractWithRolesConfig
,RoleTokensMint
, andmkMint
functions. The roles "Thread" and "Party A" are created with their respective destinations and optional metadata. Ensure that the test passes and covers all the necessary cases for open roles.marlowe-apps/src/Language/Marlowe/Runtime/App/Build.hs (2)
24-30: The import statements are well-organized and only import the necessary modules and functions, which is a good practice to avoid namespace pollution.
60-61: The
build
function is called with the appropriate arguments. The lambda function provided as the second argument tobuild
extracts thecontractId
andtxBody
from theContractCreated
constructor and wraps them in a tuple with theTxBodyInEraWithReferenceScripts
constructor. This seems to be a correct usage of thebuild
function based on the provided context.marlowe-runtime-web/server/Language/Marlowe/Runtime/Web/Server/DTO.hs (3)
70-70: The new import statement is correctly placed and follows the alphabetical order of import statements. Ensure that
HelperScript
is used in the code.795-795: The new case in the
fromDTO
function correctly handles theUsePolicyWithOpenRoles
policy. Ensure that theUsePolicyWithOpenRoles
policy is correctly implemented in theWeb
module and that theRoleTokensUsePolicyWithOpenRoles
constructor is correctly implemented in theTx
module.809-817: The new cases in the
convertConfig
function correctly handle theThreadRoleTokenSimple
,ThreadRoleTokenAdvanced
,OpenRoleTokenSimple
, andOpenRoleTokenAdvanced
configurations. Ensure that these configurations are correctly implemented in theWeb
module and that theToSelf
andOpenRoleScript
constructors are correctly implemented in theTx
module.marlowe-integration/src/Test/Integration/Marlowe/Local.hs (3)
109-115: The new import for
HelperScript
in theLanguage.Marlowe.Runtime.Core.ScriptRegistry
module is introduced. Ensure that theHelperScript
is correctly defined and exported in theScriptRegistry
module.449-463: The new variable
openRoleValidatorInfo
and a new scriptopenRoleScript
are added. ThehelperScripts
map is updated to include theOpenRoleScript
and its corresponding script. Ensure thatmrOpenRoleValidator
is correctly defined and that theOpenRoleScript
is correctly handled in the rest of the codebase.487-503: The
helperScriptUTxOs
map is updated to include theOpenRoleScript
and its associated transaction output. Ensure that the transaction output forOpenRoleScript
is correctly handled in the rest of the codebase.marlowe-cli/tests/Spec/Analysis.hs (2)
27-30: The import of
unitAnnotator
and its usage infindTransactions'
function call is a new addition. Ensure that theunitAnnotator
function is correctly implemented and that it provides the expected functionality.111-116: The
findTransactions'
function call now includesunitAnnotator
as an argument. Ensure that this change doesn't affect the functionality of thefindTransactions'
function and that it still returns the expected results.marlowe-runtime-web/src/Language/Marlowe/Runtime/Web/Types.hs (3)
811-839: The new constructor
UsePolicyWithOpenRoles
is added to theRolesConfig
data type. TheFromJSON
andToJSON
instances are updated to handle this new constructor. Ensure that the new constructor is handled everywhere theRolesConfig
type is used.851-881: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [854-903]
The
RoleTokenConfig
data type is updated with new constructorsOpenRoleTokenSimple
,OpenRoleTokenAdvanced
,ThreadRoleTokenSimple
, andThreadRoleTokenAdvanced
. TheFromJSON
andToJSON
instances are updated to handle these new constructors. Ensure that the new constructors are handled everywhere theRoleTokenConfig
type is used.
- 917-933: The
ToSchema
instance forRoleTokenConfig
is updated to include the new constructors. Ensure that the new constructors are handled everywhere theRoleTokenConfig
type is used.marlowe-runtime/marlowe-runtime.cabal (1)
- 535-541: The addition of the
Language.Marlowe.Runtime.Transaction.Query.Helper
module to thetx
library seems to be in line with the changes described in the pull request summary. Ensure that this new module is properly integrated with the rest of the codebase and that it doesn't introduce any breaking changes.marlowe-runtime/marlowe-runtime/Logging.hs (4)
30-43: The new import for
Language.Marlowe.Runtime.Transaction.Query.Helper
is added. Ensure that this module is available and contains the necessary definitions.60-63: A new data constructor
LoadHelpersContext
is added to theRootSelector
type. This seems to be in line with the other constructors in the type.102-103: An instance of
Inject
forQ.LoadHelpersContextSelector
andRootSelector
is added. This is consistent with the otherInject
instances for different selectors.144-147: A case for
LoadHelpersContext
is added in therenderRootSelectorOTel
function. This is consistent with the other cases in the function.marlowe-runtime/marlowe-tx/Main.hs (2)
29-35: The new import statement for
Language.Marlowe.Runtime.Transaction.Query.Helper
is correctly placed and follows the Haskell import conventions.140-151: The
loadHelpersContext
function is correctly added to therun
function. It uses theHelper.loadHelpersContext
function to load the helper context. Ensure that theHelper.loadHelpersContext
function is correctly implemented and handles all possible error scenarios.marlowe-runtime/runtime/Language/Marlowe/Runtime.hs (3)
63-69: The new import statement for
Language.Marlowe.Runtime.Transaction.Query.Helper
and the new functionloadHelpersContext
are added correctly. Ensure that the new function is used correctly throughout the codebase.128-134: The new
Inject LoadHelpersContextSelector s
is added correctly to themarloweRuntime
function. Ensure that the newLoadHelpersContextSelector
is used correctly throughout the codebase.205-211: The new
loadHelpersContext
function is used correctly in themarlowe-tx
supervisor. Ensure that the function is used correctly throughout the codebase.marlowe-runtime-web/changelog.d/20231024_132059_brian.bush_PLT_7111.md (1)
- 1-3: The changelog update is clear and concise, providing a good summary of the new feature added.
marlowe-integration-tests/test/Language/Marlowe/Runtime/Web/Contracts/Contract/Post.hs (3)
20-32: The new test cases are well defined and cover the new functionality of open roles. Ensure that these tests pass and that they cover all the edge cases for the new functionality.
34-39: The
specWithRolesConfig
function is well defined and correctly sets up the test environment. Ensure that this function is used correctly in all test cases where it is needed.59-65: The
roles
field of theWeb.PostContractsRequest
is correctly set using theroles
argument. Ensure that this field is correctly used in the server-side code that handles this request.marlowe-runtime/test/Language/Marlowe/Runtime/Transaction/SafetySpec.hs (5)
84-93: The
spec
function has been updated to include additional parameters in function calls. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.119-134: The
minAdaUpperBound
function has been modified to include additional parameters. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.307-333: The
checkTransactions
function has been modified to include additional parameters. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.358-372: The
checkTransactions
function has been modified to include additional parameters. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.411-431: The
checkTransactions
function has been modified to include additional parameters. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.marlowe-integration-tests/test/Language/Marlowe/Runtime/Integration/StandardContract.hs (4)
46-52: The import of
RoleTokensConfig
is new and is used in the updated functions to handle role token configurations. This is part of the changes to support open roles.111-121: The
createStandardContract
function now usescreateStandardContractWithTags
with an empty set of tags. ThecreateStandardContractWithTags
function is modified to usecreateStandardContractWithTagsAndRolesConfig
with aRoleTokensConfig
that mints a role token for "Party A". A new functioncreateStandardContractWithRolesConfig
is added that usescreateStandardContractWithTagsAndRolesConfig
with an empty set of tags.+ createStandardContract = createStandardContractWithTags mempty + createStandardContractWithTags :: Set MarloweMetadataTag -> Wallet -> Wallet -> Integration (StandardContractInit 'V1) + createStandardContractWithTags tags partyAWallet = + createStandardContractWithTagsAndRolesConfig + (RoleTokensMint $ mkMint $ pure ("Party A", (ToAddress . changeAddress $ addresses partyAWallet, Nothing))) + tags + partyAWallet + createStandardContractWithRolesConfig :: RoleTokensConfig -> Wallet -> Wallet -> Integration (StandardContractInit 'V1) + createStandardContractWithRolesConfig rolesConfig = createStandardContractWithTagsAndRolesConfig rolesConfig mempty
- 123-128: The
createStandardContractWithTagsAndRolesConfig
function is added. It takes aRoleTokensConfig
, a set ofMarloweMetadataTag
, and twoWallet
parameters, and returns anIntegration
ofStandardContractInit 'V1
. This function allows creating a standard contract with a specific role token configuration and a set of metadata tags.+ createStandardContractWithTagsAndRolesConfig + :: RoleTokensConfig -> Set MarloweMetadataTag -> Wallet -> Wallet -> Integration (StandardContractInit 'V1) + createStandardContractWithTagsAndRolesConfig rolesConfig tags partyAWallet partyBWallet = do + partyBAddress <- + expectJust "Failed to convert party B address" $ toPlutusAddress $ changeAddress $ addresses partyBWallet + now <- liftIO getCurrentTime
- 133-139: The
createContract
function now takes aRoleTokensConfig
parameter. If the set of tags is empty,emptyMarloweTransactionMetadata
is used; otherwise, aMarloweMetadata
with the set of tags is used.+ createContract + Nothing + MarloweV1 + (addresses partyAWallet) + rolesConfig + ( if Set.null tags + then emptyMarloweTransactionMetadata + else + emptyMarloweTransactionMetadata + { marloweMetadata = + Just + MarloweMetadata + { tags = Map.fromSet (const Nothing) tags + , continuations = Nothing + } + } + ) + Nothing + (Right contractHash)marlowe-runtime-cli/app/Language/Marlowe/Runtime/CLI/Command/Create.hs (2)
52-58: The new import
Destination (ToAddress)
and theRoleTokensConfig
data type are introduced. These changes seem to be related to handling role tokens and minting.236-246: The
runCreateCommand
function is updated to handle different types ofroles
. ThetoNFT
function now usesToAddress
to specify the address, and theRoleTokensMint
constructor is updated to useToAddress
for the address parameter. These changes seem to be related to handling role tokens and minting.marlowe-runtime/tx/Language/Marlowe/Runtime/Transaction.hs (3)
41-54: The new import statements for
LoadHelpersContext
and related modules are correctly placed and follow the Haskell best practices for import ordering.69-72: The
loadHelpersContext
field has been added to theTransactionDependencies
data type. Ensure that all instances ofTransactionDependencies
throughout the codebase have been updated to include this new field.247-296: The
renderLoadHelpersContextSelectorOTel
function has been added to handle rendering ofLoadHelpersContextSelector
events. This function follows the pattern of the otherrender*SelectorOTel
functions in this module, and appears to be correctly implemented.marlowe-runtime/test/Language/Marlowe/Runtime/Transaction/BuildConstraintsSpec.hs (9)
13-19: The new import
Data.Bifunctor (second)
is used in theopenRolesSpec
function. Thesecond
function is used to apply a function to the second element of a pair.46-52: The new import
Language.Marlowe.Runtime.Core.ScriptRegistry (HelperScript (..))
is used in theopenRolesSpec
function. TheHelperScript
data type is used in thehelperOutputConstraints
field of theTxConstraints
data type.61-64: The new
HelperOutputConstraints
data type is used in thehelperOutputConstraints
field of theTxConstraints
data type. This field is used to store constraints for helper scripts.115-115: The
openRolesSpec
function is added to the list of test specifications. This function tests the constraints for open roles.197-200: The
extractSentRoleTokens
function is updated to handle theMintRoleTokens
case. This function extracts the role tokens that are sent in a transaction.259-265: The
genRoleTokensConfig
function is updated to generate aRoleTokensConfig
that includes open roles. TheRoleTokensMint
case is updated to generate a list of roles and destinations.301-304: The
helperOutputConstraints
field is added to theTxConstraints
data type. This field is used to store constraints for helper scripts.772-857: The
openRolesSpec
function is added. This function tests the constraints for open roles. It tests that the thread tokens are added to the initial state, the constraints for all open-role tokens are included, the open-role datum references the thread token, and the open-role validator UTxO contains the open-role token.857-864: The
genOpenRolesConfig
function is added. This function generates aRoleTokensConfig
that includes open roles.marlowe-runtime/tx-api/Language/Marlowe/Runtime/Transaction/Api.hs (10)
24-25: New data type
LoadHelpersContextError
has been added. Ensure that all error handling code has been updated to handle this new type of error.270-274: New data type
Destination
has been added. This is a good practice as it makes the code more readable and maintainable.278-280: The
Mint
data type has been updated to use the newDestination
type. This is a breaking change and all uses of theMint
type should be updated accordingly.285-289: A new constructor
RoleTokensUsePolicyWithOpenRoles
has been added to theRoleTokensConfig
data type. Ensure that all code that usesRoleTokensConfig
has been updated to handle this new constructor.886-887: A new constructor
InvalidHelperDatum
has been added to theConstraintError
data type. Ensure that all error handling code has been updated to handle this new type of error.896-897: A new error
HelperScriptNotFound
has been added. Ensure that all error handling code has been updated to handle this new type of error.910-917: A new constructor
CreateLoadHelpersContextFailed
has been added to theCreateError
data type. Ensure that all error handling code has been updated to handle this new type of error.939-940: A new constructor
ApplyInputsLoadHelpersContextFailed
has been added to theApplyInputsError
data type. Ensure that all error handling code has been updated to handle this new type of error.962-963: A new constructor
WithdrawLoadHelpersContextFailed
has been added to theWithdrawError
data type. Ensure that all error handling code has been updated to handle this new type of error.982-990: New data type
LoadHelpersContextError
with several constructors has been added. This is a good practice as it makes the code more readable and maintainable.marlowe-runtime/tx/Language/Marlowe/Runtime/Transaction/Query/Helper.hs (1)
- 1-278: The new module
Language.Marlowe.Runtime.Transaction.Query.Helper
seems to be well-structured and follows Haskell best practices. It introduces new types and functions for managing helper scripts in the Marlowe runtime. However, there are a few points to consider:
- In line 122, there's a TODO comment. Ensure that this is addressed or tracked in your project management tool.
- In line 194, there's a comment about silently ignoring script output without exactly one role token. This could potentially lead to unexpected behavior. Consider adding logging or some form of notification for these cases.
- In line 158, 166, 204, 218, 226, 244, and 250, there are error handling cases where the function returns an error. Ensure that these errors are properly handled in the calling code.
- In line 267, the function
fromJust
is used which can cause a runtime error if the Maybe value is Nothing. Consider using a safer alternative like pattern matching or themaybe
function to handle the Nothing case.marlowe-runtime/changelog.d/20231024_132111_brian.bush_PLT_7111.md (1)
- 1-3: The changelog update is clear and concise, providing a good summary of the new feature.
marlowe-runtime-web/server/Language/Marlowe/Runtime/Web/Server/REST/ApiError.hs (4)
120-123: New error handling for
WithdrawLoadHelpersContextFailed
has been added. Ensure that this error is properly handled in all places whereWithdrawError
is used.139-143: New error handling for
RequiresSingleThreadToken
andCreateLoadHelpersContextFailed
has been added. Ensure that these errors are properly handled in all places whereCreateError
is used.155-158: New error handling for
ApplyInputsLoadHelpersContextFailed
has been added. Ensure that this error is properly handled in all places whereApplyInputsError
is used.166-172: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [169-178]
New error cases
InvalidHelperDatum
andHelperScriptNotFound
have been added tostatusCodeConstraintError
. Ensure that these errors are properly handled in all places whereConstraintError
is used.marlowe-integration-tests/test/Language/Marlowe/Runtime/Integration/ApplyInputs.hs (1)
- 1040-1040: The change seems to be correct, but ensure that the
changeAddress
function is returning the expected results and that theToAddress
constructor is being used correctly. Also, make sure that theaddresses
field is correctly populated.- mkRoleTokens = RoleTokensMint . mkMint . (fmap . fmap) ((,Nothing) . ToAddress . changeAddress . addresses) . NE.fromList + mkRoleTokens = RoleTokensMint . mkMint . (fmap . fmap) ((,Nothing) . ToAddress . changeAddress . addresses) . NE.fromListmarlowe/src/Language/Marlowe/Analysis/Safety/Ledger.hs (2)
298-316: The
worstValue
function has been updated to take an additionalMaybe State
parameter. If the state is provided, it uses the account balances from the state to calculate the worst-case value. This change is logical and should improve the accuracy of the worst-case value calculation. However, ensure that all calls to this function throughout the codebase have been updated to match the new signature.318-339: The
worstTxOut
function has been updated to take an additionalMaybe State
parameter. If the state is provided, it uses the account balances from the state to calculate the worst-case value for the transaction output. This change is logical and should improve the accuracy of the worst-case transaction output calculation. However, ensure that all calls to this function throughout the codebase have been updated to match the new signature.marlowe-runtime-web/src/Language/Marlowe/Runtime/Web/Orphans.hs (2)
579-579: The change in the type of
transactionSchema
toV1.Transaction ()
seems to be in line with the changes in theTransaction
data type. Ensure that this change is propagated correctly throughout the codebase.633-633: The change in the type signature of the
ToSchema
instance forV1.Transaction
to(V1.Transaction ())
is consistent with the changes in theTransaction
data type. Make sure that all uses of this instance are updated accordingly.marlowe-runtime/tx/Language/Marlowe/Runtime/Transaction/BuildConstraints.hs (8)
11-12: The
initialMarloweState
function is added to the export list. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.81-94: The
HelperScript
data type is imported from theLanguage.Marlowe.Runtime.Core.ScriptRegistry
module. TheCreateBuildupError
data type is updated to include new error typesAddressDecodingFailed
,MintingScriptDecodingFailed
, andMintingUtxoSelectionFailed
.155-161: The
buildCreateConstraints
function now takes an additional parameteradjustMinUtxo
and returns an additional valuePolicyId
. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.184-190: The
buildCreateConstraintsV1
function now takes an additional parameteradjustMinUtxo
. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.225-230: The
sendMarloweOutput
function is updated to use the newinitialMarloweStateV1
function.222-256: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [241-288]
The
mintRoleTokens
function is updated to handle the newRoleTokensConfig
data types. Ensure that all calls to this function throughout the codebase have been updated to match the new logic.
296-309: The
sendOpenRoleOutputs
function is added to handle open roles. Ensure that all calls to this function throughout the codebase have been updated to match the new logic.323-370: The
initialMarloweState
andinitialMarloweStateV1
functions are added to calculate the initial Marlowe state based on the provided parameters. Ensure that all calls to these functions throughout the codebase have been updated to match the new logic.marlowe-cli/src/Language/Marlowe/CLI/Analyze.hs (1)
- 603-607: The argument type of the
checkTransactionSize
function is changed toTransaction ()
. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.marlowe/src/Language/Marlowe/Analysis/Safety/Types.hs (4)
7-15: The added language extensions
FlexibleInstances
andNamedFieldPuns
are generally safe to use and can improve code readability and flexibility. Ensure that they are used appropriately throughout the module.19-23: The function
stripAnnotation
is added to the module's exports. This function is used to remove the annotation from aTransaction
. This is a good practice as it allows for more modular code.91-103: The constructors
TransactionSizeMayExceedProtocol
,TransactionCostMayExceedProtocol
,TransactionValidationError
, andTransactionWarning
of theSafetyError
data type have been modified to useTransactionWithoutAnnotation
instead ofTransaction
. This change is logical as it allows for more precise error handling, specifically in cases where the annotation of a transaction is not relevant to the error.372-400: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [354-416]
The
Transaction
data type has been modified to include an annotation field. This is a good practice as it allows for more detailed transactions. TheToJSON
andFromJSON
instances forTransaction
have been updated to handle the annotation field. The functionstripAnnotation
has been added to remove the annotation from aTransaction
. This function is useful in cases where the annotation is not needed. The type aliasTransactionWithoutAnnotation
has been defined forTransaction ()
, which represents a transaction without an annotation.marlowe-runtime/src/Language/Marlowe/Runtime/Core/Api.hs (1)
- 579-579: The change to the
Binary
instance forV1.Transaction
allows for more flexibility, as it can now handle any typea
that is also an instance ofBinary
. However, ensure that this change doesn't introduce any unintended side effects, especially when serializing and deserializingV1.Transaction
objects in the rest of the codebase.marlowe-runtime/test/Language/Marlowe/Runtime/Core/ScriptRegistrySpec.hs (3)
5-11: The new import statement for
Data.Map.Strict
is appropriate for the use ofMap
in the code.24-28: The
helperScriptUTxOs
field is initialized tomempty
. Ensure that this is the intended behavior and that it doesn't cause any issues in the rest of the code.38-52: The test case "Should specify the correct current scripts" has been updated to include the handling of
helperScripts
. ThehelperScripts
map is populated with a single entry for theOpenRoleScript
key, using thehashScript
function on theopenRoleScriptBytes
. ThecurrentScripts'
data structure is updated to include thehelperScripts
andhelperScriptUTxOs
fields. The test then checks ifcurrentScripts
is equal tocurrentScripts'
.marlowe-runtime/src/Language/Marlowe/Runtime/Core/ScriptRegistry.hs (3)
45-49: The addition of
helperScripts
andhelperScriptUTxOs
fields to theMarloweScripts
data type is consistent with the PR summary. Ensure that these fields are used appropriately in the rest of the codebase.52-54: The
HelperScript
data type with a single constructorOpenRoleScript
is consistent with the PR summary. Ensure that this type is used appropriately in the rest of the codebase.81-87: The
helperScripts
field is being initialized with aMap
containing a singleOpenRoleScript
entry. This is consistent with the PR summary.99, 113, 127, 146, 160, 174, 190:
Thescript
field is being initialized with a call todeserialiseFromCBOR
. This function call includes an error case that will crash the program if deserialization fails. Consider replacing this with a safer error handling mechanism, such as returning anEither
type or throwing a custom exception that can be caught and handled at a higher level in the program.- script = either (error . show) id $ deserialiseFromCBOR (AsPlutusScript AsPlutusScriptV2) currentV1MarloweScriptCBOR + script = case deserialiseFromCBOR (AsPlutusScript AsPlutusScriptV2) currentV1MarloweScriptCBOR of + Left err -> throw (DeserializationError err) + Right script -> scriptmarlowe-integration-tests/test/Language/Marlowe/Runtime/CliSpec.hs (2)
60-66: The import statements are updated to include the new
Destination
type and its constructorToAddress
. This change is consistent with the updates in the rest of the code.60-66: > Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [602-608]
The
mkMint
function call is updated to wrap thechangeAddress
value withToAddress
. This change is consistent with the introduction of theDestination
type. Ensure that themkMint
function and thechangeAddress
function are updated to handle this change correctly.marlowe-runtime/test/Language/Marlowe/Runtime/Transaction/ConstraintsSpec.hs (7)
66-66: The import of
Destination
data type fromLanguage.Marlowe.Runtime.Transaction.Api
is new. Ensure that it is used in the code and is not an unnecessary import.129-129: The
HelpersContext
is being passed to a function. Ensure that the function has been updated to handle this new argument.362-362: The
helpersContext
variable is being defined. Ensure that it is used in the code and is not an unused variable.843-843: The
helpersContext
is being passed to a function. Ensure that the function has been updated to handle this new argument.739-739: The
helpersContext
variable is being defined. Ensure that it is used in the code and is not an unused variable.1150-1150: The
ToAddress
constructor is being used for address comparison. Ensure that this is the correct way to compare addresses in your codebase.1424-1424: The
ToAddress
constructor is being used for address generation. Ensure that this is the correct way to generate addresses in your codebase.marlowe-runtime/tx/Language/Marlowe/Runtime/Transaction/Safety.hs (5)
4-4: The addition of the
ViewPatterns
language extension. This extension allows pattern matching on the result of a function application. It can make the code more readable and concise, but it can also make it more difficult to understand for those unfamiliar with the extension. Ensure that its usage is justified and well-documented.162-176: The
minAdaUpperBound
function has been modified to useworstValue
instead ofworstMinimumUtxo'
and to handle assets. This change seems to be in line with the overall goal of handling helper scripts and open roles. However, it's important to ensure that the new function behaves as expected in all scenarios, especially edge cases.177-193: The addition of the
mkAdjustMinimumUtxo
function to adjust the ada in aTxOut
to satisfy the minimum UTxO ledger rule. This function seems to be a necessary addition to handle the new requirements of the system. However, it's important to ensure that it behaves as expected in all scenarios, especially edge cases.281-318: The
checkTransactions
function has been modified to include theHelpersContext
and handle helper scripts. This change seems to be in line with the overall goal of handling helper scripts and open roles. However, it's important to ensure that the new function behaves as expected in all scenarios, especially edge cases.389-418: The addition of the
helpersForRoles
function to create a helpers context for specified helper roles. This function seems to be a necessary addition to handle the new requirements of the system. However, it's important to ensure that it behaves as expected in all scenarios, especially edge cases.marlowe-runtime/tx/Language/Marlowe/Runtime/Transaction/Server.hs (13)
9-9: The
ViewPatterns
language extension has been added. Ensure that it is used appropriately in the code.107-113: New data types
Destination
,Mint
, andRoleTokensConfig
have been exported. Ensure that they are used correctly in the rest of the codebase.137-143: The
LoadHelpersContext
type andmkAdjustMinimumUtxo
function have been imported. Ensure that they are used correctly in the rest of the codebase.184-184: The
loadHelpersContext
field has been added to theTransactionServerDependencies
data type. Ensure that it is initialized correctly whereverTransactionServerDependencies
is instantiated.587-587: The
loadHelpersContext
parameter has been added to several functions. Ensure that it is passed correctly wherever these functions are called.318-329: The
mkAdjustMinimumUtxo
function is used to adjust the minimum UTXO. Ensure that this adjustment is correct and does not lead to any issues with transaction validation.342-343: The
minAdaUpperBound
function is used to calculate the minimum Ada deposit. Ensure that this calculation is correct and does not lead to any issues with transaction validation.356-356: The
adjustMinUtxo
function is used in thebuildCreateConstraints
function. Ensure that this adjustment is correct and does not lead to any issues with transaction validation.387-400: The
loadHelpersContext
function is used to load the helpers context, and thethreadRole
variable is set based on theroleTokens
parameter. Ensure that these operations are correct and do not lead to any issues with transaction execution.417-428: The
solveConstraints
function is used to solve transaction constraints. Ensure that this operation is correct and does not lead to any issues with transaction validation.588-588: The
loadHelpersContext
parameter has been added to theexecApplyInputs
andexecWithdraw
functions. Ensure that it is passed correctly wherever these functions are called.598-598: The
loadHelpersContext
function is used to load the helpers context. Ensure that this operation is correct and does not lead to any issues with transaction execution.602-602: The
solveConstraints
function is used to solve transaction constraints. Ensure that this operation is correct and does not lead to any issues with transaction validation.marlowe/src/Language/Marlowe/Analysis/Safety/Transaction.hs (11)
18-18: The
TupleSections
language extension is added. This extension allows for partial application of tuple constructors. Ensure that this extension is used appropriately in the code.36-39: Two new functions
unitAnnotator
andfirstRoleAuthorizationAnnotator
are added to the module exports. Ensure that these functions are used correctly in the rest of the codebase.118-122: The
executeTransaction
function now includes an additional type parametera
. This change will affect all calls to this function. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.259-265: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [262-271]
The
calcMarloweTxExBudget
function now includes an additional type parametera
. This change will affect all calls to this function. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.
553-555: The
foldTransactionsM
function now includes an additional type parametera
. This change will affect all calls to this function. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.564-591: The
findTransactions
function now includes an additional type parametera
. This change will affect all calls to this function. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.594-615: The
findTransactions'
function now includes an additional type parametera
. This change will affect all calls to this function. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.627-631: The
findTransactionPath
function now includes an additional type parametera
. This change will affect all calls to this function. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.669-673: The
findPaths
function now includes an additional type parametera
. This change will affect all calls to this function. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.692-696: The
unitAnnotator
function is added. This function does not annotate the transactions and returns a tuple of the transaction and unit. Ensure that this function is used correctly in the rest of the codebase.699-715: The
firstRoleAuthorizationAnnotator
function is added. This function annotates the transactions with the roles that are used for the first time to authorize a transaction. Ensure that this function is used correctly in the rest of the codebase.marlowe-runtime/tx/Language/Marlowe/Runtime/Transaction/Constraints.hs (23)
11-14: New data types related to helper scripts are being exported. Ensure that these are being used correctly throughout the codebase.
31-31: A new function
mustSendHelperOutput
is being exported. Ensure that this function is being used correctly throughout the codebase.65-65: The
Data.Maybe
module is being imported with additional functions. Ensure that these new functions are being used correctly throughout the codebase.74-74: The
fromCardanoDatumHash
function is being imported. Ensure that this function is being used correctly throughout the codebase.84-84: The
toCardanoTxOutDatum'
function is being imported. Ensure that this function is being used correctly throughout the codebase.105-107: New imports related to helper scripts are being added. Ensure that these new imports are being used correctly throughout the codebase.
119-119: The
TxConstraints
data type now includes ahelperOutputConstraints
field to specify constraints for helper script outputs. Ensure that this new field is being used correctly throughout the codebase.157-159: The
mustMintRoleToken
function now accepts aDestination
parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.188-193: The
HelperOutputConstraints
data type is being introduced. Ensure that this new data type is being used correctly throughout the codebase.224-228: The
mustSendHelperOutput
function is being introduced. Ensure that this new function is being used correctly throughout the codebase.318-318: The
helperOutputConstraints
field is being used in theMonoid
instance forTxConstraints
. Ensure that this field is being used correctly throughout the codebase.337-337: The
helperOutputConstraints
field is being used in theMonoid
instance forTxConstraints
. Ensure that this field is being used correctly throughout the codebase.379-417: New data types and instances related to helper scripts are being introduced. Ensure that these new data types and instances are being used correctly throughout the codebase.
435-440: The
solveConstraints
function now takes aHelpersContext
parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.624-635: The
selectCoins
function now takes aHelpersContext
parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.842-843: The
balanceTx
function now takes aHelpersContext
parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.900-900: The
allUtxos
function now takes aHelpersContext
parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.955-962: The
toCardanoTxOutDatum'
function is being used. Ensure that this function is being used correctly.973-992: The
allUtxos
function has been updated to handle helper scripts. Ensure that this function is being used correctly throughout the codebase.1001-1005: The
solveInitialTxBodyContent
function now takes aHelpersContext
parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.1067-1080: The
getWalletInputs
function has been updated to handle helper scripts. Ensure that this function is being used correctly throughout the codebase.1224-1269: New functions related to helper scripts are being introduced. Ensure that these new functions are being used correctly throughout the codebase.
1279-1309: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [1282-1340]
The
solveTxOuts
function has been updated to handle helper scripts. Ensure that this function is being used correctly throughout the codebase.
let roles' = | ||
if M.null roles | ||
then RoleTokensNone | ||
else RoleTokensMint . mkMint . fmap (second (,Nothing)) . NE.fromList . M.toList $ roles | ||
else RoleTokensMint . mkMint . fmap (second $ (,Nothing) . ToAddress) . NE.fromList . M.toList $ roles |
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.
The buildCreation
function has been updated to handle the case where the roles
map is empty. If it is, RoleTokensNone
is used. Otherwise, the RoleTokensMint
constructor is used with the mkMint
function applied to the transformed roles
map. The transformation involves converting the map to a list, wrapping it in a NonEmpty
list, and then mapping over it to apply the ToAddress
function to the second element of each tuple in the list. This is a complex operation and might be difficult to understand for someone unfamiliar with the code. Consider adding a comment explaining what this operation does.
-- If the roles map is not empty, we convert each role's address to a 'Destination' type
-- and prepare it for minting role tokens.
let roles' =
if M.null roles
then RoleTokensNone
else RoleTokensMint . mkMint . fmap (second $ (,Nothing) . ToAddress) . NE.fromList . M.toList $ roles
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.
That is not right, the empty case was already handled before the PR, the result type of roles'
is RoleTokensConfig
, and the result of the fmap
is a NonEmpty (TokenName, (Address, Maybe RoleTokenMetadata))
, there is no Destination
type anywhere
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.
@palas Thank you for your correction. I apologize for the confusion. You're right, the fmap
operation is producing a NonEmpty (TokenName, (Address, Maybe RoleTokenMetadata))
, not a Destination
. The ToAddress
function is used to convert the Address
associated with each TokenName
in the roles
map into the appropriate format for the RoleTokensMint
constructor. The comment should be corrected as follows:
-- If the roles map is not empty, we convert each role's address to the appropriate format
-- and prepare it for minting role tokens.
let roles' =
if M.null roles
then RoleTokensNone
else RoleTokensMint . mkMint . fmap (second $ (,Nothing) . id) . NE.fromList . M.toList $ roles
I appreciate your patience and understanding.
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.
That's also incorrect. There is in fact there a Destination
type and the fmap
produces a NonEmpty (TokenName, (Destination, Maybe RoleTokenMetadata))
. ToAddress
is a data constructor of the Destination
type which has the type signature ToAddress :: Address -> Destination
.
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.
Huh, thanks
configMap <- ExceptT $ liftIO $ first RolesConfigFileDecodingError <$> A.eitherDecodeFileStrict roleTokensConfigFilePath | ||
case Map.toList configMap of | ||
[] -> throwE $ RolesConfigFileDecodingError "Empty role token config" | ||
(x : xs) -> pure $ RoleTokensMint $ mkMint $ fmap (\RoleConfig{..} -> (address, Just metadata)) <$> x :| xs | ||
(x : xs) -> pure $ RoleTokensMint $ mkMint $ fmap (\RoleConfig{..} -> (ToAddress address, Just metadata)) <$> x :| xs |
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.
The code reads a configuration file and throws an error if it's empty. It's a good practice to validate external inputs. However, consider adding more specific error messages to help with debugging.
- [] -> throwE $ RolesConfigFileDecodingError "Empty role token config"
+ [] -> throwE $ RolesConfigFileDecodingError "The role token configuration file is empty."
Commitable suggestion (Beta)
configMap <- ExceptT $ liftIO $ first RolesConfigFileDecodingError <$> A.eitherDecodeFileStrict roleTokensConfigFilePath | |
case Map.toList configMap of | |
[] -> throwE $ RolesConfigFileDecodingError "Empty role token config" | |
(x : xs) -> pure $ RoleTokensMint $ mkMint $ fmap (\RoleConfig{..} -> (address, Just metadata)) <$> x :| xs | |
(x : xs) -> pure $ RoleTokensMint $ mkMint $ fmap (\RoleConfig{..} -> (ToAddress address, Just metadata)) <$> x :| xs | |
configMap <- ExceptT $ liftIO $ first RolesConfigFileDecodingError <$> A.eitherDecodeFileStrict roleTokensConfigFilePath | |
case Map.toList configMap of | |
[] -> throwE $ RolesConfigFileDecodingError "The role token configuration file is empty." | |
(x : xs) -> pure $ RoleTokensMint $ mkMint $ fmap (\RoleConfig{..} -> (ToAddress address, Just metadata)) <$> x :| xs |
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 meant to comment this days ago... apparently I never submitted the review!
marlowe-runtime/gen/Language/Marlowe/Runtime/Transaction/Gen.hs
Outdated
Show resolved
Hide resolved
marlowe-runtime/gen/Language/Marlowe/Runtime/Transaction/Gen.hs
Outdated
Show resolved
Hide resolved
marlowe-runtime/test/Language/Marlowe/Runtime/Transaction/BuildConstraintsSpec.hs
Outdated
Show resolved
Hide resolved
marlowe-runtime/tx/Language/Marlowe/Runtime/Transaction/Constraints.hs
Outdated
Show resolved
Hide resolved
1. Runtime was miscalculating Plutus execution costs because the UTxO set listed the Marlowe output as having inline datum instead of a datum hash. 2. All of the balancing checks, trial Plutus executions, safety analyses, etc. passed because they were based on the erroneous UTxO set. 3. However, when the Cardano node builds the UTxO set, it rightly uses `TxDatumHash` instead of the erroneous `TxDatumInLine` (since we are embedding the datum in Marlowe output not inlining it). 4. Thus, when the node executes the transaction before submitting it, the Plutus costs are slightly different than calculated when Runtime built the transaction (due to the `ScriptContext` being slightly different). a. It turns out that Runtime would overestimate the execution cost when running just the Marlowe validator, so we never noticed this previously. b. Unfortunately, Runtime would underestimate the execution cost when running the open-roles validator, so the transaction fails upon submission. This fix simply uses `TxDatumHash` in the UTxO set for balancing instead of `TxDatumInLine`.
Co-authored-by: Olof Blomqvist <[email protected]>
Co-authored-by: Jamie Bertram <[email protected]>
Pre-submit checklist:
Summary by CodeRabbit
New Features:
Refactor:
MarloweScripts
data type and added new types and functions related to helper scripts, enhancing script management.Tests:
Documentation: