fix Panic In ProcessOrderPending Leads To Chain Halt (#392)

Co-authored-by: Liam Lai <liamlai@Liams-Laptop.local>
This commit is contained in:
Liam 2024-01-19 08:22:24 +08:00 committed by GitHub
parent a76c885774
commit 81ff6421d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 0 deletions

View file

@ -304,6 +304,9 @@ func NewOrderTransactionByNonce(signer OrderSigner, txs map[common.Address]Order
// Initialize a price based heap with the head transactions
heads := make(OrderTxByNonce, 0, len(txs))
for from, accTxs := range txs {
if len(accTxs) == 0 {
continue
}
heads = append(heads, accTxs[0])
// Ensure the sender address is from the signer
acc, _ := OrderSender(signer, accTxs[0])

View file

@ -0,0 +1,31 @@
package types
import (
"crypto/ecdsa"
"math/big"
"testing"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/crypto"
)
func TestNewOrderTransactionByNonce(t *testing.T) {
// Generate a batch of accounts to start with
keys := make([]*ecdsa.PrivateKey, 1)
for i := 0; i < len(keys); i++ {
keys[i], _ = crypto.GenerateKey()
}
groups := map[common.Address]OrderTransactions{}
for start, key := range keys {
addr := crypto.PubkeyToAddress(key.PublicKey)
for i := 0; i < 1; i++ {
//tx, _ := SignTx(NewTransaction(uint64(start+i), common.Address{}, big.NewInt(100), 100, big.NewInt(int64(start+i)), nil), signer, key)
orderTx := NewOrderTransaction(uint64(start+i), big.NewInt(1), big.NewInt(2), common.Address{}, common.Address{}, common.Address{}, common.Address{}, "new", "BID", "test", common.Hash{}, 1001)
groups[addr] = append(groups[addr], orderTx)
}
}
tx := NewOrderTransactionByNonce(OrderTxSigner{}, groups)
t.Log(tx)
}