Skip to content

Commit

Permalink
Merge pull request #58 from vulcanize/v1.10.1-statediff-0.0.16
Browse files Browse the repository at this point in the history
add leaf key to removed 'nodes'
  • Loading branch information
i-norden authored Mar 24, 2021
2 parents daa2cdd + a101102 commit b4a421f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 32 deletions.
38 changes: 26 additions & 12 deletions statediff/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,18 +419,6 @@ func (sdb *builder) deletedOrUpdatedState(a, b trie.NodeIterator, diffPathsAtB m
if err != nil {
return nil, err
}
// if this node's path did not show up in diffPathsAtB
// that means the node at this path was deleted (or moved) in B
// emit an empty "removed" diff to signify as such
if _, ok := diffPathsAtB[common.Bytes2Hex(node.Path)]; !ok {
if err := output(StateNode{
Path: node.Path,
NodeValue: []byte{},
NodeType: Removed,
}); err != nil {
return nil, err
}
}
switch node.NodeType {
case Leaf:
// map all different accounts at A to their leafkey
Expand All @@ -449,7 +437,32 @@ func (sdb *builder) deletedOrUpdatedState(a, b trie.NodeIterator, diffPathsAtB m
LeafKey: leafKey,
Account: &account,
}
// if this node's path did not show up in diffPathsAtB
// that means the node at this path was deleted (or moved) in B
// emit an empty "removed" diff to signify as such
if _, ok := diffPathsAtB[common.Bytes2Hex(node.Path)]; !ok {
if err := output(StateNode{
Path: node.Path,
NodeValue: []byte{},
NodeType: Removed,
LeafKey: leafKey,
}); err != nil {
return nil, err
}
}
case Extension, Branch:
// if this node's path did not show up in diffPathsAtB
// that means the node at this path was deleted (or moved) in B
// emit an empty "removed" diff to signify as such
if _, ok := diffPathsAtB[common.Bytes2Hex(node.Path)]; !ok {
if err := output(StateNode{
Path: node.Path,
NodeValue: []byte{},
NodeType: Removed,
}); err != nil {
return nil, err
}
}
// fall through, we did everything we need to do with these node types
default:
return nil, fmt.Errorf("unexpected node type %s", node.NodeType)
Expand Down Expand Up @@ -703,6 +716,7 @@ func (sdb *builder) deletedOrUpdatedStorage(a, b trie.NodeIterator, diffPathsAtB
NodeType: Removed,
Path: node.Path,
NodeValue: []byte{},
LeafKey: leafKey,
}); err != nil {
return err
}
Expand Down
16 changes: 15 additions & 1 deletion statediff/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1375,11 +1375,13 @@ func TestBuilderWithRemovedAccountAndStorage(t *testing.T) {
{
Path: []byte{'\x0b'},
NodeType: sdtypes.Removed,
LeafKey: slot1StorageKey.Bytes(),
NodeValue: []byte{},
},
{
Path: []byte{'\x0c'},
NodeType: sdtypes.Removed,
LeafKey: slot3StorageKey.Bytes(),
NodeValue: []byte{},
},
},
Expand Down Expand Up @@ -1434,11 +1436,13 @@ func TestBuilderWithRemovedAccountAndStorage(t *testing.T) {
{
Path: []byte{'\x02'},
NodeType: sdtypes.Removed,
LeafKey: slot0StorageKey.Bytes(),
NodeValue: []byte{},
},
{
Path: []byte{'\x04'},
NodeType: sdtypes.Removed,
LeafKey: slot2StorageKey.Bytes(),
NodeValue: []byte{},
},
},
Expand Down Expand Up @@ -1474,6 +1478,7 @@ func TestBuilderWithRemovedAccountAndStorage(t *testing.T) {
{
Path: []byte{'\x06'},
NodeType: sdtypes.Removed,
LeafKey: contractLeafKey,
NodeValue: []byte{},
},
{
Expand Down Expand Up @@ -1571,11 +1576,13 @@ func TestBuilderWithRemovedAccountAndStorageWithoutIntermediateNodes(t *testing.
{
Path: []byte{'\x0b'},
NodeType: sdtypes.Removed,
LeafKey: slot1StorageKey.Bytes(),
NodeValue: []byte{},
},
{
Path: []byte{'\x0c'},
NodeType: sdtypes.Removed,
LeafKey: slot3StorageKey.Bytes(),
NodeValue: []byte{},
},
},
Expand Down Expand Up @@ -1618,17 +1625,19 @@ func TestBuilderWithRemovedAccountAndStorageWithoutIntermediateNodes(t *testing.
{
Path: []byte{},
NodeType: sdtypes.Leaf,
NodeValue: slot0StorageLeafRootNode,
LeafKey: slot0StorageKey.Bytes(),
NodeValue: slot0StorageLeafRootNode,
},
{
Path: []byte{'\x02'},
NodeType: sdtypes.Removed,
LeafKey: slot0StorageKey.Bytes(),
NodeValue: []byte{},
},
{
Path: []byte{'\x04'},
NodeType: sdtypes.Removed,
LeafKey: slot2StorageKey.Bytes(),
NodeValue: []byte{},
},
},
Expand Down Expand Up @@ -1658,6 +1667,7 @@ func TestBuilderWithRemovedAccountAndStorageWithoutIntermediateNodes(t *testing.
{
Path: []byte{'\x06'},
NodeType: sdtypes.Removed,
LeafKey: contractLeafKey,
NodeValue: []byte{},
},
{
Expand Down Expand Up @@ -1881,11 +1891,13 @@ func TestBuilderWithMovedAccount(t *testing.T) {
{
Path: []byte{'\x01'},
NodeType: sdtypes.Removed,
LeafKey: contractLeafKey,
NodeValue: []byte{},
},
{
Path: []byte{'\x00'},
NodeType: sdtypes.Removed,
LeafKey: testhelpers.BankLeafKey,
NodeValue: []byte{},
},
},
Expand Down Expand Up @@ -2003,11 +2015,13 @@ func TestBuilderWithMovedAccountOnlyLeafs(t *testing.T) {
{
Path: []byte{'\x01'},
NodeType: sdtypes.Removed,
LeafKey: contractLeafKey,
NodeValue: []byte{},
},
{
Path: []byte{'\x00'},
NodeType: sdtypes.Removed,
LeafKey: testhelpers.BankLeafKey,
NodeValue: []byte{},
},
},
Expand Down
19 changes: 2 additions & 17 deletions statediff/indexer/postgres/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,14 @@ import (
)

const (
BeginTransactionFailedMsg = "failed to begin transaction"
DbConnectionFailedMsg = "db connection failed"
DeleteQueryFailedMsg = "delete query failed"
InsertQueryFailedMsg = "insert query failed"
SettingNodeFailedMsg = "unable to set db node"
DbConnectionFailedMsg = "db connection failed"
SettingNodeFailedMsg = "unable to set db node"
)

func ErrBeginTransactionFailed(beginErr error) error {
return formatError(BeginTransactionFailedMsg, beginErr.Error())
}

func ErrDBConnectionFailed(connectErr error) error {
return formatError(DbConnectionFailedMsg, connectErr.Error())
}

func ErrDBDeleteFailed(deleteErr error) error {
return formatError(DeleteQueryFailedMsg, deleteErr.Error())
}

func ErrDBInsertFailed(insertErr error) error {
return formatError(InsertQueryFailedMsg, insertErr.Error())
}

func ErrUnableToSetNode(setErr error) error {
return formatError(SettingNodeFailedMsg, setErr.Error())
}
Expand Down
10 changes: 8 additions & 2 deletions statediff/indexer/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ import (
"github.com/ethereum/go-ethereum/statediff/indexer/shared"
)

var DBParams postgres.ConnectionParams
var DBParams = postgres.ConnectionParams{
Name: "vulcanize_testing",
Password: "",
Port: 5432,
Hostname: "localhost",
User: "postgres",
}

func expectContainsSubstring(t *testing.T, full string, sub string) {
if !strings.Contains(full, sub) {
Expand All @@ -49,7 +55,7 @@ func TestPostgresDB(t *testing.T) {
sqlxdb, err = sqlx.Connect("postgres", pgConfig)

if err != nil {
t.Fatal(err)
t.Fatalf("failed to connect to db with connection string: %s err: %v", pgConfig, err)
}
if sqlxdb == nil {
t.Fatal("DB is nil")
Expand Down

0 comments on commit b4a421f

Please sign in to comment.