package dummy
import (
"errors"
"fmt"
"golang.org/x/crypto/sha3"
"math/big"
"runtime"
"time"
"github.com/ava-labs/coreth/consensus"
"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/rpc"
"github.com/ava-labs/go-ethereum/common"
"github.com/ava-labs/go-ethereum/rlp"
mapset "github.com/deckarep/golang-set"
)
type OnFinalizeCallbackType = func(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header)
type OnFinalizeAndAssembleCallbackType = func(state *state.StateDB, txs []*types.Transaction) ([]byte, error)
type OnAPIsCallbackType = func(consensus.ChainReader) []rpc.API
type OnExtraStateChangeType = func(block *types.Block, statedb *state.StateDB) error
type ConsensusCallbacks struct {
OnSeal func(*types.Block) error
OnSealHash func(*types.Header)
OnAPIs OnAPIsCallbackType
OnFinalize OnFinalizeCallbackType
OnFinalizeAndAssemble OnFinalizeAndAssembleCallbackType
OnExtraStateChange OnExtraStateChangeType
}
type DummyEngine struct {
cb *ConsensusCallbacks
}
func NewDummyEngine(cb *ConsensusCallbacks) *DummyEngine {
return &DummyEngine{cb: cb}
}
var (
allowedFutureBlockTime = 15 * time.Second // Max time from current time allowed for blocks, before they're considered future blocks
)
var (
maxUncles = 2 // Maximum number of uncles allowed in a single block
errTooManyUncles = errors.New("too many uncles")
errZeroBlockTime = errors.New("timestamp equals parent's")
errDuplicateUncle = errors.New("duplicate uncle")
errUncleIsAncestor = errors.New("uncle is ancestor")
errDanglingUncle = errors.New("uncle's parent is not ancestor")
)
// modified from consensus.go
func (self *DummyEngine) verifyHeader(chain consensus.ChainReader, header, parent *types.Header, uncle bool, seal bool) error {
// Ensure that the header's extra-data section is of a reasonable size
if uint64(len(header.Extra)) > params.MaximumExtraDataSize {
return fmt.Errorf("extra-data too long: %d > %d", len