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)
for _, tx := range txs {
// check the sequence number of tx
txAccount, err := getAccount(tx)
if err != nil {
mpi.logger.Warningf("get tx account failed, err: %s", err.Error())
continue
}
txAccount := tx.Account()
currentSeqNo := mpi.txStore.nonceCache.getPendingNonce(txAccount)
if tx.Nonce < currentSeqNo {
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
import (
"fmt"
"testing"
"github.com/meshplus/bitxhub-model/pb"
"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) {
ast := assert.New(t)
mpi, _ := mockMempoolImpl()

View File

@ -1,7 +1,6 @@
package mempool
import (
"fmt"
"strconv"
"sync/atomic"
"time"
@ -103,11 +102,3 @@ func newTimer(d time.Duration) *timerManager {
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
}