Documentation
¶
Overview ¶
Package module is how an application mounts its topic managers and lookup services in the Go overlay engine.
It replaces the TypeScript host's Module/ModuleHost loader. Go has no runtime module loading worth using, so a module is compiled in: its package calls Register from init, the binary imports it, and OVERLAY_MODULES names which registered modules this host mounts. Each module is a thin adapter over its application's Go core: it holds no admission or lookup logic of its own that the core does not already hold.
The interfaces a module satisfies are bcommon's engine-neutral contract (github.com/lightwebinc/bcommon/module: TopicManager, LookupService and their payloads, Host, Module). A module written to that contract imports no engine; this package holds the registry, the runtime Host it is built with, and the adapters that make a contract manager an engine.TopicManager and a contract service an engine.LookupService.
Index ¶
- Variables
- func LookupService(svc bmodule.LookupService) engine.LookupService
- func Output(o *engine.Output) (*bmodule.Output, error)
- func Register(name string, f Factory)
- func Registered() []string
- func TopicManager(tm bmodule.TopicManager) engine.TopicManager
- type Background
- type Factory
- type Host
- type Module
- type Mounted
- type Prechecker
Constants ¶
This section is empty.
Variables ¶
var ErrCannotEvict = errors.New("module: the storage cannot forget an applied transaction")
ErrCannotEvict is a storage with no way to forget an applied transaction.
Functions ¶
func LookupService ¶ added in v0.2.0
func LookupService(svc bmodule.LookupService) engine.LookupService
LookupService makes an engine.LookupService of a contract service. The engine hands every admission as Atomic BEEF; the adapter reshapes it to the service's AdmissionMode, and a spend to its SpendNotificationMode, and leaves out what the service did not ask for.
Every notification inside a submission (admitted, spent, no longer retained, evicted) is timed into the submission's notify stage: the engine tells every mounted lookup service of every admitted and spent output, and a service's own indexing (a journal write, say) runs there.
func Output ¶ added in v0.2.0
Output makes a contract row of an engine row. The script and satoshis come from the row's BEEF, which the engine's reads include when asked; a row read without it has neither, which a restore that needs them refuses through its own check.
func Register ¶
Register makes a module available under name. Call it from init. A name registered twice panics: two modules under one name is a build error.
func TopicManager ¶ added in v0.2.0
func TopicManager(tm bmodule.TopicManager) engine.TopicManager
TopicManager makes an engine.TopicManager of a contract manager. A manager that is not an InputIdentifier needs no inputs fetched.
Types ¶
type Background ¶ added in v0.9.0
type Background struct {
// contains filtered or unexported fields
}
Background is the life of the modules' background work on one host.
func NewBackground ¶ added in v0.9.0
func NewBackground() *Background
NewBackground starts a background life.
type Host ¶
type Host struct {
// Topics are the topics this host carries (OVERLAY_TOPICS). A module may
// claim only topics in this list.
Topics []string
// Storage is the engine's storage, for lookup services that answer from
// it rather than from an index of their own.
Storage engine.Storage
// Registerer is the host's metrics registry; a module's families use its
// own prefix (bstore_, bbox_ ...), never overlay_go_.
Registerer prometheus.Registerer
Log *slog.Logger
// Background is the life of the module's background work (a terms
// route, a retention tick): its context ends when the host closes, and
// the host waits for what Go started before it closes its storage. Nil
// in a test that builds a Host by hand; Go then runs fn under a context
// that never ends.
Background *Background
}
Host is what a module is handed when it is built: the runtime this engine offers beyond the contract. Contract gives the contract's view of it.
type Module ¶
Module is what a factory returns: the contract's Module, managers keyed by tm_* topic name and lookup services keyed by ls_* name.
type Mounted ¶
type Mounted struct {
TopicManagers map[string]engine.TopicManager
LookupServices map[string]engine.LookupService
// Owner says which module mounted each topic and lookup name.
Owner map[string]string
// Restorers are the mounted lookup services that rebuild an index at
// startup, by name. Restore runs them.
Restorers map[string]bmodule.Restorer
// RestoreTopics are, by restorer name, the topics its module manages:
// the rows Restore hands it. None (a module that manages no topic) is
// every carried topic.
RestoreTopics map[string][]string
// Replayers are, by topic, the replayer of the module that manages the
// topic: its lookup service that is a bcommon module.Replayer (the
// first by name, if it has two). Catch-up asks it for the topics GASP
// never carries (ruling R-o).
Replayers map[string]bmodule.Replayer
// Prechecks are, by topic, the managers that are Prechecker.
Prechecks map[string]Prechecker
}
Mounted is the result of Mount: what the engine is built with.
func Mount ¶
Mount builds the named modules in order and merges them. It refuses rather than resolves every conflict, and it refuses a carried topic with no manager: a host must never admit a topic under a manager nobody chose.
- a name not registered;
- a topic outside h.Topics, or claimed by two modules;
- a lookup name claimed by two modules;
- a carried topic no module claims.
func (*Mounted) Restore ¶ added in v0.2.0
Restore hands every mounted Restorer the host's unspent rows on the topics its module manages (RestoreTopics), with the storage seam the contract allows, and returns the count each indexed. It runs before the engine serves, as the TypeScript host's restore does; a topic no restorer reads (anytx's load topics) is never read. Every module filters the rows it is handed by its own topics and reads anything else through the seam, so handing it only its own changes nothing but the time a start takes. A service that fails is the host failing to start.
type Prechecker ¶ added in v0.13.0
Prechecker is a contract topic manager whose verdict reads nothing the topic holds but the previous coins (bstore's records manager): the host calls Precheck with the submission's context (bcommon module.WithSubmission) before it takes the topic's lock, and hands the context Precheck returns down to IdentifyAdmissibleOutputs under the lock, where the manager finishes the verdict it left there. Precheck must count, log and store nothing: the host may never show the manager the transaction (a duplicate, an earlier refusal). A manager implements it without importing this package; the method is the contract.