Skip to content

Commit 6e51a8a

Browse files
feat: exit warmup dynamically based on Kademlia peer stabilization (#5077)
1 parent b7bc25a commit 6e51a8a

File tree

30 files changed

+852
-192
lines changed

30 files changed

+852
-192
lines changed

cmd/bee/cmd/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
271271
cmd.Flags().String(optionNameRedistributionAddress, "", "redistribution contract address")
272272
cmd.Flags().String(optionNameStakingAddress, "", "staking contract address")
273273
cmd.Flags().Uint64(optionNameBlockTime, 5, "chain block time")
274-
cmd.Flags().Duration(optionWarmUpTime, time.Minute*5, "time to warmup the node before some major protocols can be kicked off")
274+
cmd.Flags().Duration(optionWarmUpTime, time.Minute*5, "maximum node warmup duration; proceeds when stable or after this time")
275275
cmd.Flags().Bool(optionNameMainNet, true, "triggers connect to main net bootnodes.")
276276
cmd.Flags().Bool(optionNameRetrievalCaching, true, "enable forwarded content caching")
277277
cmd.Flags().Bool(optionNameResync, false, "forces the node to resync postage contract data")

cmd/bee/cmd/start.go

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -279,57 +279,57 @@ func buildBeeNode(ctx context.Context, c *command, cmd *cobra.Command, logger lo
279279
}
280280

281281
b, err := node.NewBee(ctx, c.config.GetString(optionNameP2PAddr), signerConfig.publicKey, signerConfig.signer, networkID, logger, signerConfig.libp2pPrivateKey, signerConfig.pssPrivateKey, signerConfig.session, &node.Options{
282-
DataDir: c.config.GetString(optionNameDataDir),
282+
Addr: c.config.GetString(optionNameP2PAddr),
283+
AllowPrivateCIDRs: c.config.GetBool(optionNameAllowPrivateCIDRs),
284+
APIAddr: c.config.GetString(optionNameAPIAddr),
285+
BlockchainRpcEndpoint: c.config.GetString(optionNameBlockchainRpcEndpoint),
286+
BlockProfile: c.config.GetBool(optionNamePProfBlock),
287+
BlockTime: networkConfig.blockTime,
288+
BootnodeMode: bootNode,
289+
Bootnodes: networkConfig.bootNodes,
283290
CacheCapacity: c.config.GetUint64(optionNameCacheCapacity),
284-
DBOpenFilesLimit: c.config.GetUint64(optionNameDBOpenFilesLimit),
291+
ChainID: networkConfig.chainID,
292+
ChequebookEnable: c.config.GetBool(optionNameChequebookEnable),
293+
CORSAllowedOrigins: c.config.GetStringSlice(optionCORSAllowedOrigins),
294+
DataDir: c.config.GetString(optionNameDataDir),
285295
DBBlockCacheCapacity: c.config.GetUint64(optionNameDBBlockCacheCapacity),
286-
DBWriteBufferSize: c.config.GetUint64(optionNameDBWriteBufferSize),
287296
DBDisableSeeksCompaction: c.config.GetBool(optionNameDBDisableSeeksCompaction),
288-
APIAddr: c.config.GetString(optionNameAPIAddr),
289-
Addr: c.config.GetString(optionNameP2PAddr),
290-
NATAddr: c.config.GetString(optionNameNATAddr),
297+
DBOpenFilesLimit: c.config.GetUint64(optionNameDBOpenFilesLimit),
298+
DBWriteBufferSize: c.config.GetUint64(optionNameDBWriteBufferSize),
299+
EnableStorageIncentives: c.config.GetBool(optionNameStorageIncentivesEnable),
291300
EnableWS: c.config.GetBool(optionNameP2PWSEnable),
292-
WelcomeMessage: c.config.GetString(optionWelcomeMessage),
293-
Bootnodes: networkConfig.bootNodes,
294-
CORSAllowedOrigins: c.config.GetStringSlice(optionCORSAllowedOrigins),
295-
TracingEnabled: c.config.GetBool(optionNameTracingEnabled),
296-
TracingEndpoint: tracingEndpoint,
297-
TracingServiceName: c.config.GetString(optionNameTracingServiceName),
301+
FullNodeMode: fullNode,
298302
Logger: logger,
303+
MinimumStorageRadius: c.config.GetUint(optionMinimumStorageRadius),
304+
MutexProfile: c.config.GetBool(optionNamePProfMutex),
305+
NATAddr: c.config.GetString(optionNameNATAddr),
306+
NeighborhoodSuggester: neighborhoodSuggester,
307+
PaymentEarly: c.config.GetInt64(optionNamePaymentEarly),
299308
PaymentThreshold: c.config.GetString(optionNamePaymentThreshold),
300309
PaymentTolerance: c.config.GetInt64(optionNamePaymentTolerance),
301-
PaymentEarly: c.config.GetInt64(optionNamePaymentEarly),
302-
ResolverConnectionCfgs: resolverCfgs,
303-
BootnodeMode: bootNode,
304-
BlockchainRpcEndpoint: c.config.GetString(optionNameBlockchainRpcEndpoint),
305-
SwapFactoryAddress: c.config.GetString(optionNameSwapFactoryAddress),
306-
SwapInitialDeposit: c.config.GetString(optionNameSwapInitialDeposit),
307-
SwapEnable: c.config.GetBool(optionNameSwapEnable),
308-
ChequebookEnable: c.config.GetBool(optionNameChequebookEnable),
309-
FullNodeMode: fullNode,
310310
PostageContractAddress: c.config.GetString(optionNamePostageContractAddress),
311311
PostageContractStartBlock: c.config.GetUint64(optionNamePostageContractStartBlock),
312312
PriceOracleAddress: c.config.GetString(optionNamePriceOracleAddress),
313313
RedistributionContractAddress: c.config.GetString(optionNameRedistributionAddress),
314-
StakingContractAddress: c.config.GetString(optionNameStakingAddress),
315-
BlockTime: networkConfig.blockTime,
316-
WarmupTime: c.config.GetDuration(optionWarmUpTime),
317-
ChainID: networkConfig.chainID,
318-
RetrievalCaching: c.config.GetBool(optionNameRetrievalCaching),
314+
ReserveCapacityDoubling: c.config.GetInt(optionReserveCapacityDoubling),
315+
ResolverConnectionCfgs: resolverCfgs,
319316
Resync: c.config.GetBool(optionNameResync),
320-
BlockProfile: c.config.GetBool(optionNamePProfBlock),
321-
MutexProfile: c.config.GetBool(optionNamePProfMutex),
322-
StaticNodes: staticNodes,
323-
AllowPrivateCIDRs: c.config.GetBool(optionNameAllowPrivateCIDRs),
324-
UsePostageSnapshot: c.config.GetBool(optionNameUsePostageSnapshot),
325-
EnableStorageIncentives: c.config.GetBool(optionNameStorageIncentivesEnable),
317+
RetrievalCaching: c.config.GetBool(optionNameRetrievalCaching),
318+
StakingContractAddress: c.config.GetString(optionNameStakingAddress),
326319
StatestoreCacheCapacity: c.config.GetUint64(optionNameStateStoreCacheCapacity),
320+
StaticNodes: staticNodes,
321+
SwapEnable: c.config.GetBool(optionNameSwapEnable),
322+
SwapFactoryAddress: c.config.GetString(optionNameSwapFactoryAddress),
323+
SwapInitialDeposit: c.config.GetString(optionNameSwapInitialDeposit),
327324
TargetNeighborhood: c.config.GetString(optionNameTargetNeighborhood),
328-
NeighborhoodSuggester: neighborhoodSuggester,
329-
WhitelistedWithdrawalAddress: c.config.GetStringSlice(optionNameWhitelistedWithdrawalAddress),
325+
TracingEnabled: c.config.GetBool(optionNameTracingEnabled),
326+
TracingEndpoint: tracingEndpoint,
327+
TracingServiceName: c.config.GetString(optionNameTracingServiceName),
330328
TrxDebugMode: c.config.GetBool(optionNameTransactionDebugMode),
331-
MinimumStorageRadius: c.config.GetUint(optionMinimumStorageRadius),
332-
ReserveCapacityDoubling: c.config.GetInt(optionReserveCapacityDoubling),
329+
UsePostageSnapshot: c.config.GetBool(optionNameUsePostageSnapshot),
330+
WarmupTime: c.config.GetDuration(optionWarmUpTime),
331+
WelcomeMessage: c.config.GetString(optionWelcomeMessage),
332+
WhitelistedWithdrawalAddress: c.config.GetStringSlice(optionNameWhitelistedWithdrawalAddress),
333333
})
334334

335335
return b, err

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ require (
4949
golang.org/x/term v0.27.0
5050
golang.org/x/time v0.5.0
5151
gopkg.in/yaml.v2 v2.4.0
52+
resenje.org/feed v0.1.2
5253
resenje.org/multex v0.1.0
5354
resenje.org/singleflight v0.4.0
5455
resenje.org/web v0.4.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,8 @@ lukechampine.com/blake3 v1.3.0 h1:sJ3XhFINmHSrYCgl958hscfIa3bw8x4DqMP3u1YvoYE=
15321532
lukechampine.com/blake3 v1.3.0/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k=
15331533
resenje.org/daemon v0.1.2/go.mod h1:mF5JRpH3EbrxI9WoeKY78e6PqSsbBtX9jAQL5vj/GBA=
15341534
resenje.org/email v0.1.3/go.mod h1:OhAVLRG3vqd9NSgayN3pAgzxTmc2B6mAefgShZvEgf0=
1535+
resenje.org/feed v0.1.2 h1:3OianQkoI4EalWx1SlzHtGjUMsoB4XTJQbeehWiyeFI=
1536+
resenje.org/feed v0.1.2/go.mod h1:ABlv4P3svuZY3dkZq3un+XIEoX+TDwbGEkjLcSP8TnM=
15351537
resenje.org/jsonhttp v0.2.0/go.mod h1:EDyeguyTWj2fU3D3SCE0qNTgthzyEkHYLM1uu0uikHU=
15361538
resenje.org/logging v0.1.5/go.mod h1:1IdoCm3+UwYfsplxDGV2pHCkUrLlQzlWwp4r28XfPx4=
15371539
resenje.org/marshal v0.1.1/go.mod h1:P7Cla6Ju5CFvW4Y8JbRgWX1Hcy4L1w4qcCsyadO7G94=

packaging/bee.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ password-file: "/var/lib/bee/password"
110110
# use-postage-snapshot: false
111111
## log verbosity level 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=trace
112112
# verbosity: info
113-
## time to warmup the node before some major protocols can be kicked off
113+
## maximum node warmup duration; proceeds when stable or after this time
114114
# warmup-time: 5m0s
115115
## send a welcome message string during handshakes
116116
# welcome-message: ""

packaging/docker/env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
# BEE_TRANSACTION_DEBUG_MODE=false
124124
## bootstrap node using postage snapshot from the network
125125
# BEE_USE_POSTAGE_SNAPSHOT=false
126-
## time to warmup the node before some major protocols can be kicked off
126+
## maximum node warmup duration; proceeds when stable or after this time
127127
# BEE_WARMUP_TIME=
128128
## withdrawal target addresses
129129
# BEE_WITHDRAWAL_ADDRESSES_WHITELIST=

packaging/homebrew-amd64/bee.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ password-file: "/usr/local/var/lib/swarm-bee/password"
110110
# use-postage-snapshot: false
111111
## log verbosity level 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=trace
112112
# verbosity: info
113-
## time to warmup the node before some major protocols can be kicked off
113+
## maximum node warmup duration; proceeds when stable or after this time
114114
# warmup-time: 5m0s
115115
## send a welcome message string during handshakes
116116
# welcome-message: ""

packaging/homebrew-arm64/bee.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ password-file: "/opt/homebrew/var/lib/swarm-bee/password"
110110
# use-postage-snapshot: false
111111
## log verbosity level 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=trace
112112
# verbosity: info
113-
## time to warmup the node before some major protocols can be kicked off
113+
## maximum node warmup duration; proceeds when stable or after this time
114114
# warmup-time: 5m0s
115115
## send a welcome message string during handshakes
116116
# welcome-message: ""

packaging/scoop/bee.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ password-file: "./password"
110110
# use-postage-snapshot: false
111111
## log verbosity level 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=trace
112112
# verbosity: info
113-
## time to warmup the node before some major protocols can be kicked off
113+
## maximum node warmup duration; proceeds when stable or after this time
114114
# warmup-time: 5m0s
115115
## send a welcome message string during handshakes
116116
# welcome-message: ""

pkg/node/bootstrap.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/ethersphere/bee/v2/pkg/retrieval"
3636
"github.com/ethersphere/bee/v2/pkg/settlement/pseudosettle"
3737
"github.com/ethersphere/bee/v2/pkg/spinlock"
38+
"github.com/ethersphere/bee/v2/pkg/stabilization"
3839
"github.com/ethersphere/bee/v2/pkg/storage"
3940
"github.com/ethersphere/bee/v2/pkg/storer"
4041
"github.com/ethersphere/bee/v2/pkg/swarm"
@@ -72,9 +73,9 @@ func bootstrapNode(
7273
networkID uint64,
7374
logger log.Logger,
7475
libp2pPrivateKey *ecdsa.PrivateKey,
76+
detector *stabilization.Detector,
7577
o *Options,
7678
) (snapshot *postage.ChainSnapshot, retErr error) {
77-
7879
tracer, tracerCloser, err := tracing.NewTracer(&tracing.Options{
7980
Enabled: o.TracingEnabled,
8081
Endpoint: o.TracingEndpoint,
@@ -116,7 +117,7 @@ func bootstrapNode(
116117
}
117118
b.hiveCloser = hive
118119

119-
kad, err := kademlia.New(swarmAddress, addressbook, hive, p2ps, logger,
120+
kad, err := kademlia.New(swarmAddress, addressbook, hive, p2ps, detector, logger,
120121
kademlia.Options{Bootnodes: bootnodes, BootnodeMode: o.BootnodeMode, StaticNodes: o.StaticNodes, DataDir: o.DataDir})
121122
if err != nil {
122123
return nil, fmt.Errorf("unable to create kademlia: %w", err)
@@ -339,7 +340,6 @@ func getLatestSnapshot(
339340
}
340341

341342
func batchStoreExists(s storage.StateStorer) (bool, error) {
342-
343343
hasOne := false
344344
err := s.Iterate("batchstore_", func(key, value []byte) (stop bool, err error) {
345345
hasOne = true

0 commit comments

Comments
 (0)