Skip to content

fix: sim config for triggered txs#1373

Closed
danieljrc888 wants to merge 5 commits intomainfrom
fix/sim-config-for-triggered-txs
Closed

fix: sim config for triggered txs#1373
danieljrc888 wants to merge 5 commits intomainfrom
fix/sim-config-for-triggered-txs

Conversation

@danieljrc888
Copy link
Copy Markdown
Contributor

@danieljrc888 danieljrc888 commented Jan 8, 2026

Fixes DXP-729

What

  • Inherit sim config in triggered transactions

Why

  • To use mocking capabilities in localnet

Testing done

  • tested with rally ICs

Decisions made

Checks

  • I have tested this code
  • I have reviewed my own PR
  • I have created an issue for this PR
  • I have set a descriptive PR title compliant with conventional commits

Reviewing tips

User facing release notes

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Simplified transaction type labeling display by removing unnecessary contract snapshot dependencies for improved consistency.
  • Improvements

    • Enhanced backend transaction processing with configuration data propagation and improved mock response handling with format-aware formatting.

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 8, 2026

📝 Walkthrough

Walkthrough

The PR propagates simulation configuration metadata through the transaction processing API, simplifies transaction type label rendering by removing contract snapshot-based deployment detection, extends mock response handling to support default values and format-specific transformations, and applies formatting improvements to health check imports.

Changes

Cohort / File(s) Change Summary
Transaction Configuration Propagation
backend/consensus/base.py, backend/database_handler/transactions_processor.py
Adds sim_config parameter to insert_transaction method, propagating simulation configuration from context through the transaction processing pipeline.
Health Endpoint Formatting
backend/protocol_rpc/health.py
Reformats metrics import to multi-line grouped style and splits needed_workers_count calculation for readability; no functional changes.
Mock Response Handling Enhancement
backend/node/llm.lua
Adds support for default mock response matching via empty string key, introduces format-aware response wrapping (JSON vs. text), enabling fallback responses when no exact key match is found.
Transaction Type Label Refactoring
explorer/src/components/TransactionTypeLabel.tsx, explorer/src/lib/transactionUtils.ts
Removes contractSnapshot prop and isContractDeploy function; replaces conditional deployment detection with direct type-to-label mapping (0=Send, 1=Deploy, 2=Call, 3=Upgrade).
Transaction Type Label Usage Updates
explorer/src/app/transactions/[hash]/components/OverviewTab.tsx, explorer/src/app/transactions/[hash]/page.tsx, explorer/src/components/TransactionTable.tsx
Removes contractSnapshot prop from TransactionTypeLabel component calls across three file locations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

run-tests

Suggested reviewers

  • cristiam86

Poem

🐰 A config flows through transactions deep,
Type labels simpler, their secrets to keep,
Mock responses with defaults so sly,
Labels unlabeled—no snapshots nearby! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.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
Title check ✅ Passed The title 'fix: sim config for triggered txs' directly relates to the main change: inheriting sim config in triggered transactions (backend/consensus/base.py), and follows conventional commits format.
Description check ✅ Passed The PR description covers the main sections but lacks depth. It addresses What, Why, and Testing, but the Decisions section is empty and the PR title does not follow conventional commits format.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

@danieljrc888 danieljrc888 force-pushed the fix/sim-config-for-triggered-txs branch from b2461c3 to 12b41e4 Compare January 13, 2026 01:08
@danieljrc888 danieljrc888 changed the title Fix/sim config for triggered txs fix: sim config for triggered txs Jan 13, 2026
@danieljrc888 danieljrc888 self-assigned this Jan 13, 2026
@danieljrc888 danieljrc888 marked this pull request as ready for review January 13, 2026 01:20
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarQube Cloud

Copy link
Copy Markdown
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 @backend/node/llm.lua:
- Around line 217-234: When mapped_prompt.format == "json" and mock_data.data is
a string, protect the call to lib.rs.json_parse by wrapping it in a safe
error-handling path (e.g., pcall/xpcall) so parse failures do not raise an
unhandled error; on failure set data_value to a safe fallback (nil or the
original string) and surface/log the parse error via your logger (or attach an
error field) so callers of data_value can handle invalid mock JSON gracefully;
update the branch that currently assigns data_value =
lib.rs.json_parse(mock_data.data) to use this guarded parse and fallback
behavior while keeping existing behavior when parsing succeeds.
🧹 Nitpick comments (2)
explorer/src/components/TransactionTypeLabel.tsx (1)

7-45: Clean refactor with improved maintainability.

The switch-based approach is cleaner and the backend type documentation is helpful.

Consider using a const enum or object mapping for the transaction types to improve type safety and eliminate magic numbers:

✨ Optional: Type-safe transaction type constants
// Could be defined in a shared types/constants file
export const TRANSACTION_TYPES = {
  SEND: 0,
  DEPLOY_CONTRACT: 1,
  RUN_CONTRACT: 2,
  UPGRADE_CONTRACT: 3,
} as const;

export type TransactionType = typeof TRANSACTION_TYPES[keyof typeof TRANSACTION_TYPES];

This would allow the switch cases to use TRANSACTION_TYPES.SEND instead of 0, making the code self-documenting and reducing the risk of typos. Low priority since the inline comments already document the mapping.

backend/protocol_rpc/health.py (1)

535-535: Consider adding return type hint for consistency.

The metrics() function is missing a return type hint, while other health endpoint functions in this file properly annotate their return types. As per coding guidelines, type hints should be included in all Python code.

📝 Suggested addition
-async def metrics():
+async def metrics() -> Response:
     """Return worker metrics for autoscaling in Prometheus format."""
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 307e555 and c533910.

