pow

package
v0.0.0-...-decf009 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: ISC Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockLevel

func BlockLevel(header externalapi.BlockHeader, maxBlockLevel int) int

BlockLevel returns the block level of the given header.

func CalcGlobalVMHash

func CalcGlobalVMHash(data []byte) []byte

CalcGlobalVMHash calculates the hash using one of the RandomX VMs from the global pool.

func CheckProofOfWorkByBits

func CheckProofOfWorkByBits(header externalapi.MutableBlockHeader) bool

CheckProofOfWorkByBits check's if the block has a valid PoW according to its Bits field it does not check if the difficulty itself is valid or less than the maximum for the appropriate network

func ResizeGlobalPool

func ResizeGlobalPool(newSize int) error

ResizeGlobalPool adjusts the size of the global RxVMPool to the specified size.

Types

type RxVMPool

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

RxVMPool represents a pool of RandomX VMs.

func NewRxVMPool

func NewRxVMPool(poolSize int) (*RxVMPool, error)

NewRxVMPool initializes a new pool of RandomX VMs with the given size.

func (*RxVMPool) CalcHash

func (p *RxVMPool) CalcHash(data []byte) []byte

CalcHash calculates the hash using one of the available RandomX VMs.

func (*RxVMPool) Cleanup

func (p *RxVMPool) Cleanup()

Cleanup safely destroys all RandomX VMs in the pool.

func (*RxVMPool) ResizePool

func (p *RxVMPool) ResizePool(newSize int) error

ResizePool adjusts the size of the RxVMPool to the specified size. This function increases the pool size by creating new RandomX VM instances and transferring existing ones to a new channel with the desired size.

Note:

  • This function is not thread-safe and should not be called concurrently.
  • It does not support shrinking the pool size; attempting to do so will return an error.
  • The pool can only be resized when it's not in use (i.e., when the current pool size equals the number of VMs in the channel). Attempting to resize while the pool is in use will result in an error.

Parameters: - newSize: The desired size of the pool after resizing.

Returns an error if shrinking is attempted, the pool is in use, or if there is an issue creating new RandomX VM instances.

type State

type State struct {
	Timestamp int64
	Nonce     uint64
	Target    big.Int
	// contains filtered or unexported fields
}

State is an intermediate data structure with pre-computed values to speed up mining.

func NewState

func NewState(header externalapi.MutableBlockHeader) *State

NewState creates a new state with pre-computed values to speed up mining It takes the target from the Bits field

func (*State) CalculateProofOfWorkValue

func (state *State) CalculateProofOfWorkValue() *big.Int

CalculateProofOfWorkValue hashes the internal header and returns its big.Int value

func (*State) CheckProofOfWork

func (state *State) CheckProofOfWork() bool

CheckProofOfWork check's if the block has a valid PoW according to the provided target it does not check if the difficulty itself is valid or less than the maximum for the appropriate network

func (*State) IncrementNonce

func (state *State) IncrementNonce()

IncrementNonce the nonce in State by 1

Jump to

Keyboard shortcuts

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