Skip to content

feat(canton): integrate Canton support#613

Open
RodrigoAD wants to merge 28 commits into
mainfrom
canton-main
Open

feat(canton): integrate Canton support#613
RodrigoAD wants to merge 28 commits into
mainfrom
canton-main

Conversation

@RodrigoAD
Copy link
Copy Markdown
Member

No description provided.

- Adds Canton configurer implementation, unit and e2e tests
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 6, 2026

⚠️ No Changeset found

Latest commit: b1fc944

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment thread sdk/canton/resolver.go Fixed
JohnChangUK and others added 5 commits April 7, 2026 22:57
## Desc
Resolve targetCids execution time

- Added TargetTemplateID field to AdditionalFields
- Added ResolveTargetContractID resolver function
- Updated `TimelockExecutor.Execute` and `Executor.ExecuteOperation` for
auto-resolution
Comment thread sdk/canton/resolver.go Fixed
Comment thread sdk/canton/resolver.go Fixed
Comment thread sdk/canton/resolver.go Fixed
stackman27 and others added 3 commits May 20, 2026 23:18
Resolve go.mod/go.sum conflicts by keeping main dependency updates
alongside Canton-specific modules (chainlink-canton, go-daml, dazl-client,
chainlink-deployments-framework).

Co-authored-by: Cursor <cursoragent@cursor.com>
@stackman27 stackman27 changed the title [WIP] Canton integration feat(canton): integrate Canton support May 28, 2026
@stackman27 stackman27 marked this pull request as ready for review May 28, 2026 03:22
@stackman27 stackman27 requested a review from a team as a code owner May 28, 2026 03:22
Copilot AI review requested due to automatic review settings May 28, 2026 03:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Integrates Canton (Daml-based) chain support into MCMS by adding a new sdk/canton package implementing the Encoder/Inspector/Executor/Configurer/Timelock interfaces against the chainlink-canton bindings, wiring Canton into the factory, validation, chain selectors, and chain-wrapper builders, and adding an e2e test suite plus task entry.

