Skip to content

Commit

Permalink
add some test code
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrie-yl committed Jul 22, 2022
1 parent 75445bb commit 8288715
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ 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())
if v.remoteValidator != nil {
if verified, err := v.remoteValidator.AncestorVerified(block.Header()); !verified {
return fmt.Errorf("%w, number: %s, hash: %s, error: %s", ErrAncestorHasNotBeenVerified, block.Number(), block.Hash(), err.Error())
}
}
return nil
},
Expand Down
13 changes: 8 additions & 5 deletions core/remote_state_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (vm *remoteVerifyManager) NewBlockVerifyTask(header *types.Header) {
}

if header.TxHash == types.EmptyRootHash {
log.Debug("this is an empty block:", "block", hash, "number", header.Number)
log.Info("this is an empty block:", "block", hash, "number", header.Number)
vm.cacheBlockVerified(hash)
return
}
Expand Down Expand Up @@ -208,13 +208,13 @@ func (vm *remoteVerifyManager) cacheBlockVerified(hash common.Hash) {
}

// AncestorVerified function check block has been verified or it's a empty block.
func (vm *remoteVerifyManager) AncestorVerified(header *types.Header) bool {
func (vm *remoteVerifyManager) AncestorVerified(header *types.Header) (bool, error) {
// find header of H-11 block.
header = vm.bc.GetHeaderByNumber(header.Number.Uint64() - maxForkHeight)
// If start from genesis block, there has not a H-11 block,return true.
// Either if the block is an empty block, return true.
if header == nil || header.TxHash == types.EmptyRootHash {
return true
return true, nil
}

hash := header.Hash()
Expand All @@ -229,12 +229,15 @@ func (vm *remoteVerifyManager) AncestorVerified(header *types.Header) bool {
select {
case <-task.terminalCh:
case <-timeout.C:
return false
return false, fmt.Errorf("task of %s is timeout", hash.String())
}
}

_, exist = vm.verifiedCache.Get(hash)
return exist
if !exist {
return false, fmt.Errorf("block of %s has not been marked as verified", hash.String())
}
return true, nil
}

func (vm *remoteVerifyManager) HandleRootResponse(vr *VerifyResult, pid string) error {
Expand Down

0 comments on commit 8288715

Please sign in to comment.