@@ -11,14 +11,11 @@ use kaspa_consensus_core::{
1111
1212impl BlockBodyProcessor {
1313 pub fn validate_body_in_isolation ( self : & Arc < Self > , block : & Block ) -> BlockProcessResult < Mass > {
14- let crescendo_activated = self . crescendo_activation . is_active ( block. header . daa_score ) ;
15-
1614 Self :: check_has_transactions ( block) ?;
1715 Self :: check_hash_merkle_root ( block) ?;
1816 Self :: check_only_one_coinbase ( block) ?;
1917 self . check_transactions_in_isolation ( block) ?;
20- self . check_coinbase_has_zero_mass ( block, crescendo_activated) ?;
21- let mass = self . check_block_mass ( block, crescendo_activated) ?;
18+ let mass = self . check_block_mass ( block) ?;
2219 self . check_duplicate_transactions ( block) ?;
2320 self . check_block_double_spends ( block) ?;
2421 self . check_no_chained_transactions ( block) ?;
@@ -63,56 +60,36 @@ impl BlockBodyProcessor {
6360 Ok ( ( ) )
6461 }
6562
66- fn check_coinbase_has_zero_mass ( & self , block : & Block , crescendo_activated : bool ) -> BlockProcessResult < ( ) > {
67- // TODO (post HF): move to check_coinbase_in_isolation
68- if crescendo_activated && block. transactions [ 0 ] . mass ( ) > 0 {
69- return Err ( RuleError :: CoinbaseNonZeroMassCommitment ) ;
70- }
71- Ok ( ( ) )
72- }
73-
74- fn check_block_mass ( self : & Arc < Self > , block : & Block , crescendo_activated : bool ) -> BlockProcessResult < Mass > {
75- if crescendo_activated {
76- let mut total_compute_mass: u64 = 0 ;
77- let mut total_transient_mass: u64 = 0 ;
78- let mut total_storage_mass: u64 = 0 ;
79- for tx in block. transactions . iter ( ) {
80- // Calculate the non-contextual masses
81- let NonContextualMasses { compute_mass, transient_mass } = self . mass_calculator . calc_non_contextual_masses ( tx) ;
82-
83- // Read the storage mass commitment. This value cannot be computed here w/o UTXO context
84- // so we use the commitment. Later on, when the transaction is verified in context, we use
85- // the context to calculate the expected storage mass and verify it matches this commitment
86- let storage_mass_commitment = tx. mass ( ) ;
87-
88- // Sum over the various masses separately
89- total_compute_mass = total_compute_mass. saturating_add ( compute_mass) ;
90- total_transient_mass = total_transient_mass. saturating_add ( transient_mass) ;
91- total_storage_mass = total_storage_mass. saturating_add ( storage_mass_commitment) ;
92-
93- // Verify all limits
94- if total_compute_mass > self . max_block_mass {
95- return Err ( RuleError :: ExceedsComputeMassLimit ( total_compute_mass, self . max_block_mass ) ) ;
96- }
97- if total_transient_mass > self . max_block_mass {
98- return Err ( RuleError :: ExceedsTransientMassLimit ( total_transient_mass, self . max_block_mass ) ) ;
99- }
100- if total_storage_mass > self . max_block_mass {
101- return Err ( RuleError :: ExceedsStorageMassLimit ( total_storage_mass, self . max_block_mass ) ) ;
102- }
63+ fn check_block_mass ( self : & Arc < Self > , block : & Block ) -> BlockProcessResult < Mass > {
64+ let mut total_compute_mass: u64 = 0 ;
65+ let mut total_transient_mass: u64 = 0 ;
66+ let mut total_storage_mass: u64 = 0 ;
67+ for tx in block. transactions . iter ( ) {
68+ // Calculate the non-contextual masses
69+ let NonContextualMasses { compute_mass, transient_mass } = self . mass_calculator . calc_non_contextual_masses ( tx) ;
70+
71+ // Read the storage mass commitment. This value cannot be computed here w/o UTXO context
72+ // so we use the commitment. Later on, when the transaction is verified in context, we use
73+ // the context to calculate the expected storage mass and verify it matches this commitment
74+ let storage_mass_commitment = tx. mass ( ) ;
75+
76+ // Sum over the various masses separately
77+ total_compute_mass = total_compute_mass. saturating_add ( compute_mass) ;
78+ total_transient_mass = total_transient_mass. saturating_add ( transient_mass) ;
79+ total_storage_mass = total_storage_mass. saturating_add ( storage_mass_commitment) ;
80+
81+ // Verify all limits
82+ if total_compute_mass > self . max_block_mass {
83+ return Err ( RuleError :: ExceedsComputeMassLimit ( total_compute_mass, self . max_block_mass ) ) ;
84+ }
85+ if total_transient_mass > self . max_block_mass {
86+ return Err ( RuleError :: ExceedsTransientMassLimit ( total_transient_mass, self . max_block_mass ) ) ;
10387 }
104- Ok ( ( NonContextualMasses :: new ( total_compute_mass, total_transient_mass) , ContextualMasses :: new ( total_storage_mass) ) )
105- } else {
106- let mut total_mass: u64 = 0 ;
107- for tx in block. transactions . iter ( ) {
108- let compute_mass = self . mass_calculator . calc_non_contextual_masses ( tx) . compute_mass ;
109- total_mass = total_mass. saturating_add ( compute_mass) ;
110- if total_mass > self . max_block_mass {
111- return Err ( RuleError :: ExceedsComputeMassLimit ( total_mass, self . max_block_mass ) ) ;
112- }
88+ if total_storage_mass > self . max_block_mass {
89+ return Err ( RuleError :: ExceedsStorageMassLimit ( total_storage_mass, self . max_block_mass ) ) ;
11390 }
114- Ok ( ( NonContextualMasses :: new ( total_mass, 0 ) , ContextualMasses :: new ( 0 ) ) )
11591 }
92+ Ok ( ( NonContextualMasses :: new ( total_compute_mass, total_transient_mass) , ContextualMasses :: new ( total_storage_mass) ) )
11693 }
11794
11895 fn check_block_double_spends ( self : & Arc < Self > , block : & Block ) -> BlockProcessResult < ( ) > {
0 commit comments