Skip to content

Commit

Permalink
refrator: network
Browse files Browse the repository at this point in the history
  • Loading branch information
hunjixin committed Aug 4, 2022
1 parent 14d26a4 commit 71a74ba
Show file tree
Hide file tree
Showing 33 changed files with 141 additions and 923 deletions.
25 changes: 9 additions & 16 deletions app/node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package node
import (
"context"
"fmt"
"github.com/filecoin-project/venus/app/submodule/dagservice"
"github.com/filecoin-project/venus/app/submodule/network"
"time"

logging "github.com/ipfs/go-log"
Expand All @@ -13,13 +15,10 @@ import (
"github.com/filecoin-project/venus/app/submodule/chain"
"github.com/filecoin-project/venus/app/submodule/common"
config2 "github.com/filecoin-project/venus/app/submodule/config"
"github.com/filecoin-project/venus/app/submodule/dagservice"
"github.com/filecoin-project/venus/app/submodule/discovery"
"github.com/filecoin-project/venus/app/submodule/market"
"github.com/filecoin-project/venus/app/submodule/mining"
"github.com/filecoin-project/venus/app/submodule/mpool"
"github.com/filecoin-project/venus/app/submodule/multisig"
"github.com/filecoin-project/venus/app/submodule/network"
"github.com/filecoin-project/venus/app/submodule/paych"
"github.com/filecoin-project/venus/app/submodule/storagenetworking"
"github.com/filecoin-project/venus/app/submodule/syncer"
Expand Down Expand Up @@ -113,28 +112,23 @@ func (b *Builder) build(ctx context.Context) (*Node, error) {
return nil, errors.Wrap(err, "failed to build node.blockstore")
}

nd.network, err = network.NewNetworkSubmodule(ctx, (*builder)(b))
nd.chain, err = chain.NewChainSubmodule(ctx, (*builder)(b), nd.circulatiingSupplyCalculator)
if err != nil {
return nil, errors.Wrap(err, "failed to build node.Network")
return nil, errors.Wrap(err, "failed to build node.Chain")
}

nd.blockservice, err = dagservice.NewDagserviceSubmodule(ctx, (*builder)(b), nd.network)
nd.network, err = network.NewNetworkSubmodule(ctx, nd.chain.ChainReader, nd.chain.MessageStore, (*builder)(b))
if err != nil {
return nil, errors.Wrap(err, "failed to build node.dagservice")
return nil, errors.Wrap(err, "failed to build node.Network")
}

nd.chain, err = chain.NewChainSubmodule(ctx, (*builder)(b), nd.circulatiingSupplyCalculator)
nd.blockservice, err = dagservice.NewDagserviceSubmodule(ctx, (*builder)(b), nd.network)
if err != nil {
return nil, errors.Wrap(err, "failed to build node.Chain")
return nil, errors.Wrap(err, "failed to build node.dagservice")
}

// todo change builder interface to read config
nd.discovery, err = discovery.NewDiscoverySubmodule(ctx, (*builder)(b), nd.network, nd.chain.ChainReader, nd.chain.MessageStore)
if err != nil {
return nil, errors.Wrap(err, "failed to build node.discovery")
}

nd.syncer, err = syncer.NewSyncerSubmodule(ctx, (*builder)(b), nd.blockstore, nd.network, nd.discovery, nd.chain, nd.circulatiingSupplyCalculator)
nd.syncer, err = syncer.NewSyncerSubmodule(ctx, (*builder)(b), nd.blockstore, nd.network, nd.chain, nd.circulatiingSupplyCalculator)
if err != nil {
return nil, errors.Wrap(err, "failed to build node.Syncer")
}
Expand Down Expand Up @@ -177,7 +171,6 @@ func (b *Builder) build(ctx context.Context) (*Node, error) {
nd.blockstore,
nd.network,
nd.blockservice,
nd.discovery,
nd.chain,
nd.syncer,
nd.wallet,
Expand Down
21 changes: 6 additions & 15 deletions app/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
chain2 "github.com/filecoin-project/venus/app/submodule/chain"
configModule "github.com/filecoin-project/venus/app/submodule/config"
"github.com/filecoin-project/venus/app/submodule/dagservice"
"github.com/filecoin-project/venus/app/submodule/discovery"
"github.com/filecoin-project/venus/app/submodule/market"
"github.com/filecoin-project/venus/app/submodule/mining"
"github.com/filecoin-project/venus/app/submodule/mpool"
Expand Down Expand Up @@ -75,7 +74,6 @@ type Node struct {
blockstore *blockstore.BlockstoreSubmodule
blockservice *dagservice.DagServiceSubmodule
network *network2.NetworkSubmodule
discovery *discovery.DiscoverySubmodule

//
// Subsystems
Expand Down Expand Up @@ -125,10 +123,6 @@ func (node *Node) MultiSig() *multisig.MultiSigSubmodule {
return node.multiSig
}

func (node *Node) Discovery() *discovery.DiscoverySubmodule {
return node.discovery
}

func (node *Node) Network() *network2.NetworkSubmodule {
return node.network
}
Expand Down Expand Up @@ -172,11 +166,6 @@ func (node *Node) Start(ctx context.Context) error {
var syncCtx context.Context
syncCtx, node.syncer.CancelChainSync = context.WithCancel(context.Background())

// Start node discovery
if err = node.discovery.Start(node.offlineMode); err != nil {
return err
}

// start syncer module to receive new blocks and start sync to latest height
err = node.syncer.Start(syncCtx)
if err != nil {
Expand All @@ -194,6 +183,12 @@ func (node *Node) Start(ctx context.Context) error {
return err
}

// network should start late,
err = node.network.Start(syncCtx)
if err != nil {
return err
}

return nil
}

Expand All @@ -207,10 +202,6 @@ func (node *Node) Stop(ctx context.Context) {
log.Infof("shutting down chain syncer...")
node.syncer.Stop(ctx)

// Stop discovery submodule
log.Infof("shutting down discovery...")
node.discovery.Stop()

// Stop network submodule
log.Infof("shutting down network...")
node.network.Stop(ctx)
Expand Down
9 changes: 0 additions & 9 deletions app/submodule/discovery/discovery_api.go

This file was deleted.

137 changes: 0 additions & 137 deletions app/submodule/discovery/discovery_submodule.go

This file was deleted.

Loading

0 comments on commit 71a74ba

Please sign in to comment.