-
Notifications
You must be signed in to change notification settings - Fork 0
fast node verification #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: separate-nodes
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,6 +121,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, " + | ||
|
|
@@ -259,9 +267,11 @@ var ( | |
| Usage: "The layer of tries trees that keep in memory", | ||
| Value: 128, | ||
| } | ||
| AllowInsecureNoTriesFlag = cli.BoolTFlag{ | ||
| Name: "allow-insecure-no-tries", | ||
| Usage: `Disable the tries state root verification, the state consistency is no longer 100% guaranteed, diffsync is not allowed if enabled. Do not enable it unless you know exactly what the consequence it will cause.`, | ||
| defaultVerifyMode = ethconfig.Defaults.TriesVerifyMode | ||
| TriesVerifyModeFlag = TextMarshalerFlag{ | ||
| Name: "tries-verify-mode", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better description is needed to let users understand the meaning of each mode |
||
| Usage: `tries verify mode: "local", "full", "light", "insecure"`, | ||
|
||
| Value: &defaultVerifyMode, | ||
| } | ||
| OverrideBerlinFlag = cli.Uint64Flag{ | ||
| Name: "override.berlin", | ||
|
|
@@ -1622,6 +1632,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) | ||
| } | ||
|
|
@@ -1652,8 +1668,18 @@ 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(AllowInsecureNoTriesFlag.Name) { | ||
| cfg.NoTries = ctx.GlobalBool(AllowInsecureNoTriesFlag.Name) | ||
| if ctx.GlobalIsSet(TriesVerifyModeFlag.Name) { | ||
| cfg.TriesVerifyMode = *GlobalTextMarshaler(ctx, TriesVerifyModeFlag.Name).(*core.VerifyMode) | ||
| //If a node sets verify mode to full or light, it's a fast node and need | ||
| //to verify blocks from verify nodes, then it should enable trust protocol. | ||
| if cfg.TriesVerifyMode == core.FullVerify || cfg.TriesVerifyMode == core.LightVerify { | ||
keefel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cfg.EnableTrustProtocol = true | ||
| } | ||
| //If a node sets verify node but not local, it's a fast node whose difflayer is not integral. | ||
| //So fast node should disable diff protocol. | ||
| if cfg.TriesVerifyMode != core.LocalVerify { | ||
|
||
| cfg.DisableDiffProtocol = true | ||
| } | ||
| } | ||
| if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheSnapshotFlag.Name) { | ||
| cfg.SnapshotCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheSnapshotFlag.Name) / 100 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -239,6 +239,7 @@ type BlockChain struct { | |
| engine consensus.Engine | ||
| validator Validator // Block and state validator interface | ||
| processor Processor // Block transaction processor interface | ||
| verifyManager *VerifyManager | ||
|
||
| vmConfig vm.Config | ||
|
|
||
| shouldPreserve func(*types.Block) bool // Function used to determine whether should preserve the given block. | ||
|
|
@@ -462,6 +463,16 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par | |
| return bc, nil | ||
| } | ||
|
|
||
| func (bc *BlockChain) StartVerify(peers VerifyPeers, allowUntrustedVerify bool) { | ||
|
||
| bc.verifyManager.peers = peers | ||
| bc.verifyManager.allowUntrustedVerify = allowUntrustedVerify | ||
| bc.verifyManager.Start() | ||
| } | ||
|
|
||
| func (bc *BlockChain) VerifyManger() *VerifyManager { | ||
| return bc.verifyManager | ||
| } | ||
|
|
||
| // GetVMConfig returns the block chain VM config. | ||
| func (bc *BlockChain) GetVMConfig() *vm.Config { | ||
| return &bc.vmConfig | ||
|
|
@@ -1191,6 +1202,9 @@ func (bc *BlockChain) Stop() { | |
| close(bc.quit) | ||
| bc.StopInsert() | ||
| bc.wg.Wait() | ||
| if bc.verifyManager != nil { | ||
| bc.verifyManager.Stop() | ||
| } | ||
|
|
||
| // Ensure that the entirety of the state snapshot is journalled to disk. | ||
| var snapBase common.Hash | ||
|
|
@@ -2009,6 +2023,11 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er | |
| log.Debug("Abort during block processing") | ||
| break | ||
| } | ||
| //For fast node, if the H-11 block has not been verified, stop processing blocks. | ||
|
||
| if bc.verifyManager != nil && bc.verifyManager.CheckAncestorVerified(block.Header()) { | ||
| log.Debug("Block ancestor has not been verified", "hash", block.Hash(), "number", block.Number()) | ||
| break | ||
| } | ||
| // If the header is a banned one, straight out abort | ||
| if BadHashes[block.Hash()] { | ||
| bc.reportBlock(block, nil, ErrBlacklistedHash) | ||
|
|
@@ -2052,6 +2071,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er | |
| lastCanon = block | ||
| continue | ||
| } | ||
|
|
||
| // Retrieve the parent block and it's state to execute on top | ||
| start := time.Now() | ||
|
|
||
|
|
@@ -2122,6 +2142,11 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er | |
| blockWriteTimer.Update(time.Since(substart)) | ||
| blockInsertTimer.UpdateSince(start) | ||
|
|
||
| //Start a routine to verify this block. | ||
| if bc.verifyManager != nil { | ||
| bc.verifyManager.NewBlockVerifyTask(block.Header()) | ||
|
||
| } | ||
|
|
||
| switch status { | ||
| case CanonStatTy: | ||
| log.Debug("Inserted new block", "number", block.Number(), "hash", block.Hash(), | ||
|
|
@@ -3020,8 +3045,15 @@ func EnablePersistDiff(limit uint64) BlockChainOption { | |
| } | ||
| } | ||
|
|
||
| func (bc *BlockChain) GetRootByDiffHash(blockNumber uint64, blockHash common.Hash, diffHash common.Hash) (*types.VerifyResult, error) { | ||
| var res types.VerifyResult | ||
| func EnableVerifyManager() BlockChainOption { | ||
| return func(chain *BlockChain) *BlockChain { | ||
| chain.verifyManager = NewVerifyManager(chain) | ||
| return chain | ||
| } | ||
| } | ||
|
|
||
| func (bc *BlockChain) GetRootByDiffHash(blockNumber uint64, blockHash common.Hash, diffHash common.Hash) (*VerifyResult, error) { | ||
| var res VerifyResult | ||
| res.BlockNumber = blockNumber | ||
| res.BlockHash = blockHash | ||
|
|
||
|
|
@@ -3076,6 +3108,10 @@ func (bc *BlockChain) GetRootByDiffHash(blockNumber uint64, blockHash common.Has | |
| return &res, nil | ||
| } | ||
|
|
||
| func (bc *BlockChain) GenerateDiffLayer(blockHash common.Hash) (*types.DiffLayer, error) { | ||
|
|
||
| } | ||
|
|
||
| func (bc *BlockChain) GetTrustedDiffLayer(blockHash common.Hash) *types.DiffLayer { | ||
| var diff *types.DiffLayer | ||
| if cached, ok := bc.diffLayerCache.Get(blockHash); ok { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,26 @@ func DeleteCanonicalHash(db ethdb.KeyValueWriter, number uint64) { | |
| } | ||
| } | ||
|
|
||
| func ReadTrustBlockHash(db ethdb.Reader, hash common.Hash) bool { | ||
|
||
| data, _ := db.Get(trustBlockHashKey(hash)) | ||
| if len(data) == 0 { | ||
|
||
| return false | ||
| } | ||
| return bytes.Equal(data,[]byte{0x01}) | ||
|
||
| } | ||
|
|
||
| func WriteTrustBlockHash(db ethdb.KeyValueWriter, hashkey common.Hash) { | ||
|
||
| if err := db.Put(trustBlockHashKey(hashkey),[]byte{0x01}); err != nil { | ||
| log.Crit("Failed to store trust block hash") | ||
| } | ||
| } | ||
|
|
||
| func DeleteTrustBlockHash(db ethdb.KeyValueWriter, hash common.Hash) { | ||
|
||
| if err := db.Delete(trustBlockHashKey(hash)); err != nil { | ||
| log.Crit("Failed to delete trust block hash") | ||
| } | ||
| } | ||
|
|
||
| // ReadAllHashes retrieves all the hashes assigned to blocks at a certain heights, | ||
| // both canonical and reorged forks included. | ||
| func ReadAllHashes(db ethdb.Iteratee, number uint64) []common.Hash { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,6 +93,9 @@ var ( | |
| // difflayer database | ||
| diffLayerPrefix = []byte("d") // diffLayerPrefix + hash -> diffLayer | ||
|
|
||
| // trust block database | ||
| trustBlockPrefix = []byte("tb") // trustBlockPrefix + hash -> verify result | ||
|
||
|
|
||
| preimagePrefix = []byte("secure-key-") // preimagePrefix + hash -> preimage | ||
| configPrefix = []byte("ethereum-config-") // config prefix for the db | ||
|
|
||
|
|
@@ -164,6 +167,10 @@ func headerTDKey(number uint64, hash common.Hash) []byte { | |
| func headerHashKey(number uint64) []byte { | ||
| return append(append(headerPrefix, encodeBlockNumber(number)...), headerHashSuffix...) | ||
| } | ||
| // trustBlockHashKey = trustBlockPrefix + hash | ||
| func trustBlockHashKey(hash common.Hash) []byte { | ||
|
||
| return append(append(trustBlockPrefix, hash.Bytes()...)) | ||
| } | ||
|
|
||
| // headerNumberKey = headerNumberPrefix + hash | ||
| func headerNumberKey(hash common.Hash) []byte { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean it is not proper to introduce such low level flag. Especially it is related with other flags.
For example: when
TriesVerifyModeFlagneed trust protocol whileEnableTrustProtocolFlagis false, it is become complicated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider we should disable diff protocol in verify node, and enable trust protocol, we didn't have better solution temporary.