pow

package module
v0.0.0-...-9cc8e37 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2024 License: MIT Imports: 13 Imported by: 4

README

PoW (Proof of Work)

This is the core module for requesting PoW, which is required to publish blocks to the Nano or BANANO networks.

There are 3 mechanisms for requesting work within this module.

  1. BoomPoW
  2. API-driven, using something like Nano work server or a node itself.
  3. Local PoW, using nanopow - if compiled with -tags cl it will utilize OpenCL CGO bindings to calculate PoW on GPU.

These mechanisms can all be invoked separately, or by Pippin's mechanism (WorkGenerateMeta function).

WorkGenerateMeta will

  1. Execute concurrent goroutines requesting from BoomPoW and all configured work servers.
  2. When first result comes back, cancel all pending goroutines and send work_cancel to all work servers.
  3. If API fails, we generate PoW locally and set a flag WorkFailing, then subsequent requests will use local PoW along with the peers until the peers are working again

APIs are preferred, if no APIs are configured then local work generation will be the primary mechanism.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DifficultyFromMultiplier

func DifficultyFromMultiplier(multiplier int) uint64

This is a helper to convert work multiplier to difficulty string representation BoomPoW takes a multiplier while the node/other work servers take the string Our base is banano or nano's receive, which would be 1x Nano's send would be 64x

func DifficultyToString

func DifficultyToString(difficulty uint64) string

func IsWorkValid

func IsWorkValid(previous string, difficultyMultiplier int, w string) bool

func MultiplierFromDifficulty

func MultiplierFromDifficulty(difficulty uint64) int

func WorkCancelAPIRequest

func WorkCancelAPIRequest(url string, hash string)

Makes a work cancel request

func WorkToString

func WorkToString(w nanopow.Work) string

func WriteChannelSafe

func WriteChannelSafe(out chan *string, msg string) (err error)

Recovers from writing to close channel

Types

type PippinPow

type PippinPow struct {
	WorkPeers []string
	// contains filtered or unexported fields
}

func NewPippinPow

func NewPippinPow(workPeers []string, bpowKey string, bpowUrl string) *PippinPow

workPeers is an array of URLs to send work_generate requests to bpowKey and bpowUrl are optional, bpowUrl will default to boompow.banano.cc/graphql

func (*PippinPow) SetWorkPeersFailing

func (p *PippinPow) SetWorkPeersFailing(failing bool)

func (*PippinPow) WorkGenerateMeta

func (p *PippinPow) WorkGenerateMeta(hash string, difficultyMultiplier int, validate bool, blockAward bool, bpowKey string) (string, error)

The main entry point for Pippin WorkGenerate Invokes work_generate requests to every peer simultaneously including BoomPoW, depending on configuration Returns the first valid work response, sends cancel to everybody else If no peers or boompow configured, uses local PoW If all peers fail, will use local PoW until peers are responsive again

func (*PippinPow) WorkPeersFailing

func (p *PippinPow) WorkPeersFailing() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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