Skip to content

[FVM] Resolve reusable runtime environment import cycle#8303

Merged
janezpodhostnik merged 4 commits intomasterfrom
janez/resolve-runtime-poll-import-cycle
Jan 12, 2026
Merged

[FVM] Resolve reusable runtime environment import cycle#8303
janezpodhostnik merged 4 commits intomasterfrom
janez/resolve-runtime-poll-import-cycle

Conversation

@janezpodhostnik
Copy link
Contributor

@janezpodhostnik janezpodhostnik commented Jan 6, 2026

ref: #8301

Resolve the issue where the runtime had to create a copy of the Environment interface.

Summary by CodeRabbit

  • Refactor
    • Runtime environment moved to an interface-driven design for improved modularity and swap-in runtime implementations.
    • Environment initialization centralized via a single default-parameters provider to standardize runtime setup.
  • Tests
    • Test infrastructure expanded with autogenerated mocks for runtime and pooling to simplify testing of execution and resource reuse.

✏️ Tip: You can customize this high-level summary in your review settings.

@janezpodhostnik janezpodhostnik self-assigned this Jan 6, 2026
@janezpodhostnik janezpodhostnik requested a review from a team as a code owner January 6, 2026 21:01
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 6, 2026

📝 Walkthrough

Walkthrough

Adds interface-based abstractions for the Cadence runtime and its pool (ReusableCadenceRuntime, ReusableCadenceRuntimePool), moves default environment params to package fvm, updates runtime and environment implementations and mocks to use the new interfaces, and updates call sites/tests to consume the new APIs. (≈33 words)

Changes

Cohort / File(s) Summary
Env interfaces & params
fvm/environment/env.go
Adds ReusableCadenceRuntime interface; updates Environment to use it for BorrowCadenceRuntime/ReturnCadenceRuntime; removes DefaultEnvironmentParams() from environment package. Attention: public interface change affects all consumers.
Default params relocation
fvm/context.go
Adds exported DefaultEnvironmentParams() in fvm that returns a base environment.EnvironmentParams with defaults (chain, runtime/log/event/block/tx/contract updater params, zero exec-version provider).
Runtime abstraction & runtime params
fvm/environment/runtime.go, fvm/runtime/reusable_cadence_runtime.go, fvm/runtime/reusable_cadence_runtime_pool.go
Introduces ReusableCadenceRuntimePool interface; RuntimeParams now embeds that interface; Runtime gains env field and NewRuntime constructor; ReusableCadenceRuntime and pool use environment.ReusableCadenceRuntime/ReusableCadenceRuntimePool types and expose CadenceTXEnv/CadenceScriptEnv; added DefaultRuntimeParams. Attention: signature/type changes and interface assertions.
Mocks (generated + manual)
fvm/environment/mock/environment.go, fvm/environment/mock/reusable_cadence_runtime*.go
Updates mock Environment methods to new signatures; adds autogenerated testify mocks for ReusableCadenceRuntime, ReusableCadenceRuntimeInterface, and ReusableCadenceRuntimePool. Attention: verify mock generation matches new interfaces and test cleanup wiring.
Call sites & tests
fvm/script.go, fvm/transactionInvoker.go, fvm/environment/programs_test.go, fvm/fvm_test.go
Replace environment.DefaultEnvironmentParams() with fvm.DefaultEnvironmentParams(); use CadenceScriptEnv() / CadenceTXEnv() from borrowed runtime; adjust field types to interface. Attention: EVM setup now receives runtime-provided envs.

Sequence Diagram(s)

sequenceDiagram
  participant Caller as FVM caller (script/tx)
  participant RuntimePool as ReusableCadenceRuntimePool
  participant Reusable as ReusableCadenceRuntime
  participant Env as environment.Environment
  participant EVM as EVM setup/exec

  Caller->>RuntimePool: Borrow(fvmEnv: Env)
  RuntimePool-->>Caller: ReusableCadenceRuntime
  Caller->>Reusable: CadenceScriptEnv() / CadenceTXEnv()
  Caller->>EVM: SetupEnvironment(using cadence env)
  Caller->>Reusable: ExecuteScript / NewTransactionExecutor / InvokeContractFunction / ReadStored
  EVM-->>Caller: execution results
  Caller->>RuntimePool: Return(Reusable)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

Improvement, Flow EVM

