provider

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 49 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 provider is bstore-provider: the market front of spec section 17 over a hold backend. It receives pieces from a bucket's blob topic (the plane's delivery, or a writer's unicast through BRC-167 upload sessions) and entries from its records topic; checks each closure as spec section 5 and rows C1 to C4 of frozen.md section 14 have it, and recomputes the proof root; decides by its hold policy and the bounty's own checks (spec section 9.3); advertises at once, because the writer ranks by first sight; answers challenges, renewals and settlement remittances on its front (spec section 10.1); and serves the closure on BRC-167's object routes, with HTTP Range.

Index

Constants

This section is empty.

Variables

View Source
var Profile = bwallet.Profile{
	FundProtocol:   storerec.Protocol,
	FundKeyID:      storerec.KeyFund,
	FundBasket:     "bstore fund",
	Version:        "bstore-provider-1",
	LegacyPoolFile: "bstore-provider-pool.json",
}

Profile is the embedded wallet's profile: the fund key under [1, "bstore"] key id fund, counterparty self, and the registered basket.

Functions

func Init

func Init(data string) (string, error)

Init creates a provider's wallet under data and returns its identity key; it refuses a directory that holds one.

func WalletDir

func WalletDir(data string) string

WalletDir is the wallet's directory under a data directory.

Types

type AdRec

type AdRec struct {
	Txid   string `json:"txid"`
	Vout   uint32 `json:"vout"`
	Expiry uint64 `json:"expiry"`
	Height uint32 `json:"height"`
	RawHex string `json:"rawHex"`
	Bump   string `json:"bump"`
	// First is the txid of the advertisement this one renews, through
	// every renewal: the one whose first sight a renewal keeps.
	First string `json:"first"`
}

AdRec is a mined advertisement.

type BucketConfig

type BucketConfig struct {
	Bucket string `json:"bucket"`
	// Writers, when set, are the only writers whose pieces and entries are
	// taken, 66 hex digits each.
	Writers []string `json:"writers,omitempty"`
}

BucketConfig is one bucket the provider subscribes to.

type Config

type Config struct {
	// Data is the data directory: the wallet, the state, the store, the
	// payment ledger. Absolute.
	Data string `json:"data"`
	// Listen is the address the routes are served on; TLSCert and TLSKey,
	// when both set, serve them over TLS (otherwise a TLS proxy in front
	// terminates it).
	Listen  string `json:"listen"`
	TLSCert string `json:"tls_cert,omitempty"`
	TLSKey  string `json:"tls_key,omitempty"`
	// PublicURL is the https URL the routes are reached at from outside:
	// objects at <PublicURL>/chirp/v1/..., the front at
	// <PublicURL>/bstore/v1 (spec section 10.1). No trailing slash, no
	// query, no fragment, no user information.
	PublicURL string `json:"public_url"`
	// Node is a Teranode asset API (proofs, spends, block hashes); Settle
	// the settlement leg, tcp:<host:port>, rpc:<url> or arcade:<url>, with
	// RPCUser, RPCPass and ArcadeKey as it needs; Headers a header source
	// (bcommon headers: woc:main, chaintracks:<url> or a bridge URL).
	Node      string `json:"node"`
	Settle    string `json:"settle"`
	RPCUser   string `json:"rpc_user,omitempty"`
	RPCPass   string `json:"rpc_pass,omitempty"`
	ArcadeKey string `json:"arcade_key,omitempty"`
	Headers   string `json:"headers"`
	// Hosts are the overlay hosts advertisements are submitted to, each
	// directly; Facade, when set, is a plane facade they are submitted to
	// once as well. UHRPTopic also submits each to tm_uhrp, as BRC-26 has
	// it, where a host carries that topic.
	Hosts     []string `json:"hosts"`
	Facade    string   `json:"facade,omitempty"`
	UHRPTopic bool     `json:"uhrp_topic"`
	// Buckets are the buckets the provider takes objects for.
	Buckets []BucketConfig `json:"buckets"`
	// Backend selects the hold backend: "native" (the content-addressed
	// store under Data/store). Export, when set, keeps a read-only view of
	// every held closure there for an NFS export (docs/provider.md).
	Backend string `json:"backend"`
	Export  string `json:"export,omitempty"`
	// QuotaBytes bounds the store; UnclaimedBytes the part of it pieces no
	// entry has claimed yet may take, and UnclaimedSeconds how long such a
	// piece is kept.
	QuotaBytes       uint64 `json:"quota_bytes"`
	UnclaimedBytes   uint64 `json:"unclaimed_bytes"`
	UnclaimedSeconds uint64 `json:"unclaimed_seconds"`
	// Policy is what the provider takes, Terms what it publishes and
	// charges, Limits its routes' hardening.
	Policy Policy `json:"policy"`
	Terms  Terms  `json:"terms"`
	Limits Limits `json:"limits"`
	// TreeCount and TreeSats size the funding trees advertisements and
	// renewals spend; FeeRate and FeeFloor are the fee policy.
	TreeCount int    `json:"tree_count"`
	TreeSats  uint64 `json:"tree_sats"`
	FeeRate   uint64 `json:"fee_sat_per_byte"`
	FeeFloor  uint64 `json:"fee_floor"`
	// Mainnet selects mainnet addresses for the fund address.
	Mainnet bool `json:"mainnet"`
	// TrustedProxies are the addresses (CIDR) of proxies in front of the
	// provider whose X-Forwarded-For names the client: every per-address
	// budget is the client's, not the proxy's.
	TrustedProxies []string `json:"trusted_proxies,omitempty"`
	// MetricsListen, when set, serves /metrics there, and only there.
	MetricsListen string `json:"metrics_listen,omitempty"`
}

