config

package
v0.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config reads the host's configuration from the environment. The names follow the TypeScript host's (OVERLAY_*) wherever the meaning is the same, so one EnvironmentFile reads the same to an operator on either host. It refuses rather than guesses: a malformed value stops the host before the port opens.

Index

Constants

View Source
const (
	GenesisMain = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
	GenesisTest = "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"
)

Genesis block hashes of the networks the scope can default.

Variables

This section is empty.

Functions

func ReadEnvFile added in v0.19.0

func ReadEnvFile(path string) (map[string]string, error)

ReadEnvFile reads a file of KEY=VALUE lines as systemd's EnvironmentFile does for the forms an operator writes: blank lines and lines starting with # or ; are skipped, an optional leading "export " is dropped, and a value wholly in single or double quotes loses them. Anything else is an error, never a guess.

func StateDirs added in v0.12.0

func StateDirs(get func(string) string, modules []string) (map[string]string, error)

StateDirs reads the modules' state directories: OVERLAY_STATE_DIRS (name=/abs/dir,...; "none" for none) or, unset, the <MODULE>_STATE_DIR of each module in modules that sets one (BBOX_STATE_DIR for bbox ...). The CLI reads them the same way.

Types

type Config

type Config struct {
	Listen string
	Port   int
	// Topics the host carries (OVERLAY_TOPICS).
	Topics []string
	// Modules mounted, by registered name (OVERLAY_MODULES, default anytx).
	Modules []string
	// DynamicFile is where the topics local applications ask for are kept
	// (OVERLAY_TOPICS_DYNAMIC_FILE, Dynamic); empty takes none. Dynamic
	// bounds what they may ask: the list keys, the most entries, the
	// longest lifetime.
	DynamicFile string
	Dynamic     DynamicOptions

	// IndexURL and BlobsURL name the two halves of storage (pkg/store):
	// pebble:///dir or sqlite:///file.db, and file:///dir.
	IndexURL string
	BlobsURL string
	// WALSync is the Pebble write-ahead log sync interval; 0 syncs every
	// batch. Loss on power failure is bounded by it (ruling R-j).
	WALSync time.Duration
	// BlobFsync fsyncs each BEEF file before its rename.
	BlobFsync bool
	// StoreCacheMB is the index cache.
	StoreCacheMB int
	// RetentionBlocks unlinks the BEEF of spent-and-proven outputs this many
	// blocks below the tip; 0 is off.
	RetentionBlocks uint32
	RetentionEvery  time.Duration
	// BackupDir is where POST /admin/checkpoint (loopback only) writes
	// checkpoints; empty disables the route.
	BackupDir string
	// StateDirs are the directories of state the mounted modules keep
	// beside the store (a rows journal, a payment ledger), by name: a
	// checkpoint copies each at the instant it copies the index, and
	// `store restore` puts them back with it. OVERLAY_STATE_DIRS, or else
	// the <MODULE>_STATE_DIR of each mounted module that sets one.
	StateDirs map[string]string

	// AnytxKeepTopics are globs (path.Match) naming the topics anytx
	// manages whose rows the anytx retention removes once AnytxKeep old
	// (zero: off); a pass runs every AnytxPruneEvery. Topics another
	// module manages are never pruned here: their module keeps its own
	// retention.
	AnytxKeepTopics []string
	AnytxKeep       time.Duration
	AnytxPruneEvery time.Duration

	// ChainTrackerURL is the overlay-bridge header API origin.
	ChainTrackerURL string
	// Network selects pkg/spv's activation heights and names the storage scope.
	Network     spv.Network
	GenesisHash string

	Finality       spv.FinalityPolicy
	VerifyTimeout  time.Duration
	MinFeeSatPerKB uint64
	// TrustBridgeVerify honors overlay-bridge's SPV marker on POST /submit
	// (internal/bridgetrust): a loopback submission whose marker checks
	// under the key in BridgeMarkerKeyFile skips the scripts only.
	TrustBridgeVerify   bool
	BridgeMarkerKeyFile string
	// SigVerifier is the secp256k1 ECDSA verifier behind go-sdk's hooks:
	// decred (overlay-bridge pkg/secpverify, the default) or sdk (go-sdk's
	// built-in crypto/ecdsa path).
	SigVerifier string

	ReconcileDepth uint32
	ReconcileEvery time.Duration

	// PprofListen serves net/http/pprof (with block and mutex profiling at
	// low rates) on this loopback host:port; empty is off.
	PprofListen string

	// GASP catch-up (internal/catchup). GASPPeers are the hosts this one
	// pulls from, as origins (http://host:port); none leaves the sync loop
	// off, and the peer routes are still served to GASPAllow.
	GASPPeers       []string
	GASPInterval    time.Duration
	GASPConcurrency int
	// GASPAllow is who may call the peer routes: OVERLAY_GASP_ALLOW, or
	// loopback and the peers' addresses when it is unset.
	GASPAllow []netip.Prefix
	// GASPServePerSec is the requests a second each allowed address may
	// make of the peer routes (a burst of twice that); all of them together
	// get twice the rate.
	GASPServePerSec int
	// GASPShedURL is the bridge's /metrics. When set, a sync round also runs
	// right after a burst of sheds ends.
	GASPShedURL string
	// CatchupHold holds catch-up's admissions (GASP and replay) while the
	// bridge at GASPShedURL sheds or its engine queue is CatchupHoldFill
	// full, for at most CatchupHoldMax at a time, read every
	// CatchupHoldPoll (OVERLAY_CATCHUP_HOLD*; on by default, effective
	// only with GASPShedURL set).
	CatchupHold     bool
	CatchupHoldFill float64
	CatchupHoldMax  time.Duration
	CatchupHoldPoll time.Duration
	// Replay is ordered replay for the topics GASP never carries (R-o),
	// from the same peers on the same schedule (OVERLAY_REPLAY, on by
	// default); ReplayQuestions and ReplayObjects bound one call of a
	// module's replayer, ReplayRoundQuestions one topic from one peer in a
	// round.
	Replay               bool
	ReplayQuestions      int
	ReplayObjects        int
	ReplayRoundQuestions int
}

