-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: analyzer/runtime: Store a more-parsed tx in the db #368
Changes from 1 commit
3eff2e9
9327bb9
cd21b56
20a13af
25e2bc0
c8dbca9
13298d3
02ef2d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -313,33 +313,42 @@ const ( | |
SELECT | ||
txs.round, | ||
txs.tx_index, | ||
txs.timestamp, | ||
txs.tx_hash, | ||
txs.tx_eth_hash, | ||
signer0.signer_address AS sender0, | ||
encode(signer_eth.address_data, 'hex') AS sender0_eth, | ||
signer0.nonce AS nonce0, | ||
txs.fee, | ||
txs.gas_limit, | ||
txs.gas_used, | ||
txs.size, | ||
txs.timestamp, | ||
txs.raw, | ||
txs.result_raw, | ||
( | ||
SELECT | ||
json_object_agg(pre.address, encode(pre.address_data, 'hex')) | ||
FROM chain.runtime_related_transactions AS rel | ||
JOIN chain.address_preimages AS pre ON rel.account_address = pre.address | ||
WHERE txs.runtime = rel.runtime | ||
AND txs.round = rel.tx_round | ||
AND txs.tx_index = rel.tx_index | ||
) AS eth_addr_lookup | ||
txs.method, | ||
txs.body, | ||
-- .to, .to_eth, and .amout have to be inferred from the body post-hoc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. amout -> amount There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
txs.success, | ||
txs.error_module, | ||
txs.error_code, | ||
txs.error_message | ||
FROM chain.runtime_transactions AS txs | ||
LEFT JOIN chain.runtime_related_transactions AS rel ON txs.round = rel.tx_round | ||
AND txs.tx_index = rel.tx_index | ||
AND txs.runtime = rel.runtime | ||
LEFT JOIN chain.runtime_transaction_signers AS signer0 USING (runtime, round, tx_index) | ||
LEFT JOIN chain.address_preimages AS signer_eth ON | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AS signer0_eth |
||
(signer0.signer_address = signer_eth.address) AND | ||
(signer_eth.context_identifier = 'oasis-runtime-sdk/address: secp256k1eth') AND | ||
(signer_eth.context_version = 0) | ||
LEFT JOIN chain.runtime_related_transactions AS rel ON | ||
(txs.round = rel.tx_round) AND | ||
(txs.tx_index = rel.tx_index) AND | ||
(txs.runtime = rel.runtime) AND | ||
-- When related_address ($4) is NULL and hence we do no filtering on it, avoid the join altogether. | ||
-- Otherwise, every tx will be returned as many times as there are related addresses for it. | ||
AND $4::text IS NOT NULL | ||
WHERE (txs.runtime = $1) AND | ||
($2::bigint IS NULL OR txs.round = $2::bigint) AND | ||
($3::text IS NULL OR txs.tx_hash = $3::text OR txs.tx_eth_hash = $3::text) AND | ||
($4::text IS NULL OR rel.account_address = $4::text) | ||
($4::text IS NOT NULL) | ||
WHERE | ||
(txs.runtime = $1) AND | ||
(signer0.signer_index = 0) AND | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be a dumb q, but is it worth moving this line to the join above? eg, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not dumb at all, might be a little more readable. I debated it myself. A gotcha is that you cannot mix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question about this: does factoring out this WHERE signer0.signer_index = 0 change the meaning of the join outer-sidedness? if we tried doing the same for a hypothetical signer1 field, would the dbms conceptually first come up with a record: method=accounts.Transfer, signer0=oasis1xxxx, signer1=NULL and then determine NULL != 0 and discard it? we're lucky here that everything actually has a signer0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought they were equivalent. I now see there's a subtle difference:
See "Notice that placing the restriction in the WHERE clause produces a different result:" here. Thanks. For our case ... Perhaps we should keep the WHERE even though it's less "pure"? It makes the join less "outer": In the hypothetical case of a tx without a signer, WHERE would discard that tx, whereas ON would return the tx but with a null signer. But our data types don't support null signers. Hrm it's actually good that we'd then crash and return a 500 for a result involving such a tx. OK let's change the query. It's all pretty philosophical because we always have a signer, but still. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changing in #367 |
||
($2::bigint IS NULL OR txs.round = $2::bigint) AND | ||
($3::text IS NULL OR txs.tx_hash = $3::text OR txs.tx_eth_hash = $3::text) AND | ||
($4::text IS NULL OR rel.account_address = $4::text) | ||
ORDER BY txs.round DESC, txs.tx_index DESC | ||
LIMIT $5::bigint | ||
OFFSET $6::bigint | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
view logic in storage layer 🙃