Skip to content
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

[BUG] - pool_owner.hash cannot be joined with stake_address.hash_raw #543

Closed
tdiesler opened this issue Mar 11, 2021 · 5 comments · Fixed by #553
Closed

[BUG] - pool_owner.hash cannot be joined with stake_address.hash_raw #543

tdiesler opened this issue Mar 11, 2021 · 5 comments · Fixed by #553

Comments

@tdiesler
Copy link

tdiesler commented Mar 11, 2021

Other than pool_update.reward_addr and epoch_stake.addr_id, pool_owner.hash cannot be joined with stake_address.hash_raw.

Is this intentionally? Perhaps there is another way to get at the BECH32 for a pool owner?

@erikd
Copy link
Contributor

erikd commented Mar 11, 2021

Why can't pool_owner.hash be joined with stake_address.hash_raw ?

Ahh, now I see it. stake_address.hash_raw is 33 bytes (because if prepends a byte indicating the network) when pool_owner.hash is a 32 byte hash.

Yes, that is a pain in the neck!. The pool_owner.hash should be replaced with an index into the stake_address table. That would make joins easy and obvious.

@tdiesler tdiesler changed the title pool_owner.hash cannot be joined with stake_address.hash_raw [BUG] - pool_owner.hash cannot be joined with stake_address.hash_raw Mar 12, 2021
@tdiesler
Copy link
Author

tdiesler commented Mar 12, 2021

Merci. Would it be safe to prepend the pool_owner.hash with '\xe1' for now?

@erikd
Copy link
Contributor

erikd commented Mar 12, 2021

Yes, that would help for now. Also, please post the working query here.

@tdiesler
Copy link
Author

tdiesler commented Mar 12, 2021

Here you go ... it actually removes the prefix from both and does a string compare

# Pool Update
SELECT pu.id, pu.active_epoch_no epoch, pu.meta_id, pu.pledge, pu.margin, sar.view reward_addr, sao.view owner_addr
FROM pool_update pu
LEFT JOIN pool_owner po ON pu.registered_tx_id = po.registered_tx_id
INNER JOIN stake_address sar ON pu.reward_addr = sar.hash_raw
INNER JOIN stake_address sao ON substring(cast(po.hash as varchar), 3) = substring(cast(sao.hash_raw as varchar), 5)
WHERE hash_id = 1806
ORDER BY pu.id DESC

I use the H2 Console for this

Untitled

@tdiesler
Copy link
Author

simplified, like this ...

SELECT pu.active_epoch_no epoch, pu.meta_id, pu.pledge, pu.margin, sar.view reward_addr, sao.view owner_addr
FROM pool_update pu
JOIN pool_owner po ON pu.registered_tx_id = po.registered_tx_id
JOIN stake_address sar ON pu.reward_addr = sar.hash_raw
JOIN stake_address sao ON substring(cast(po.hash as varchar), 3) = substring(cast(sao.hash_raw as varchar), 5)
WHERE pu.hash_id = 1806
ORDER BY pu.id DESC

erikd added a commit that referenced this issue Mar 23, 2021
The `pool_owner` table used to contain a hash of the pool owners staking
key, which is difficult to do an SQL join on so instead we use an index
into the `stake_address` table.

To get a staking credential from a staking key hash it just needs to be
wrapped it in a `KeyHashObj` constructor whose id can then be queried from
the `stake_address` table.

Closes: #543
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 a pull request may close this issue.

2 participants