Skip to content

Commit 25dd497

Browse files
committed
remove unrelated stuff from wasm node
1 parent e273eba commit 25dd497

1 file changed

Lines changed: 22 additions & 214 deletions

File tree

pkg/node/node_js.go

Lines changed: 22 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/ethersphere/bee/v2/pkg/accounting"
2323
"github.com/ethersphere/bee/v2/pkg/addressbook"
2424
"github.com/ethersphere/bee/v2/pkg/api"
25-
"github.com/ethersphere/bee/v2/pkg/config"
2625
"github.com/ethersphere/bee/v2/pkg/crypto"
2726
"github.com/ethersphere/bee/v2/pkg/feeds/factory"
2827
"github.com/ethersphere/bee/v2/pkg/gsoc"
@@ -32,14 +31,10 @@ import (
3231
"github.com/ethersphere/bee/v2/pkg/p2p/libp2p"
3332
"github.com/ethersphere/bee/v2/pkg/pingpong"
3433
"github.com/ethersphere/bee/v2/pkg/postage"
35-
"github.com/ethersphere/bee/v2/pkg/postage/batchservice"
3634
"github.com/ethersphere/bee/v2/pkg/postage/batchstore"
37-
"github.com/ethersphere/bee/v2/pkg/postage/listener"
38-
"github.com/ethersphere/bee/v2/pkg/postage/postagecontract"
3935
"github.com/ethersphere/bee/v2/pkg/pricer"
4036
"github.com/ethersphere/bee/v2/pkg/pricing"
4137
"github.com/ethersphere/bee/v2/pkg/pss"
42-
"github.com/ethersphere/bee/v2/pkg/puller"
4338
"github.com/ethersphere/bee/v2/pkg/pullsync"
4439
"github.com/ethersphere/bee/v2/pkg/pusher"
4540
"github.com/ethersphere/bee/v2/pkg/pushsync"
@@ -55,20 +50,16 @@ import (
5550
"github.com/ethersphere/bee/v2/pkg/status"
5651
"github.com/ethersphere/bee/v2/pkg/steward"
5752
"github.com/ethersphere/bee/v2/pkg/storageincentives"
58-
"github.com/ethersphere/bee/v2/pkg/storageincentives/redistribution"
59-
"github.com/ethersphere/bee/v2/pkg/storageincentives/staking"
6053
"github.com/ethersphere/bee/v2/pkg/storer"
6154
"github.com/ethersphere/bee/v2/pkg/swarm"
6255
"github.com/ethersphere/bee/v2/pkg/topology/kademlia"
6356
"github.com/ethersphere/bee/v2/pkg/topology/lightnode"
6457
"github.com/ethersphere/bee/v2/pkg/tracing"
6558
"github.com/ethersphere/bee/v2/pkg/transaction"
66-
"github.com/ethersphere/bee/v2/pkg/util/abiutil"
6759
"github.com/ethersphere/bee/v2/pkg/util/ioutil"
6860
"github.com/ethersphere/bee/v2/pkg/util/nbhdutil"
6961
"github.com/ethersphere/bee/v2/pkg/util/syncutil"
7062
ma "github.com/multiformats/go-multiaddr"
71-
"golang.org/x/crypto/sha3"
7263

7364
wasmhttp "github.com/nlepage/go-wasm-http-server/v2"
7465
)
@@ -171,7 +162,7 @@ func NewBee(
171162
}
172163
}
173164

