Skip to content

Commit 30bb889

Browse files
brentstonetzemanovic
authored andcommitted
fixup! Merge branch 'grarco/tx-batch' (#3103)
1 parent d5dd8a3 commit 30bb889

File tree

26 files changed

+131
-84
lines changed

26 files changed

+131
-84
lines changed

crates/apps/src/lib/bench_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl BenchShell {
404404
/// Execute the tx and return a set of verifiers inserted by the tx.
405405
pub fn execute_tx(
406406
&mut self,
407-
batched_tx: &BatchedTxRef,
407+
batched_tx: &BatchedTxRef<'_>,
408408
) -> BTreeSet<Address> {
409409
let gas_meter =
410410
RefCell::new(TxGasMeter::new_from_sub_limit(u64::MAX.into()));

crates/apps/src/lib/node/ledger/shell/finalize_block.rs

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -214,29 +214,27 @@ where
214214
continue;
215215
}
216216

217-
let (mut tx_event, tx_gas_meter, mut wrapper_args) =
218-
match &tx_header.tx_type {
219-
TxType::Wrapper(wrapper) => {
220-
stats.increment_wrapper_txs();
221-
let tx_event = new_tx_event(&tx, height.0);
222-
let gas_limit = match Gas::try_from(wrapper.gas_limit) {
223-
Ok(value) => value,
224-
Err(_) => {
225-
response.events.emit(
226-
new_tx_event(&tx, height.0)
227-
.with(Code(ResultCode::InvalidTx))
228-
.with(Info(
229-
"The wrapper gas limit overflowed \
230-
gas representation"
231-
.to_owned(),
232-
))
233-
.with(GasUsed(0.into())),
234-
);
235-
continue;
236-
}
237-
};
238-
let gas_meter = TxGasMeter::new(gas_limit);
239-
for cmt in tx.commitments() {
217+
let (tx_gas_meter, mut wrapper_args) = match &tx_header.tx_type {
218+
TxType::Wrapper(wrapper) => {
219+
stats.increment_wrapper_txs();
220+
let gas_limit = match Gas::try_from(wrapper.gas_limit) {
221+
Ok(value) => value,
222+
Err(_) => {
223+
response.events.emit(
224+
new_tx_event(&tx, height.0)
225+
.with(Code(ResultCode::InvalidTx))
226+
.with(Info(
227+
"The wrapper gas limit overflowed gas \
228+
representation"
229+
.to_owned(),
230+
))
231+
.with(GasUsed(0.into())),
232+
);
233+
continue;
234+
}
235+
};
236+
let gas_meter = TxGasMeter::new(gas_limit);
237+
for cmt in tx.commitments() {
240238
if let Some(code_sec) = tx
241239
.get_section(cmt.code_sechash())
242240
.and_then(|x| Section::code_sec(x.as_ref()))
@@ -245,8 +243,8 @@ where
245243
code_sec.code.hash().to_string(),
246244
);
247245
}
248-
}
249246
}
247+
250248
(
251249
gas_meter,
252250
Some(WrapperArgs {
@@ -544,8 +542,8 @@ where
544542
namada::tx::data::TxResult<protocol::Error>,
545543
DispatchError,
546544
>,
547-
tx_data: TxData,
548-
mut tx_logs: TxLogs,
545+
tx_data: TxData<'_>,
546+
mut tx_logs: TxLogs<'_>,
549547
) {
550548
// Check the commitment of the fee unshielding regardless of the
551549
// result, it could be committed even in case of errors
@@ -628,8 +626,8 @@ where
628626
&mut self,
629627
response: &mut shim::response::FinalizeBlock,
630628
tx_result: namada::tx::data::TxResult<protocol::Error>,
631-
tx_data: TxData,
632-
tx_logs: &mut TxLogs,
629+
tx_data: TxData<'_>,
630+
tx_logs: &mut TxLogs<'_>,
633631
) {
634632
let mut temp_log = TempTxLogs::new_from_tx_logs(tx_logs);
635633

@@ -646,8 +644,13 @@ where
646644
if tx_data.is_atomic_batch && is_any_tx_invalid {
647645
// Atomic batches need custom handling when even a single tx fails,
648646
// since we need to drop everything
649-
let unrun_txs = tx_data.commitments_len
650-
- tx_result.batch_results.0.len() as u64;
647+
let unrun_txs = tx_data
648+
.commitments_len
649+
.checked_sub(
650+
u64::try_from(tx_result.batch_results.0.len())
651+
.expect("Should be able to convert to u64"),
652+
)
653+
.expect("Shouldn't underflow");
651654
temp_log.stats.set_failing_atomic_batch(unrun_txs);
652655
temp_log.commit_stats_only(tx_logs);
653656
self.state.write_log_mut().drop_batch();
@@ -687,8 +690,8 @@ where
687690
response: &mut shim::response::FinalizeBlock,
688691
msg: &Error,
689692
tx_result: namada::tx::data::TxResult<protocol::Error>,
690-
tx_data: TxData,
691-
tx_logs: &mut TxLogs,
693+
tx_data: TxData<'_>,
694+
tx_logs: &mut TxLogs<'_>,
692695
) {
693696
let mut temp_log = TempTxLogs::new_from_tx_logs(tx_logs);
694697

@@ -702,8 +705,13 @@ where
702705
tx_data.height,
703706
);
704707

705-
let unrun_txs =
706-
tx_data.commitments_len - tx_result.batch_results.0.len() as u64;
708+
let unrun_txs = tx_data
709+
.commitments_len
710+
.checked_sub(
711+
u64::try_from(tx_result.batch_results.0.len())
712+
.expect("Should be able to convert to u64"),
713+
)
714+
.expect("Shouldn't underflow");
707715

708716
if tx_data.is_atomic_batch {
709717
tx_logs.stats.set_failing_atomic_batch(unrun_txs);
@@ -735,7 +743,7 @@ where
735743
.extend(Batch(&tx_result.to_result_string()));
736744
}
737745

738-
fn handle_batch_error_reprot(&mut self, err: &Error, tx_data: TxData) {
746+
fn handle_batch_error_reprot(&mut self, err: &Error, tx_data: TxData<'_>) {
739747
// If user transaction didn't fail because of out of gas nor
740748
// invalid section commitment, commit its hash to prevent
741749
// replays
@@ -801,7 +809,7 @@ struct TempTxLogs {
801809
}
802810

803811
impl TempTxLogs {
804-
fn new_from_tx_logs(tx_logs: &TxLogs) -> Self {
812+
fn new_from_tx_logs(tx_logs: &TxLogs<'_>) -> Self {
805813
Self {
806814
tx_event: Event::new(
807815
tx_logs.tx_event.kind().to_owned(),
@@ -3095,7 +3103,7 @@ mod test_finalize_block {
30953103
assert_eq!(*event[0].kind(), APPLIED_TX);
30963104
let code = event[0].read_attribute::<CodeAttr>().expect("Test failed");
30973105
assert_eq!(code, ResultCode::Ok);
3098-
let inner_tx_result = event[0].read_attribute::<Batch>().unwrap();
3106+
let inner_tx_result = event[0].read_attribute::<Batch<'_>>().unwrap();
30993107
let first_tx_result = inner_tx_result
31003108
.batch_results
31013109
.0
@@ -3246,7 +3254,7 @@ mod test_finalize_block {
32463254
assert_eq!(*event[1].kind(), APPLIED_TX);
32473255
let code = event[1].read_attribute::<CodeAttr>().expect("Test failed");
32483256
assert_eq!(code, ResultCode::Ok);
3249-
let inner_tx_result = event[1].read_attribute::<Batch>().unwrap();
3257+
let inner_tx_result = event[1].read_attribute::<Batch<'_>>().unwrap();
32503258
let inner_result = inner_tx_result
32513259
.batch_results
32523260
.0
@@ -3256,7 +3264,7 @@ mod test_finalize_block {
32563264
assert_eq!(*event[2].kind(), APPLIED_TX);
32573265
let code = event[2].read_attribute::<CodeAttr>().expect("Test failed");
32583266
assert_eq!(code, ResultCode::Ok);
3259-
let inner_tx_result = event[2].read_attribute::<Batch>().unwrap();
3267+
let inner_tx_result = event[2].read_attribute::<Batch<'_>>().unwrap();
32603268
let inner_result = inner_tx_result
32613269
.batch_results
32623270
.0
@@ -3271,7 +3279,7 @@ mod test_finalize_block {
32713279
assert_eq!(*event[3].kind(), APPLIED_TX);
32723280
let code = event[3].read_attribute::<CodeAttr>().expect("Test failed");
32733281
assert_eq!(code, ResultCode::Ok);
3274-
let inner_tx_result = event[3].read_attribute::<Batch>().unwrap();
3282+
let inner_tx_result = event[3].read_attribute::<Batch<'_>>().unwrap();
32753283
let inner_result = inner_tx_result
32763284
.batch_results
32773285
.0
@@ -3476,7 +3484,7 @@ mod test_finalize_block {
34763484
assert_eq!(*event.kind(), APPLIED_TX);
34773485
let code = event.read_attribute::<CodeAttr>().expect("Test failed");
34783486
assert_eq!(code, ResultCode::Ok);
3479-
let inner_tx_result = event.read_attribute::<Batch>().unwrap();
3487+
let inner_tx_result = event.read_attribute::<Batch<'_>>().unwrap();
34803488
let inner_result = inner_tx_result
34813489
.batch_results
34823490
.0
@@ -5399,7 +5407,7 @@ mod test_finalize_block {
53995407

54005408
let code = event[0].read_attribute::<CodeAttr>().unwrap();
54015409
assert_eq!(code, ResultCode::Ok);
5402-
let inner_tx_result = event[0].read_attribute::<Batch>().unwrap();
5410+
let inner_tx_result = event[0].read_attribute::<Batch<'_>>().unwrap();
54035411
let inner_results = inner_tx_result.batch_results.0;
54045412

54055413
for cmt in batch.commitments() {
@@ -5444,7 +5452,7 @@ mod test_finalize_block {
54445452

54455453
let code = event[0].read_attribute::<CodeAttr>().unwrap();
54465454
assert_eq!(code, ResultCode::WasmRuntimeError);
5447-
let inner_tx_result = event[0].read_attribute::<Batch>().unwrap();
5455+
let inner_tx_result = event[0].read_attribute::<Batch<'_>>().unwrap();
54485456
let inner_results = inner_tx_result.batch_results.0;
54495457

54505458
assert!(
@@ -5494,7 +5502,7 @@ mod test_finalize_block {
54945502

54955503
let code = event[0].read_attribute::<CodeAttr>().unwrap();
54965504
assert_eq!(code, ResultCode::Ok);
5497-
let inner_tx_result = event[0].read_attribute::<Batch>().unwrap();
5505+
let inner_tx_result = event[0].read_attribute::<Batch<'_>>().unwrap();
54985506
let inner_results = inner_tx_result.batch_results.0;
54995507

55005508
assert!(
@@ -5562,7 +5570,7 @@ mod test_finalize_block {
55625570

55635571
let code = event[0].read_attribute::<CodeAttr>().unwrap();
55645572
assert_eq!(code, ResultCode::WasmRuntimeError);
5565-
let inner_tx_result = event[0].read_attribute::<Batch>().unwrap();
5573+
let inner_tx_result = event[0].read_attribute::<Batch<'_>>().unwrap();
55665574
let inner_results = inner_tx_result.batch_results.0;
55675575

55685576
assert!(
@@ -5611,7 +5619,7 @@ mod test_finalize_block {
56115619

56125620
let code = event[0].read_attribute::<CodeAttr>().unwrap();
56135621
assert_eq!(code, ResultCode::WasmRuntimeError);
5614-
let inner_tx_result = event[0].read_attribute::<Batch>().unwrap();
5622+
let inner_tx_result = event[0].read_attribute::<Batch<'_>>().unwrap();
56155623
let inner_results = inner_tx_result.batch_results.0;
56165624

56175625
assert!(

crates/namada/src/ledger/governance/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ where
6969

7070
fn validate_tx(
7171
&self,
72-
tx_data: &BatchedTxRef,
72+
tx_data: &BatchedTxRef<'_>,
7373
keys_changed: &BTreeSet<Key>,
7474
verifiers: &BTreeSet<Address>,
7575
) -> Result<()> {
@@ -1119,7 +1119,10 @@ where
11191119
}
11201120

11211121
/// Validate a governance parameter
1122-
pub fn is_valid_parameter(&self, batched_tx: &BatchedTxRef) -> Result<()> {
1122+
pub fn is_valid_parameter(
1123+
&self,
1124+
batched_tx: &BatchedTxRef<'_>,
1125+
) -> Result<()> {
11231126
let BatchedTxRef { tx, cmt } = batched_tx;
11241127
tx.data(cmt).map_or_else(
11251128
|| {

crates/namada/src/ledger/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub use {
2323
mod dry_run_tx {
2424
use std::cell::RefCell;
2525

26+
use namada_gas::Gas;
2627
use namada_sdk::queries::{EncodedResponseQuery, RequestCtx, RequestQuery};
2728
use namada_state::{DBIter, ResultExt, StorageHasher, DB};
2829
use namada_tx::data::{GasLimit, TxResult};

crates/namada/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ where
543543

544544
fn validate_tx(
545545
&self,
546-
batched_tx: &BatchedTxRef,
546+
batched_tx: &BatchedTxRef<'_>,
547547
keys_changed: &BTreeSet<Key>,
548548
_verifiers: &BTreeSet<Address>,
549549
) -> Result<(), Error> {

crates/namada/src/ledger/native_vp/ethereum_bridge/nut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ where
4141

4242
fn validate_tx(
4343
&self,
44-
_: &BatchedTxRef,
44+
_: &BatchedTxRef<'_>,
4545
keys_changed: &BTreeSet<Key>,
4646
verifiers: &BTreeSet<Address>,
4747
) -> Result<(), Self::Error> {

crates/namada/src/ledger/native_vp/ethereum_bridge/vp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ where
9393
/// no wasm transactions should be able to modify those keys.
9494
fn validate_tx(
9595
&self,
96-
_: &BatchedTxRef,
96+
_: &BatchedTxRef<'_>,
9797
keys_changed: &BTreeSet<Key>,
9898
verifiers: &BTreeSet<Address>,
9999
) -> Result<(), Self::Error> {

crates/namada/src/ledger/native_vp/ibc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ where
7979

8080
fn validate_tx(
8181
&self,
82-
batched_tx: &BatchedTxRef,
82+
batched_tx: &BatchedTxRef<'_>,
8383
keys_changed: &BTreeSet<Key>,
8484
_verifiers: &BTreeSet<Address>,
8585
) -> VpResult<()> {

crates/namada/src/ledger/native_vp/masp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ where
387387

388388
fn validate_tx(
389389
&self,
390-
tx_data: &BatchedTxRef,
390+
tx_data: &BatchedTxRef<'_>,
391391
keys_changed: &BTreeSet<Key>,
392392
_verifiers: &BTreeSet<Address>,
393393
) -> Result<()> {

crates/namada/src/ledger/native_vp/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub trait NativeVp {
4343
/// Run the validity predicate
4444
fn validate_tx(
4545
&self,
46-
batched_tx: &BatchedTxRef,
46+
batched_tx: &BatchedTxRef<'_>,
4747
keys_changed: &BTreeSet<Key>,
4848
verifiers: &BTreeSet<Address>,
4949
) -> std::result::Result<(), Self::Error>;

0 commit comments

Comments
 (0)