stratum

package
v4.9.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2025 License: MIT Imports: 29 Imported by: 1

Documentation

Index

Constants

View Source
const HighFeeValue uint64 = 6000000000

HighFeeValue 0.006 XMR

View Source
const ShuffleMappingZeroKeyIndex = 0
View Source
const Target4BytesLimit = math.MaxUint64 / 4000001

Target4BytesLimit Use short target format (4 bytes) for diff <= 4 million

View Source
const TimeInMempool = time.Second * 5

Variables

View Source
var ErrBannable = errors.New("banned")

Functions

func ApplyShuffleMapping

func ApplyShuffleMapping[T any](v []T, mappings ShuffleMapping) []T

ApplyShuffleMapping Applies a shuffle mapping depending on source length Returns nil in case no source length matches shuffle mapping

func BanError added in v4.9.0

func BanError(err error) error

func CoinbaseIdHash

func CoinbaseIdHash(hasher *sha3.HasherState, coinbaseBlobMinusBaseRTC types.Hash, result *types.Hash)

func TargetHex

func TargetHex(target uint64) string

Types

type BanEntry

type BanEntry struct {
	Expiration uint64
	Error      error
}

type Client

type Client struct {
	Lock sync.RWMutex
	Conn *net.TCPConn

	Agent      string
	Login      bool
	Extensions struct {
		Algo bool
	}
	MergeMiningExtra  sidechain.MergeMiningExtra
	Address           address.PackedAddress
	SubaddressViewPub [33]byte
	Password          string
	RigId             string

	RpcId uint32
	// contains filtered or unexported fields
}

func (*Client) Write

func (c *Client) Write(b []byte) (int, error)

type Job added in v4.9.0

type Job struct {
	TemplateCounter uint64

	ExtraNonce       uint32
	SideRandomNumber uint32
	SideExtraNonce   uint32

	MerkleRoot       types.Hash
	MerkleProof      crypto.MerkleProof
	MergeMiningExtra sidechain.MergeMiningExtra
}

func JobFromString added in v4.9.0

func JobFromString(s string) (j Job, err error)

func (Job) Id added in v4.9.0

func (j Job) Id() string

type JsonRpcJob

type JsonRpcJob struct {
	// JsonRpcVersion Always "2.0"
	JsonRpcVersion string `json:"jsonrpc"`
	// Method always "job"
	Method string           `json:"method"`
	Params jsonRpcJobParams `json:"params"`
}

type JsonRpcMessage

type JsonRpcMessage struct {
	// Id set by client
	Id any `json:"id,omitempty"`
	// JsonRpcVersion Always "2.0"
	JsonRpcVersion string `json:"jsonrpc"`
	Method         string `json:"method"`
	Params         any    `json:"params,omitempty"`
}

type JsonRpcResponseJob

type JsonRpcResponseJob struct {
	// Id set by client
	Id any `json:"id,omitempty"`
	// JsonRpcVersion Always "2.0"
	JsonRpcVersion string                   `json:"jsonrpc"`
	Result         jsonRpcResponseJobResult `json:"result"`
}

type JsonRpcResult

type JsonRpcResult struct {
	// Id set by client
	Id any `json:"id,omitempty"`
	// JsonRpcVersion Always "2.0"
	JsonRpcVersion string `json:"jsonrpc"`
	Result         any    `json:"result,omitempty"`
	Error          any    `json:"error"`
}

type MinerTrackingEntry

type MinerTrackingEntry struct {
	Lock         sync.RWMutex
	Counter      atomic.Uint64
	LastTemplate atomic.Uint64
	Templates    map[uint64]*Template
	LastJob      time.Time
}

func (*MinerTrackingEntry) GetJobBlob

func (e *MinerTrackingEntry) GetJobBlob(c *Client, consensus *sidechain.Consensus, job Job, nonce uint32) []byte

GetJobBlob Gets old job data based on returned id

type MiningMempool

type MiningMempool map[types.Hash]*mempool.Entry

func (MiningMempool) Add