Suggested reviewers

  • zhangchiqing
  • fxamacker
  • turbolent
  • holyfuchs

Poem

🐰
I hopped through code with nimble paws,
I swapped the runtimes, fixed the flaws.
Pools now share and mocks agree,
Envs relocated, runtime set free—
A carrot-party for CI applause.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 clearly and specifically describes the main objective of the pull request: resolving a circular import dependency issue between the reusable runtime and environment packages.

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

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c58d291 and 6b850b7.

📒 Files selected for processing (1)
  • fvm/environment/env.go
🧰 Additional context used
📓 Path-based instructions (4)
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/coding_conventions.mdc)

Follow Go coding conventions as documented in @docs/agents/CodingConventions.md

Follow Go coding standards and conventions as documented in @docs/agents/GoDocs.md

**/*.go: Follow the existing module structure in /module/, /engine/, /model/ and use dependency injection patterns for component composition
Implement proper interfaces before concrete types
Follow Go naming conventions and the project's coding style defined in /docs/CodingConventions.md
Use mock generators: run make generate-mocks after interface changes
All inputs must be considered potentially byzantine; error classification is context-dependent and no code path is safe unless explicitly proven and documented
Use comprehensive error wrapping for debugging; avoid fmt.Errorf, use irrecoverable package for exceptions
NEVER log and continue on best effort basis; ALWAYS explicitly handle errors
Uses golangci-lint with custom configurations (.golangci.yml) and custom linters for Flow-specific conventions (struct write checking)

Files:

  • fvm/environment/env.go
{crypto,fvm,ledger,storage}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Security checks for cryptographic misuse must be enforced using gosec

Files:

  • fvm/environment/env.go
{crypto,fvm,ledger,access,engine}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Cryptographic operations require careful handling; refer to crypto library documentation for proper implementation

Files:

  • fvm/environment/env.go
{storage,ledger,execution,fvm}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

State consistency is paramount; use proper synchronization primitives

Files:

  • fvm/environment/env.go
🧬 Code graph analysis (1)
fvm/environment/env.go (3)
fvm/runtime/reusable_cadence_runtime.go (1)
  • ReusableCadenceRuntime (12-18)
fvm/environment/mock/reusable_cadence_runtime.go (1)
  • ReusableCadenceRuntime (19-21)
fvm/environment/mock/environment.go (1)
  • Environment (41-43)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (36)
  • GitHub Check: Lint (./)
  • GitHub Check: Lint (./insecure/)
  • GitHub Check: Lint (./integration/)
  • GitHub Check: Unit Tests (storage)
  • GitHub Check: Unit Tests (engine/execution)
  • GitHub Check: Unit Tests (engine/execution/ingestion)
  • GitHub Check: Unit Tests (network/test/cohort1)
  • GitHub Check: Unit Tests (network)
  • GitHub Check: Unit Tests (engine/verification)
  • GitHub Check: Unit Tests (module/dkg)
  • GitHub Check: Unit Tests (network/p2p/scoring)
  • GitHub Check: Unit Tests (network/alsp)
  • GitHub Check: Unit Tests (module)
  • GitHub Check: Unit Tests (engine)
  • GitHub Check: Unit Tests (network/p2p/node)
  • GitHub Check: Unit Tests (engine/execution/computation)
  • GitHub Check: Unit Tests (network/p2p)
  • GitHub Check: Unit Tests (network/p2p/connection)
  • GitHub Check: Unit Tests (others)
  • GitHub Check: Unit Tests (fvm)
  • GitHub Check: Unit Tests (ledger)
  • GitHub Check: Unit Tests (engine/consensus)
  • GitHub Check: Unit Tests (admin)
  • GitHub Check: Unit Tests (utils)
  • GitHub Check: Unit Tests (engine/common)
  • GitHub Check: Unit Tests (engine/collection)
  • GitHub Check: Unit Tests (state)
  • GitHub Check: Unit Tests (cmd)
  • GitHub Check: Unit Tests (engine/access)
  • GitHub Check: Unit Tests (consensus)
  • GitHub Check: Integration Tests Others (integration)
  • GitHub Check: Unit Tests Insecure (insecure)
  • GitHub Check: Unit Tests Insecure (insecure/integration/functional/test/gossipsub/rpc_inspector)
  • GitHub Check: Unit Tests Insecure (insecure/integration/functional/test/gossipsub/scoring)
  • GitHub Check: Docker Build
  • GitHub Check: analyze-code (go)
🔇 Additional comments (4)
fvm/environment/env.go (4)

3-10: LGTM!

The new imports (cadence/common, cadence/sema) are correctly added to support the ReusableCadenceRuntime interface types.


24-25: Good interface abstraction to break the import cycle.

Changing from concrete type *reusableRuntime.ReusableCadenceRuntime to the local ReusableCadenceRuntime interface properly decouples the environment package from the runtime package, resolving the import cycle as intended.


88-134: Well-designed interface abstraction.

The ReusableCadenceRuntime interface is clean and well-documented. All seven methods are correctly implemented in the concrete type (fvm/runtime/reusable_cadence_runtime.go), as verified by the interface assertion on line 20. The methods correctly expose the necessary runtime operations while hiding implementation details.

The design creates a bidirectional dependency between Environment and ReusableCadenceRuntime (via SetFvmEnvironment), which is the expected pattern for resolving the import cycle mentioned in the PR objectives.


136-161: DefaultEnvironmentParams relocation is complete and correct.

The function was successfully moved to fvm/context.go and all callers have been updated: fvm/fvm_test.go, fvm/context.go, and fvm/environment/programs_test.go all reference it via fvm.DefaultEnvironmentParams(). No broken references to the old location exist.


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.

@janezpodhostnik
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 6, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI Agents
In @fvm/environment/env.go:
- Around line 126-130: Fix the duplicate "a" typo in the doc comments for
CadenceTXEnv and CadenceScriptEnv: change "returns a a cadence
runtime.Environment" to "returns a cadence runtime.Environment" in the comments
above the CadenceTXEnv and CadenceScriptEnv method declarations.
🧹 Nitpick comments (1)
fvm/runtime/reusable_cadence_runtime_pool.go (1)

118-126: Verify intent of zero pool size in DefaultRuntimeParams.

DefaultRuntimeParams creates a pool with poolSize: 0, which means no runtime instances are cached—each Borrow creates a new runtime, and Return discards it. If this is intentional for default/testing scenarios, consider adding a brief comment to document the rationale.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c7a93c and b729f1b.

📒 Files selected for processing (13)
  • fvm/context.go
  • fvm/environment/env.go
  • fvm/environment/mock/environment.go
  • fvm/environment/mock/reusable_cadence_runtime.go
  • fvm/environment/mock/reusable_cadence_runtime_interface.go
  • fvm/environment/mock/reusable_cadence_runtime_pool.go
  • fvm/environment/programs_test.go
  • fvm/environment/runtime.go
  • fvm/fvm_test.go
  • fvm/runtime/reusable_cadence_runtime.go
  • fvm/runtime/reusable_cadence_runtime_pool.go
  • fvm/script.go
  • fvm/transactionInvoker.go
🧰 Additional context used
📓 Path-based instructions (5)
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/coding_conventions.mdc)

Follow Go coding conventions as documented in @docs/agents/CodingConventions.md

Follow Go coding standards and conventions as documented in @docs/agents/GoDocs.md

**/*.go: Follow the existing module structure in /module/, /engine/, /model/ and use dependency injection patterns for component composition
Implement proper interfaces before concrete types
Follow Go naming conventions and the project's coding style defined in /docs/CodingConventions.md
Use mock generators: run make generate-mocks after interface changes
All inputs must be considered potentially byzantine; error classification is context-dependent and no code path is safe unless explicitly proven and documented
Use comprehensive error wrapping for debugging; avoid fmt.Errorf, use irrecoverable package for exceptions
NEVER log and continue on best effort basis; ALWAYS explicitly handle errors
Uses golangci-lint with custom configurations (.golangci.yml) and custom linters for Flow-specific conventions (struct write checking)

