nanopow

package module
v0.0.0-...-1c39817 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2020 License: MIT Imports: 6 Imported by: 0

README

Golang NanoPoW

NanoPoW is an implementation of the proof-of-work used by Nano. That supports CPU and GPU (currently only OpenCL).

Usage

func main() {
    nanopow.GenerateWork([]byte{/** PREVIOUS HASH **/}, nanopow.V1BaseDifficult)
}
CPU

By default, we always uses CPU. If GPU is available, it will use CPU and GPU, combined.

GPU

By default, we don't support GPU. You need to enable it using the "build tags", when build use:

go build -tags cl

Currently the only available option is OpenCL ("cl" tag).

"Benchmarks"

I don't have an huge amount of data to compare and limited devices to test against. Some devices doesn't supports OpenCL. All times are using the V1 difficulty.

Device OS CPU-Only CPU + OpenCL
Samsung Galaxy S20+ Android ~9.62 seg Untested
Blackberry KeyOne Android ~36.7 seg Untested
R9 3900X + RX 5700XT Windows ~0.66 seg ~0.27 seg

Limitations

Support OpenGL, OpenGLES or Vulkan:

Currently we only support OpenCL, which is not natively supported by some devices. I have some plans to add some support for OpenGL, OpenGLES or Vulkan. Seems that Vulkan Compute, if possible, is the best solution since it's compatible with Windows, Linux and Android.

Support multi-GPU:

Currently only one GPU is supported, but it can be easily fixed, but I don't have a multi-GPU setup to be able to test. :(

Contributing

Pull requests are welcome.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotSupported           = errors.New("that device don't support that type of work method")
	ErrNoDeviceAvailable      = errors.New("no device found")
	ErrNoDefaultPoolAvailable = errors.New("no default pool found")
)
View Source
var (
	V1BaseDifficult    = CalculateDifficulty(0)
	V2BaseDifficult    = CalculateDifficulty(8)
	V2ReceiveDifficult = CalculateDifficulty(-8)
)

Functions

func CalculateDifficulty

func CalculateDifficulty(multiplier int64) uint64

func IsValid

func IsValid(previous []byte, difficult uint64, w Work) bool

func NewWorkerGPU

func NewWorkerGPU() (*clWorker, error)

func NewWorkerGPUThread

func NewWorkerGPUThread(thread uint64) (*clWorker, error)

Types

type Context

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

func NewContext

func NewContext() *Context

func (*Context) Cancel

func (c *Context) Cancel()

func (*Context) Result

func (c *Context) Result() (result Work)

type Pool

type Pool struct {
	Workers []WorkerGenerator
}
var DefaultWorkerPool *Pool // We don't use DefaultWorkerPool = newDefaultPool() because it slow down the init

func NewPool

func NewPool(w ...WorkerGenerator) (p *Pool)

func (*Pool) GenerateWork

func (p *Pool) GenerateWork(root []byte, difficulty uint64) (w Work, err error)

type Work

type Work [8]byte

func GenerateWork

func GenerateWork(root []byte, difficulty uint64) (w Work, err error)

func NewWork

func NewWork(b []byte) (work Work)

type WorkerGenerator

type WorkerGenerator interface {
	GenerateWork(ctx *Context, root []byte, difficulty uint64) (err error)
}

Jump to

Keyboard shortcuts

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