@@ -10,6 +10,7 @@ use node::key_manager::generate_keys_from_mnemonic;
1010use node:: wallet:: { TaprootWallet , Wallet } ;
1111use oracle:: esplora:: EsploraOracle ;
1212use oracle:: oracle:: Oracle ;
13+ use tonic:: transport:: Channel ;
1314use types:: proto:: node_proto:: node_control_client:: NodeControlClient ;
1415use types:: proto:: node_proto:: {
1516 CheckBalanceRequest , ConfirmWithdrawalRequest , CreateDepositIntentRequest , GetChainInfoRequest ,
@@ -658,6 +659,9 @@ async fn run_consensus_test(
658659 }
659660 }
660661
662+ println ! ( "🔗 Verifying chain state consistency across nodes" ) ;
663+ verify_chain_state_consistency ( & mut clients) . await ?;
664+
661665 // Check final balances to verify transaction execution
662666 println ! ( "🔍 Verifying transaction execution across nodes" ) ;
663667 let mut execution_consistent = true ;
@@ -764,3 +768,48 @@ where
764768 tokio:: time:: sleep ( poll_interval) . await ;
765769 }
766770}
771+
772+ async fn verify_chain_state_consistency (
773+ clients : & mut [ NodeControlClient < Channel > ] ,
774+ ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
775+ use types:: proto:: node_proto:: GetChainInfoRequest ;
776+
777+ let mut reference_height: Option < u64 > = None ;
778+ let mut reference_hash: Option < String > = None ;
779+
780+ for ( idx, client) in clients. iter_mut ( ) . enumerate ( ) {
781+ let info = client
782+ . get_chain_info ( GetChainInfoRequest { } )
783+ . await ?
784+ . into_inner ( ) ;
785+
786+ println ! (
787+ " 🌐 Node {}: height={} | hash={}" ,
788+ idx + 1 ,
789+ info. latest_height,
790+ info. latest_block_hash
791+ ) ;
792+
793+ if let Some ( h) = reference_height {
794+ if let Some ( hash) = & reference_hash {
795+ if h != info. latest_height || hash != & info. latest_block_hash {
796+ return Err ( format ! (
797+ "Chain state mismatch on node {} (height/hash differ)" ,
798+ idx + 1
799+ )
800+ . into ( ) ) ;
801+ }
802+ }
803+ } else {
804+ reference_height = Some ( info. latest_height ) ;
805+ reference_hash = Some ( info. latest_block_hash ) ;
806+ }
807+ }
808+
809+ println ! (
810+ " ✅ Chain state is consistent across all {} nodes" ,
811+ clients. len( )
812+ ) ;
813+
814+ Ok ( ( ) )
815+ }
0 commit comments