Config is a provider's configuration file, JSON. Every field has a default but Data, PublicURL, Node, Settle, Headers and Buckets.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig reads a configuration file, takes the defaults and checks it. An unknown key is refused, so a misspelt one is not silently a default.

func (*Config) Check

func (c *Config) Check() error

Check takes the defaults and refuses a configuration that cannot run.

func (*Config) FrontURL

func (c *Config) FrontURL() string

FrontURL is the front a provider's advertisement derives: the public URL followed by /bstore/v1.

type EntryRec

type EntryRec struct {
	C           string   `json:"c"`
	Bucket      string   `json:"bucket"`
	Writer      string   `json:"writer"`
	Root        string   `json:"root"`
	Size        uint64   `json:"size"`
	ContentHash string   `json:"contentHash"`
	ProofRoot   string   `json:"proofRoot"`
	Created     uint64   `json:"created"`
	Hold        *HoldRec `json:"hold,omitempty"`
	// Decision is "", "held", or why it was declined; At when it arrived.
	Decision string `json:"decision"`
	At       int64  `json:"at"`
}

EntryRec is an object entry the provider received, and what it decided.

type Funding

type Funding struct {
	C  string `json:"c"`
	At int64  `json:"at"`
}

Funding is the carrier a funding outpoint paid for.

type HoldRec

type HoldRec struct {
	Txid      string `json:"txid"` // display order
	Vout      uint32 `json:"vout"`
	Sats      uint64 `json:"sats"`
	T         uint64 `json:"t"`
	K         uint64 `json:"k"`
	Retention uint64 `json:"retention"`
	Deadline  uint64 `json:"deadline"`
	CheckC    uint64 `json:"checkC"`
	// Height is the hold output's block, once checked.
	Height uint32 `json:"height,omitempty"`
}

HoldRec is an entry's hold terms and what the provider found of them.

func (*HoldRec) Outpoint

func (h *HoldRec) Outpoint() string

Outpoint is the hold output as "<txid>.<vout>".

type Holding

type Holding struct {
	Root        string `json:"root"`
	Size        uint64 `json:"size"`
	ContentHash string `json:"contentHash"`
	ProofRoot   string `json:"proofRoot"`
	// RootLen is the root node's length: the advertisement's fileSize.
	RootLen uint64 `json:"rootLen"`
	// Objects and Blobs count the closure's distinct objects and its blob
	// positions; Bytes is what its distinct objects take on disk.
	Objects int    `json:"objects"`
	Blobs   int    `json:"blobs"`
	Bytes   uint64 `json:"bytes"`
	// Verified once the closure and its proof root checked out; Damaged
	// once an object read back wrong or went missing, after which the root
	// is neither served, answered for nor renewed.
	Verified bool `json:"verified"`
	Damaged  bool `json:"damaged,omitempty"`
	// Buckets and Entries name what it is held for.
	Buckets []string `json:"buckets"`
	Entries []string `json:"entries"`
	// Ad is the live advertisement; Lease is the expiry the closure is
	// kept through (an advertisement's, or a pending one's).
	Ad    *AdRec `json:"ad,omitempty"`
	Lease uint64 `json:"lease"`
	// At is when it was taken, Unix seconds.
	At int64 `json:"at"`
}

Holding is a closure the provider holds, or is deciding to.

type Limits