174-
var changedOverlay, resetReserve bool
165+
var resetReserve bool
175166
if targetNeighborhood != "" {
176167
neighborhood, err := swarm.ParseBitStrAddress(targetNeighborhood)
177168
if err != nil {
@@ -208,7 +199,6 @@ func NewBee(
208199
if err != nil {
209200
return nil, fmt.Errorf("statestore: save new overlay: %w", err)
210201
}
211-
changedOverlay = true
212202
}
213203
}
214204

@@ -477,13 +467,12 @@ func NewBee(
477467
logger.Debug("node warmup check: period complete.", "periodEndTime", t, "eventsInPeriod", periodCount, "rateStdDev", stDev)
478468
}
479469

480-
var initBatchState *postage.ChainSnapshot
481470
// Bootstrap node with postage snapshot only if it is running on mainnet, is a fresh
482471
// install or explicitly asked by user to resync
483472
if networkID == mainnetNetworkID && o.UsePostageSnapshot && (!batchStoreExists || o.Resync) {
484473
start := time.Now()
485474
logger.Info("cold postage start detected. fetching postage stamp snapshot from swarm")
486-
initBatchState, err = bootstrapNode(
475+
_, err = bootstrapNode(
487476
ctx,
488477
addr,
489478
swarmAddress,
@@ -530,54 +519,6 @@ func NewBee(
530519
b.postageServiceCloser = post
531520
batchStore.SetBatchExpiryHandler(post)
532521

533-
var (
534-
postageStampContractService postagecontract.Interface
535-
batchSvc postage.EventUpdater
536-
eventListener postage.Listener
537-
)
538-
539-
chainCfg, found := config.GetByChainID(chainID)
540-
postageStampContractAddress, postageSyncStart := chainCfg.PostageStampAddress, chainCfg.PostageStampStartBlock
541-
if o.PostageContractAddress != "" {
542-
if !common.IsHexAddress(o.PostageContractAddress) {
543-
return nil, errors.New("malformed postage stamp address")
544-
}
545-
postageStampContractAddress = common.HexToAddress(o.PostageContractAddress)
546-
if o.PostageContractStartBlock == 0 {
547-
return nil, errors.New("postage contract start block option not provided")
548-
}
549-
postageSyncStart = o.PostageContractStartBlock
550-
} else if !found {
551-
return nil, errors.New("no known postage stamp addresses for this network")
552-
}
553-
554-
postageStampContractABI := abiutil.MustParseABI(chainCfg.PostageStampABI)
555-
556-
bzzTokenAddress, err := postagecontract.LookupERC20Address(ctx, transactionService, postageStampContractAddress, postageStampContractABI, chainEnabled)
557-
if err != nil {
558-
return nil, fmt.Errorf("lookup erc20 postage address: %w", err)
559-
}
560-
561-
postageStampContractService = postagecontract.New(
562-
overlayEthAddress,
563-
postageStampContractAddress,
564-
postageStampContractABI,
565-
bzzTokenAddress,
566-
transactionService,
567-
post,
568-
batchStore,
569-
chainEnabled,
570-
o.TrxDebugMode,
571-
)
572-
573-
eventListener = listener.New(b.syncingStopped, logger, chainBackend, postageStampContractAddress, postageStampContractABI, o.BlockTime, postageSyncingStallingTimeout, postageSyncingBackoffTimeout)
574-
b.listenerCloser = eventListener
575-
576-
batchSvc, err = batchservice.New(stateStore, batchStore, logger, eventListener, overlayEthAddress.Bytes(), post, sha3.New256, o.Resync)
577-
if err != nil {
578-
return nil, fmt.Errorf("init batch service: %w", err)
579-
}
580-
581522
// Construct protocols.
582523
pingPong := pingpong.New(p2ps, logger, tracer)
583524

@@ -672,40 +613,6 @@ func NewBee(
672613
}
673614
)
674615

675-
if batchSvc != nil && chainEnabled {
676-
logger.Info("waiting to sync postage contract data, this may take a while... more info available in Debug loglevel")
677-
678-
paused, err := postageStampContractService.Paused(ctx)
679-
if err != nil {
680-
logger.Error(err, "Error checking postage contract is paused")
681-
}
682-
683-
if paused {
684-
return nil, errors.New("postage contract is paused")
685-
}
686-
687-
if o.FullNodeMode {
688-
err = batchSvc.Start(ctx, postageSyncStart, initBatchState)
689-
syncStatus.Store(true)
690-
if err != nil {
691-
syncErr.Store(err)
692-
return nil, fmt.Errorf("unable to start batch service: %w", err)
693-
}
694-
} else {
695-
go func() {
696-
logger.Info("started postage contract data sync in the background...")
697-
err := batchSvc.Start(ctx, postageSyncStart, initBatchState)
698-
syncStatus.Store(true)
699-
if err != nil {
700-
syncErr.Store(err)
701-
logger.Error(err, "unable to sync batches")
702-
b.syncingStopped.Signal() // trigger shutdown in start.go
703-
}
704-
}()
705-
}
706-
707-
}
708-
709616
minThreshold := big.NewInt(2 * refreshRate)
710617
maxThreshold := big.NewInt(24 * refreshRate)
711618

@@ -907,107 +814,10 @@ func NewBee(
907814
apiService.SetIsWarmingUp(false)
908815
}()
909816

910-
stakingContractAddress := chainCfg.StakingAddress
911-
if o.StakingContractAddress != "" {
912-
if !common.IsHexAddress(o.StakingContractAddress) {
913-
return nil, errors.New("malformed staking contract address")
914-
}
915-
stakingContractAddress = common.HexToAddress(o.StakingContractAddress)
916-
}
917-
918-
stakingContract := staking.New(overlayEthAddress, stakingContractAddress, abiutil.MustParseABI(chainCfg.StakingABI), bzzTokenAddress, transactionService, common.BytesToHash(nonce), o.TrxDebugMode, uint8(o.ReserveCapacityDoubling))
919-
920-
if chainEnabled {
921-
922-
stake, err := stakingContract.GetPotentialStake(ctx)
923-
if err != nil {
924-
return nil, fmt.Errorf("get potential stake: %w", err)
925-
}
926-
927-
if stake.Cmp(big.NewInt(0)) > 0 {
928-
929-
if changedOverlay {
930-
logger.Debug("changing overlay address in staking contract")
931-
tx, err := stakingContract.ChangeStakeOverlay(ctx, common.BytesToHash(nonce))
932-
if err != nil {
933-
return nil, fmt.Errorf("cannot change staking overlay address: %v", err.Error())
934-
}
935-
logger.Info("overlay address changed in staking contract", "transaction", tx)
936-
}
937-
938-
// make sure that the staking contract has the up to date height
939-
tx, updated, err := stakingContract.UpdateHeight(ctx)
940-
if err != nil {
941-
return nil, fmt.Errorf("update height in staking contract: %w", err)
942-
}
943-
if updated {
944-
logger.Info("updated new reserve capacity doubling height in the staking contract", "transaction", tx, "new_height", o.ReserveCapacityDoubling)
945-
}
946-
947-
// Check if the staked amount is sufficient to cover the additional neighborhoods.
948-
// The staked amount must be at least 2^h * MinimumStake.
949-
if o.ReserveCapacityDoubling > 0 && stake.Cmp(big.NewInt(0).Mul(big.NewInt(1<<o.ReserveCapacityDoubling), staking.MinimumStakeAmount)) < 0 {
950-
logger.Warning("staked amount does not sufficiently cover the additional reserve capacity. Stake should be at least 2^h * 10 BZZ, where h is the number extra doublings.")
951-
}
952-
}
953-
}
954-
955817
var (
956-
pullerService *puller.Puller
957-
agent *storageincentives.Agent
818+
agent *storageincentives.Agent
958819
)
959820

960-
if o.FullNodeMode && !o.BootnodeMode {
961-
pullerService = puller.New(swarmAddress, stateStore, kad, localStore, pullSyncProtocol, p2ps, logger, puller.Options{})
962-
b.pullerCloser = pullerService
963-
964-
localStore.StartReserveWorker(ctx, pullerService, waitNetworkRFunc)
965-
nodeStatus.SetSync(pullerService)
966-
967-
if o.EnableStorageIncentives {
968-
969-
redistributionContractAddress := chainCfg.RedistributionAddress
970-
if o.RedistributionContractAddress != "" {
971-
if !common.IsHexAddress(o.RedistributionContractAddress) {
972-
return nil, errors.New("malformed redistribution contract address")
973-
}
974-
redistributionContractAddress = common.HexToAddress(o.RedistributionContractAddress)
975-
}
976-
977-
redistributionContract := redistribution.New(swarmAddress, overlayEthAddress, logger, transactionService, redistributionContractAddress, abiutil.MustParseABI(chainCfg.RedistributionABI), o.TrxDebugMode)
978-
979-
isFullySynced := func() bool {
980-
reserveTreshold := reserveCapacity * 5 / 10
981-
logger.Debug("Sync status check evaluated", "stabilized", detector.IsStabilized())
982-
return localStore.ReserveSize() >= reserveTreshold && pullerService.SyncRate() == 0 && detector.IsStabilized()
983-
}
984-
985-
agent, err = storageincentives.New(
986-
swarmAddress,
987-
overlayEthAddress,
988-
chainBackend,
989-
redistributionContract,
990-
postageStampContractService,
991-
stakingContract,
992-
localStore,
993-
isFullySynced,
994-
o.BlockTime,
995-
storageincentives.DefaultBlocksPerRound,
996-
storageincentives.DefaultBlocksPerPhase,
997-
stateStore,
998-
batchStore,
999-
erc20Service,
1000-
transactionService,
1001-
saludService,
1002-
logger,
1003-
)
1004-
if err != nil {
1005-
return nil, fmt.Errorf("storage incentives agent: %w", err)
1006-
}
1007-
b.storageIncetivesCloser = agent
1008-
}
1009-
1010-
}
1011821
multiResolver := multiresolver.NewMultiResolver(
1012822
multiresolver.WithConnectionConfigs(o.ResolverConnectionCfgs),
1013823
multiresolver.WithLogger(o.Logger),
@@ -1019,27 +829,25 @@ func NewBee(
1019829
steward := steward.New(localStore, retrieval, localStore.Cache())
1020830

1021831
extraOpts := api.ExtraOptions{
1022-
Pingpong: pingPong,
1023-
TopologyDriver: kad,
1024-
LightNodes: lightNodes,
1025-
Accounting: acc,
1026-
Pseudosettle: pseudosettleService,
1027-
Swap: swapService,
1028-
Chequebook: chequebookService,
1029-
BlockTime: o.BlockTime,
1030-
Storer: localStore,
1031-
Resolver: multiResolver,
1032-
Pss: pssService,
1033-
Gsoc: gsocService,
1034-
FeedFactory: feedFactory,
1035-
Post: post,
1036-
AccessControl: accesscontrol,
1037-
PostageContract: postageStampContractService,
1038-
Staking: stakingContract,
1039-
Steward: steward,
1040-
SyncStatus: syncStatusFn,
1041-
NodeStatus: nodeStatus,
1042-
PinIntegrity: localStore.PinIntegrity(),
832+
Pingpong: pingPong,
833+
TopologyDriver: kad,
834+
LightNodes: lightNodes,
835+
Accounting: acc,
836+
Pseudosettle: pseudosettleService,
837+
Swap: swapService,
838+
Chequebook: chequebookService,
839+
BlockTime: o.BlockTime,
840+
Storer: localStore,
841+
Resolver: multiResolver,
842+
Pss: pssService,
843+
Gsoc: gsocService,
844+
FeedFactory: feedFactory,
845+
Post: post,
846+
AccessControl: accesscontrol,
847+
Steward: steward,
848+
SyncStatus: syncStatusFn,
849+
NodeStatus: nodeStatus,
850+
PinIntegrity: localStore.PinIntegrity(),
1043851
}
1044852

1045853
if o.APIAddr != "" {

0 commit comments

Comments
 (0)