Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix GetTxs
  • Loading branch information
Manav-Aggarwal committed Jun 24, 2025
commit b4e5877dd3f88fd142f015d827b2665b59a13d2b
26 changes: 25 additions & 1 deletion execution/evm/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"
"math/big"
"net/http"
"sort"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -137,7 +139,29 @@ func (c *EngineClient) GetTxs(ctx context.Context) ([][]byte, error) {

// add pending txs
for _, accountTxs := range result.Pending {
for _, tx := range accountTxs {
// Extract and sort keys to iterate in ordered fashion
keys := make([]string, 0, len(accountTxs))
for key := range accountTxs {
keys = append(keys, key)
}

// Sort keys as integers (they represent nonces)
sort.Slice(keys, func(i, j int) bool {
// Parse as integers for proper numerical sorting
a, errA := strconv.Atoi(keys[i])
b, errB := strconv.Atoi(keys[j])

// If parsing fails, fall back to string comparison
if errA != nil || errB != nil {
return keys[i] < keys[j]
}

return a < b
})

// Iterate over sorted keys
for _, key := range keys {
tx := accountTxs[key]
txBytes, err := tx.MarshalBinary()
if err != nil {
return nil, fmt.Errorf("failed to marshal transaction: %w", err)
Expand Down
24 changes: 8 additions & 16 deletions execution/evm/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,15 @@ func TestEngineExecution(t *testing.T) {
nTxs = 0
}

// Create transactions but don't submit to mempool for rollkit-reth
// Rollkit handles transaction inclusion via Engine API payload attributes
var payload [][]byte
if nTxs > 0 {
txs := make([]*ethTypes.Transaction, nTxs)
for i := range txs {
txs[i] = GetRandomTransaction(t, TEST_PRIVATE_KEY, TEST_TO_ADDRESS, CHAIN_ID, 22000, &lastNonce)
}

// Convert transactions to payload format (raw bytes)
payload = make([][]byte, len(txs))
for i, tx := range txs {
txBytes, err := tx.MarshalBinary()
require.NoError(tt, err)
payload[i] = txBytes
}
txs := make([]*ethTypes.Transaction, nTxs)
for i := range txs {
txs[i] = GetRandomTransaction(t, TEST_PRIVATE_KEY, TEST_TO_ADDRESS, CHAIN_ID, 22000, &lastNonce)
SubmitTransaction(tt, txs[i])
}

payload, err := executionClient.GetTxs(ctx)
require.NoError(tt, err)

if nTxs > 0 {
require.Lenf(tt, payload, nTxs, "expected %d transactions, got %d", nTxs, len(payload))
} else {
Expand Down