diff --git a/core/src/lib.rs b/core/src/lib.rs index 0743cd3ab81..82315f56039 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -18,7 +18,7 @@ pub mod uncle; pub use crate::error::Error; pub use bytes::Bytes; -pub use occupied_capacity::{capacity_bytes, Capacity}; +pub use occupied_capacity::{capacity_bytes, Capacity, OccupiedCapacity}; pub type PublicKey = numext_fixed_hash::H512; pub type BlockNumber = u64; pub type EpochNumber = u64; diff --git a/miner/src/block_assembler.rs b/miner/src/block_assembler.rs index d3d3934b9fa..f27618a323e 100644 --- a/miner/src/block_assembler.rs +++ b/miner/src/block_assembler.rs @@ -9,14 +9,14 @@ use ckb_core::transaction::{ CellInput, CellOutput, ProposalShortId, Transaction, TransactionBuilder, }; use ckb_core::uncle::UncleBlock; -use ckb_core::BlockNumber; +use ckb_core::OccupiedCapacity; +use ckb_core::{BlockNumber, Bytes, Capacity}; use ckb_core::{Cycle, Version}; use ckb_logger::{error, info}; use ckb_notify::NotifyController; use ckb_shared::{shared::Shared, tx_pool::ProposedEntry}; use ckb_store::ChainStore; use ckb_traits::ChainProvider; -use ckb_verification::TransactionError; use crossbeam_channel::{self, select, Receiver, Sender}; use failure::Error as FailureError; use faketime::unix_time_as_millis; @@ -403,19 +403,21 @@ impl BlockAssembler { ) -> Result { let witness = lock.into_witness(); let input = CellInput::new_cellbase_input(candidate_number); - let output = CellOutput::new( - self.shared - .consensus() - .genesis_epoch_ext() - .block_reward(candidate_number)?, - self.config.data.clone().into_bytes(), - self.shared.consensus().bootstrap_lock().clone(), - None, - ); - // User-defined data has a risk of exceeding capacity - if output.is_lack_of_capacity()? { - return Err(TransactionError::InsufficientCellCapacity.into()); - } + + let block_reward = self + .shared + .consensus() + .genesis_epoch_ext() + .block_reward(candidate_number)?; + + let lock = self.shared.consensus().bootstrap_lock().clone(); + + let r#type = None; + + let data = self.custom_data(&block_reward, &lock, &r#type)?; + + let output = CellOutput::new(block_reward, data, lock, r#type); + Ok(TransactionBuilder::default() .input(input) .output(output) @@ -429,16 +431,13 @@ impl BlockAssembler { let witness = lock.into_witness(); let input = CellInput::new_cellbase_input(candidate_number); - let output = CellOutput::new( - block_reward, - self.config.data.clone().into_bytes(), - target_lock, - None, - ); - // User-defined data has a risk of exceeding capacity - if output.is_lack_of_capacity()? { - return Err(TransactionError::InsufficientCellCapacity.into()); - } + + let r#type = None; + + let data = self.custom_data(&block_reward, &target_lock, &r#type)?; + + let output = CellOutput::new(block_reward, data, target_lock, r#type); + Ok(TransactionBuilder::default() .input(input) .output(output) @@ -446,6 +445,27 @@ impl BlockAssembler { .build()) } + fn custom_data( + &self, + reward: &Capacity, + lock: &Script, + r#type: &Option