📒 Files selected for processing (8)
  • backend/consensus/base.py
  • backend/node/llm.lua
  • backend/protocol_rpc/health.py
  • explorer/src/app/transactions/[hash]/components/OverviewTab.tsx
  • explorer/src/app/transactions/[hash]/page.tsx
  • explorer/src/components/TransactionTable.tsx
  • explorer/src/components/TransactionTypeLabel.tsx
  • explorer/src/lib/transactionUtils.ts
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use ESLint and Prettier for TypeScript/JavaScript code formatting and linting with strict mode enabled

Files:

  • explorer/src/app/transactions/[hash]/components/OverviewTab.tsx
  • explorer/src/lib/transactionUtils.ts
  • explorer/src/components/TransactionTable.tsx
  • explorer/src/app/transactions/[hash]/page.tsx
  • explorer/src/components/TransactionTypeLabel.tsx
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Target Python 3.12, use 4-space indentation, and rely on Black via pre-commit for formatting consistency

**/*.py: Apply Black formatter for Python code formatting
Include type hints in all Python code

Files:

  • backend/consensus/base.py
  • backend/protocol_rpc/health.py
backend/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Align backend filenames with their behavior (e.g., validators/llm_validator.py) and mirror that pattern in tests

Files:

  • backend/consensus/base.py
  • backend/protocol_rpc/health.py
backend/consensus/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

Implement validator rotation using VRF (Verifiable Random Function) in the consensus system

Files:

  • backend/consensus/base.py
🧠 Learnings (1)
📚 Learning: 2025-08-14T18:56:08.197Z
Learnt from: epsjunior
Repo: genlayerlabs/genlayer-studio PR: 1282
File: frontend/src/hooks/useContractQueries.ts:80-81
Timestamp: 2025-08-14T18:56:08.197Z
Learning: In frontend/src/hooks/useContractQueries.ts, the fetchContractSchema catch block throws error.details directly to maintain existing production behavior. The previous extractErrorMessage helper function was removed to eliminate unused code, but the error handling pattern remains the same as what was working in production.

Applied to files:

  • explorer/src/app/transactions/[hash]/components/OverviewTab.tsx
  • explorer/src/lib/transactionUtils.ts
  • explorer/src/components/TransactionTable.tsx
  • explorer/src/app/transactions/[hash]/page.tsx
🧬 Code graph analysis (5)
explorer/src/app/transactions/[hash]/components/OverviewTab.tsx (2)
explorer/src/components/InfoRow.tsx (1)
  • InfoRow (12-24)
explorer/src/components/TransactionTypeLabel.tsx (1)
  • TransactionTypeLabel (7-46)
backend/consensus/base.py (1)
backend/node/types.py (2)
  • to_dict (147-162)
  • to_dict (202-229)
explorer/src/components/TransactionTable.tsx (1)
explorer/src/components/TransactionTypeLabel.tsx (1)
  • TransactionTypeLabel (7-46)
explorer/src/app/transactions/[hash]/page.tsx (4)
explorer/src/components/TransactionTable.tsx (1)
  • TransactionTypeLabel (221-221)
explorer/src/components/TransactionTypeLabel.tsx (1)
  • TransactionTypeLabel (7-46)
explorer/src/components/index.ts (1)
  • TransactionTypeLabel (11-11)
hardhat/scripts/restore.js (1)
  • tx (82-82)
explorer/src/components/TransactionTypeLabel.tsx (2)
explorer/src/components/TransactionTable.tsx (1)
  • TransactionTypeLabel (221-221)
explorer/src/components/index.ts (1)
  • TransactionTypeLabel (11-11)
⏰ 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). (1)
  • GitHub Check: backend-unit-tests
🔇 Additional comments (8)
explorer/src/lib/transactionUtils.ts (1)

1-1: LGTM!

The import cleanup is correct—removing NewConsensusHistory along with the deleted isContractDeploy function keeps the imports minimal and aligned with actual usage.

explorer/src/components/TransactionTable.tsx (1)

123-123: LGTM!

The updated prop usage is consistent with the refactored TransactionTypeLabel API, which now relies solely on the backend-provided type field for rendering the appropriate label.

explorer/src/app/transactions/[hash]/page.tsx (1)

115-115: LGTM!

Consistent with the TransactionTypeLabel API update across the codebase.

explorer/src/app/transactions/[hash]/components/OverviewTab.tsx (1)

24-24: LGTM!

The simplified TransactionTypeLabel usage is consistent with the broader refactor.

backend/node/llm.lua (1)

47-65: LGTM! Default mock response implementation is clean.

The use of an empty string key as a sentinel for the default value is a reasonable convention. The logic correctly prioritizes specific matches over the default fallback.

backend/consensus/base.py (1)

3762-3766: LGTM! Correctly propagates sim_config to triggered transactions.

This change properly inherits the simulation configuration for child transactions, enabling mocking capabilities for contract-to-contract calls in localnet. The pattern is consistent with how other configuration values (like leader_only, num_of_initial_validators, config_rotation_rounds) are cascaded. The TransactionsProcessor.insert_transaction method correctly accepts the sim_config parameter.

backend/protocol_rpc/health.py (2)

540-545: LGTM! Import reformatting improves readability.

The multi-line import format aligns with Black's formatting conventions and improves code readability.


566-568: LGTM! Calculation reformatting improves readability.

The multi-line format makes the autoscaling logic clearer while preserving the semantic meaning.

Comment thread backend/node/llm.lua
@cristiam86
Copy link
Copy Markdown
Contributor

Added to #1377

@cristiam86 cristiam86 closed this Jan 14, 2026
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.

2 participants