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 ¶
- Variables
- func Doctor(ctx context.Context, cfg *Config, ca string, w io.Writer) error
- func Init(data string) (string, error)
- func Reach(ctx context.Context, hc *http.Client, urls ...string) string
- func WalletDir(data string) string
- type AdRec
- type BucketConfig
- type Config
- type EntryRec
- type Front
- type Funding
- type HeldRec
- type HoldRec
- type Holding
- type Limits
- type Options
- type Outgoing
- type Owed
- type Payout
- type PendingAd
- type PendingTree
- type Policy
- type Provider
- func (p *Provider) Addr() string
- func (p *Provider) Close() error
- func (p *Provider) Fees() mint.Fees
- func (p *Provider) FundAddress() (string, error)
- func (p *Provider) Identity() string
- func (p *Provider) NewPayer() *producer.Payer
- func (p *Provider) Purse(maxPay uint64) *purse.Purse
- func (p *Provider) Settler() publish.Settler
- func (p *Provider) Signer() *bwallet.Signer
- func (p *Provider) Staged(h [32]byte) ([]byte, error)
- func (p *Provider) Start(ctx context.Context) error
- func (p *Provider) Wallet() wallet.Interface
- type Settlement
- type State
- type Terms
- type Unclaimed
Constants ¶
This section is empty.
Variables ¶
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 Doctor ¶ added in v0.2.0
Doctor reports a provider's identity, its pool, its store, and whether the chain view, the header source, the settlement leg, the hosts, the facade and its own public routes answer, and the fee policy in force. It reads only: it opens the wallet to read the pool, walks the store's directory, and asks each endpoint one GET. ca, when set, is a PEM file trusted besides the system's for the provider's own public URL. It returns an error only when the configuration or the wallet cannot be read; an endpoint that does not answer is reported.
func Init ¶
Init creates a provider's wallet under data and returns its identity key; it refuses a directory that holds one.
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"`
// Chain is the chain view (proofs, spends, transactions):
// nodeapi.ParseChain's woc:main, woc:test, asset:<url> or a list;
// default woc:main or woc:test by Mainnet. Node, the older key, a
// node's asset API, is chain asset:<url>. Settle is the settlement leg,
// arcade:main, arcade:test, arcade:<url>, arc:<url>, rpc:<url> or
// tcp:<host:port> (default GorillaPool's arcade), with RPCUser, RPCPass
// and ArcadeKey as it needs; Headers a header source (bcommon headers:
// woc:main, bhs:<url>, arcade:<url>, chaintracks:<url> or a bridge
// URL; default woc:main or woc:test), HeadersToken its bearer token.
// WoCKey and WoCRate are a WhatsOnChain API key and its requests a
// second: a busy provider exceeds the free 3 a second and needs a key,
// or a node. On a regtest chain set chain, settle and headers.
Chain string `json:"chain,omitempty"`
Node string `json:"node,omitempty"`
Settle string `json:"settle,omitempty"`
RPCUser string `json:"rpc_user,omitempty"`
RPCPass string `json:"rpc_pass,omitempty"`
ArcadeKey string `json:"arcade_key,omitempty"`
Headers string `json:"headers,omitempty"`
HeadersToken string `json:"headers_token,omitempty"`
WoCKey string `json:"woc_key,omitempty"`
WoCRate float64 `json:"woc_rate,omitempty"`
// 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), or "bridge" when a bridge runs the provider
// as a front for another advertiser and supplies the backend (Front).
// Export, when set, keeps a read-only view of every held closure there
// for an NFS export (docs/provider.md); a bridge keeps no closure.
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. Fee is the miner fee policy (feepolicy.Config;
// default 100 satoshis per 1000 bytes, floor 250); FeeRate and FeeFloor
// are its older keys fee_sat_per_byte and fee_floor, still read.
TreeCount int `json:"tree_count"`
TreeSats uint64 `json:"tree_sats"`
Fee *feepolicy.Config `json:"fee,omitempty"`
FeeRate uint64 `json:"fee_sat_per_byte,omitempty"`
FeeFloor uint64 `json:"fee_floor,omitempty"`
// Mainnet selects mainnet addresses for the fund address, and the
// mainnet services by default.
Mainnet bool `json:"mainnet"`
// RefuseUnmined makes fund -beef take mined payments only.
RefuseUnmined bool `json:"refuse_unmined,omitempty"`
// 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"`
// Accept is the payment acceptance rule (accept_threshold_sats and the
// other accept_ keys, docs/provider.md).
acceptcfg.Config
}
Config is a provider's configuration file, JSON. Every field has a default but Data, PublicURL and Buckets.
func LoadConfig ¶
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.
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 Front ¶
type Front struct {
// Backend is the bridge backend. Its Advertise returns the
// advertiser's advertisement mined, with its own proof in the BEEF.
Backend backend.Backend
// Advertiser is the advertiser's identity key, 33 bytes compressed:
// every advertisement the backend returns must name it.
Advertiser []byte
// Forward is told of every spend of a held entry's hold output (a
// settlement, or a reclaim) once it is mined. An error is retried.
Forward func(context.Context, Settlement) error
}
Front makes a provider the market front of spec section 17 for an advertiser that holds, serves and advertises the bytes itself: an incumbent UHRP host joined through a bridge backend. The provider still receives, checks the closure, recomputes the proof root, decides and answers; then, for each closure it takes, it hands every object to the backend (Put), has the backend make the closure held (Advertise: the advertiser commits or renews through its own routes), checks the advertisement the backend returns, publishes it to the bucket's records topic unchanged, and drops its own copy of the bytes, keeping the proof tree's segment hashes. It answers challenges by reference only, every sampled segment read through the backend (from the advertiser's URL) and checked against the kept hashes before anything is signed; it serves no object routes and takes no uploads; a bounty pays the advertiser, so a settlement it finds is passed to Forward rather than taken.
type HeldRec ¶ added in v0.4.0
HeldRec is a challenge payment held for confirmation: its class and when it was taken (Unix seconds).
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.
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"`
// Handed is a front's: every object was handed to the backend and the
// advertiser's advertisement adopted, and the front's own copy of the
// bytes dropped (Bytes is then 0).
Handed bool `json:"handed,omitempty"`
}
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
// Front, when set, makes the provider a front for another advertiser
// (configuration backend "bridge"): see Front.
Front *Front
// Accept, when set, adjusts the payment verifier once it is built
// (tests: a broadcaster or a status source of their own).
Accept func(*acceptance.Verifier)
}
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"`
// Held is a renewal whose payment is held for confirmation: made once
// the payment's proof verifies, dropped if it is double-spent first.
Held bool `json:"held,omitempty"`
}
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 (*Provider) FundAddress ¶
FundAddress is where coin for the provider's fees is paid.
func (*Provider) NewPayer ¶
NewPayer is a payer over the provider's pool, for a transaction a caller funds from it (its fee coin taken, its change kept).
func (*Provider) Purse ¶
Purse pays from the provider's pool, up to maxPay for one payment (zero pays nothing): a BRC-105 402 answered as a client (the wallet of go-sdk AuthFetch).
func (*Provider) Staged ¶
Staged is an object of the provider's own store, whole: for a front, what a bridge backend uploads from between Put and Advertise, before the front drops its copy.
type Settlement ¶
type Settlement struct {
Entry string `json:"entry"`
Bucket string `json:"bucket"`
Root string `json:"root"`
Hold string `json:"hold"`
Writer string `json:"senderIdentityKey"`
K uint64 `json:"k"`
Txid string `json:"txid"`
Height uint32 `json:"height"`
DerivationPrefix string `json:"derivationPrefix"`
// BEEF is the spending transaction as Atomic BEEF with its proof.
BEEF []byte `json:"beef"`
}
Settlement is a spend of the hold output of an entry a front took, as a front finds it: the payee of a bounty is the advertiser, whose key the front does not hold, so the front forwards what the advertiser needs to find and take its output (spec section 9.5): the transaction, and the BRC-29 derivation's prefix and sender; the suffix is the rank's, for ranks 1 to K.
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"`
// MadeGood are lost fast remittances (unsettleable) whose entry's hold
// output was later spent by a mined settlement paying this provider at
// least as much, by the lost txid: the writer made the loss good, so it
// is not held for confirmation on their account.
MadeGood map[string]string `json:"madeGood,omitempty"`
// Owed are renewals paid for and not made yet.
Owed []Owed `json:"owed,omitempty"`
// Held are challenge payments taken and held for confirmation, by
// txid, with their class: sent again once mined, each buys its answer.
Held map[string]HeldRec `json:"held,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.