eccpow

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: GPL-3.0 Imports: 30 Imported by: 2

Documentation

Index

Constants

View Source
const (
	BigInfinity = 1000000.0
	Inf         = 64.0
	MaxNonce    = 1<<32 - 1
)

Parameters for matrix and seed

Variables

View Source
var (
	MinimumDifficulty   = ProbToDifficulty(Table[0].miningProb)
	BlockGenerationTime = big.NewInt(36) // 36) // 10 ) // 36)
	Sensitivity         = big.NewInt(8)

	// BlockGenerationTime for Seoul
	BlockGenerationTimeSeoul = big.NewInt(10) // 36) // 10 ) // 36)
	SeoulDifficulty          = big.NewInt(1023)
)

"github.com/cryptoecc/ETH-ECC/consensus/ethash/consensus.go" Some weird constants to avoid constant memory allocs for them.

View Source
var (
	FrontierBlockReward       = big.NewInt(5e+18) // Block reward in wei for successfully mining a block
	ByzantiumBlockReward      = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Byzantium
	ConstantinopleBlockReward = big.NewInt(2e+18) // Block reward in wei for successfully mining a block upward from Constantinople
	WorldLandBlockReward      = big.NewInt(4e+18) //Block reward in wei for successfully mining a block upward from WorldLand

	HALVING_INTERVAL  = uint64(6307200) //Block per year * 2year
	MATURITY_INTERVAL = uint64(3153600) //Block per year

	SumRewardUntilMaturity = big.NewInt(47304000) //Total supply of token until maturity

	MaxHalving = int64(4)
)

ecc proof-of-work protocol constants.

View Source
var DynamicDifficultyCalculator = makeDifficultyCalculator
View Source
var FrontierDifficultyCalculator = calcDifficultyFrontier

Exported for fuzzing

View Source
var Table = []difficulty{}/* 381 elements not displayed */

Table is difficulty table slice

Functions

func BigIntToFloat

func BigIntToFloat(val *big.Int) float64

BigIntToFloat convert big int to float64

func DifficultyToProb

func DifficultyToProb(difficulty *big.Int) float64

DifficultyToProb convert difficulty to probability of table

func FloatToBigInt

func FloatToBigInt(val float64) *big.Int

FloatToBigInt convert float64 to big integer

func MakeDecision

func MakeDecision(header *types.Header, colInRow [][]int, outputWord []int) (bool, int)

MakeDecision check outputWord is valid or not using colInRow

func MakeDecision_Seoul added in v1.0.0

func MakeDecision_Seoul(header *types.Header, colInRow [][]int, outputWord []int) (bool, int)

MakeDecision check outputWord is valid or not using colInRow

func MakeLDPCDifficultyCalculator

func MakeLDPCDifficultyCalculator() func(time uint64, parent *types.Header) *big.Int

MakeLDPCDifficultyCalculator calculate difficulty using difficulty table

func MakeLDPCDifficultyCalculator_Seoul added in v1.0.0

func MakeLDPCDifficultyCalculator_Seoul() func(time uint64, parent *types.Header) *big.Int

func OptimizedDecoding

func OptimizedDecoding(parameters Parameters, hashVector []int, H, rowInCol, colInRow [][]int) ([]int, []int, [][]float64)

OptimizedDecoding return hashVector, outputWord, LRrtl

func OptimizedDecodingSeoul added in v1.0.0

func OptimizedDecodingSeoul(parameters Parameters, hashVector []int, H, rowInCol, colInRow [][]int) ([]int, []int, [][]float64)

OptimizedDecoding return hashVector, outputWord, LRrtl

func ProbToDifficulty

func ProbToDifficulty(miningProb float64) *big.Int

ProbToDifficulty convert probability to difficulty of header

func RunOptimizedConcurrencyLDPC

func RunOptimizedConcurrencyLDPC(header *types.Header, hash []byte) (bool, []int, []int, uint64, []byte)

RunOptimizedConcurrencyLDPC use goroutine for mining block

func RunOptimizedConcurrencyLDPC_Seoul added in v1.0.0

func RunOptimizedConcurrencyLDPC_Seoul(header *types.Header, hash []byte) (bool, []int, []int, uint64, []byte)

func SearchLevel

func SearchLevel(difficulty *big.Int) int

SearchLevel return next level by using currentDifficulty of header Type of Ethereum difficulty is *bit.Int so arg is *big.int

func SearchLevel_Seoul added in v1.0.0

func SearchLevel_Seoul(difficulty *big.Int) int

SearchLevel return next level by using currentDifficulty of header Type of Ethereum difficulty is *bit.Int so arg is *big.int

func SeedHash

func SeedHash(block uint64) []byte

// SeedHash is the seed to use for generating a verification cache and the mining // dataset.

func VerifyOptimizedDecoding

func VerifyOptimizedDecoding(header *types.Header, hash []byte) (bool, []int, []int, []byte)

VerifyOptimizedDecoding return bool, hashVector, outputword, digest which are used for validation

func VerifyOptimizedDecodingSeoul added in v1.0.0

func VerifyOptimizedDecodingSeoul(header *types.Header, hash []byte) (bool, []int, []int, []byte)

VerifyOptimizedDecoding return bool, hashVector, outputword, digest which are used for validation

Types

type API

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

API exposes ecc related methods for the RPC interface.

func (*API) Geccrate

func (api *API) Geccrate() uint64

Geccrate returns the current hashrate for local CPU miner and remote miner.

