@@ -8,7 +8,7 @@ use std::{collections::HashSet, sync::Arc};
88use async_trait:: async_trait;
99use futures:: Future ;
1010use linera_base:: {
11- crypto:: { CryptoHash , Signer } ,
11+ crypto:: { CryptoHash , Signer , ValidatorPublicKey } ,
1212 data_types:: { BlockHeight , ChainDescription , Timestamp } ,
1313 identifiers:: { Account , AccountOwner , BlobId , BlobType , ChainId } ,
1414 ownership:: ChainOwnership ,
@@ -17,13 +17,14 @@ use linera_base::{
1717use linera_chain:: types:: ConfirmedBlockCertificate ;
1818use linera_core:: {
1919 client:: { BlanketMessagePolicy , ChainClient , Client , MessagePolicy , PendingProposal } ,
20- data_types:: ClientOutcome ,
20+ data_types:: { ChainInfoQuery , ClientOutcome } ,
2121 join_set_ext:: JoinSet ,
22- node:: CrossChainMessageDelivery ,
23- Environment , JoinSetExt ,
22+ node:: { CrossChainMessageDelivery , ValidatorNode } ,
23+ Environment , JoinSetExt as _ ,
2424} ;
2525use linera_rpc:: node_provider:: { NodeOptions , NodeProvider } ;
2626use linera_storage:: Storage ;
27+ use linera_version:: VersionInfo ;
2728use linera_views:: views:: ViewError ;
2829use thiserror_context:: Context ;
2930use tracing:: { debug, info} ;
@@ -537,6 +538,93 @@ where
537538 info ! ( "New preferred owner set" ) ;
538539 Ok ( ( ) )
539540 }
541+
542+ pub async fn check_compatible_version_info (
543+ & self ,
544+ address : & str ,
545+ node : & impl ValidatorNode ,
546+ ) -> Result < VersionInfo , Error > {
547+ match node. get_version_info ( ) . await {
548+ Ok ( version_info) if version_info. is_compatible_with ( & linera_version:: VERSION_INFO ) => {
549+ info ! (
550+ "Version information for validator {address}: {}" ,
551+ version_info
552+ ) ;
553+ Ok ( version_info)
554+ }
555+ Ok ( version_info) => Err ( error:: Inner :: UnexpectedVersionInfo {
556+ remote : Box :: new ( version_info) ,
557+ local : Box :: new ( linera_version:: VERSION_INFO . clone ( ) ) ,
558+ }
559+ . into ( ) ) ,
560+ Err ( error) => Err ( error:: Inner :: UnavailableVersionInfo {
561+ address : address. to_string ( ) ,
562+ error : Box :: new ( error) ,
563+ }
564+ . into ( ) ) ,
565+ }
566+ }
567+
568+ pub async fn check_matching_network_description (
569+ & self ,
570+ address : & str ,
571+ node : & impl ValidatorNode ,
572+ ) -> Result < CryptoHash , Error > {
573+ let network_description = self . wallet ( ) . genesis_config ( ) . network_description ( ) ;
574+ match node. get_network_description ( ) . await {
575+ Ok ( description) => {
576+ if description == network_description {
577+ Ok ( description. genesis_config_hash )
578+ } else {
579+ Err ( error:: Inner :: UnexpectedNetworkDescription {
580+ remote : Box :: new ( description) ,
581+ local : Box :: new ( network_description) ,
582+ }
583+ . into ( ) )
584+ }
585+ }
586+ Err ( error) => Err ( error:: Inner :: UnavailableNetworkDescription {
587+ address : address. to_string ( ) ,
588+ error : Box :: new ( error) ,
589+ }
590+ . into ( ) ) ,
591+ }
592+ }
593+
594+ pub async fn check_validator_chain_info_response (
595+ & self ,
596+ public_key : Option < & ValidatorPublicKey > ,
597+ address : & str ,
598+ node : & impl ValidatorNode ,
599+ chain_id : ChainId ,
600+ ) -> Result < ( ) , Error > {
601+ let query = ChainInfoQuery :: new ( chain_id) ;
602+ match node. handle_chain_info_query ( query) . await {
603+ Ok ( response) => {
604+ info ! (
605+ "Validator {address} sees chain {chain_id} at block height {} and epoch {:?}" ,
606+ response. info. next_block_height, response. info. epoch,
607+ ) ;
608+ if let Some ( public_key) = public_key {
609+ if response. check ( public_key) . is_ok ( ) {
610+ info ! ( "Signature for public key {public_key} is OK." ) ;
611+ } else {
612+ return Err ( error:: Inner :: InvalidSignature {
613+ public_key : * public_key,
614+ }
615+ . into ( ) ) ;
616+ }
617+ }
618+ Ok ( ( ) )
619+ }
620+ Err ( error) => Err ( error:: Inner :: UnavailableChainInfo {
621+ address : address. to_string ( ) ,
622+ chain_id,
623+ error : Box :: new ( error) ,
624+ }
625+ . into ( ) ) ,
626+ }
627+ }
540628}
541629
542630#[ cfg( feature = "fs" ) ]
0 commit comments