lib

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: ISC Imports: 25 Imported by: 0

Documentation

Overview

* Qitmeer james

Copyright (c) 2019 The qitmeer developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2019 The qitmeer developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2019 The qitmeer developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	//every mode position
	POWTYPE_START = 108
	POWTYPE_END   = 109
	TIMESTART     = 104
	TIMEEND       = 108
	NONCESTART    = 109
	NONCEEND      = 117
	NBITSTART     = 100
	NBITEND       = 104
	STATESTART    = 68
	STATEEND      = 100
	MERKLESTART   = 36
	MERKLEEND     = 68
	PRESTART      = 4
	PREEND        = 36
	TXEND         = 68
	VERSIONSTART  = 0
	VERSIONEND    = 4
)
View Source
const (
	POW_MEER_CRYPTO = "meer_crypto"
)

Variables

View Source
var ErrLimitWork = fmt.Errorf("Submission interval Limited")
View Source
var ErrSameWork = fmt.Errorf("Same work, Had Submitted!")
View Source
var ErrStratumStaleWork = fmt.Errorf("Stale work, throwing away")

ErrStratumStaleWork indicates that the work to send to the pool was stale.

Functions

func BlockComputePoolData

func BlockComputePoolData(b []byte) []byte

Header structure of assembly pool

func BlockDataWithProof

func BlockDataWithProof(h *types.BlockHeader) []byte

qitmeer block header

func ReadBlockHeader

func ReadBlockHeader(b []byte, bh *types.BlockHeader) error

readBlockHeader reads a block header from io reader. See Deserialize for decoding block headers stored to disk, such as in a database, as opposed to decoding from the type. TODO, redefine the protocol version and storage

Types

type BasicReply

type BasicReply struct {
	ID     interface{} `json:"id"`
	Error  interface{} `json:"error,omitempty"`
	Result bool        `json:"result"`
}

Basic reply is a reply type for any of the simple messages.

type BlockHeader

type BlockHeader struct {
	sync.Mutex
	// block version
	Version uint32 `json:"version"`
	// The merkle root of the previous parent blocks (the dag layer)
	ParentRoot hash.Hash `json:"previousblockhash"`
	// The merkle root of the tx tree  (tx of the block)
	// included Witness here instead of the separated witness commitment
	TxRoot hash.Hash `json:"tx_root"`
	// The Multiset hash of UTXO set or(?) merkle range/path or(?) tire tree root
	// can all of the state data (stake, receipt, utxo) in state root?
	StateRoot hash.Hash `json:"stateroot"`

	// block number
	Height     uint64 `json:"height"`
	Difficulty uint64 `json:"difficulty"`

	// TimeStamp
	Curtime uint32 `json:"curtime"`

	Pow pow.IPow

	// Nonce
	Target string `json:"target"`

	PowDiffReference json.PowDiffReference `json:"pow_diff_reference"`

	Coinbasevalue   int64 `json:"coinbasevalue"`
	HasCoinbasePack bool
	TotalFee        uint64

	BlockFeesMap    map[int]int64 `json:"block_fees_map"`
	NodeInfo        string        `json:"nodeinfo"`
	CoinbaseVersion string        `json:"coinbase_version"`
	GBTID           int64
	WorkData        []byte
	// contains filtered or unexported fields
}

qitmeer block header

func (*BlockHeader) SetTxs

func (h *BlockHeader) SetTxs(transactions []*types.Tx)

type MeerCrypto

type MeerCrypto struct {
	core.Device
	Work *QitmeerWork
	// contains filtered or unexported fields
}

func (*MeerCrypto) GetDiff

func (this *MeerCrypto) GetDiff() float64

func (*MeerCrypto) InitDevice

func (this *MeerCrypto) InitDevice()

func (*MeerCrypto) Mine

func (this *MeerCrypto) Mine(wg *sync.WaitGroup)

func (*MeerCrypto) Status

func (this *MeerCrypto) Status(wg *sync.WaitGroup)

func (*MeerCrypto) Update

func (this *MeerCrypto) Update()

type MinerBlockData

type MinerBlockData struct {
	HeaderData  []byte
	TargetDiff  *big.Int
	Target2     []byte
	Exnonce2    string
	JobID       string
	HeaderBlock *types.BlockHeader
	Height      uint64
}

func (*MinerBlockData) BlockData

func (this *MinerBlockData) BlockData() []byte

func (*MinerBlockData) PackagePoolHeader

func (this *MinerBlockData) PackagePoolHeader(work *QitmeerWork, powType pow.PowType)

the pool work submit structure

func (*MinerBlockData) PackageRpcHeader

func (this *MinerBlockData) PackageRpcHeader(work *QitmeerWork)

the solo work submit structure

type NotifyRes

type NotifyRes struct {
	JobID          string
	Hash           string
	GenTX1         string
	GenTX2         string
	MerkleBranches []string
	BlockVersion   string
	Nbits          string
	Ntime          string
	CleanJobs      bool
	StateRoot      string
	Height         int64
	CB3            string
	CB4            string
}

NotifyRes models the json from a mining.notify message.

type NotifyWork

type NotifyWork struct {
	Clean             bool
	Target            *big.Int
	ExtraNonce1       string
	ExtraNonce2       string
	ExtraNonce2Length float64
	Nonce2            uint32
	CB1               string
	CB2               string
	CB3               string
	CB4               string
	Height            int64
	NtimeDelta        int64
	JobID             string
	Hash              string
	Nbits             string
	Ntime             string
	Version           string
	NewWork           bool
	StateRoot         string
	MerkleBranches    []string
	WorkData          []byte
	LatestJobTime     uint64
	PowType           pow.PowType
	CuckooProof       [169]byte
}

