remove debug stmts; remove faulty nodes from expected results

This commit is contained in:
i-norden 2023-03-23 07:51:18 -05:00
parent 198fc65a7d
commit d0d8e6d217
2 changed files with 2 additions and 86 deletions

View File

@ -22,13 +22,6 @@ package statediff
import (
"bytes"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/statediff/test_helpers"
"github.com/ethereum/go-ethereum/statediff/indexer/shared"
ipld2 "github.com/ethereum/go-ethereum/statediff/indexer/ipld"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
@ -36,6 +29,8 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
ipld2 "github.com/ethereum/go-ethereum/statediff/indexer/ipld"
"github.com/ethereum/go-ethereum/statediff/indexer/shared"
"github.com/ethereum/go-ethereum/statediff/trie_helpers"
types2 "github.com/ethereum/go-ethereum/statediff/types"
"github.com/ethereum/go-ethereum/trie"
@ -196,15 +191,6 @@ func (sdb *StateDiffBuilder) createdAndUpdatedState(a, b trie.NodeIterator,
}
// index values by leaf key
if it.Leaf() {
if bytes.Equal(common.Hex2Bytes("20f2e24db7943eab4415f99e109698863b0fecca1cf9ffc500f38cefbbe29e"), it.LeafKey()) {
panic("I should be reached but I am not")
}
if bytes.Equal(common.Hex2Bytes("08d4679cbcf198c1741a6f4e4473845659a30caa8b26f8d37a0be2e2bc0d8892"), it.LeafKey()) {
fmt.Printf("\r\nI am reached, like a good leaf node\r\n")
}
if bytes.Equal(common.Hex2Bytes("ce573ced93917e658d10e2d9009470dad72b63c898d173721194a12f2ae5e190"), it.LeafKey()) {
fmt.Printf("\r\nI am also reached, like a good leaf node\r\n")
}
// if it is a "value" node, we will index the value by leaf key
accountW, err := sdb.processStateValueNode(it, watchedAddressesLeafPaths)
if err != nil {
@ -240,23 +226,6 @@ func (sdb *StateDiffBuilder) createdAndUpdatedState(a, b trie.NodeIterator,
}
}
}
if bytes.Equal(block2MovedPremineLeafNode, nodeVal) {
fmt.Printf("\r\nfurther demonstration that the so-called leaf node is present in the trie but just doesn't show up under it.Leaf()\r\n")
// and if we decode the node, and check whether or not it is a leaf by looking at the partial path
// we see it is indeed a leaf node
// so the partial path has the leaf flag, but the first part of the path (the position of the node in the trie) does not have the terminator flag
var elements []interface{}
if err := rlp.DecodeBytes(nodeVal, &elements); err != nil {
return nil, err
}
ok, err := isLeaf(elements)
if err != nil {
return nil, err
}
if ok {
fmt.Printf("\r\nyep I'm a leaf\r\n")
}
}
nodeHash := make([]byte, len(it.Hash().Bytes()))
copy(nodeHash, it.Hash().Bytes())
if err := output(types2.IPLD{
@ -270,21 +239,6 @@ func (sdb *StateDiffBuilder) createdAndUpdatedState(a, b trie.NodeIterator,
return diffAccountsAtB, it.Error()
}
var (
block2MovedPremineBalance, _ = new(big.Int).SetString("4000000000000000000000", 10)
block2MovedPremineAccount = &types.StateAccount{
Nonce: 0,
Balance: block2MovedPremineBalance,
CodeHash: test_helpers.NullCodeHash.Bytes(),
Root: test_helpers.EmptyContractRoot,
}
block2MovedPremineAccountRLP, _ = rlp.EncodeToBytes(block2MovedPremineAccount)
block2MovedPremineLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
common.Hex2Bytes("20f2e24db7943eab4415f99e109698863b0fecca1cf9ffc500f38cefbbe29e"),
block2MovedPremineAccountRLP,
})
)
// reminder: it.Leaf() == true when the iterator is positioned at a "value node" which is not something that actually exists in an MMPT
func (sdb *StateDiffBuilder) processStateValueNode(it trie.NodeIterator, watchedAddressesLeafPaths [][]byte) (*types2.AccountWrapper, error) {
// skip if it is not a watched address
@ -333,12 +287,6 @@ func (sdb *StateDiffBuilder) deletedOrUpdatedState(a, b trie.NodeIterator, diffA
}
if it.Leaf() {
if bytes.Equal(common.Hex2Bytes("20f2e24db7943eab4415f99e109698863b0fecca1cf9ffc500f38cefbbe29e"), it.LeafKey()) {
panic("I should be reached but I am not")
}
if bytes.Equal(common.Hex2Bytes("08d4679cbcf198c1741a6f4e4473845659a30caa8b26f8d37a0be2e2bc0d8892"), it.LeafKey()) {
fmt.Printf("\r\nI am reached, like a good leaf node\r\n")
}
accountW, err := sdb.processStateValueNode(it, watchedAddressesLeafPaths)
if err != nil {
return nil, err

View File

@ -549,23 +549,6 @@ func TestBuilderOnMainnetBlocks(t *testing.T) {
BlockNumber: block2.Number(),
BlockHash: block2.Hash(),
Nodes: []sdtypes.StateLeafNode{
// this new leaf at x00 x08 x0d x00 was "created" when a premine account (leaf) was moved from path x00 x08 x0d
// this occurred because of the creation of the new coinbase receiving account (leaf) at x00 x08 x0d x04
// which necessitates we create a branch at x00 x08 x0d (as shown in the below UpdateAccounts)
{ // TODO: this doesn't show up? WHY??? It shows up below in the IPLDs, as it is a diffed node,
// but it doesn't show up here because it.Leaf() doesn't evaluate to true for it for some reason
// even though it is a leaf node by every other measure, and we know the nodes are all correct
// because we can hash the root node written out above that links down to this
// and the hash matches the expected root hash
// NOTE: IF YOU REMOVE ME, THE TEST WILL PASS
Removed: false,
AccountWrapper: sdtypes.AccountWrapper{
Account: block2MovedPremineAccount,
LeafKey: common.HexToHash("08d0f2e24db7943eab4415f99e109698863b0fecca1cf9ffc500f38cefbbe29e").Bytes(),
CID: ipld2.Keccak256ToCid(ipld2.MEthStateTrie, crypto.Keccak256(block2MovedPremineLeafNode)).String(),
},
StorageDiff: emptyStorage,
},
{
Removed: false,
AccountWrapper: sdtypes.AccountWrapper{
@ -627,21 +610,6 @@ func TestBuilderOnMainnetBlocks(t *testing.T) {
},
StorageDiff: emptyStorage,
},
{ // This account (leaf) used to be at 0c 0e 05 07, likely moves because of the new account above
// TODO: this doesn't show up? WHY??? It shows up below in the IPLDs, as it is a diffed node,
// but it doesn't show up here because it.Leaf() doesn't evaluate to true for it for some reason
// even though it is a leaf node by every other measure, and we know the nodes are all correct
// because we can hash the root node written out above that links down to this
// and the hash matches the expected root hash
// NOTE: IF YOU REMOVE ME, THE TEST WILL PASS
Removed: false,
AccountWrapper: sdtypes.AccountWrapper{
Account: block3MovedPremineAccount2,
LeafKey: common.HexToHash("ce5783bc1e69eedf90f402e11f6862da14ed8e50156635a04d6393bbae154012").Bytes(),
CID: ipld2.Keccak256ToCid(ipld2.MEthStateTrie, crypto.Keccak256(block3MovedPremineLeafNode2)).String(),
},
StorageDiff: emptyStorage,
},
{ // this is the new account created due to the coinbase mining a block, it's creation shouldn't affect 0x 0e 05 07
Removed: false,
AccountWrapper: sdtypes.AccountWrapper{