Skip to content

fix: fund wallet before peer connect#71

Open
arunabha003 wants to merge 1 commit intoStabilityNexus:mainfrom
arunabha003:fix-fund-before-connect
Open

fix: fund wallet before peer connect#71
arunabha003 wants to merge 1 commit intoStabilityNexus:mainfrom
arunabha003:fix-fund-before-connect

Conversation

@arunabha003
Copy link
Contributor

@arunabha003 arunabha003 commented Mar 23, 2026

Addressed Issues:

Summary

  • move initial --fund credit ahead of peer connection during node startup
  • ensure peers see the funded account state during initial sync instead of pre-fund state
  • keep the change scoped to startup ordering only

Additional Notes:

AI Usage Disclosure:

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.

Check one of the checkboxes below:

  • This PR does not contain AI-generated code at all.
  • [ x] This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools: TODO

Checklist

  • [ x] My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • [x ] My code follows the project's code style and conventions
  • [x ] If applicable, I have made corresponding changes or additions to the documentation
  • [x ] If applicable, I have made corresponding changes or additions to tests
  • [x ] My changes generate no new warnings or errors
  • [ x] I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • [x ] I have read the Contribution Guidelines
  • [x ] Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • [ x] I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Summary by CodeRabbit

  • Refactor
    • Adjusted the sequence of operations during node startup to ensure wallet funding occurs immediately after network initialization, before establishing peer connections.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 23, 2026

Walkthrough

The code reorders a wallet funding block in main.py to execute immediately after network startup, before optional peer-connection setup. The funding logic itself remains unchanged—same behavior, parameters, and condition check. Only the execution sequence is modified.

Changes

Cohort / File(s) Summary
Wallet Funding Reordering
main.py
Moved credit_mining_reward(pk, reward=fund) and associated logging to execute immediately after await network.start(...), prior to optional --connect peer-connection logic. No functional changes to the funding operation itself.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

Python Lang

Poem

🐰 A hop, skip, and line-shift away,
The wallet gets funded without delay,
Before peers arrive for their network play,
The funds are in place—hip, hip, hooray!

🚥 Pre-merge checks | ✅ 2
✅ 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 'fix: fund wallet before peer connect' directly and clearly describes the main change: reordering wallet funding to occur before peer connection during node startup.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@main.py`:
- Around line 331-336: The run_node function references an undefined variable
host when calling network.start(port=port, host=host); update run_node to accept
a host parameter (e.g., def run_node(..., host):) and propagate the parsed
--host value from main() into the call to run_node so network.start receives the
CLI host; ensure the run_node signature and all callers (main) are updated to
pass host and that network.start uses that host parameter.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b1a4d3f4-79a2-41fa-baf0-66082be53124

📥 Commits

Reviewing files that changed from the base of the PR and between 05ac7ea and 0e08347.

📒 Files selected for processing (1)
  • main.py

Comment on lines 331 to +336
await network.start(port=port, host=host)

# Fund this node's wallet so it can transact in the demo
if fund > 0:
chain.state.credit_mining_reward(pk, reward=fund)
logger.info("💰 Funded %s... with %d coins", pk[:12], fund)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Undefined variable host will cause a NameError.

Line 331 references host, but this variable is not defined in the run_node function scope. The --host argument is parsed in main() (line 362) but never passed to run_node().

🐛 Proposed fix: Add host parameter to run_node

Update the function signature:

-async def run_node(port: int, connect_to: str | None, fund: int, datadir: str | None):
+async def run_node(port: int, connect_to: str | None, fund: int, datadir: str | None, host: str = "127.0.0.1"):

And update the call in main():

-        asyncio.run(run_node(args.port, args.connect, args.fund, args.datadir))
+        asyncio.run(run_node(args.port, args.connect, args.fund, args.datadir, args.host))
🧰 Tools
🪛 Ruff (0.15.6)

[error] 331-331: Undefined name host

(F821)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@main.py` around lines 331 - 336, The run_node function references an
undefined variable host when calling network.start(port=port, host=host); update
run_node to accept a host parameter (e.g., def run_node(..., host):) and
propagate the parsed --host value from main() into the call to run_node so
network.start receives the CLI host; ensure the run_node signature and all
callers (main) are updated to pass host and that network.start uses that host
parameter.

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