Documentation ¶
Overview ¶
Package amhash implements the amhash proof-of-work consensus engine.
Index ¶
- Variables
- func CalcDifficulty(config *params.ChainConfig, curVersion string, time uint64, ...) *big.Int
- func Reverse(s []byte) string
- type Amhash
- func (amhash *Amhash) APIs(chain consensus.ChainReader) []rpc.API
- func (amhash *Amhash) Author(header *types.Header) (common.Address, error)
- func (amhash *Amhash) CalcDifficulty(chain consensus.ChainReader, curVersion string, time uint64, ...) (*big.Int, error)
- func (amhash *Amhash) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDBManage, ...) (*types.Block, error)
- func (amhash *Amhash) Hashrate() float64
- func (amhash *Amhash) Prepare(chain consensus.ChainReader, header *types.Header) error
- func (amhash *Amhash) Seal(chain consensus.ChainReader, header *types.Header, stop <-chan struct{}, ...) (*types.Header, error)
- func (amhash *Amhash) SetThreads(threads int)
- func (amhash *Amhash) Threads() int
- func (amhash *Amhash) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error
- func (amhash *Amhash) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (amhash *Amhash) VerifySeal(chain consensus.ChainReader, header *types.Header) error
- func (amhash *Amhash) VerifySignatures(signature []common.Signature) (bool, error)
- func (amhash *Amhash) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- type Config
- type Mode
Constants ¶
This section is empty.
Variables ¶
var ( FrontierBlockReward *big.Int = big.NewInt(5e+18) // Block reward in wei for successfully mining a block ByzantiumBlockReward *big.Int = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Byzantium )
amhash proof-of-work protocol constants.
Functions ¶
func CalcDifficulty ¶
func CalcDifficulty(config *params.ChainConfig, curVersion string, time uint64, parent *types.Header, minimumDifficulty *big.Int) *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 Reverse ¶
YYYYYYYYYYYYYYYYYYYYYYYYYYY
func combinationData(header *types.Header) []byte { headerHash := hashString2LittleEndian(reverseHashString(header.ParentHash.Hex())) aiHash := hashString2LittleEndian(reverseHashString(header.AIHash.Hex())) //tmpnonce2 := header.Nonce nonce, _ := header.Nonce.MarshalText() Reverse(nonce) header.Nonce.UnmarshalText(nonce) nonce32 := uint32ToBytes(uint32(header.Nonce.Uint64())) //log.Info("==testID==", "yuan shi nonce", tmpnonce2.Uint64(), "fan zhuan hou de header.Nonce", header.Nonce.Uint64(), "nonce32", nonce32, "headerHash", headerHash) databufio := bytes.NewBuffer([]byte{}) binary.Write(databufio, binary.BigEndian, common.HexToHash(headerHash)) binary.Write(databufio, binary.BigEndian, common.HexToHash(aiHash)) binary.Write(databufio, binary.BigEndian, uint64(0)) //coinbase crc64 binary.Write(databufio, binary.BigEndian, uint32(0)) //extranonce binary.Write(databufio, binary.LittleEndian, nonce32) return databufio.Bytes() }
Types ¶
type Amhash ¶
type Amhash struct {
// contains filtered or unexported fields
}
Amhash is a consensus engine based on proot-of-work implementing the amhash algorithm.
func (*Amhash) APIs ¶
func (amhash *Amhash) APIs(chain consensus.ChainReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC APIs. Currently that is empty.
func (*Amhash) Author ¶
Author implements consensus.Engine, returning the header's coinbase as the proof-of-work verified author of the block.
func (*Amhash) CalcDifficulty ¶
func (amhash *Amhash) CalcDifficulty(chain consensus.ChainReader, curVersion string, time uint64, parent *types.Header) (*big.Int, error)
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 (*Amhash) Finalize ¶
func (amhash *Amhash) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDBManage, uncles []*types.Header, currencyBlock []types.CurrencyBlock) (*types.Block, error)
Finalize implements consensus.Engine, accumulating the block and uncle rewards, setting the final state and assembling the block.
func (*Amhash) Hashrate ¶
Hashrate implements PoW, returning the measured rate of the search invocations per second over the last minute.
func (*Amhash) Prepare ¶
YYYYYYYYYYY end YYYYYYYYYYY Prepare implements consensus.Engine, initializing the difficulty field of a header to conform to the amhash protocol. The changes are done inline.
func (*Amhash) Seal ¶
func (amhash *Amhash) Seal(chain consensus.ChainReader, header *types.Header, stop <-chan struct{}, isBroadcastNode bool) (*types.Header, error)
Seal implements consensus.Engine, attempting to find a nonce that satisfies the block's difficulty requirements.
func (*Amhash) SetThreads ¶
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 (*Amhash) Threads ¶
Threads returns the number of mining threads currently enabled. This doesn't necessarily mean that mining is running!
func (*Amhash) VerifyHeader ¶
func (amhash *Amhash) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error
VerifyHeader checks whether a header conforms to the consensus rules of the stock Matrix amhash engine.
func (*Amhash) VerifyHeaders ¶
func (amhash *Amhash) VerifyHeaders(chain consensus.ChainReader, 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 (*Amhash) VerifySeal ¶
VerifySeal implements consensus.Engine, checking whether the given block satisfies the PoW difficulty requirements.
func (*Amhash) VerifySignatures ¶
VerifyHeader checks whether a header conforms to the consensus rules of the stock Matrix amhash engine.
func (*Amhash) VerifyUncles ¶
VerifyUncles verifies that the given block's uncles conform to the consensus rules of the stock Matrix amhash engine.