func (m MiningMempool) Add(tx *mempool.Entry) (added bool)

Add Inserts a transaction into the mempool.

func (MiningMempool) Select

func (m MiningMempool) Select(highFee uint64, receivedSince time.Duration) (pool mempool.Mempool)

func (MiningMempool) Swap

func (m MiningMempool) Swap(pool mempool.Mempool)

type NewTemplateData

type NewTemplateData struct {
	PreviousTemplateId        types.Hash
	SideHeight                uint64
	Difficulty                types.Difficulty
	CumulativeDifficulty      types.Difficulty
	TransactionPrivateKeySeed types.Hash
	// TransactionPrivateKey Generated from TransactionPrivateKeySeed
	TransactionPrivateKey  crypto.PrivateKeyBytes
	TransactionPublicKey   crypto.PublicKeySlice
	Timestamp              uint64
	TotalReward            uint64
	Transactions           []types.Hash
	MaxRewardAmountsWeight uint64
	ShareVersion           sidechain.ShareVersion
	Uncles                 []types.Hash
	Ready                  bool
	Window                 struct {
		ReservedShareIndex   int
		Shares               sidechain.Shares
		ShuffleMapping       ShuffleMapping
		EphemeralPubKeyCache map[ephemeralPubKeyCacheKey]*ephemeralPubKeyCacheEntry
	}
}

type Server

type Server struct {
	SubmitFunc     func(block *sidechain.PoolBlock) error
	SubmitMainFunc func(b *block.Block) error
	// contains filtered or unexported fields
}

func NewServer

func NewServer(s *sidechain.SideChain, submitFunc func(block *sidechain.PoolBlock) error, submitMain func(b *block.Block) error) *Server

func (*Server) Ban

func (s *Server) Ban(ip netip.Addr, duration time.Duration, err error)

func (*Server) BuildTemplate

func (s *Server) BuildTemplate(addr address.PackedAddress, forceNewTemplate bool) (tpl *Template, jobCounter uint64, difficultyTarget types.Difficulty, seedHash types.Hash, err error)

func (*Server) CleanupBanList

func (s *Server) CleanupBanList()

func (*Server) CleanupMiners

func (s *Server) CleanupMiners()

func (*Server) CloseClient

func (s *Server) CloseClient(c *Client)

func (*Server) HandleBroadcast

func (s *Server) HandleBroadcast(block *sidechain.PoolBlock)

func (*Server) HandleMempoolData

func (s *Server) HandleMempoolData(data mempool.Mempool)

func (*Server) HandleMinerData

func (s *Server) HandleMinerData(minerData *p2pooltypes.MinerData)

func (*Server) HandleTip

func (s *Server) HandleTip(tip *sidechain.PoolBlock)

func (*Server) IsBanned

func (s *Server) IsBanned(ip netip.Addr) (bool, *BanEntry)

func (*Server) Listen

func (s *Server) Listen(listen string, controlOpts ...func(network, address string, c syscall.RawConn) (err error)) error

func (*Server) SendTemplate

func (s *Server) SendTemplate(c *Client, supportsTemplate bool) (err error)

func (*Server) SendTemplateResponse

func (s *Server) SendTemplateResponse(c *Client, id any, supportsTemplate bool) (err error)

func (*Server) Update

func (s *Server) Update()

type ShuffleMapping

type ShuffleMapping struct {
	// Including the index mapping contains a new miner in the list
	Including []int
	// Excluding the index mapping doesn't contain a new miner.
	// len(Excluding) = len(Including) - 1 (unless len(Including) == 1, where it's also 1)
	Excluding []int
}

func BuildShuffleMapping

func BuildShuffleMapping(n int, shareVersion sidechain.ShareVersion, transactionPrivateKeySeed types.Hash, oldMappings ShuffleMapping) (mappings ShuffleMapping)

BuildShuffleMapping Creates a mapping of source to destination miner output post shuffle This uses two mappings, one where a new miner is added to the list, and one where the count stays the same Usual usage will place Zero key in index 0

