Skip to content

Commit

Permalink
refrator: 重构了discovery包,删除了重复的代码 (#5157)
Browse files Browse the repository at this point in the history
* refrator: network

* fix: fix test error in venus-shared
  • Loading branch information
hunjixin authored Aug 9, 2022
1 parent 4d85109 commit 15088ed
Show file tree
Hide file tree
Showing 35 changed files with 155 additions and 938 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jobs:
./gengen --keypath ./fixtures/live --out-car ./fixtures/live/genesis.car --out-json ./fixtures/live/gen.json --config ./fixtures/setup.json
./gengen --keypath ./fixtures/test --out-car ./fixtures/test/genesis.car --out-json ./fixtures/test/gen.json --config ./fixtures/setup.json
- name: Integration Test
run: go test -coverpkg=./... -coverprofile=coverage_venus_shared.txt -covermode=atomic -timeout=30m -parallel=4 -v ./venus-shared/...

- name: Unit Test
run: go test -coverpkg=./... -coverprofile=coverage_unit.txt -covermode=atomic -timeout=30m -parallel=4 -v ./... -integration=false -unit=true

Expand All @@ -61,7 +64,7 @@ jobs:
uses: codecov/codecov-action@v2
with:
token:
files: ./coverage_unit.txt,./coverage_integration.txt
files: ./coverage_unit.txt,./coverage_integration.txt,./coverage_venus_shared.txt
flags: unittests,integration
name: venus
fail_ci_if_error: true
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ actor-render:
actor-replica:
cd venus-devtool && go run ./compatible/actors/*.go replica --dst ../venus-shared/actors/

test:
test:test-venus-shared
go build -o genesis-file-server ./tools/genesis-file-server
go build -o gengen ./tools/gengen
./gengen --keypath ./fixtures/live --out-car ./fixtures/live/genesis.car --out-json ./fixtures/live/gen.json --config ./fixtures/setup.json
./gengen --keypath ./fixtures/test --out-car ./fixtures/test/genesis.car --out-json ./fixtures/test/gen.json --config ./fixtures/setup.json
go test -v ./... -integration=true -unit=false
go test $(go list ./... | grep -v /venus-shared/) -unit=false

lint: $(BUILD_DEPS)
golangci-lint run
Expand Down
27 changes: 10 additions & 17 deletions app/node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"fmt"
"time"

"github.com/filecoin-project/venus/app/submodule/dagservice"
"github.com/filecoin-project/venus/app/submodule/network"

logging "github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p"
"github.com/pkg/errors"
Expand All @@ -13,13 +16,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 +113,22 @@ 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))
if err != nil {
return nil, errors.Wrap(err, "failed to build node.Network")
}

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

nd.chain, err = chain.NewChainSubmodule(ctx, (*builder)(b), nd.circulatiingSupplyCalculator)
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.Chain")
return nil, errors.Wrap(err, "failed to build node.Network")
}

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

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 15088ed

Please sign in to comment.