Skip to content

Commit 27bf3fe

Browse files
committed
Merge pull request bnb-chain#926 from binance-chain/develop
[R4R] Separate Processing and State Verification on BSC commit 73e6147 Merge: 84bb85c 2f2b98a Author: cryyl <[email protected]> Date: Fri May 6 16:48:35 2022 +0800 Merge remote-tracking branch 'bnb-chain/develop' into separate-node commit 84bb85c Author: zjubfd <[email protected]> Date: Fri May 6 16:42:40 2022 +0800 refine the description commit cc1940c Author: zjubfd <[email protected]> Date: Fri May 6 16:38:59 2022 +0800 change the flag description commit e440880 Author: dean65 <[email protected]> Date: Fri May 6 02:17:24 2022 +0800 fix TestFastNode commit 4001f37 Author: dean65 <[email protected]> Date: Fri May 6 02:16:57 2022 +0800 fix sorting difflayer.storage commit e93cced Author: dean65 <[email protected]> Date: Fri May 6 01:06:14 2022 +0800 use NewTimer instead of time.After commit f027818 Author: cryyl <[email protected]> Date: Thu May 5 19:10:52 2022 +0800 fix to resolve comments Signed-off-by: cryyl <[email protected]> commit ae3bdea Author: cryyl <[email protected]> Date: Thu May 5 19:10:52 2022 +0800 fix to resolve comments Signed-off-by: cryyl <[email protected]> commit 2f2b98a Merge: 0f5a4c8 55ef216 Author: zjubfd <[email protected]> Date: Thu May 5 17:26:16 2022 +0800 Merge pull request bnb-chain#888 from bnb-chain/develop [R4R] Release For BSC v1.1.10 commit 2dbc8c5 Merge: e9be0d4 0132f13 Author: realuncle <[email protected]> Date: Wed May 4 21:37:55 2022 +0800 Merge pull request bnb-chain#14 from node-real/separate-node-test close verifyTask when there is no valid peer and add UT tests commit 0132f13 Author: kyrie-yl <[email protected]> Date: Fri Apr 29 14:39:46 2022 +0800 add UT tests commit e9be0d4 Author: dean65 <[email protected]> Date: Fri Apr 29 10:01:16 2022 +0800 close verifyTask when length of verifyPeers is 0 commit 8929510 Author: dean65 <[email protected]> Date: Thu Apr 28 17:01:05 2022 +0800 fix tests commit 7490499 Author: dean65 <[email protected]> Date: Thu Apr 28 15:22:06 2022 +0800 setup default validator for blockchain commit ef3ec13 Author: dean65 <[email protected]> Date: Thu Apr 28 14:49:38 2022 +0800 fix lint error commit 4771d86 Merge: 5f22105 15bc254 Author: dean65 <[email protected]> Date: Thu Apr 28 14:36:59 2022 +0800 Merge remote-tracking branch 'origin/develop' into separate-node commit 5f22105 Author: j75689 <[email protected]> Date: Wed Apr 27 16:20:47 2022 +0800 add unit-test for fastnode commit 5a254c4 Author: j75689 <[email protected]> Date: Wed Apr 27 10:20:27 2022 +0800 add interval when getting ErrSnapshotStale commit b56c19c Author: j75689 <[email protected]> Date: Tue Apr 26 11:18:03 2022 +0800 fix diffhash issue commit 0f5a4c8 Author: Leon <[email protected]> Date: Mon Apr 25 10:47:02 2022 +0800 [R4R]fix:Shift panic for zero length of heads (bnb-chain#870) * fix:Shift panic for zero length of heads * fix: make sure peek before shift * refactor and update ut * refactor commit dfff219 Author: j75689 <[email protected]> Date: Mon Apr 25 10:25:23 2022 +0800 fix close of closed channel issue commit 3150755 Author: j75689 <[email protected]> Date: Sat Apr 23 16:29:41 2022 +0800 fix log format commit c840e7f Author: j75689 <[email protected]> Date: Sat Apr 23 06:02:29 2022 +0800 fix diffhash mismatch issue commit 734d17f Author: j75689 <[email protected]> Date: Sat Apr 23 06:01:23 2022 +0800 fix gracefull shutdown issue commit a73aad6 Author: j75689 <[email protected]> Date: Wed Apr 20 18:00:32 2022 +0800 fix validateBody commit 23913cf Author: j75689 <[email protected]> Date: Wed Apr 20 17:53:52 2022 +0800 remove unused code commit 2e6c33b Author: j75689 <[email protected]> Date: Wed Apr 20 15:52:24 2022 +0800 don't need to send verify task when node start commit e0cf707 Author: j75689 <[email protected]> Date: Wed Apr 20 15:48:47 2022 +0800 remove unused code commit c57fdd7 Author: j75689 <[email protected]> Date: Wed Apr 20 15:27:30 2022 +0800 fix comments commit 7ad4d02 Author: j75689 <[email protected]> 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 <[email protected]> Date: Tue Apr 19 17:54:37 2022 +0800 fixup! rewind to last non verified block when restart fast node commit 8c6d5a8 Author: j75689 <[email protected]> Date: Tue Apr 19 17:37:04 2022 +0800 fixup! rewind to last non verified block when restart fast node commit be53153 Author: j75689 <[email protected]> Date: Tue Apr 19 14:39:12 2022 +0800 rewind to last non verified block when restart fast node commit b3a701d Author: j75689 <[email protected]> Date: Tue Apr 19 13:40:17 2022 +0800 refactor block remote validation code commit f8c6a4a Author: j75689 <[email protected]> Date: Tue Apr 19 12:46:01 2022 +0800 change type of diffLayerChanCache to sync.Map commit 5675916 Author: j75689 <[email protected]> Date: Thu Apr 14 01:16:00 2022 +0800 fixup! put difflayer into verifyManage cache when node restart commit 34e8ce0 Author: j75689 <[email protected]> Date: Thu Apr 14 00:19:41 2022 +0800 remove testing code commit 161c467 Merge: b978ed3 1aeadc1 Author: j75689 <[email protected]> Date: Thu Apr 14 00:18:02 2022 +0800 Merge branch 'develop' into fast-node-fix commit b978ed3 Author: j75689 <[email protected]> Date: Wed Apr 13 18:40:49 2022 +0800 put difflayer into verifyManage cache when node restart commit 1aaab76 Author: kyrie-yl <[email protected]> Date: Thu Apr 7 00:21:26 2022 +0800 verify task get difflayer cache synchronously Signed-off-by: kyrie-yl <[email protected]> commit 74ecbf2 Merge: 859186f 1aeadc1 Author: zjubfd <[email protected]> Date: Fri Apr 8 19:06:42 2022 +0800 Merge pull request bnb-chain#850 from bnb-chain/develop [R4R] Release v1.1.9 commit 7b070c0 Author: kyrie-yl <[email protected]> Date: Wed Mar 2 10:07:14 2022 +0800 resolve comments Signed-off-by: kyrie-yl <[email protected]> commit 2ed75ab Author: kyrie-yl <[email protected]> Date: Tue Mar 1 13:58:20 2022 +0800 add metrics Signed-off-by: kyrie-yl <[email protected]> commit f7ef016 Author: kyrie-yl <[email protected]> Date: Thu Feb 24 17:13:40 2022 +0800 fast node verification and fix conflicts Signed-off-by: kyrie-yl <[email protected]> commit 1e46537 Merge: 6fffa8e 0ca4bc1 Author: zjubfd <[email protected]> Date: Mon Feb 14 16:59:55 2022 +0800 Merge pull request bnb-chain#763 from KeefeL/dev [R4R]Separate Processing and State Verification on BSC: sync develop branch commit 0ca4bc1 Merge: 6fffa8e fed2f35 Author: Keefe-Liu <[email protected]> Date: Mon Feb 14 12:33:53 2022 +0800 Merge branch 'develop' into separate-node commit fed2f35 Author: KeefeL <[email protected]> Date: Thu Jan 27 16:50:59 2022 +0800 testcases for trust protocol (bnb-chain#742) commit 529e66e Author: Keefe-Liu <[email protected]> Date: Tue Jan 25 21:18:56 2022 +0800 fix misc bugs of verify node commit 0405b68 Author: Keefe-Liu <[email protected]> Date: Fri Jan 21 18:17:06 2022 +0800 generate diff layer by replaying block commit 4905aab Author: Keefe-Liu <[email protected]> Date: Thu Jan 20 15:22:06 2022 +0800 testcases for getting root by diff hash commit c6e8652 Author: Keefe-Liu <[email protected]> Date: Tue Jan 11 16:17:03 2022 +0800 implement trust protocol and verify node commit 359906c Author: RealUncle <[email protected]> Date: Thu Dec 2 17:40:47 2021 +0800 implement the framework of fast node commit 859186f Merge: 74f6b61 21a3b11 Author: zjubfd <[email protected]> Date: Fri Jan 28 11:44:08 2022 +0800 Merge pull request bnb-chain#743 from binance-chain/develop [R4R] Release v1.1.8 commit 6fffa8e Author: KeefeL <[email protected]> Date: Thu Jan 27 16:50:59 2022 +0800 testcases for trust protocol (bnb-chain#742) commit 0b296e8 Author: Keefe-Liu <[email protected]> Date: Tue Jan 25 21:18:56 2022 +0800 fix misc bugs of verify node commit 6306002 Author: Keefe-Liu <[email protected]> Date: Fri Jan 21 18:17:06 2022 +0800 generate diff layer by replaying block commit 66dd9ea Author: Keefe-Liu <[email protected]> Date: Thu Jan 20 15:22:06 2022 +0800 testcases for getting root by diff hash commit 885aeb9 Author: Keefe-Liu <[email protected]> Date: Tue Jan 11 16:17:03 2022 +0800 implement trust protocol and verify node commit 3f266bf Author: RealUncle <[email protected]> Date: Thu Dec 2 17:40:47 2021 +0800 implement the framework of fast node
1 parent b5851ff commit 27bf3fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2639
-198
lines changed

cmd/geth/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ var (
7171
utils.NoUSBFlag,
7272
utils.DirectBroadcastFlag,
7373
utils.DisableSnapProtocolFlag,
74+
utils.DisableDiffProtocolFlag,
75+
utils.EnableTrustProtocolFlag,
7476
utils.DiffSyncFlag,
7577
utils.PipeCommitFlag,
7678
utils.RangeLimitFlag,
@@ -99,6 +101,7 @@ var (
99101
utils.TxPoolLifetimeFlag,
100102
utils.TxPoolReannounceTimeFlag,
101103
utils.SyncModeFlag,
104+
utils.TriesVerifyModeFlag,
102105
utils.ExitWhenSyncedFlag,
103106
utils.GCModeFlag,
104107
utils.SnapshotFlag,

cmd/geth/snapshot.go

+74-3
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ import (
3030

3131
"github.com/ethereum/go-ethereum/cmd/utils"
3232
"github.com/ethereum/go-ethereum/common"
33+
"github.com/ethereum/go-ethereum/core"
3334
"github.com/ethereum/go-ethereum/core/rawdb"
3435
"github.com/ethereum/go-ethereum/core/state"
3536
"github.com/ethereum/go-ethereum/core/state/pruner"
3637
"github.com/ethereum/go-ethereum/core/state/snapshot"
3738
"github.com/ethereum/go-ethereum/core/types"
3839
"github.com/ethereum/go-ethereum/crypto"
40+
"github.com/ethereum/go-ethereum/eth/ethconfig"
3941
"github.com/ethereum/go-ethereum/ethdb"
4042
"github.com/ethereum/go-ethereum/log"
43+
"github.com/ethereum/go-ethereum/metrics"
4144
"github.com/ethereum/go-ethereum/node"
4245
"github.com/ethereum/go-ethereum/rlp"
4346
"github.com/ethereum/go-ethereum/trie"
@@ -133,6 +136,32 @@ geth snapshot verify-state <state-root>
133136
will traverse the whole accounts and storages set based on the specified
134137
snapshot and recalculate the root hash of state for verification.
135138
In other words, this command does the snapshot to trie conversion.
139+
`,
140+
},
141+
{
142+
Name: "insecure-prune-all",
143+
Usage: "Prune all trie state data except genesis block, it will break storage for fullnode, only suitable for fast node " +
144+
"who do not need trie storage at all",
145+
ArgsUsage: "<genesisPath>",
146+
Action: utils.MigrateFlags(pruneAllState),
147+
Category: "MISCELLANEOUS COMMANDS",
148+
Flags: []cli.Flag{
149+
utils.DataDirFlag,
150+
utils.AncientFlag,
151+
utils.RopstenFlag,
152+
utils.RinkebyFlag,
153+
utils.GoerliFlag,
154+
},
155+
Description: `
156+
will prune all historical trie state data except genesis block.
157+
All trie nodes will be deleted from the database.
158+
159+
It expects the genesis file as argument.
160+
161+
WARNING: It's necessary to delete the trie clean cache after the pruning.
162+
If you specify another directory for the trie clean cache via "--cache.trie.journal"
163+
during the use of Geth, please also specify it here for correct deletion. Otherwise
164+
the trie clean cache with default directory will be deleted.
136165
`,
137166
},
138167
{
@@ -228,7 +257,7 @@ func accessDb(ctx *cli.Context, stack *node.Node) (ethdb.Database, error) {
228257
}
229258
headHeader := headBlock.Header()
230259
//Make sure the MPT and snapshot matches before pruning, otherwise the node can not start.
231-
snaptree, err := snapshot.New(chaindb, trie.NewDatabase(chaindb), 256, TriesInMemory, headBlock.Root(), false, false, false)
260+
snaptree, err := snapshot.New(chaindb, trie.NewDatabase(chaindb), 256, TriesInMemory, headBlock.Root(), false, false, false, false)
232261
if err != nil {
233262
log.Error("snaptree error", "err", err)
234263
return nil, err // The relevant snapshot(s) might not exist
@@ -396,6 +425,48 @@ func pruneState(ctx *cli.Context) error {
396425
return nil
397426
}
398427

428+
func pruneAllState(ctx *cli.Context) error {
429+
stack, _ := makeConfigNode(ctx)
430+
defer stack.Close()
431+
432+
genesisPath := ctx.Args().First()
433+
if len(genesisPath) == 0 {
434+
utils.Fatalf("Must supply path to genesis JSON file")
435+
}
436+
file, err := os.Open(genesisPath)
437+
if err != nil {
438+
utils.Fatalf("Failed to read genesis file: %v", err)
439+
}
440+
defer file.Close()
441+
442+
g := new(core.Genesis)
443+
if err := json.NewDecoder(file).Decode(g); err != nil {
444+
cfg := gethConfig{
445+
Eth: ethconfig.Defaults,
446+
Node: defaultNodeConfig(),
447+
Metrics: metrics.DefaultConfig,
448+
}
449+
450+
// Load config file.
451+
if err := loadConfig(genesisPath, &cfg); err != nil {
452+
utils.Fatalf("%v", err)
453+
}
454+
g = cfg.Eth.Genesis
455+
}
456+
457+
chaindb := utils.MakeChainDatabase(ctx, stack, false, false)
458+
pruner, err := pruner.NewAllPruner(chaindb)
459+
if err != nil {
460+
log.Error("Failed to open snapshot tree", "err", err)
461+
return err
462+
}
463+
if err = pruner.PruneAll(g); err != nil {
464+
log.Error("Failed to prune state", "err", err)
465+
return err
466+
}
467+
return nil
468+
}
469+
399470
func verifyState(ctx *cli.Context) error {
400471
stack, _ := makeConfigNode(ctx)
401472
defer stack.Close()
@@ -406,7 +477,7 @@ func verifyState(ctx *cli.Context) error {
406477
log.Error("Failed to load head block")
407478
return errors.New("no head block")
408479
}
409-
snaptree, err := snapshot.New(chaindb, trie.NewDatabase(chaindb), 256, 128, headBlock.Root(), false, false, false)
480+
snaptree, err := snapshot.New(chaindb, trie.NewDatabase(chaindb), 256, 128, headBlock.Root(), false, false, false, false)
410481
if err != nil {
411482
log.Error("Failed to open snapshot tree", "err", err)
412483
return err
@@ -658,7 +729,7 @@ func dumpState(ctx *cli.Context) error {
658729
return err
659730
}
660731
triesInMemory := ctx.GlobalUint64(utils.TriesInMemoryFlag.Name)
661-
snaptree, err := snapshot.New(db, trie.NewDatabase(db), int(triesInMemory), 256, root, false, false, false)
732+
snaptree, err := snapshot.New(db, trie.NewDatabase(db), int(triesInMemory), 256, root, false, false, false, false)
662733
if err != nil {
663734
return err
664735
}

cmd/geth/usage.go

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ var AppHelpFlagGroups = []flags.FlagGroup{
4141
utils.NoUSBFlag,
4242
utils.DirectBroadcastFlag,
4343
utils.DisableSnapProtocolFlag,
44+
utils.DisableDiffProtocolFlag,
45+
utils.EnableTrustProtocolFlag,
4446
utils.RangeLimitFlag,
4547
utils.SmartCardDaemonPathFlag,
4648
utils.NetworkIdFlag,
@@ -50,6 +52,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
5052
utils.RopstenFlag,
5153
utils.SepoliaFlag,
5254
utils.SyncModeFlag,
55+
utils.TriesVerifyModeFlag,
5356
utils.ExitWhenSyncedFlag,
5457
utils.GCModeFlag,
5558
utils.TxLookupLimitFlag,

cmd/utils/flags.go

+38-1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ var (
124124
Name: "disablesnapprotocol",
125125
Usage: "Disable snap protocol",
126126
}
127+
DisableDiffProtocolFlag = cli.BoolFlag{
128+
Name: "disablediffprotocol",
129+
Usage: "Disable diff protocol",
130+
}
131+
EnableTrustProtocolFlag = cli.BoolFlag{
132+
Name: "enabletrustprotocol",
133+
Usage: "Enable trust protocol",
134+
}
127135
DiffSyncFlag = cli.BoolFlag{
128136
Name: "diffsync",
129137
Usage: "Enable diffy sync, Please note that enable diffsync will improve the syncing speed, " +
@@ -285,6 +293,20 @@ var (
285293
Usage: "The layer of tries trees that keep in memory",
286294
Value: 128,
287295
}
296+
defaultVerifyMode = ethconfig.Defaults.TriesVerifyMode
297+
TriesVerifyModeFlag = TextMarshalerFlag{
298+
Name: "tries-verify-mode",
299+
Usage: `tries verify mode:
300+
"local(default): a normal full node with complete state world(both MPT and snapshot), merkle state root will
301+
be verified against the block header.",
302+
"full: a fast node with only snapshot state world. Merkle state root is verified by the trustworthy remote verify node
303+
by comparing the diffhash(an identify of difflayer generated by the block) and state root.",
304+
"insecure: same as full mode, except that it can tolerate without verifying the diffhash when verify node does not have it.",
305+
"none: no merkle state root verification at all, there is no need to setup or connect remote verify node at all,
306+
it is more light comparing to full and insecure mode, but get a very small chance that the state is not consistent
307+
with other peers."`,
308+
Value: &defaultVerifyMode,
309+
}
288310
OverrideBerlinFlag = cli.Uint64Flag{
289311
Name: "override.berlin",
290312
Usage: "Manually specify Berlin fork-block, overriding the bundled setting",
@@ -1646,6 +1668,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
16461668
if ctx.GlobalIsSet(DisableSnapProtocolFlag.Name) {
16471669
cfg.DisableSnapProtocol = ctx.GlobalBool(DisableSnapProtocolFlag.Name)
16481670
}
1671+
if ctx.GlobalIsSet(DisableDiffProtocolFlag.Name) {
1672+
cfg.DisableDiffProtocol = ctx.GlobalIsSet(DisableDiffProtocolFlag.Name)
1673+
}
1674+
if ctx.GlobalIsSet(EnableTrustProtocolFlag.Name) {
1675+
cfg.EnableTrustProtocol = ctx.GlobalIsSet(EnableTrustProtocolFlag.Name)
1676+
}
16491677
if ctx.GlobalIsSet(DiffSyncFlag.Name) {
16501678
cfg.DiffSync = ctx.GlobalBool(DiffSyncFlag.Name)
16511679
}
@@ -1679,6 +1707,14 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
16791707
if ctx.GlobalIsSet(TriesInMemoryFlag.Name) {
16801708
cfg.TriesInMemory = ctx.GlobalUint64(TriesInMemoryFlag.Name)
16811709
}
1710+
if ctx.GlobalIsSet(TriesVerifyModeFlag.Name) {
1711+
cfg.TriesVerifyMode = *GlobalTextMarshaler(ctx, TriesVerifyModeFlag.Name).(*core.VerifyMode)
1712+
// If a node sets verify mode to full or insecure, it's a fast node and need
1713+
// to verify blocks from verify nodes, then it should enable trust protocol.
1714+
if cfg.TriesVerifyMode.NeedRemoteVerify() {
1715+
cfg.EnableTrustProtocol = true
1716+
}
1717+
}
16821718
if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheSnapshotFlag.Name) {
16831719
cfg.SnapshotCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheSnapshotFlag.Name) / 100
16841720
}
@@ -1714,7 +1750,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
17141750
cfg.RPCTxFeeCap = ctx.GlobalFloat64(RPCGlobalTxFeeCapFlag.Name)
17151751
}
17161752
if ctx.GlobalIsSet(NoDiscoverFlag.Name) {
1717-
cfg.EthDiscoveryURLs, cfg.SnapDiscoveryURLs = []string{}, []string{}
1753+
cfg.EthDiscoveryURLs, cfg.SnapDiscoveryURLs, cfg.TrustDiscoveryURLs = []string{}, []string{}, []string{}
17181754
} else if ctx.GlobalIsSet(DNSDiscoveryFlag.Name) {
17191755
urls := ctx.GlobalString(DNSDiscoveryFlag.Name)
17201756
if urls == "" {
@@ -1828,6 +1864,7 @@ func SetDNSDiscoveryDefaults(cfg *ethconfig.Config, genesis common.Hash) {
18281864
if url := params.KnownDNSNetwork(genesis, protocol); url != "" {
18291865
cfg.EthDiscoveryURLs = []string{url}
18301866
cfg.SnapDiscoveryURLs = cfg.EthDiscoveryURLs
1867+
cfg.TrustDiscoveryURLs = cfg.EthDiscoveryURLs
18311868
}
18321869
}
18331870

core/block_validator.go

+29-4
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,38 @@ import (
3030

3131
const badBlockCacheExpire = 30 * time.Second
3232

33+
type BlockValidatorOption func(*BlockValidator) *BlockValidator
34+
35+
func EnableRemoteVerifyManager(remoteValidator *remoteVerifyManager) BlockValidatorOption {
36+
return func(bv *BlockValidator) *BlockValidator {
37+
bv.remoteValidator = remoteValidator
38+
return bv
39+
}
40+
}
41+
3342
// BlockValidator is responsible for validating block headers, uncles and
3443
// processed state.
3544
//
3645
// BlockValidator implements Validator.
3746
type BlockValidator struct {
38-
config *params.ChainConfig // Chain configuration options
39-
bc *BlockChain // Canonical block chain
40-
engine consensus.Engine // Consensus engine used for validating
47+
config *params.ChainConfig // Chain configuration options
48+
bc *BlockChain // Canonical block chain
49+
engine consensus.Engine // Consensus engine used for validating
50+
remoteValidator *remoteVerifyManager
4151
}
4252

4353
// NewBlockValidator returns a new block validator which is safe for re-use
44-
func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engine consensus.Engine) *BlockValidator {
54+
func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engine consensus.Engine, opts ...BlockValidatorOption) *BlockValidator {
4555
validator := &BlockValidator{
4656
config: config,
4757
engine: engine,
4858
bc: blockchain,
4959
}
60+
61+
for _, opt := range opts {
62+
validator = opt(validator)
63+
}
64+
5065
return validator
5166
}
5267

@@ -92,6 +107,12 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
92107
}
93108
return nil
94109
},
110+
func() error {
111+
if v.remoteValidator != nil && !v.remoteValidator.AncestorVerified(block.Header()) {
112+
return fmt.Errorf("%w, number: %s, hash: %s", ErrAncestorHasNotBeenVerified, block.Number(), block.Hash())
113+
}
114+
return nil
115+
},
95116
}
96117
validateRes := make(chan error, len(validateFuns))
97118
for _, f := range validateFuns {
@@ -171,6 +192,10 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
171192
return err
172193
}
173194

195+
func (v *BlockValidator) RemoteVerifyManager() *remoteVerifyManager {
196+
return v.remoteValidator
197+
}
198+
174199
// CalcGasLimit computes the gas limit of the next block after parent. It aims
175200
// to keep the baseline gas close to the provided target, and increase it towards
176201
// the target if the baseline gas is lower.

0 commit comments

Comments
 (0)