Skip to content

Commit 3cb23f0

Browse files
Merge branch 'develop' into reset_skipped_traces
2 parents 269bac1 + fa0be69 commit 3cb23f0

File tree

6 files changed

+138
-33
lines changed

6 files changed

+138
-33
lines changed

core/types/transaction.go

+57
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ import (
2020
"bytes"
2121
"container/heap"
2222
"errors"
23+
"fmt"
2324
"io"
2425
"math/big"
26+
"sort"
2527
"sync/atomic"
2628
"time"
2729

2830
"github.com/scroll-tech/go-ethereum/common"
2931
"github.com/scroll-tech/go-ethereum/common/math"
3032
"github.com/scroll-tech/go-ethereum/crypto"
33+
"github.com/scroll-tech/go-ethereum/log"
3134
"github.com/scroll-tech/go-ethereum/rlp"
3235
)
3336

@@ -522,6 +525,18 @@ func (s *TxByPriceAndTime) Pop() interface{} {
522525
return x
523526
}
524527

528+
// OrderedTransactionSet represents a set of transactions and some ordering on top of this set.
529+
type OrderedTransactionSet interface {
530+
// Peek returns the next transaction.
531+
Peek() *Transaction
532+
533+
// Shift removes the next transaction.
534+
Shift()
535+
536+
// Pop removes all transactions from the current account.
537+
Pop()
538+
}
539+
525540
// TransactionsByPriceAndNonce represents a set of transactions that can return
526541
// transactions in a profit-maximizing sorted order, while supporting removing
527542
// entire batches of transactions for non-executable accounts.
@@ -590,6 +605,48 @@ func (t *TransactionsByPriceAndNonce) Pop() {
590605
heap.Pop(&t.heads)
591606
}
592607

608+
// L1MessagesByQueueIndex represents a set of L1 messages ordered by their queue indices.
609+
type L1MessagesByQueueIndex struct {
610+
msgs []L1MessageTx
611+
}
612+
613+
func NewL1MessagesByQueueIndex(msgs []L1MessageTx) (*L1MessagesByQueueIndex, error) {
614+
// sort by queue index
615+
sort.Slice(msgs, func(i, j int) bool {
616+
return msgs[i].QueueIndex < msgs[j].QueueIndex
617+
})
618+
619+
// check for duplicates/gaps
620+
for ii := 0; ii < len(msgs)-1; ii++ {
621+
current := msgs[ii].QueueIndex
622+
next := msgs[ii+1].QueueIndex
623+
if next != current+1 {
624+
return nil, fmt.Errorf("invalid L1 message set, current index: %d, next index: %d", current, next)
625+
}
626+
}
627+
628+
return &L1MessagesByQueueIndex{msgs: msgs}, nil
629+
}
630+
631+
func (t *L1MessagesByQueueIndex) Peek() *Transaction {
632+
if len(t.msgs) == 0 {
633+
return nil
634+
}
635+
return NewTx(&t.msgs[0])
636+
}
637+
638+
func (t *L1MessagesByQueueIndex) Shift() {
639+
t.msgs = t.msgs[1:]
640+
}
641+
642+
func (t *L1MessagesByQueueIndex) Pop() {
643+
log.Error("Pop() is called on L1MessagesByQueueIndex")
644+
645+
// this is a logic error, the intention should be "Shift()",
646+
// so we will follow the same behavior in Pop
647+
t.Shift()
648+
}
649+
593650
// Message is a fully derived transaction and implements core.Message
594651
//
595652
// NOTE: In a future PR this will be removed.

core/types/transaction_test.go

+57
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
"testing"
2828
"time"
2929

30+
"github.com/stretchr/testify/assert"
31+
3032
"github.com/scroll-tech/go-ethereum/common"
3133
"github.com/scroll-tech/go-ethereum/crypto"
3234
"github.com/scroll-tech/go-ethereum/rlp"
@@ -405,6 +407,61 @@ func TestTransactionTimeSort(t *testing.T) {
405407
}
406408
}
407409

410+
func TestL1MessageQueueIndexSort(t *testing.T) {
411+
assert := assert.New(t)
412+
413+
msgs := []L1MessageTx{
414+
{QueueIndex: 3, Gas: 21016, To: &common.Address{1}, Data: []byte{0x01}, Sender: common.Address{2}},
415+
{QueueIndex: 6, Gas: 21016, To: &common.Address{1}, Data: []byte{0x01}, Sender: common.Address{2}},
416+
{QueueIndex: 1, Gas: 21016, To: &common.Address{1}, Data: []byte{0x01}, Sender: common.Address{2}},
417+
{QueueIndex: 2, Gas: 21016, To: &common.Address{1}, Data: []byte{0x01}, Sender: common.Address{3}},
418+
{QueueIndex: 5, Gas: 21016, To: &common.Address{1}, Data: []byte{0x01}, Sender: common.Address{3}},
419+
{QueueIndex: 4, Gas: 21016, To: &common.Address{1}, Data: []byte{0x01}, Sender: common.Address{3}},
420+
}
421+
422+
txset, err := NewL1MessagesByQueueIndex(msgs)
423+
assert.NoError(err)
424+
425+
nextIndex := uint64(1)
426+
427+
for {
428+
tx := txset.Peek()
429+
if tx == nil {
430+
break
431+
}
432+
433+
assert.True(tx.IsL1MessageTx())
434+
assert.Equal(nextIndex, tx.AsL1MessageTx().QueueIndex)
435+
436+
txset.Shift()
437+
nextIndex++
438+
}
439+
440+
assert.Equal(uint64(7), nextIndex)
441+
}
442+
443+
func TestL1MessageQueueIndexSortInvalid(t *testing.T) {
444+
assert := assert.New(t)
445+
446+
msgs := []L1MessageTx{
447+
{QueueIndex: 1, Gas: 21016, To: &common.Address{1}, Data: []byte{0x01}, Sender: common.Address{2}},
448+
{QueueIndex: 1, Gas: 21016, To: &common.Address{1}, Data: []byte{0x01}, Sender: common.Address{2}},
449+
{QueueIndex: 2, Gas: 21016, To: &common.Address{1}, Data: []byte{0x01}, Sender: common.Address{2}},
450+
}
451+
452+
_, err := NewL1MessagesByQueueIndex(msgs)
453+
assert.Error(err)
454+
455+
msgs = []L1MessageTx{
456+
{QueueIndex: 1, Gas: 21016, To: &common.Address{1}, Data: []byte{0x01}, Sender: common.Address{2}},
457+
{QueueIndex: 3, Gas: 21016, To: &common.Address{1}, Data: []byte{0x01}, Sender: common.Address{2}},
458+
{QueueIndex: 4, Gas: 21016, To: &common.Address{1}, Data: []byte{0x01}, Sender: common.Address{2}},
459+
}
460+
461+
_, err = NewL1MessagesByQueueIndex(msgs)
462+
assert.Error(err)
463+
}
464+
408465
// TestTransactionCoding tests serializing/de-serializing to/from rlp and JSON.
409466
func TestTransactionCoding(t *testing.T) {
410467
key, err := crypto.GenerateKey()

miner/worker.go

+11-20
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
962962
return receipt.Logs, traces, nil
963963
}
964964

