Skip to content

[CLD-2461]: feat(datastore): new WriteMetadata util#1007

Open
graham-chainlink wants to merge 1 commit into
mainfrom
ggoh/CLD-2461/datastore-util
Open

[CLD-2461]: feat(datastore): new WriteMetadata util#1007
graham-chainlink wants to merge 1 commit into
mainfrom
ggoh/CLD-2461/datastore-util

Conversation

@graham-chainlink
Copy link
Copy Markdown
Collaborator

@graham-chainlink graham-chainlink commented May 26, 2026

Chainlink CCIP tooling api provides WriteMetadataToDatastore util, this is heavily used in their changets.

I have integrated this into the datastore package with the MutableDatastore and added the ability to add addresses as well as that is a common pattern.

JIRA: https://smartcontract-it.atlassian.net/browse/CLD-2461

@graham-chainlink graham-chainlink requested a review from Copilot May 26, 2026 05:02
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 26, 2026

⚠️ No Changeset found

Latest commit: ff3fcbf

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

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

Adds a WriteMetadata utility to the datastore package to simplify writing common deployment artifacts (address refs, contract metadata, chain metadata, env metadata) into a mutable in-memory datastore.

Changes:

  • Introduces a new Metadata struct and (*MemoryDataStore).WriteMetadata(...) helper for writing/upserting multiple datastore record types.
  • Adds unit tests covering no-op behavior, address duplicate handling, and upsert overwrites.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
datastore/memory_datastore.go Adds Metadata and WriteMetadata helper to write/upsert datastore records in one call.
datastore/memory_datastore_test.go Adds test coverage for WriteMetadata behavior (no-op, duplicates, overwrites).

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

Comment thread datastore/memory_datastore.go Outdated
Comment thread datastore/memory_datastore.go Outdated
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 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread datastore/memory_datastore.go
Comment thread datastore/memory_datastore.go Outdated
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 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread datastore/memory_datastore.go Outdated
Chainlink CCIP tooling api provides [WriteMetadataToDatastore util](https://github.com/smartcontractkit/chainlink-ccip/blob/298ed1c38d5cda61a688beb2494a96a5409daf3d/deployment/utils/sequences/sequences.go#L76), this is heavily used in their changets.

I have integrated this into the datastore package with the MutableDatastore and added the ability to add addresses as well as that is a common pattern.

JIRA: https://smartcontract-it.atlassian.net/browse/CLD-2461
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 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread datastore/write_metadata.go
@cl-sonarqube-production
Copy link
Copy Markdown

Quality Gate failed Quality Gate failed

Failed conditions
70.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube

}

// WriteMetadataToDatastore adds address refs and upserts contract and chain metadata and sets env metadata.
func WriteMetadataToDatastore(ds MutableDataStore, bundle MetadataBundle) error {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Instead of extending the interface of MutableDataStore to include WriteMetadata, i just introduce a helper function here so any variable of type MutableDataStore can use this

@graham-chainlink graham-chainlink marked this pull request as ready for review May 26, 2026 12:56
@graham-chainlink graham-chainlink requested a review from a team as a code owner May 26, 2026 12:56
@graham-chainlink graham-chainlink requested a review from giogam May 26, 2026 13:00
// WriteMetadataToDatastore adds address refs and upserts contract and chain metadata and sets env metadata.
func WriteMetadataToDatastore(ds MutableDataStore, bundle MetadataBundle) error {
for _, ref := range bundle.Addresses {
if err := ds.Addresses().Add(ref); err != nil {
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.

Why not Upsert? Using Add would fail if, for example, someone called WriteMetadata intending to update an existing AddressRef

// Contracts defines any metadata pertaining to contracts that were deployed.
Contracts []ContractMetadata
// Chain defines any metadata pertaining to the chain that was operated against.
Chain *ChainMetadata
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 get why Chain isn't a slice here, but as we generalize this CCIP-specific logic into a broadly available API, could this become a limitation? It's technically possible to have multiple ChainMetadata records per domain/environment, and other users might need that.

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.

3 participants