11use alloy:: primitives:: Address ;
22use anyhow:: Result ;
3- use futures:: future:: join_all;
43use log:: { debug, error, info} ;
54use shared:: {
65 models:: node:: DiscoveryNode ,
@@ -9,8 +8,6 @@ use shared::{
98 wallet:: { Wallet , WalletProvider } ,
109 } ,
1110} ;
12- use std:: sync:: Arc ;
13- use tokio:: sync:: Semaphore ;
1411
1512use crate :: p2p:: client:: P2PClient ;
1613use crate :: validators:: hardware_challenge:: HardwareChallenge ;
@@ -80,6 +77,8 @@ impl<'a> HardwareValidator<'a> {
8077 ) ;
8178 }
8279
80+ debug ! ( "Sending validation transaction for node {}" , node. id) ;
81+
8382 if let Err ( e) = contracts
8483 . prime_network
8584 . validate_node ( provider_address, node_address)
@@ -89,45 +88,35 @@ impl<'a> HardwareValidator<'a> {
8988 return Err ( anyhow:: anyhow!( "Failed to validate node: {}" , e) ) ;
9089 }
9190
91+ // Small delay to ensure nonce incrementation
92+ tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 100 ) ) . await ;
93+
9294 info ! ( "Node {} successfully validated" , node. id) ;
9395 Ok ( ( ) )
9496 }
9597
9698 pub async fn validate_nodes ( & self , nodes : Vec < DiscoveryNode > ) -> Result < ( ) > {
9799 let non_validated: Vec < _ > = nodes. into_iter ( ) . filter ( |n| !n. is_validated ) . collect ( ) ;
98100 debug ! ( "Non validated nodes: {:?}" , non_validated) ;
101+ info ! ( "Starting validation for {} nodes" , non_validated. len( ) ) ;
102+
99103 let contracts = self . contracts . clone ( ) ;
100104 let wallet = self . wallet ;
101105 let p2p_client = self . p2p_client ;
102- let semaphore = Arc :: new ( Semaphore :: new ( 10 ) ) ;
103- let futures = non_validated
104- . into_iter ( )
105- . map ( |node| {
106- let node_clone = node. clone ( ) ;
107- let contracts_clone = contracts. clone ( ) ;
108- let permit = semaphore. clone ( ) ;
109-
110- async move {
111- let _permit = permit. acquire ( ) . await ;
112-
113- match HardwareValidator :: validate_node (
114- wallet,
115- contracts_clone,
116- p2p_client,
117- node_clone,
118- )
119- . await
120- {
121- Ok ( _) => ( ) ,
122- Err ( e) => {
123- error ! ( "Failed to validate node: {}" , e) ;
124- }
125- }
126- }
127- } )
128- . collect :: < Vec < _ > > ( ) ;
129106
130- join_all ( futures) . await ;
107+ // Process non validated nodes sequentially as simple fix
108+ // to avoid nonce conflicts for now. Will sophisticate this in the future
109+ for node in non_validated {
110+ let node_id = node. id . clone ( ) ;
111+ match HardwareValidator :: validate_node ( wallet, contracts. clone ( ) , p2p_client, node)
112+ . await
113+ {
114+ Ok ( _) => ( ) ,
115+ Err ( e) => {
116+ error ! ( "Failed to validate node {}: {}" , node_id, e) ;
117+ }
118+ }
119+ }
131120 Ok ( ( ) )
132121 }
133122}
@@ -138,6 +127,7 @@ mod tests {
138127 use shared:: models:: node:: Node ;
139128 use shared:: web3:: contracts:: core:: builder:: ContractBuilder ;
140129 use shared:: web3:: wallet:: Wallet ;
130+ use std:: sync:: Arc ;
141131 use url:: Url ;
142132
143133 #[ tokio:: test]
0 commit comments