miner

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2022 License: ISC Imports: 33 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",
}

How to use extra nonce by CoinbaseFlagsDynamic in remote GBT ?

miner call RPC [ GetRemoteGBT(powType, true) ]=> QNG Node =>[return json :headerhex,coinbasetxhex,txmerklepath,txwitnessroot]

...
miner call function mining.CalculateTransactionsRoot(coinbasetxhex,txmerklepath,txwitnessroot,YourExtraNonce) to update blockHeader.TxRoot 
...

miner call RPC [ SubmitBlockHeader(YouerHeaderhex,YourExtraNonce) ] => QNG Node

Documentation

Index

Constants

View Source
const (
	CPUWorkerType    = "CPU_Worker"
	GBTWorkerType    = "GBT_Worker"
	RemoteWorkerType = "Remote_Worker"
	PoolWorkerType   = "Pool_Worker"
)
View Source
const (

	// This is the timeout for HTTP requests to notify external miners.
	NotifyURLTimeout = 1 * time.Second
)
View Source
const (
	SubmitInterval = time.Second
)

Variables

This section is empty.

Functions

func IsEqualForMiner

func IsEqualForMiner(header *types.BlockHeader, other *types.BlockHeader) bool

func UseLogger

func UseLogger(logger l.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type BlockChainChangeMsg

type BlockChainChangeMsg struct {
}

type CPUMiningGenerateMsg

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

type CPUWorker

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

func NewCPUWorker

func NewCPUWorker(miner *Miner) *CPUWorker

func (*CPUWorker) GetType

func (w *CPUWorker) GetType() string

func (*CPUWorker) HashesPerSecond

func (w *CPUWorker) 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 (*CPUWorker) IsRunning

func (w *CPUWorker) IsRunning() bool

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

This function is safe for concurrent access.

func (*CPUWorker) NumWorkers

func (w *CPUWorker) NumWorkers() int32

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

This function is safe for concurrent access.

func (*CPUWorker) SetNumWorkers

func (w *CPUWorker) 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 (*CPUWorker) Start

func (w *CPUWorker) Start() error

func (*CPUWorker) Stop

func (w *CPUWorker) Stop()

func (*CPUWorker) Update

func (w *CPUWorker) Update()

type GBTMiningMsg

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

type GBTWorker

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

func NewGBTWorker

func NewGBTWorker(miner *Miner) *GBTWorker

func (*GBTWorker) GetRequest

func (w *GBTWorker) GetRequest(request *json.TemplateRequest, reply chan *gbtResponse)

func (*GBTWorker) GetType

func (w *GBTWorker) GetType() string

func (*GBTWorker) IsRunning

func (w *GBTWorker) IsRunning() bool

func (*GBTWorker) Start

func (w *GBTWorker) Start() error

func (*GBTWorker) Stop

func (w *GBTWorker) Stop()

func (*GBTWorker) Update

func (w *GBTWorker) Update()

type IWorker

type IWorker interface {
	GetType() string
	Start() error
	Stop()
	IsRunning() bool
	Update()
}

type MempoolChangeMsg

type MempoolChangeMsg struct {
}

type Miner

type Miner struct {
	service.Service

	sync.Mutex

	RpcSer *rpc.RpcServer
	// contains filtered or unexported fields
}

Miner creates blocks and searches for proof-of-work values.

func NewMiner

func NewMiner(cfg *config.Config, policy *mining.Policy,
	sigCache *txscript.SigCache,
	txSource mining.TxSource, tsource blockchain.MedianTimeSource, blkMgr *blkmgr.BlockManager, events *event.Feed) *Miner

func (*Miner) APIs

func (m *Miner) APIs() []api.API

func (*Miner) BlockChainChange

func (m *Miner) BlockChainChange()

func (*Miner) CPUMiningGenerate

func (m *Miner) CPUMiningGenerate(discreteNum int, block chan *hash.Hash, powType pow.PowType) error

func (*Miner) CanMining

func (m *Miner) CanMining() error

func (*Miner) GBTMining

func (m *Miner) GBTMining(request *json.TemplateRequest, reply chan *gbtResponse) error

func (*Miner) GetCoinbasePKAddress

func (m *Miner) GetCoinbasePKAddress() *address.SecpPubKeyAddress

func (*Miner) IsEnable

func (m *Miner) IsEnable() bool

func (*Miner) MempoolChange

func (m *Miner) MempoolChange()

func (*Miner) RemoteMining

func (m *Miner) RemoteMining(powType pow.PowType, coinbaseFlags mining.CoinbaseFlags, reply chan *gbtResponse) error

func (*Miner) Start

func (m *Miner) Start() error

func (*Miner) StartCPUMining

func (m *Miner) StartCPUMining()

func (*Miner) Stop

func (m *Miner) Stop() error

type PrivateMinerAPI

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

PrivateMinerAPI provides private RPC methods to control the miner.

func NewPrivateMinerAPI

func NewPrivateMinerAPI(m *Miner) *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(m *Miner) *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) GetMinerInfo

func (api *PublicMinerAPI) GetMinerInfo() (interface{}, error)

func (*PublicMinerAPI) GetRemoteGBT

func (api *PublicMinerAPI) GetRemoteGBT(powType byte, extraNonce *bool) (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

func (*PublicMinerAPI) SubmitBlockHeader

func (api *PublicMinerAPI) SubmitBlockHeader(hexBlockHeader string, extraNonce *uint64) (interface{}, error)

type RemoteMiningMsg

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

type RemoteWorker

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

func NewRemoteWorker

func NewRemoteWorker(miner *Miner) *RemoteWorker

func (*RemoteWorker) GetRemoteGBTResult

func (w *RemoteWorker) GetRemoteGBTResult() *json.RemoteGBTResult

func (*RemoteWorker) GetRequest

func (w *RemoteWorker) GetRequest(powType pow.PowType, coinbaseFlags mining.CoinbaseFlags, reply chan *gbtResponse)

func (*RemoteWorker) GetType

func (w *RemoteWorker) GetType() string

func (*RemoteWorker) IsRunning

func (w *RemoteWorker) IsRunning() bool

func (*RemoteWorker) Start

func (w *RemoteWorker) Start() error

func (*RemoteWorker) Stop

func (w *RemoteWorker) Stop()

func (*RemoteWorker) Update

func (w *RemoteWorker) Update()

type StartCPUMiningMsg

type StartCPUMiningMsg struct {
}

Jump to

Keyboard shortcuts

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