4
4
use std:: {
5
5
net:: { AddrParseError , SocketAddr } ,
6
6
str:: FromStr ,
7
- sync:: Arc ,
7
+ sync:: { atomic :: AtomicBool , Arc } ,
8
8
} ;
9
9
10
10
use log:: { error, info} ;
@@ -53,6 +53,7 @@ where S: ShareChain
53
53
stats_collector : Option < StatsCollector > ,
54
54
shutdown_signal : ShutdownSignal ,
55
55
stats_broadcast_client : StatsBroadcastClient ,
56
+ are_we_synced_with_p2pool : Arc < AtomicBool > ,
56
57
}
57
58
58
59
impl < S > Server < S >
@@ -69,7 +70,7 @@ where S: ShareChain
69
70
let share_chain_sha3x = Arc :: new ( share_chain_sha3x) ;
70
71
let share_chain_random_x = Arc :: new ( share_chain_random_x) ;
71
72
let network_peer_store = PeerStore :: new ( & config. peer_store , stats_broadcast_client. clone ( ) ) ;
72
-
73
+ let are_we_synced_with_p2pool = Arc :: new ( AtomicBool :: new ( false ) ) ;
73
74
let stats_client = stats_collector. create_client ( ) ;
74
75
75
76
let mut p2p_service: p2p:: Service < S > = p2p:: Service :: new (
@@ -107,6 +108,7 @@ where S: ShareChain
107
108
genesis_block_hash,
108
109
stats_broadcast_client. clone ( ) ,
109
110
config. p2p_service . squad . clone ( ) ,
111
+ are_we_synced_with_p2pool. clone ( ) ,
110
112
)
111
113
. await
112
114
. map_err ( Error :: Grpc ) ?;
@@ -135,6 +137,7 @@ where S: ShareChain
135
137
stats_collector : Some ( stats_collector) ,
136
138
shutdown_signal,
137
139
stats_broadcast_client,
140
+ are_we_synced_with_p2pool,
138
141
} )
139
142
}
140
143
@@ -167,6 +170,15 @@ where S: ShareChain
167
170
pub async fn start ( & mut self ) -> Result < ( ) , Error > {
168
171
info ! ( target: LOG_TARGET , "⛏ Starting Tari SHA-3 mining P2Pool..." ) ;
169
172
173
+ // this is stupid way of checking sync, but should atleast give as something to mine solo for a while and giving
174
+ // p2pool 4 mins to sync
175
+ let sync_start = self . are_we_synced_with_p2pool . clone ( ) ;
176
+ tokio:: spawn ( async move {
177
+ tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 240 ) ) . await ;
178
+ info ! ( target: LOG_TARGET , "Setting as synced" ) ;
179
+ sync_start. store ( true , std:: sync:: atomic:: Ordering :: Relaxed ) ;
180
+ } ) ;
181
+
170
182
if self . config . mining_enabled {
171
183
// local base node and p2pool node grpc services
172
184
let base_node_grpc_service = self . base_node_grpc_service . clone ( ) . unwrap ( ) ;
0 commit comments