Skip to content

Commit

Permalink
looks good
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Coppola committed Jan 28, 2022
1 parent 4f93de2 commit 33b1d87
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/chainstate/stacks/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ use crate::types::chainstate::{BlockHeaderHash, StacksAddress, StacksWorkScore};
use crate::types::chainstate::{StacksBlockHeader, StacksBlockId, StacksMicroblockHeader};
use crate::types::proof::TrieHash;
use chainstate::stacks::db::blocks::SetupBlockResult;
use clarity_vm::clarity::MAX_EPOCH_SIZE;
use clarity_vm::clarity::ProductionBlockLimitFns;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -603,7 +602,7 @@ impl<'a> StacksMicroblockBuilder<'a> {
/// # Pre-Checks
/// - skip if the `anchor_mode` rules out micro-blocks
/// - skip if 'tx.txid()` is already in `considered`
/// - skip if adding the block would result in a block size bigger than `MAX_EPOCH_SIZE`
/// - skip if adding the block would result in a block size bigger than the block maximum
///
/// # Error Handling
/// - If the error when processing a tx is `CostOverflowError`, reset the cost of the block.
Expand Down Expand Up @@ -635,7 +634,11 @@ impl<'a> StacksMicroblockBuilder<'a> {
considered.insert(tx.txid());
}

let max_epoch_size = self.header_reader.clarity_state.block_limits_fns.output_length_limit;
let max_epoch_size = self
.header_reader
.clarity_state
.block_limits_fns
.output_length_limit;
if bytes_so_far + tx_len >= max_epoch_size.into() {
info!(
"Adding microblock tx {} would exceed epoch data size",
Expand Down Expand Up @@ -1302,11 +1305,12 @@ impl StacksBlockBuilder {
.map_err(Error::CodecError)?;
let tx_len = tx_bytes.len() as u64;

if self.bytes_so_far + tx_len >= MAX_EPOCH_SIZE.into() {
let max_epoch_size = self.block_limits_fns.output_length_limit.into();
if self.bytes_so_far + tx_len >= max_epoch_size {
warn!(
"Epoch size is {} >= {}",
self.bytes_so_far + tx_len,
MAX_EPOCH_SIZE
max_epoch_size
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/chainstate/stacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ pub struct StacksBlockBuilder {
parent_header_hash: BlockHeaderHash,
parent_microblock_hash: Option<BlockHeaderHash>,
miner_id: usize,
block_limits_fns:BlockLimitsFunctions,
block_limits_fns: BlockLimitsFunctions,
}

// maximum microblock size is 64KB, but note that the current leader has a space budget of
Expand Down
2 changes: 1 addition & 1 deletion src/clarity_vm/clarity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl ClarityBlockConnection<'_> {
}

// Maximum amount of data a leader can send during its epoch (2MB).
pub const MAX_EPOCH_SIZE: u32 = 2 * 1024 * 1024;
const MAX_EPOCH_SIZE: u32 = 2 * 1024 * 1024;

/// `BlockLimitsFunctions` for production. Use `MAX_EPOCH_SIZE` for length limit and get block
/// limits from `StacksEpoch`.
Expand Down

0 comments on commit 33b1d87

Please sign in to comment.