Config is the host's whole configuration.

func Load

func Load() (*Config, error)

Load reads the environment.

func LoadFrom added in v0.19.0

func LoadFrom(get func(string) string) (*Config, error)

LoadFrom reads the configuration from get, the settings a reload reads (Source), with every check Load makes.

type Dynamic added in v0.19.0

type Dynamic struct {
	// contains filtered or unexported fields
}

Dynamic is the topics a local application asks this host to carry while it uses them (POST /admin/topics): each entry names list items to append to the host's own list settings (OVERLAY_TOPICS, BSTORE_BUCKETS ...) and a lifetime after which, not refreshed, it lapses. It lives in a file the host owns (OVERLAY_TOPICS_DYNAMIC_FILE), so a restart carries what was asked for, and is laid over the settings source at every load and reload.

It holds no topic state of the engine's: only what was asked, under which id, until when. The engine's reload turns it into mounted topics, and a bridge that follows the engine announces them.

The host decides what an application may touch: only the keys in DynamicOptions.Keys, each a comma list the item is appended to (never a single value an item could corrupt), at most Max entries, each living at most MaxTTL.

func OpenDynamic added in v0.19.0

func OpenDynamic(path string, opt DynamicOptions) (*Dynamic, error)

OpenDynamic reads the file at path, absent being empty. An empty path is a host with no dynamic topics: nil, which every method takes. An entry the host's bounds no longer allow is left out, never a host that will not start.

func OpenDynamicDropped added in v0.19.0

func OpenDynamicDropped(path string, opt DynamicOptions) (*Dynamic, []string, error)