Changes:

  • New sdk/canton package: Merkle hashing matching the Daml Crypto.daml layout, MCMS/timelock SetConfig/SetRoot/Execute/Schedule/Cancel/Bypass, InstanceAddress→contract-ID resolver, and metadata inference for timelock proposal conversion.
  • Wire Canton into shared infrastructure: factory.go, validation.go, types/chain_selector.go, timelock_proposal.go (Canton-only EnsureChainMetadata step), chainwrappers/* (new CantonChain accessor + mock), go.mod deps + replace directives.
  • New e2e/tests/canton suite (configurer, inspector, timelock proposal/cancel/bypass, set-root/execute) and e2e:canton task.

Reviewed changes

Copilot reviewed 38 out of 40 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
validation.go Adds Canton case to validateChainMetadata (per-tx validator not wired).
types/chain_selector.go Adds FamilyCanton to supported families.
timelock_proposal.go Adds Canton-only EnsureChainMetadata step during Convert.
factory.go Registers Canton encoder and OperationID.
go.mod Adds Canton/Daml deps and replace directives.
taskfiles/test/Taskfile.yml Adds e2e:canton task.
sdk/canton/chain_metadata.go Defines TimelockRole, AdditionalFieldsMetadata, and NewChainMetadata.
sdk/canton/chain_metadata_infer.go Infers metadata using hard-coded instance ID candidates and default chain id 1.
sdk/canton/chain_metadata_infer_test.go Unit test for inference happy path.
sdk/canton/encoder.go Merkle leaf hashing with domain separators and length prefixes.
sdk/canton/configurer.go SetConfig against MCMS contract; sets Hash to a literal "tx.Digest".
sdk/canton/inspector.go Reads config/op count/root/root metadata; converts MultisigConfig to types.Config.
sdk/canton/inspector_test.go E2E-tagged unit tests for toConfig hierarchy.
sdk/canton/executor.go ExecuteOperation/SetRoot; manual map-based metadata parsing; value receivers; dead PadLeft32.
sdk/canton/timelock_converter.go Schedule/Bypass/Cancel encoding and OperationID.
sdk/canton/timelock_crypto.go HashTimelockOpId matching Daml hashing.
sdk/canton/timelock_executor.go ExecuteScheduledBatch submission.
sdk/canton/timelock_inspector.go Read-only choices (IsOperation*, GetMinDelay) and role getters.
sdk/canton/resolver.go Resolves InstanceAddress hex to active contract ID.
sdk/canton/helpers.go Template ID parsing/formatting and constants.
chainwrappers/chainaccessor.go Adds CantonChain(selector) and fixes a Sui alias.
chainwrappers/mocks/chain_accessor.go Generated CantonChain mock.
chainwrappers/converters.go Canton converter case.
chainwrappers/inspectors.go Canton inspector case + cantonRole helper.
chainwrappers/executors.go Canton executor case (requires *cantonsdk.Encoder).
chainwrappers/timelock_executors.go Canton timelock executor case.
e2e/tests/setup.go Adds CantonChain config and CantonBlockchain to shared setup.
e2e/tests/runner_test.go Registers TestCantonSuite.
e2e/config.canton.toml Canton e2e config.
e2e/tests/canton/* New e2e suites; timelock_cancel.go contains a non-compiling salt expression.
Files not reviewed (1)
  • chainwrappers/mocks/chain_accessor.go: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

AddChainMetadata(s.chainSelector, cancellerMetadata).
SetAction(types.TimelockActionCancel).
SetDelay(delay).
SetSalt((*common.Hash)(new(scheduleProposal.Salt()))).
Comment thread sdk/canton/configurer.go
}

return types.TransactionResult{
Hash: "tx.Digest",
Comment thread sdk/canton/executor.go
Comment on lines +259 to +279
var additionalFields map[string]any
if unmarshalErr := json.Unmarshal(metadata.AdditionalFields, &additionalFields); unmarshalErr != nil {
return types.TransactionResult{}, fmt.Errorf("failed to unmarshal additional fields: %w", unmarshalErr)
}

// Extract fields with type assertions
if chainId, ok := additionalFields["chainId"].(float64); ok {
rootMetadata.ChainId = cantontypes.INT64(int64(chainId))
}
if multisigId, ok := additionalFields["multisigId"].(string); ok {
rootMetadata.MultisigId = cantontypes.TEXT(multisigId)
}
if preOpCount, ok := additionalFields["preOpCount"].(float64); ok {
rootMetadata.PreOpCount = cantontypes.INT64(int64(preOpCount))
}
if postOpCount, ok := additionalFields["postOpCount"].(float64); ok {
rootMetadata.PostOpCount = cantontypes.INT64(int64(postOpCount))
}
if overridePreviousRoot, ok := additionalFields["overridePreviousRoot"].(bool); ok {
rootMetadata.OverridePreviousRoot = cantontypes.BOOL(overridePreviousRoot)
}
Comment thread validation.go
Comment on lines +61 to +62
case chainsel.FamilyCanton:
return canton.ValidateChainMetadata(metadata)
Comment thread sdk/canton/executor.go
Comment on lines +367 to +374

func PadLeft32(hexStr string) string {
if len(hexStr) >= hexWordLen {
return hexStr[:hexWordLen]
}

return strings.Repeat("0", hexWordLen-len(hexStr)) + hexStr
}
Comment thread sdk/canton/executor.go
}, nil
}

func (e Executor) ExecuteOperation(
Comment on lines +14 to +16
// defaultMCMSInstanceIDCandidates are common Canton MCMS instance IDs tried when inferring
// chain metadata from mcmAddress + party (e.g. proposals generated without additionalFields).
var defaultMCMSInstanceIDCandidates = []string{"mcms-ccip", "mcms-ccv", "mcms"}
return fields, nil
}

const defaultCantonChainID int64 = 1
Comment thread chainwrappers/chainaccessor.go Outdated
Copy link
Copy Markdown
Contributor

@gustavogama-cll gustavogama-cll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitting a few thoughts after a shallow initial pass because I think there is one request (the last comment) that might require a bigger refactoring.

Comment thread chainwrappers/executors.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see canton changes to the chainwrappers/executors_test.go in this PR, nor in #628.

Comment thread chainwrappers/inspectors.go Outdated
Comment thread chainwrappers/inspectors.go Outdated
}
}

func cantonRole(action types.TimelockAction) cantonsdk.TimelockRole {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please move this to the sdk/canton package (like aptos does it)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to canton sdk package under canton_helpers.go

Comment thread chainwrappers/timelock_executors.go Outdated
return nil, fmt.Errorf("missing Canton chain participant for selector %d", rawSelector)
}
participant := ch.Participants[0]
mcmsParties := make([]string, len(ch.Participants))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: lo.Map

Comment thread timelock_proposal.go Outdated
return Proposal{}, nil, fmt.Errorf("missing chain metadata for chainSelector %d", chainSelector)
}

family, err := types.GetChainSelectorFamily(chainSelector) //nolint:contextcheck //OPT-400
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't need any chain-specific logic here. And we shouldn't be adding to the chain metadata at runtime -- these attributes should be specified by the user when building the proposal.

I took a peek at what "EnsureChainMetadata" does and it seems that at least the attributes that are related to mcms can be computed or retrieved without the need to have them in the chain metadata.

Let's try to keep the "timelock_proposal.Convert" method intact -- if you are unsure about to work around it, let me know and we can iterate.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed and updated. Now users are expected to supply complete chain metadata when building the proposal

Copilot AI review requested due to automatic review settings May 29, 2026 21:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 43 changed files in this pull request and generated 6 comments.

Files not reviewed (1)
  • chainwrappers/mocks/chain_accessor.go: Language not supported

AddChainMetadata(s.chainSelector, cancellerMetadata).
SetAction(types.TimelockActionCancel).
SetDelay(delay).
SetSalt((*common.Hash)(new(scheduleProposal.Salt()))).
Comment thread sdk/canton/configurer.go
}

return types.TransactionResult{
Hash: "tx.Digest",
Comment thread validation.go
Comment on lines +61 to +62
case chainsel.FamilyCanton:
return canton.ValidateChainMetadata(metadata)
Comment on lines +139 to +152
case chainsel.FamilyCanton:
ch, ok := chains.CantonChain(rawSelector)
if !ok || len(ch.Participants) == 0 {
return nil, fmt.Errorf("missing Canton chain participant for selector %d", rawSelector)
}
participant := ch.Participants[0]
mcmsParties := lo.Map(ch.Participants, func(p cantonsdk.Participant, _ int) string { return p.PartyID })

return cantonsdk.NewTimelockExecutor(
participant.LedgerServices.Command,
participant.LedgerServices.State,
participant.PartyID,
mcmsParties,
), nil
Comment thread sdk/canton/executor.go
Comment on lines +368 to +374
func PadLeft32(hexStr string) string {
if len(hexStr) >= hexWordLen {
return hexStr[:hexWordLen]
}

return strings.Repeat("0", hexWordLen-len(hexStr)) + hexStr
}
Comment thread sdk/canton/configurer.go
Comment on lines +79 to +114
// Build exercise command using generated bindings
mcmsContract := mcmscore.MCMS{}
exerciseCmd := mcmsContract.SetConfig(mcmsContractID, input)

// Parse template ID
packageID, moduleName, entityName, err := parseTemplateIDFromString(mcmsContract.GetTemplateID())
if err != nil {
return types.TransactionResult{}, fmt.Errorf("failed to parse template ID: %w", err)
}

// Convert input to choice argument
choiceArgument := ledger.MapToValue(input)

commandID := uuid.Must(uuid.NewUUID()).String()
submitResp, err := c.client.SubmitAndWaitForTransaction(ctx, &apiv2.SubmitAndWaitForTransactionRequest{
Commands: &apiv2.Commands{
WorkflowId: "mcms-set-config",
CommandId: commandID,
ActAs: []string{c.mcmsParties[0]},
ReadAs: c.mcmsParties,
Commands: []*apiv2.Command{{
Command: &apiv2.Command_Exercise{
Exercise: &apiv2.ExerciseCommand{
TemplateId: &apiv2.Identifier{
PackageId: packageID,
ModuleName: moduleName,
EntityName: entityName,
},
ContractId: exerciseCmd.ContractID,
Choice: exerciseCmd.Choice,
ChoiceArgument: choiceArgument,
},
},
}},
},
})
Copilot AI review requested due to automatic review settings May 31, 2026 16:31
@cl-sonarqube-production
Copy link
Copy Markdown

Quality Gate failed Quality Gate failed

Failed conditions
7.4% Coverage on New Code (required ≥ 75%)

See analysis details on SonarQube

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants