Skip to content

Comments

Script data multiple languages#730

Open
nicolasLuduena wants to merge 4 commits intotxpipe:mainfrom
nicolasLuduena:script-data-multiple-languages
Open

Script data multiple languages#730
nicolasLuduena wants to merge 4 commits intotxpipe:mainfrom
nicolasLuduena:script-data-multiple-languages

Conversation

@nicolasLuduena
Copy link
Member

@nicolasLuduena nicolasLuduena commented Feb 13, 2026

This pull request refactors how Plutus language cost models are handled throughout the codebase, changing from a single LanguageView (supporting just one language/cost model at a time) to a new LanguageViews type that supports multiple languages and their cost models simultaneously. This enables transactions to include cost models for multiple Plutus versions, aligning with Cardano's evolving protocol requirements. The changes affect primitives, transaction building, validation, and test infrastructure.

Core API and Data Model Changes:

  • Replaced the LanguageView struct (which only allowed a single Plutus version and cost model) with a new LanguageViews struct, which is a BTreeMap mapping multiple PlutusVersion values to their respective CostModels. This affects all serialization, encoding, and builder APIs. [1] [2] [3]

  • Updated the ScriptData struct and associated methods to use language_views instead of language_view, and revised encoding logic to support multiple cost models in canonical order. [1] [2] [3]

Transaction Builder and Usage:

  • Refactored the transaction builder (StagingTransaction) to support multiple language cost models, including new methods for adding individual or multiple language/cost model pairs. Updated all usages and tests to use the new API.

Validation and Protocol Parameter Handling:

  • Updated the validation logic to compute and check script data hashes using all relevant cost models for the Plutus versions present in a transaction, rather than just the highest version. This includes changes to how languages are detected and how protocol parameters are used to fetch cost models.

Testing and Test Data:

  • Refactored tests to use the new LanguageViews structure, added support for transactions with multiple Plutus versions, and introduced a new test vector (conway9.tx) containing a transaction with three Plutus versions and their cost models.

Most important changes:

API and Data Model Refactor:

  • Replaced LanguageView with LanguageViews (a BTreeMap of Plutus versions to cost models) throughout the primitives, transaction builder, and script data handling code.

Builder and Usage:

  • Refactored transaction builder API to support adding multiple cost models and provided new methods for adding individual or multiple language/cost model pairs.

Validation and Protocol Parameter Handling:

  • Changed validation logic to use all languages present in a transaction for cost model lookup, and updated protocol parameter handling to return a LanguageViews map.

Testing and Test Data:

  • Updated tests to use LanguageViews, added a new test vector with multiple Plutus versions, and ensured hash checks work with the new structure.

Summary by CodeRabbit

  • New Features

    • Support for including multiple smart-contract language cost models in a single transaction.
  • API Updates

    • Field renamed from language_view to language_views; builder API now supports setting or adding multiple language entries.
    • Cost-model handling for Conway transactions reorganized for multi-language support and deterministic encoding.
  • Tests

    • Updated test vectors and added new transaction test data to cover multi-language scenarios.

@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

Refactors LanguageView into a map-based LanguageViews (BTreeMap of PlutusVersion → CostModel) with deterministic CBOR encoding (PlutusV1 encoded last). Replaces language_view fields/APIs with language_views across primitives, txbuilder, validation, and tests; adds a new test vector file.

Changes

Cohort / File(s) Summary
Core Type & ScriptData
pallas-primitives/src/conway/script_data.rs
Replaced tuple LanguageView with LanguageViews(pub BTreeMap<PlutusVersion, CostModel>). Added Default, FromIterator, and custom Encode producing deterministic ordering (exclude/append PlutusV1 last). ScriptData field renamed to language_views: Option<LanguageViews> and encoding/hash updated. Tests adjusted.
TxBuilder Model API
pallas-txbuilder/src/transaction/model.rs
Renamed StagingTransaction.language_viewlanguage_views (Option). Replaced language_view(...) setter with language_views(...) and added add_language(...) to insert per-version cost models.
TxBuilder Usage & Serialization
pallas-txbuilder/src/conway.rs, pallas-txbuilder/src/transaction/serialise.rs
Updated Conway tx construction to pass language_views.as_ref() into ScriptData and adjusted tests/serialization to construct LanguageViews via from_iter() instead of single tuple.
Validation / Cost Model Discovery
pallas-validate/src/phase1/conway.rs
cost_model_for_tx() now returns Option<LanguageViews> and builds a map of detected Plutus versions → cost models. tx_languages() simplified; check_script_data_hash() updated to pass language_views into ScriptData::build_for.
Test Data
test_data/conway9.tx
Added a new hex-encoded Conway transaction test vector file.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • scarmuega

Poem

"I nibble maps, not single views,
I sort Plutus1 to last in queues.
Cost models tucked in tidy rows,
A rabbit's hop through ordered flows. 🐇📜"

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (5 files):

⚔️ pallas-primitives/src/conway/script_data.rs (content)
⚔️ pallas-txbuilder/src/conway.rs (content)
⚔️ pallas-txbuilder/src/transaction/model.rs (content)
⚔️ pallas-txbuilder/src/transaction/serialise.rs (content)
⚔️ pallas-validate/src/phase1/conway.rs (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Script data multiple languages' is partially related to the changeset. It refers to supporting multiple Plutus languages/versions in script data, which is accurate, but is somewhat vague and doesn't fully capture the main refactoring from LanguageView to LanguageViews or the encoding/serialization changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch script-data-multiple-languages
  • Post resolved changes as copyable diffs in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
pallas-txbuilder/src/transaction/model.rs (2)

44-44: Consider importing LanguageViews to reduce verbosity.

The fully qualified pallas_primitives::conway::LanguageViews is repeated at lines 44, 291, and 309. A use import would clean this up.

♻️ Suggested import

Add to the existing import block at line 6:

 use pallas_primitives::{
-    conway::{self, AuxiliaryData},
+    conway::{self, AuxiliaryData, LanguageViews},
     Fragment, NonEmptySet,
 };

Then replace the three fully qualified usages with LanguageViews.


296-311: Unnecessary clone — use take() instead of as_ref() + clone().

Since self is already mut, you can take ownership of the inner map to avoid a full clone on every add_language call.

♻️ Proposed fix
         let mut map = self
             .language_views
-            .as_ref()
-            .map(|v| v.0.clone())
+            .take()
+            .map(|v| v.0)
             .unwrap_or_default();

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant