Skip to content

Commit

Permalink
Merge pull request bnb-chain#926 from binance-chain/develop
Browse files Browse the repository at this point in the history
[R4R] Separate Processing and State Verification on BSC

commit 73e6147
Merge: 84bb85c 2f2b98a
Author: cryyl <1226241521@qq.com>
Date:   Fri May 6 16:48:35 2022 +0800

    Merge remote-tracking branch 'bnb-chain/develop' into separate-node

commit 84bb85c
Author: zjubfd <296179868@qq.com>
Date:   Fri May 6 16:42:40 2022 +0800

    refine the description

commit cc1940c
Author: zjubfd <296179868@qq.com>
Date:   Fri May 6 16:38:59 2022 +0800

    change the flag description

commit e440880
Author: dean65 <dean950605@gmail.com>
Date:   Fri May 6 02:17:24 2022 +0800

    fix TestFastNode

commit 4001f37
Author: dean65 <dean950605@gmail.com>
Date:   Fri May 6 02:16:57 2022 +0800

    fix sorting difflayer.storage

commit e93cced
Author: dean65 <dean950605@gmail.com>
Date:   Fri May 6 01:06:14 2022 +0800

    use NewTimer instead of time.After

commit f027818
Author: cryyl <1226241521@qq.com>
Date:   Thu May 5 19:10:52 2022 +0800

    fix to resolve comments

    Signed-off-by: cryyl <1226241521@qq.com>

commit ae3bdea
Author: cryyl <1226241521@qq.com>
Date:   Thu May 5 19:10:52 2022 +0800

    fix to resolve comments

    Signed-off-by: cryyl <1226241521@qq.com>

commit 2f2b98a
Merge: 0f5a4c8 55ef216
Author: zjubfd <296179868@qq.com>
Date:   Thu May 5 17:26:16 2022 +0800

    Merge pull request #888 from bnb-chain/develop

    [R4R] Release For BSC v1.1.10

commit 2dbc8c5
Merge: e9be0d4 0132f13
Author: realuncle <90668111+realuncle@users.noreply.github.com>
Date:   Wed May 4 21:37:55 2022 +0800

    Merge pull request #14 from node-real/separate-node-test

    close verifyTask when there is no valid peer and add UT tests

commit 0132f13
Author: kyrie-yl <yl.on.the.way@gmail.com>
Date:   Fri Apr 29 14:39:46 2022 +0800

    add UT tests

commit e9be0d4
Author: dean65 <dean950605@gmail.com>
Date:   Fri Apr 29 10:01:16 2022 +0800

    close verifyTask when length of verifyPeers is 0

commit 8929510
Author: dean65 <dean950605@gmail.com>
Date:   Thu Apr 28 17:01:05 2022 +0800

    fix tests

commit 7490499
Author: dean65 <dean950605@gmail.com>
Date:   Thu Apr 28 15:22:06 2022 +0800

    setup default validator for blockchain

commit ef3ec13
Author: dean65 <dean950605@gmail.com>
Date:   Thu Apr 28 14:49:38 2022 +0800

    fix lint error

commit 4771d86
Merge: 5f22105 15bc254
Author: dean65 <dean950605@gmail.com>
Date:   Thu Apr 28 14:36:59 2022 +0800

    Merge remote-tracking branch 'origin/develop' into separate-node

commit 5f22105
Author: j75689 <j75689@gmail.com>
Date:   Wed Apr 27 16:20:47 2022 +0800

    add unit-test for fastnode

commit 5a254c4
Author: j75689 <j75689@gmail.com>
Date:   Wed Apr 27 10:20:27 2022 +0800

    add interval when getting ErrSnapshotStale

commit b56c19c
Author: j75689 <j75689@gmail.com>
Date:   Tue Apr 26 11:18:03 2022 +0800

    fix diffhash issue

commit 0f5a4c8
Author: Leon <316032931@qq.com>
Date:   Mon Apr 25 10:47:02 2022 +0800

    [R4R]fix:Shift panic for zero length of heads (#870)

    * fix:Shift panic for zero length of heads

    * fix: make sure peek before shift

    * refactor and update ut

    * refactor

commit dfff219
Author: j75689 <j75689@gmail.com>
Date:   Mon Apr 25 10:25:23 2022 +0800

    fix close of closed channel issue

commit 3150755
Author: j75689 <j75689@gmail.com>
Date:   Sat Apr 23 16:29:41 2022 +0800

    fix log format

commit c840e7f
Author: j75689 <j75689@gmail.com>
Date:   Sat Apr 23 06:02:29 2022 +0800

    fix diffhash mismatch issue

commit 734d17f
Author: j75689 <j75689@gmail.com>
Date:   Sat Apr 23 06:01:23 2022 +0800

    fix gracefull shutdown issue

commit a73aad6
Author: j75689 <j75689@gmail.com>
Date:   Wed Apr 20 18:00:32 2022 +0800

    fix validateBody

commit 23913cf
Author: j75689 <j75689@gmail.com>
Date:   Wed Apr 20 17:53:52 2022 +0800

    remove unused code

commit 2e6c33b
Author: j75689 <j75689@gmail.com>
Date:   Wed Apr 20 15:52:24 2022 +0800

    don't need to send verify task when node start

commit e0cf707
Author: j75689 <j75689@gmail.com>
Date:   Wed Apr 20 15:48:47 2022 +0800

    remove unused code

commit c57fdd7
Author: j75689 <j75689@gmail.com>
Date:   Wed Apr 20 15:27:30 2022 +0800

    fix comments

commit 7ad4d02
Author: j75689 <j75689@gmail.com>
Date:   Wed Apr 20 15:13:51 2022 +0800

    Revert "change type of diffLayerChanCache to sync.Map"

    This reverts commit f8c6a4a.

commit 1e44aa6
Author: j75689 <j75689@gmail.com>
Date:   Tue Apr 19 17:54:37 2022 +0800

    fixup! rewind to last non verified block when restart fast node

commit 8c6d5a8
Author: j75689 <j75689@gmail.com>
Date:   Tue Apr 19 17:37:04 2022 +0800

    fixup! rewind to last non verified block when restart fast node

commit be53153
Author: j75689 <j75689@gmail.com>
Date:   Tue Apr 19 14:39:12 2022 +0800

    rewind to last non verified block when restart fast node

commit b3a701d
Author: j75689 <j75689@gmail.com>
Date:   Tue Apr 19 13:40:17 2022 +0800

    refactor block remote validation code

commit f8c6a4a
Author: j75689 <j75689@gmail.com>
Date:   Tue Apr 19 12:46:01 2022 +0800

    change type of diffLayerChanCache to sync.Map

commit 5675916
Author: j75689 <j75689@gmail.com>
Date:   Thu Apr 14 01:16:00 2022 +0800

    fixup! put difflayer into verifyManage cache when node restart

commit 34e8ce0
Author: j75689 <j75689@gmail.com>
Date:   Thu Apr 14 00:19:41 2022 +0800

    remove testing code

commit 161c467
Merge: b978ed3 1aeadc1
Author: j75689 <j75689@gmail.com>
Date:   Thu Apr 14 00:18:02 2022 +0800

    Merge branch 'develop' into fast-node-fix

commit b978ed3
Author: j75689 <j75689@gmail.com>
Date:   Wed Apr 13 18:40:49 2022 +0800

    put difflayer into verifyManage cache when node restart

commit 1aaab76
Author: kyrie-yl <yl.on.the.way@gmail.com>
Date:   Thu Apr 7 00:21:26 2022 +0800

    verify task get difflayer cache synchronously

    Signed-off-by: kyrie-yl <yl.on.the.way@gmail.com>

commit 74ecbf2
Merge: 859186f 1aeadc1
Author: zjubfd <296179868@qq.com>
Date:   Fri Apr 8 19:06:42 2022 +0800

    Merge pull request #850 from bnb-chain/develop

    [R4R] Release v1.1.9

commit 7b070c0
Author: kyrie-yl <yl.on.the.way@gmail.com>
Date:   Wed Mar 2 10:07:14 2022 +0800

    resolve comments

    Signed-off-by: kyrie-yl <yl.on.the.way@gmail.com>

commit 2ed75ab
Author: kyrie-yl <yl.on.the.way@gmail.com>
Date:   Tue Mar 1 13:58:20 2022 +0800

    add metrics

    Signed-off-by: kyrie-yl <yl.on.the.way@gmail.com>

commit f7ef016
Author: kyrie-yl <yl.on.the.way@gmail.com>
Date:   Thu Feb 24 17:13:40 2022 +0800

    fast node verification and fix conflicts

    Signed-off-by: kyrie-yl <yl.on.the.way@gmail.com>

commit 1e46537
Merge: 6fffa8e 0ca4bc1
Author: zjubfd <296179868@qq.com>
Date:   Mon Feb 14 16:59:55 2022 +0800

    Merge pull request #763 from KeefeL/dev

    [R4R]Separate Processing and State Verification on BSC: sync develop branch

commit 0ca4bc1
Merge: 6fffa8e fed2f35
Author: Keefe-Liu <bianze.kernel@gmail.com>
Date:   Mon Feb 14 12:33:53 2022 +0800

    Merge branch 'develop' into separate-node

commit fed2f35
Author: KeefeL <90749943+KeefeL@users.noreply.github.com>
Date:   Thu Jan 27 16:50:59 2022 +0800

    testcases for trust protocol (#742)

commit 529e66e
Author: Keefe-Liu <bianze.kernel@gmail.com>
Date:   Tue Jan 25 21:18:56 2022 +0800

    fix misc bugs of verify node

commit 0405b68
Author: Keefe-Liu <bianze.kernel@gmail.com>
Date:   Fri Jan 21 18:17:06 2022 +0800

    generate diff layer by replaying block

commit 4905aab
Author: Keefe-Liu <bianze.kernel@gmail.com>
Date:   Thu Jan 20 15:22:06 2022 +0800

    testcases for getting root by diff hash

commit c6e8652
Author: Keefe-Liu <bianze.kernel@gmail.com>
Date:   Tue Jan 11 16:17:03 2022 +0800

    implement trust protocol and verify node

commit 359906c
Author: RealUncle <walt@nodereal.io>
Date:   Thu Dec 2 17:40:47 2021 +0800

    implement the framework of fast node

commit 859186f
Merge: 74f6b61 21a3b11
Author: zjubfd <296179868@qq.com>
Date:   Fri Jan 28 11:44:08 2022 +0800

    Merge pull request #743 from binance-chain/develop

    [R4R] Release v1.1.8

commit 6fffa8e
Author: KeefeL <90749943+KeefeL@users.noreply.github.com>
Date:   Thu Jan 27 16:50:59 2022 +0800

    testcases for trust protocol (#742)

commit 0b296e8
Author: Keefe-Liu <bianze.kernel@gmail.com>
Date:   Tue Jan 25 21:18:56 2022 +0800

    fix misc bugs of verify node

commit 6306002
Author: Keefe-Liu <bianze.kernel@gmail.com>
Date:   Fri Jan 21 18:17:06 2022 +0800

    generate diff layer by replaying block

commit 66dd9ea
Author: Keefe-Liu <bianze.kernel@gmail.com>
Date:   Thu Jan 20 15:22:06 2022 +0800

    testcases for getting root by diff hash

commit 885aeb9
Author: Keefe-Liu <bianze.kernel@gmail.com>
Date:   Tue Jan 11 16:17:03 2022 +0800

    implement trust protocol and verify node

commit 3f266bf
Author: RealUncle <walt@nodereal.io>
Date:   Thu Dec 2 17:40:47 2021 +0800

    implement the framework of fast node
  • Loading branch information
j75689 committed Jun 1, 2022
1 parent 338b661 commit a8bee46
Show file tree
Hide file tree
Showing 48 changed files with 2,639 additions and 198 deletions.
3 changes: 3 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ var (
utils.NoUSBFlag,
utils.DirectBroadcastFlag,
utils.DisableSnapProtocolFlag,
utils.DisableDiffProtocolFlag,
utils.EnableTrustProtocolFlag,
utils.DiffSyncFlag,
utils.PipeCommitFlag,
utils.RangeLimitFlag,
Expand Down Expand Up @@ -99,6 +101,7 @@ var (
utils.TxPoolLifetimeFlag,
utils.TxPoolReannounceTimeFlag,
utils.SyncModeFlag,
utils.TriesVerifyModeFlag,
utils.ExitWhenSyncedFlag,
utils.GCModeFlag,
utils.SnapshotFlag,
Expand Down
77 changes: 74 additions & 3 deletions cmd/geth/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ import (

"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/state/pruner"
"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
Expand Down Expand Up @@ -133,6 +136,32 @@ geth snapshot verify-state <state-root>
will traverse the whole accounts and storages set based on the specified
snapshot and recalculate the root hash of state for verification.
In other words, this command does the snapshot to trie conversion.
`,
},
{
Name: "insecure-prune-all",
Usage: "Prune all trie state data except genesis block, it will break storage for fullnode, only suitable for fast node " +
"who do not need trie storage at all",
ArgsUsage: "<genesisPath>",
Action: utils.MigrateFlags(pruneAllState),
Category: "MISCELLANEOUS COMMANDS",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.AncientFlag,
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
},
Description: `
will prune all historical trie state data except genesis block.
All trie nodes will be deleted from the database.
It expects the genesis file as argument.
WARNING: It's necessary to delete the trie clean cache after the pruning.
If you specify another directory for the trie clean cache via "--cache.trie.journal"
during the use of Geth, please also specify it here for correct deletion. Otherwise
the trie clean cache with default directory will be deleted.
`,
},
{
Expand Down Expand Up @@ -228,7 +257,7 @@ func accessDb(ctx *cli.Context, stack *node.Node) (ethdb.Database, error) {
}
headHeader := headBlock.Header()
//Make sure the MPT and snapshot matches before pruning, otherwise the node can not start.
snaptree, err := snapshot.New(chaindb, trie.NewDatabase(chaindb), 256, TriesInMemory, headBlock.Root(), false, false, false)
snaptree, err := snapshot.New(chaindb, trie.NewDatabase(chaindb), 256, TriesInMemory, headBlock.Root(), false, false, false, false)
if err != nil {
log.Error("snaptree error", "err", err)
return nil, err // The relevant snapshot(s) might not exist
Expand Down Expand Up @@ -396,6 +425,48 @@ func pruneState(ctx *cli.Context) error {
return nil
}

func pruneAllState(ctx *cli.Context) error {
stack, _ := makeConfigNode(ctx)
defer stack.Close()

genesisPath := ctx.Args().First()
if len(genesisPath) == 0 {
utils.Fatalf("Must supply path to genesis JSON file")
}
file, err := os.Open(genesisPath)
if err != nil {
utils.Fatalf("Failed to read genesis file: %v", err)
}
defer file.Close()

g := new(core.Genesis)
if err := json.NewDecoder(file).Decode(g); err != nil {
cfg := gethConfig{
Eth: ethconfig.Defaults,
Node: defaultNodeConfig(),
Metrics: metrics.DefaultConfig,
}

// Load config file.
if err := loadConfig(genesisPath, &cfg); err != nil {
utils.Fatalf("%v", err)
}
g = cfg.Eth.Genesis
}

chaindb := utils.MakeChainDatabase(ctx, stack, false, false)
pruner, err := pruner.NewAllPruner(chaindb)
if err != nil {
log.Error("Failed to open snapshot tree", "err", err)
return err
}
if err = pruner.PruneAll(g); err != nil {
log.Error("Failed to prune state", "err", err)
return err
}
return nil
}

func verifyState(ctx *cli.Context) error {
stack, _ := makeConfigNode(ctx)
defer stack.Close()
Expand All @@ -406,7 +477,7 @@ func verifyState(ctx *cli.Context) error {
log.Error("Failed to load head block")
return errors.New("no head block")
}
snaptree, err := snapshot.New(chaindb, trie.NewDatabase(chaindb), 256, 128, headBlock.Root(), false, false, false)
snaptree, err := snapshot.New(chaindb, trie.NewDatabase(chaindb), 256, 128, headBlock.Root(), false, false, false, false)
if err != nil {
log.Error("Failed to open snapshot tree", "err", err)
return err
Expand Down Expand Up @@ -658,7 +729,7 @@ func dumpState(ctx *cli.Context) error {
return err
}
triesInMemory := ctx.GlobalUint64(utils.TriesInMemoryFlag.Name)
snaptree, err := snapshot.New(db, trie.NewDatabase(db), int(triesInMemory), 256, root, false, false, false)
snaptree, err := snapshot.New(db, trie.NewDatabase(db), int(triesInMemory), 256, root, false, false, false, false)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.NoUSBFlag,
utils.DirectBroadcastFlag,
utils.DisableSnapProtocolFlag,
utils.DisableDiffProtocolFlag,
utils.EnableTrustProtocolFlag,
utils.RangeLimitFlag,
utils.SmartCardDaemonPathFlag,
utils.NetworkIdFlag,
Expand All @@ -50,6 +52,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.RopstenFlag,
utils.SepoliaFlag,
utils.SyncModeFlag,
utils.TriesVerifyModeFlag,
utils.ExitWhenSyncedFlag,
utils.GCModeFlag,
utils.TxLookupLimitFlag,
Expand Down
39 changes: 38 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ var (
Name: "disablesnapprotocol",
Usage: "Disable snap protocol",
}
DisableDiffProtocolFlag = cli.BoolFlag{
Name: "disablediffprotocol",
Usage: "Disable diff protocol",
}
EnableTrustProtocolFlag = cli.BoolFlag{
Name: "enabletrustprotocol",
Usage: "Enable trust protocol",
}
DiffSyncFlag = cli.BoolFlag{
Name: "diffsync",
Usage: "Enable diffy sync, Please note that enable diffsync will improve the syncing speed, " +
Expand Down Expand Up @@ -285,6 +293,20 @@ var (
Usage: "The layer of tries trees that keep in memory",
Value: 128,
}
defaultVerifyMode = ethconfig.Defaults.TriesVerifyMode
TriesVerifyModeFlag = TextMarshalerFlag{
Name: "tries-verify-mode",
Usage: `tries verify mode:
"local(default): a normal full node with complete state world(both MPT and snapshot), merkle state root will
be verified against the block header.",
"full: a fast node with only snapshot state world. Merkle state root is verified by the trustworthy remote verify node
by comparing the diffhash(an identify of difflayer generated by the block) and state root.",
"insecure: same as full mode, except that it can tolerate without verifying the diffhash when verify node does not have it.",
"none: no merkle state root verification at all, there is no need to setup or connect remote verify node at all,
it is more light comparing to full and insecure mode, but get a very small chance that the state is not consistent
with other peers."`,
Value: &defaultVerifyMode,
}
OverrideBerlinFlag = cli.Uint64Flag{
Name: "override.berlin",
Usage: "Manually specify Berlin fork-block, overriding the bundled setting",
Expand Down Expand Up @@ -1646,6 +1668,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.GlobalIsSet(DisableSnapProtocolFlag.Name) {
cfg.DisableSnapProtocol = ctx.GlobalBool(DisableSnapProtocolFlag.Name)
}
if ctx.GlobalIsSet(DisableDiffProtocolFlag.Name) {
cfg.DisableDiffProtocol = ctx.GlobalIsSet(DisableDiffProtocolFlag.Name)
}
if ctx.GlobalIsSet(EnableTrustProtocolFlag.Name) {
cfg.EnableTrustProtocol = ctx.GlobalIsSet(EnableTrustProtocolFlag.Name)
}
if ctx.GlobalIsSet(DiffSyncFlag.Name) {
cfg.DiffSync = ctx.GlobalBool(DiffSyncFlag.Name)
}
Expand Down Expand Up @@ -1679,6 +1707,14 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.GlobalIsSet(TriesInMemoryFlag.Name) {
cfg.TriesInMemory = ctx.GlobalUint64(TriesInMemoryFlag.Name)
}
if ctx.GlobalIsSet(TriesVerifyModeFlag.Name) {
cfg.TriesVerifyMode = *GlobalTextMarshaler(ctx, TriesVerifyModeFlag.Name).(*core.VerifyMode)
// If a node sets verify mode to full or insecure, it's a fast node and need
// to verify blocks from verify nodes, then it should enable trust protocol.
if cfg.TriesVerifyMode.NeedRemoteVerify() {
cfg.EnableTrustProtocol = true
}
}
if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheSnapshotFlag.Name) {
cfg.SnapshotCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheSnapshotFlag.Name) / 100
}
Expand Down Expand Up @@ -1714,7 +1750,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.RPCTxFeeCap = ctx.GlobalFloat64(RPCGlobalTxFeeCapFlag.Name)
}
if ctx.GlobalIsSet(NoDiscoverFlag.Name) {
cfg.EthDiscoveryURLs, cfg.SnapDiscoveryURLs = []string{}, []string{}
cfg.EthDiscoveryURLs, cfg.SnapDiscoveryURLs, cfg.TrustDiscoveryURLs = []string{}, []string{}, []string{}
} else if ctx.GlobalIsSet(DNSDiscoveryFlag.Name) {
urls := ctx.GlobalString(DNSDiscoveryFlag.Name)
if urls == "" {
Expand Down Expand Up @@ -1828,6 +1864,7 @@ func SetDNSDiscoveryDefaults(cfg *ethconfig.Config, genesis common.Hash) {
if url := params.KnownDNSNetwork(genesis, protocol); url != "" {
cfg.EthDiscoveryURLs = []string{url}
cfg.SnapDiscoveryURLs = cfg.EthDiscoveryURLs
cfg.TrustDiscoveryURLs = cfg.EthDiscoveryURLs
}
}

Expand Down
33 changes: 29 additions & 4 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,38 @@ import (

const badBlockCacheExpire = 30 * time.Second

type BlockValidatorOption func(*BlockValidator) *BlockValidator

func EnableRemoteVerifyManager(remoteValidator *remoteVerifyManager) BlockValidatorOption {
return func(bv *BlockValidator) *BlockValidator {
bv.remoteValidator = remoteValidator
return bv
}
}

// BlockValidator is responsible for validating block headers, uncles and
// processed state.
//
// BlockValidator implements Validator.
type BlockValidator struct {
config *params.ChainConfig // Chain configuration options
bc *BlockChain // Canonical block chain
engine consensus.Engine // Consensus engine used for validating
config *params.ChainConfig // Chain configuration options
bc *BlockChain // Canonical block chain
engine consensus.Engine // Consensus engine used for validating
remoteValidator *remoteVerifyManager
}

// NewBlockValidator returns a new block validator which is safe for re-use
func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engine consensus.Engine) *BlockValidator {
func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engine consensus.Engine, opts ...BlockValidatorOption) *BlockValidator {
validator := &BlockValidator{
config: config,
engine: engine,
bc: blockchain,
}

for _, opt := range opts {
validator = opt(validator)
}

return validator
}

Expand Down Expand Up @@ -92,6 +107,12 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
}
return nil
},
func() error {
if v.remoteValidator != nil && !v.remoteValidator.AncestorVerified(block.Header()) {
return fmt.Errorf("%w, number: %s, hash: %s", ErrAncestorHasNotBeenVerified, block.Number(), block.Hash())
}
return nil
},
}
validateRes := make(chan error, len(validateFuns))
for _, f := range validateFuns {
Expand Down Expand Up @@ -171,6 +192,10 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
return err
}

func (v *BlockValidator) RemoteVerifyManager() *remoteVerifyManager {
return v.remoteValidator
}

// CalcGasLimit computes the gas limit of the next block after parent. It aims
// to keep the baseline gas close to the provided target, and increase it towards
// the target if the baseline gas is lower.
Expand Down
Loading

0 comments on commit a8bee46

Please sign in to comment.