Skip to content

Commit b4a421f

Browse files
authored
Merge pull request #58 from vulcanize/v1.10.1-statediff-0.0.16
add leaf key to removed 'nodes'
2 parents daa2cdd + a101102 commit b4a421f

File tree

4 files changed

+51
-32
lines changed

4 files changed

+51
-32
lines changed

statediff/builder.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -419,18 +419,6 @@ func (sdb *builder) deletedOrUpdatedState(a, b trie.NodeIterator, diffPathsAtB m
419419
if err != nil {
420420
return nil, err
421421
}
422-
// if this node's path did not show up in diffPathsAtB
423-
// that means the node at this path was deleted (or moved) in B
424-
// emit an empty "removed" diff to signify as such
425-
if _, ok := diffPathsAtB[common.Bytes2Hex(node.Path)]; !ok {
426-
if err := output(StateNode{
427-
Path: node.Path,
428-
NodeValue: []byte{},
429-
NodeType: Removed,
430-
}); err != nil {
431-
return nil, err
432-
}
433-
}
434422
switch node.NodeType {
435423
case Leaf:
436424
// map all different accounts at A to their leafkey
@@ -449,7 +437,32 @@ func (sdb *builder) deletedOrUpdatedState(a, b trie.NodeIterator, diffPathsAtB m
449437
LeafKey: leafKey,
450438
Account: &account,
451439
}
440+
// if this node's path did not show up in diffPathsAtB
441+
// that means the node at this path was deleted (or moved) in B
442+
// emit an empty "removed" diff to signify as such
443+
if _, ok := diffPathsAtB[common.Bytes2Hex(node.Path)]; !ok {
444+
if err := output(StateNode{
445+
Path: node.Path,
446+
NodeValue: []byte{},
447+
NodeType: Removed,
448+
LeafKey: leafKey,
449+
}); err != nil {
450+
return nil, err
451+
}
452+
}
452453
case Extension, Branch:
454+
// if this node's path did not show up in diffPathsAtB
455+
// that means the node at this path was deleted (or moved) in B
456+
// emit an empty "removed" diff to signify as such
457+
if _, ok := diffPathsAtB[common.Bytes2Hex(node.Path)]; !ok {
458+
if err := output(StateNode{
459+
Path: node.Path,
460+
NodeValue: []byte{},
461+
NodeType: Removed,
462+
}); err != nil {
463+
return nil, err
464+
}
465+
}
453466
// fall through, we did everything we need to do with these node types
454467
default:
455468
return nil, fmt.Errorf("unexpected node type %s", node.NodeType)
@@ -703,6 +716,7 @@ func (sdb *builder) deletedOrUpdatedStorage(a, b trie.NodeIterator, diffPathsAtB
703716
NodeType: Removed,
704717
Path: node.Path,
705718
NodeValue: []byte{},
719+
LeafKey: leafKey,
706720
}); err != nil {
707721
return err
708722
}

statediff/builder_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,11 +1375,13 @@ func TestBuilderWithRemovedAccountAndStorage(t *testing.T) {
13751375
{
13761376
Path: []byte{'\x0b'},
13771377
NodeType: sdtypes.Removed,
1378+
LeafKey: slot1StorageKey.Bytes(),
13781379
NodeValue: []byte{},
13791380
},
13801381
{
13811382
Path: []byte{'\x0c'},
13821383
NodeType: sdtypes.Removed,
1384+
LeafKey: slot3StorageKey.Bytes(),
13831385
NodeValue: []byte{},
13841386
},
13851387
},
@@ -1434,11 +1436,13 @@ func TestBuilderWithRemovedAccountAndStorage(t *testing.T) {
14341436
{
14351437
Path: []byte{'\x02'},
14361438
NodeType: sdtypes.Removed,
1439+
LeafKey: slot0StorageKey.Bytes(),
14371440
NodeValue: []byte{},
14381441
},
14391442
{
14401443
Path: []byte{'\x04'},
14411444
NodeType: sdtypes.Removed,
1445+
LeafKey: slot2StorageKey.Bytes(),
14421446
NodeValue: []byte{},
14431447
},
14441448
},
@@ -1474,6 +1478,7 @@ func TestBuilderWithRemovedAccountAndStorage(t *testing.T) {
14741478
{
14751479
Path: []byte{'\x06'},
14761480
NodeType: sdtypes.Removed,
1481+
LeafKey: contractLeafKey,
14771482
NodeValue: []byte{},
14781483
},
14791484
{
@@ -1571,11 +1576,13 @@ func TestBuilderWithRemovedAccountAndStorageWithoutIntermediateNodes(t *testing.
15711576
{
15721577
Path: []byte{'\x0b'},
15731578
NodeType: sdtypes.Removed,
1579+
LeafKey: slot1StorageKey.Bytes(),
15741580
NodeValue: []byte{},
15751581
},
15761582
{
15771583
Path: []byte{'\x0c'},
15781584
NodeType: sdtypes.Removed,
1585+
LeafKey: slot3StorageKey.Bytes(),
15791586
NodeValue: []byte{},
15801587
},
15811588
},
@@ -1618,17 +1625,19 @@ func TestBuilderWithRemovedAccountAndStorageWithoutIntermediateNodes(t *testing.
16181625
{
16191626
Path: []byte{},
16201627
NodeType: sdtypes.Leaf,
1621-
NodeValue: slot0StorageLeafRootNode,
16221628
LeafKey: slot0StorageKey.Bytes(),
1629+
NodeValue: slot0StorageLeafRootNode,
16231630
},
16241631
{
16251632
Path: []byte{'\x02'},
16261633
NodeType: sdtypes.Removed,
1634+
LeafKey: slot0StorageKey.Bytes(),
16271635
NodeValue: []byte{},
16281636
},
16291637
{
16301638
Path: []byte{'\x04'},
16311639
NodeType: sdtypes.Removed,
1640+
LeafKey: slot2StorageKey.Bytes(),
16321641
NodeValue: []byte{},
16331642
},
16341643
},
@@ -1658,6 +1667,7 @@ func TestBuilderWithRemovedAccountAndStorageWithoutIntermediateNodes(t *testing.
16581667
{
16591668
Path: []byte{'\x06'},
16601669
NodeType: sdtypes.Removed,
1670+
LeafKey: contractLeafKey,
16611671
NodeValue: []byte{},
16621672
},
16631673
{
@@ -1881,11 +1891,13 @@ func TestBuilderWithMovedAccount(t *testing.T) {
18811891
{
18821892
Path: []byte{'\x01'},
18831893
NodeType: sdtypes.Removed,
1894+
LeafKey: contractLeafKey,
18841895
NodeValue: []byte{},
18851896
},
18861897
{
18871898
Path: []byte{'\x00'},
18881899
NodeType: sdtypes.Removed,
1900+
LeafKey: testhelpers.BankLeafKey,
18891901
NodeValue: []byte{},
18901902
},
18911903
},
@@ -2003,11 +2015,13 @@ func TestBuilderWithMovedAccountOnlyLeafs(t *testing.T) {
20032015
{
20042016
Path: []byte{'\x01'},
20052017
NodeType: sdtypes.Removed,
2018+
LeafKey: contractLeafKey,
20062019
NodeValue: []byte{},
20072020
},
20082021
{
20092022
Path: []byte{'\x00'},
20102023
NodeType: sdtypes.Removed,
2024+
LeafKey: testhelpers.BankLeafKey,
20112025
NodeValue: []byte{},
20122026
},
20132027
},

statediff/indexer/postgres/errors.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,14 @@ import (
2121
)
2222

2323
const (
24-
BeginTransactionFailedMsg = "failed to begin transaction"
25-
DbConnectionFailedMsg = "db connection failed"
26-
DeleteQueryFailedMsg = "delete query failed"
27-
InsertQueryFailedMsg = "insert query failed"
28-
SettingNodeFailedMsg = "unable to set db node"
24+
DbConnectionFailedMsg = "db connection failed"
25+
SettingNodeFailedMsg = "unable to set db node"
2926
)
3027

31-
func ErrBeginTransactionFailed(beginErr error) error {
32-
return formatError(BeginTransactionFailedMsg, beginErr.Error())
33-
}
34-
3528
func ErrDBConnectionFailed(connectErr error) error {
3629
return formatError(DbConnectionFailedMsg, connectErr.Error())
3730
}
3831

39-
func ErrDBDeleteFailed(deleteErr error) error {
40-
return formatError(DeleteQueryFailedMsg, deleteErr.Error())
41-
}
42-
43-
func ErrDBInsertFailed(insertErr error) error {
44-
return formatError(InsertQueryFailedMsg, insertErr.Error())
45-
}
46-
4732
func ErrUnableToSetNode(setErr error) error {
4833
return formatError(SettingNodeFailedMsg, setErr.Error())
4934
}

statediff/indexer/postgres/postgres_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ import (
3131
"github.com/ethereum/go-ethereum/statediff/indexer/shared"
3232
)
3333

34-
var DBParams postgres.ConnectionParams
34+
var DBParams = postgres.ConnectionParams{
35+
Name: "vulcanize_testing",
36+
Password: "",
37+
Port: 5432,
38+
Hostname: "localhost",
39+
User: "postgres",
40+
}
3541

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

5157
if err != nil {
52-
t.Fatal(err)
58+
t.Fatalf("failed to connect to db with connection string: %s err: %v", pgConfig, err)
5359
}
5460
if sqlxdb == nil {
5561
t.Fatal("DB is nil")

0 commit comments

Comments
 (0)