diff --git a/README.md b/README.md index 2bf5070e4..55b6fab59 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ overview of all settings configurable through the CLI. | `Worker.UploadOverdriveTimeout` | Timeout for overdriving slab uploads | `3s` | `--worker.uploadOverdriveTimeout` | - | `worker.uploadOverdriveTimeout` | | `Worker.Enabled` | Enables/disables worker | `true` | `--worker.enabled` | `RENTERD_WORKER_ENABLED` | `worker.enabled` | | `Worker.AllowUnauthenticatedDownloads` | Allows unauthenticated downloads | - | `--worker.unauthenticatedDownloads` | `RENTERD_WORKER_UNAUTHENTICATED_DOWNLOADS` | `worker.allowUnauthenticatedDownloads` | +| `Worker.ExternalAddress` | Address of the worker on the network, only necessary when the bus is remote | - | - | `RENTERD_WORKER_EXTERNAL_ADDR` | `worker.externalAddress` | | `Autopilot.AccountsRefillInterval` | Interval for refilling workers' account balances | `24h` | `--autopilot.accountRefillInterval` | - | `autopilot.accountsRefillInterval` | | `Autopilot.Heartbeat` | Interval for autopilot loop execution | `30m` | `--autopilot.heartbeat` | - | `autopilot.heartbeat` | | `Autopilot.MigrationHealthCutoff` | Threshold for migrating slabs based on health | `0.75` | `--autopilot.migrationHealthCutoff` | - | `autopilot.migrationHealthCutoff` | diff --git a/cmd/renterd/main.go b/cmd/renterd/main.go index f803859ce..17cbc8bc4 100644 --- a/cmd/renterd/main.go +++ b/cmd/renterd/main.go @@ -295,6 +295,7 @@ func main() { flag.DurationVar(&cfg.Worker.UploadOverdriveTimeout, "worker.uploadOverdriveTimeout", cfg.Worker.UploadOverdriveTimeout, "Timeout for overdriving slab uploads") flag.BoolVar(&cfg.Worker.Enabled, "worker.enabled", cfg.Worker.Enabled, "Enables/disables worker (overrides with RENTERD_WORKER_ENABLED)") flag.BoolVar(&cfg.Worker.AllowUnauthenticatedDownloads, "worker.unauthenticatedDownloads", cfg.Worker.AllowUnauthenticatedDownloads, "Allows unauthenticated downloads (overrides with RENTERD_WORKER_UNAUTHENTICATED_DOWNLOADS)") + flag.StringVar(&cfg.Worker.ExternalAddress, "worker.externalAddress", cfg.Worker.ExternalAddress, "Address of the worker on the network, only necessary when the bus is remote (overrides with RENTERD_WORKER_EXTERNAL_ADDR)") // autopilot flag.DurationVar(&cfg.Autopilot.AccountsRefillInterval, "autopilot.accountRefillInterval", cfg.Autopilot.AccountsRefillInterval, "Interval for refilling workers' account balances") @@ -365,6 +366,7 @@ func main() { parseEnvVar("RENTERD_WORKER_UNAUTHENTICATED_DOWNLOADS", &cfg.Worker.AllowUnauthenticatedDownloads) parseEnvVar("RENTERD_WORKER_DOWNLOAD_MAX_MEMORY", &cfg.Worker.DownloadMaxMemory) parseEnvVar("RENTERD_WORKER_UPLOAD_MAX_MEMORY", &cfg.Worker.UploadMaxMemory) + parseEnvVar("RENTERD_WORKER_EXTERNAL_ADDR", &cfg.Worker.ExternalAddress) parseEnvVar("RENTERD_AUTOPILOT_ENABLED", &cfg.Autopilot.Enabled) parseEnvVar("RENTERD_AUTOPILOT_REVISION_BROADCAST_INTERVAL", &cfg.Autopilot.RevisionBroadcastInterval) @@ -462,8 +464,12 @@ func main() { } var shutdownFns []shutdownFnEntry - if cfg.Bus.RemoteAddr != "" && len(cfg.Worker.Remotes) != 0 && !cfg.Autopilot.Enabled { - logger.Fatal("remote bus, remote worker, and no autopilot -- nothing to do!") + if cfg.Bus.RemoteAddr != "" { + if len(cfg.Worker.Remotes) != 0 && !cfg.Autopilot.Enabled { + logger.Fatal("remote bus, remote worker, and no autopilot -- nothing to do!") + } else if cfg.Worker.ExternalAddress == "" { + logger.Fatal("if the bus is remote, the worker needs to be able to tell it where to find its API, this can be configured using worker.externalAddress") + } } if len(cfg.Worker.Remotes) == 0 && !cfg.Worker.Enabled && cfg.Autopilot.Enabled { logger.Fatal("can't enable autopilot without providing either workers to connect to or creating a worker") @@ -534,8 +540,14 @@ func main() { if err != nil { logger.Fatal("failed to create worker: " + err.Error()) } + var workerExternAddr string + if cfg.Bus.RemoteAddr != "" { + workerExternAddr = cfg.Worker.ExternalAddress + "/api/worker" + } else { + workerExternAddr = workerAddr + } setupWorkerFn = func(ctx context.Context) error { - return setupFn(ctx, workerAddr, cfg.HTTP.Password) + return setupFn(ctx, workerExternAddr, cfg.HTTP.Password) } shutdownFns = append(shutdownFns, shutdownFnEntry{ name: "Worker", diff --git a/config/config.go b/config/config.go index 565eaa802..909856b8e 100644 --- a/config/config.go +++ b/config/config.go @@ -124,6 +124,7 @@ type ( UploadMaxMemory uint64 `yaml:"uploadMaxMemory,omitempty"` UploadMaxOverdrive uint64 `yaml:"uploadMaxOverdrive,omitempty"` AllowUnauthenticatedDownloads bool `yaml:"allowUnauthenticatedDownloads,omitempty"` + ExternalAddress string `yaml:"externalAddress,omitempty"` } // Autopilot contains the configuration for an autopilot. diff --git a/worker/host.go b/worker/host.go index b0d36aad5..e6ffa9822 100644 --- a/worker/host.go +++ b/worker/host.go @@ -110,11 +110,14 @@ func (h *host) DownloadSector(ctx context.Context, w io.Writer, root types.Hash2 return err } - var refund types.Currency payment := rhpv3.PayByEphemeralAccount(h.acc.id, cost, pt.HostBlockHeight+defaultWithdrawalExpiryBlocks, h.accountKey) - cost, refund, err = RPCReadSector(ctx, t, w, hpt, &payment, offset, length, root) + cost, refund, err := RPCReadSector(ctx, t, w, hpt, &payment, offset, length, root) + if err != nil { + return err + } + amount = cost.Sub(refund) - return err + return nil }) return })