func (*API) GetWork

func (api *API) GetWork() ([4]string, error)

GetWork returns a work package for external miner.

The work package consists of 3 strings:

result[0] - 32 bytes hex encoded current block header pow-hash
result[1] - 32 bytes hex encoded seed hash used for DAG
result[2] - 32 bytes hex encoded boundary condition ("target"), 2^256/difficulty
result[3] - hex encoded block number

func (*API) SubmitHashRate

func (api *API) SubmitHashRate(rate hexutil.Uint64, id common.Hash) bool

SubmitHashrate can be used for remote miners to submit their hash rate. This enables the node to report the combined hash rate of all miners which submit work through this node.

It accepts the miner hash rate and an identifier which must be unique between nodes.

func (*API) SubmitWork

func (api *API) SubmitWork(nonce types.BlockNonce, hash, digest common.Hash) bool

SubmitWork can be used by external miner to submit their POW solution. It returns an indication if the work was accepted. Note either an invalid solution, a stale work a non-existent work will return false.

type Config

type Config struct {
	PowMode Mode
	// When set, notifications sent by the remote sealer will
	// be block header JSON objects instead of work package arrays.
	NotifyFull bool
	Log        log.Logger `toml:"-"`
}

Config are the configuration parameters of the ethash.

type ECC

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

func New

func New(config Config, notify []string, noverify bool) *ECC

func NewFakeDelayer

func NewFakeDelayer(delay time.Duration) *ECC

NewFakeDelayer creates a ethash consensus engine with a fake PoW scheme that accepts all blocks as valid, but delays verifications by some time, though they still have to conform to the Ethereum consensus rules.

func NewFakeFailer

func NewFakeFailer(fail uint64) *ECC

NewFakeFailer creates a ethash consensus engine with a fake PoW scheme that accepts all blocks as valid apart from the single one specified, though they still have to conform to the Ethereum consensus rules.

func NewFaker

func NewFaker() *ECC

NewFaker creates a ethash consensus engine with a fake PoW scheme that accepts all blocks' seal as valid, though they still have to conform to the Ethereum consensus rules.

func NewFullFaker

func NewFullFaker() *ECC

NewFullFaker creates an ethash consensus engine with a full fake scheme that accepts all blocks as valid, without checking any consensus rules whatsoever.

func NewTester

func NewTester(notify []string, noverify bool) *ECC

func (*ECC) APIs

func (ecc *ECC) APIs(chain consensus.ChainHeaderReader) []rpc.API

APIs implements consensus.Engine, returning the user facing RPC APIs.

func (*ECC) Author

func (ecc *ECC) Author(header *types.Header) (common.Address, error)

Author implements consensus.Engine, returning the header's coinbase as the proof-of-work verified author of the block.

func (*ECC) CalcDifficulty

func (ecc *ECC) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int

CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have when created at time given the parent block's time and difficulty.

func (*ECC) Close

func (ecc *ECC) Close() error

Close closes the exit channel to notify all backend threads exiting.

func (*ECC) Finalize

func (ecc *ECC) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header)

Finalize implements consensus.Engine, accumulating the block and uncle rewards, setting the final state and assembling the block.

func (*ECC) FinalizeAndAssemble

func (ecc *ECC) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)

func (*ECC) Hashrate

func (ecc *ECC) Hashrate() float64

Hashrate implements PoW, returning the measured rate of the search invocations per second over the last minute. Note the returned hashrate includes local hashrate, but also includes the total hashrate of all remote miner.

func (*ECC) Prepare

func (ecc *ECC) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error

Prepare implements consensus.Engine, initializing the difficulty field of a header to conform to the ecc protocol. The changes are done inline.

func (*ECC) Seal

func (ecc *ECC) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error

Seal implements consensus.Engine, attempting to find a nonce that satisfies the block's difficulty requirements.

func (*ECC) SealHash

func (ecc *ECC) SealHash(header *types.Header) (hash common.Hash)

SealHash returns the hash of a block prior to it being sealed.

func (*ECC) SetThreads

func (ecc *ECC) SetThreads(threads int)

SetThreads updates the number of mining threads currently enabled. Calling this method does not start mining, only sets the thread count. If zero is specified, the miner will use all cores of the machine. Setting a thread count below zero is allowed and will cause the miner to idle, without any work being done.

func (*ECC) StopRemoteSealer added in v1.0.0

func (ecc *ECC) StopRemoteSealer() error

StopRemoteSealer stops the remote sealer

func (*ECC) Threads

func (ecc *ECC) Threads() int

Threads returns the number of mining threads currently enabled. This doesn't necessarily mean that mining is running!

func (*ECC) VerifyHeader

func (ecc *ECC) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error

VerifyHeader checks whether a header conforms to the consensus rules of the stock Ethereum ecc engine.

func (*ECC) VerifyHeaders

func (ecc *ECC) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)

VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers concurrently. The method returns a quit channel to abort the operations and a results channel to retrieve the async verifications.

func (*ECC) VerifyUncles

func (ecc *ECC) VerifyUncles(chain consensus.ChainReader, block *types.Block) error

VerifyUncles verifies that the given block's uncles conform to the consensus rules of the stock Ethereum ecc engine.

type Mode

type Mode uint
const (
	ModeNormal Mode = iota
	ModeShared
	ModeTest
	ModeFake
	ModeFullFake
)

type Parameters

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

Jump to

Keyboard shortcuts

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