pow

package
v1.0.0-beta.23 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package pow provides Proof-of-Work implementations. Consider using Proof-of-Work implementations prefixed with "Sync" to ensure that concurrent calls are synchronized (running at most one Proof-of-Work task at a time). The provided Proof-of-Work implementations allow the caller to supply a parallelism option, defining how many concurrent goroutines are used. If no parallelism option is supplied, then the number of CPU cores - 1 is used.

Index

Constants

View Source
const (
	PearlDiverMidStateLow0  uint64 = 0xDB6DB6DB6DB6DB6D
	PearlDiverMidStateHigh0 uint64 = 0xB6DB6DB6DB6DB6DB
	PearlDiverMidStateLow1  uint64 = 0xF1F8FC7E3F1F8FC7
	PearlDiverMidStateHigh1 uint64 = 0x8FC7E3F1F8FC7E3F
	PearlDiverMidStateLow2  uint64 = 0x7FFFE00FFFFC01FF
	PearlDiverMidStateHigh2 uint64 = 0xFFC01FFFF803FFFF
	PearlDiverMidStateLow3  uint64 = 0xFFC0000007FFFFFF
	PearlDiverMidStateHigh3 uint64 = 0x003FFFFFFFFFFFFF
)

trytes

Variables

View Source
var (
	// ErrInvalidTrytesForProofOfWork gets returned when invalid trytes are supplied for PoW.
	ErrInvalidTrytesForProofOfWork = errors.New("invalid trytes supplied to Proof-of-Work func")
	// ErrUnknownProofOfWorkFunc gets returned when the wanted Proof-of-Work implementation is unknown.
	ErrUnknownProofOfWorkFunc = errors.New("unknown Proof-of-Work func")
)

Functions

func DoPoW

func DoPoW(trunkTx Trytes, branchTx Trytes, trytes []Trytes, mwm uint64, pow ProofOfWorkFunc) ([]Trytes, error)

DoPoW computes the nonce field for each transaction so that the last MWM-length trits of the transaction hash are all zeroes. Starting from the 0 index transaction, the transactions get chained to each other through the trunk transaction hash field. The last transaction in the bundle approves the given branch and trunk transactions. This function also initializes the attachment timestamp fields. This function expects the passed in transaction trytes from highest to lowest index, meaning the transaction with current index 0 at the last position.

func GetProofOfWorkImplementations

func GetProofOfWorkImplementations() []string

GetProofOfWorkImplementations returns an array with the names of all available Proof-of-Work implementations.

func GoProofOfWork

func GoProofOfWork(trytes Trytes, mwm int, parallelism ...int) (Trytes, error)

GoProofOfWork does Proof-of-Work on the given trytes using only Go code.

func Loop

func Loop(lmid *[curl.StateSize]uint64, hmid *[curl.StateSize]uint64, m int, cancelled *int32, checkFun CheckFunc, loopCnt int) (nonce Trits, rate int64, foundIndex int)

Loop increments and transforms until checkFun is true.

func Para

func Para(in Trits) (*[curl.StateSize]uint64, *[curl.StateSize]uint64)

Para transforms trits to ptrits (01:-1 11:0 10:1)

func SyncGoProofOfWork

func SyncGoProofOfWork(trytes Trytes, mwm int, parallelism ...int) (Trytes, error)

SyncGoProofOfWork is like GoProofOfWork() but only runs one ongoing Proof-of-Work task at a time.

Types

type CheckFunc

type CheckFunc = func(low *[curl.StateSize]uint64, high *[curl.StateSize]uint64, param int) int

CheckFunc is a function which checks if the required amount of work was fulfilled. It needs the low and high trits of the curl state and a parameter (e.g. MWM for hashcash, Security for hamming)

type ProofOfWorkFunc

type ProofOfWorkFunc = func(trytes Trytes, mwm int, parallelism ...int) (Trytes, error)

ProofOfWorkFunc is a function which given transaction trytes and a difficulty (called MWM), does the required amount of work to fulfill the difficulty requirement. The Proof-of-Work involves finding a nonce, which together with other elements of a transaction, result in a transaction hash with MWM-amount of 0s at the end of the hash. Given a MWM of 14, the hash of the transaction must have 14 zero trits at the end of the hash.

func GetFastestProofOfWorkImpl

func GetFastestProofOfWorkImpl() (string, ProofOfWorkFunc)

GetFastestProofOfWorkImpl returns the fastest Proof-of-Work implementation. All returned Proof-of-Work implementations returned are "sync", meaning that they only run one Proof-of-Work task simultaneously.

func GetFastestProofOfWorkUnsyncImpl

func GetFastestProofOfWorkUnsyncImpl() (string, ProofOfWorkFunc)

GetFastestProofOfWorkUnsyncImpl returns the fastest Proof-of-Work implementation. All returned Proof-of-Work implementations returned are "unsync", meaning that they can run several Proof-of-Work tasks in parallel.

func GetProofOfWorkImpl

func GetProofOfWorkImpl(name string) (ProofOfWorkFunc, error)

GetProofOfWorkImpl returns the specified Proof-of-Work implementation given a name.

Jump to

Keyboard shortcuts

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