Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refrator: 重构了discovery包,删除了重复的代码 #5157

Merged
merged 2 commits into from
Aug 9, 2022
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
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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 @@ -69,7 +72,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