type Limits struct {
	HandshakesPerSec        float64 `json:"handshakes_per_sec"`
	HandshakeBurst          float64 `json:"handshake_burst"`
	HandshakesPerAddrPerSec float64 `json:"handshakes_per_addr_per_sec"`
	HandshakeAddrBurst      float64 `json:"handshake_addr_burst"`
	ResponsesPerSec         float64 `json:"responses_per_sec"`
	ResponseBurst           float64 `json:"response_burst"`
	Sessions                int     `json:"sessions"`
	SessionTTLSeconds       int     `json:"session_ttl_seconds"`
	// ChallengesPerBuyerPerMin and ChallengeBurst bound the challenges one
	// buyer (identity key) is answered; FreePerWriterPerMin the free
	// settlement challenges one writer is.
	ChallengesPerBuyerPerMin float64 `json:"challenges_per_buyer_per_min"`
	ChallengeBurst           float64 `json:"challenge_burst"`
	FreePerWriterPerMin      float64 `json:"free_per_writer_per_min"`
	// ChallengeWorkers bounds the challenges answered at once.
	ChallengeWorkers int `json:"challenge_workers"`
	// RenewalsPerRootPerHour bounds paid renewals of one root.
	RenewalsPerRootPerHour float64 `json:"renewals_per_root_per_hour"`
	// SubmitsPerAddrPerSec and SubmitBurst bound submissions from one
	// address (the plane's listener, or a writer's unicast).
	SubmitsPerAddrPerSec float64 `json:"submits_per_addr_per_sec"`
	SubmitBurst          float64 `json:"submit_burst"`
	// ObjectReaders bounds the object reads served at once;
	// ObjectReadsPerAddrPerSec and ObjectReadBurst one address's reads.
	ObjectReaders            int     `json:"object_readers"`
	ObjectReadsPerAddrPerSec float64 `json:"object_reads_per_addr_per_sec"`
	ObjectReadBurst          float64 `json:"object_read_burst"`
	// UploadSessions bounds the open upload sessions, and their life.
	UploadSessions       int    `json:"upload_sessions"`
	UploadSessionSeconds uint64 `json:"upload_session_seconds"`
}

Limits are the routes' hardening; zero takes the default.

type Options

type Options struct {
	// Now is the clock; Tick paces the background work (resuming,
	// publishing, collecting, settling, evicting); Logf receives the log.
	Now  func() time.Time
	Tick time.Duration
	Logf func(format string, args ...any)
	// Settler, when set, is the settlement leg instead of the configured
	// one.
	Settler publish.Settler
}

Options are what a caller embedding a provider may set beyond the configuration.

type Outgoing

type Outgoing struct {
	Host  string `json:"host"`
	Topic string `json:"topic"`
	Txid  string `json:"txid"`
	Beef  string `json:"beef"`
	Tries int    `json:"tries"`
	Next  int64  `json:"next"`
}

Outgoing is a mined advertisement still to reach one host on one topic.

type Owed

type Owed struct {
	Root    string `json:"root"`
	Until   uint64 `json:"until"`
	Payment string `json:"payment"`
}

Owed is a renewal paid for: the root's advertisement is owed through Until.

type Payout

type Payout struct {
	Settlement string `json:"settlement"`
	Rank       int    `json:"rank"`
	Satoshis   uint64 `json:"satoshis"`
	// Via is "remittance" or "scan".
	Via string `json:"via"`
	At  int64  `json:"at"`
}

Payout is a settlement found paying this provider for one entry.

type PendingAd

type PendingAd struct {
	Root    string `json:"root"`
	Txid    string `json:"txid"`
	BeefHex string `json:"beef"`
	Expiry  uint64 `json:"expiry"`
	// Tree and Vout are the funding output it spends for its fee; Prev the
	// advertisement a renewal spends.
	Tree string `json:"tree"`
	Vout uint32 `json:"vout"`
	Prev *AdRec `json:"prev,omitempty"`
	// Sent once the settlement leg took it.
	Sent bool  `json:"sent,omitempty"`
	At   int64 `json:"at"`
}

PendingAd is an advertisement or renewal transaction signed and persisted before it reaches the settlement leg.

type PendingTree

type PendingTree struct {
	Tree         funding.Tree   `json:"tree"`
	Coin         bwallet.Output `json:"coin"`
	ReturnedOnce bool           `json:"returnedOnce,omitempty"`
}

PendingTree is a funding tree signed for a coin and not yet adopted (producer.Trees.Prepare); ReturnedOnce marks one whose coin came back once, kept for one more recovery.

type Policy