Files:

  • fvm/script.go
  • fvm/fvm_test.go
  • fvm/environment/mock/reusable_cadence_runtime_pool.go
  • fvm/environment/mock/environment.go
  • fvm/environment/env.go
  • fvm/runtime/reusable_cadence_runtime_pool.go
  • fvm/environment/programs_test.go
  • fvm/environment/mock/reusable_cadence_runtime_interface.go
  • fvm/context.go
  • fvm/environment/runtime.go
  • fvm/environment/mock/reusable_cadence_runtime.go
  • fvm/transactionInvoker.go
  • fvm/runtime/reusable_cadence_runtime.go
{crypto,fvm,ledger,storage}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Security checks for cryptographic misuse must be enforced using gosec

Files:

  • fvm/script.go
  • fvm/fvm_test.go
  • fvm/environment/mock/reusable_cadence_runtime_pool.go
  • fvm/environment/mock/environment.go
  • fvm/environment/env.go
  • fvm/runtime/reusable_cadence_runtime_pool.go
  • fvm/environment/programs_test.go
  • fvm/environment/mock/reusable_cadence_runtime_interface.go
  • fvm/context.go
  • fvm/environment/runtime.go
  • fvm/environment/mock/reusable_cadence_runtime.go
  • fvm/transactionInvoker.go
  • fvm/runtime/reusable_cadence_runtime.go
{crypto,fvm,ledger,access,engine}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

