Skip to content
Closed

wasm #5084

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
5bcfded
fix: upgrade viper that supports wasm
v1rtl Apr 26, 2025
12875e7
chore: bump libp2p trying to fix webrtc errors
v1rtl Apr 26, 2025
c516890
fix: prevent undefined errors for unreachable errors
v1rtl Apr 26, 2025
9a75730
fix: only add tcp transport if not compiling to wasm
v1rtl Apr 26, 2025
d63a87f
fix: upgrade go-ethereum to remove compilation errors from it
v1rtl Apr 26, 2025
2804620
make it compile to wasi
v1rtl Apr 26, 2025
3daeab9
add make entry
v1rtl Apr 26, 2025
3243e65
almost working web version
v1rtl May 1, 2025
0884958
wip: prepare bee to externalize libp2p to JS
v1rtl May 1, 2025
b869abe
implement wasm ws transport for libp2p and partially wrap fs
v1rtl May 2, 2025
8fe81d8
virtual filesystem everywhere
v1rtl May 2, 2025
46a08d4
regenerate keys
v1rtl May 2, 2025
aa42b70
wip fix wasmws transport
v1rtl May 2, 2025
d372135
use a working wswasm transport
v1rtl May 4, 2025
f8b1816
fix: skip tcp underlays when targeting browsers
v1rtl May 4, 2025
bfbe845
feat: attempt at making bee api available over sw in wasm
v1rtl May 5, 2025
85780b9
feat: worker bee
v1rtl May 5, 2025
d44c696
enable local pushsync
v1rtl May 5, 2025
e0404b4
basic styling
v1rtl May 5, 2025
7c724a1
Merge branch 'master' of https://github.com/ethersphere/bee into wasm
v1rtl May 5, 2025
e5c6f0c
separate native and wasm stuff further
v1rtl May 10, 2025
7d8a8c5
implement stub endpoints to avoid any issues with runtime
v1rtl May 10, 2025
ee1f14c
move windows-only usage to separate files
v1rtl May 11, 2025
9e12f82
prepare wasm binary for release and move system-only endpoints for no…
v1rtl May 11, 2025
9cd472d
disable checkbook for demo
v1rtl May 11, 2025
cf28bbe
upgrade all deps to see if it helps decreasing binary size
v1rtl May 11, 2025
b1f5e99
fix error on chrome
v1rtl May 11, 2025
ae2dec3
Merge branch 'master' of https://github.com/ethersphere/bee into wasm
v1rtl May 11, 2025
eac8fed
Merge branch 'master' of https://github.com/ethersphere/bee into wasm
v1rtl May 13, 2025
69788d9
switch to testnet
v1rtl May 13, 2025
39e008a
strip ~1MB from from bee wasm build
v1rtl May 14, 2025
889a15f
Merge branch 'master' of https://github.com/ethersphere/bee into wasm
v1rtl May 28, 2025
f23bd47
Revert "Merge branch 'master' of https://github.com/ethersphere/bee i…
v1rtl May 28, 2025
29f471a
fix: exclude irrelevant such as NAT and dev mode from wasm
v1rtl May 28, 2025
a18ddc9
fix: exclude irrelevant commands from bee wasm
v1rtl May 28, 2025
48cc669
fix: exclude more stuff from wasm build
v1rtl May 28, 2025
1c49a85
fix: use custom go-ethereum and try to get rid of prometheus in impor…
v1rtl May 28, 2025
de7eb76
remove api metrics from the bundle
v1rtl May 30, 2025
635c9fe
exclude some metrics from wasm
v1rtl May 30, 2025
b5ea06d
remove retrieval metrics from wasm
v1rtl May 30, 2025
f38f8d6
move pusher analytics out of wasm
v1rtl May 30, 2025
5f3d44e
move metrics for pushsync and pullsync out of wasm too
v1rtl May 30, 2025
59ec05b
move metrics out of api and accounting for wasm
v1rtl May 30, 2025
1f23df2
remove more prometheus
v1rtl May 30, 2025
0a0be51
exclude prometheus stuff more
v1rtl May 30, 2025
01a7c26
remove metrics from storer and topology too
v1rtl May 30, 2025
3519e24
remove analytics from sharky for wasm
v1rtl May 30, 2025
1686f63
remove wrapped tx metrics from wasm build
v1rtl May 30, 2025
aaa1560
exclude metrics from logger in wasm build
v1rtl May 30, 2025
26e31ae
further decrease the wasm binary
v1rtl May 30, 2025
63db194
move libp2p options to separate files
v1rtl May 30, 2025
f30b041
remove metrics from handshake
v1rtl May 30, 2025
80e706a
remove metrics from reacher
v1rtl May 30, 2025
fb23176
exclude metrics from js completely
v1rtl May 31, 2025
db79628
remoe autonat from wasm build
v1rtl May 31, 2025
806f42a
update params
v1rtl Jun 9, 2025
e46c46c
force convert underlays to ws
v1rtl Jun 10, 2025
5bae01a
bump deps
v1rtl Aug 4, 2025
a8239de
fix(salud): use exponential backoff for wake up of salud check (#5109)
gacevicljubisa Jun 3, 2025
9b9a5a7
merge
v1rtl Aug 4, 2025
43601a5
chore: bump handshake protocol version to v14.0.0 (#5120)
martinconic Jun 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/dist
/.idea
/.vscode
/tmp
Expand Down Expand Up @@ -29,3 +28,6 @@ _testmain.go
*.prof

.DS_Store

dist/bee*
dist/sw_bundle.js
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,9 @@ clean:
$(GO) clean
rm -rf dist/

FORCE:
FORCE:

wasm:
GOOS=js GOARCH=wasm go build -o ./dist/bee.wasm ./cmd/bee
wasm-release:
GOOS=js GOARCH=wasm go build -trimpath -o ./dist/bee.wasm -ldflags="-s -w" ./cmd/bee
246 changes: 2 additions & 244 deletions cmd/bee/cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -1,104 +1,17 @@
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !js
// +build !js

package cmd

import (
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"time"

chaincfg "github.com/ethersphere/bee/v2/pkg/config"
"github.com/ethersphere/bee/v2/pkg/log"
"github.com/ethersphere/bee/v2/pkg/node"
"github.com/ethersphere/bee/v2/pkg/swarm"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

const (
optionNameDataDir = "data-dir"
optionNameCacheCapacity = "cache-capacity"
optionNameDBOpenFilesLimit = "db-open-files-limit"
optionNameDBBlockCacheCapacity = "db-block-cache-capacity"
optionNameDBWriteBufferSize = "db-write-buffer-size"
optionNameDBDisableSeeksCompaction = "db-disable-seeks-compaction"
optionNamePassword = "password"
optionNamePasswordFile = "password-file"
optionNameAPIAddr = "api-addr"
optionNameP2PAddr = "p2p-addr"
optionNameNATAddr = "nat-addr"
optionNameP2PWSEnable = "p2p-ws-enable"
optionNameBootnodes = "bootnode"
optionNameNetworkID = "network-id"
optionWelcomeMessage = "welcome-message"
optionCORSAllowedOrigins = "cors-allowed-origins"
optionNameTracingEnabled = "tracing-enable"
optionNameTracingEndpoint = "tracing-endpoint"
optionNameTracingHost = "tracing-host"
optionNameTracingPort = "tracing-port"
optionNameTracingServiceName = "tracing-service-name"
optionNameVerbosity = "verbosity"
optionNamePaymentThreshold = "payment-threshold"
optionNamePaymentTolerance = "payment-tolerance-percent"
optionNamePaymentEarly = "payment-early-percent"
optionNameResolverEndpoints = "resolver-options"
optionNameBootnodeMode = "bootnode-mode"
optionNameBlockchainRpcEndpoint = "blockchain-rpc-endpoint"
optionNameSwapFactoryAddress = "swap-factory-address"
optionNameSwapInitialDeposit = "swap-initial-deposit"
optionNameSwapEnable = "swap-enable"
optionNameChequebookEnable = "chequebook-enable"
optionNameFullNode = "full-node"
optionNamePostageContractAddress = "postage-stamp-address"
optionNamePostageContractStartBlock = "postage-stamp-start-block"
optionNamePriceOracleAddress = "price-oracle-address"
optionNameRedistributionAddress = "redistribution-address"
optionNameStakingAddress = "staking-address"
optionNameBlockTime = "block-time"
optionWarmUpTime = "warmup-time"
optionNameMainNet = "mainnet"
optionNameRetrievalCaching = "cache-retrieval"
optionNameDevReserveCapacity = "dev-reserve-capacity"
optionNameResync = "resync"
optionNamePProfBlock = "pprof-profile"
optionNamePProfMutex = "pprof-mutex"
optionNameStaticNodes = "static-nodes"
optionNameAllowPrivateCIDRs = "allow-private-cidrs"
optionNameSleepAfter = "sleep-after"
optionNameUsePostageSnapshot = "use-postage-snapshot"
optionNameStorageIncentivesEnable = "storage-incentives-enable"
optionNameStateStoreCacheCapacity = "statestore-cache-capacity"
optionNameTargetNeighborhood = "target-neighborhood"
optionNameNeighborhoodSuggester = "neighborhood-suggester"
optionNameWhitelistedWithdrawalAddress = "withdrawal-addresses-whitelist"
optionNameTransactionDebugMode = "transaction-debug-mode"
optionMinimumStorageRadius = "minimum-storage-radius"
optionReserveCapacityDoubling = "reserve-capacity-doubling"
optionSkipPostageSnapshot = "skip-postage-snapshot"
)

// nolint:gochecknoinits
func init() {
cobra.EnableCommandSorting = false
}

type command struct {
root *cobra.Command
config *viper.Viper
passwordReader passwordReader
cfgFile string
homeDir string
isWindowsService bool
}

type option func(*command)

func newCommand(opts ...option) (c *command, err error) {
c = &command{
root: &cobra.Command{
Expand Down Expand Up @@ -126,10 +39,6 @@ func newCommand(opts ...option) (c *command, err error) {

c.initGlobalFlags()

if err := c.initCommandVariables(); err != nil {
return nil, err
}

if err := c.initStartCmd(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -159,139 +68,6 @@ func newCommand(opts ...option) (c *command, err error) {
return c, nil
}

func (c *command) Execute() (err error) {
return c.root.Execute()
}

// Execute parses command line arguments and runs appropriate functions.
func Execute() (err error) {
c, err := newCommand()
if err != nil {
return err
}
return c.Execute()
}

func (c *command) initGlobalFlags() {
globalFlags := c.root.PersistentFlags()
globalFlags.StringVar(&c.cfgFile, "config", "", "config file (default is $HOME/.bee.yaml)")
}

func (c *command) initCommandVariables() error {
isWindowsService, err := isWindowsService()
if err != nil {
return fmt.Errorf("failed to determine if we are running in service: %w", err)
}

c.isWindowsService = isWindowsService

return nil
}

func (c *command) initConfig() (err error) {
config := viper.New()
configName := ".bee"
if c.cfgFile != "" {
// Use config file from the flag.
config.SetConfigFile(c.cfgFile)
} else {
// Search config in home directory with name ".bee" (without extension).
config.AddConfigPath(c.homeDir)
config.SetConfigName(configName)
}

// Environment
config.SetEnvPrefix("bee")
config.AutomaticEnv() // read in environment variables that match
config.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))

if c.homeDir != "" && c.cfgFile == "" {
c.cfgFile = filepath.Join(c.homeDir, configName+".yaml")
}

// If a config file is found, read it in.
if err := config.ReadInConfig(); err != nil {
var e viper.ConfigFileNotFoundError
if !errors.As(err, &e) {
return err
}
}
c.config = config
return nil
}

func (c *command) setHomeDir() (err error) {
if c.homeDir != "" {
return
}
dir, err := os.UserHomeDir()
if err != nil {
return err
}
c.homeDir = dir
return nil
}

func (c *command) setAllFlags(cmd *cobra.Command) {
cmd.Flags().String(optionNameDataDir, filepath.Join(c.homeDir, ".bee"), "data directory")
cmd.Flags().Uint64(optionNameCacheCapacity, 1_000_000, fmt.Sprintf("cache capacity in chunks, multiply by %d to get approximate capacity in bytes", swarm.ChunkSize))
cmd.Flags().Uint64(optionNameDBOpenFilesLimit, 200, "number of open files allowed by database")
cmd.Flags().Uint64(optionNameDBBlockCacheCapacity, 32*1024*1024, "size of block cache of the database in bytes")
cmd.Flags().Uint64(optionNameDBWriteBufferSize, 32*1024*1024, "size of the database write buffer in bytes")
cmd.Flags().Bool(optionNameDBDisableSeeksCompaction, true, "disables db compactions triggered by seeks")
cmd.Flags().String(optionNamePassword, "", "password for decrypting keys")
cmd.Flags().String(optionNamePasswordFile, "", "path to a file that contains password for decrypting keys")
cmd.Flags().String(optionNameAPIAddr, "127.0.0.1:1633", "HTTP API listen address")
cmd.Flags().String(optionNameP2PAddr, ":1634", "P2P listen address")
cmd.Flags().String(optionNameNATAddr, "", "NAT exposed address")
cmd.Flags().Bool(optionNameP2PWSEnable, false, "enable P2P WebSocket transport")
cmd.Flags().StringSlice(optionNameBootnodes, []string{"/dnsaddr/mainnet.ethswarm.org"}, "initial nodes to connect to")
cmd.Flags().Uint64(optionNameNetworkID, chaincfg.Mainnet.NetworkID, "ID of the Swarm network")
cmd.Flags().StringSlice(optionCORSAllowedOrigins, []string{}, "origins with CORS headers enabled")
cmd.Flags().Bool(optionNameTracingEnabled, false, "enable tracing")
cmd.Flags().String(optionNameTracingEndpoint, "127.0.0.1:6831", "endpoint to send tracing data")
cmd.Flags().String(optionNameTracingHost, "", "host to send tracing data")
cmd.Flags().String(optionNameTracingPort, "", "port to send tracing data")
cmd.Flags().String(optionNameTracingServiceName, "bee", "service name identifier for tracing")
cmd.Flags().String(optionNameVerbosity, "info", "log verbosity level 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=trace")
cmd.Flags().String(optionWelcomeMessage, "", "send a welcome message string during handshakes")
cmd.Flags().String(optionNamePaymentThreshold, "13500000", "threshold in BZZ where you expect to get paid from your peers")
cmd.Flags().Int64(optionNamePaymentTolerance, 25, "excess debt above payment threshold in percentages where you disconnect from your peer")
cmd.Flags().Int64(optionNamePaymentEarly, 50, "percentage below the peers payment threshold when we initiate settlement")
cmd.Flags().StringSlice(optionNameResolverEndpoints, []string{}, "ENS compatible API endpoint for a TLD and with contract address, can be repeated, format [tld:][contract-addr@]url")
cmd.Flags().Bool(optionNameBootnodeMode, false, "cause the node to always accept incoming connections")
cmd.Flags().String(optionNameBlockchainRpcEndpoint, "", "rpc blockchain endpoint")
cmd.Flags().String(optionNameSwapFactoryAddress, "", "swap factory addresses")
cmd.Flags().String(optionNameSwapInitialDeposit, "0", "initial deposit if deploying a new chequebook")
cmd.Flags().Bool(optionNameSwapEnable, false, "enable swap")
cmd.Flags().Bool(optionNameChequebookEnable, true, "enable chequebook")
cmd.Flags().Bool(optionNameFullNode, false, "cause the node to start in full mode")
cmd.Flags().String(optionNamePostageContractAddress, "", "postage stamp contract address")
cmd.Flags().Uint64(optionNamePostageContractStartBlock, 0, "postage stamp contract start block number")
cmd.Flags().String(optionNamePriceOracleAddress, "", "price oracle contract address")
cmd.Flags().String(optionNameRedistributionAddress, "", "redistribution contract address")
cmd.Flags().String(optionNameStakingAddress, "", "staking contract address")
cmd.Flags().Uint64(optionNameBlockTime, 5, "chain block time")
cmd.Flags().Duration(optionWarmUpTime, time.Minute*5, "maximum node warmup duration; proceeds when stable or after this time")
cmd.Flags().Bool(optionNameMainNet, true, "triggers connect to main net bootnodes.")
cmd.Flags().Bool(optionNameRetrievalCaching, true, "enable forwarded content caching")
cmd.Flags().Bool(optionNameResync, false, "forces the node to resync postage contract data")
cmd.Flags().Bool(optionNamePProfBlock, false, "enable pprof block profile")
cmd.Flags().Bool(optionNamePProfMutex, false, "enable pprof mutex profile")
cmd.Flags().StringSlice(optionNameStaticNodes, []string{}, "protect nodes from getting kicked out on bootnode")
cmd.Flags().Bool(optionNameAllowPrivateCIDRs, false, "allow to advertise private CIDRs to the public network")
cmd.Flags().Bool(optionNameUsePostageSnapshot, false, "bootstrap node using postage snapshot from the network")
cmd.Flags().Bool(optionNameStorageIncentivesEnable, true, "enable storage incentives feature")
cmd.Flags().Uint64(optionNameStateStoreCacheCapacity, 100_000, "lru memory caching capacity in number of statestore entries")
cmd.Flags().String(optionNameTargetNeighborhood, "", "neighborhood to target in binary format (ex: 111111001) for mining the initial overlay")
cmd.Flags().String(optionNameNeighborhoodSuggester, "https://api.swarmscan.io/v1/network/neighborhoods/suggestion", "suggester for target neighborhood")
cmd.Flags().StringSlice(optionNameWhitelistedWithdrawalAddress, []string{}, "withdrawal target addresses")
cmd.Flags().Bool(optionNameTransactionDebugMode, false, "skips the gas estimate step for contract transactions")
cmd.Flags().Uint(optionMinimumStorageRadius, 0, "minimum radius storage threshold")
cmd.Flags().Int(optionReserveCapacityDoubling, 0, "reserve capacity doubling")
cmd.Flags().Bool(optionSkipPostageSnapshot, false, "skip postage snapshot")
}

func newLogger(cmd *cobra.Command, verbosity string) (log.Logger, error) {
var (
sink = cmd.OutOrStdout()
Expand Down Expand Up @@ -326,21 +102,3 @@ func newLogger(cmd *cobra.Command, verbosity string) (log.Logger, error) {
log.WithVerbosity(vLevel),
).Register(), nil
}

func (c *command) CheckUnknownParams(cmd *cobra.Command, args []string) error {
if err := c.initConfig(); err != nil {
return err
}
var unknownParams []string
for _, v := range c.config.AllKeys() {
if cmd.Flags().Lookup(v) == nil {
unknownParams = append(unknownParams, v)
}
}

if len(unknownParams) > 0 {
return fmt.Errorf("unknown parameters:\n\t%v", strings.Join(unknownParams, "\n\t"))
}

return nil
}
91 changes: 91 additions & 0 deletions cmd/bee/cmd/cmd_js.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//go:build js
// +build js

package cmd

import (
"fmt"
"io"

"github.com/ethersphere/bee/v2/pkg/log"
"github.com/ethersphere/bee/v2/pkg/node"
"github.com/spf13/cobra"
)

func newCommand(opts ...option) (c *command, err error) {
c = &command{
root: &cobra.Command{
Use: "bee",
Short: "Ethereum Swarm Bee",
SilenceErrors: true,
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return c.initConfig()
},
},
}

for _, o := range opts {
o(c)
}
if c.passwordReader == nil {
c.passwordReader = new(stdInPasswordReader)
}

// Find home directory.
if err := c.setHomeDir(); err != nil {
return nil, err
}

c.initGlobalFlags()

if err := c.initStartCmd(); err != nil {
return nil, err
}

if err := c.initInitCmd(); err != nil {
return nil, err
}

c.initVersionCmd()
c.initDBCmd()
if err := c.initSplitCmd(); err != nil {
return nil, err
}

return c, nil
}

func newLogger(cmd *cobra.Command, verbosity string) (log.Logger, error) {
var (
sink = cmd.OutOrStdout()
vLevel = log.VerbosityNone
)

switch verbosity {
case "0", "silent":
sink = io.Discard
case "1", "error":
vLevel = log.VerbosityError
case "2", "warn":
vLevel = log.VerbosityWarning
case "3", "info":
vLevel = log.VerbosityInfo
case "4", "debug":
vLevel = log.VerbosityDebug
case "5", "trace":
vLevel = log.VerbosityDebug + 1 // For backwards compatibility, just enable v1 debugging as trace.
default:
return nil, fmt.Errorf("unknown verbosity level %q", verbosity)
}

log.ModifyDefaults(
log.WithTimestamp(),
)

return log.NewLogger(
node.LoggerName,
log.WithSink(sink),
log.WithVerbosity(vLevel),
).Register(), nil
}
Loading