Skip to content

Commit e8ca9c7

Browse files
authored
Merge branch 'develop' into reset_skipped_traces
2 parents ee38a03 + 9c1433b commit e8ca9c7

File tree

12 files changed

+254
-149
lines changed

12 files changed

+254
-149
lines changed

core/rawdb/accessors_skipped_txs.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type SkippedTransaction struct {
5858
// BlockNumber is the number of the block in which this transaction was skipped.
5959
BlockNumber uint64
6060

61-
// BlockNumber is the hash of the block in which this transaction was skipped or nil.
61+
// BlockHash is the hash of the block in which this transaction was skipped or nil.
6262
BlockHash *common.Hash
6363
}
6464

@@ -80,21 +80,23 @@ type SkippedTransactionV2 struct {
8080
// BlockNumber is the number of the block in which this transaction was skipped.
8181
BlockNumber uint64
8282

83-
// BlockNumber is the hash of the block in which this transaction was skipped or nil.
83+
// BlockHash is the hash of the block in which this transaction was skipped or nil.
8484
BlockHash *common.Hash
8585
}
8686

8787
// writeSkippedTransaction writes a skipped transaction to the database.
8888
func writeSkippedTransaction(db ethdb.KeyValueWriter, tx *types.Transaction, traces *types.BlockTrace, reason string, blockNumber uint64, blockHash *common.Hash) {
89+
var err error
8990
// workaround: RLP decoding fails if this is nil
9091
if blockHash == nil {
9192
blockHash = &common.Hash{}
9293
}
93-
b, err := json.Marshal(traces)
94-
if err != nil {
95-
log.Crit("Failed to json marshal skipped transaction", "hash", tx.Hash().String(), "err", err)
94+
stx := SkippedTransactionV2{Tx: tx, Reason: reason, BlockNumber: blockNumber, BlockHash: blockHash}
95+
if traces != nil {
96+
if stx.TracesBytes, err = json.Marshal(traces); err != nil {
97+
log.Crit("Failed to json marshal skipped transaction", "hash", tx.Hash().String(), "err", err)
98+
}
9699
}
97-
stx := SkippedTransactionV2{Tx: tx, TracesBytes: b, Reason: reason, BlockNumber: blockNumber, BlockHash: blockHash}
98100
bytes, err := rlp.EncodeToBytes(stx)
99101
if err != nil {
100102
log.Crit("Failed to RLP encode skipped transaction", "hash", tx.Hash().String(), "err", err)

core/trace.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ func (env *TraceEnv) getTxResult(state *state.StateDB, index int, block *types.B
322322
// still we have no state root for per tx, only set the head and tail
323323
if index == 0 {
324324
txStorageTrace.RootBefore = state.GetRootHash()
325-
} else if index == len(block.Transactions())-1 {
325+
}
326+
if index == len(block.Transactions())-1 {
326327
txStorageTrace.RootAfter = block.Root()
327328
}
328329

eth/api.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,11 @@ func (api *ScrollAPI) GetSkippedTransaction(ctx context.Context, hash common.Has
738738
rpcTx.SkipBlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(stx.BlockNumber))
739739
rpcTx.SkipBlockHash = stx.BlockHash
740740
if len(stx.TracesBytes) != 0 {
741-
if err := json.Unmarshal(stx.TracesBytes, rpcTx.Traces); err != nil {
741+
traces := &types.BlockTrace{}
742+
if err := json.Unmarshal(stx.TracesBytes, traces); err != nil {
742743
return nil, fmt.Errorf("fail to Unmarshal traces for skipped tx, hash: %s, err: %w", hash.String(), err)
743744
}
745+
rpcTx.Traces = traces
744746
}
745747
return &rpcTx, nil
746748
}

miner/worker.go

+13
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ loop:
11451145
// However, after `ErrUnknown`, ccc might remain in an
11461146
// inconsistent state, so we cannot pack more transactions.
11471147
circuitCapacityReached = true
1148+
w.checkCurrentTxNumWithCCC(w.current.tcount)
11481149
break loop
11491150

11501151
case (errors.Is(err, circuitcapacitychecker.ErrUnknown) && !tx.IsL1MessageTx()):
@@ -1164,6 +1165,7 @@ loop:
11641165
// inconsistent state, so we cannot pack more transactions.
11651166
w.eth.TxPool().RemoveTx(tx.Hash(), true)
11661167
circuitCapacityReached = true
1168+
w.checkCurrentTxNumWithCCC(w.current.tcount)
11671169
break loop
11681170

11691171
default:
@@ -1208,6 +1210,17 @@ loop:
12081210
return false, circuitCapacityReached
12091211
}
12101212

1213+
func (w *worker) checkCurrentTxNumWithCCC(expected int) {
1214+
match, got, err := w.circuitCapacityChecker.CheckTxNum(expected)
1215+
if err != nil {
1216+
log.Error("failed to CheckTxNum in ccc", "err", err)
1217+
return
1218+
}
1219+
if !match {
1220+
log.Error("tx count in miner is different with CCC", "w.current.tcount", w.current.tcount, "got", got)
1221+
}
1222+
}
1223+
12111224
func (w *worker) collectPendingL1Messages(startIndex uint64) []types.L1MessageTx {
12121225
maxCount := w.chainConfig.Scroll.L1Config.NumL1MessagesPerBlock
12131226
return rawdb.ReadL1MessagesFrom(w.eth.ChainDb(), startIndex, maxCount)

params/version.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323

2424
const (
2525
VersionMajor = 4 // Major version component of the current release
26-
VersionMinor = 3 // Minor version component of the current release
27-
VersionPatch = 63 // Patch version component of the current release
26+
VersionMinor = 4 // Minor version component of the current release
27+
VersionPatch = 5 // Patch version component of the current release
2828
VersionMeta = "sepolia" // Version metadata to append to the version string
2929
)
3030

rollup/circuitcapacitychecker/impl.go

+28
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import "C" //nolint:typecheck
1111

1212
import (
1313
"encoding/json"
14+
"fmt"
1415
"sync"
1516
"unsafe"
1617

@@ -31,6 +32,7 @@ type CircuitCapacityChecker struct {
3132
ID uint64
3233
}
3334

35+
// NewCircuitCapacityChecker creates a new CircuitCapacityChecker
3436
func NewCircuitCapacityChecker() *CircuitCapacityChecker {
3537
creationMu.Lock()
3638
defer creationMu.Unlock()
@@ -39,13 +41,15 @@ func NewCircuitCapacityChecker() *CircuitCapacityChecker {
3941
return &CircuitCapacityChecker{ID: uint64(id)}
4042
}
4143

44+
// Reset resets a CircuitCapacityChecker
4245
func (ccc *CircuitCapacityChecker) Reset() {
4346
ccc.Lock()
4447
defer ccc.Unlock()
4548

4649
C.reset_circuit_capacity_checker(C.uint64_t(ccc.ID))
4750
}
4851

52+
// ApplyTransaction appends a tx's wrapped BlockTrace into the ccc, and return the accumulated RowConsumption
4953
func (ccc *CircuitCapacityChecker) ApplyTransaction(traces *types.BlockTrace) (*types.RowConsumption, error) {
5054
ccc.Lock()
5155
defer ccc.Unlock()
@@ -100,6 +104,7 @@ func (ccc *CircuitCapacityChecker) ApplyTransaction(traces *types.BlockTrace) (*
100104
return (*types.RowConsumption)(&result.AccRowUsage.RowUsageDetails), nil
101105
}
102106

107+
// ApplyBlock gets a block's RowConsumption
103108
func (ccc *CircuitCapacityChecker) ApplyBlock(traces *types.BlockTrace) (*types.RowConsumption, error) {
104109
ccc.Lock()
105110
defer ccc.Unlock()
@@ -141,3 +146,26 @@ func (ccc *CircuitCapacityChecker) ApplyBlock(traces *types.BlockTrace) (*types.
141146
}
142147
return (*types.RowConsumption)(&result.AccRowUsage.RowUsageDetails), nil
143148
}
149+
150+
// CheckTxNum compares whether the tx_count in ccc match the expected
151+
func (ccc *CircuitCapacityChecker) CheckTxNum(expected int) (bool, uint64, error) {
152+
ccc.Lock()
153+
defer ccc.Unlock()
154+
155+
log.Debug("ccc get_tx_num start", "id", ccc.ID)
156+
rawResult := C.get_tx_num(C.uint64_t(ccc.ID))
157+
defer func() {
158+
C.free(unsafe.Pointer(rawResult))
159+
}()
160+
log.Debug("ccc get_tx_num end", "id", ccc.ID)
161+
162+
result := &WrappedTxNum{}
163+
if err := json.Unmarshal([]byte(C.GoString(rawResult)), result); err != nil {
164+
return false, 0, fmt.Errorf("fail to json unmarshal get_tx_num result, id: %d, err: %w", ccc.ID, err)
165+
}
166+
if result.Error != "" {
167+
return false, 0, fmt.Errorf("fail to get_tx_num in CircuitCapacityChecker, id: %d, err: %w", ccc.ID, result.Error)
168+
}
169+
170+
return result.TxNum == uint64(expected), result.TxNum, nil
171+
}

0 commit comments

Comments
 (0)