miner

package module
v0.0.0-...-847d463 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2019 License: MIT Imports: 18 Imported by: 0

README

To build

cd opencl
mkdir build
cd build
cmake ..
make
sudo make install
cd ../../miner
go build
cp ../opencl/cruzbit.cl .
LD_LIBRARY_PATH=/usr/local/lib ./miner -pubkey <your public key> -peer <pool address>

This is not very polished at the moment. Use at your own risk!

Documentation

Index

Constants

View Source
const OPENCL_ENABLED = true
View Source
const Protocol = "cruzbit.1"

Protocol is the name of this version of the cruzbit peer protocol.

Variables

This section is empty.

Functions

func OpenCLInit

func OpenCLInit() int

OpenCLInit is called on startup.

func OpenCLMinerMine

func OpenCLMinerMine(minerNum int, startNonce int64) int64

OpenCLMinerMine is called on every solution attempt by a miner goroutine. It will perform N hashing attempts where N is the maximum number of threads your device is capable of executing. Returns a solving nonce; otherwise 0x7FFFFFFFFFFFFFFF.

func OpenCLMinerUpdate

func OpenCLMinerUpdate(minerNum int, headerBytes []byte, headerBytesLen, startNonceOffset, endNonceOffset int, target cruzbit.BlockID) int64

OpenCLMinerUpdate is called by a miner goroutine when the underlying header changes.

Types

type BlockHeaderHasher

type BlockHeaderHasher struct {
	// contains filtered or unexported fields
}

BlockHeaderHasher is used to more efficiently hash JSON serialized block headers while mining.

func NewBlockHeaderHasher

func NewBlockHeaderHasher() *BlockHeaderHasher

NewBlockHeaderHasher returns a newly initialized BlockHeaderHasher

func (*BlockHeaderHasher) Update

func (h *BlockHeaderHasher) Update(minerNum int, header *cruzbit.BlockHeader, target cruzbit.BlockID) (*big.Int, int64)

Update is called everytime the header is updated and the caller wants its new hash value/ID.

type GetWorkMessage

type GetWorkMessage struct {
	PublicKeys []ed25519.PublicKey `json:"public_keys"`
	Memo       string              `json:"memo,omitempty"`
}

GetWorkMessage is used by a mining peer to request mining work. Type: "get_work"

type HashWithRead

type HashWithRead interface {
	hash.Hash

	// the sha3 state objects aren't exported from stdlib but some of their methods like Read are.
	// we can get the sum without the clone done by Sum which saves us a malloc in the fast path
	Read(out []byte) (n int, err error)
}

HashWithRead extends hash.Hash to provide a Read interface.

type Message

type Message struct {
	Type string      `json:"type"`
	Body interface{} `json:"body,omitempty"`
}

Message is a message frame for all messages in the cruzbit.1 protocol.

type Miner

type Miner struct {
	// contains filtered or unexported fields
}

Miner tries to mine a new tip block.

func NewMiner

func NewMiner(genesisID cruzbit.BlockID, peerAddr string, pubKeys []ed25519.PublicKey, num int) *Miner

NewMiner returns a new Miner instance.

func (*Miner) Run

func (m *Miner) Run()

Run executes the miner's main loop in its own goroutine.

func (*Miner) Shutdown

func (m *Miner) Shutdown()

Shutdown stops the miner synchronously.

type Peer

type Peer struct {
	// contains filtered or unexported fields
}

Peer is a client in the cruzbit network providing us with mining work.

func NewPeer

func NewPeer(genesisID cruzbit.BlockID, workChan chan<- WorkMessage, submitChan <-chan SubmitWorkMessage) *Peer

NewPeer returns a new instance of a peer.

func (*Peer) Connect

func (p *Peer) Connect(ctx context.Context, addr string, pubKeys []ed25519.PublicKey) (int, error)

Connect connects outbound to a peer.

func (*Peer) Run

func (p *Peer) Run()

Run executes the peer's main loop in its own goroutine. It manages reading and writing to the peer's WebSocket and facilitating the protocol.

func (*Peer) Shutdown

func (p *Peer) Shutdown()

Shutdown is called to shutdown the underlying WebSocket synchronously.

type SubmitWorkMessage

type SubmitWorkMessage struct {
	WorkID int32                `json:"work_id"`
	Header *cruzbit.BlockHeader `json:"header"`
}

SubmitWorkMessage is used by a mining peer to submit a potential solution to the client. Type: "submit_work"

type SubmitWorkResultMessage

type SubmitWorkResultMessage struct {
	WorkID int32  `json:"work_id"`
	Error  string `json:"error,omitempty"`
}

SubmitWorkResultMessage is used to inform a mining peer of the result of its work. Type: "submit_work_result"

type WorkMessage

type WorkMessage struct {
	WorkID  int32                `json:"work_id"`
	Header  *cruzbit.BlockHeader `json:"header"`
	MinTime int64                `json:"min_time"`
	Target  *cruzbit.BlockID     `json:"target,omitempty"` // optional pool target
	Error   string               `json:"error,omitempty"`
}

WorkMessage is used by a client to send work to perform to a mining peer. The timestamp and nonce in the header can be manipulated by the mining peer. It is the mining peer's responsibility to ensure the timestamp is not set below the minimum timestamp and that the nonce does not exceed MAX_NUMBER (2^53-1). Type: "work"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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