Skip to content

(VDB-110) cat wards storage transformer#88

Merged
gslaughl merged 4 commits intostagingfrom
vdb-1110-cat-wards
Jan 14, 2020
Merged

(VDB-110) cat wards storage transformer#88
gslaughl merged 4 commits intostagingfrom
vdb-1110-cat-wards

Conversation

@gslaughl
Copy link
Copy Markdown
Contributor

@gslaughl gslaughl commented Jan 9, 2020

Transforms wards storage mapping for the Cat contract. Using usr and msg_sender of rely and deny events for key discovery.

header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
log_id BIGINT NOT NULL REFERENCES header_sync_logs (id) ON DELETE CASCADE,
address_id INTEGER NOT NULL REFERENCES addresses (id) ON DELETE CASCADE,
msg_sender INTEGER NOT NULL REFERENCES addresses (id) ON DELETE CASCADE,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to make some event transformer updates, because we ended up needing the msg.sender of auth events (for all contracts besides Vat, which doesn't give us an easy way of finding msg.sender).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads on up these for the rebase... header_sync_logs => event_logs and addresses => public.addresses

header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
address_id INTEGER NOT NULL REFERENCES addresses (id) ON DELETE CASCADE,
usr INTEGER NOT NULL REFERENCES addresses (id) ON DELETE CASCADE,
wards INTEGER NOT NULL,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a uint256 in the contract, but I figured a regular int would work here since the value can only be 0 or 1 :P

TableName event.TableName
}

func (t Transformer) ToModels(_ string, logs []core.HeaderSyncLog, db *postgres.DB) ([]event.InsertionModel, error) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up separating out the vat_auth event transformer, because it's looking less and less like the generic auth one. I figured since both the structure of the log and the structure of the target InsertionModel are different from the generic version, it would make sense to just let vat_auth events have their own transformer.

Comment on lines +268 to +286
SELECT addresses.address
FROM maker.rely
LEFT JOIN public.addresses ON rely.usr = addresses.id
WHERE rely.address_id = $1
UNION
SELECT addresses.address
FROM maker.rely
LEFT JOIN public.addresses ON rely.msg_sender = addresses.id
WHERE rely.address_id = $1
UNION
SELECT addresses.address
FROM maker.deny
LEFT JOIN public.addresses ON deny.usr = addresses.id
WHERE deny.address_id = $1
UNION
SELECT addresses.address
FROM maker.deny
LEFT JOIN public.addresses ON deny.msg_sender = addresses.id
WHERE deny.address_id = $1`, contractAddressID)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason this query needs to combine more than just rely.usr and deny.usr is because we also want to find the msg_sender of the transaction that deployed the contract. Since we don't have a direct way of doing that (constructor doesn't emit an event), we have to infer it.

The msg_sender of the first rely event must be the msg_sender who deployed the contract, because at that point no one else is authorized to call rely (or any other method with the auth modifier). Technically I didn't need to UNION with all rely/deny msg_senders (just the 1st rely event's), but I figured we might as well for redundancy's sake.

Also worth noting that these tables will likely be very small, so hopefully there's no reason to worry about performance.

Context("Cat deny events", func() {
usrAddress := "0x13141b8a5e4a82ebc6b636849dd6a515185d6236"
denyIntegrationTest(int64(14764643), test_data.CatAddress(), usrAddress, defaultOffset)
denyIntegrationTest(int64(14764643), test_data.CatAddress(), usrAddress, usrAddress)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of weird that for all these integration tests I'm passing in usrAddress twice, but it's because I just happened to pick deny events where msg.senders are passing their own addresses in as the usr parameter. I didn't want to abstract usrAddressHex and msgSenderAddressHex (on line 59) into a single parameter, because I was worried that would imply that those 2 addresses have to be the same, which they don't.

@gslaughl gslaughl force-pushed the vdb-1074-rely-transformer branch from eaccd13 to f78198d Compare January 9, 2020 19:51
@gslaughl gslaughl changed the base branch from vdb-1074-rely-transformer to staging January 10, 2020 19:27
@gslaughl gslaughl force-pushed the vdb-1110-cat-wards branch 2 times, most recently from f6e442c to 0b19eed Compare January 10, 2020 19:31
Copy link
Copy Markdown
Contributor

@rmulhol rmulhol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

storageKeysLookup = storage.NewKeysLookup(cat.NewKeysLoader(&mcdStorage.MakerStorageRepository{}))
repository = cat.CatStorageRepository{}
contractAddress = "81f7aa9c1570de564eb511b3a1e57dae558c65b5"
contractAddress = test_data.CatAddress()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@@ -30,41 +30,25 @@ var _ = Describe("Deny Transformer", func() {
test_data.RelyHeaderSyncLog.Log.Address.String())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RelyHeaderSyncLog => RelyEventLog

repository.GetFlopBidIdsCalledWith = contractAddress
return repository.FlopBidIds, repository.GetFlopBidIdsError
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇


var insertWardsQuery = `INSERT INTO maker.wards (diff_id, header_id, address_id, usr, wards) VALUES ($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING`

func InsertWards(diffID, headerID int64, metadata storage.ValueMetadata, contractAddress, wards string, db *postgres.DB) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gabe Laughlin added 4 commits January 13, 2020 22:34
Transform auth event msg.sender, separate out Vat auth transformer
Reduce wards duplication between transformers
GetCdpis() ([]string, error)
GetDaiKeys() ([]string, error)
GetFlapBidIds(string) ([]string, error)
GetFlipBidIds(contractAddress string) ([]string, error)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@yaoandrew yaoandrew mentioned this pull request Jan 14, 2020
@gslaughl gslaughl merged commit a2e1f1b into staging Jan 14, 2020
@gslaughl gslaughl deleted the vdb-1110-cat-wards branch January 14, 2020 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants