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

fix: usage of providerUrl in fuels dev command #3528

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

nedsalk
Copy link
Contributor

@nedsalk nedsalk commented Jan 3, 2025

Summary

The autoStartFuelCore function wasn't using the provider url returned by launchNode but was rather constructing its own url, which led to the inability to use the ephemeral port 0 because it'd construct an invalid http://127.0.0.1:0/v1/graphql url.

Checklist

  • All changes are covered by tests (or not applicable)
  • All changes are documented (or not applicable)
  • I reviewed the entire PR myself (preferably, on GH UI)
  • I described all Breaking Changes (or there's none)

@nedsalk nedsalk added the bug Issue is a bug label Jan 3, 2025
@nedsalk nedsalk self-assigned this Jan 3, 2025
Copy link

vercel bot commented Jan 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fuels-template ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 3:19pm
ts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 3:19pm
ts-docs-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 3:19pm

@nedsalk nedsalk marked this pull request as ready for review January 3, 2025 09:25
@nedsalk nedsalk marked this pull request as draft January 3, 2025 09:33
@nedsalk nedsalk force-pushed the ns/fix/fuels-dev-ephemeral-port branch from d43f113 to 84095cd Compare January 8, 2025 18:06
@@ -124,7 +124,8 @@
"vite-plugin-json5": "1.1.2",
"vite-plugin-node-polyfills": "0.22.0",
"vite-plugin-plain-text": "1.4.2",
"vitest": "2.0.5"
"vitest": "2.0.5",
"fuels": "workspace:*"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to add this so that I could run this command in the test. This is because the spawn is running in the root of the repo and there is no fuels dependency there that it can run. Upon adding it, the spawn runs as expected.

const providerUrl = `http://${accessIp}:${port}/v1/graphql`;

const { cleanup, snapshotDir } = await launchNode({
const { cleanup, url, snapshotDir } = await launchNode({
Copy link
Member

Choose a reason for hiding this comment

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

I think this PR could be reduced to this:

const port = config.fuelCorePort ?? 0;

const { cleanup, snapshotDir, url: providerUrl } = await launchNode({

And then changing the title to something like:

fix: usage of `providerUrl` in `fuels dev` command

Then, remove the portfinder if it's not used elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did consider this but was hesitant to suggest because it would be a breaking change due to the default previously being port 4000 and now it'd become a random port unless specified by the user.

I don't see a way to mitigate this breaking change technically. For example, if we set a default value for config.fuelCorePort to 4000 and then, if launchNode fails to create a node on that port that we retry with port 0, we wouldn't be able to differentiate between the default 4000 and an explicit 4000 that the user set and for which we don't want to default to 0 and retry.

We could, however, just make the PR a breaking change one and tell the users that they have to specify the fuelCorePort value now if they want their fuel-core node to always run on the same port.

Copy link
Member

Choose a reason for hiding this comment

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

How would it be a breaking change if the port is not static? Besides, if we can't start the node on the port users chose (if they do choose a port), we just throw and exit. Retries make no sense here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would always start at 4000 and probably would always stay at 4000 for the majority of users and people might have taken it as a static default, hence why I saw it as a breaking change. But you're right, we didn't guarantee it being static. I made the changes, please review again.

Copy link
Member

Choose a reason for hiding this comment

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

The tests are now failing, but you have a good point: we must consider these soft changes on behalf of users since 4000 is usually the default port used to start fuel-core, and users may be accustomed to it.

If we default to 0, which port does the search start at?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will be a random port assigned by the OS in the ephemeral port range. The below command gives the range in linux systems and is 32768 to 60999.

sysctl net.ipv4.ip_local_port_range
# net.ipv4.ip_local_port_range = 32768    60999

Copy link
Member

Choose a reason for hiding this comment

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

Ok, it's way distant than the default 4000.

Let me go back for a second here: Why can't we continue to use getPortPromise()?

const port = config.fuelCorePort ?? (await getPortPromise({ port: 4000 }));

const { cleanup, snapshotDir, url: providerUrl } = await launchNode({

@nedsalk nedsalk requested a review from arboleya January 9, 2025 08:07
@nedsalk nedsalk changed the title fix: enable usage of 0 port for the fuelCorePort field fix: usage of providerUrl in fuels dev command Jan 9, 2025
Copy link
Contributor

github-actions bot commented Jan 9, 2025

Coverage Report:

Lines Branches Functions Statements
76.9%(-0.07%) 70.35%(-0.14%) 74.89%(-0.13%) 76.9%(-0.07%)
Changed Files:
Ok File (✨=New File) Lines Branches Functions Statements
🔴 packages/account/src/providers/provider.ts 68.69%
(-0.45%)
58.08%
(+0%)
70.21%
(-1.06%)
68.42%
(-0.43%)
🔴 packages/account/src/providers/generated/operations.ts 94.03%
(-0.67%)
100%
(+0%)
81.63%
(-2.04%)
94.51%
(-0.61%)
🔴 packages/account/src/providers/transaction-request/transaction-request.ts 88.57%
(+0%)
78.08%
(+1.37%)
84%
(+0%)
88.81%
(+0%)
🔴 packages/account/src/providers/transaction-response/transaction-response.ts 76.66%
(+0.26%)
64.4%
(-1.05%)
93.75%
(+0%)
76.66%
(+0.26%)
🔴 packages/account/src/providers/transaction-summary/assemble-transaction-summary.ts 100%
(+0%)
77.77%
(+6.35%)
100%
(+0%)
100%
(+0%)
🔴 packages/account/src/providers/transaction-summary/calculate-tx-fee-for-summary.ts 100%
(+0%)
90%
(-1.66%)
100%
(+0%)
100%
(+0%)
🔴 packages/account/src/providers/transaction-summary/status.ts 100%
(+0%)
93.33%
(+2.43%)
100%
(+0%)
100%
(+0%)
🔴 packages/address/src/address.ts 90.9%
(-0.17%)
86.66%
(+0%)
85.71%
(+0%)
91.07%
(-0.15%)
🔴 packages/address/src/utils.ts 69.23%
(-9.03%)
50%
(-21.42%)
77.77%
(-9.73%)
70.37%
(-8.79%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for fuelCorePort: 0 in fuels.config.ts
2 participants