Skip to content

Conversation

@v1rtl
Copy link

@v1rtl v1rtl commented Apr 26, 2025

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

How to get this running:

  1. Clone the repo
  2. gh pr checkout 5084
  3. Clone my fork of goleveldb
  4. Clone my fork of libp2p that includes WASM
  5. Build local bee node via go build -o ./dist/bee ./cmd/bee
  6. Start a local bee node in full mode and --p2p-ws-enable
  7. make wasm to produce the WASM build
  8. Change Peer ID in dist/sw.js to match your node's libp2p peer ID
  9. cd dist && bun i && bun run build
  10. Start a local web server in dist and navigate to localhost:{port}
  11. Wait for SW to install
  12. Open SW debugger and observe the logs and ensure the node connected to bootnode addresses, as well as endpoints working

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

Screenshots (if appropriate):

@v1rtl v1rtl mentioned this pull request Apr 26, 2025
@v1rtl v1rtl force-pushed the wasm branch 2 times, most recently from 9111c7e to e46c46c Compare August 4, 2025 12:44
Copy link
Contributor

@sbackend123 sbackend123 left a comment

Choose a reason for hiding this comment

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

Great job, but have a few questions/suggestions:

  1. Split this PR to a few separate.
  2. PR has a lot of refactoring like split existing logic between *_js.go and *_shared.go
    But it doesn't look like renaming, it looks like 2 new files, so it also makes review harder. In future I would suggest to avoid it.
  3. For me it is not quite clear, is the Bee browser build, is this actually a dial-only node? How is participation in overlay/DHT ensured without incoming: relay/signal/bootstrap policy? I understand, it should work somehow, but it would be great to have some doc
  4. What is planned to replace Prometheus in the browser build?
  5. how will the node behave if the peer does not support ws?

func isWindowsService() (bool, error) {
return false, nil
}
func (c *command) initStartCmd() (err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In cmd/start_windows.go and cmd/start_unix.go most of the logic is the same, with the only differences being the runtime setup (Windows Service + Event Log vs. Unix signal handling).
Maybe we could extract the shared logic into a common file and add platform-specific adapters?

Copy link
Author

Choose a reason for hiding this comment

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

you can't do platform-specific compilation by putting everything in one file. go build tags apply for the whole file

// Mutex is a drop in replacement for the sync.Mutex
// it will not lock if the context is expired
type Mutex struct {
mu chan struct{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we use sync.Mutex here instead of channel?
Looks like chan was added only for ctx expiration case, but I think it is possible to handle context expiration without creating our own version of mutex.
Or I miss smth?

Copy link
Author

Choose a reason for hiding this comment

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

this is copied from original bee source


func (m noOpChainBackend) CodeAt(context.Context, common.Address, *big.Int) ([]byte, error) {
return common.FromHex(sw3abi.SimpleSwapFactoryDeployedBinv0_6_9), nil
return common.FromHex(sw3abi.SimpleSwapFactoryDeployedBinv0_6_5), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Why lower version here?

Copy link
Author

Choose a reason for hiding this comment

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

the branch is very out of date from upstream so this is just an older version

return f.currOffset, nil
case io.SeekEnd:
f.currOffset = -offset
return f.currOffset, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like potential problem to me. We return negative offset and no error... So method which calls this one has to keep in mind, that offset might be negative.

case a == nil || b == nil:
return false
default:
return a.Equal(b)
Copy link
Contributor

Choose a reason for hiding this comment

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

May be instead? Logic is same, but easier to read, I think
if a == nil || b == nil { return a == nil && b == nil } return a.Equal(b)

@v1rtl
Copy link
Author

v1rtl commented Aug 26, 2025

Great job, but have a few questions/suggestions:

1. Split this PR to a few separate.

2. PR has a lot of refactoring like split existing logic between *_js.go and *_shared.go
   But it doesn't look like renaming, it looks like 2 new files, so it also makes review harder. In future I would suggest to avoid it.

3. For me it is not quite clear, is the Bee browser build, is this actually a dial-only node? How is participation in overlay/DHT ensured without incoming: relay/signal/bootstrap policy? I understand, it should work somehow, but it would be great to have some doc

4. What is planned to replace Prometheus in the browser build?

5. how will the node behave if the peer does not support ws?
  1. this branch is an experiment and isn't meant to be merged. there are some significant changes required for Bee in-browser to work properly, such as support for non-TCP addresses in overlays, until then there's no point in developing it further before that. Once all the requirements are met, I will create a new PR (or set of PRs) for proper wasm support.

  2. I did it as a temporary hack to tell go to avoid compiling certain parts of code. In later PRs I will instead use <file_native>.go / <file.go> / <file_js.go>. This would also produce less merge conflicts

  3. It's a dial only node yes. Can't listen on a TCP socket in a browser. Not sure what bootstrap policy is, the way it currently works is that it connects to a bootnode to obtain a list of peers, and runs a DHT in-browser to retrieve chunks. Other peers see browser node as localhost as if it would be running locally. When deployed on the web, those will instead be public IP addresses or website names.

  4. Nothing. Prometheus is stripped off to decrease bundle size. A lot of metrics for a browser node are irrelevant, and you wouldn't gather metrics in-browser anyway.

  5. It skips nodes with no WS available

@v1rtl
Copy link
Author

v1rtl commented Dec 7, 2025

superseeded by #5300

@v1rtl v1rtl closed this Dec 7, 2025
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.

4 participants