Struct bitcoin_miner::BlockAssembler
source · pub struct BlockAssembler { /* private fields */ }Expand description
| Generate a new block, without valid | proof-of-work |
Implementations§
source§impl BlockAssembler
impl BlockAssembler
pub fn new_with_options( chainstate: &mut ChainState, mempool: &TxMemPool, params: &ChainParams, options: &Options ) -> Self
pub fn new( chainstate: &mut ChainState, mempool: &TxMemPool, params: &ChainParams ) -> Self
sourcepub fn reset_block(&mut self)
pub fn reset_block(&mut self)
| Clear the block’s state and prepare | for assembling a new block |
sourcepub fn create_new_block(
&mut self,
script_pub_key_in: &Script
) -> Box<BlockTemplate>
pub fn create_new_block( &mut self, script_pub_key_in: &Script ) -> Box<BlockTemplate>
| Construct a new block template with | coinbase to scriptPubKeyIn |
sourcepub fn only_unconfirmed(&mut self, test_set: &mut TxMemPoolSetEntries)
pub fn only_unconfirmed(&mut self, test_set: &mut TxMemPoolSetEntries)
| Remove confirmed (inBlock) entries | from given set |
sourcepub fn test_package(&self, package_size: u64, package_sig_ops_cost: i64) -> bool
pub fn test_package(&self, package_size: u64, package_sig_ops_cost: i64) -> bool
| Test if a new package would “fit” in the | block |
sourcepub fn test_package_transactions(&self, package: &TxMemPoolSetEntries) -> bool
pub fn test_package_transactions(&self, package: &TxMemPoolSetEntries) -> bool
| Perform checks on each transaction | in a package: locktime, premature-witness, | serialized size (if necessary) | | These checks should always succeed, | and they’re here only as an extra check | in case of suboptimal node configuration |
| Perform transaction-level checks before adding | to block: | | - transaction finality (locktime) | | - premature witness (in case segwit | transactions are added to mempool before | segwit activation)
sourcepub fn add_to_block(&mut self, iter: TxMemPoolTxIter)
pub fn add_to_block(&mut self, iter: TxMemPoolTxIter)
| Add a tx to the block |
sourcepub fn update_packages_for_added(
&mut self,
already_added: &TxMemPoolSetEntries,
map_modified_tx: &mut IndexedModifiedTransactionSet
) -> i32
pub fn update_packages_for_added( &mut self, already_added: &TxMemPoolSetEntries, map_modified_tx: &mut IndexedModifiedTransactionSet ) -> i32
| Add descendants of given transactions | to mapModifiedTx with ancestor state | updated assuming given transactions | are inBlock. Returns number of updated | descendants. |
sourcepub fn skip_map_tx_entry(
&mut self,
it: TxMemPoolTxIter,
map_modified_tx: &mut IndexedModifiedTransactionSet,
failed_tx: &mut TxMemPoolSetEntries
) -> bool
pub fn skip_map_tx_entry( &mut self, it: TxMemPoolTxIter, map_modified_tx: &mut IndexedModifiedTransactionSet, failed_tx: &mut TxMemPoolSetEntries ) -> bool
| Return true if given transaction from | mapTx has already been evaluated, or | if the transaction’s cached data in | mapTx is incorrect. | | Skip entries in mapTx that are already in | a block or are present in mapModifiedTx (which | implies that the mapTx ancestor state is stale | due to ancestor inclusion in the block) | | Also skip transactions that we’ve already | failed to add. This can happen if we consider | a transaction in mapModifiedTx and it fails: we | can then potentially consider it again while | walking mapTx. It’s currently guaranteed to | fail again, but as a belt-and-suspenders check | we put it in failedTx and avoid re-evaluation, | since the re-evaluation would be using cached | size/sigops/fee values that are not actually | correct.
sourcepub fn sort_for_block(
&mut self,
package: &TxMemPoolSetEntries,
sorted_entries: &mut Vec<TxMemPoolTxIter>
)
pub fn sort_for_block( &mut self, package: &TxMemPoolSetEntries, sorted_entries: &mut Vec<TxMemPoolTxIter> )
| Sort the package in an order that is valid | to appear in a block |
sourcepub fn add_package_txs(
&mut self,
n_packages_selected: &mut i32,
n_descendants_updated: &mut i32
)
pub fn add_package_txs( &mut self, n_packages_selected: &mut i32, n_descendants_updated: &mut i32 )
| Add transactions based on feerate including | unconfirmed ancestors | | Increments nPackagesSelected / nDescendantsUpdated | with corresponding statistics from | the package selection (for logging | statistics). |
| This transaction selection algorithm orders the | mempool based on feerate of a transaction | including all unconfirmed ancestors. | | Since we don’t remove transactions from the | mempool as we select them for block inclusion, | we need an alternate method of updating the | feerate of a transaction with its | not-yet-selected ancestors as we go. | | This is accomplished by walking the in-mempool | descendants of selected transactions and | storing a temporary modified state in | mapModifiedTxs. | | Each time through the loop, we compare the best | transaction in mapModifiedTxs with the next | transaction in the mempool to decide what | transaction package to work on next.