Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

[CAD-779] Add a database backend. #8

Merged
merged 8 commits into from
Jun 19, 2020
Merged

[CAD-779] Add a database backend. #8

merged 8 commits into from
Jun 19, 2020

Conversation

ksaric
Copy link
Contributor

@ksaric ksaric commented Jun 11, 2020

src/DB.hs Outdated
let hashFromMetadata = B16.encode $ Crypto.digest (Proxy :: Proxy Crypto.Blake2b_256) $ (encodeUtf8 poolEncodedMetadata)

when (hashFromMetadata /= poolHashBytestring) $
panic "TxMetadataHashMismatch"
Copy link
Contributor

Choose a reason for hiding this comment

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

I get from this line that poolHash is actually not the pool id but the hash of the metadata? This feels rather confusing with the name "poolHash"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A lot of things in this PR are confusing, will address that.

src/Lib.hs Outdated
putTextLn $ show poolHash
return examplePoolOfflineMetadata
fmap PoolMetadataWrapped $ either (\m -> panic $ renderLookupFail m) (\a -> a) <$> (dlGetPoolMetadataSimple dataLayer) poolHash
Copy link
Contributor

Choose a reason for hiding this comment

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

As a result, this returns a string which encodes a JSON object, and not a JSON object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Encoding it into a JSON object can change the JSON contents, and accordingly, the hash.

Copy link
Contributor

@KtorZ KtorZ left a comment

Choose a reason for hiding this comment

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

Some additional notes:

  • When a "unknown" hash is provided, the server doesn't reply at all (simply closes the connection) and this shows in the logs:
FatalError {fatalErrorMessage = "Tx metadata hash cbdfc4f21feb0a414b2b9471fa56b0ebd312825e63db776d68cc3fa0ca1f5aaa"}

@ksaric
Copy link
Contributor Author

ksaric commented Jun 15, 2020

Now returning the original JSON content on the correct hash (as agreed):

{"name": "test", "description": "This is a test pool", "ticker": "testy", "homepage": "https://github.com/input-output-hk/cardano-db-sync/tree/master/cardano-db/src/Cardano/Db"}

Returning the error structure (as agreed):

{"code":"DbLookupTxMetadataHash","description":"The hash cbdfc4f21feb0a414b2b9471fa56b0ebd312825e63db776d68cc3fa0ca1f5a2b is missing from the DB."}

@ksaric ksaric force-pushed the ksaric/CAD-779 branch 4 times, most recently from ca91f09 to 90615e9 Compare June 16, 2020 07:34
app/Main.hs Outdated Show resolved Hide resolved
src/Cardano/Db/Error.hs Show resolved Hide resolved
src/Types.hs Show resolved Hide resolved
@ksaric
Copy link
Contributor Author

ksaric commented Jun 17, 2020

A note that might be of use - the argument name was changed from filepath to metadata when inserting the pool metadata:

PGPASSFILE=config/pgpass stack run smash-exe -- insert-pool --metadata test_pool.json --poolhash "cbdfc4f21feb0a414b2b9471fa56b0ebd312825e63db776d68cc3fa0ca1f5a2f"

README.md Outdated Show resolved Hide resolved
@ksaric ksaric merged commit 6a96243 into master Jun 19, 2020
@ksaric ksaric deleted the ksaric/CAD-779 branch June 19, 2020 10:12
@ksaric
Copy link
Contributor Author

ksaric commented Jun 19, 2020

@jbgi This was merged so you can base deployment commit from master if you want. New PR with some new changes should be going up today.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants