Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deployments part ii #11

Merged
merged 5 commits into from
Feb 5, 2025
Merged

feat: deployments part ii #11

merged 5 commits into from
Feb 5, 2025

Conversation

lgalabru
Copy link
Member

@lgalabru lgalabru commented Feb 5, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced the deployment workflow with an interactive multi-select and confirmation prompt, allowing for more controlled deployment configuration.
    • Integrated real-time progress tracking into the interface, offering dynamic status updates during deployment.
    • Improved network data responses, ensuring more accurate transaction status and balance information.
  • Refactor

    • Streamlined the deployment scaffolding process and optimized event handling for smoother, more responsive user interactions.

Copy link

coderabbitai bot commented Feb 5, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request updates dependency versions and introduces new dependencies while refactoring concurrent event handling and deployment flows. In the CLI layer, the changes replace standard channels with crossbeam channels, modify function signatures, adjust runbook generation, and add user confirmation prompts. In the core modules, several RPC methods obtain concrete implementations and enhanced logging with unique identifiers. Overall, the modifications standardize channel usage, improve deployment scaffolding, and streamline both CLI and RPC functionalities.

Changes

File(s) Summary
crates/cli/Cargo.toml Updated txtx-addon-network-svm from 0.1.0 to 0.1.1 and added new dependency crossbeam (0.8.4).
cli/src/{cli/simnet/mod.rs, runbook/mod.rs, scaffold/{anchor.rs, mod.rs}, tui/simnet.rs} Replaced standard channels with crossbeam::channel, revised deployment logic in handle_start_simnet_command, updated runbook execution (signature change, manifest tweaks, removal of background progress thread), modified scaffolding to generate runbooks with new templates and name collision checks, and enhanced TUI event handling (new fields, select! for concurrent channel listening, and reduced polling interval).
core/src/rpc/{accounts_data.rs, bank_data.rs, full.rs, minimal.rs, mod.rs} In RPC modules, commented out debug prints, implemented get_minimum_balance_for_rent_exemption, added a concrete get_signature_statuses implementation and modified send_transaction (now including a context ID), updated balance and epoch methods to retrieve state data, and introduced a unique id field with tuple-based mempool messaging.
core/src/simnet/mod.rs Modified start function to spawn the server in a dedicated thread using crossbeam_channel and to adjust transaction tuple handling for improved concurrency management.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant CLI as CLI Handler
    participant DF as Framework Detector
    participant SC as Scaffold Builder
    participant EX as Runbook Executor
    participant LG as Event Logger

    U->>CLI: Invoke simnet command
    CLI->>DF: Call detect_program_frameworks
    alt Framework detected
        CLI->>U: Prompt for program selection
        U->>CLI: Return selected programs
        CLI->>SC: Build runbook layout with selected programs
        CLI->>EX: Execute runbook ("deployment")
    else Error detected
        CLI->>LG: Log error and assign None deployment
    end
    CLI->>LG: Begin logging events (with deploy_progress_rx)
Loading
sequenceDiagram
    participant T as TUI App
    participant SE as Simnet Events
    participant DP as Deployment Progress

    T->>T: Start event loop (using select!)
    alt Receives simnet event
        SE->>T: Send Simnet event
        T->>T: Process and update view
    else Receives deployment progress event
        DP->>T: Send BlockEvent update
        T->>T: Update status bar with new message
    end
Loading

Possibly related PRs

Poem

I hopped through lines of code, so bright,
Switching channels in my wee delight,
Runbooks refined with a gentle nudge,
Prompts and hashes form a subtle grudge,
With every update, my joy unfurls—
A bunny’s dance in deployment worlds!
🐇💻✨

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83836d4 and 5c35641.

📒 Files selected for processing (5)
  • crates/cli/src/cli/simnet/mod.rs (2 hunks)
  • crates/cli/src/runbook/mod.rs (1 hunks)
  • crates/cli/src/scaffold/anchor.rs (3 hunks)
  • crates/cli/src/scaffold/mod.rs (9 hunks)
  • crates/core/src/simnet/mod.rs (2 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

# Conflicts:
#	crates/cli/src/cli/simnet/mod.rs
#	crates/cli/src/scaffold/mod.rs
#	crates/cli/src/tui/simnet.rs
Copy link

@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: 5

🔭 Outside diff range comments (1)
crates/cli/src/runbook/mod.rs (1)

74-79: Remove duplicate error handling block.

This error handling block is redundant as it's already handled by the previous block at lines 64-72.

-    if let Err(diags) = res {
-        for diag in diags.iter() {
-            println!("{} {}", red!("x"), diag);
-        }
-        std::process::exit(1);
-    }
🧹 Nitpick comments (14)
crates/cli/src/scaffold/mod.rs (9)

26-26: Check for possible misalignment with other frameworks.

The conditional logic to detect an Anchor project might lead to confusion if multiple frameworks are detected or partially present. Consider clarifying or logging when multiple frameworks match, to aid in debugging.


77-77: Redundant empty line.

This line is just a placeholder comment or whitespace. Verify if it’s intentional or can be removed to keep the code tidy.


96-99: Initializing runbook_src.

Concatenating multiple template strings is fine. Consider grouping these template additions in a dedicated function or builder pattern to improve readability.


107-112: signer_testnet construction repeats.

Repetitive code blocks for each environment might benefit from a helper function that generates signer templates. This will reduce duplication and potential drift among environments.


114-119: signer_simnet construction.

Similar to earlier signers, consider consolidating the environment-based signer creation logic into a single function or data-driven approach.


133-142: Creating a RunbookMetadata struct.

Storing a short description is helpful. Any chance we want a more detailed or dynamic description (e.g., including environment details)? Just a thought.


170-181: Environment config for localnet and devnet.

Adding these environment entries is convenient. Consider adding mainnet by default, or clarifying that mainnet environment is intentionally omitted from the manifest.


240-254: Generating main.tx.

You're writing the runbook source to main.tx. Consider also generating a default “readme” statement in the file that references usage instructions, so new users can quickly see how to run that script.


300-309: Confirmation logic with no revert/rollback.

Pressing “no” leaves behind partially created files. Consider an optional cleanup step if the user cancels. This can prevent clutter or confusion on canceled deployments.

crates/cli/src/tui/simnet.rs (3)

101-102: Introducing status_bar_message.

Adding a transient status bar message is helpful for user feedback. Confirm that messages clear at the right times to avoid user confusion.


179-239: New select! usage integrated with simnet events.

This concurrency pattern is a clear improvement. However, ensure that no event branch starves the other (especially if deploy_progress_rx is very active).


269-269: Empty default block in select!.

This is effectively a “non-blocking” check. If no messages exist, the loop continues. This non-blocking approach is valid but keep an eye on CPU usage when combined with the tight 3 ms poll.

crates/cli/src/runbook/mod.rs (1)

41-42: Consider making the environment configurable.

The hardcoded "localnet" value reduces flexibility. Consider making this configurable through a parameter or environment variable.

crates/core/src/rpc/mod.rs (1)

27-30: LGTM! Consider adding documentation.

Good addition of unique identifiers for transaction tracking. Consider adding documentation to explain:

  • The purpose of the id field
  • The relationship between Hash and VersionedTransaction in the tuple
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 09ddb23 and 83836d4.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (16)
  • Cargo.toml (1 hunks)
  • crates/cli/Cargo.toml (2 hunks)
  • crates/cli/src/cli/mod.rs (1 hunks)
  • crates/cli/src/cli/simnet/mod.rs (3 hunks)
  • crates/cli/src/runbook/mod.rs (3 hunks)
  • crates/cli/src/scaffold/anchor.rs (2 hunks)
  • crates/cli/src/scaffold/mod.rs (10 hunks)
  • crates/cli/src/tui/simnet.rs (9 hunks)
  • crates/core/Cargo.toml (1 hunks)
  • crates/core/src/lib.rs (1 hunks)
  • crates/core/src/rpc/accounts_data.rs (1 hunks)
  • crates/core/src/rpc/bank_data.rs (1 hunks)
  • crates/core/src/rpc/full.rs (2 hunks)
  • crates/core/src/rpc/minimal.rs (1 hunks)
  • crates/core/src/rpc/mod.rs (4 hunks)
  • crates/core/src/simnet/mod.rs (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Cargo.toml
🔇 Additional comments (32)
crates/cli/src/scaffold/mod.rs (7)

1-2: Additions to imports look good.

You've introduced Confirm and other dialoguer utilities, as well as specialized template functions. This is helpful for streamlined user prompts and templating. No issues noted.


8-8: Expanded import for FileLocation and AuthorizationContext.

This import suggests new usage of these functionalities. Ensure they’re leveraged securely and tested for potential file system edge cases (e.g., invalid or missing paths).


51-55: Function signature changed to accept selected_programs and manifest_path.

The revised parameters look like a more direct approach to scaffolding. Double-check all callers of scaffold_runbooks_layout to ensure they supply the correct arguments, particularly for the updated manifest_path.


63-68: Target directory creation logic.

You’re building a target_location for deployments. Verify that it aligns with the standard cargo “target/” behavior or that it won’t conflict with build artifacts. Also confirm that _function_spec and _context placeholders are not needed for subsequent logic.


100-105: signer_mainnet construction.

You're preparing a dedicated runbook snippet for mainnet. Evaluate whether storing authority keypair paths in plain text is acceptable or if encryption/different handling is required to avoid potential exposure.
[security]


121-131: Iterating over selected_programs for anchor deployment templates.

This loop appears straightforward. Ensure that if multiple frameworks or non-Anchor programs are selected, the logic either fails gracefully or is extended to handle them appropriately.


224-235: Creating runbooks/deployment directory.

This logic is straightforward. Ensure your application either has the correct permissions or fails gracefully if creation is disallowed (e.g., on a read-only file system).

crates/cli/src/tui/simnet.rs (11)

2-2: Importing crossbeam concurrency primitives.

Switching to crossbeam::{channel::unbounded, select} is typically more performant than std's channels. Looks good.


13-13: Added import for time::Duration.

This aligns with decreased poll intervals below. Watch for potential CPU load increases from very frequent polling.


18-19: Importing BlockEvent and ProgressBarStatusColor.

Indicates new or deeper integration with runbook deployment statuses. Ensure that every event type is correctly handled or logged to prevent silent failures.


74-75: Safeguard for optional deploy_progress_rx.

If deploy_progress_rx is None, the code ensures minimal overhead. Good approach to gracefully handle optional concurrency.


79-83: Extended App::new signature for deployment progress.

You’ve added deploy_progress_rx to track additional events. Make sure the UI remains stable if a large volume of progress events flood in.


145-145: Updated start_app to accept deploy_progress_rx.

Ensure any code paths that call start_app are updated accordingly and tested. In multi-platform contexts, the optional parameter is a robust design.


155-155: Instantiating App with deploy_progress_rx.

All logic for receiving deployment updates is now integrated into the UI. Confirm that any concurrency edge cases (like channel closure) are handled gracefully.


172-178: Reduced polling to 3 ms.

Very frequent polling can introduce CPU overhead. Evaluate system usage under load to confirm a good balance between responsiveness and resource consumption.
[performance]


240-266: Handling BlockEvent updates.

You update the UI differently based on status color, which is great for clarity. Verify no state collisions: if multiple events arrive quickly, ensure the correct final state message is displayed.


272-272: Using 3 ms for event::poll.

As highlighted above, this is quite frequent. If it proves too CPU-heavy in production, consider adjusting or introducing exponential backoff when idle.
[performance]


482-487: Conditional footer display for status_bar_message.

Providing immediate feedback or help text is a nice UX improvement. Just confirm that partial messages do not persist if events or states change quickly.

crates/core/src/lib.rs (1)

15-15: Migration to crossbeam_channel::Sender.

Adopting crossbeam’s channels typically yields better performance and more flexible concurrency patterns than std’s MPSC. Make sure all related receiving ends are updated and tested.

crates/core/src/rpc/bank_data.rs (1)

64-71: Improve rent exemption calculation.

The current implementation:

  1. Returns a hardcoded value regardless of the data length
  2. Ignores the commitment parameter
  3. Doesn't utilize the metadata context

Consider implementing a proper calculation based on data length or documenting why a fixed value is acceptable.

crates/cli/src/cli/mod.rs (1)

16-16: Consider IPv6 compatibility.

Changing from "localhost" to "127.0.0.1" makes the binding explicit but might affect IPv6 compatibility. Consider using "::1" for IPv6 or providing both options.

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Check if IPv6 is used anywhere in the codebase
rg "::1" 

Length of output: 8


I'm not seeing any IPv6 references with the initial command. To get a clearer picture, let’s search for broader IPv6 mentions and see how the constant is used across the codebase. I'll run additional shell scripts to gather more context.


🏁 Script executed:

#!/bin/bash
echo "Searching for IPv6 related references:"
rg -i "ipv6"
echo "-----"
echo "Searching for references to DEFAULT_BINDING_ADDRESS:"
rg "DEFAULT_BINDING_ADDRESS"

Length of output: 447


IPv6 Compatibility Consideration – No Immediate Impact Detected

  • The search for IPv6-related references (e.g., "::1" or case-insensitive "ipv6") in the repository returned no hits.
  • The constant DEFAULT_BINDING_ADDRESS (now set to "127.0.0.1") is used exclusively in an IPv4 context with no current indication of IPv6 support in the codebase.
  • While this change makes the address explicit, it may affect future IPv6 compatibility if needed. Consider documenting or revisiting this should IPv6 support become a requirement.
crates/core/src/rpc/accounts_data.rs (1)

78-81: LGTM! Removed debug prints.

Good cleanup of debug print statements, keeping the code clean for production.

crates/cli/src/cli/simnet/mod.rs (2)

25-25: Good choice using crossbeam channels.

Using crossbeam::channel instead of std::sync::mpsc is a good improvement as it provides better performance and more features.


61-84: Well-structured deployment UI and error handling.

Good improvements:

  • User-friendly colored multi-select prompt for program selection
  • Proper error handling with logging
  • Clean separation of deployment progress tracking
crates/core/src/simnet/mod.rs (1)

104-104: LGTM! Improved transaction handling.

The tuple pattern matching in mempool_rx.try_recv() makes the code more explicit about the data structure being handled.

crates/cli/src/scaffold/anchor.rs (1)

13-15: LGTM! Better separation of concerns.

Good refactoring to remove runbook source generation from this function, making it more focused on its primary responsibility of detecting programs.

crates/core/src/rpc/minimal.rs (2)

143-147: LGTM!

The get_slot implementation correctly retrieves the current slot from the system variable.


178-186: LGTM!

The get_version implementation correctly returns the default version information.

crates/core/src/rpc/full.rs (1)

296-296: LGTM!

The send_transaction implementation correctly includes the context ID when sending to mempool.

crates/cli/Cargo.toml (2)

40-40: LGTM!

Adding crossbeam dependency aligns with the concurrent processing changes in the codebase.


22-22: Verify compatibility with the new txtx-addon-network-svm version.

The dependency version has been updated to 0.1.1.

crates/core/Cargo.toml (1)

40-40: LGTM!

Adding crossbeam dependency is consistent with its addition in cli/Cargo.toml and aligns with the concurrent processing changes.

Comment on lines 261 to 296
let mut base_dir = runbook_file_location.get_parent_location().unwrap();
base_dir.append_path(&format!("signers.localnet.tx"))?;
let _ =
File::create(base_dir.to_string()).expect("creation failed");
base_dir.write_content(signer_simnet.as_bytes())?;
println!(
"{} {}",
green!("Created runbook"),
base_dir
.get_relative_path_from_base(&base_location)
.unwrap()
);
let mut base_dir = base_dir.get_parent_location().unwrap();
base_dir.append_path(&format!("signers.testnet.tx"))?;
let _ =
File::create(base_dir.to_string()).expect("creation failed");
base_dir.write_content(signer_testnet.as_bytes())?;
println!(
"{} {}",
green!("Created runbook"),
base_dir
.get_relative_path_from_base(&base_location)
.unwrap()
);
let mut base_dir = base_dir.get_parent_location().unwrap();
base_dir.append_path(&format!("signers.mainnet.tx"))?;
let _ =
File::create(base_dir.to_string()).expect("creation failed");
base_dir.write_content(signer_mainnet.as_bytes())?;
println!(
"{} {}",
green!("Created runbook"),
base_dir
.get_relative_path_from_base(&base_location)
.unwrap()
);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Creating signer files for localnet, testnet, and mainnet.

The repeated code for each environment can be extracted into a helper function to reduce duplication. Also, verify that writing these keypair references to disk aligns with your security posture.

Comment on lines +144 to +151
let mut collision = false;
for r in manifest.runbooks.iter() {
if r.name.eq(&runbook.name) {
collision = true;
}
}
if !collision {
manifest.runbooks.push(runbook);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Collision detection with no fallback solution.

If a runbook with the same name exists, the code sets collision = true but the // todo remains. This might cause silent overwrites or inconsistent states. Recommend handling collisions explicitly (abort, rename, or prompt user).

+        return Err(format!(
+            "A runbook named '{}' already exists. Please rename or remove it.",
+            runbook.name
+        ));

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 85 to 88
let server = ServerBuilder::new(io)
.cors(DomainsValidation::Disabled)
.start_http(&server_bind).unwrap();
let _ = simnet_events_tx_copy.send(SimnetEvent::Ready);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider better error handling for server initialization.

Using unwrap() could cause panic if server initialization fails. Consider proper error handling:

-        let server = ServerBuilder::new(io)
-            .cors(DomainsValidation::Disabled)
-            .start_http(&server_bind).unwrap();
+        let server = match ServerBuilder::new(io)
+            .cors(DomainsValidation::Disabled)
+            .start_http(&server_bind) {
+                Ok(server) => server,
+                Err(e) => {
+                    let _ = simnet_events_tx_copy.send(SimnetEvent::Aborted(format!("Failed to start server: {}", e)));
+                    return;
+                }
+            };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let server = ServerBuilder::new(io)
.cors(DomainsValidation::Disabled)
.start_http(&server_bind).unwrap();
let _ = simnet_events_tx_copy.send(SimnetEvent::Ready);
let server = match ServerBuilder::new(io)
.cors(DomainsValidation::Disabled)
.start_http(&server_bind) {
Ok(server) => server,
Err(e) => {
let _ = simnet_events_tx_copy.send(SimnetEvent::Aborted(format!("Failed to start server: {}", e)));
return;
}
};
let _ = simnet_events_tx_copy.send(SimnetEvent::Ready);

Comment on lines +103 to +110
// println!("get_balance rpc request received: {:?}", pubkey_str);
let pubkey = verify_pubkey(&pubkey_str)?;
// meta.get_balance(&pubkey, config.unwrap_or_default())
unimplemented!()
let state_reader = meta.get_state()?;
let res = RpcResponse {
context: RpcResponseContext::new(state_reader.epoch_info.absolute_slot),
value: 10000,
};
Ok(res)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Hardcoded balance value needs attention.

The implementation returns a hardcoded balance of 10000, which may not be suitable for production use.

Consider implementing actual balance retrieval:

-        let res = RpcResponse {
-            context: RpcResponseContext::new(state_reader.epoch_info.absolute_slot),
-            value: 10000,
-        };
+        let balance = state_reader.svm.get_balance(&pubkey)
+            .map_err(|e| Error::invalid_params(format!("Failed to get balance: {}", e)))?;
+        let res = RpcResponse {
+            context: RpcResponseContext::new(state_reader.epoch_info.absolute_slot),
+            value: balance,
+        };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// println!("get_balance rpc request received: {:?}", pubkey_str);
let pubkey = verify_pubkey(&pubkey_str)?;
// meta.get_balance(&pubkey, config.unwrap_or_default())
unimplemented!()
let state_reader = meta.get_state()?;
let res = RpcResponse {
context: RpcResponseContext::new(state_reader.epoch_info.absolute_slot),
value: 10000,
};
Ok(res)
// println!("get_balance rpc request received: {:?}", pubkey_str);
let pubkey = verify_pubkey(&pubkey_str)?;
let state_reader = meta.get_state()?;
let balance = state_reader.svm.get_balance(&pubkey)
.map_err(|e| Error::invalid_params(format!("Failed to get balance: {}", e)))?;
let res = RpcResponse {
context: RpcResponseContext::new(state_reader.epoch_info.absolute_slot),
value: balance,
};
Ok(res)

Comment on lines +219 to 236
let mut statuses = vec![];
for sig in signature_strs.iter() {
statuses.push(Some(TransactionStatus {
slot: 0,
confirmations: Some(5),
status: Ok(()),
err: None,
confirmation_status: Some(TransactionConfirmationStatus::Finalized),
}));
}

let res = RpcResponse {
context: RpcResponseContext::new(0),
value: statuses,
};

Box::pin(future::ready(Ok(res)))
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Hardcoded transaction status needs attention.

The implementation returns hardcoded values for transaction statuses, which may not reflect actual transaction states.

Consider implementing actual transaction status retrieval:

-        let mut statuses = vec![];
-        for sig in signature_strs.iter() {
-            statuses.push(Some(TransactionStatus {
-                slot: 0,
-                confirmations: Some(5),
-                status: Ok(()),
-                err: None,
-                confirmation_status: Some(TransactionConfirmationStatus::Finalized),
-            }));
-        }
+        let state_reader = meta.get_state()?;
+        let mut statuses = vec![];
+        for sig_str in signature_strs.iter() {
+            let signature = Signature::from_str(sig_str)
+                .map_err(|err| Error::invalid_params(format!("Invalid signature: {}", err)))?;
+            let status = state_reader.svm.get_signature_status(&signature)?;
+            statuses.push(status);
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let mut statuses = vec![];
for sig in signature_strs.iter() {
statuses.push(Some(TransactionStatus {
slot: 0,
confirmations: Some(5),
status: Ok(()),
err: None,
confirmation_status: Some(TransactionConfirmationStatus::Finalized),
}));
}
let res = RpcResponse {
context: RpcResponseContext::new(0),
value: statuses,
};
Box::pin(future::ready(Ok(res)))
}
let state_reader = meta.get_state()?;
let mut statuses = vec![];
for sig_str in signature_strs.iter() {
let signature = Signature::from_str(sig_str)
.map_err(|err| Error::invalid_params(format!("Invalid signature: {}", err)))?;
let status = state_reader.svm.get_signature_status(&signature)?;
statuses.push(status);
}
let res = RpcResponse {
context: RpcResponseContext::new(0),
value: statuses,
};
Box::pin(future::ready(Ok(res)))
}

@lgalabru lgalabru merged commit 99ac952 into main Feb 5, 2025
2 of 3 checks passed
@lgalabru lgalabru deleted the feat/deployments-part-ii branch February 5, 2025 18:31
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