Skip to content

Commit

Permalink
fix(core/consensus): include coinbase_extra max size into coinbase …
Browse files Browse the repository at this point in the history
…weight calculation (#5501)

Description
---
Include the `coinbase_extra` maximum size into block weight calculation

Motivation and Context
---
In the consensus constants function
`get_max_block_weight_excluding_coinbase` we are not taking into account
the size that the `coinbase_extra` field may have. This PR includes the
maximum size of that field (provided by
`coinbase_output_features_extra_max_length`) in to the calculation.

How Has This Been Tested?
---
Unit tests

What process can a PR reviewer use to test or verify this change?
---

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->

---------

Co-authored-by: SW van Heerden <swvheerden@gmail.com>
  • Loading branch information
mrnaveira and SWvheerden authored Jun 26, 2023
1 parent af32f96 commit 4554cc5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions base_layer/core/src/consensus/consensus_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,17 @@ impl ConsensusConstants {
}

/// Maximum transaction weight used for the construction of new blocks. It leaves place for 1 kernel and 1 output
/// with default features
/// with default features, as well as the maximum possible value of the `coinbase_extra` field
pub fn get_max_block_weight_excluding_coinbase(&self) -> u64 {
self.max_block_transaction_weight - self.calculate_1_output_kernel_weight()
}

fn calculate_1_output_kernel_weight(&self) -> u64 {
let output_features = OutputFeatures { ..Default::default() };
let max_extra_size = self.coinbase_output_features_extra_max_length() as usize;

let features_and_scripts_size = self.transaction_weight.round_up_features_and_scripts_size(
output_features.get_serialized_size() + script![Nop].get_serialized_size(),
output_features.get_serialized_size() + max_extra_size + script![Nop].get_serialized_size(),
);
self.transaction_weight.calculate(1, 0, 1, features_and_scripts_size)
}
Expand Down

0 comments on commit 4554cc5

Please sign in to comment.