Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/gsoc-subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
nugaon committed Oct 22, 2024
2 parents 450d973 + 253d382 commit 7134e02
Show file tree
Hide file tree
Showing 81 changed files with 1,779 additions and 997 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/beekeeper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
REPLICA: 3
RUN_TYPE: "PR RUN"
SETUP_CONTRACT_IMAGE: "ethersphere/bee-localchain"
SETUP_CONTRACT_IMAGE_TAG: "0.9.1-rc6"
SETUP_CONTRACT_IMAGE_TAG: "0.9.2-rc1"
BEELOCAL_BRANCH: "main"
BEEKEEPER_BRANCH: "master"
BEEKEEPER_METRICS_ENABLED: false
Expand Down
8 changes: 2 additions & 6 deletions cmd/bee/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ const (
optionNamePaymentEarly = "payment-early-percent"
optionNameResolverEndpoints = "resolver-options"
optionNameBootnodeMode = "bootnode-mode"
optionNameClefSignerEnable = "clef-signer-enable"
optionNameClefSignerEndpoint = "clef-signer-endpoint"
optionNameClefSignerEthereumAddress = "clef-signer-ethereum-address"
optionNameSwapEndpoint = "swap-endpoint" // deprecated: use rpc endpoint instead
optionNameBlockchainRpcEndpoint = "blockchain-rpc-endpoint"
optionNameSwapFactoryAddress = "swap-factory-address"
Expand Down Expand Up @@ -84,6 +81,7 @@ const (
optionNameWhitelistedWithdrawalAddress = "withdrawal-addresses-whitelist"
optionNameTransactionDebugMode = "transaction-debug-mode"
optionMinimumStorageRadius = "minimum-storage-radius"
optionReserveCapacityDoubling = "reserve-capacity-doubling"
)

// nolint:gochecknoinits
Expand Down Expand Up @@ -263,9 +261,6 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
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().Bool(optionNameClefSignerEnable, false, "enable clef signer")
cmd.Flags().String(optionNameClefSignerEndpoint, "", "clef signer endpoint")
cmd.Flags().String(optionNameClefSignerEthereumAddress, "", "blockchain address to use from clef signer")
cmd.Flags().String(optionNameSwapEndpoint, "", "swap blockchain endpoint") // deprecated: use rpc endpoint instead
cmd.Flags().String(optionNameBlockchainRpcEndpoint, "", "rpc blockchain endpoint")
cmd.Flags().String(optionNameSwapFactoryAddress, "", "swap factory addresses")
Expand Down Expand Up @@ -296,6 +291,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
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")
}

