fix(order): fix errors in node_test

1. logger in mempool and txCache passed by Order module instead of loggers
2. fix goroutine not return after receiving signal from close channel in mempool error
3. fix idSlice is not initialized with 0 length in GenerateRaftPeers function
This commit is contained in:
Alexader 2020-09-25 15:21:05 +08:00 committed by Lizen
parent 76e3690bf0
commit 940f6857d0
7 changed files with 14 additions and 452 deletions

439
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -92,6 +92,7 @@ func NewNode(opts ...order.Option) (order.Order, error) {
PeerMgr: config.PeerMgr,
ChainHeight: config.Applied,
GetTransactionFunc: config.GetTransactionFunc,
Logger: config.Logger,
BatchSize: memConfig.BatchSize,
BatchTick: memConfig.BatchTick,
@ -551,8 +552,10 @@ func GenerateRaftPeers(config *order.Config) ([]raft.Peer, error) {
peers := make([]raft.Peer, 0, len(nodes))
// sort by node id
idSlice := make([]uint64, len(nodes))
i := 0
for id := range nodes {
idSlice = append(idSlice, id)
idSlice[i] = id
i++
}
sortkeys.Uint64s(idSlice)

View File

@ -2,7 +2,6 @@ package etcdraft
import (
"io/ioutil"
"math/rand"
"os"
"path/filepath"
"testing"
@ -86,7 +85,7 @@ func generateTx() *pb.Transaction {
Amount: 10,
},
Timestamp: time.Now().UnixNano(),
Nonce: uint64(rand.Int63()),
Nonce: 1,
}
_ = tx.Sign(privKey)
tx.TransactionHash = tx.Hash()

View File

@ -127,8 +127,8 @@ func (mpi *mempoolImpl) GetPendingNonceByAccount(account string) uint64 {
waitC := make(chan uint64)
getNonceRequest := &getNonceRequest{
account: account,
waitC: waitC,
waitC: waitC,
}
mpi.subscribe.pendingNonceC <- getNonceRequest
return <- waitC
return <-waitC
}

View File

@ -11,7 +11,6 @@ import (
"github.com/meshplus/bitxhub-kit/crypto/asym"
"github.com/meshplus/bitxhub-kit/types"
"github.com/meshplus/bitxhub-model/pb"
"github.com/meshplus/bitxhub/internal/loggers"
raftproto "github.com/meshplus/bitxhub/pkg/order/etcdraft/proto"
"github.com/meshplus/bitxhub/pkg/peermgr"
"github.com/meshplus/bitxhub/pkg/storage"
@ -44,12 +43,12 @@ func newMempoolImpl(config *Config, storage storage.Storage, batchC chan *raftpr
peerMgr: config.PeerMgr,
batchSeqNo: config.ChainHeight,
ledgerHelper: config.GetTransactionFunc,
logger: loggers.Logger(loggers.Order),
logger: config.Logger,
batchC: batchC,
storage: storage,
}
mpi.txStore = newTransactionStore()
mpi.txCache = newTxCache(config.TxSliceTimeout)
mpi.txCache = newTxCache(config.TxSliceTimeout, config.Logger)
mpi.subscribe = newSubscribe()
if config.BatchSize == 0 {
mpi.batchSize = DefaultBatchSize

View File

@ -4,8 +4,6 @@ import (
"time"
"github.com/meshplus/bitxhub-model/pb"
"github.com/meshplus/bitxhub/internal/loggers"
"github.com/sirupsen/logrus"
)
@ -21,7 +19,7 @@ type TxCache struct {
txSetTick time.Duration
}
func newTxCache(txSliceTimeout time.Duration) *TxCache {
func newTxCache(txSliceTimeout time.Duration, logger logrus.FieldLogger) *TxCache {
txCache := &TxCache{}
txCache.recvTxC = make(chan *pb.Transaction, DefaultTxCacheSize)
txCache.close = make(chan bool)
@ -29,7 +27,7 @@ func newTxCache(txSliceTimeout time.Duration) *TxCache {
txCache.timerC = make(chan bool)
txCache.stopTimerC = make(chan bool)
txCache.txSet = make([]*pb.Transaction, 0)
txCache.logger = loggers.Logger(loggers.Order)
txCache.logger = logger
if txSliceTimeout == 0 {
txCache.txSetTick = DefaultTxSetTick
} else {
@ -43,6 +41,7 @@ func (tc *TxCache) listenEvent() {
select {
case <-tc.close:
tc.logger.Info("Exit transaction cache")
return
case tx := <-tc.recvTxC:
tc.appendTx(tx)

View File

@ -7,8 +7,8 @@ import (
"github.com/meshplus/bitxhub-model/pb"
raftproto "github.com/meshplus/bitxhub/pkg/order/etcdraft/proto"
"github.com/meshplus/bitxhub/pkg/peermgr"
cmap "github.com/orcaman/concurrent-map"
"github.com/sirupsen/logrus"
)
const (
@ -82,6 +82,7 @@ type Config struct {
PeerMgr peermgr.PeerManager
GetTransactionFunc func(hash types.Hash) (*pb.Transaction, error)
ChainHeight uint64
Logger logrus.FieldLogger
}
type timerManager struct {