Skip to content

Commit

Permalink
Merge remote-tracking branch 'namada/tiago/main/hotfix-prepare-propos…
Browse files Browse the repository at this point in the history
…al' (#952) into maint-0.12

* namada/tiago/main/hotfix-prepare-proposal:
  changelog: add #952
  prepare_proposal: update comment to reflect hotfix
  prepare_proposal: use TxRecord struct on ABCI++ build
  Prioritize wrapper txs during proposal construction
  Hot fix PrepareProposal
  • Loading branch information
juped committed Dec 22, 2022
2 parents 6920cbc + 0410c6b commit 7dd385e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Limit block space to under Tendermint's limit, and limit transactions included
in a block by their size. ([#952](https://github.com/anoma/namada/pull/952))
38 changes: 32 additions & 6 deletions apps/src/lib/node/ledger/shell/prepare_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ use crate::facade::tendermint_proto::abci::{tx_record::TxAction, TxRecord};
use crate::node::ledger::shell::{process_tx, ShellMode};
use crate::node::ledger::shims::abcipp_shim_types::shim::TxBytes;

// TODO: remove this hard-coded value; Tendermint, and thus
// Namada uses 20 MiB max block sizes by default; 16 MiB leaves
// plenty of room for header data, evidence and protobuf serialization
// overhead
const MAX_PROPOSAL_SIZE: usize = 16 << 20;
const HALF_MAX_PROPOSAL_SIZE: usize = MAX_PROPOSAL_SIZE / 2;

impl<D, H> Shell<D, H>
where
D: DB + for<'iter> DBIter<'iter> + Sync + 'static,
H: StorageHasher + Sync + 'static,
{
/// Begin a new block.
///
/// We include half of the new wrapper txs given to us from the mempool
/// by tendermint. The rest of the block is filled with decryptions
/// of the wrapper txs from the previously committed block.
/// We fill half the block space with new wrapper txs given to us
/// from the mempool by tendermint. The rest of the block is filled
/// with decryptions of the wrapper txs from the previously
/// committed block.
///
/// INVARIANT: Any changes applied in this method must be reverted if
/// the proposal is rejected (unless we can simply overwrite
Expand All @@ -38,12 +46,11 @@ where
// TODO: Craft the Ethereum state update tx
// filter in half of the new txs from Tendermint, only keeping
// wrappers
let number_of_new_txs = 1 + req.txs.len() / 2;
let mut total_proposal_size = 0;
#[cfg(feature = "abcipp")]
let mut txs: Vec<TxRecord> = req
.txs
.into_iter()
.take(number_of_new_txs)
.map(|tx_bytes| {
if let Ok(Ok(TxType::Wrapper(_))) =
Tx::try_from(tx_bytes.as_slice()).map(process_tx)
Expand All @@ -53,12 +60,22 @@ where
record::remove(tx_bytes)
}
})
.take_while(|tx_record| {
let new_size = total_proposal_size + tx_record.tx.len();
if new_size > HALF_MAX_PROPOSAL_SIZE
|| tx_record.action != TxAction::Unmodified as i32
{
false
} else {
total_proposal_size = new_size;
true
}
})
.collect();
#[cfg(not(feature = "abcipp"))]
let mut txs: Vec<TxBytes> = req
.txs
.into_iter()
.take(number_of_new_txs)
.filter_map(|tx_bytes| {
if let Ok(Ok(TxType::Wrapper(_))) =
Tx::try_from(tx_bytes.as_slice()).map(process_tx)
Expand All @@ -68,6 +85,15 @@ where
None
}
})
.take_while(|tx_bytes| {
let new_size = total_proposal_size + tx_bytes.len();
if new_size > HALF_MAX_PROPOSAL_SIZE {
false
} else {
total_proposal_size = new_size;
true
}
})
.collect();

// decrypt the wrapper txs included in the previous block
Expand Down

0 comments on commit 7dd385e

Please sign in to comment.