erigon-pulse/consensus/consensus.go

113 lines
4.9 KiB
Go
Raw Normal View History

// Copyright 2017 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Package consensus implements different Ethereum consensus engines.
package consensus
import (
"math/big"
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/core/state"
"github.com/ledgerwatch/turbo-geth/core/types"
"github.com/ledgerwatch/turbo-geth/params"
"github.com/ledgerwatch/turbo-geth/rpc"
)
// Engine is an algorithm agnostic consensus engine.
type Engine interface {
// Author retrieves the Ethereum address of the account that minted the given
// block, which may be different from the header's coinbase if a consensus
// engine is based on signatures.
Author(header *types.Header) (common.Address, error)
// VerifyHeader checks whether a header conforms to the consensus rules of a
// given engine. Verifying the seal may be done optionally here, or explicitly
// via the VerifySeal method.
VerifyHeader(chain ChainHeaderReader, header *types.Header, seal bool) 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 (the order is that of
// the input slice).
2020-08-15 17:32:05 +00:00
VerifyHeaders(chain ChainHeaderReader, headers []*types.Header, seals []bool) (func(), <-chan error)
// VerifyUncles verifies that the given block's uncles conform to the consensus
// rules of a given engine.
VerifyUncles(chain ChainReader, block *types.Block) error
// VerifySeal checks whether the crypto seal on a header is valid according to
// the consensus rules of the given engine.
VerifySeal(chain ChainHeaderReader, header *types.Header) error
// Prepare initializes the consensus fields of a block header according to the
// rules of a particular engine. The changes are executed inline.
Prepare(chain ChainHeaderReader, header *types.Header) error
// Finalize runs any post-transaction state modifications (e.g. block rewards)
// but does not assemble the block.
//
// Note: The block header and state database might be updated to reflect any
// consensus rules that happen at finalization (e.g. block rewards).
2020-08-15 15:30:34 +00:00
Finalize(config *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []*types.Transaction, uncles []*types.Header)
// FinalizeAndAssemble runs any post-transaction state modifications (e.g. block
// rewards) and assembles the final block.
//
// Note: The block header and state database might be updated to reflect any
// consensus rules that happen at finalization (e.g. block rewards).
2020-08-14 16:03:20 +00:00
FinalizeAndAssemble(config *params.ChainConfig, header *types.Header, state *state.IntraBlockState, txs []*types.Transaction,
uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)
// Seal generates a new sealing request for the given input block and pushes
// the result into the given channel.
//
// Note, the method returns immediately and will send the result async. More
2018-09-03 14:49:00 +00:00
// than one result may also be returned depending on the consensus algorithm.
2020-08-15 17:32:05 +00:00
Seal(ctx Cancel, chain ChainHeaderReader, block *types.Block, results chan<- ResultWithContext, stop <-chan struct{}) error
// SealHash returns the hash of a block prior to it being sealed.
SealHash(header *types.Header) common.Hash
// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
// that a new block should have.
CalcDifficulty(chain ChainHeaderReader, time, parentTime uint64, parentDifficulty, parentNumber *big.Int, parentHash, parentUncleHash common.Hash) *big.Int
// APIs returns the RPC APIs this consensus engine provides.
APIs(chain ChainHeaderReader) []rpc.API
// Close terminates any background threads maintained by the consensus engine.
Close() error
Extract validating interface (#1120) * interface * generalize interface * linters * fix deadlock * fix linters * close goroutine * fix * debug * id+ttl * refactor downloader tests * tests * lru * handle genesis, extract fake consensuses * fix fake consensus * test uncles, verify * after a new master * fmt * fix close * debug * debug * fix chain length * remove test field * use single account * fix data race on closing channel * remove postponed blocks queue * miner test * VerifyHeaderRequests * fmt * fmt * fix data race * handle validating errors * simplify matchParents * remove copy-paste * move sort to constructor * clean up * debug for 10 parents * debug * debug * batch responses * batch requests * works for many ancestors * remove debug * always Close an engine * linters * ancestors deduplication * fix test * reduce interface * api * clique * green clique sync * stable * perpermance per second * full sync * linters * gitignore * deps * fix panic after master merge * init consensus * clique tests * fix tests * fix tests * clean up * reuse snap * store vefified snapshots * optimize snapshots * safe close * cleanup loop * after downloader * downloader and consensus tests * update tests * hack.go * clique flags * fix cliuqe config * review * gitignore * remove additional bucket * blk/sec instead of blk/microsecond * rename * deps * optimize * debug * test * tests without extracted validation process * same base performance as on master * benchmark * simplify ethash verification * ethash * ethash * linters * ethash * master stats * cleanup * gomod * linters * tests * better locks * Fix * Remove logging for verifyHeaders * Verification speed in the logs * Fix compile error Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-02-25 19:40:45 +00:00
Verifier
}
// PoW is a consensus engine based on proof-of-work.
type PoW interface {
Engine
// Hashrate returns the current mining hashrate of a PoW consensus engine.
Hashrate() float64
}
Extract validating interface (#1120) * interface * generalize interface * linters * fix deadlock * fix linters * close goroutine * fix * debug * id+ttl * refactor downloader tests * tests * lru * handle genesis, extract fake consensuses * fix fake consensus * test uncles, verify * after a new master * fmt * fix close * debug * debug * fix chain length * remove test field * use single account * fix data race on closing channel * remove postponed blocks queue * miner test * VerifyHeaderRequests * fmt * fmt * fix data race * handle validating errors * simplify matchParents * remove copy-paste * move sort to constructor * clean up * debug for 10 parents * debug * debug * batch responses * batch requests * works for many ancestors * remove debug * always Close an engine * linters * ancestors deduplication * fix test * reduce interface * api * clique * green clique sync * stable * perpermance per second * full sync * linters * gitignore * deps * fix panic after master merge * init consensus * clique tests * fix tests * fix tests * clean up * reuse snap * store vefified snapshots * optimize snapshots * safe close * cleanup loop * after downloader * downloader and consensus tests * update tests * hack.go * clique flags * fix cliuqe config * review * gitignore * remove additional bucket * blk/sec instead of blk/microsecond * rename * deps * optimize * debug * test * tests without extracted validation process * same base performance as on master * benchmark * simplify ethash verification * ethash * ethash * linters * ethash * master stats * cleanup * gomod * linters * tests * better locks * Fix * Remove logging for verifyHeaders * Verification speed in the logs * Fix compile error Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-02-25 19:40:45 +00:00
// chain is only needed to get Config
type Verifier interface {
Verify(chain ChainHeaderReader, header *types.Header, parents []*types.Header, uncle bool, seal bool) error
AncestorsNeededForVerification(header *types.Header) int
PrepareHeaders(headers []*types.Header)
}