Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions cmd/bee/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const (
optionMinimumStorageRadius = "minimum-storage-radius"
optionReserveCapacityDoubling = "reserve-capacity-doubling"
optionSkipPostageSnapshot = "skip-postage-snapshot"
optionNameMinimumGasTipCap = "minimum-gas-tip-cap"
)

// nolint:gochecknoinits
Expand Down Expand Up @@ -290,6 +291,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
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")
cmd.Flags().Uint64(optionNameMinimumGasTipCap, 0, "minimum gas tip cap in wei for transactions, 0 means use suggested gas tip cap")
}

func newLogger(cmd *cobra.Command, verbosity string) (log.Logger, error) {
Expand Down
1 change: 1 addition & 0 deletions cmd/bee/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (c *command) initDeployCmd() error {
signer,
blocktime,
true,
c.config.GetUint64(optionNameMinimumGasTipCap),
)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/bee/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ func buildBeeNode(ctx context.Context, c *command, cmd *cobra.Command, logger lo
EnableWS: c.config.GetBool(optionNameP2PWSEnable),
FullNodeMode: fullNode,
Logger: logger,
MinimumGasTipCap: c.config.GetUint64(optionNameMinimumGasTipCap),
MinimumStorageRadius: c.config.GetUint(optionMinimumStorageRadius),
MutexProfile: c.config.GetBool(optionNamePProfMutex),
NATAddr: c.config.GetString(optionNameNATAddr),
Expand Down
2 changes: 2 additions & 0 deletions packaging/bee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ data-dir: "/var/lib/bee"
# help: false
## triggers connect to main net bootnodes.
# mainnet: true
## minimum gas tip cap in wei for transactions, 0 means use suggested gas tip cap
# minimum-gas-tip-cap: 0
## minimum radius storage threshold
# minimum-storage-radius: "0"
## NAT exposed address
Expand Down
2 changes: 2 additions & 0 deletions packaging/homebrew-amd64/bee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ data-dir: "/usr/local/var/lib/swarm-bee"
# help: false
## triggers connect to main net bootnodes.
# mainnet: true
## minimum gas tip cap in wei for transactions, 0 means use suggested gas tip cap
# minimum-gas-tip-cap: 0
## minimum radius storage threshold
# minimum-storage-radius: "0"
## NAT exposed address
Expand Down
2 changes: 2 additions & 0 deletions packaging/homebrew-arm64/bee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ data-dir: "/opt/homebrew/var/lib/swarm-bee"
# help: false
## triggers connect to main net bootnodes.
# mainnet: true
## minimum gas tip cap in wei for transactions, 0 means use suggested gas tip cap
# minimum-gas-tip-cap: 0
## minimum radius storage threshold
# minimum-storage-radius: "0"
## NAT exposed address
Expand Down
2 changes: 2 additions & 0 deletions packaging/scoop/bee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ data-dir: "./data"
# help: false
## triggers connect to main net bootnodes.
# mainnet: true
## minimum gas tip cap in wei for transactions, 0 means use suggested gas tip cap
# minimum-gas-tip-cap: 0
## minimum radius storage threshold
# minimum-storage-radius: "0"
## NAT exposed address
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/redistribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func TestRedistributionStatus(t *testing.T) {
backendmock.WithBalanceAt(func(ctx context.Context, address common.Address, block *big.Int) (*big.Int, error) {
return big.NewInt(100000000), nil
}),
backendmock.WithSuggestGasPriceFunc(func(ctx context.Context) (*big.Int, error) {
return big.NewInt(1), nil
backendmock.WithSuggestedFeeAndTipFunc(func(ctx context.Context, gasPrice *big.Int, boostPercent int) (*big.Int, *big.Int, error) {
return big.NewInt(1), big.NewInt(2), nil
}),
},
})
Expand Down
23 changes: 6 additions & 17 deletions pkg/node/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/ethersphere/bee/v2/pkg/storage"
"github.com/ethersphere/bee/v2/pkg/transaction"
"github.com/ethersphere/bee/v2/pkg/transaction/wrapped"
"github.com/ethersphere/go-sw3-abi/sw3abi"
"github.com/prometheus/client_golang/prometheus"
)

Expand All @@ -53,6 +52,7 @@ func InitChain(
signer crypto.Signer,
pollingInterval time.Duration,
chainEnabled bool,
minimumGasTipCap uint64,
) (transaction.Backend, common.Address, int64, transaction.Monitor, transaction.Service, error) {
var backend transaction.Backend = &noOpChainBackend{
chainID: oChainID,
Expand All @@ -74,7 +74,7 @@ func InitChain(

logger.Info("connected to blockchain backend", "version", versionString)

backend = wrapped.NewBackend(ethclient.NewClient(rpcClient))
backend = wrapped.NewBackend(ethclient.NewClient(rpcClient), minimumGasTipCap)
}

chainID, err := backend.ChainID(ctx)
Expand Down Expand Up @@ -346,19 +346,10 @@ type noOpChainBackend struct {
chainID int64
}

// BlockByNumber implements transaction.Backend.
func (m *noOpChainBackend) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
return nil, postagecontract.ErrChainDisabled
}

func (m noOpChainBackend) Metrics() []prometheus.Collector {
return nil
}

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

func (m noOpChainBackend) CallContract(context.Context, ethereum.CallMsg, *big.Int) ([]byte, error) {
return nil, errors.New("disabled chain backend")
}
Expand All @@ -373,12 +364,12 @@ func (m noOpChainBackend) PendingNonceAt(context.Context, common.Address) (uint6
panic("chain no op: PendingNonceAt")
}

func (m noOpChainBackend) SuggestGasPrice(context.Context) (*big.Int, error) {
panic("chain no op: SuggestGasPrice")
func (m noOpChainBackend) SuggestedFeeAndTip(ctx context.Context, gasPrice *big.Int, boostPercent int) (*big.Int, *big.Int, error) {
panic("chain no op: SuggestedFeeAndTip")
}

func (m noOpChainBackend) SuggestGasTipCap(context.Context) (*big.Int, error) {
panic("chain no op: SuggestGasPrice")
panic("chain no op: SuggestGasTipCap")
}

func (m noOpChainBackend) EstimateGas(context.Context, ethereum.CallMsg) (uint64, error) {
Expand Down Expand Up @@ -419,6 +410,4 @@ func (m noOpChainBackend) ChainID(context.Context) (*big.Int, error) {
return big.NewInt(m.chainID), nil
}

func (m noOpChainBackend) Close() error {
return nil
}
func (m noOpChainBackend) Close() {}
14 changes: 10 additions & 4 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ type Bee struct {
pullSyncCloser io.Closer
pssCloser io.Closer
gsocCloser io.Closer
ethClientCloser io.Closer
transactionMonitorCloser io.Closer
transactionCloser io.Closer
listenerCloser io.Closer
Expand All @@ -121,6 +120,7 @@ type Bee struct {
shutdownMutex sync.Mutex
syncingStopped *syncutil.Signaler
accesscontrolCloser io.Closer
ethClientCloser func()
}

type Options struct {
Expand All @@ -145,6 +145,7 @@ type Options struct {
EnableWS bool
FullNodeMode bool
Logger log.Logger
MinimumGasTipCap uint64
MinimumStorageRadius uint
MutexProfile bool
NATAddr string
Expand Down Expand Up @@ -390,11 +391,13 @@ func NewBee(
o.ChainID,
signer,
o.BlockTime,
chainEnabled)
chainEnabled,
o.MinimumGasTipCap,
)
if err != nil {
return nil, fmt.Errorf("init chain: %w", err)
}
b.ethClientCloser = chainBackend
b.ethClientCloser = chainBackend.Close

logger.Info("using chain with network network", "chain_id", chainID, "network_id", networkID)

Expand Down Expand Up @@ -1384,7 +1387,10 @@ func (b *Bee) Shutdown() error {

wg.Wait()

tryClose(b.ethClientCloser, "eth client")
if b.ethClientCloser != nil {
b.ethClientCloser()
}

tryClose(b.accesscontrolCloser, "accesscontrol")
tryClose(b.tracerCloser, "tracer")
tryClose(b.topologyCloser, "topology driver")
Expand Down
4 changes: 2 additions & 2 deletions pkg/settlement/swap/chequebook/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func checkBalance(
minimumEth := big.NewInt(0)

if gasPrice == nil {
gasPrice, err = swapBackend.SuggestGasPrice(timeoutCtx)
gasPrice, _, err = swapBackend.SuggestedFeeAndTip(timeoutCtx, gasPrice, 0)
if err != nil {
return err
}

minimumEth = gasPrice.Mul(gasPrice, big.NewInt(250000))
minimumEth = new(big.Int).Mul(gasPrice, big.NewInt(250000))
}

insufficientERC20 := erc20Balance.Cmp(swapInitialDeposit) < 0
Expand Down
4 changes: 2 additions & 2 deletions pkg/storageincentives/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type ChainBackend interface {
BlockNumber(context.Context) (uint64, error)
HeaderByNumber(context.Context, *big.Int) (*types.Header, error)
BalanceAt(ctx context.Context, address common.Address, block *big.Int) (*big.Int, error)
SuggestGasPrice(ctx context.Context) (*big.Int, error)
SuggestedFeeAndTip(ctx context.Context, gasPrice *big.Int, boostPercent int) (*big.Int, *big.Int, error)
}

type Health interface {
Expand Down Expand Up @@ -604,7 +604,7 @@ func (a *Agent) HasEnoughFundsToPlay(ctx context.Context) (*big.Int, bool, error
return nil, false, err
}

price, err := a.backend.SuggestGasPrice(ctx)
price, _, err := a.backend.SuggestedFeeAndTip(ctx, nil, redistribution.BoostTipPercent)
if err != nil {
return nil, false, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/storageincentives/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ func (m *mockchainBackend) BalanceAt(ctx context.Context, address common.Address
return m.balance, nil
}

func (m *mockchainBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
return big.NewInt(4), nil
func (m *mockchainBackend) SuggestedFeeAndTip(ctx context.Context, gasPrice *big.Int, boostPercent int) (*big.Int, *big.Int, error) {
return big.NewInt(4), big.NewInt(5), nil
}

type contractCall int
Expand Down
11 changes: 7 additions & 4 deletions pkg/storageincentives/redistribution/redistribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import (
"github.com/ethersphere/bee/v2/pkg/transaction"
)

const loggerName = "redistributionContract"
const (
loggerName = "redistributionContract"
BoostTipPercent = 50
Copy link
Member

Choose a reason for hiding this comment

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

in a future PR, this could be dynamic based on how far the node is from the end of the round phase. wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is nice idea

)

type Contract interface {
ReserveSalt(context.Context) ([]byte, error)
Expand Down Expand Up @@ -117,7 +120,7 @@ func (c *contract) Claim(ctx context.Context, proofs ChunkInclusionProofs) (comm
Value: big.NewInt(0),
Description: "claim win transaction",
}
txHash, err := c.sendAndWait(ctx, request, transaction.RedistributionTipBoostPercent)
txHash, err := c.sendAndWait(ctx, request, BoostTipPercent)
if err != nil {
return txHash, fmt.Errorf("claim: %w", err)
}
Expand All @@ -140,7 +143,7 @@ func (c *contract) Commit(ctx context.Context, obfusHash []byte, round uint64) (
Value: big.NewInt(0),
Description: "commit transaction",
}
txHash, err := c.sendAndWait(ctx, request, transaction.RedistributionTipBoostPercent)
txHash, err := c.sendAndWait(ctx, request, BoostTipPercent)
if err != nil {
return txHash, fmt.Errorf("commit: obfusHash %v: %w", common.BytesToHash(obfusHash), err)
}
Expand All @@ -163,7 +166,7 @@ func (c *contract) Reveal(ctx context.Context, storageDepth uint8, reserveCommit
Value: big.NewInt(0),
Description: "reveal transaction",
}
txHash, err := c.sendAndWait(ctx, request, transaction.RedistributionTipBoostPercent)
txHash, err := c.sendAndWait(ctx, request, BoostTipPercent)
if err != nil {
return txHash, fmt.Errorf("reveal: storageDepth %d reserveCommitmentHash %v RandomNonce %v: %w", storageDepth, common.BytesToHash(reserveCommitmentHash), common.BytesToHash(RandomNonce), err)
}
Expand Down
26 changes: 4 additions & 22 deletions pkg/transaction/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,21 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethersphere/bee/v2/pkg/log"
"github.com/ethersphere/bee/v2/pkg/transaction/backend"
)

// Backend is the minimum of blockchain backend functions we need.
type Backend interface {
CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)
CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
SuggestGasPrice(ctx context.Context) (*big.Int, error)
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)
SendTransaction(ctx context.Context, tx *types.Transaction) error
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)
BlockNumber(ctx context.Context) (uint64, error)
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
BalanceAt(ctx context.Context, address common.Address, block *big.Int) (*big.Int, error)
NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)
ChainID(ctx context.Context) (*big.Int, error)
Close() error
backend.Geth
SuggestedFeeAndTip(ctx context.Context, gasPrice *big.Int, boostPercent int) (*big.Int, *big.Int, error)
}

// IsSynced will check if we are synced with the given blockchain backend. This
// is true if the current wall clock is after the block time of last block
// with the given maxDelay as the maximum duration we can be behind the block
// time.
func IsSynced(ctx context.Context, backend Backend, maxDelay time.Duration) (bool, time.Time, error) {
number, err := backend.BlockNumber(ctx)
if err != nil {
return false, time.Time{}, err
}
header, err := backend.HeaderByNumber(ctx, big.NewInt(int64(number)))
header, err := backend.HeaderByNumber(ctx, nil)
if errors.Is(err, ethereum.NotFound) {
return false, time.Time{}, nil
}
Expand Down
32 changes: 32 additions & 0 deletions pkg/transaction/backend/backend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2025 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.

package backend

import (
"context"
"math/big"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

// Geth is the interface that an ethclient.Client satisfies.
type Geth interface {
BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
BlockNumber(ctx context.Context) (uint64, error)
CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
ChainID(ctx context.Context) (*big.Int, error)
Close()
EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)
FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
SendTransaction(ctx context.Context, tx *types.Transaction) error
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
}
Loading
Loading