Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 9c6182c

Browse files
Rename StorageDiff field from KeccakOfContractAddress to HashedAddress
1 parent 6672ecf commit 9c6182c

File tree

9 files changed

+68
-68
lines changed

9 files changed

+68
-68
lines changed

libraries/shared/factories/storage/transformer_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ var _ = Describe("Storage transformer", func() {
7272
fakeBlockNumber := 123
7373
fakeBlockHash := "0x67890"
7474
fakeRow := utils.StorageDiff{
75-
KeccakOfContractAddress: common.Hash{},
76-
BlockHash: common.HexToHash(fakeBlockHash),
77-
BlockHeight: fakeBlockNumber,
78-
StorageKey: common.Hash{},
79-
StorageValue: rawValue.Hash(),
75+
HashedAddress: common.Hash{},
76+
BlockHash: common.HexToHash(fakeBlockHash),
77+
BlockHeight: fakeBlockNumber,
78+
StorageKey: common.Hash{},
79+
StorageValue: rawValue.Hash(),
8080
}
8181

8282
err := t.Execute(fakeRow)
@@ -120,11 +120,11 @@ var _ = Describe("Storage transformer", func() {
120120
It("passes the decoded data items to the repository", func() {
121121
mappings.Metadata = fakeMetadata
122122
fakeRow := utils.StorageDiff{
123-
KeccakOfContractAddress: common.Hash{},
124-
BlockHash: common.HexToHash(fakeBlockHash),
125-
BlockHeight: fakeBlockNumber,
126-
StorageKey: common.Hash{},
127-
StorageValue: rawValue.Hash(),
123+
HashedAddress: common.Hash{},
124+
BlockHash: common.HexToHash(fakeBlockHash),
125+
BlockHeight: fakeBlockNumber,
126+
StorageKey: common.Hash{},
127+
StorageValue: rawValue.Hash(),
128128
}
129129

130130
err := t.Execute(fakeRow)

libraries/shared/fetcher/geth_rpc_storage_fetcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (fetcher GethRpcStorageFetcher) FetchStorageDiffs(out chan<- utils.StorageD
6161
for _, storage := range account.Storage {
6262
diff, formatErr := utils.FromGethStateDiff(account, stateDiff, storage)
6363
logrus.Trace("adding storage diff to out channel",
64-
"keccak of address: ", diff.KeccakOfContractAddress.Hex(),
64+
"keccak of address: ", diff.HashedAddress.Hex(),
6565
"block height: ", diff.BlockHeight,
6666
"storage key: ", diff.StorageKey.Hex(),
6767
"storage value: ", diff.StorageValue.Hex())

libraries/shared/fetcher/geth_rpc_storage_fetcher_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,25 +113,25 @@ var _ = Describe("Geth RPC Storage Fetcher", func() {
113113
height := test_data.BlockNumber
114114
intHeight := int(height.Int64())
115115
createdExpectedStorageDiff := utils.StorageDiff{
116-
KeccakOfContractAddress: common.BytesToHash(test_data.ContractLeafKey[:]),
117-
BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"),
118-
BlockHeight: intHeight,
119-
StorageKey: common.BytesToHash(test_data.StorageKey),
120-
StorageValue: common.BytesToHash(test_data.SmallStorageValue),
116+
HashedAddress: common.BytesToHash(test_data.ContractLeafKey[:]),
117+
BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"),
118+
BlockHeight: intHeight,
119+
StorageKey: common.BytesToHash(test_data.StorageKey),
120+
StorageValue: common.BytesToHash(test_data.SmallStorageValue),
121121
}
122122
updatedExpectedStorageDiff := utils.StorageDiff{
123-
KeccakOfContractAddress: common.BytesToHash(test_data.AnotherContractLeafKey[:]),
124-
BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"),
125-
BlockHeight: intHeight,
126-
StorageKey: common.BytesToHash(test_data.StorageKey),
127-
StorageValue: common.BytesToHash(test_data.LargeStorageValue),
123+
HashedAddress: common.BytesToHash(test_data.AnotherContractLeafKey[:]),
124+
BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"),
125+
BlockHeight: intHeight,
126+
StorageKey: common.BytesToHash(test_data.StorageKey),
127+
StorageValue: common.BytesToHash(test_data.LargeStorageValue),
128128
}
129129
deletedExpectedStorageDiff := utils.StorageDiff{
130-
KeccakOfContractAddress: common.BytesToHash(test_data.AnotherContractLeafKey[:]),
131-
BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"),
132-
BlockHeight: intHeight,
133-
StorageKey: common.BytesToHash(test_data.StorageKey),
134-
StorageValue: common.BytesToHash(test_data.SmallStorageValue),
130+
HashedAddress: common.BytesToHash(test_data.AnotherContractLeafKey[:]),
131+
BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"),
132+
BlockHeight: intHeight,
133+
StorageKey: common.BytesToHash(test_data.StorageKey),
134+
StorageValue: common.BytesToHash(test_data.SmallStorageValue),
135135
}
136136

137137
createdStateDiff := <-storagediffChan

libraries/shared/storage/storage_queue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewStorageQueue(db *postgres.DB) StorageQueue {
3838
func (queue StorageQueue) Add(diff utils.StorageDiff) error {
3939
_, err := queue.db.Exec(`INSERT INTO public.queued_storage (contract,
4040
block_hash, block_height, storage_key, storage_value) VALUES
41-
($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING`, diff.KeccakOfContractAddress.Bytes(), diff.BlockHash.Bytes(),
41+
($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING`, diff.HashedAddress.Bytes(), diff.BlockHash.Bytes(),
4242
diff.BlockHeight, diff.StorageKey.Bytes(), diff.StorageValue.Bytes())
4343
return err
4444
}

libraries/shared/storage/storage_queue_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ var _ = Describe("Storage queue", func() {
3636
BeforeEach(func() {
3737
fakeAddr := "0x123456"
3838
diff = utils.StorageDiff{
39-
KeccakOfContractAddress: utils.HexToKeccak256Hash(fakeAddr),
40-
BlockHash: common.HexToHash("0x678901"),
41-
BlockHeight: 987,
42-
StorageKey: common.HexToHash("0x654321"),
43-
StorageValue: common.HexToHash("0x198765"),
39+
HashedAddress: utils.HexToKeccak256Hash(fakeAddr),
40+
BlockHash: common.HexToHash("0x678901"),
41+
BlockHeight: 987,
42+
StorageKey: common.HexToHash("0x654321"),
43+
StorageValue: common.HexToHash("0x198765"),
4444
}
4545
db = test_config.NewTestDB(test_config.NewTestNode())
4646
test_config.CleanTestDB(db)
@@ -83,11 +83,11 @@ var _ = Describe("Storage queue", func() {
8383
It("gets all storage diffs from db", func() {
8484
fakeAddr := "0x234567"
8585
diffTwo := utils.StorageDiff{
86-
KeccakOfContractAddress: utils.HexToKeccak256Hash(fakeAddr),
87-
BlockHash: common.HexToHash("0x678902"),
88-
BlockHeight: 988,
89-
StorageKey: common.HexToHash("0x654322"),
90-
StorageValue: common.HexToHash("0x198766"),
86+
HashedAddress: utils.HexToKeccak256Hash(fakeAddr),
87+
BlockHash: common.HexToHash("0x678902"),
88+
BlockHeight: 988,
89+
StorageKey: common.HexToHash("0x654322"),
90+
StorageValue: common.HexToHash("0x198766"),
9191
}
9292
addErr := queue.Add(diffTwo)
9393
Expect(addErr).NotTo(HaveOccurred())
@@ -98,13 +98,13 @@ var _ = Describe("Storage queue", func() {
9898
Expect(len(diffs)).To(Equal(2))
9999
Expect(diffs[0]).NotTo(Equal(diffs[1]))
100100
Expect(diffs[0].Id).NotTo(BeZero())
101-
Expect(diffs[0].KeccakOfContractAddress).To(Or(Equal(diff.KeccakOfContractAddress), Equal(diffTwo.KeccakOfContractAddress)))
101+
Expect(diffs[0].HashedAddress).To(Or(Equal(diff.HashedAddress), Equal(diffTwo.HashedAddress)))
102102
Expect(diffs[0].BlockHash).To(Or(Equal(diff.BlockHash), Equal(diffTwo.BlockHash)))
103103
Expect(diffs[0].BlockHeight).To(Or(Equal(diff.BlockHeight), Equal(diffTwo.BlockHeight)))
104104
Expect(diffs[0].StorageKey).To(Or(Equal(diff.StorageKey), Equal(diffTwo.StorageKey)))
105105
Expect(diffs[0].StorageValue).To(Or(Equal(diff.StorageValue), Equal(diffTwo.StorageValue)))
106106
Expect(diffs[1].Id).NotTo(BeZero())
107-
Expect(diffs[1].KeccakOfContractAddress).To(Or(Equal(diff.KeccakOfContractAddress), Equal(diffTwo.KeccakOfContractAddress)))
107+
Expect(diffs[1].HashedAddress).To(Or(Equal(diff.HashedAddress), Equal(diffTwo.HashedAddress)))
108108
Expect(diffs[1].BlockHash).To(Or(Equal(diff.BlockHash), Equal(diffTwo.BlockHash)))
109109
Expect(diffs[1].BlockHeight).To(Or(Equal(diff.BlockHeight), Equal(diffTwo.BlockHeight)))
110110
Expect(diffs[1].StorageKey).To(Or(Equal(diff.StorageKey), Equal(diffTwo.StorageKey)))

libraries/shared/storage/utils/diff.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ import (
2727
const ExpectedRowLength = 5
2828

2929
type StorageDiff struct {
30-
Id int
31-
KeccakOfContractAddress common.Hash `db:"contract"`
32-
BlockHash common.Hash `db:"block_hash"`
33-
BlockHeight int `db:"block_height"`
34-
StorageKey common.Hash `db:"storage_key"`
35-
StorageValue common.Hash `db:"storage_value"`
30+
Id int
31+
HashedAddress common.Hash `db:"contract"`
32+
BlockHash common.Hash `db:"block_hash"`
33+
BlockHeight int `db:"block_height"`
34+
StorageKey common.Hash `db:"storage_key"`
35+
StorageValue common.Hash `db:"storage_value"`
3636
}
3737

3838
func FromParityCsvRow(csvRow []string) (StorageDiff, error) {
@@ -44,11 +44,11 @@ func FromParityCsvRow(csvRow []string) (StorageDiff, error) {
4444
return StorageDiff{}, err
4545
}
4646
return StorageDiff{
47-
KeccakOfContractAddress: HexToKeccak256Hash(csvRow[0]),
48-
BlockHash: common.HexToHash(csvRow[1]),
49-
BlockHeight: height,
50-
StorageKey: common.HexToHash(csvRow[3]),
51-
StorageValue: common.HexToHash(csvRow[4]),
47+
HashedAddress: HexToKeccak256Hash(csvRow[0]),
48+
BlockHash: common.HexToHash(csvRow[1]),
49+
BlockHeight: height,
50+
StorageKey: common.HexToHash(csvRow[3]),
51+
StorageValue: common.HexToHash(csvRow[4]),
5252
}, nil
5353
}
5454

@@ -60,11 +60,11 @@ func FromGethStateDiff(account statediff.AccountDiff, stateDiff *statediff.State
6060
}
6161

6262
return StorageDiff{
63-
KeccakOfContractAddress: common.BytesToHash(account.Key),
64-
BlockHash: stateDiff.BlockHash,
65-
BlockHeight: int(stateDiff.BlockNumber.Int64()),
66-
StorageKey: common.BytesToHash(storage.Key),
67-
StorageValue: common.BytesToHash(decodedValue),
63+
HashedAddress: common.BytesToHash(account.Key),
64+
BlockHash: stateDiff.BlockHash,
65+
BlockHeight: int(stateDiff.BlockNumber.Int64()),
66+
StorageKey: common.BytesToHash(storage.Key),
67+
StorageValue: common.BytesToHash(decodedValue),
6868
}, nil
6969
}
7070

libraries/shared/storage/utils/diff_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var _ = Describe("Storage row parsing", func() {
4343

4444
Expect(err).NotTo(HaveOccurred())
4545
expectedKeccakOfContractAddress := utils.HexToKeccak256Hash(contract)
46-
Expect(result.KeccakOfContractAddress).To(Equal(expectedKeccakOfContractAddress))
46+
Expect(result.HashedAddress).To(Equal(expectedKeccakOfContractAddress))
4747
Expect(result.BlockHash).To(Equal(common.HexToHash(blockHash)))
4848
Expect(result.BlockHeight).To(Equal(789))
4949
Expect(result.StorageKey).To(Equal(common.HexToHash(storageKey)))
@@ -87,7 +87,7 @@ var _ = Describe("Storage row parsing", func() {
8787
Expect(err).NotTo(HaveOccurred())
8888

8989
expectedAddress := common.BytesToHash(accountDiff.Key)
90-
Expect(result.KeccakOfContractAddress).To(Equal(expectedAddress))
90+
Expect(result.HashedAddress).To(Equal(expectedAddress))
9191
Expect(result.BlockHash).To(Equal(fakes.FakeHash))
9292
expectedBlockHeight := int(stateDiff.BlockNumber.Int64())
9393
Expect(result.BlockHeight).To(Equal(expectedBlockHeight))

libraries/shared/watcher/storage_watcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (storageWatcher StorageWatcher) Execute(diffsChan chan utils.StorageDiff, e
7474
}
7575

7676
func (storageWatcher StorageWatcher) getTransformer(diff utils.StorageDiff) (transformer.StorageTransformer, bool) {
77-
storageTransformer, ok := storageWatcher.KeccakAddressTransformers[diff.KeccakOfContractAddress]
77+
storageTransformer, ok := storageWatcher.KeccakAddressTransformers[diff.HashedAddress]
7878
return storageTransformer, ok
7979
}
8080

libraries/shared/watcher/storage_watcher_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ var _ = Describe("Storage Watcher", func() {
6565
mockQueue = &mocks.MockStorageQueue{}
6666
mockTransformer = &mocks.MockStorageTransformer{KeccakOfAddress: hashedAddress}
6767
csvDiff = utils.StorageDiff{
68-
Id: 1337,
69-
KeccakOfContractAddress: hashedAddress,
70-
BlockHash: common.HexToHash("0xfedcba9876543210"),
71-
BlockHeight: 0,
72-
StorageKey: common.HexToHash("0xabcdef1234567890"),
73-
StorageValue: common.HexToHash("0x9876543210abcdef"),
68+
Id: 1337,
69+
HashedAddress: hashedAddress,
70+
BlockHash: common.HexToHash("0xfedcba9876543210"),
71+
BlockHeight: 0,
72+
StorageKey: common.HexToHash("0xabcdef1234567890"),
73+
StorageValue: common.HexToHash("0x9876543210abcdef"),
7474
}
7575
})
7676

@@ -190,8 +190,8 @@ var _ = Describe("Storage Watcher", func() {
190190

191191
It("deletes obsolete diff from queue if contract not recognized", func(done Done) {
192192
obsoleteDiff := utils.StorageDiff{
193-
Id: csvDiff.Id + 1,
194-
KeccakOfContractAddress: utils.HexToKeccak256Hash("0xfedcba9876543210"),
193+
Id: csvDiff.Id + 1,
194+
HashedAddress: utils.HexToKeccak256Hash("0xfedcba9876543210"),
195195
}
196196
mockQueue.DiffsToReturn = []utils.StorageDiff{obsoleteDiff}
197197

@@ -205,8 +205,8 @@ var _ = Describe("Storage Watcher", func() {
205205

206206
It("logs error if deleting obsolete diff fails", func(done Done) {
207207
obsoleteDiff := utils.StorageDiff{
208-
Id: csvDiff.Id + 1,
209-
KeccakOfContractAddress: utils.HexToKeccak256Hash("0xfedcba9876543210"),
208+
Id: csvDiff.Id + 1,
209+
HashedAddress: utils.HexToKeccak256Hash("0xfedcba9876543210"),
210210
}
211211
mockQueue.DiffsToReturn = []utils.StorageDiff{obsoleteDiff}
212212
mockQueue.DeleteErr = fakes.FakeError

0 commit comments

Comments
 (0)