Cryptographic operations require careful handling; refer to crypto library documentation for proper implementation

Files:

  • fvm/script.go
  • fvm/fvm_test.go
  • fvm/environment/mock/reusable_cadence_runtime_pool.go
  • fvm/environment/mock/environment.go
  • fvm/environment/env.go
  • fvm/runtime/reusable_cadence_runtime_pool.go
  • fvm/environment/programs_test.go
  • fvm/environment/mock/reusable_cadence_runtime_interface.go
  • fvm/context.go
  • fvm/environment/runtime.go
  • fvm/environment/mock/reusable_cadence_runtime.go
  • fvm/transactionInvoker.go
  • fvm/runtime/reusable_cadence_runtime.go
{storage,ledger,execution,fvm}/**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

State consistency is paramount; use proper synchronization primitives

Files:

  • fvm/script.go
  • fvm/fvm_test.go
  • fvm/environment/mock/reusable_cadence_runtime_pool.go
  • fvm/environment/mock/environment.go
  • fvm/environment/env.go
  • fvm/runtime/reusable_cadence_runtime_pool.go
  • fvm/environment/programs_test.go
  • fvm/environment/mock/reusable_cadence_runtime_interface.go
  • fvm/context.go
  • fvm/environment/runtime.go
  • fvm/environment/mock/reusable_cadence_runtime.go
  • fvm/transactionInvoker.go
  • fvm/runtime/reusable_cadence_runtime.go
**/*_test.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*_test.go: Unit tests should be co-located with the code they test
Follow the existing pattern of *_test.go files for test naming
Use fixtures for realistic test data as defined in /utils/unittest/

Files:

  • fvm/fvm_test.go
  • fvm/environment/programs_test.go
🧠 Learnings (2)
📚 Learning: 2025-12-23T00:28:41.005Z
Learnt from: CR
Repo: onflow/flow-go PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-23T00:28:41.005Z
Learning: Applies to **/*.go : Use mock generators: run `make generate-mocks` after interface changes

Applied to files:

  • fvm/environment/mock/reusable_cadence_runtime_pool.go
  • fvm/environment/mock/environment.go
  • fvm/environment/mock/reusable_cadence_runtime_interface.go
  • fvm/environment/mock/reusable_cadence_runtime.go
📚 Learning: 2025-12-23T00:28:41.005Z
Learnt from: CR
Repo: onflow/flow-go PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-23T00:28:41.005Z
Learning: Applies to {storage,ledger,execution,fvm}/**/*.go : State consistency is paramount; use proper synchronization primitives

Applied to files:

  • fvm/transactionInvoker.go
🧬 Code graph analysis (10)
fvm/fvm_test.go (1)
fvm/context.go (1)
  • DefaultEnvironmentParams (90-103)
fvm/environment/mock/reusable_cadence_runtime_pool.go (5)
fvm/environment/runtime.go (1)
  • ReusableCadenceRuntimePool (5-12)
fvm/runtime/reusable_cadence_runtime_pool.go (2)
  • ReusableCadenceRuntimePool (12-29)
  • NewReusableCadenceRuntimePool (52-63)
fvm/environment/env.go (2)
  • Environment (14-86)
  • ReusableCadenceRuntime (90-134)
fvm/environment/mock/environment.go (1)
  • Environment (41-43)
fvm/environment/mock/reusable_cadence_runtime.go (1)
  • ReusableCadenceRuntime (19-21)
