Conversation
Signed-off-by: kyrie-yl <yl.on.the.way@gmail.com>
| utils.NoUSBFlag, | ||
| utils.DirectBroadcastFlag, | ||
| utils.DisableSnapProtocolFlag, | ||
| utils.DisableDiffProtocolFlag, |
There was a problem hiding this comment.
I mean it is not proper to introduce such low level flag. Especially it is related with other flags.
For example: when TriesVerifyModeFlag need trust protocol while EnableTrustProtocolFlag is false, it is become complicated.
There was a problem hiding this comment.
Consider we should disable diff protocol in verify node, and enable trust protocol, we didn't have better solution temporary.
cmd/utils/flags.go
Outdated
| defaultVerifyMode = ethconfig.Defaults.TriesVerifyMode | ||
| TriesVerifyModeFlag = TextMarshalerFlag{ | ||
| Name: "tries-verify-mode", | ||
| Usage: `tries verify mode: "local", "full", "light", "insecure"`, |
There was a problem hiding this comment.
please explain in details what the each mode means in the usage so that the user can understand
core/verify_modes.go
Outdated
| } | ||
|
|
||
| func (mode *VerifyMode) NeedRemoteVerify() bool { | ||
| if *mode == FullVerify || *mode == LightVerify { |
There was a problem hiding this comment.
return *mode == FullVerify || *mode == LightVerify directly?
core/blockchain.go
Outdated
| engine consensus.Engine | ||
| validator Validator // Block and state validator interface | ||
| processor Processor // Block transaction processor interface | ||
| verifyManager *VerifyManager |
There was a problem hiding this comment.
Shall we use interface here, like validator, processor ?
There was a problem hiding this comment.
verifyManager is not a good name, we need distinguish it from validator here.
core/blockchain.go
Outdated
| return bc, nil | ||
| } | ||
|
|
||
| func (bc *BlockChain) StartVerify(peers VerifyPeers, allowUntrustedVerify bool) { |
There was a problem hiding this comment.
Can we not pass allowUntrustedVerify when StartVerify, but pass it when new the verifyManager.
core/trie_verify.go
Outdated
| header := vm.bc.CurrentHeader() | ||
| // Start verify task from H to H-11 if need. | ||
| vm.NewBlockVerifyTask(header) | ||
| prune := time.NewTicker(time.Second) |
There was a problem hiding this comment.
1 second is too short for pruneTicker, I will suggest 5 seconds
core/trie_verify.go
Outdated
| } | ||
| case <-prune.C: | ||
| for hash, task := range vm.tasks { | ||
| if vm.bc.CurrentHeader().Number.Uint64()-task.blockHeader.Number.Uint64() > 15 { |
core/trie_verify.go
Outdated
|
|
||
| func (vm *VerifyManager) Stop() { | ||
| // stop all the tasks | ||
| for _, task := range vm.tasks { |
There was a problem hiding this comment.
race condition on vm.tasks, it may double close task.terminalCh and cause panic
core/trie_verify.go
Outdated
| func (vt *VerifyTask) Start(verifyCh chan common.Hash) { | ||
| vt.startAt = time.Now() | ||
|
|
||
| vt.selectPeersToVerify(defaultPeerNumber) |
There was a problem hiding this comment.
Please try better name thanselectPeersToVerify. 主语是select,就是挑选,实际上会把请求发出去。
core/trie_verify.go
Outdated
| validPeers = append(validPeers, p) | ||
| } | ||
| } | ||
| // if |
| } | ||
|
|
||
| // if n < len(validPeers), select n peers from validPeers randomly. | ||
| rand.Seed(time.Now().UnixNano()) |
There was a problem hiding this comment.
Please log(warn) if there is no node to request.
core/trie_verify.go
Outdated
| func (vt *VerifyTask) compareRootHashAndWrite(msg VerifyMessage, verifyCh chan common.Hash) { | ||
| if msg.verifyResult.Root == vt.blockHeader.Root { | ||
| blockhash := msg.verifyResult.BlockHash | ||
| rawdb.MarkTrustBlock(vt.db, blockhash) |
There was a problem hiding this comment.
we have done MarkTrustBlock twice, I think we can delete here, but let VerifyManager to do it.
core/types.go
Outdated
| // VerifyBlock verify the given blcok. | ||
| VerifyBlock(header *types.Header) | ||
| // ValidateBlockVerify validate the given block has been verified. | ||
| ValidateBlockVerify(block *types.Block) error |
There was a problem hiding this comment.
ValidateBlockVerify is too confusing...
core/types.go
Outdated
| ValidateState(block *types.Block, state *state.StateDB, receipts types.Receipts, usedGas uint64) error | ||
|
|
||
| // StartRemoteVerify start the remote verify routine for given peers. | ||
| StartRemoteVerify(peers VerifyPeers) |
There was a problem hiding this comment.
I think there is some way to hide StartRemoteVerify and StopRemoteVerify, we should expose as less interface as possible.
core/types.go
Outdated
| // StopRemoteVerify stop the remote verify routine. | ||
| StopRemoteVerify() | ||
| // VerifyBlock verify the given blcok. | ||
| VerifyBlock(header *types.Header) |
There was a problem hiding this comment.
We can merge VerifyBlock and ValidateBody into one.
core/block_validator.go
Outdated
| bc: blockchain, | ||
| } | ||
| if mode.NeedRemoteVerify() { | ||
| remoteValidator := NewVerifyManager(blockchain, peers, *mode == InsecureVerify) |
There was a problem hiding this comment.
Should assign validator's remoteValidator, not just a local variable.
core/block_validator.go
Outdated
| if !v.remoteValidator.AncestorVerified(v.bc.GetHeaderByNumber(header.Number.Uint64())) { | ||
| return fmt.Errorf("block's ancessor %x has not been verified", block.Hash()) | ||
| } | ||
| } |
There was a problem hiding this comment.
Wrap these code as a new validateFunc is better? Can run concurrently with above another two validateFuncs
There was a problem hiding this comment.
Please run concurrently like another two validateFuncs.
| if diffLayer, err = vm.bc.GenerateDiffLayer(hash); err != nil { | ||
| log.Error("failed to get diff layer", "block", hash, "number", header.Number, "error", err) | ||
| return | ||
| } |
There was a problem hiding this comment.
There is a case if the block is an empty block, the error is nil and difflayer is nil too. So, add another branch to test if difflayer == nil, if so, return directly.
core/trie_verify.go
Outdated
| if header.TxHash == types.EmptyRootHash { | ||
| parent := vm.bc.GetHeaderByHash(header.ParentHash) | ||
| if header.Root == parent.Root { | ||
| return true |
There was a problem hiding this comment.
No need use if branch, actually if you use if branch, when not equal, you should use else branch to return false here, so recommend to return header.Root == parent.Root directly.
There was a problem hiding this comment.
I think when header.Root == parent.Root, we should check whether the parent has been verified, if not, this empty block is not verified, if the parent has been verified already, this empty block is verified. So maybe here should be
if header.Root != parent.Root { return false }
core/trie_verify.go
Outdated
| allowUntrusted: allowUntrusted, | ||
|
|
||
| newTaskCh: make(chan *types.Header), | ||
| verifyCh: make(chan common.Hash), |
There was a problem hiding this comment.
I will suggest verifyCh have some buffer, like 11, so than the main process will not been blocked.
There was a problem hiding this comment.
So do newTaskCh, please allocate some buffer.
| 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.
Better description is needed to let users understand the meaning of each mode
cmd/utils/flags.go
Outdated
| } | ||
| // If a node sets verify mode 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 { |
There was a problem hiding this comment.
After discuss with nash, we can delete flag DisableDiffProtocol, even fast node can provide difflayer for diff sync.
core/rawdb/schema.go
Outdated
| diffLayerPrefix = []byte("d") // diffLayerPrefix + hash -> diffLayer | ||
|
|
||
| // trust block database | ||
| trustBlockPrefix = []byte("trust-block-") // trustBlockPrefix + hash -> verify result |
core/rawdb/schema.go
Outdated
| } | ||
|
|
||
| // trustBlockHashKey = trustBlockPrefix + hash | ||
| func trustBlockHashKey(hash common.Hash) []byte { |
core/trie_verify.go
Outdated
| tryAllPeersTime = 15 * time.Second | ||
| ) | ||
|
|
||
| type verifyManager struct { |
There was a problem hiding this comment.
Please rename verifyManager to remoteVerifyManager
| @@ -0,0 +1,345 @@ | |||
| package core | |||
There was a problem hiding this comment.
The file name trie_verify can rename to remote_state_verifier
core/trie_verify.go
Outdated
| return nil | ||
| } | ||
|
|
||
| func (mode *VerifyMode) NeedRemoteVerify() bool { |
There was a problem hiding this comment.
Please change func (mode *VerifyMode) NeedRemoteVerify() bool to func (mode VerifyMode) NeedRemoteVerify() bool, so that you can change
func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engine consensus.Engine, mode *VerifyMode, peers verifyPeers) *BlockValidator
to
func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engine consensus.Engine, mode VerifyMode, peers verifyPeers) *BlockValidator {
core/block_validator.go
Outdated
| return err | ||
| } | ||
|
|
||
| func (v *BlockValidator) VerifyBlockTrie(header *types.Header) { |
There was a problem hiding this comment.
Let us try subscribe the header info rather than called in main process.
core/trie_verify.go
Outdated
| tasks map[common.Hash]*verifyTask | ||
| peers verifyPeers | ||
| verifiedCache *lru.Cache | ||
| allowUntrusted bool |
There was a problem hiding this comment.
can we rename it to allowInsecure, since the peer is still trusted, but the result is not insecure
|
Please add promethus metrics |
0d80e6f to
f3820ca
Compare
Signed-off-by: kyrie-yl <yl.on.the.way@gmail.com>
f3820ca to
1af60b3
Compare
Signed-off-by: kyrie-yl <yl.on.the.way@gmail.com>
No description provided.