func newLogger(cmd *cobra.Command, verbosity string) (log.Logger, error) {
Expand Down
18 changes: 9 additions & 9 deletions cmd/bee/cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func dbInfoCmd(cmd *cobra.Command) {
Logger: logger,
RadiusSetter: noopRadiusSetter{},
Batchstore: new(postage.NoOpBatchStore),
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
CacheCapacity: 1_000_000,
})
if err != nil {
Expand Down Expand Up @@ -166,7 +166,7 @@ func dbCompactCmd(cmd *cobra.Command) {
Logger: logger,
RadiusSetter: noopRadiusSetter{},
Batchstore: new(postage.NoOpBatchStore),
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
}, validation)
if err != nil {
return fmt.Errorf("localstore: %w", err)
Expand Down Expand Up @@ -221,7 +221,7 @@ func dbValidatePinsCmd(cmd *cobra.Command) {
Logger: logger,
RadiusSetter: noopRadiusSetter{},
Batchstore: new(postage.NoOpBatchStore),
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
})
if err != nil {
return fmt.Errorf("localstore: %w", err)
Expand Down Expand Up @@ -283,7 +283,7 @@ func dbRepairReserve(cmd *cobra.Command) {
Logger: logger,
RadiusSetter: noopRadiusSetter{},
Batchstore: new(postage.NoOpBatchStore),
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
CacheCapacity: 1_000_000,
})
if err != nil {
Expand Down Expand Up @@ -347,7 +347,7 @@ func dbValidateCmd(cmd *cobra.Command) {
Logger: logger,
RadiusSetter: noopRadiusSetter{},
Batchstore: new(postage.NoOpBatchStore),
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
})
if err != nil {
return fmt.Errorf("localstore: %w", err)
Expand Down Expand Up @@ -410,7 +410,7 @@ func dbExportReserveCmd(cmd *cobra.Command) {
Logger: logger,
RadiusSetter: noopRadiusSetter{},
Batchstore: new(postage.NoOpBatchStore),
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
CacheCapacity: 1_000_000,
})
if err != nil {
Expand Down Expand Up @@ -493,7 +493,7 @@ func dbExportPinningCmd(cmd *cobra.Command) {
Logger: logger,
RadiusSetter: noopRadiusSetter{},
Batchstore: new(postage.NoOpBatchStore),
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
CacheCapacity: 1_000_000,
})
if err != nil {
Expand Down Expand Up @@ -603,7 +603,7 @@ func dbImportReserveCmd(cmd *cobra.Command) {
Logger: logger,
RadiusSetter: noopRadiusSetter{},
Batchstore: new(postage.NoOpBatchStore),
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
CacheCapacity: 1_000_000,
})
if err != nil {
Expand Down Expand Up @@ -687,7 +687,7 @@ func dbImportPinningCmd(cmd *cobra.Command) {
Logger: logger,
RadiusSetter: noopRadiusSetter{},
Batchstore: new(postage.NoOpBatchStore),
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
CacheCapacity: 1_000_000,
})
if err != nil {
Expand Down
17 changes: 8 additions & 9 deletions cmd/bee/cmd/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/ethersphere/bee/v2/cmd/bee/cmd"
"github.com/ethersphere/bee/v2/pkg/log"
"github.com/ethersphere/bee/v2/pkg/node"
"github.com/ethersphere/bee/v2/pkg/postage"
storagetest "github.com/ethersphere/bee/v2/pkg/storage/testing"
"github.com/ethersphere/bee/v2/pkg/storer"
Expand All @@ -35,7 +34,7 @@ func TestDBExportImport(t *testing.T) {
Batchstore: new(postage.NoOpBatchStore),
RadiusSetter: kademlia.NewTopologyDriver(),
Logger: testutil.NewLogger(t),
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
}, dir1)

chunks := make(map[string]int)
Expand Down Expand Up @@ -64,7 +63,7 @@ func TestDBExportImport(t *testing.T) {
Batchstore: new(postage.NoOpBatchStore),
RadiusSetter: kademlia.NewTopologyDriver(),
Logger: testutil.NewLogger(t),
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
}, dir2)

err = db2.ReserveIterateChunks(func(chunk swarm.Chunk) (bool, error) {
Expand Down Expand Up @@ -95,7 +94,7 @@ func TestDBExportImportPinning(t *testing.T) {
Batchstore: new(postage.NoOpBatchStore),
RadiusSetter: kademlia.NewTopologyDriver(),
Logger: testutil.NewLogger(t),
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
}, dir1)

chunks := make(map[string]int)
Expand Down Expand Up @@ -139,7 +138,7 @@ func TestDBExportImportPinning(t *testing.T) {
Batchstore: new(postage.NoOpBatchStore),
RadiusSetter: kademlia.NewTopologyDriver(),
Logger: testutil.NewLogger(t),
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
}, dir2)
addresses, err := db2.Pins()
if err != nil {
Expand Down Expand Up @@ -183,7 +182,7 @@ func TestDBNuke_FLAKY(t *testing.T) {
Batchstore: new(postage.NoOpBatchStore),
RadiusSetter: kademlia.NewTopologyDriver(),
Logger: log.Noop,
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
}, dataDir)

