message

package
v0.0.0-...-9b1746c Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PowMasterMsgSize = blocks.BlockHeadSize + blocks.BlockMetaSizeV1 + 1 + 4 + 4

	PowMasterMsgStatusContinue                          fields.VarUint1 = 0
	PowMasterMsgStatusSuccess                           fields.VarUint1 = 1
	PowMasterMsgStatusStop                              fields.VarUint1 = 2
	PowMasterMsgStatusMostPowerHash                     fields.VarUint1 = 3
	PowMasterMsgStatusMostPowerHashAndRequestNextMining fields.VarUint1 = 4
)
View Source
const (
	PoolAndWorkerAgreementVersionNumber uint16 = 1 // 通信协议版本号
	// 挖矿端类型
	WorkerKindOfBlank uint8 = 0
	WorkerKindOfCPU   uint8 = 1 // CPU
	WorkerKindOfGPU   uint8 = 2 // GPU 显卡挖矿

)

type

View Source
const (
	MsgErrorRetCodeSuccess                   uint16 = 0 // OK
	MsgErrorRetCodeConnectReadSengErr        uint16 = 1 // 消息发送或读取错误
	MsgErrorRetCodeAgreementVersionNumberErr uint16 = 2 // 连接数太多
	MsgErrorRetCodeTooManyConnects           uint16 = 3 // 连接数太多
)

错误响应

View Source
const (
	//  0 为错误
	MinerWorkMsgTypeWorkerRegistration uint16 = 1 // worker 注册
	MinerWorkMsgTypeServerResponse     uint16 = 2 // server 响应
	MinerWorkMsgTypeMiningBlock        uint16 = 3 // 矿池发给矿工的区块挖矿信息
	MinerWorkMsgTypeReportMiningResult uint16 = 4 // 挖掘结果上报
)

msg

View Source
const MsgWorkerRegistrationSize = 2 + 1 + 21
View Source
const MsgWorkerServerResponseSize = 2 + 1

Variables

This section is empty.

Functions

func MsgReadFromTcpConn

func MsgReadFromTcpConn(conn *net.TCPConn, mustlen uint32) (msgty uint16, msgbody []byte, err error)

收取消息 mustlen = 消息必须长度

func MsgSendToTcpConn

func MsgSendToTcpConn(conn *net.TCPConn, msgty uint16, msgbody []byte) (err error)

发送消息

func SendServerResponse

func SendServerResponse(conn *net.TCPConn, resmsg *MsgServerResponse)

服务端响应

func SendServerResponseByRetCode

func SendServerResponseByRetCode(conn *net.TCPConn, retcode uint16)

服务端响应

Types

type MsgPendingMiningBlockStuff

type MsgPendingMiningBlockStuff struct {
	BlockHeadMeta                          interfaces.Block                     // 区块的 head 和 meta
	CoinbaseTx                             *transactions.Transaction_0_Coinbase // coinbase 交易
	MrklRelatedTreeListForCoinbaseTxModify []fields.Hash                        // 默克尔树关联哈希
	// contains filtered or unexported fields
}

func CreatePendingMiningBlockStuffByBlock

func CreatePendingMiningBlockStuffByBlock(block interfaces.Block) (*MsgPendingMiningBlockStuff, error)

创建 mining stuff

func (MsgPendingMiningBlockStuff) CalculateBlockHashByBothNonce

func (m MsgPendingMiningBlockStuff) CalculateBlockHashByBothNonce(headNonce fields.Bytes4, coinbaseNonce fields.Bytes32, retcopy bool) (*MsgPendingMiningBlockStuff, fields.Hash)

通过设置nonce值计算 区块哈希

func (MsgPendingMiningBlockStuff) CalculateBlockHashByMiningResult

func (m MsgPendingMiningBlockStuff) CalculateBlockHashByMiningResult(result *MsgReportMiningResult, retcopy bool) (*MsgPendingMiningBlockStuff, fields.Hash)

通过设置nonce值计算 区块哈希

func (MsgPendingMiningBlockStuff) CopyForMiningByRandomSetCoinbaseNonce

func (m MsgPendingMiningBlockStuff) CopyForMiningByRandomSetCoinbaseNonce() interfaces.PowWorkerMiningStuffItem

func (MsgPendingMiningBlockStuff) GetCoinbaseNonce