NotifyWork holds all the info recieved from a mining.notify message along with the Work data generate from it.

func (*NotifyWork) PrepQitmeerWork

func (s *NotifyWork) PrepQitmeerWork() []byte

func (*NotifyWork) PrepWork

func (s *NotifyWork) PrepWork() error

PrepWork converts the stratum notify to getwork style data for mining.

type PendingBlock

type PendingBlock struct {
	CoinbaseHash string
	Height       uint64
	BlockHash    string
}

type QitmeerRobot

type QitmeerRobot struct {
	core.MinerRobot
	Work                 QitmeerWork
	NeedGBT              chan struct{}
	Devices              []core.BaseDevice
	Stratu               *QitmeerStratum
	StratuFee            *QitmeerStratum
	AllTransactionsCount int64
	PendingBlocks        map[string]PendingBlock
	SubmitLock           sync.Mutex
	WsClient             *client.Client
}

func (*QitmeerRobot) GetPow

func (this *QitmeerRobot) GetPow(i int, ctx context.Context, uart_path string, allCount uint64) core.BaseDevice

func (*QitmeerRobot) HandlePendingBlocks

func (this *QitmeerRobot) HandlePendingBlocks()

stats the submit result

func (*QitmeerRobot) InitDevice

func (this *QitmeerRobot) InitDevice(ctx context.Context)

func (*QitmeerRobot) ListenWork

func (this *QitmeerRobot) ListenWork()

ListenWork

func (*QitmeerRobot) NotifyWork

func (this *QitmeerRobot) NotifyWork(r bool)

func (*QitmeerRobot) Run

func (this *QitmeerRobot) Run(ctx context.Context)

runing

func (*QitmeerRobot) Status

func (this *QitmeerRobot) Status()

stats the submit result

func (*QitmeerRobot) SubmitWork

func (this *QitmeerRobot) SubmitWork()

ListenWork

func (*QitmeerRobot) WsConnect

func (this *QitmeerRobot) WsConnect()

type QitmeerStratum

type QitmeerStratum struct {
	core.Stratum
	Target   *big.Int
	Diff     float64
	PoolWork NotifyWork
}

func (*QitmeerStratum) CalcBasePowLimit

func (s *QitmeerStratum) CalcBasePowLimit() *big.Int

func (*QitmeerStratum) HandleReply

func (this *QitmeerStratum) HandleReply()

func (*QitmeerStratum) HandleSubmitReply

func (s *QitmeerStratum) HandleSubmitReply(resp interface{})

func (*QitmeerStratum) PrepSubmit

func (s *QitmeerStratum) PrepSubmit(data []byte, jobID string, ExtraNonce2 string) (Submit, error)

func (*QitmeerStratum) Unmarshal

func (s *QitmeerStratum) Unmarshal(blob []byte) (interface{}, error)

Unmarshal provides a json unmarshaler for the commands. I'm sure a lot of this can be generalized but the json we deal with is pretty yucky.

type QitmeerWork

type QitmeerWork struct {
	core.Work
	Block    *BlockHeader
	PoolWork NotifyWork

	StartWork   bool
	ForceUpdate bool
	Ing         bool
	WorkLock    sync.Mutex
	WsClient    *client.Client
	LastSubmit  time.Time
	GbtID       int64
	SubmitID    int64
	// contains filtered or unexported fields
}

func (*QitmeerWork) BuildBlock added in v1.2.0

func (this *QitmeerWork) BuildBlock(header *types.BlockHeader) bool

BuildBlock

func (*QitmeerWork) Get

func (this *QitmeerWork) Get() bool

GetBlockTemplate

func (*QitmeerWork) GetPowType

func (this *QitmeerWork) GetPowType() pow.PowType

func (*QitmeerWork) PoolGet

func (this *QitmeerWork) PoolGet() bool

pool get work

func (*QitmeerWork) PoolSubmit

func (this *QitmeerWork) PoolSubmit(subm string) error

pool submit work

func (*QitmeerWork) Submit

func (this *QitmeerWork) Submit(header *types.BlockHeader, gbtID string) (string, int, error)

submit

type StratErr

type StratErr struct {
	ErrNum uint64
	ErrStr string
	Result *json.RawMessage `json:"result,omitempty"`
}

StratErr is the basic error type (a number and a string) sent by the stratum server.

type StratumMsg

type StratumMsg struct {
	Method string `json:"method"`
	// Need to make generic.
	Params []string    `json:"params"`
	ID     interface{} `json:"id"`
}

StratumMsg is the basic message object from stratum.

type StratumRsp

type StratumRsp struct {
	Method string `json:"method"`
	// Need to make generic.
	ID     interface{}      `json:"id"`
	Error  StratErr         `json:"error,omitempty"`
	Result *json.RawMessage `json:"result,omitempty"`
}

StratumRsp is the basic response type from stratum.

type Submit

type Submit struct {
	Params []string    `json:"params"`
	ID     interface{} `json:"id"`
	Method string      `json:"method"`
}

Submit models a submission message.

type SubscribeReply

type SubscribeReply struct {
	SubscribeID       string
	ExtraNonce1       string
	ExtraNonce2Length float64
}

SubscribeReply models the server response to a subscribe message.

Jump to

Keyboard shortcuts

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