Skip to content

Commit 6992cfe

Browse files
silathdiir0xmountaintopThegaram
authored
fix: update row estimation with scroll-prover v0.7.2 (#475)
* Fix row estimation. * Update libzkp. * more * prepare * finish * upgrade * bump version * fix tests * Update to scroll-prover `v0.7.2`. * fix tests * Update miner/worker.go Co-authored-by: Péter Garamvölgyi <peter@scroll.io> * Update miner/worker.go Co-authored-by: Péter Garamvölgyi <peter@scroll.io> * Reset ccc when skips first tx. * do not unnecessarily skip L1 message * fix ccc reset and improve code readability * seal block on circuitcapacitychecker.ErrUnknown --------- Co-authored-by: HAOYUatHZ <haoyu@protonmail.com> Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
1 parent 727f88b commit 6992cfe

File tree

8 files changed

+88
-79
lines changed

8 files changed

+88
-79
lines changed

miner/worker.go

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,40 +1068,38 @@ loop:
10681068
log.Trace("Skipping unsupported transaction type", "sender", from, "type", tx.Type())
10691069
txs.Pop()
10701070

1071+
// Circuit capacity check
10711072
case errors.Is(err, circuitcapacitychecker.ErrBlockRowConsumptionOverflow):
1072-
// Circuit capacity check: circuit capacity limit reached in a block,
1073-
// don't pop or shift, just quit the loop immediately;
1074-
// though it might still be possible to add some "smaller" txs,
1075-
// but it's a trade-off between tracing overhead & block usage rate
1076-
log.Trace("Circuit capacity limit reached in a block", "acc_rows", w.current.accRows, "tx", tx.Hash().String())
1077-
circuitCapacityReached = true
1078-
break loop
1079-
1080-
case (errors.Is(err, circuitcapacitychecker.ErrTxRowConsumptionOverflow) && tx.IsL1MessageTx()):
1081-
// Circuit capacity check: L1MessageTx row consumption too high, shift to the next from the account,
1082-
// because we shouldn't skip the entire txs from the same account.
1083-
// This is also useful for skipping "problematic" L1MessageTxs.
1084-
queueIndex := tx.AsL1MessageTx().QueueIndex
1085-
log.Trace("Circuit capacity limit reached for a single tx", "tx", tx.Hash().String(), "queueIndex", queueIndex)
1086-
log.Info("Skipping L1 message", "queueIndex", queueIndex, "tx", tx.Hash().String(), "block", w.current.header.Number, "reason", "row consumption overflow")
1087-
w.current.nextL1MsgIndex = queueIndex + 1
1088-
1089-
// after `ErrTxRowConsumptionOverflow`, ccc might not revert updates
1090-
// associated with this transaction so we cannot pack more transactions.
1091-
// TODO: fix this in ccc and change these lines back to `txs.Shift()`
1092-
circuitCapacityReached = true
1093-
break loop
1094-
1095-
case (errors.Is(err, circuitcapacitychecker.ErrTxRowConsumptionOverflow) && !tx.IsL1MessageTx()):
1096-
// Circuit capacity check: L2MessageTx row consumption too high, skip the account.
1097-
// This is also useful for skipping "problematic" L2MessageTxs.
1098-
log.Trace("Circuit capacity limit reached for a single tx", "tx", tx.Hash().String())
1073+
if w.current.tcount >= 1 {
1074+
// 1. Circuit capacity limit reached in a block, and it's not the first tx:
1075+
// don't pop or shift, just quit the loop immediately;
1076+
// though it might still be possible to add some "smaller" txs,
1077+
// but it's a trade-off between tracing overhead & block usage rate
1078+
log.Trace("Circuit capacity limit reached in a block", "acc_rows", w.current.accRows, "tx", tx.Hash().String())
1079+
circuitCapacityReached = true
1080+
break loop
1081+
} else {
1082+
// 2. Circuit capacity limit reached in a block, and it's the first tx: skip the tx
1083+
log.Trace("Circuit capacity limit reached for a single tx", "tx", tx.Hash().String())
1084+
1085+
if tx.IsL1MessageTx() {
1086+
// Skip L1 message transaction,
1087+
// shift to the next from the account because we shouldn't skip the entire txs from the same account
1088+
txs.Shift()
1089+
1090+
queueIndex := tx.AsL1MessageTx().QueueIndex
1091+
log.Info("Skipping L1 message", "queueIndex", queueIndex, "tx", tx.Hash().String(), "block", w.current.header.Number, "reason", "row consumption overflow")
1092+
w.current.nextL1MsgIndex = queueIndex + 1
1093+
} else {
1094+
// Skip L2 transaction and all other transactions from the same sender account
1095+
txs.Pop()
1096+
}
10991097

1100-
// after `ErrTxRowConsumptionOverflow`, ccc might not revert updates
1101-
// associated with this transaction so we cannot pack more transactions.
1102-
// TODO: fix this in ccc and change these lines back to `txs.Pop()`
1103-
circuitCapacityReached = true
1104-
break loop
1098+
// Reset ccc so that we can process other transactions for this block
1099+
w.circuitCapacityChecker.Reset()
1100+
log.Trace("Worker reset ccc", "id", w.circuitCapacityChecker.ID)
1101+
circuitCapacityReached = false
1102+
}
11051103

11061104
case (errors.Is(err, circuitcapacitychecker.ErrUnknown) && tx.IsL1MessageTx()):
11071105
// Circuit capacity check: unknown circuit capacity checker error for L1MessageTx,
@@ -1111,19 +1109,19 @@ loop:
11111109
log.Info("Skipping L1 message", "queueIndex", queueIndex, "tx", tx.Hash().String(), "block", w.current.header.Number, "reason", "unknown row consumption error")
11121110
w.current.nextL1MsgIndex = queueIndex + 1
11131111

1114-
// after `ErrUnknown`, ccc might not revert updates associated
1115-
// with this transaction so we cannot pack more transactions.
1116-
// TODO: fix this in ccc and change these lines back to `txs.Shift()`
1112+
// Normally we would do `txs.Shift()` here.
1113+
// However, after `ErrUnknown`, ccc might remain in an
1114+
// inconsistent state, so we cannot pack more transactions.
11171115
circuitCapacityReached = true
11181116
break loop
11191117

11201118
case (errors.Is(err, circuitcapacitychecker.ErrUnknown) && !tx.IsL1MessageTx()):
11211119
// Circuit capacity check: unknown circuit capacity checker error for L2MessageTx, skip the account
11221120
log.Trace("Unknown circuit capacity checker error for L2MessageTx", "tx", tx.Hash().String())
11231121

1124-
// after `ErrUnknown`, ccc might not revert updates associated
1125-
// with this transaction so we cannot pack more transactions.
1126-
// TODO: fix this in ccc and change these lines back to `txs.Pop()`
1122+
// Normally we would do `txs.Pop()` here.
1123+
// However, after `ErrUnknown`, ccc might remain in an
1124+
// inconsistent state, so we cannot pack more transactions.
11271125
circuitCapacityReached = true
11281126
break loop
11291127

miner/worker_test.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,10 +1010,10 @@ func TestOversizedTxThenNormal(t *testing.T) {
10101010
switch blockNum {
10111011
case 0:
10121012
// schedule to skip 2nd call to ccc
1013-
w.getCCC().ScheduleError(2, circuitcapacitychecker.ErrTxRowConsumptionOverflow)
1013+
w.getCCC().ScheduleError(2, circuitcapacitychecker.ErrBlockRowConsumptionOverflow)
10141014
return false
10151015
case 1:
1016-
// include #0, skip #1, then terminate
1016+
// include #0, fail on #1, then seal the block
10171017
assert.Equal(1, len(block.Transactions()))
10181018

10191019
assert.True(block.Transactions()[0].IsL1MessageTx())
@@ -1022,7 +1022,23 @@ func TestOversizedTxThenNormal(t *testing.T) {
10221022
// db is updated correctly
10231023
queueIndex := rawdb.ReadFirstQueueIndexNotInL2Block(db, block.Hash())
10241024
assert.NotNil(queueIndex)
1025-
assert.Equal(uint64(2), *queueIndex)
1025+
assert.Equal(uint64(1), *queueIndex)
1026+
1027+
// schedule to skip next call to ccc
1028+
w.getCCC().ScheduleError(1, circuitcapacitychecker.ErrBlockRowConsumptionOverflow)
1029+
1030+
return false
1031+
case 2:
1032+
// skip #1, include #2, then seal the block
1033+
assert.Equal(1, len(block.Transactions()))
1034+
1035+
assert.True(block.Transactions()[0].IsL1MessageTx())
1036+
assert.Equal(uint64(2), block.Transactions()[0].AsL1MessageTx().QueueIndex)
1037+
1038+
// db is updated correctly
1039+
queueIndex := rawdb.ReadFirstQueueIndexNotInL2Block(db, block.Hash())
1040+
assert.NotNil(queueIndex)
1041+
assert.Equal(uint64(3), *queueIndex)
10261042

10271043
return true
10281044
default:

params/version.go

Lines changed: 1 addition & 1 deletion
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 = 3 // Minor version component of the current release
27-
VersionPatch = 47 // Patch version component of the current release
27+
VersionPatch = 48 // Patch version component of the current release
2828
VersionMeta = "sepolia" // Version metadata to append to the version string
2929
)
3030

rollup/circuitcapacitychecker/impl.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,13 @@ func (ccc *CircuitCapacityChecker) ApplyTransaction(traces *types.BlockTrace) (*
8787
log.Error("fail to apply_tx in CircuitCapacityChecker", "id", ccc.ID, "TxHash", traces.Transactions[0].TxHash, "err", result.Error)
8888
return nil, ErrUnknown
8989
}
90-
if result.TxRowUsage == nil || result.AccRowUsage == nil {
90+
if result.AccRowUsage == nil {
9191
log.Error("fail to apply_tx in CircuitCapacityChecker",
9292
"id", ccc.ID, "TxHash", traces.Transactions[0].TxHash,
93-
"result.TxRowUsage==nil", result.TxRowUsage == nil,
9493
"result.AccRowUsage == nil", result.AccRowUsage == nil,
95-
"err", "TxRowUsage or AccRowUsage is empty unexpectedly")
94+
"err", "AccRowUsage is empty unexpectedly")
9695
return nil, ErrUnknown
9796
}
98-
if !result.TxRowUsage.IsOk {
99-
return nil, ErrTxRowConsumptionOverflow
100-
}
10197
if !result.AccRowUsage.IsOk {
10298
return nil, ErrBlockRowConsumptionOverflow
10399
}

rollup/circuitcapacitychecker/libzkp/Cargo.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup/circuitcapacitychecker/libzkp/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ 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/scroll-prover", tag = "v0.6.4" }
24-
types = { git = "https://github.com/scroll-tech/scroll-prover", tag = "v0.6.4" }
23+
prover = { git = "https://github.com/scroll-tech/scroll-prover", tag = "v0.7.2" }
24+
types = { git = "https://github.com/scroll-tech/scroll-prover", tag = "v0.7.2" }
2525

2626
log = "0.4"
2727
env_logger = "0.9.0"

rollup/circuitcapacitychecker/libzkp/src/lib.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub mod checker {
1414
#[derive(Debug, Clone, Deserialize, Serialize)]
1515
pub struct RowUsageResult {
1616
pub acc_row_usage: Option<RowUsage>,
17-
pub tx_row_usage: Option<RowUsage>,
1817
pub error: Option<String>,
1918
}
2019

@@ -59,7 +58,11 @@ pub mod checker {
5958
#[no_mangle]
6059
pub unsafe extern "C" fn apply_tx(id: u64, tx_traces: *const c_char) -> *const c_char {
6160
let result = panic::catch_unwind(|| {
62-
log::debug!("ccc apply_tx raw input, id: {:?}, tx_traces: {:?}", id, c_char_to_str(tx_traces));
61+
log::debug!(
62+
"ccc apply_tx raw input, id: {:?}, tx_traces: {:?}",
63+
id,
64+
c_char_to_str(tx_traces)
65+
);
6366
let tx_traces_vec = c_char_to_vec(tx_traces);
6467
let traces = serde_json::from_slice::<BlockTrace>(&tx_traces_vec)
6568
.unwrap_or_else(|_| panic!("id: {id:?}, fail to deserialize tx_traces"));
@@ -88,22 +91,19 @@ pub mod checker {
8891
})
8992
});
9093
let r = match result {
91-
Ok((acc_row_usage, tx_row_usage)) => {
94+
Ok(acc_row_usage) => {
9295
log::debug!(
93-
"id: {:?}, acc_row_usage: {:?}, tx_row_usage: {:?}",
96+
"id: {:?}, acc_row_usage: {:?}",
9497
id,
9598
acc_row_usage.row_number,
96-
tx_row_usage.row_number
9799
);
98100
RowUsageResult {
99101
acc_row_usage: Some(acc_row_usage),
100-
tx_row_usage: Some(tx_row_usage),
101102
error: None,
102103
}
103104
}
104105
Err(e) => RowUsageResult {
105106
acc_row_usage: None,
106-
tx_row_usage: None,
107107
error: Some(format!("{e:?}")),
108108
},
109109
};
@@ -114,7 +114,11 @@ pub mod checker {
114114
#[no_mangle]
115115
pub unsafe extern "C" fn apply_block(id: u64, block_trace: *const c_char) -> *const c_char {
116116
let result = panic::catch_unwind(|| {
117-
log::debug!("ccc apply_block raw input, id: {:?}, block_trace: {:?}", id, c_char_to_str(block_trace));
117+
log::debug!(
118+
"ccc apply_block raw input, id: {:?}, block_trace: {:?}",
119+
id,
120+
c_char_to_str(block_trace)
121+
);
118122
let block_trace = c_char_to_vec(block_trace);
119123
let traces = serde_json::from_slice::<BlockTrace>(&block_trace)
120124
.unwrap_or_else(|_| panic!("id: {id:?}, fail to deserialize block_trace"));
@@ -136,22 +140,19 @@ pub mod checker {
136140
})
137141
});
138142
let r = match result {
139-
Ok((acc_row_usage, tx_row_usage)) => {
143+
Ok(acc_row_usage) => {
140144
log::debug!(
141-
"id: {:?}, acc_row_usage: {:?}, tx_row_usage: {:?}",
145+
"id: {:?}, acc_row_usage: {:?}",
142146
id,
143147
acc_row_usage.row_number,
144-
tx_row_usage.row_number
145148
);
146149
RowUsageResult {
147150
acc_row_usage: Some(acc_row_usage),
148-
tx_row_usage: Some(tx_row_usage),
149151
error: None,
150152
}
151153
}
152154
Err(e) => RowUsageResult {
153155
acc_row_usage: None,
154-
tx_row_usage: None,
155156
error: Some(format!("{e:?}")),
156157
},
157158
};

rollup/circuitcapacitychecker/types.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import (
88

99
var (
1010
ErrUnknown = errors.New("unknown circuit capacity checker error")
11-
ErrTxRowConsumptionOverflow = errors.New("tx row consumption oveflow")
1211
ErrBlockRowConsumptionOverflow = errors.New("block row consumption oveflow")
1312
)
1413

1514
type WrappedRowUsage struct {
1615
AccRowUsage *types.RowUsage `json:"acc_row_usage,omitempty"`
17-
TxRowUsage *types.RowUsage `json:"tx_row_usage,omitempty"`
1816
Error string `json:"error,omitempty"`
1917
}

0 commit comments

Comments
 (0)