Skip to content

Commit

Permalink
fix Panic In ProcessOrderPending Leads To Chain Halt (#392)
Browse files Browse the repository at this point in the history
Co-authored-by: Liam Lai <liamlai@Liams-Laptop.local>
  • Loading branch information
liam-lai and Liam Lai committed Jan 19, 2024
1 parent a76c885 commit 81ff642
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/types/order_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
31 changes: 31 additions & 0 deletions core/types/order_transaction_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 81ff642

Please sign in to comment.