type Policy struct {
	// MaxObject is the largest object taken, bytes.
	MaxObject uint64 `json:"max_object"`
	// MinDeadlineBlocks is how far ahead of the tip an entry's deadline
	// must be for its bounty to be raced for.
	MinDeadlineBlocks uint64 `json:"min_deadline_blocks"`
	// MaxRetentionSeconds is the longest an entry may ask an advertisement
	// to last from the entry's created time.
	MaxRetentionSeconds uint64 `json:"max_retention_seconds"`
	// HoldUnbountied takes an entry with no bounty, or one whose bounty
	// does not check out, for UnbountiedSeconds.
	HoldUnbountied    bool   `json:"hold_unbountied"`
	UnbountiedSeconds uint64 `json:"unbountied_seconds"`
	// AnswerInline answers challenges with the segments (the default); off,
	// every sample is by reference, fetched by the buyer from the
	// advertised URL.
	AnswerInline *bool `json:"answer_inline,omitempty"`
}

Policy is the provider's hold policy (spec section 9.3; not frozen).

type Provider

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

Provider is one running provider.

func New

func New(ctx context.Context, cfg *Config, opts Options) (*Provider, error)

New opens a provider over a checked configuration; Start serves it.

func (*Provider) Addr

func (p *Provider) Addr() string

Addr is the address the routes are served on.

func (*Provider) Close

func (p *Provider) Close() error

Close stops serving and the background work, and saves.

func (*Provider) FundAddress

func (p *Provider) FundAddress() (string, error)

FundAddress is where coin for the provider's fees is paid.

func (*Provider) Identity

func (p *Provider) Identity() string

Identity is the provider's identity key, 66 hex digits.

func (*Provider) Start

func (p *Provider) Start(ctx context.Context) error

Start listens, recovers what a previous run left, and starts the background work. It returns once the routes are served.

func (*Provider) Wallet

func (p *Provider) Wallet() wallet.Interface

Wallet is the provider's wallet.

type State

type State struct {
	Identity string `json:"identity"`

	// The funding trees advertisements and renewals spend.
	Tree         *funding.Tree  `json:"tree,omitempty"`
	Trees        []funding.Tree `json:"trees,omitempty"`
	Ahead        []funding.Tree `json:"ahead,omitempty"`
	PendingTrees []PendingTree  `json:"pendingTrees,omitempty"`

	// Holdings by root (64 hex digits); Entries by commitment (display
	// txid of the entry carrier).
	Holdings map[string]*Holding  `json:"holdings"`
	Entries  map[string]*EntryRec `json:"entries"`
	// Unclaimed are pieces no held closure names yet, by object hash.
	Unclaimed map[string]*Unclaimed `json:"unclaimed"`
	// PendingAds are advertisement and renewal transactions signed and not
	// yet recorded as mined: the journal a restart resumes from.
	PendingAds []PendingAd `json:"pendingAds,omitempty"`
	// Outbox is mined advertisements still to reach a host.
	Outbox []Outgoing `json:"outbox,omitempty"`
	// Free counts the free settlement challenges answered, by hold
	// outpoint ("<txid>.<vout>"): at most two each (spec section 9.4).
	Free map[string]int `json:"free"`
	// Payouts are the settlements found paying this provider, by entry
	// commitment: from a remittance or from the hold output's spend.
	Payouts map[string]*Payout `json:"payouts"`
	// Owed are renewals paid for and not made yet.
	Owed []Owed `json:"owed,omitempty"`
	// Fundings are the funding outpoints carriers were taken on, and the
	// carrier each paid for (its commitment, hex).
	Fundings map[string]*Funding `json:"fundings"`
	// Book is the payee's record of the ledger's payments settled.
	payee.Book
	// contains filtered or unexported fields
}

State is what a provider keeps between runs, in state.json in its data directory, written whole to a temporary file, synced and renamed. Large per-root data (the proof tree's leaves, the closure's objects) lives in files of its own under roots/.

type Terms

type Terms struct {
	ChallengeBase      uint64 `json:"challenge_base"`
	ChallengePerSample uint64 `json:"challenge_per_sample"`
	FreeC              uint64 `json:"free_c"`
	MinBounty          uint64 `json:"min_bounty"`
	MinAge             uint64 `json:"min_age"`
	RenewPerGiBDay     uint64 `json:"renew_per_gib_day"`
	RenewMinimum       uint64 `json:"renew_minimum"`
	// MaxRenewSeconds is the furthest ahead of now a renewal may run.
	MaxRenewSeconds uint64 `json:"max_renew_seconds"`
}

Terms are the provider's published terms (spec section 10.1), and the limits of what it sells.

type Unclaimed

type Unclaimed struct {
	Root   string `json:"root"`
	Bucket string `json:"bucket"`
	// Writer is who sent it: the piece's writer, or the identity that
	// uploaded it.
	Writer string `json:"writer"`
	Size   uint64 `json:"size"`
	At     int64  `json:"at"`
}

Unclaimed is a piece kept until an entry names its closure.

Jump to

Keyboard shortcuts

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