Rename StorageDiff field from KeccakOfContractAddress to HashedAddress

This commit is contained in:
Elizabeth Engelman 2019-09-10 16:26:54 -05:00
parent 6672ecf547
commit 9c6182c356
9 changed files with 68 additions and 68 deletions

View File

@ -72,11 +72,11 @@ var _ = Describe("Storage transformer", func() {
fakeBlockNumber := 123 fakeBlockNumber := 123
fakeBlockHash := "0x67890" fakeBlockHash := "0x67890"
fakeRow := utils.StorageDiff{ fakeRow := utils.StorageDiff{
KeccakOfContractAddress: common.Hash{}, HashedAddress: common.Hash{},
BlockHash: common.HexToHash(fakeBlockHash), BlockHash: common.HexToHash(fakeBlockHash),
BlockHeight: fakeBlockNumber, BlockHeight: fakeBlockNumber,
StorageKey: common.Hash{}, StorageKey: common.Hash{},
StorageValue: rawValue.Hash(), StorageValue: rawValue.Hash(),
} }
err := t.Execute(fakeRow) err := t.Execute(fakeRow)
@ -120,11 +120,11 @@ var _ = Describe("Storage transformer", func() {
It("passes the decoded data items to the repository", func() { It("passes the decoded data items to the repository", func() {
mappings.Metadata = fakeMetadata mappings.Metadata = fakeMetadata
fakeRow := utils.StorageDiff{ fakeRow := utils.StorageDiff{
KeccakOfContractAddress: common.Hash{}, HashedAddress: common.Hash{},
BlockHash: common.HexToHash(fakeBlockHash), BlockHash: common.HexToHash(fakeBlockHash),
BlockHeight: fakeBlockNumber, BlockHeight: fakeBlockNumber,
StorageKey: common.Hash{}, StorageKey: common.Hash{},
StorageValue: rawValue.Hash(), StorageValue: rawValue.Hash(),
} }
err := t.Execute(fakeRow) err := t.Execute(fakeRow)

View File

@ -61,7 +61,7 @@ func (fetcher GethRpcStorageFetcher) FetchStorageDiffs(out chan<- utils.StorageD
for _, storage := range account.Storage { for _, storage := range account.Storage {
diff, formatErr := utils.FromGethStateDiff(account, stateDiff, storage) diff, formatErr := utils.FromGethStateDiff(account, stateDiff, storage)
logrus.Trace("adding storage diff to out channel", logrus.Trace("adding storage diff to out channel",
"keccak of address: ", diff.KeccakOfContractAddress.Hex(), "keccak of address: ", diff.HashedAddress.Hex(),
"block height: ", diff.BlockHeight, "block height: ", diff.BlockHeight,
"storage key: ", diff.StorageKey.Hex(), "storage key: ", diff.StorageKey.Hex(),
"storage value: ", diff.StorageValue.Hex()) "storage value: ", diff.StorageValue.Hex())

View File

@ -113,25 +113,25 @@ var _ = Describe("Geth RPC Storage Fetcher", func() {
height := test_data.BlockNumber height := test_data.BlockNumber
intHeight := int(height.Int64()) intHeight := int(height.Int64())
createdExpectedStorageDiff := utils.StorageDiff{ createdExpectedStorageDiff := utils.StorageDiff{
KeccakOfContractAddress: common.BytesToHash(test_data.ContractLeafKey[:]), HashedAddress: common.BytesToHash(test_data.ContractLeafKey[:]),
BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"), BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"),
BlockHeight: intHeight, BlockHeight: intHeight,
StorageKey: common.BytesToHash(test_data.StorageKey), StorageKey: common.BytesToHash(test_data.StorageKey),
StorageValue: common.BytesToHash(test_data.SmallStorageValue), StorageValue: common.BytesToHash(test_data.SmallStorageValue),
} }
updatedExpectedStorageDiff := utils.StorageDiff{ updatedExpectedStorageDiff := utils.StorageDiff{
KeccakOfContractAddress: common.BytesToHash(test_data.AnotherContractLeafKey[:]), HashedAddress: common.BytesToHash(test_data.AnotherContractLeafKey[:]),
BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"), BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"),
BlockHeight: intHeight, BlockHeight: intHeight,
StorageKey: common.BytesToHash(test_data.StorageKey), StorageKey: common.BytesToHash(test_data.StorageKey),
StorageValue: common.BytesToHash(test_data.LargeStorageValue), StorageValue: common.BytesToHash(test_data.LargeStorageValue),
} }
deletedExpectedStorageDiff := utils.StorageDiff{ deletedExpectedStorageDiff := utils.StorageDiff{
KeccakOfContractAddress: common.BytesToHash(test_data.AnotherContractLeafKey[:]), HashedAddress: common.BytesToHash(test_data.AnotherContractLeafKey[:]),
BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"), BlockHash: common.HexToHash("0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"),
BlockHeight: intHeight, BlockHeight: intHeight,
StorageKey: common.BytesToHash(test_data.StorageKey), StorageKey: common.BytesToHash(test_data.StorageKey),
StorageValue: common.BytesToHash(test_data.SmallStorageValue), StorageValue: common.BytesToHash(test_data.SmallStorageValue),
} }
createdStateDiff := <-storagediffChan createdStateDiff := <-storagediffChan

View File

@ -38,7 +38,7 @@ func NewStorageQueue(db *postgres.DB) StorageQueue {
func (queue StorageQueue) Add(diff utils.StorageDiff) error { func (queue StorageQueue) Add(diff utils.StorageDiff) error {
_, err := queue.db.Exec(`INSERT INTO public.queued_storage (contract, _, err := queue.db.Exec(`INSERT INTO public.queued_storage (contract,
block_hash, block_height, storage_key, storage_value) VALUES 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()) diff.BlockHeight, diff.StorageKey.Bytes(), diff.StorageValue.Bytes())
return err return err
} }

View File

@ -36,11 +36,11 @@ var _ = Describe("Storage queue", func() {
BeforeEach(func() { BeforeEach(func() {
fakeAddr := "0x123456" fakeAddr := "0x123456"
diff = utils.StorageDiff{ diff = utils.StorageDiff{
KeccakOfContractAddress: utils.HexToKeccak256Hash(fakeAddr), HashedAddress: utils.HexToKeccak256Hash(fakeAddr),
BlockHash: common.HexToHash("0x678901"), BlockHash: common.HexToHash("0x678901"),
BlockHeight: 987, BlockHeight: 987,
StorageKey: common.HexToHash("0x654321"), StorageKey: common.HexToHash("0x654321"),
StorageValue: common.HexToHash("0x198765"), StorageValue: common.HexToHash("0x198765"),
} }
db = test_config.NewTestDB(test_config.NewTestNode()) db = test_config.NewTestDB(test_config.NewTestNode())
test_config.CleanTestDB(db) test_config.CleanTestDB(db)
@ -83,11 +83,11 @@ var _ = Describe("Storage queue", func() {
It("gets all storage diffs from db", func() { It("gets all storage diffs from db", func() {
fakeAddr := "0x234567" fakeAddr := "0x234567"
diffTwo := utils.StorageDiff{ diffTwo := utils.StorageDiff{
KeccakOfContractAddress: utils.HexToKeccak256Hash(fakeAddr), HashedAddress: utils.HexToKeccak256Hash(fakeAddr),
BlockHash: common.HexToHash("0x678902"), BlockHash: common.HexToHash("0x678902"),
BlockHeight: 988, BlockHeight: 988,
StorageKey: common.HexToHash("0x654322"), StorageKey: common.HexToHash("0x654322"),
StorageValue: common.HexToHash("0x198766"), StorageValue: common.HexToHash("0x198766"),
} }
addErr := queue.Add(diffTwo) addErr := queue.Add(diffTwo)
Expect(addErr).NotTo(HaveOccurred()) Expect(addErr).NotTo(HaveOccurred())
@ -98,13 +98,13 @@ var _ = Describe("Storage queue", func() {
Expect(len(diffs)).To(Equal(2)) Expect(len(diffs)).To(Equal(2))
Expect(diffs[0]).NotTo(Equal(diffs[1])) Expect(diffs[0]).NotTo(Equal(diffs[1]))
Expect(diffs[0].Id).NotTo(BeZero()) 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].BlockHash).To(Or(Equal(diff.BlockHash), Equal(diffTwo.BlockHash)))
Expect(diffs[0].BlockHeight).To(Or(Equal(diff.BlockHeight), Equal(diffTwo.BlockHeight))) 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].StorageKey).To(Or(Equal(diff.StorageKey), Equal(diffTwo.StorageKey)))
Expect(diffs[0].StorageValue).To(Or(Equal(diff.StorageValue), Equal(diffTwo.StorageValue))) Expect(diffs[0].StorageValue).To(Or(Equal(diff.StorageValue), Equal(diffTwo.StorageValue)))
Expect(diffs[1].Id).NotTo(BeZero()) 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].BlockHash).To(Or(Equal(diff.BlockHash), Equal(diffTwo.BlockHash)))
Expect(diffs[1].BlockHeight).To(Or(Equal(diff.BlockHeight), Equal(diffTwo.BlockHeight))) Expect(diffs[1].BlockHeight).To(Or(Equal(diff.BlockHeight), Equal(diffTwo.BlockHeight)))
Expect(diffs[1].StorageKey).To(Or(Equal(diff.StorageKey), Equal(diffTwo.StorageKey))) Expect(diffs[1].StorageKey).To(Or(Equal(diff.StorageKey), Equal(diffTwo.StorageKey)))

View File

@ -27,12 +27,12 @@ import (
const ExpectedRowLength = 5 const ExpectedRowLength = 5
type StorageDiff struct { type StorageDiff struct {
Id int Id int
KeccakOfContractAddress common.Hash `db:"contract"` HashedAddress common.Hash `db:"contract"`
BlockHash common.Hash `db:"block_hash"` BlockHash common.Hash `db:"block_hash"`
BlockHeight int `db:"block_height"` BlockHeight int `db:"block_height"`
StorageKey common.Hash `db:"storage_key"` StorageKey common.Hash `db:"storage_key"`
StorageValue common.Hash `db:"storage_value"` StorageValue common.Hash `db:"storage_value"`
} }
func FromParityCsvRow(csvRow []string) (StorageDiff, error) { func FromParityCsvRow(csvRow []string) (StorageDiff, error) {
@ -44,11 +44,11 @@ func FromParityCsvRow(csvRow []string) (StorageDiff, error) {
return StorageDiff{}, err return StorageDiff{}, err
} }
return StorageDiff{ return StorageDiff{
KeccakOfContractAddress: HexToKeccak256Hash(csvRow[0]), HashedAddress: HexToKeccak256Hash(csvRow[0]),
BlockHash: common.HexToHash(csvRow[1]), BlockHash: common.HexToHash(csvRow[1]),
BlockHeight: height, BlockHeight: height,
StorageKey: common.HexToHash(csvRow[3]), StorageKey: common.HexToHash(csvRow[3]),
StorageValue: common.HexToHash(csvRow[4]), StorageValue: common.HexToHash(csvRow[4]),
}, nil }, nil
} }
@ -60,11 +60,11 @@ func FromGethStateDiff(account statediff.AccountDiff, stateDiff *statediff.State
} }
return StorageDiff{ return StorageDiff{
KeccakOfContractAddress: common.BytesToHash(account.Key), HashedAddress: common.BytesToHash(account.Key),
BlockHash: stateDiff.BlockHash, BlockHash: stateDiff.BlockHash,
BlockHeight: int(stateDiff.BlockNumber.Int64()), BlockHeight: int(stateDiff.BlockNumber.Int64()),
StorageKey: common.BytesToHash(storage.Key), StorageKey: common.BytesToHash(storage.Key),
StorageValue: common.BytesToHash(decodedValue), StorageValue: common.BytesToHash(decodedValue),
}, nil }, nil
} }

View File

@ -43,7 +43,7 @@ var _ = Describe("Storage row parsing", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
expectedKeccakOfContractAddress := utils.HexToKeccak256Hash(contract) 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.BlockHash).To(Equal(common.HexToHash(blockHash)))
Expect(result.BlockHeight).To(Equal(789)) Expect(result.BlockHeight).To(Equal(789))
Expect(result.StorageKey).To(Equal(common.HexToHash(storageKey))) Expect(result.StorageKey).To(Equal(common.HexToHash(storageKey)))
@ -87,7 +87,7 @@ var _ = Describe("Storage row parsing", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
expectedAddress := common.BytesToHash(accountDiff.Key) expectedAddress := common.BytesToHash(accountDiff.Key)
Expect(result.KeccakOfContractAddress).To(Equal(expectedAddress)) Expect(result.HashedAddress).To(Equal(expectedAddress))
Expect(result.BlockHash).To(Equal(fakes.FakeHash)) Expect(result.BlockHash).To(Equal(fakes.FakeHash))
expectedBlockHeight := int(stateDiff.BlockNumber.Int64()) expectedBlockHeight := int(stateDiff.BlockNumber.Int64())
Expect(result.BlockHeight).To(Equal(expectedBlockHeight)) Expect(result.BlockHeight).To(Equal(expectedBlockHeight))

View File

@ -74,7 +74,7 @@ func (storageWatcher StorageWatcher) Execute(diffsChan chan utils.StorageDiff, e
} }
func (storageWatcher StorageWatcher) getTransformer(diff utils.StorageDiff) (transformer.StorageTransformer, bool) { 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 return storageTransformer, ok
} }

View File

@ -65,12 +65,12 @@ var _ = Describe("Storage Watcher", func() {
mockQueue = &mocks.MockStorageQueue{} mockQueue = &mocks.MockStorageQueue{}
mockTransformer = &mocks.MockStorageTransformer{KeccakOfAddress: hashedAddress} mockTransformer = &mocks.MockStorageTransformer{KeccakOfAddress: hashedAddress}
csvDiff = utils.StorageDiff{ csvDiff = utils.StorageDiff{
Id: 1337, Id: 1337,
KeccakOfContractAddress: hashedAddress, HashedAddress: hashedAddress,
BlockHash: common.HexToHash("0xfedcba9876543210"), BlockHash: common.HexToHash("0xfedcba9876543210"),
BlockHeight: 0, BlockHeight: 0,
StorageKey: common.HexToHash("0xabcdef1234567890"), StorageKey: common.HexToHash("0xabcdef1234567890"),
StorageValue: common.HexToHash("0x9876543210abcdef"), 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) { It("deletes obsolete diff from queue if contract not recognized", func(done Done) {
obsoleteDiff := utils.StorageDiff{ obsoleteDiff := utils.StorageDiff{
Id: csvDiff.Id + 1, Id: csvDiff.Id + 1,
KeccakOfContractAddress: utils.HexToKeccak256Hash("0xfedcba9876543210"), HashedAddress: utils.HexToKeccak256Hash("0xfedcba9876543210"),
} }
mockQueue.DiffsToReturn = []utils.StorageDiff{obsoleteDiff} 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) { It("logs error if deleting obsolete diff fails", func(done Done) {
obsoleteDiff := utils.StorageDiff{ obsoleteDiff := utils.StorageDiff{
Id: csvDiff.Id + 1, Id: csvDiff.Id + 1,
KeccakOfContractAddress: utils.HexToKeccak256Hash("0xfedcba9876543210"), HashedAddress: utils.HexToKeccak256Hash("0xfedcba9876543210"),
} }
mockQueue.DiffsToReturn = []utils.StorageDiff{obsoleteDiff} mockQueue.DiffsToReturn = []utils.StorageDiff{obsoleteDiff}
mockQueue.DeleteErr = fakes.FakeError mockQueue.DeleteErr = fakes.FakeError