fix(executor): get IBTP directly instead of unmarshal

This commit is contained in:
Lizen0512 2020-10-22 16:43:43 +08:00
parent af89883ec8
commit a138baa674
3 changed files with 1 additions and 35 deletions

View File

@ -155,11 +155,7 @@ func (mpi *mempoolImpl) processTransactions(txs []*pb.Transaction) error {
validTxs := make(map[string][]*pb.Transaction) validTxs := make(map[string][]*pb.Transaction)
for _, tx := range txs { for _, tx := range txs {
// check the sequence number of tx // check the sequence number of tx
txAccount, err := getAccount(tx) txAccount := tx.Account()
if err != nil {
mpi.logger.Warningf("get tx account failed, err: %s", err.Error())
continue
}
currentSeqNo := mpi.txStore.nonceCache.getPendingNonce(txAccount) currentSeqNo := mpi.txStore.nonceCache.getPendingNonce(txAccount)
if tx.Nonce < currentSeqNo { if tx.Nonce < currentSeqNo {
mpi.logger.Warningf("Account %s, current sequence number is %d, required %d", txAccount, tx.Nonce, currentSeqNo+1) mpi.logger.Warningf("Account %s, current sequence number is %d, required %d", txAccount, tx.Nonce, currentSeqNo+1)

View File

@ -1,32 +1,11 @@
package mempool package mempool
import ( import (
"fmt"
"testing" "testing"
"github.com/meshplus/bitxhub-model/pb"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestGetAccount(t *testing.T) {
ast := assert.New(t)
privKey := genPrivKey()
address, _ := privKey.PublicKey().Address()
tx := constructIBTPTx(uint64(1), &privKey)
addr, err := getAccount(tx)
ast.Nil(err)
expectedAddr := fmt.Sprintf("%s-%s-%d", address, address, pb.IBTP_INTERCHAIN)
ast.Equal(expectedAddr, addr)
tx = &pb.Transaction{
From: InterchainContractAddr,
To: InterchainContractAddr,
}
addr, err = getAccount(tx)
ast.Nil(err)
ast.Equal(addr,InterchainContractAddr.String())
}
func TestPoolIsFull(t *testing.T) { func TestPoolIsFull(t *testing.T) {
ast := assert.New(t) ast := assert.New(t)
mpi, _ := mockMempoolImpl() mpi, _ := mockMempoolImpl()

View File

@ -1,7 +1,6 @@
package mempool package mempool
import ( import (
"fmt"
"strconv" "strconv"
"sync/atomic" "sync/atomic"
"time" "time"
@ -103,11 +102,3 @@ func newTimer(d time.Duration) *timerManager {
timeoutEventC: make(chan bool), timeoutEventC: make(chan bool),
} }
} }
func getAccount(tx *pb.Transaction) (string, error) {
if tx.IBTP != nil {
account := fmt.Sprintf("%s-%s-%d", tx.IBTP.From, tx.IBTP.To, tx.IBTP.Category())
return account, nil
}
return tx.From.String(), nil
}