nChunks := 10
Expand Down Expand Up @@ -213,7 +212,7 @@ func TestDBNuke_FLAKY(t *testing.T) {
Batchstore: new(postage.NoOpBatchStore),
RadiusSetter: kademlia.NewTopologyDriver(),
Logger: log.Noop,
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
}, path.Join(dataDir, "localstore"))
if err != nil {
t.Fatal(err)
Expand All @@ -238,7 +237,7 @@ func TestDBInfo(t *testing.T) {
Batchstore: new(postage.NoOpBatchStore),
RadiusSetter: kademlia.NewTopologyDriver(),
Logger: testutil.NewLogger(t),
ReserveCapacity: node.ReserveCapacity,
ReserveCapacity: storer.DefaultReserveCapacity,
}, dir1)

nChunks := 10
Expand All @@ -265,7 +264,7 @@ func TestDBInfo(t *testing.T) {
t.Fatal(err)
}

if !strings.Contains(buf.String(), fmt.Sprintf("\"msg\"=\"reserve\" \"size_within_radius\"=%d \"total_size\"=%d \"capacity\"=%d", nChunks, nChunks, node.ReserveCapacity)) {
if !strings.Contains(buf.String(), fmt.Sprintf("\"msg\"=\"reserve\" \"size_within_radius\"=%d \"total_size\"=%d \"capacity\"=%d", nChunks, nChunks, storer.DefaultReserveCapacity)) {
t.Fatal("reserve info not correct")
}
}
Expand Down
72 changes: 7 additions & 65 deletions cmd/bee/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,16 @@ import (
"syscall"
"time"

"github.com/ethereum/go-ethereum/accounts/external"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethersphere/bee/v2"
"github.com/ethersphere/bee/v2/pkg/accesscontrol"
chaincfg "github.com/ethersphere/bee/v2/pkg/config"
"github.com/ethersphere/bee/v2/pkg/crypto"
"github.com/ethersphere/bee/v2/pkg/crypto/clef"
"github.com/ethersphere/bee/v2/pkg/keystore"
filekeystore "github.com/ethersphere/bee/v2/pkg/keystore/file"
memkeystore "github.com/ethersphere/bee/v2/pkg/keystore/mem"
"github.com/ethersphere/bee/v2/pkg/log"
"github.com/ethersphere/bee/v2/pkg/node"
"github.com/ethersphere/bee/v2/pkg/resolver/multiresolver"
"github.com/ethersphere/bee/v2/pkg/spinlock"
"github.com/ethersphere/bee/v2/pkg/swarm"
"github.com/kardianos/service"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -340,6 +335,7 @@ func buildBeeNode(ctx context.Context, c *command, cmd *cobra.Command, logger lo
WhitelistedWithdrawalAddress: c.config.GetStringSlice(optionNameWhitelistedWithdrawalAddress),
TrxDebugMode: c.config.GetBool(optionNameTransactionDebugMode),
MinimumStorageRadius: c.config.GetUint(optionMinimumStorageRadius),
ReserveCapacityDoubling: c.config.GetInt(optionReserveCapacityDoubling),
})

return b, err
Expand Down Expand Up @@ -369,22 +365,6 @@ type signerConfig struct {
session accesscontrol.Session
}

func waitForClef(logger log.Logger, maxRetries uint64, endpoint string) (externalSigner *external.ExternalSigner, err error) {
var (
interval = time.Second * 5
timeout = interval * time.Duration(maxRetries)
)

spinErr := spinlock.WaitWithInterval(timeout, interval, func() bool {
externalSigner, err = external.NewExternalSigner(endpoint)
return err == nil
})
if spinErr != nil {
logger.Warning("connect to clef signer failed", "error", err)
}
return
}