func (m MsgPendingMiningBlockStuff) GetCoinbaseNonce() []byte

func (MsgPendingMiningBlockStuff) GetHeadMetaBlock

func (m MsgPendingMiningBlockStuff) GetHeadMetaBlock() interfaces.Block

func (MsgPendingMiningBlockStuff) GetHeadNonce

func (m MsgPendingMiningBlockStuff) GetHeadNonce() []byte

func (MsgPendingMiningBlockStuff) GetMiningSuccessed

func (m MsgPendingMiningBlockStuff) GetMiningSuccessed() bool

func (*MsgPendingMiningBlockStuff) Parse

func (m *MsgPendingMiningBlockStuff) Parse(buf []byte, seek uint32) (uint32, error)

反序列化

func (MsgPendingMiningBlockStuff) Serialize

func (m MsgPendingMiningBlockStuff) Serialize() []byte

序列化

func (MsgPendingMiningBlockStuff) SetHeadNonce

func (m MsgPendingMiningBlockStuff) SetHeadNonce(nonce []byte)

func (*MsgPendingMiningBlockStuff) SetMiningSuccessed

func (m *MsgPendingMiningBlockStuff) SetMiningSuccessed(ok bool)

type MsgReportMiningResult

type MsgReportMiningResult struct {
	MintSuccessed fields.Bool        // 挖掘成功 或者 报告算力
	BlockHeight   fields.BlockHeight // 挖掘的区块高度
	HeadNonce     fields.Bytes4      // block head nonce
	CoinbaseNonce fields.Bytes32     // coinbase nonce
}

func (*MsgReportMiningResult) Parse

func (m *MsgReportMiningResult) Parse(buf []byte, seek uint32) (uint32, error)

反序列化

func (MsgReportMiningResult) Serialize

func (m MsgReportMiningResult) Serialize() []byte

序列化

type MsgServerResponse

type MsgServerResponse struct {
	RetCode                  fields.VarUint2 // 响应码: 0. 正确可连接 1.版本不匹配   2. 连接数过多   等等
	AcceptHashrateStatistics fields.Bool     // 是否接受算力统计
}

func HandleConnectToServer

func HandleConnectToServer(conn *net.TCPConn, rewardaddr *fields.Address) (*MsgServerResponse, error)

连接到服务器

func (*MsgServerResponse) Parse

func (m *MsgServerResponse) Parse(buf []byte, seek uint32) (uint32, error)

反序列化

func (MsgServerResponse) Serialize

func (m MsgServerResponse) Serialize() []byte

序列化

type MsgWorkerRegistration

type MsgWorkerRegistration struct {
	PoolAndWorkerAgreementVersionNumber fields.VarUint2 // 版本号
	WorkerKind                          fields.VarUint1 // 挖矿端类型
	RewardAddress                       fields.Address  // 收取奖励地址
}

func HandleConnectToClient

func HandleConnectToClient(conn *net.TCPConn, isAcceptHashrateStatistics bool) (*MsgWorkerRegistration, error)

连接到客户端

func (*MsgWorkerRegistration) Parse

func (m *MsgWorkerRegistration) Parse(buf []byte, seek uint32) (uint32, error)

反序列化

func (MsgWorkerRegistration) Serialize

func (m MsgWorkerRegistration) Serialize() []byte

序列化

type PowDeviceWorker

type PowDeviceWorker interface {
	Excavate(inputblockheadmeta interfaces.Block, outputCh chan PowMasterMsg)

	SetCoinbaseMsgNum(coinbaseMsgNum uint32)

	StopMining()
}

type PowMasterMsg

type PowMasterMsg struct {
	Status         fields.VarUint1 //
	CoinbaseMsgNum fields.VarUint4
	NonceBytes     fields.Bytes4
	BlockHeadMeta  interfaces.Block
}

func NewPowMasterMsg

func NewPowMasterMsg() *PowMasterMsg

func (*PowMasterMsg) Parse

func (p *PowMasterMsg) Parse(buf []byte, seek uint32) (uint32, error)

func (*PowMasterMsg) Serialize

func (p *PowMasterMsg) Serialize() ([]byte, error)

func (*PowMasterMsg) Size

func (p *PowMasterMsg) Size() uint32

Jump to

Keyboard shortcuts

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