miner

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: ISC Imports: 25 Imported by: 0

README

Solo Mining

Get BlockTemplate
curl -X POST \
  http://47.244.17.119:2234/ \
  -H 'authorization: Basic dGVzdDp0ZXN0' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: a6702d2a-9deb-4d42-6fbd-51dfb3173001' \
  -d '{
  "method":"getBlockTemplate",
  "version":"2.0",
  "params":[["coinbasetxn","coinbasevalue"],8],
  "id":1
}'

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "stateroot": "0000000000000000000000000000000000000000000000000000000000000000",
        "curtime": 1608036734,
        "height": 1,
        "blues": 1,
        "previousblockhash": "45512392e69843f98182582f4279c1745074633fe7a00fb8eb43ac143d23a9a7",
        "sigoplimit": 80000,
        "sizelimit": 1048576,
        "weightlimit": 4000000,
        "parents": [
            {
                "data": "a7a9233d14ac43ebb80fa0e73f63745074c179422f588281f94398e692235145",
                "hash": "45512392e69843f98182582f4279c1745074633fe7a00fb8eb43ac143d23a9a7"
            }
        ],
        "transactions": [],
        "version": 18,
        "coinbaseaux": {
            "flags": "092f7169746d6565722f"
        },
        "coinbasevalue": 12000000000,
        "longpollid": "45512392e69843f98182582f4279c1745074633fe7a00fb8eb43ac143d23a9a7-1608036734",
        "pow_diff_reference": {
            "nbits": "2003ffff",
            "target": "03ffff0000000000000000000000000000000000000000000000000000000000"
        },
        "maxtime": 1608037094,
        "mintime": 1547735582,
        "mutable": [
            "time",
            "transactions/add",
            "prevblock",
            "coinbase/append"
        ],
        "noncerange": "00000000ffffffff",
        "capabilities": [
            "proposal"
        ],
        "workdata": "12000000a7a9233d14ac43ebb80fa0e73f63745074c179422f588281f94398e6922351452a56f96d4f7b037fee75b15cf9744e0b77d29ed308e795e965314eb2baf10cda0000000000000000000000000000000000000000000000000000000000000000ffff03207eb1d85f0800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a7a9233d14ac43ebb80fa0e73f63745074c179422f588281f94398e692235145010100000001eb5552605a1187746fe66534c3720e3aa7bb8bfc3f09f90c1c1ac2305593fe64ffffffffffffffff01007841cb02000000015100000000000000007eb1d85f0114510837a5726fec66c722092f7169746d6565722f"
    }
}
Use workdata and calc nonce , replace the 8 bytes nonce of header
nonce position is 109-117
header hash is MeerXKeccakV1(workdata[:117])
pow_diff_reference.target is the target hash
submit work
cpu solo golang code
submit
curl -X POST \
  http://47.244.17.119:2234/ \
  -H 'authorization: Basic dGVzdDp0ZXN0' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: 6b997b0f-a45f-9c4c-9d2d-224f71d79adc' \
  -d '{
  "method":"submitBlock",
  "version":"2.0",
  "params":["12000000a7a9233d14ac43ebb80fa0e73f63745074c179422f588281f94398e6922351452a56f96d4f7b037fee75b15cf9744e0b77d29ed308e795e965314eb2baf10cda0000000000000000000000000000000000000000000000000000000000000000ffff03207eb1d85f0800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a7a9233d14ac43ebb80fa0e73f63745074c179422f588281f94398e692235145010100000001eb5552605a1187746fe66534c3720e3aa7bb8bfc3f09f90c1c1ac2305593fe64ffffffffffffffff01007841cb02000000015100000000000000007eb1d85f0114510837a5726fec66c722092f7169746d6565722f"],
  "id":1
}
'
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": "0c034550cf7aa78c76e17fb4d79e94c9f687fb9aa57c6dd00c000000cf7ad290",
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UseLogger

func UseLogger(logger l.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type CPUMiner

type CPUMiner struct {
	sync.Mutex
	// contains filtered or unexported fields
}

CPUMiner provides facilities for solving blocks (mining) using the CPU in a concurrency-safe manner. It consists of two main goroutines -- a speed monitor and a controller for worker goroutines which generate and solve blocks. The number of goroutines can be set via the SetMaxGoRoutines function, but the default is based on the number of processor cores in the system which is typically sufficient.

func NewCPUMiner

func NewCPUMiner(cfg *config.Config, par *params.Params, policy *mining.Policy,
	cache *txscript.SigCache,
	source mining.TxSource, tsource blockchain.MedianTimeSource, blkMgr *blkmgr.BlockManager, numWorkers uint32) *CPUMiner

newCPUMiner returns a new instance of a CPU miner for the provided server. Use Start to begin the mining process. See the documentation for CPUMiner type for more details.

func (*CPUMiner) APIs

func (c *CPUMiner) APIs() []rpc.API

func (*CPUMiner) GenerateBlockByParents

func (m *CPUMiner) GenerateBlockByParents(parents []*hash.Hash) (*hash.Hash, error)

func (*CPUMiner) GenerateNBlocks

func (m *CPUMiner) GenerateNBlocks(n uint32, powType pow.PowType) ([]*hash.Hash, error)

GenerateNBlocks generates the requested number of blocks. It is self contained in that it creates block templates and attempts to solve them while detecting when it is performing stale work and reacting accordingly by generating a new block template. When a block is solved, it is submitted. The function returns a list of the hashes of generated blocks.

func (*CPUMiner) GetPolicy

func (m *CPUMiner) GetPolicy() *mining.Policy

return policy

func (*CPUMiner) GetSigCache

func (m *CPUMiner) GetSigCache() *txscript.SigCache

return sig cache

func (*CPUMiner) GetTimeSource

func (m *CPUMiner) GetTimeSource() blockchain.MedianTimeSource

return time source

func (*CPUMiner) HashesPerSecond

func (m *CPUMiner) HashesPerSecond() float64

HashesPerSecond returns the number of hashes per second the mining process is performing. 0 is returned if the miner is not currently running.

This function is safe for concurrent access.

func (*CPUMiner) IsMining

func (m *CPUMiner) IsMining() bool

IsMining returns whether or not the CPU miner has been started and is therefore currenting mining.

This function is safe for concurrent access.

func (*CPUMiner) NumWorkers

func (m *CPUMiner) NumWorkers() int32

NumWorkers returns the number of workers which are running to solve blocks.

This function is safe for concurrent access.

func (*CPUMiner) SetNumWorkers

func (m *CPUMiner) SetNumWorkers(numWorkers int32)

SetNumWorkers sets the number of workers to create which solve blocks. Any negative values will cause a default number of workers to be used which is based on the number of processor cores in the system. A value of 0 will cause all CPU mining to be stopped.

This function is safe for concurrent access.

func (*CPUMiner) Start

func (m *CPUMiner) Start()

Start begins the CPU mining process as well as the speed monitor used to track hashing metrics. Calling this function when the CPU miner has already been started will have no effect.

This function is safe for concurrent access.

func (*CPUMiner) Stop

func (m *CPUMiner) Stop()

Stop gracefully stops the mining process by signalling all workers, and the speed monitor to quit. Calling this function when the CPU miner has not already been started will have no effect.

This function is safe for concurrent access.

type PrivateMinerAPI

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

PrivateMinerAPI provides private RPC methods to control the miner.

func NewPrivateMinerAPI

func NewPrivateMinerAPI(c *CPUMiner) *PrivateMinerAPI

func (*PrivateMinerAPI) Generate

func (api *PrivateMinerAPI) Generate(numBlocks uint32, powType pow.PowType) ([]string, error)

type PublicMinerAPI

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

func NewPublicMinerAPI

func NewPublicMinerAPI(c *CPUMiner) *PublicMinerAPI

func (*PublicMinerAPI) GetBlockTemplate

func (api *PublicMinerAPI) GetBlockTemplate(capabilities []string, powType byte) (interface{}, error)

func (api *PublicMinerAPI) GetBlockTemplate(request *mining.TemplateRequest) (interface{}, error){

func (*PublicMinerAPI) SubmitBlock

func (api *PublicMinerAPI) SubmitBlock(hexBlock string) (interface{}, error)

LL Attempts to submit new block to network. See https://en.bitcoin.it/wiki/BIP_0022 for full specification

Jump to

Keyboard shortcuts

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