func (c *command) configureSigner(cmd *cobra.Command, logger log.Logger) (config *signerConfig, err error) {
var keystore keystore.Service
if c.config.GetString(optionNameDataDir) == "" {
Expand Down Expand Up @@ -427,51 +407,13 @@ func (c *command) configureSigner(cmd *cobra.Command, logger log.Logger) (config
}
}

if c.config.GetBool(optionNameClefSignerEnable) {
endpoint := c.config.GetString(optionNameClefSignerEndpoint)
if endpoint == "" {
endpoint, err = clef.DefaultIpcPath()
if err != nil {
return nil, err
}
}

externalSigner, err := waitForClef(logger, 5, endpoint)
if err != nil {
return nil, err
}

clefRPC, err := rpc.Dial(endpoint)
if err != nil {
return nil, err
}

wantedAddress := c.config.GetString(optionNameClefSignerEthereumAddress)
var overlayEthAddress *common.Address = nil
// if wantedAddress was specified use that, otherwise clef account 0 will be selected.
if wantedAddress != "" {
ethAddress := common.HexToAddress(wantedAddress)
overlayEthAddress = &ethAddress
}

signer, err = clef.NewSigner(externalSigner, clefRPC, crypto.Recover, overlayEthAddress)
if err != nil {
return nil, err
}

publicKey, err = signer.PublicKey()
if err != nil {
return nil, err
}
} else {
swarmPrivateKey, _, err := keystore.Key("swarm", password, crypto.EDGSecp256_K1)
if err != nil {
return nil, fmt.Errorf("swarm key: %w", err)
}
signer = crypto.NewDefaultSigner(swarmPrivateKey)
publicKey = &swarmPrivateKey.PublicKey
session = accesscontrol.NewDefaultSession(swarmPrivateKey)
swarmPrivateKey, _, err := keystore.Key("swarm", password, crypto.EDGSecp256_K1)
if err != nil {
return nil, fmt.Errorf("swarm key: %w", err)
}
signer = crypto.NewDefaultSigner(swarmPrivateKey)
publicKey = &swarmPrivateKey.PublicKey
session = accesscontrol.NewDefaultSession(swarmPrivateKey)

logger.Info("swarm public key", "public_key", hex.EncodeToString(crypto.EncodeSecp256k1PublicKey(publicKey)))

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/coreos/go-semver v0.3.0
github.com/ethereum/go-ethereum v1.14.3
github.com/ethersphere/go-price-oracle-abi v0.2.0
github.com/ethersphere/go-storage-incentives-abi v0.9.1-rc6
github.com/ethersphere/go-storage-incentives-abi v0.9.2-rc1
github.com/ethersphere/go-sw3-abi v0.6.5
github.com/ethersphere/langos v1.0.0
github.com/go-playground/validator/v10 v10.11.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ github.com/ethereum/go-ethereum v1.14.3 h1:5zvnAqLtnCZrU9uod1JCvHWJbPMURzYFHfc2e
github.com/ethereum/go-ethereum v1.14.3/go.mod h1:1STrq471D0BQbCX9He0hUj4bHxX2k6mt5nOQJhDNOJ8=
github.com/ethersphere/go-price-oracle-abi v0.2.0 h1:wtIcYLgNZHY4BjYwJCnu93SvJdVAZVvBaKinspyyHvQ=
github.com/ethersphere/go-price-oracle-abi v0.2.0/go.mod h1:sI/Qj4/zJ23/b1enzwMMv0/hLTpPNVNacEwCWjo6yBk=
github.com/ethersphere/go-storage-incentives-abi v0.9.1-rc6 h1:wWSHAF1siVmiMj9koBTrJ8Vl9fK1I9w9DL3so+Ye5ss=
github.com/ethersphere/go-storage-incentives-abi v0.9.1-rc6/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
github.com/ethersphere/go-storage-incentives-abi v0.9.2-rc1 h1:Cf3LFlz87FqlTqcuN4q4Hry4iUaAbbroaFxpCgHVhtY=
github.com/ethersphere/go-storage-incentives-abi v0.9.2-rc1/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc=
github.com/ethersphere/go-sw3-abi v0.6.5 h1:M5dcIe1zQYvGpY2K07UNkNU9Obc4U+A1fz68Ho/Q+XE=
github.com/ethersphere/go-sw3-abi v0.6.5/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU=
github.com/ethersphere/langos v1.0.0 h1:NBtNKzXTTRSue95uOlzPN4py7Aofs0xWPzyj4AI1Vcc=
Expand Down
Loading

0 comments on commit 7134e02

Please sign in to comment.