@@ -31,6 +31,24 @@ import (
31
31
"go.uber.org/zap"
32
32
)
33
33
34
+ type spoofedSyncer struct {
35
+ * syncer.Syncer
36
+ }
37
+
38
+ func (s * spoofedSyncer ) Connect (ctx context.Context , addr string ) (* syncer.Peer , error ) {
39
+ return new (syncer.Peer ), nil
40
+ }
41
+
42
+ func (s * spoofedSyncer ) Peers () (peers []* syncer.Peer ) {
43
+ for i := 0 ; i < 10 ; i ++ {
44
+ peers = append (peers , & syncer.Peer {
45
+ ConnAddr : "" ,
46
+ Inbound : false ,
47
+ })
48
+ }
49
+ return
50
+ }
51
+
34
52
// StartRenterd starts a new renterd node and adds it to the manager.
35
53
// This function blocks until the context is canceled. All resources will be
36
54
// cleaned up before the function returns.
@@ -210,15 +228,19 @@ func (m *Manager) StartRenterd(ctx context.Context, sk types.PrivateKey, ready c
210
228
}
211
229
defer wm .Close ()
212
230
213
- explorerURL := "https://api.siascan.com"
231
+ var bs bus.Syncer = s
232
+ if m .shareConsensus {
233
+ // note: autopilot refuses to start without peers
234
+ bs = & spoofedSyncer {s }
235
+ }
214
236
b , err := bus .New (ctx , config.Bus {
215
237
AllowPrivateIPs : true ,
216
238
AnnouncementMaxAgeHours : 90 * 24 ,
217
239
Bootstrap : true ,
218
240
GatewayAddr : s .Addr (),
219
241
UsedUTXOExpiry : time .Hour ,
220
242
SlabBufferCompletionThreshold : 1 << 12 ,
221
- }, ([32 ]byte )(sk [:32 ]), am , wh , cm , s , wm , store , explorerURL , log .Named ("bus" ))
243
+ }, ([32 ]byte )(sk [:32 ]), am , wh , cm , bs , wm , store , "https://api.siascan.com" , log .Named ("bus" ))
222
244
if err != nil {
223
245
return fmt .Errorf ("failed to create bus: %w" , err )
224
246
}
@@ -379,6 +401,12 @@ func (m *Manager) StartRenterd(ctx context.Context, sk types.PrivateKey, ready c
379
401
return fmt .Errorf ("failed to update setting: %w" , err )
380
402
}
381
403
404
+ walletAddress := types .StandardUnlockHash (sk .PublicKey ())
405
+ // note: renterd does not properly trigger synced unless a block is mined
406
+ if err := m .MineBlocks (ctx , 1 , walletAddress ); err != nil {
407
+ return fmt .Errorf ("failed to mine blocks: %w" , err )
408
+ }
409
+
382
410
waitForSync := func () error {
383
411
for {
384
412
select {
@@ -391,6 +419,7 @@ func (m *Manager) StartRenterd(ctx context.Context, sk types.PrivateKey, ready c
391
419
} else if state .BlockHeight == m .chain .Tip ().Height {
392
420
return nil
393
421
}
422
+ log .Debug ("waiting for sync" , zap .Bool ("synced" , state .Synced ), zap .Uint64 ("height" , state .BlockHeight ))
394
423
}
395
424
}
396
425
}
@@ -400,7 +429,6 @@ func (m *Manager) StartRenterd(ctx context.Context, sk types.PrivateKey, ready c
400
429
}
401
430
402
431
// mine blocks to fund the wallet
403
- walletAddress := types .StandardUnlockHash (sk .PublicKey ())
404
432
if err := m .MineBlocks (ctx , int (network .MaturityDelay )+ 20 , walletAddress ); err != nil {
405
433
return fmt .Errorf ("failed to mine blocks: %w" , err )
406
434
}
0 commit comments