stratum

package
v0.4.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: ISC Imports: 23 Imported by: 0

Documentation

Overview

Package stratum implements a minimal Handshake-specific Stratum v1 server.

The protocol uses standard Stratum JSON line framing and method names (mining.subscribe, mining.authorize, mining.submit). Work notifications intentionally carry a serialized Handshake header template instead of Bitcoin coinbase-splitting fields because Handshake's mining search space is in the 236-byte header, including the 24-byte ExtraNonce field.

Index

Constants

View Source
const (
	// ExtraNonce1Size is the server-assigned prefix of the Handshake
	// header ExtraNonce field.
	ExtraNonce1Size = 8

	// ExtraNonce2Size is the miner-supplied suffix of the Handshake header
	// ExtraNonce field.
	ExtraNonce2Size = 16
)

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type BlockTemplateGenerator

type BlockTemplateGenerator interface {
	NewBlockTemplate(hnsutil.Address) (*mining.BlockTemplate, error)
	BestSnapshot() *blockchain.BestState
}

BlockTemplateGenerator is the subset of the mining template generator used by the Stratum server.

type Config

type Config struct {
	ChainParams            *chaincfg.Params
	BlockTemplateGenerator BlockTemplateGenerator
	MiningAddrs            []hnsutil.Address
	Listeners              []net.Listener
	ProcessBlock           func(*hnsutil.Block, blockchain.BehaviorFlags) (bool, error)
	Authorize              func(user, pass string) bool
	Difficulty             float64
	JobRefreshInterval     time.Duration
}

Config describes a Stratum server instance.

type Job

type Job struct {
	ID        string
	Seq       uint64
	Block     *wire.MsgBlock
	Height    int32
	PrevBlock chainhash.Hash
	Created   time.Time
	Submitted map[string]struct{}
}

Job is a mining job derived from a Handshake block template.

type Server

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

Server provides a minimal Stratum v1 server for Handshake mining.

func New

func New(cfg *Config) (*Server, error)

New returns a Stratum server configured with the provided settings.

func (*Server) ServeConn

func (s *Server) ServeConn(conn net.Conn)

ServeConn runs a single Stratum client connection. It is primarily useful for focused protocol tests.

func (*Server) Start

func (s *Server) Start()

Start begins accepting Stratum clients.

func (*Server) Stop

func (s *Server) Stop()

Stop gracefully stops the Stratum server.

func (*Server) Submit

func (s *Server) Submit(jobID string, extraNonce1 []byte,
	extraNonce2Hex, ntimeHex, nonceHex string) (*SubmitResult, error)

Submit validates and possibly submits a share for the provided job. It only calls ProcessBlock when the reconstructed Handshake block hash meets the network target encoded by the block header.

type SubmitResult

type SubmitResult struct {
	Accepted      bool
	BlockAccepted bool
	BlockHash     chainhash.Hash
}

SubmitResult describes the result of a submitted share.

Jump to

Keyboard shortcuts

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