stratum

package
v5.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MIT Imports: 31 Imported by: 0

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

func BanError(err error) error

func CoinbaseTransactionIdHash

func CoinbaseTransactionIdHash(dst *types.Hash, hasher *sha3.Digest, coinbaseBlobMinusBaseRTC 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.Conn

	Agent      string
	Login      bool
	Extensions struct {
		Algo bool
	}
	MergeMiningExtra sidechain.MergeMiningExtra
	Address          address.PackedAddress
	Subaddress       *address.PackedAddress
	Password         string
	RigId            string

	RpcId      uint32
	InternalId uint64
	// contains filtered or unexported fields
}

func (*Client) GetAddress

func (c *Client) GetAddress(majorVersion uint8) address.PackedAddressWithSubaddress

func (*Client) Write

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

type Job

type Job struct {
	TemplateCounter uint64

	ExtraNonce       uint32
	SideRandomNumber uint32
	SideExtraNonce   uint32

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

func JobFromString

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

func (*Job) Id

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
	Weight                    types.Difficulty
	Difficulty                types.Difficulty
	CumulativeDifficulty      types.Difficulty
	TransactionPrivateKeySeed types.Hash
	// TransactionPrivateKey Generated from TransactionPrivateKeySeed
	TransactionPrivateKey curve25519.PrivateKeyBytes
	TransactionPublicKey  curve25519.PublicKeyBytes
	Timestamp             uint64

	// Weights List of weights, first with zero index, second for all other entries
	Weights      []*WeightEntries
	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(minerId uint64, addrFunc func(majorVersion uint8) address.PackedAddressWithSubaddress, 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, majorVersion uint8, 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

	// FCMPOffset Start of FCMP++ section
	FCMPOffset 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, addr address.PackedAddressWithSubaddress, nonce, extraNonce, sideRandomNumber, sideExtraNonce uint32, merkleRoot types.Hash, merkleProof crypto.MerkleProof, mmExtra sidechain.MergeMiningExtra, softwareId p2pooltypes.SoftwareId, softwareVersion p2pooltypes.SoftwareVersion) []byte

func (*Template) BufferLength

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) CoinbaseBlobData

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

func (*Template) CoinbaseBlobId

func (tpl *Template) CoinbaseBlobId(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.Digest, extraNonce uint32, merkleRoot types.Hash, result *types.Hash)

func (*Template) HashingBlob

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

func (*Template) HashingBlobBufferLength

func (tpl *Template) HashingBlobBufferLength() int

func (*Template) MajorVersion

func (tpl *Template) MajorVersion() uint64

func (*Template) ShareVersion

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

func (*Template) TemplateId

func (tpl *Template) TemplateId(preAllocatedBuffer []byte, consensus *sidechain.Consensus, addr address.PackedAddressWithSubaddress, 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, addr address.PackedAddressWithSubaddress, nonce, extraNonce, sideRandomNumber, sideExtraNonce uint32, merkleRoot types.Hash, merkleProof crypto.MerkleProof, mmExtra sidechain.MergeMiningExtra, softwareId p2pooltypes.SoftwareId, softwareVersion p2pooltypes.SoftwareVersion) error

type WeightEntries

type WeightEntries struct {
	MaxRewardAmounts    uint64
	TotalReward         uint64
	CoinbaseTransaction uint64
	Transactions        []types.Hash
}