Skip to content

Commit 0042e3b

Browse files
authored
Ignore small bounded values in block size limit. (#3653)
## Motivation The current way of computing the block size during execution is complicated (e.g. due to ULEB128 sequence lengths) and doesn't fully take into account the new block structure anyway: It computes the size of `ExecutedBlock`, not `Block`. ## Proposal Remove the ULEB128 sequence length size tracking. ## Test Plan CI The block size limit test still passes, because the small transaction that is used to push it past the size limit is bigger than the few sequence length bytes we are not taking into account, plus the hashes in the `BlockHeader`. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - Closes #3652. - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent 5c50ce8 commit 0042e3b

File tree

3 files changed

+1
-43
lines changed

3 files changed

+1
-43
lines changed

linera-chain/src/chain.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -751,12 +751,6 @@ where
751751
resource_controller
752752
.track_block_size(EMPTY_BLOCK_SIZE)
753753
.with_execution_context(ChainExecutionContext::Block)?;
754-
resource_controller
755-
.track_executed_block_size_sequence_extension(0, block.incoming_bundles.len())
756-
.with_execution_context(ChainExecutionContext::Block)?;
757-
resource_controller
758-
.track_executed_block_size_sequence_extension(0, block.operations.len())
759-
.with_execution_context(ChainExecutionContext::Block)?;
760754
for blob in published_blobs {
761755
let blob_type = blob.content().blob_type();
762756
if blob_type == BlobType::Data
@@ -900,18 +894,6 @@ where
900894
.with_execution_context(chain_execution_context)?;
901895
}
902896
}
903-
resource_controller
904-
.track_executed_block_size_sequence_extension(oracle_responses.len(), 1)
905-
.with_execution_context(chain_execution_context)?;
906-
resource_controller
907-
.track_executed_block_size_sequence_extension(messages.len(), 1)
908-
.with_execution_context(chain_execution_context)?;
909-
resource_controller
910-
.track_executed_block_size_sequence_extension(events.len(), 1)
911-
.with_execution_context(chain_execution_context)?;
912-
resource_controller
913-
.track_executed_block_size_sequence_extension(blobs.len(), 1)
914-
.with_execution_context(chain_execution_context)?;
915897
oracle_responses.push(txn_outcome.oracle_responses);
916898
messages.push(txn_outcome.outgoing_messages);
917899
events.push(txn_outcome.events);
@@ -921,9 +903,6 @@ where
921903
resource_controller
922904
.track_block_size_of(&(&txn_outcome.operation_result))
923905
.with_execution_context(chain_execution_context)?;
924-
resource_controller
925-
.track_executed_block_size_sequence_extension(operation_results.len(), 1)
926-
.with_execution_context(chain_execution_context)?;
927906
operation_results.push(OperationResult(txn_outcome.operation_result));
928907
}
929908
}

linera-chain/src/unit_tests/chain_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ async fn test_block_size_limit() {
189189
.unwrap();
190190
let block = Block::new(valid_block, outcome);
191191

192-
// ...because its size is exactly at the allowed limit.
192+
// ...because its size is at the allowed limit.
193193
assert_eq!(
194194
bcs::serialized_size(&block).unwrap(),
195195
maximum_executed_block_size as usize

linera-execution/src/resources.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -384,27 +384,6 @@ impl<Account, Tracker> ResourceController<Account, Tracker>
384384
where
385385
Tracker: AsMut<ResourceTracker>,
386386
{
387-
/// Tracks the extension of a sequence in an executed block.
388-
///
389-
/// The sequence length is ULEB128-encoded, so extending a sequence can add an additional byte.
390-
pub fn track_executed_block_size_sequence_extension(
391-
&mut self,
392-
old_len: usize,
393-
delta: usize,
394-
) -> Result<(), ExecutionError> {
395-
if delta == 0 {
396-
return Ok(());
397-
}
398-
let new_len = old_len + delta;
399-
// ULEB128 uses one byte per 7 bits of the number. It always uses at least one byte.
400-
let old_size = ((usize::BITS - old_len.leading_zeros()) / 7).max(1);
401-
let new_size = ((usize::BITS - new_len.leading_zeros()) / 7).max(1);
402-
if new_size > old_size {
403-
self.track_block_size((new_size - old_size) as usize)?;
404-
}
405-
Ok(())
406-
}
407-
408387
/// Tracks the serialized size of an executed block, or parts of it.
409388
pub fn track_block_size_of(&mut self, data: &impl Serialize) -> Result<(), ExecutionError> {
410389
self.track_block_size(bcs::serialized_size(data)?)

0 commit comments

Comments
 (0)