Don't read cwd in blockchain validator, remove debug code (#992)

* print cwd

* don't read cwd, remove debug code

* oops, overdelete

* clean
This commit is contained in:
Alex Sharov 2020-08-28 16:30:22 +07:00 committed by GitHub
parent d73b036cff
commit d30df505c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,16 +20,12 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/consensus"
"github.com/ledgerwatch/turbo-geth/core/state"
"github.com/ledgerwatch/turbo-geth/core/types"
"github.com/ledgerwatch/turbo-geth/log"
"github.com/ledgerwatch/turbo-geth/params"
)
@ -41,7 +37,6 @@ type BlockValidator struct {
config *params.ChainConfig // Chain configuration options
bc *BlockChain // Canonical block chain
engine consensus.Engine // Consensus engine used for validating
dblks map[uint64]bool // Block numbers to run diagnostics on
}
// NewBlockValidator returns a new block validator which is safe for re-use
@ -50,34 +45,6 @@ func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engin
config: config,
engine: engine,
bc: blockchain,
dblks: make(map[uint64]bool),
}
files, err := ioutil.ReadDir("./")
if err != nil {
panic(err)
}
for _, f := range files {
if !f.IsDir() && strings.HasPrefix(f.Name(), "root_") && strings.HasSuffix(f.Name(), ".txt") {
blockNumber, err := strconv.ParseUint(f.Name()[len("root_"):len(f.Name())-len(".txt")], 10, 64)
if err != nil {
panic(err)
}
if _, ok := validator.dblks[blockNumber]; !ok {
validator.dblks[blockNumber] = true
}
}
if !f.IsDir() && strings.HasPrefix(f.Name(), "right_") && strings.HasSuffix(f.Name(), ".txt") {
blockNumber, err := strconv.ParseUint(f.Name()[len("right_"):len(f.Name())-len(".txt")], 10, 64)
if err != nil {
panic(err)
}
validator.dblks[blockNumber] = false
}
}
for blockNumber, ok := range validator.dblks {
if ok {
log.Info("Block validator will watch", "block", blockNumber)
}
}
return validator
}
@ -158,25 +125,10 @@ func (v *BlockValidator) ValidateGasAndRoot(block *types.Block, root common.Hash
// Validate the state root against the received state root and throw
// an error if they don't match.
if block.Header().Root != root {
filename := fmt.Sprintf("root_%d.txt", block.NumberU64())
log.Warn("Generating deep snapshot of the wrong tries...", "file", filename)
f, err := os.Create(filename)
if err == nil {
defer f.Close()
tds.PrintTrie(f)
}
if errorBuf.Len() > 0 {
errorBuf.WriteString("; ")
}
fmt.Fprintf(&errorBuf, "[pre-processed] invalid merkle root (remote: %x local: %x)", block.Header().Root, root)
} else if has, ok := v.dblks[block.NumberU64()]; ok && has {
filename := fmt.Sprintf("right_%d.txt", block.NumberU64())
log.Warn("Generating deep snapshot of right tries...", "file", filename)
f, err := os.Create(filename)
if err == nil {
defer f.Close()
tds.PrintTrie(f)
}
}
if errorBuf.Len() > 0 {