965-
func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coinbase common.Address, interrupt *int32) (bool, bool) {
965+
func (w *worker) commitTransactions(txs types.OrderedTransactionSet, coinbase common.Address, interrupt *int32) (bool, bool) {
966966
var circuitCapacityReached bool
967967

968968
// Short circuit if current is nil
@@ -1348,29 +1348,16 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
13481348
w.commit(uncles, nil, false, tstart)
13491349
}
13501350
// fetch l1Txs
1351-
l1Txs := make(map[common.Address]types.Transactions)
1352-
pendingL1Txs := 0
1351+
var l1Messages []types.L1MessageTx
13531352
if w.chainConfig.Scroll.ShouldIncludeL1Messages() {
1354-
l1Messages := w.collectPendingL1Messages(env.nextL1MsgIndex)
1355-
pendingL1Txs = len(l1Messages)
1356-
for _, l1msg := range l1Messages {
1357-
tx := types.NewTx(&l1msg)
1358-
sender := l1msg.Sender
1359-
senderTxs, ok := l1Txs[sender]
1360-
if ok {
1361-
senderTxs = append(senderTxs, tx)
1362-
l1Txs[sender] = senderTxs
1363-
} else {
1364-
l1Txs[sender] = types.Transactions{tx}
1365-
}
1366-
}
1353+
l1Messages = w.collectPendingL1Messages(env.nextL1MsgIndex)
13671354
}
13681355
// Fill the block with all available pending transactions.
13691356
pending := w.eth.TxPool().Pending(true)
13701357
// Short circuit if there is no available pending transactions.
13711358
// But if we disable empty precommit already, ignore it. Since
13721359
// empty block is necessary to keep the liveness of the network.
1373-
if len(pending) == 0 && pendingL1Txs == 0 && atomic.LoadUint32(&w.noempty) == 0 {
1360+
if len(pending) == 0 && len(l1Messages) == 0 && atomic.LoadUint32(&w.noempty) == 0 {
13741361
w.updateSnapshot()
13751362
return
13761363
}
@@ -1383,9 +1370,13 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
13831370
}
13841371
}
13851372
var skipCommit, circuitCapacityReached bool
1386-
if w.chainConfig.Scroll.ShouldIncludeL1Messages() && len(l1Txs) > 0 {
1387-
log.Trace("Processing L1 messages for inclusion", "count", pendingL1Txs)
1388-
txs := types.NewTransactionsByPriceAndNonce(w.current.signer, l1Txs, header.BaseFee)
1373+
if w.chainConfig.Scroll.ShouldIncludeL1Messages() && len(l1Messages) > 0 {
1374+
log.Trace("Processing L1 messages for inclusion", "count", len(l1Messages))
1375+
txs, err := types.NewL1MessagesByQueueIndex(l1Messages)
1376+
if err != nil {
1377+
log.Error("Failed to create L1 message set", "l1Messages", l1Messages, "err", err)
1378+
return
1379+
}
13891380
skipCommit, circuitCapacityReached = w.commitTransactions(txs, w.coinbase, interrupt)
13901381
if skipCommit {
13911382
return

params/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 4 // Major version component of the current release
2626
VersionMinor = 4 // Minor version component of the current release
27-
VersionPatch = 10 // Patch version component of the current release
27+
VersionPatch = 12 // Patch version component of the current release
2828
VersionMeta = "sepolia" // Version metadata to append to the version string
2929
)
3030

rollup/circuitcapacitychecker/libzkp/Cargo.lock

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup/circuitcapacitychecker/libzkp/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ maingate = { git = "https://github.com/scroll-tech/halo2wrong", branch = "halo2-
2020
halo2curves = { git = "https://github.com/scroll-tech/halo2curves.git", branch = "0.3.1-derive-serde" }
2121

2222
[dependencies]
23-
prover = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.9.1", default-features = false, features = ["parallel_syn", "scroll", "shanghai"] }
23+
prover = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.9.2", default-features = false, features = ["parallel_syn", "scroll", "shanghai"] }
2424

2525
anyhow = "1.0"
2626
log = "0.4"

0 commit comments

Comments
 (0)