pow

package
v4.0.0-...-3659144 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// Hash defines the hash function that is used to compute the PoW digest.
	Hash = crypto.BLAKE2b_256

	// HashLength defines the length of the hash function in bytes.
	HashLength = blake2b.Size256

	// NonceLength defines the length of the nonce in bytes.
	NonceLength = serializer.UInt64ByteSize

	// MaxTrailingZeros defines the maximum amount of trailing zeros.
	MaxTrailingZeros = serializer.UInt64ByteSize * 8
)

Variables

View Source
var (
	// ErrCanceled gets returned when the context for the PoW was canceled.
	ErrCanceled = ierrors.New("canceled")

	// ErrDone gets returned when the PoW was done but no valid nonce was found.
	ErrDone = ierrors.New("done")

	// ErrInvalidTargetTrailingZeroes gets returned when an invalid target trailing zeroes parameter was set.
	ErrInvalidTargetTrailingZeroes = ierrors.New("invalid target trailing zeros")
)

Functions

func TrailingZeros

func TrailingZeros(msgBytes []byte, nonce uint64) int

TrailingZeros returns amount of trailing zeros for the hash of the given msg and nonce.

Types

type Worker

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

The Worker performs the PoW.

func New

func New(numWorkers ...int) *Worker

New creates a new PoW Worker. The optional numWorkers specifies how many go routines should be used to perform the PoW.

func (*Worker) Mine

func (w *Worker) Mine(ctx context.Context, data []byte, targetTrailingZeros int) (uint64, error)

Mine performs the PoW for data. It returns a nonce that appended to data results in at least targetTrailingZeros. The computation can be canceled anytime using ctx.

Jump to

Keyboard shortcuts

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