OpenDynamicDropped is OpenDynamic, also answering the ids of the entries it left out (out of the host's bounds, or past its count), for the host to log.

func (*Dynamic) Check added in v0.19.0

func (d *Dynamic) Check(e DynamicEntry) error

Check is whether e may be kept: the bounds, and room for it.

func (*Dynamic) Delete added in v0.19.0

func (d *Dynamic) Delete(id string) (bool, error)

Delete removes an entry and writes the file; it reports whether there was one.

func (*Dynamic) Drop added in v0.19.0

func (d *Dynamic) Drop(e DynamicEntry) (bool, error)

Drop removes the entry e stored, if the id still holds it (a later Put of the id stands), and reports whether it did. A failed ask is dropped, never rolled back to an earlier version: that version may be the one that failed.

func (*Dynamic) Expire added in v0.19.0

func (d *Dynamic) Expire(now time.Time) ([]string, error)

Expire removes the entries whose lifetime ran out by now and answers their ids.

func (*Dynamic) Layer added in v0.19.0

func (d *Dynamic) Layer(get func(string) string) func(string) string

Layer answers get with every entry's items appended to their keys' comma lists, once each, in id order. The snapshot is taken now: a later Put takes effect at the next Layer.

func (*Dynamic) LayerWith added in v0.19.0

func (d *Dynamic) LayerWith(e DynamicEntry, get func(string) string) func(string) string

LayerWith is Layer as it would be with e put: what a reload would read if e were kept, for checking it first.

func (*Dynamic) List added in v0.19.0

func (d *Dynamic) List() []DynamicEntry

List answers the entries, by id.

func (*Dynamic) Put added in v0.19.0

func (d *Dynamic) Put(e DynamicEntry) (prev *DynamicEntry, err error)

Put adds or replaces an entry and writes the file. It answers the entry it replaced, if any, for Undo.

type DynamicEntry added in v0.19.0

type DynamicEntry struct {
	// ID names the ask, so the same application refreshes or withdraws it
	// (a bucket name, a site, a stream).
	ID string `json:"id"`
	// Settings are list items appended to the host's settings, by key.
	Settings map[string][]string `json:"settings"`
	// Expires is when the entry lapses unless refreshed.
	Expires time.Time `json:"expires"`
	Updated time.Time `json:"updated"`
}

DynamicEntry is one application's ask.

type DynamicOptions added in v0.19.0

type DynamicOptions struct {
	// Keys are the list settings an entry may append to
	// (OVERLAY_TOPICS_DYNAMIC_KEYS).
	Keys []string
	// Max is the most entries kept (OVERLAY_TOPICS_DYNAMIC_MAX).
	Max int
	// MaxTTL is the longest lifetime an entry may ask
	// (OVERLAY_TOPICS_DYNAMIC_MAX_TTL_SECONDS).
	MaxTTL time.Duration
}

DynamicOptions bound what applications may ask for.

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is a configuration error.

func (*Error) Error

func (e *Error) Error() string

type Source added in v0.19.0

type Source struct {
	// contains filtered or unexported fields
}

Source is where the host reads its settings: the process environment with the file OVERLAY_ENV_FILE names laid over it. A reload (SIGHUP, POST /admin/reload) reads the file again, so a setting edited there takes effect without a restart; the environment a running process was started with never changes. A key the file held when the host started and holds no longer reads as unset, even where the unit loaded the same file as its EnvironmentFile, so removing a line removes the setting.

func NewSource added in v0.19.0

func NewSource() (*Source, func(string) string, error)

NewSource reads OVERLAY_ENV_FILE, if set, and answers the source with the getter it gives now. Without the variable the getter is the process environment and a reload changes nothing.

func (*Source) File added in v0.19.0

func (s *Source) File() string

File is the file the source reads; empty when none is set.

func (*Source) Read added in v0.19.0

func (s *Source) Read() (func(string) string, error)

Read reads the file again and answers the getter for it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL