stratum

package
v3.11.3 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: MIT Imports: 27 Imported by: 1

Documentation

Index

Constants

View Source
const HighFeeValue uint64 = 6000000000

HighFeeValue 0.006 XMR

View Source
const JobIdentifierSize = 8 + 4 + 4 + 4 + types.HashSize
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

This section is empty.

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 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
	Address  address.PackedAddress
	Password string
	RigId    string

	RpcId uint32
	// contains filtered or unexported fields
}

func (*Client) Write

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

type JobIdentifier

type JobIdentifier [JobIdentifierSize]byte

func JobIdentifierFromString

func JobIdentifierFromString(s string) (JobIdentifier, error)

func JobIdentifierFromValues

func JobIdentifierFromValues(templateCounter uint64, extraNonce, sideRandomNumber, sideExtraNonce uint32, templateId types.Hash) JobIdentifier

func (JobIdentifier) ExtraNonce

func (id JobIdentifier) ExtraNonce() uint32

func (JobIdentifier) SideExtraNonce

func (id JobIdentifier) SideExtraNonce() uint32

func (JobIdentifier) SideRandomNumber

func (id JobIdentifier) SideRandomNumber() uint32

func (JobIdentifier) String

func (id JobIdentifier) String() string

func (JobIdentifier) TemplateCounter

func (id JobIdentifier) TemplateCounter() uint64

func (JobIdentifier) TemplateId

func (id JobIdentifier) TemplateId() types.Hash

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(jobId JobIdentifier, nonce uint32) []byte

GetJobBlob Gets old job data based on returned id

type MiningMempool added in v3.4.0

type MiningMempool swiss.Map[types.Hash, *mempool.Entry]

func (*MiningMempool) Add added in v3.4.0

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

Add Inserts a transaction into the mempool.

func (*MiningMempool) Select added in v3.4.0

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

func (*MiningMempool) Swap added in v3.4.0

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
	// contains filtered or unexported fields
}

func NewServer

func NewServer(s *sidechain.SideChain, submitFunc func(block *sidechain.PoolBlock) 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) error

func (*Server) SendTemplate

func (s *Server) SendTemplate(c *Client) (err error)

func (*Server) SendTemplateResponse

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

func (*Server) Update

func (s *Server) Update()

type ShuffleMapping added in v3.11.0

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 added in v3.11.0

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

type ShuffleMappingIndices added in v3.11.0

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

	// TemplateIdOffset offset of a types.Hash
	TemplateIdOffset int

	// TransactionsOffset Start of transactions section
	TransactionsOffset int

	// TemplateSideDataOffset Start of side data section
	TemplateSideDataOffset int

	// TemplateExtraBufferOffset offset of 4*uint32
	TemplateExtraBufferOffset int

	MainHeight uint64
	MainParent types.Hash

	SideHeight     uint64
	SideParent     types.Hash
	SideDifficulty types.Difficulty

	MerkleTreeMainBranch []types.Hash
}

func TemplateFromPoolBlock

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

func (*Template) Blob

func (tpl *Template) Blob(preAllocatedBuffer []byte, nonce, extraNonce, sideRandomNumber, sideExtraNonce uint32, templateId types.Hash) []byte

func (*Template) CoinbaseBlob

func (tpl *Template) CoinbaseBlob(preAllocatedBuffer []byte, extraNonce uint32, templateId 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, templateId types.Hash, result *types.Hash)

func (*Template) HashingBlob

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

func (*Template) HashingBlobBufferLength

func (tpl *Template) HashingBlobBufferLength() int

func (*Template) MainBlock added in v3.11.0

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

func (*Template) ShareVersion added in v3.4.0

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

func (*Template) SideData added in v3.11.0

func (tpl *Template) SideData(consensus *sidechain.Consensus) (d sidechain.SideData, err error)

func (*Template) TemplateId

func (tpl *Template) TemplateId(hasher *sha3.HasherState, preAllocatedBuffer []byte, consensus *sidechain.Consensus, sideRandomNumber, sideExtraNonce uint32, result *types.Hash)

func (*Template) Timestamp

func (tpl *Template) Timestamp() uint64

func (*Template) Write

func (tpl *Template) Write(writer io.Writer, nonce, extraNonce, sideRandomNumber, sideExtraNonce uint32, templateId types.Hash) error

Jump to

Keyboard shortcuts

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