func (ShuffleMapping) RangePossibleIndices

func (m ShuffleMapping) RangePossibleIndices(f func(i, ix0, ix1, ix2 int))

type ShuffleMappingIndices

type ShuffleMappingIndices [][3]int

type Template

type Template struct {
	Buffer []byte

	// NonceOffset offset of an uint32
	NonceOffset int

	CoinbaseOffset int

	// ExtraNonceOffset offset of an uint32
	ExtraNonceOffset int

	// MerkleRootOffset offset of a types.Hash for merge mining id
	MerkleRootOffset int

	// TransactionsOffset Start of transactions section
	TransactionsOffset int

	// TemplateSideDataOffset Start of side data section
	TemplateSideDataOffset int

	MainHeight uint64
	MainParent types.Hash

	SideHeight     uint64
	SideParent     types.Hash
	SideDifficulty types.Difficulty

	MerkleTreeMainBranch []types.Hash
}

func TemplateFromPoolBlock

func TemplateFromPoolBlock(consensus *sidechain.Consensus, b *sidechain.PoolBlock) (tpl *Template, err error)

func (*Template) Blob

func (tpl *Template) Blob(preAllocatedBuffer []byte, consensus *sidechain.Consensus, nonce, extraNonce, sideRandomNumber, sideExtraNonce uint32, merkleRoot types.Hash, merkleProof crypto.MerkleProof, mmExtra sidechain.MergeMiningExtra, softwareId p2pooltypes.SoftwareId, softwareVersion p2pooltypes.SoftwareVersion) []byte

func (*Template) BufferLength added in v4.9.0

func (tpl *Template) BufferLength(consensus *sidechain.Consensus, merkleProof crypto.MerkleProof, mmExtra sidechain.MergeMiningExtra) int

func (*Template) CoinbaseBlob

func (tpl *Template) CoinbaseBlob(preAllocatedBuffer []byte, extraNonce uint32, merkleRoot types.Hash) []byte

func (*Template) CoinbaseBlobId

func (tpl *Template) CoinbaseBlobId(hasher *sha3.HasherState, preAllocatedBuffer []byte, extraNonce uint32, templateId types.Hash, result *types.Hash)

func (*Template) CoinbaseBufferLength

func (tpl *Template) CoinbaseBufferLength() int

func (*Template) CoinbaseId

func (tpl *Template) CoinbaseId(hasher *sha3.HasherState, extraNonce uint32, merkleRoot types.Hash, result *types.Hash)

func (*Template) HashingBlob

func (tpl *Template) HashingBlob(hasher *sha3.HasherState, preAllocatedBuffer []byte, nonce, extraNonce uint32, merkleRoot types.Hash) []byte

func (*Template) HashingBlobBufferLength

func (tpl *Template) HashingBlobBufferLength() int

func (*Template) MainBlock

func (tpl *Template) MainBlock() (b mainblock.Block, err error)

func (*Template) ShareVersion

func (tpl *Template) ShareVersion(consensus *sidechain.Consensus) sidechain.ShareVersion

func (*Template) TemplateId

func (tpl *Template) TemplateId(hasher *sha3.HasherState, preAllocatedBuffer []byte, consensus *sidechain.Consensus, sideRandomNumber, sideExtraNonce uint32, merkleProof crypto.MerkleProof, mmExtra sidechain.MergeMiningExtra, softwareId p2pooltypes.SoftwareId, softwareVersion p2pooltypes.SoftwareVersion, result *types.Hash)

func (*Template) Timestamp

func (tpl *Template) Timestamp() uint64

func (*Template) Write

func (tpl *Template) Write(writer io.Writer, consensus *sidechain.Consensus, nonce, extraNonce, sideRandomNumber, sideExtraNonce uint32, merkleRoot types.Hash, merkleProof crypto.MerkleProof, mmExtra sidechain.MergeMiningExtra, softwareId p2pooltypes.SoftwareId, softwareVersion p2pooltypes.SoftwareVersion) error

Jump to

Keyboard shortcuts

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