fvm/environment/mock/environment.go (3)
fvm/environment/env.go (2)
  • Environment (14-86)
  • ReusableCadenceRuntime (90-134)
fvm/environment/mock/reusable_cadence_runtime.go (1)
  • ReusableCadenceRuntime (19-21)
fvm/runtime/reusable_cadence_runtime.go (1)
  • ReusableCadenceRuntime (11-17)
fvm/environment/env.go (3)
fvm/environment/mock/reusable_cadence_runtime.go (1)
  • ReusableCadenceRuntime (19-21)
fvm/runtime/reusable_cadence_runtime.go (1)
  • ReusableCadenceRuntime (11-17)
fvm/environment/mock/environment.go (1)
  • Environment (41-43)
fvm/runtime/reusable_cadence_runtime_pool.go (3)
fvm/environment/runtime.go (2)
  • Runtime (19-23)
  • RuntimeParams (14-16)
fvm/environment/env.go (2)
  • ReusableCadenceRuntime (90-134)
  • Environment (14-86)
fvm/runtime/reusable_cadence_runtime.go (1)
  • ReusableCadenceRuntime (11-17)
fvm/environment/programs_test.go (1)
fvm/context.go (1)
  • DefaultEnvironmentParams (90-103)
fvm/environment/mock/reusable_cadence_runtime_interface.go (2)
fvm/environment/env.go (1)
  • Environment (14-86)
fvm/environment/mock/environment.go (1)
  • Environment (41-43)
fvm/environment/runtime.go (5)
fvm/environment/env.go (2)
  • Environment (14-86)
  • ReusableCadenceRuntime (90-134)
fvm/environment/mock/environment.go (1)
  • Environment (41-43)
fvm/environment/mock/reusable_cadence_runtime.go (1)
  • ReusableCadenceRuntime (19-21)
fvm/runtime/reusable_cadence_runtime.go (1)
  • ReusableCadenceRuntime (11-17)
fvm/runtime/reusable_cadence_runtime_pool.go (1)
  • ReusableCadenceRuntimePool (12-29)
fvm/transactionInvoker.go (3)
fvm/environment/env.go (1)
  • ReusableCadenceRuntime (90-134)
fvm/environment/mock/reusable_cadence_runtime.go (1)
  • ReusableCadenceRuntime (19-21)
fvm/runtime/reusable_cadence_runtime.go (1)
  • ReusableCadenceRuntime (11-17)
fvm/runtime/reusable_cadence_runtime.go (2)
fvm/environment/runtime.go (1)
  • Runtime (19-23)
fvm/environment/env.go (2)
  • Environment (14-86)
  • ReusableCadenceRuntime (90-134)
🔇 Additional comments (19)
fvm/context.go (1)

88-103: LGTM! Well-structured default environment parameters.

The new DefaultEnvironmentParams() function provides a clean way to construct base environment settings. Using flow.Mainnet as the default chain is reasonable since the actual chain can be overridden via WithChain() context option when needed.

fvm/script.go (1)

205-209: LGTM! Correctly uses the new interface method.

The change from field access (rt.ScriptRuntimeEnv) to method call (rt.CadenceScriptEnv()) correctly aligns with the new ReusableCadenceRuntime interface abstraction.

fvm/environment/programs_test.go (1)

143-146: LGTM! Test updated for new function location.

The change correctly uses fvm.DefaultEnvironmentParams() instead of the previous environment.DefaultEnvironmentParams(), consistent with the refactoring that moved this function to the fvm package.

fvm/fvm_test.go (1)

3873-3878: LGTM! Tests updated consistently.

Both test cases correctly use fvm.DefaultEnvironmentParams() instead of the previous environment.DefaultEnvironmentParams(). The changes are consistent with the refactoring and maintain test functionality.

Also applies to: 3902-3907

fvm/transactionInvoker.go (2)

72-72: LGTM! Improved abstraction with interface usage.

The change from concrete type *reusableRuntime.ReusableCadenceRuntime to interface type environment.ReusableCadenceRuntime follows good software engineering practices by programming to interfaces rather than implementations. This provides better flexibility and testability.


187-198: LGTM! Consistent migration to interface methods.

The changes from field access (.TxRuntimeEnv) to method calls (.CadenceTXEnv()) correctly align with the new ReusableCadenceRuntime interface. Both occurrences in preprocessTransactionBody() and ExecuteTransactionBody() are updated consistently.

