From 6a12155738ff29d3aad449f4cb456cb65978d32f Mon Sep 17 00:00:00 2001 From: Nym Seddon <64070857+unseddd@users.noreply.github.com> Date: Sun, 2 Aug 2020 07:50:59 +0000 Subject: [PATCH] Expose `max_tx_weight` API (#3407) Add API for getting max transaction weight Co-authored-by: Nym Seddon --- core/src/global.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/src/global.rs b/core/src/global.rs index 557865002..db0d83a24 100644 --- a/core/src/global.rs +++ b/core/src/global.rs @@ -17,10 +17,10 @@ //! should be used sparingly. use crate::consensus::{ - graph_weight, valid_header_version, HeaderInfo, BASE_EDGE_BITS, BLOCK_TIME_SEC, - COINBASE_MATURITY, CUT_THROUGH_HORIZON, DAY_HEIGHT, DEFAULT_MIN_EDGE_BITS, - DIFFICULTY_ADJUST_WINDOW, INITIAL_DIFFICULTY, MAX_BLOCK_WEIGHT, PROOFSIZE, - SECOND_POW_EDGE_BITS, STATE_SYNC_THRESHOLD, + graph_weight, valid_header_version, HeaderInfo, BASE_EDGE_BITS, BLOCK_KERNEL_WEIGHT, + BLOCK_OUTPUT_WEIGHT, BLOCK_TIME_SEC, COINBASE_MATURITY, CUT_THROUGH_HORIZON, DAY_HEIGHT, + DEFAULT_MIN_EDGE_BITS, DIFFICULTY_ADJUST_WINDOW, INITIAL_DIFFICULTY, MAX_BLOCK_WEIGHT, + PROOFSIZE, SECOND_POW_EDGE_BITS, STATE_SYNC_THRESHOLD, }; use crate::core::block::HeaderVersion; use crate::pow::{ @@ -320,6 +320,12 @@ pub fn max_block_weight() -> usize { } } +/// Maximum allowed transaction weight (1 weight unit ~= 32 bytes) +pub fn max_tx_weight() -> u64 { + let coinbase_weight = BLOCK_OUTPUT_WEIGHT + BLOCK_KERNEL_WEIGHT; + max_block_weight().saturating_sub(coinbase_weight) as u64 +} + /// Horizon at which we can cut-through and do full local pruning pub fn cut_through_horizon() -> u32 { match get_chain_type() {