From fbcb1337353a24a4159a66f62e11751c4599fe8e Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Wed, 27 Sep 2023 16:46:13 +0000 Subject: [PATCH] Add full diff objects to output (#4) Reviewed-on: https://git.vdb.to/cerc-io/eth-statediff-compliance/pulls/4 --- README.md | 2 +- pkg/diff_dump.go | 25 ++++++++++++++++++++++--- scripts/compare-diffs.sh | 13 +++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index cbbcac2..68247cd 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,6 @@ Use `scripts/compare-diffs.sh` to compare outputs of `go-ethereum/statediff` and ./scripts/compare-diffs.sh -d _var/ geth plugeth # Compare geth-statediff and the plugin using parallel iterators: - ./scripts/compare-diffs.sh -d _var/ geth plugeth + ./scripts/compare-diffs.sh -d _var/ geth plugeth-parallel A zero exit code indicates identical outputs, modulo possible duplicate nodes. diff --git a/pkg/diff_dump.go b/pkg/diff_dump.go index 3b7bcc2..c02693f 100644 --- a/pkg/diff_dump.go +++ b/pkg/diff_dump.go @@ -70,16 +70,35 @@ func writeDiff(outputDir string, number int, diff *statediff.StateObject) { } defer f.Close() for _, item := range diff.IPLDs { - if _, err = f.WriteString("ipld," + item.CID + "\n"); err != nil { + s := fmt.Sprintf("ipld,%s,%x\n", + item.CID, + item.Content, + ) + if _, err = f.WriteString(s); err != nil { panic(err) } } for _, item := range diff.Nodes { - if _, err = f.WriteString("state," + item.AccountWrapper.CID + "\n"); err != nil { + s := fmt.Sprintf("state,%s,%x,%t,%v,%v,%s,%x\n", + item.AccountWrapper.CID, + item.AccountWrapper.LeafKey, + item.Removed, + item.AccountWrapper.Account.Nonce, + item.AccountWrapper.Account.Balance, + item.AccountWrapper.Account.Root, + item.AccountWrapper.Account.CodeHash, + ) + if _, err = f.WriteString(s); err != nil { panic(err) } for _, storage := range item.StorageDiff { - if _, err = f.WriteString("storage," + storage.CID + "\n"); err != nil { + s := fmt.Sprintf("storage,%s,%x,%t,%x\n", + storage.CID, + storage.LeafKey, + storage.Removed, + storage.Value, + ) + if _, err = f.WriteString(s); err != nil { panic(err) } } diff --git a/scripts/compare-diffs.sh b/scripts/compare-diffs.sh index 371a53e..51e116b 100755 --- a/scripts/compare-diffs.sh +++ b/scripts/compare-diffs.sh @@ -14,15 +14,13 @@ shift $((OPTIND - 1)) A=${1:-geth} B=${2:-plugeth} -if [[ -n "$output_dir" ]]; then - mkdir -p $output_dir - A_OUTPUT="$output_dir/A" - B_OUTPUT="$output_dir/B" -else - A_OUTPUT=$(mktemp -d -t A_XXXX) - B_OUTPUT=$(mktemp -d -t B_XXXX) +if [[ -z "$output_dir" ]]; then + output_dir=$(mktemp -d) fi +A_OUTPUT="$output_dir/A" +B_OUTPUT="$output_dir/B" + ./dumpdiff.$A $A_OUTPUT ./dumpdiff.$B $B_OUTPUT @@ -34,5 +32,4 @@ for file in $(ls $A_OUTPUT); do mv $tmpfile "$dir/$file" done (set -x; diff "${A_OUTPUT}/$file" "${B_OUTPUT}/$file") - echo Files match: "$PLUGIN_OUTPUT/$file" "$GETH_OUTPUT/$file" done