Address PR comments

This commit is contained in:
Elizabeth Engelman 2019-01-09 09:17:50 -06:00
parent 61c82b2326
commit 569a5a6dd8
7 changed files with 16 additions and 17 deletions

View File

@ -1353,7 +1353,6 @@ func RegisterStateDiffService(stack *node.Node, ctx *cli.Context) {
path := ctx.GlobalString(StateDiffPathFlag.Name)
config := statediff.Config{
On: false,
Mode: mode,
Path: path,
}

View File

@ -69,8 +69,8 @@ func (sdb *builder) BuildStateDiff(oldStateRoot, newStateRoot common.Hash, block
}
// Find deleted accounts
oldIt = oldTrie.NodeIterator(make([]byte, 0))
newIt = newTrie.NodeIterator(make([]byte, 0))
oldIt = oldTrie.NodeIterator([]byte{})
newIt = newTrie.NodeIterator([]byte{})
deletions, err := sdb.collectDiffNodes(newIt, oldIt)
if err != nil {
log.Error("Error collecting deletion diff nodes", "error", err)
@ -88,12 +88,12 @@ func (sdb *builder) BuildStateDiff(oldStateRoot, newStateRoot common.Hash, block
log.Error("Error building diff for updated accounts", "error", err)
return nil, err
}
createdAccounts, err := sdb.buildDiffEventual(creations, true)
createdAccounts, err := sdb.buildDiffEventual(creations)
if err != nil {
log.Error("Error building diff for created accounts", "error", err)
return nil, err
}
deletedAccounts, err := sdb.buildDiffEventual(deletions, false)
deletedAccounts, err := sdb.buildDiffEventual(deletions)
if err != nil {
log.Error("Error building diff for deleted accounts", "error", err)
return nil, err
@ -145,11 +145,11 @@ func (sdb *builder) collectDiffNodes(a, b trie.NodeIterator) (map[common.Address
return diffAccounts, nil
}
func (sdb *builder) buildDiffEventual(accounts map[common.Address]*state.Account, created bool) (map[common.Address]AccountDiff, error) {
func (sdb *builder) buildDiffEventual(accounts map[common.Address]*state.Account) (map[common.Address]AccountDiff, error) {
accountDiffs := make(map[common.Address]AccountDiff)
for addr, val := range accounts {
sr := val.Root
storageDiffs, err := sdb.buildStorageDiffsEventual(sr, created)
storageDiffs, err := sdb.buildStorageDiffsEventual(sr)
if err != nil {
log.Error("Failed building eventual storage diffs", "Address", addr, "error", err)
return nil, err
@ -204,10 +204,11 @@ func (sdb *builder) buildDiffIncremental(creations map[common.Address]*state.Acc
return updatedAccounts, nil
}
func (sdb *builder) buildStorageDiffsEventual(sr common.Hash, creation bool) (map[string]DiffString, error) {
func (sdb *builder) buildStorageDiffsEventual(sr common.Hash) (map[string]DiffString, error) {
log.Debug("Storage Root For Eventual Diff", "root", sr.Hex())
sTrie, err := trie.New(sr, sdb.trieDB)
if err != nil {
log.Info("error in build storage diff eventual", "error", err)
return nil, err
}
it := sTrie.NodeIterator(make([]byte, 0))
@ -261,7 +262,7 @@ func (sdb *builder) buildStorageDiffsIncremental(oldSR common.Hash, newSR common
func (sdb *builder) addressByPath(path []byte) (*common.Address, error) {
log.Debug("Looking up address from path", "path", hexutil.Encode(append([]byte("secure-key-"), path...)))
if addrBytes, err := sdb.chainDB.Get(append([]byte("secure-key-"), hexToKeybytes(path)...)); err != nil {
if addrBytes, err := sdb.chainDB.Get(append([]byte("secure-key-"), hexToKeyBytes(path)...)); err != nil {
log.Error("Error looking up address via path", "path", hexutil.Encode(append([]byte("secure-key-"), path...)), "error", err)
return nil, err
} else {

View File

@ -93,7 +93,7 @@ func pathToStr(it trie.NodeIterator) string {
}
// Duplicated from trie/encoding.go
func hexToKeybytes(hex []byte) []byte {
func hexToKeyBytes(hex []byte) []byte {
if hasTerm(hex) {
hex = hex[:len(hex)-1]
}

View File

@ -22,7 +22,6 @@ package statediff
import "fmt"
type Config struct {
On bool // Whether or not to extract state diffs
Mode StateDiffMode // Mode for storing diffs
Path string // Path for storing diffs
}

View File

@ -73,9 +73,9 @@ func keybytesToHex(str []byte) []byte {
return nibbles
}
// hexToKeybytes turns hex nibbles into key bytes.
// hexToKeyBytes turns hex nibbles into key bytes.
// This can only be used for keys of even length.
func hexToKeybytes(hex []byte) []byte {
func hexToKeyBytes(hex []byte) []byte {
if hasTerm(hex) {
hex = hex[:len(hex)-1]
}

View File

@ -69,8 +69,8 @@ func TestHexKeybytes(t *testing.T) {
if h := keybytesToHex(test.key); !bytes.Equal(h, test.hexOut) {
t.Errorf("keybytesToHex(%x) -> %x, want %x", test.key, h, test.hexOut)
}
if k := hexToKeybytes(test.hexIn); !bytes.Equal(k, test.key) {
t.Errorf("hexToKeybytes(%x) -> %x, want %x", test.hexIn, k, test.key)
if k := hexToKeyBytes(test.hexIn); !bytes.Equal(k, test.key) {
t.Errorf("hexToKeyBytes(%x) -> %x, want %x", test.hexIn, k, test.key)
}
}
}
@ -99,6 +99,6 @@ func BenchmarkKeybytesToHex(b *testing.B) {
func BenchmarkHexToKeybytes(b *testing.B) {
testBytes := []byte{7, 6, 6, 5, 7, 2, 6, 2, 16}
for i := 0; i < b.N; i++ {
hexToKeybytes(testBytes)
hexToKeyBytes(testBytes)
}
}

View File

@ -162,7 +162,7 @@ func (it *nodeIterator) Leaf() bool {
func (it *nodeIterator) LeafKey() []byte {
if len(it.stack) > 0 {
if _, ok := it.stack[len(it.stack)-1].node.(valueNode); ok {
return hexToKeybytes(it.path)
return hexToKeyBytes(it.path)
}
}
panic("not at leaf")