Also applies to: 254-265

fvm/runtime/reusable_cadence_runtime.go (2)

8-8: Import and interface wiring looks correct.

The import of environment package and the compile-time interface assertion var _ environment.ReusableCadenceRuntime = (*ReusableCadenceRuntime)(nil) properly ensures that the concrete type satisfies the interface defined in the environment package, breaking the import cycle.

Also applies to: 16-16, 19-19


49-55: LGTM!

The accessor methods correctly expose the internal runtime environments, matching the interface contract defined in environment.ReusableCadenceRuntime.

fvm/environment/mock/environment.go (2)

252-269: Auto-generated mock correctly reflects interface changes.

The BorrowCadenceRuntime mock now returns environment.ReusableCadenceRuntime interface type, matching the updated Environment interface. Based on learnings, ensure make generate-mocks was run after interface changes.


1493-1496: Mock signature updated correctly.

ReturnCadenceRuntime now accepts environment.ReusableCadenceRuntime, consistent with the interface definition.

fvm/environment/mock/reusable_cadence_runtime_pool.go (1)

1-52: Auto-generated mock for new pool interface.

The mock correctly implements the ReusableCadenceRuntimePool interface with proper testify/mock patterns. Based on learnings, this was generated via make generate-mocks.

fvm/runtime/reusable_cadence_runtime_pool.go (2)

31-32: Interface assertion ensures type safety.

The compile-time assertion var _ environment.ReusableCadenceRuntimePool = (*ReusableCadenceRuntimePool)(nil) ensures the concrete pool type satisfies the interface contract.


86-104: Borrow method correctly handles interface return type.

The method returns environment.ReusableCadenceRuntime interface while internally creating concrete *ReusableCadenceRuntime instances. The SetFvmEnvironment call on line 102 correctly wires the environment before returning.

fvm/environment/runtime.go (2)

3-12: Clean interface abstraction for runtime pooling.

The ReusableCadenceRuntimePool interface cleanly abstracts the pool operations, allowing different pool implementations (including mocks) to be injected.


35-37: The nil environment handling in BorrowCadenceRuntime is by design. SetEnvironment is called before the environment is returned from NewScriptEnv/NewTransactionEnv (facade_env.go line 155), and the nil environment passed during pool return operations is intentionally supported by the Return method (reusable_cadence_runtime_pool.go line 109). No code path calls BorrowCadenceRuntime before SetEnvironment is called.

fvm/environment/env.go (2)

24-25: Interface-based runtime methods.

The Environment interface now uses the ReusableCadenceRuntime interface type for borrow/return operations, enabling proper abstraction and breaking the import cycle.


88-134: Well-designed interface for reusable runtime abstraction.

The ReusableCadenceRuntime interface properly encapsulates the Cadence runtime operations needed by the FVM, including script/transaction execution, contract invocation, and environment access. This cleanly resolves the import cycle mentioned in the PR objective.

fvm/environment/mock/reusable_cadence_runtime.go (1)

1-190: Auto-generated mock correctly implements ReusableCadenceRuntime interface.

All interface methods are properly mocked with standard testify/mock patterns, including proper handling of function-based return values and direct value casting. Based on learnings, this was generated via make generate-mocks after interface changes.

fvm/environment/mock/reusable_cadence_runtime_interface.go (1)

1-190: LGTM! Auto-generated mock follows standard patterns.

The mock implementation is correctly generated by mockery and follows all standard testify/mock patterns. Each method properly:

  • Delegates to the mock recorder via Called(...)
  • Guards against missing return values with panic messages
  • Handles both function and direct value returns with type assertions
  • The constructor correctly registers test hooks and cleanup

Based on learnings, remember to run make generate-mocks if the ReusableCadenceRuntimeInterface interface changes in the future.

Base automatically changed from janez/add-chain-to-reusable-runtime to master January 9, 2026 13:39
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2026

Copy link
Member

@fxamacker fxamacker left a comment

Choose a reason for hiding this comment

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

Nice! I left a minor comment/question.

@janezpodhostnik janezpodhostnik added this pull request to the merge queue Jan 12, 2026
Merged via the queue into master with commit d163b2a Jan 12, 2026
61 checks passed
@janezpodhostnik janezpodhostnik deleted the janez/resolve-runtime-poll-import-cycle branch January 12, 2026 15:01
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.

5 participants