Merge pull request #307 from meshplus/solo-peers

fix(solo): fix solo panic bug when call peers releated interface
This commit is contained in:
Sandy Zhou 2020-12-28 15:56:10 +08:00 committed by GitHub
commit 2985baf07c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View File

@ -137,12 +137,9 @@ func GenerateBitXHubWithoutOrder(rep *repo.Repo) (*BitXHub, error) {
return nil, fmt.Errorf("create ViewExecutor: %w", err)
}
peerMgr := &peermgr.Swarm{}
if !rep.Config.Solo {
peerMgr, err = peermgr.New(rep, loggers.Logger(loggers.P2P), rwLdg)
if err != nil {
return nil, fmt.Errorf("create peer manager: %w", err)
}
peerMgr, err := peermgr.New(rep, loggers.Logger(loggers.P2P), rwLdg)
if err != nil {
return nil, fmt.Errorf("create peer manager: %w", err)
}
return &BitXHub{

View File

@ -12,6 +12,7 @@ import (
"github.com/meshplus/bitxhub/pkg/order/etcdraft"
raftproto "github.com/meshplus/bitxhub/pkg/order/etcdraft/proto"
"github.com/meshplus/bitxhub/pkg/order/mempool"
"github.com/meshplus/bitxhub/pkg/peermgr"
"github.com/sirupsen/logrus"
)
@ -24,12 +25,13 @@ type Node struct {
stateC chan *mempool.ChainState
txCache *mempool.TxCache // cache the transactions received from api
batchMgr *etcdraft.BatchTimer
lastExec uint64 // the index of the last-applied block
packSize int // maximum number of transaction packages
blockTick time.Duration // block packed period
lastExec uint64 // the index of the last-applied block
packSize int // maximum number of transaction packages
blockTick time.Duration // block packed period
peerMgr peermgr.PeerManager // network manager
ctx context.Context
cancel context.CancelFunc
ctx context.Context
cancel context.CancelFunc
sync.RWMutex
}
@ -117,6 +119,7 @@ func NewNode(opts ...order.Option) (order.Order, error) {
mempool: mempoolInst,
txCache: txCache,
batchMgr: batchTimerMgr,
peerMgr: config.PeerMgr,
proposeC: batchC,
logger: config.Logger,
ctx: ctx,