Skip to content

Commit 1e5d061

Browse files
committed
Merge branch 'upstream/v2.61.13-RC1' into zjg/merge-v2.61.13-RC1
2 parents 86fc53f + c8054e3 commit 1e5d061

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1175
-490
lines changed

.github/workflows/ci_zkevm.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ on:
55
- dev
66
- zkevm
77
- zkevm-2.60
8+
- stable/**
89
pull_request:
910
branches:
1011
- dev
1112
- zkevm
1213
- zkevm-2.60
13-
- stable*
14+
- stable/**
1415
types:
1516
- opened
1617
- reopened

.github/workflows/doc-rpc.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ on:
44
branches:
55
- dev
66
- zkevm
7+
- stable/**
78
pull_request:
89
branches:
910
- dev
1011
- zkevm
12+
- stable/**
1113
types:
1214
- opened
1315
- reopened

.github/workflows/test-resequence.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ on:
44
branches:
55
- dev
66
- zkevm
7+
- stable/**
78
pull_request:
89
branches:
910
- dev
1011
- zkevm
12+
- stable/**
1113
types:
1214
- opened
1315
- reopened

.github/workflows/test-unwinds.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
- dev
66
- zkevm
77
- zkevm-2.60
8+
- stable/**
89
workflow_dispatch:
910

1011
jobs:

cmd/rpcdaemon/cli/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ func RootCommand() (*cobra.Command, *httpcfg.HttpCfg) {
144144
rootCmd.PersistentFlags().DurationVar(&cfg.OverlayReplayBlockTimeout, "rpc.overlay.replayblocktimeout", rpccfg.DefaultOverlayReplayBlockTimeout, "Maximum amount of time to wait for the answer to replay a single block when called from an overlay_getLogs call.")
145145
rootCmd.PersistentFlags().IntVar(&cfg.BatchLimit, utils.RpcBatchLimit.Name, utils.RpcBatchLimit.Value, utils.RpcBatchLimit.Usage)
146146
rootCmd.PersistentFlags().IntVar(&cfg.ReturnDataLimit, utils.RpcReturnDataLimit.Name, utils.RpcReturnDataLimit.Value, utils.RpcReturnDataLimit.Usage)
147+
rootCmd.PersistentFlags().Uint64Var(&cfg.LogsMaxRange, utils.RpcLogsMaxRange.Name, utils.RpcLogsMaxRange.Value, utils.RpcLogsMaxRange.Usage)
147148
rootCmd.PersistentFlags().BoolVar(&cfg.AllowUnprotectedTxs, utils.AllowUnprotectedTxs.Name, utils.AllowUnprotectedTxs.Value, utils.AllowUnprotectedTxs.Usage)
148149
rootCmd.PersistentFlags().IntVar(&cfg.MaxGetProofRewindBlockCount, utils.RpcMaxGetProofRewindBlockCount.Name, utils.RpcMaxGetProofRewindBlockCount.Value, utils.RpcMaxGetProofRewindBlockCount.Usage)
149150
rootCmd.PersistentFlags().Uint64Var(&cfg.OtsMaxPageSize, utils.OtsSearchMaxCapFlag.Name, utils.OtsSearchMaxCapFlag.Value, utils.OtsSearchMaxCapFlag.Usage)

cmd/rpcdaemon/cli/httpcfg/http_cfg.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,11 @@ type HttpCfg struct {
8383
LogDirVerbosity string
8484
LogDirPath string
8585

86-
BatchLimit int // Maximum number of requests in a batch
87-
ReturnDataLimit int // Maximum number of bytes returned from calls (like eth_call)
88-
AllowUnprotectedTxs bool // Whether to allow non EIP-155 protected transactions txs over RPC
89-
MaxGetProofRewindBlockCount int //Max GetProof rewind block count
86+
BatchLimit int // Maximum number of requests in a batch
87+
ReturnDataLimit int // Maximum number of bytes returned from calls (like eth_call)
88+
LogsMaxRange uint64 // Maximum number of logs that can be requested in a single call
89+
AllowUnprotectedTxs bool // Whether to allow non EIP-155 protected transactions txs over RPC
90+
MaxGetProofRewindBlockCount int //Max GetProof rewind block count
9091
// Ots API
9192
OtsMaxPageSize uint64
9293

cmd/utils/flags.go

+33
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ var (
415415
Usage: "L2 datastreamer endpoint",
416416
Value: "",
417417
}
418+
L2DataStreamerUseTLSFlag = cli.BoolFlag{
419+
Name: "zkevm.l2-datastreamer-use-tls",
420+
Usage: "Use TLS connection to L2 datastreamer endpoint",
421+
Value: false,
422+
}
418423
L2DataStreamerTimeout = cli.StringFlag{
419424
Name: "zkevm.l2-datastreamer-timeout",
420425
Usage: "The time to wait for data to arrive from the stream before reporting an error (0s doesn't check)",
@@ -591,6 +596,11 @@ var (
591596
Usage: "A comma separated list of grpc addresses that host executors",
592597
Value: "",
593598
}
599+
ExecutorEnabled = cli.BoolFlag{
600+
Name: "zkevm.executor-enabled",
601+
Usage: "Enables the executor. Used for testing limbo, when executor-urls are set, but we don't want to use them, only in limbo to verify limbo transactions. For this case, set it to false. Defaulted to true",
602+
Value: true,
603+
}
594604
ExecutorStrictMode = cli.BoolFlag{
595605
Name: "zkevm.executor-strict",
596606
Usage: "Defaulted to true to ensure you must set some executor URLs, bypass this restriction by setting to false",
@@ -612,6 +622,12 @@ var (
612622
Usage: "A size of the memdb used on witness generation in format \"2GB\". Might fail generation for older batches if not enough for the unwind.",
613623
Value: datasizeFlagValue(2 * datasize.GB),
614624
}
625+
WitnessUnwindLimit = cli.Uint64Flag{
626+
Name: "zkevm.witness-unwind-limit",
627+
Usage: "The maximum number of blocks the witness generation can unwind",
628+
Value: 500_000,
629+
}
630+
615631
ExecutorMaxConcurrentRequests = cli.IntFlag{
616632
Name: "zkevm.executor-max-concurrent-requests",
617633
Usage: "The maximum number of concurrent requests to the executor",
@@ -667,6 +683,11 @@ var (
667683
Usage: "Allow the sequencer to proceed transactions with 0 gas price",
668684
Value: false,
669685
}
686+
RejectLowGasPriceTransactions = cli.BoolFlag{
687+
Name: "zkevm.reject-low-gas-price-transactions",
688+
Usage: "Reject the sequencer to proceed transactions with low gas price",
689+
Value: false,
690+
}
670691
AllowPreEIP155Transactions = cli.BoolFlag{
671692
Name: "zkevm.allow-pre-eip155-transactions",
672693
Usage: "Allow the sequencer to proceed pre-EIP155 transactions",
@@ -788,6 +809,11 @@ var (
788809
Usage: "Contracts that will have all of their storage added to the witness every time",
789810
Value: "",
790811
}
812+
BadTxAllowance = cli.Uint64Flag{
813+
Name: "zkevm.bad-tx-allowance",
814+
Usage: "The maximum number of times a transaction that consumes too many counters to fit into a batch will be attempted before it is rejected outright by eth_sendRawTransaction",
815+
Value: 2,
816+
}
791817
ACLPrintHistory = cli.IntFlag{
792818
Name: "acl.print-history",
793819
Usage: "Number of entries to print from the ACL history on node start up",
@@ -835,6 +861,11 @@ var (
835861
Usage: "Maximum number of bytes returned from eth_call or similar invocations",
836862
Value: 100_000,
837863
}
864+
RpcLogsMaxRange = cli.Uint64Flag{
865+
Name: "rpc.logs.maxrange",
866+
Usage: "Maximum range of logs that can be requested in a single call",
867+
Value: 1000,
868+
}
838869
HTTPTraceFlag = cli.BoolFlag{
839870
Name: "http.trace",
840871
Usage: "Print all HTTP requests to logs with INFO level",
@@ -2376,6 +2407,8 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
23762407

23772408
if ctx.IsSet(TxPoolGossipDisableFlag.Name) {
23782409
cfg.DisableTxPoolGossip = ctx.Bool(TxPoolGossipDisableFlag.Name)
2410+
} else {
2411+
cfg.DisableTxPoolGossip = txpoolcfg.DefaultConfig.NoGossip
23792412
}
23802413
}
23812414

core/vm/zk_batch_counters.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@ func (bcc *BatchCounterCollector) AddNewTransactionCounters(txCounters *Transact
8888
return bcc.CheckForOverflow(false) //no need to calculate the merkle proof here
8989
}
9090

91+
// SingleTransactionOverflowCheck is used to check if a single transaction would overflow the batch counters
92+
// by creating a new counter collector and priming it for a single block with just this transaction
93+
// in it. There is an assumption here that the tx counters being passed in have already been through execution
94+
func (bcc *BatchCounterCollector) SingleTransactionOverflowCheck(txCounters *TransactionCounter) (bool, error) {
95+
err := txCounters.CalculateRlp()
96+
if err != nil {
97+
return true, err
98+
}
99+
100+
bcc.transactions = append(bcc.transactions, txCounters)
101+
bcc.UpdateRlpCountersCache(txCounters)
102+
bcc.blockCount = 1 // simulate a single block
103+
104+
bcc.UpdateExecutionAndProcessingCountersCache(txCounters)
105+
106+
return bcc.CheckForOverflow(false) //no need to calculate the merkle proof here
107+
}
108+
91109
func (bcc *BatchCounterCollector) RemovePreviousTransactionCounters() {
92110
lastTx := bcc.transactions[len(bcc.transactions)-1]
93111
bcc.UndoTransactionCountersCache(lastTx)
@@ -275,12 +293,15 @@ func (bcc *BatchCounterCollector) CombineCollectorsNoChanges() Counters {
275293
}
276294
}
277295

296+
txCounters := NewCounters()
278297
for _, tx := range bcc.transactions {
279-
txCounters := tx.CombineCounters()
298+
_ = tx.CombineCountersInto(&txCounters)
280299
for k, v := range txCounters {
281300
combined[k].used += v.used
282301
combined[k].remaining -= v.used
283302
}
303+
304+
txCounters.NullateUsed()
284305
}
285306

286307
return combined

core/vm/zk_counters.go

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ func NewCountersFromUsedArray(used []int) *Counters {
8383
return &res
8484
}
8585

86+
func (c Counters) NullateUsed() {
87+
for _, v := range c {
88+
v.used = 0
89+
}
90+
}
91+
8692
func (c Counters) UsedAsString() string {
8793
res := fmt.Sprintf("[%s: %v]", CounterKeyNames[SHA], c[SHA].used)
8894
res += fmt.Sprintf("[%s: %v]", CounterKeyNames[A], c[A].used)

core/vm/zk_transaction_counters.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,19 @@ func NewTransactionCounter(transaction types.Transaction, smtMaxLevel int, forkI
5252

5353
func (tc *TransactionCounter) CombineCounters() Counters {
5454
combined := NewCounters()
55+
56+
_ = tc.CombineCountersInto(&combined)
57+
58+
return combined
59+
}
60+
61+
func (tc *TransactionCounter) CombineCountersInto(combined *Counters) *Counters {
5562
for k := range tc.rlpCounters.counters {
5663
val := tc.rlpCounters.counters[k].used + tc.executionCounters.counters[k].used + tc.processingCounters.counters[k].used
57-
combined[k] = &Counter{
58-
used: val,
64+
if (*combined)[k] == nil {
65+
(*combined)[k] = &Counter{used: 0}
5966
}
67+
(*combined)[k].used = val
6068
}
6169

6270
return combined

erigon-lib/.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ on:
33
push:
44
branches:
55
- main
6-
- stable
6+
- stable/**
77
- alpha
88
pull_request:
99
branches:
1010
- main
11-
- stable
11+
- stable/**
1212
- alpha
1313
env:
1414
CGO_ENABLED: "1"

erigon-lib/kv/mdbx/kv_mdbx.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ func (opts MdbxOpts) Open(ctx context.Context) (kv.RwDB, error) {
409409
writeTxLimiter: opts.writeTxLimiter,
410410

411411
txsCountMutex: txsCountMutex,
412-
txsAllDoneOnCloseCond: sync.NewCond(txsCountMutex),
412+
txsAllDoneOnCloseCond: sync.NewCond(&sync.Mutex{}),
413413

414414
leakDetector: dbg.NewLeakDetector("db."+opts.label.String(), dbg.SlowTx()),
415415

@@ -696,16 +696,19 @@ func (db *MdbxKV) trackTxBegin() bool {
696696
}
697697

698698
func (db *MdbxKV) hasTxsAllDoneAndClosed() bool {
699+
db.txsCountMutex.Lock()
700+
defer db.txsCountMutex.Unlock()
699701
return (db.txsCount == 0) && db.closed.Load()
700702
}
701703

702704
func (db *MdbxKV) trackTxEnd() {
703705
db.txsCountMutex.Lock()
704-
defer db.txsCountMutex.Unlock()
705706

706707
if db.txsCount > 0 {
707708
db.txsCount--
709+
db.txsCountMutex.Unlock()
708710
} else {
711+
db.txsCountMutex.Unlock()
709712
panic("MdbxKV: unmatched trackTxEnd")
710713
}
711714

@@ -715,9 +718,6 @@ func (db *MdbxKV) trackTxEnd() {
715718
}
716719

717720
func (db *MdbxKV) waitTxsAllDoneOnClose() {
718-
db.txsCountMutex.Lock()
719-
defer db.txsCountMutex.Unlock()
720-
721721
for !db.hasTxsAllDoneAndClosed() {
722722
db.txsAllDoneOnCloseCond.Wait()
723723
}
@@ -751,16 +751,15 @@ func (db *MdbxKV) BeginRo(ctx context.Context) (txn kv.Tx, err error) {
751751
// otherwise carry on
752752
}
753753

754-
if !db.trackTxBegin() {
755-
return nil, fmt.Errorf("db closed")
756-
}
757-
758754
// will return nil err if context is cancelled (may appear to acquire the semaphore)
759755
if semErr := db.readTxLimiter.Acquire(ctx, 1); semErr != nil {
760-
db.trackTxEnd()
761756
return nil, fmt.Errorf("mdbx.MdbxKV.BeginRo: roTxsLimiter error %w", semErr)
762757
}
763758

759+
if !db.trackTxBegin() {
760+
return nil, fmt.Errorf("db closed")
761+
}
762+
764763
defer func() {
765764
if txn == nil {
766765
// on error, or if there is whatever reason that we don't return a tx,

erigon-lib/kv/mdbx/kv_mdbx_test.go

+27-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"encoding/binary"
2222
"errors"
23+
"fmt"
2324
"sync/atomic"
2425
"testing"
2526
"time"
@@ -29,9 +30,10 @@ import (
2930
"github.com/stretchr/testify/assert"
3031
"github.com/stretchr/testify/require"
3132

33+
"sync"
34+
3235
"github.com/ledgerwatch/erigon-lib/kv"
3336
"github.com/ledgerwatch/erigon-lib/kv/order"
34-
"sync"
3537
)
3638

3739
func BaseCaseDB(t *testing.T) kv.RwDB {
@@ -1101,28 +1103,48 @@ func TestDeadlock(t *testing.T) {
11011103
}).MapSize(128 * datasize.MB).MustOpen()
11021104
t.Cleanup(db.Close)
11031105

1106+
maxGoroutines := 10_000 // Limit the number of concurrent goroutines
1107+
sem := make(chan struct{}, maxGoroutines)
1108+
1109+
var outerErr error
1110+
stop := false
11041111
wg := sync.WaitGroup{}
11051112
for i := 0; i < 300_000; i++ {
1113+
if stop {
1114+
break
1115+
}
1116+
sem <- struct{}{}
11061117
wg.Add(1)
11071118
go func(idx int) {
1119+
defer func() {
1120+
<-sem
1121+
wg.Done()
1122+
}()
11081123
ctx := context.Background()
11091124
// create a write transaction every X requests
1110-
if idx%5 == 0 {
1125+
if idx%3 == 0 {
11111126
tx, err := db.BeginRw(ctx)
11121127
if err != nil {
1113-
t.Fatal(err)
1128+
fmt.Println(err)
1129+
stop = true
1130+
outerErr = err
1131+
return
11141132
}
11151133
defer tx.Rollback()
11161134
} else {
11171135
tx, err := db.BeginRo(ctx)
11181136
if err != nil {
1119-
t.Fatal(err)
1137+
fmt.Println(err)
1138+
stop = true
1139+
outerErr = err
11201140
}
11211141
defer tx.Rollback()
11221142
}
1123-
wg.Done()
11241143
}(i)
11251144
}
11261145

11271146
wg.Wait()
1147+
if outerErr != nil {
1148+
t.Error(outerErr)
1149+
}
11281150
}

erigon-lib/kv/tables.go

+2
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ const (
548548
TablePoolLimbo = "PoolLimbo"
549549
BATCH_ENDS = "batch_ends"
550550
WITNESS_CACHE = "witness_cache"
551+
BAD_TX_HASHES = "bad_tx_hashes"
551552
//Diagnostics tables
552553
DiagSystemInfo = "DiagSystemInfo"
553554
DiagSyncStages = "DiagSyncStages"
@@ -793,6 +794,7 @@ var ChaindataTables = []string{
793794
TablePoolLimbo,
794795
BATCH_ENDS,
795796
WITNESS_CACHE,
797+
BAD_TX_HASHES,
796798
}
797799

798800
const (

0 commit comments

Comments
 (0)