From 9c6182c356792682b9628447ada2422ad201b79c Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman Date: Tue, 10 Sep 2019 16:26:54 -0500 Subject: [PATCH] Rename StorageDiff field from KeccakOfContractAddress to HashedAddress --- .../factories/storage/transformer_test.go | 20 ++++++------ .../fetcher/geth_rpc_storage_fetcher.go | 2 +- .../fetcher/geth_rpc_storage_fetcher_test.go | 30 ++++++++--------- libraries/shared/storage/storage_queue.go | 2 +- .../shared/storage/storage_queue_test.go | 24 +++++++------- libraries/shared/storage/utils/diff.go | 32 +++++++++---------- libraries/shared/storage/utils/diff_test.go | 4 +-- libraries/shared/watcher/storage_watcher.go | 2 +- .../shared/watcher/storage_watcher_test.go | 20 ++++++------ 9 files changed, 68 insertions(+), 68 deletions(-) diff --git a/libraries/shared/factories/storage/transformer_test.go b/libraries/shared/factories/storage/transformer_test.go index a0c2daa1..8fe87e52 100644 --- a/libraries/shared/factories/storage/transformer_test.go +++ b/libraries/shared/factories/storage/transformer_test.go @@ -72,11 +72,11 @@ var _ = Describe("Storage transformer", func() { fakeBlockNumber := 123 fakeBlockHash := "0x67890" fakeRow := utils.StorageDiff{ - KeccakOfContractAddress: common.Hash{}, - BlockHash: common.HexToHash(fakeBlockHash), - BlockHeight: fakeBlockNumber, - StorageKey: common.Hash{}, - StorageValue: rawValue.Hash(), + HashedAddress: common.Hash{}, + BlockHash: common.HexToHash(fakeBlockHash), + BlockHeight: fakeBlockNumber, + StorageKey: common.Hash{}, + StorageValue: rawValue.Hash(), } err := t.Execute(fakeRow) @@ -120,11 +120,11 @@ var _ = Describe("Storage transformer", func() { It("passes the decoded data items to the repository", func() { mappings.Metadata = fakeMetadata fakeRow := utils.StorageDiff{ - KeccakOfContractAddress: common.Hash{}, - BlockHash: common.HexToHash(fakeBlockHash), - BlockHeight: fakeBlockNumber, - StorageKey: common.Hash{}, - StorageValue: rawValue.Hash(), + HashedAddress: common.Hash{}, + BlockHash: common.HexToHash(fakeBlockHash), + BlockHeight: fakeBlockNumber, + StorageKey: common.Hash{}, + StorageValue: rawValue.Hash(), } err := t.Execute(fakeRow) diff --git a/libraries/shared/fetcher/geth_rpc_storage_fetcher.go b/libraries/shared/fetcher/geth_rpc_storage_fetcher.go index 96e94da3..43438ee3 100644 --- a/libraries/shared/fetcher/geth_rpc_storage_fetcher.go +++ b/libraries/shared/fetcher/geth_rpc_storage_fetcher.go @@ -61,7 +61,7 @@ func (fetcher GethRpcStorageFetcher) FetchStorageDiffs(out chan<- utils.StorageD for _, storage := range account.Storage { diff, formatErr := utils.FromGethStateDiff(account, stateDiff, storage) logrus.Trace("adding storage diff to out channel", - "keccak of address: ", diff.KeccakOfContractAddress.Hex(), + "keccak of address: ", diff.HashedAddress.Hex(), "block height: ", diff.BlockHeight, "storage key: ", diff.StorageKey.Hex(), "storage value: ", diff.StorageValue.Hex()) diff --git a/libraries/shared/fetcher/geth_rpc_storage_fetcher_test.go b/libraries/shared/fetcher/geth_rpc_storage_fetcher_test.go index f46f3f2e..b1b1aa10 100644 --- a/libraries/shared/fetcher/geth_rpc_storage_fetcher_test.go +++ b/libraries/shared/fetcher/geth_rpc_storage_fetcher_test.go @@ -113,25 +113,25 @@ var _ = Describe("Geth RPC Storage Fetcher", func() { height := test_data.BlockNumber intHeight := int(height.Int64()) createdExpectedStorageDiff := utils.StorageDiff{ - KeccakOfContractAddress: common.BytesToHash(test_data.ContractLeafKey[:]), - BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"), - BlockHeight: intHeight, - StorageKey: common.BytesToHash(test_data.StorageKey), - StorageValue: common.BytesToHash(test_data.SmallStorageValue), + HashedAddress: common.BytesToHash(test_data.ContractLeafKey[:]), + BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"), + BlockHeight: intHeight, + StorageKey: common.BytesToHash(test_data.StorageKey), + StorageValue: common.BytesToHash(test_data.SmallStorageValue), } updatedExpectedStorageDiff := utils.StorageDiff{ - KeccakOfContractAddress: common.BytesToHash(test_data.AnotherContractLeafKey[:]), - BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"), - BlockHeight: intHeight, - StorageKey: common.BytesToHash(test_data.StorageKey), - StorageValue: common.BytesToHash(test_data.LargeStorageValue), + HashedAddress: common.BytesToHash(test_data.AnotherContractLeafKey[:]), + BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"), + BlockHeight: intHeight, + StorageKey: common.BytesToHash(test_data.StorageKey), + StorageValue: common.BytesToHash(test_data.LargeStorageValue), } deletedExpectedStorageDiff := utils.StorageDiff{ - KeccakOfContractAddress: common.BytesToHash(test_data.AnotherContractLeafKey[:]), - BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"), - BlockHeight: intHeight, - StorageKey: common.BytesToHash(test_data.StorageKey), - StorageValue: common.BytesToHash(test_data.SmallStorageValue), + HashedAddress: common.BytesToHash(test_data.AnotherContractLeafKey[:]), + BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"), + BlockHeight: intHeight, + StorageKey: common.BytesToHash(test_data.StorageKey), + StorageValue: common.BytesToHash(test_data.SmallStorageValue), } createdStateDiff := <-storagediffChan diff --git a/libraries/shared/storage/storage_queue.go b/libraries/shared/storage/storage_queue.go index 4af0c476..c36b9c2d 100644 --- a/libraries/shared/storage/storage_queue.go +++ b/libraries/shared/storage/storage_queue.go @@ -38,7 +38,7 @@ func NewStorageQueue(db *postgres.DB) StorageQueue { func (queue StorageQueue) Add(diff utils.StorageDiff) error { _, err := queue.db.Exec(`INSERT INTO public.queued_storage (contract, block_hash, block_height, storage_key, storage_value) VALUES - ($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING`, diff.KeccakOfContractAddress.Bytes(), diff.BlockHash.Bytes(), + ($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING`, diff.HashedAddress.Bytes(), diff.BlockHash.Bytes(), diff.BlockHeight, diff.StorageKey.Bytes(), diff.StorageValue.Bytes()) return err } diff --git a/libraries/shared/storage/storage_queue_test.go b/libraries/shared/storage/storage_queue_test.go index be53c01e..43faca29 100644 --- a/libraries/shared/storage/storage_queue_test.go +++ b/libraries/shared/storage/storage_queue_test.go @@ -36,11 +36,11 @@ var _ = Describe("Storage queue", func() { BeforeEach(func() { fakeAddr := "0x123456" diff = utils.StorageDiff{ - KeccakOfContractAddress: utils.HexToKeccak256Hash(fakeAddr), - BlockHash: common.HexToHash("0x678901"), - BlockHeight: 987, - StorageKey: common.HexToHash("0x654321"), - StorageValue: common.HexToHash("0x198765"), + HashedAddress: utils.HexToKeccak256Hash(fakeAddr), + BlockHash: common.HexToHash("0x678901"), + BlockHeight: 987, + StorageKey: common.HexToHash("0x654321"), + StorageValue: common.HexToHash("0x198765"), } db = test_config.NewTestDB(test_config.NewTestNode()) test_config.CleanTestDB(db) @@ -83,11 +83,11 @@ var _ = Describe("Storage queue", func() { It("gets all storage diffs from db", func() { fakeAddr := "0x234567" diffTwo := utils.StorageDiff{ - KeccakOfContractAddress: utils.HexToKeccak256Hash(fakeAddr), - BlockHash: common.HexToHash("0x678902"), - BlockHeight: 988, - StorageKey: common.HexToHash("0x654322"), - StorageValue: common.HexToHash("0x198766"), + HashedAddress: utils.HexToKeccak256Hash(fakeAddr), + BlockHash: common.HexToHash("0x678902"), + BlockHeight: 988, + StorageKey: common.HexToHash("0x654322"), + StorageValue: common.HexToHash("0x198766"), } addErr := queue.Add(diffTwo) Expect(addErr).NotTo(HaveOccurred()) @@ -98,13 +98,13 @@ var _ = Describe("Storage queue", func() { Expect(len(diffs)).To(Equal(2)) Expect(diffs[0]).NotTo(Equal(diffs[1])) Expect(diffs[0].Id).NotTo(BeZero()) - Expect(diffs[0].KeccakOfContractAddress).To(Or(Equal(diff.KeccakOfContractAddress), Equal(diffTwo.KeccakOfContractAddress))) + Expect(diffs[0].HashedAddress).To(Or(Equal(diff.HashedAddress), Equal(diffTwo.HashedAddress))) Expect(diffs[0].BlockHash).To(Or(Equal(diff.BlockHash), Equal(diffTwo.BlockHash))) Expect(diffs[0].BlockHeight).To(Or(Equal(diff.BlockHeight), Equal(diffTwo.BlockHeight))) Expect(diffs[0].StorageKey).To(Or(Equal(diff.StorageKey), Equal(diffTwo.StorageKey))) Expect(diffs[0].StorageValue).To(Or(Equal(diff.StorageValue), Equal(diffTwo.StorageValue))) Expect(diffs[1].Id).NotTo(BeZero()) - Expect(diffs[1].KeccakOfContractAddress).To(Or(Equal(diff.KeccakOfContractAddress), Equal(diffTwo.KeccakOfContractAddress))) + Expect(diffs[1].HashedAddress).To(Or(Equal(diff.HashedAddress), Equal(diffTwo.HashedAddress))) Expect(diffs[1].BlockHash).To(Or(Equal(diff.BlockHash), Equal(diffTwo.BlockHash))) Expect(diffs[1].BlockHeight).To(Or(Equal(diff.BlockHeight), Equal(diffTwo.BlockHeight))) Expect(diffs[1].StorageKey).To(Or(Equal(diff.StorageKey), Equal(diffTwo.StorageKey))) diff --git a/libraries/shared/storage/utils/diff.go b/libraries/shared/storage/utils/diff.go index afa75215..a58dfab6 100644 --- a/libraries/shared/storage/utils/diff.go +++ b/libraries/shared/storage/utils/diff.go @@ -27,12 +27,12 @@ import ( const ExpectedRowLength = 5 type StorageDiff struct { - Id int - KeccakOfContractAddress common.Hash `db:"contract"` - BlockHash common.Hash `db:"block_hash"` - BlockHeight int `db:"block_height"` - StorageKey common.Hash `db:"storage_key"` - StorageValue common.Hash `db:"storage_value"` + Id int + HashedAddress common.Hash `db:"contract"` + BlockHash common.Hash `db:"block_hash"` + BlockHeight int `db:"block_height"` + StorageKey common.Hash `db:"storage_key"` + StorageValue common.Hash `db:"storage_value"` } func FromParityCsvRow(csvRow []string) (StorageDiff, error) { @@ -44,11 +44,11 @@ func FromParityCsvRow(csvRow []string) (StorageDiff, error) { return StorageDiff{}, err } return StorageDiff{ - KeccakOfContractAddress: HexToKeccak256Hash(csvRow[0]), - BlockHash: common.HexToHash(csvRow[1]), - BlockHeight: height, - StorageKey: common.HexToHash(csvRow[3]), - StorageValue: common.HexToHash(csvRow[4]), + HashedAddress: HexToKeccak256Hash(csvRow[0]), + BlockHash: common.HexToHash(csvRow[1]), + BlockHeight: height, + StorageKey: common.HexToHash(csvRow[3]), + StorageValue: common.HexToHash(csvRow[4]), }, nil } @@ -60,11 +60,11 @@ func FromGethStateDiff(account statediff.AccountDiff, stateDiff *statediff.State } return StorageDiff{ - KeccakOfContractAddress: common.BytesToHash(account.Key), - BlockHash: stateDiff.BlockHash, - BlockHeight: int(stateDiff.BlockNumber.Int64()), - StorageKey: common.BytesToHash(storage.Key), - StorageValue: common.BytesToHash(decodedValue), + HashedAddress: common.BytesToHash(account.Key), + BlockHash: stateDiff.BlockHash, + BlockHeight: int(stateDiff.BlockNumber.Int64()), + StorageKey: common.BytesToHash(storage.Key), + StorageValue: common.BytesToHash(decodedValue), }, nil } diff --git a/libraries/shared/storage/utils/diff_test.go b/libraries/shared/storage/utils/diff_test.go index 36e80ea3..2de496ac 100644 --- a/libraries/shared/storage/utils/diff_test.go +++ b/libraries/shared/storage/utils/diff_test.go @@ -43,7 +43,7 @@ var _ = Describe("Storage row parsing", func() { Expect(err).NotTo(HaveOccurred()) expectedKeccakOfContractAddress := utils.HexToKeccak256Hash(contract) - Expect(result.KeccakOfContractAddress).To(Equal(expectedKeccakOfContractAddress)) + Expect(result.HashedAddress).To(Equal(expectedKeccakOfContractAddress)) Expect(result.BlockHash).To(Equal(common.HexToHash(blockHash))) Expect(result.BlockHeight).To(Equal(789)) Expect(result.StorageKey).To(Equal(common.HexToHash(storageKey))) @@ -87,7 +87,7 @@ var _ = Describe("Storage row parsing", func() { Expect(err).NotTo(HaveOccurred()) expectedAddress := common.BytesToHash(accountDiff.Key) - Expect(result.KeccakOfContractAddress).To(Equal(expectedAddress)) + Expect(result.HashedAddress).To(Equal(expectedAddress)) Expect(result.BlockHash).To(Equal(fakes.FakeHash)) expectedBlockHeight := int(stateDiff.BlockNumber.Int64()) Expect(result.BlockHeight).To(Equal(expectedBlockHeight)) diff --git a/libraries/shared/watcher/storage_watcher.go b/libraries/shared/watcher/storage_watcher.go index 64ea29b1..7768beb4 100644 --- a/libraries/shared/watcher/storage_watcher.go +++ b/libraries/shared/watcher/storage_watcher.go @@ -74,7 +74,7 @@ func (storageWatcher StorageWatcher) Execute(diffsChan chan utils.StorageDiff, e } func (storageWatcher StorageWatcher) getTransformer(diff utils.StorageDiff) (transformer.StorageTransformer, bool) { - storageTransformer, ok := storageWatcher.KeccakAddressTransformers[diff.KeccakOfContractAddress] + storageTransformer, ok := storageWatcher.KeccakAddressTransformers[diff.HashedAddress] return storageTransformer, ok } diff --git a/libraries/shared/watcher/storage_watcher_test.go b/libraries/shared/watcher/storage_watcher_test.go index 1d2d5f1b..f3fe0afa 100644 --- a/libraries/shared/watcher/storage_watcher_test.go +++ b/libraries/shared/watcher/storage_watcher_test.go @@ -65,12 +65,12 @@ var _ = Describe("Storage Watcher", func() { mockQueue = &mocks.MockStorageQueue{} mockTransformer = &mocks.MockStorageTransformer{KeccakOfAddress: hashedAddress} csvDiff = utils.StorageDiff{ - Id: 1337, - KeccakOfContractAddress: hashedAddress, - BlockHash: common.HexToHash("0xfedcba9876543210"), - BlockHeight: 0, - StorageKey: common.HexToHash("0xabcdef1234567890"), - StorageValue: common.HexToHash("0x9876543210abcdef"), + Id: 1337, + HashedAddress: hashedAddress, + BlockHash: common.HexToHash("0xfedcba9876543210"), + BlockHeight: 0, + StorageKey: common.HexToHash("0xabcdef1234567890"), + StorageValue: common.HexToHash("0x9876543210abcdef"), } }) @@ -190,8 +190,8 @@ var _ = Describe("Storage Watcher", func() { It("deletes obsolete diff from queue if contract not recognized", func(done Done) { obsoleteDiff := utils.StorageDiff{ - Id: csvDiff.Id + 1, - KeccakOfContractAddress: utils.HexToKeccak256Hash("0xfedcba9876543210"), + Id: csvDiff.Id + 1, + HashedAddress: utils.HexToKeccak256Hash("0xfedcba9876543210"), } mockQueue.DiffsToReturn = []utils.StorageDiff{obsoleteDiff} @@ -205,8 +205,8 @@ var _ = Describe("Storage Watcher", func() { It("logs error if deleting obsolete diff fails", func(done Done) { obsoleteDiff := utils.StorageDiff{ - Id: csvDiff.Id + 1, - KeccakOfContractAddress: utils.HexToKeccak256Hash("0xfedcba9876543210"), + Id: csvDiff.Id + 1, + HashedAddress: utils.HexToKeccak256Hash("0xfedcba9876543210"), } mockQueue.DiffsToReturn = []utils.StorageDiff{obsoleteDiff} mockQueue.DeleteErr = fakes.FakeError