33use crate :: { Result , MetricsRegistry } ;
44use bitcell_consensus:: { Block , BlockHeader , Transaction , BattleProof } ;
55use bitcell_crypto:: { Hash256 , PublicKey , SecretKey } ;
6- use bitcell_economics:: { COIN , INITIAL_BLOCK_REWARD , HALVING_INTERVAL } ;
6+ use bitcell_economics:: { COIN , INITIAL_BLOCK_REWARD , HALVING_INTERVAL , MAX_HALVINGS } ;
77use bitcell_state:: StateManager ;
88use std:: sync:: { Arc , RwLock } ;
99use std:: collections:: HashMap ;
@@ -112,8 +112,8 @@ impl Blockchain {
112112 /// Calculate block reward based on height (halves every HALVING_INTERVAL blocks)
113113 pub fn calculate_block_reward ( height : u64 ) -> u64 {
114114 let halvings = height / HALVING_INTERVAL ;
115- if halvings >= 64 {
116- // After 64 halvings, reward is effectively 0
115+ if halvings >= MAX_HALVINGS {
116+ // After MAX_HALVINGS halvings, reward is effectively 0
117117 return 0 ;
118118 }
119119 INITIAL_BLOCK_REWARD >> halvings
@@ -255,8 +255,15 @@ impl Blockchain {
255255 // Apply block reward to proposer
256256 let reward = Self :: calculate_block_reward ( block_height) ;
257257 if reward > 0 {
258- state. credit_account ( * block. header . proposer . as_bytes ( ) , reward) ;
259- println ! ( "Block reward credited: {} units to proposer" , reward) ;
258+ match state. credit_account ( * block. header . proposer . as_bytes ( ) , reward) {
259+ Ok ( _) => {
260+ tracing:: info!( "Block reward credited: {} units to proposer" , reward) ;
261+ }
262+ Err ( e) => {
263+ tracing:: error!( "Failed to credit block reward: {:?}" , e) ;
264+ return Err ( crate :: Error :: Node ( "Failed to credit block reward" . to_string ( ) ) ) ;
265+ }
266+ }
260267 }
261268
262269 for tx in & block. transactions {
@@ -269,10 +276,10 @@ impl Blockchain {
269276 ) {
270277 Ok ( new_state_root) => {
271278 // State updated successfully
272- println ! ( "Transaction applied, new state root: {:?}" , new_state_root) ;
279+ tracing :: debug !( "Transaction applied, new state root: {:?}" , new_state_root) ;
273280 }
274281 Err ( e) => {
275- println ! ( "Failed to apply transaction: {:?}" , e) ;
282+ tracing :: warn !( "Failed to apply transaction: {:?}" , e) ;
276283 // In production, this should rollback the entire block
277284 // For now, we just skip the transaction
278285 }
0 commit comments