randomx

package module
v0.0.0-...-d4e94c6 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

README

go-randomx

WARNING: this is not a lib, but a binding

Do NOT use go mod import this

NOTICE: For better go.mod experience, like direcly import go-randomx dep through go get or go build, check the https://github.com/ngchain/RandomX and https://github.com/ngchain/go-randomx and their github actions.

Algorithms

  • random-x
  • random-xl
  • random-wow
  • random-arq
  • random-yada
  • ...

Build

Windows

Firstly download and install the msys2, then open and install the following components:

Take msys2's pacman for example

pacman -Syu
pacman -S git mingw64/mingw-w64-x86_64-go mingw64/mingw-w64-x86_64-gcc mingw64/mingw-w64-x86_64-cmake mingw64/mingw-w64-x86_64-make

Secondly clone this repo to your project folder

cd MyProject
git clone https://github.com/maoxs2/go-randomx

And then run ./build.sh to auto compile official random-x code

# clone and compile RandomX source code into librandomx
./build random-x # random-x can be replaced with random-xl random-arq random-wow

Finally you can using the package as your internal one.

Directly using it with import "github.com/MyProject/go-randomx" and then randomx.AllocCache() etc.

Linux

Take Ubuntu for example

Download the latest go from here and then install it following this instruction

sudo apt update && sudo apt upgrade 
sudo apt install git cmake make gcc build-essential

Secondly clone this repo to your project folder

cd MyProject
git clone https://github.com/maoxs2/go-randomx

And then run go generate to auto compile official random-x code

# clone and compile RandomX source code into librandomx
./build random-x # random-x can be replaced with random-xl random-arq random-wow

Finally you can using the package as your internal one.

Directly using it with import "github.com/myname/my-project/go-randomx" and then start the functions like randomx.AllocCache() etc.

More

If you have any better solution, tell me please.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllocCache

func AllocCache(flags ...Flag) (*C.randomx_cache, error)

func AllocDataset

func AllocDataset(flags ...Flag) (*C.randomx_dataset, error)

func CalculateHash

func CalculateHash(vm *C.randomx_vm, in []byte) []byte

func CalculateHashFirst

func CalculateHashFirst(vm *C.randomx_vm, in []byte)

func CalculateHashNext

func CalculateHashNext(vm *C.randomx_vm, in []byte) []byte

func CreateVM

func CreateVM(cache *C.randomx_cache, dataset *C.randomx_dataset, flags ...Flag) (*C.randomx_vm, error)

func DatasetItemCount

func DatasetItemCount() uint32

func DestroyVM

func DestroyVM(vm *C.randomx_vm)

func FastInitFullDataset

func FastInitFullDataset(dataset *C.randomx_dataset, cache *C.randomx_cache, workerNum uint32)

FastInitFullDataset using c's pthread to boost the dataset init. 472s -> 466s

func GetDatasetMemory

func GetDatasetMemory(dataset *C.randomx_dataset) unsafe.Pointer

func InitCache

func InitCache(cache *C.randomx_cache, seed []byte)

func InitDataset

func InitDataset(dataset *C.randomx_dataset, cache *C.randomx_cache, startItem uint32, itemCount uint32)

func ReleaseCache

func ReleaseCache(cache *C.randomx_cache)

func ReleaseDataset

func ReleaseDataset(dataset *C.randomx_dataset)
func Search(vm *C.randomx_vm, in []byte, target uint64, maxTimes uint64, jump uint32, nonce []byte) (Hash []byte, Found bool, Sol []byte)

func SetVMCache

func SetVMCache(vm *C.randomx_vm, cache *C.randomx_cache)

func SetVMDataset

func SetVMDataset(vm *C.randomx_vm, dataset *C.randomx_dataset)

Types

type Flag

type Flag int
var (
	FlagDefault     Flag = 0 // for all default
	FlagLargePages  Flag = 1 // for dataset & rxCache & vm
	FlagHardAES     Flag = 2 // for vm
	FlagFullMEM     Flag = 4 // for vm
	FlagJIT         Flag = 8 // for vm & cache
	FlagSecure      Flag = 16
	FlagArgon2SSSE3 Flag = 32 // for cache
	FlagArgon2AVX2  Flag = 64 // for cache
	FlagArgon2      Flag = 96 // = avx2 + sse3
)

type RxCache

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

func NewRxCache

func NewRxCache(flags ...Flag) (*RxCache, error)

func (*RxCache) Close

func (c *RxCache) Close()

func (*RxCache) Init

func (c *RxCache) Init(seed []byte) bool

func (*RxCache) IsReady

func (c *RxCache) IsReady(seed []byte) bool

type RxDataset

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

func NewRxDataset

func NewRxDataset(flags ...Flag) (*RxDataset, error)

func (*RxDataset) CInit

func (ds *RxDataset) CInit(seed []byte, workerNum uint32) bool

func (*RxDataset) Close

func (ds *RxDataset) Close()

func (*RxDataset) GoInit

func (ds *RxDataset) GoInit(seed []byte, workerNum uint32) bool

type RxVM

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

func NewRxVM

func NewRxVM(rxDataset *RxDataset, flags ...Flag) (*RxVM, error)

func (*RxVM) CalcHash

func (vm *RxVM) CalcHash(in []byte) []byte

func (*RxVM) CalcHashFirst

func (vm *RxVM) CalcHashFirst(in []byte)

func (*RxVM) CalcHashNext

func (vm *RxVM) CalcHashNext(in []byte) []byte

func (*RxVM) Close

func (vm *RxVM) Close()

func (*RxVM) Search

func (vm *RxVM) Search(in []byte, target uint64, maxTimes uint64, jump uint32, nonce []byte) (hash []byte, found bool, sol []byte)

func (*RxVM) UpdateDataset

func (vm *RxVM) UpdateDataset(rxDataset *RxDataset)

Jump to

Keyboard shortcuts

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