Skip to content

Commit

Permalink
fix(settings): Add missing netaddress port in RHP2 settings
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Dec 12, 2024
1 parent 0f6d95b commit 702db0b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion host/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (m *ConfigManager) RHP2Settings() (proto2.HostSettings, error) {
// host info
Address: m.wallet.Address(),
SiaMuxPort: strconv.FormatUint(uint64(m.rhp3Port), 10),
NetAddress: settings.NetAddress,
NetAddress: m.rhp2NetAddress(),
TotalStorage: totalSectors * proto2.SectorSize,
RemainingStorage: (totalSectors - usedSectors) * proto2.SectorSize,

Expand Down
49 changes: 49 additions & 0 deletions host/settings/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,52 @@ func TestSettings(t *testing.T) {
t.Fatal("settings not equal to updated")
}
}

func TestRHP2Settings(t *testing.T) {
log := zaptest.NewLogger(t)
network, genesisBlock := testutil.V1Network()
hostKey := types.GeneratePrivateKey()

node := testutil.NewConsensusNode(t, network, genesisBlock, log)

// TODO: its unfortunate that all these managers need to be created just to
// test the auto-announce feature.
wm, err := wallet.NewSingleAddressWallet(hostKey, node.Chain, node.Store)
if err != nil {
t.Fatal("failed to create wallet:", err)
}
defer wm.Close()

vm, err := storage.NewVolumeManager(node.Store, storage.WithLogger(log.Named("storage")))
if err != nil {
t.Fatal("failed to create volume manager:", err)
}
defer vm.Close()

contracts, err := contracts.NewManager(node.Store, vm, node.Chain, node.Syncer, wm, contracts.WithRejectAfter(10), contracts.WithRevisionSubmissionBuffer(5), contracts.WithLog(log))
if err != nil {
t.Fatal("failed to create contracts manager:", err)
}
defer contracts.Close()

sm, err := settings.NewConfigManager(hostKey, node.Store, node.Chain, node.Syncer, vm, wm, settings.WithLog(log.Named("settings")), settings.WithAnnounceInterval(50), settings.WithRHP2Port(1234), settings.WithRHP3Port(5678))
if err != nil {
t.Fatal(err)
}
defer sm.Close()

updated := sm.Settings()
updated.NetAddress = "foo.bar"
if err := sm.UpdateSettings(updated); err != nil {
t.Fatal(err)
}

r2, err := sm.RHP2Settings()
if err != nil {
t.Fatal(err)
} else if r2.NetAddress != "foo.bar:1234" {
t.Fatal("expected netaddress to have port")
} else if r2.SiaMuxPort != "5678" {
t.Fatal("expected siamux port to be 5678")
}
}

0 comments on commit 702db0b

Please sign in to comment.