Skip to content

Commit 53aa8e5

Browse files
committed
cmd: fix renterd when sharing consensus
1 parent 384dbc8 commit 53aa8e5

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

cmd/clusterd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func main() {
163163
defer s.Close()
164164
go s.Run(ctx)
165165

166-
nm := nodes.NewManager(dir, cm, s, nodes.WithLog(log.Named("cluster")))
166+
nm := nodes.NewManager(dir, cm, s, nodes.WithLog(log.Named("cluster")), nodes.WithSharedConsensus(true))
167167
defer nm.Close()
168168

169169
server := &http.Server{

nodes/renterd.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ import (
3131
"go.uber.org/zap"
3232
)
3333

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+
3452
// StartRenterd starts a new renterd node and adds it to the manager.
3553
// This function blocks until the context is canceled. All resources will be
3654
// cleaned up before the function returns.
@@ -210,15 +228,19 @@ func (m *Manager) StartRenterd(ctx context.Context, sk types.PrivateKey, ready c
210228
}
211229
defer wm.Close()
212230

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+
}
214236
b, err := bus.New(ctx, config.Bus{
215237
AllowPrivateIPs: true,
216238
AnnouncementMaxAgeHours: 90 * 24,
217239
Bootstrap: true,
218240
GatewayAddr: s.Addr(),
219241
UsedUTXOExpiry: time.Hour,
220242
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"))
222244
if err != nil {
223245
return fmt.Errorf("failed to create bus: %w", err)
224246
}
@@ -379,6 +401,12 @@ func (m *Manager) StartRenterd(ctx context.Context, sk types.PrivateKey, ready c
379401
return fmt.Errorf("failed to update setting: %w", err)
380402
}
381403

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+
382410
waitForSync := func() error {
383411
for {
384412
select {
@@ -391,6 +419,7 @@ func (m *Manager) StartRenterd(ctx context.Context, sk types.PrivateKey, ready c
391419
} else if state.BlockHeight == m.chain.Tip().Height {
392420
return nil
393421
}
422+
log.Debug("waiting for sync", zap.Bool("synced", state.Synced), zap.Uint64("height", state.BlockHeight))
394423
}
395424
}
396425
}
@@ -400,7 +429,6 @@ func (m *Manager) StartRenterd(ctx context.Context, sk types.PrivateKey, ready c
400429
}
401430

402431
// mine blocks to fund the wallet
403-
walletAddress := types.StandardUnlockHash(sk.PublicKey())
404432
if err := m.MineBlocks(ctx, int(network.MaturityDelay)+20, walletAddress); err != nil {
405433
return fmt.Errorf("failed to mine blocks: %w", err)
406434
}

0 commit comments

Comments
 (0)