-
Notifications
You must be signed in to change notification settings - Fork 217
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
Use SlotNo and TimeInterpreter #1901
Conversation
-- We cannot manually specify when the fetching happens. | ||
-- | ||
-- This may or may not be what we actually want. | ||
type TimeInterpreter m = forall a. Qry a -> m a |
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.
☝️ We may now have a TimeInterpreter IO
that sometimes takes a long time to run a conversion query (when it needs to refetch the summary over LSQ).
Not sure if we should change…
The re-fetching should happen on very rare occasions though…
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.
I think it would be better to have the network layer query the Interpreter on a schedule, and stash it in a mutable variable. So that all queries can be pure.
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.
So that all queries can be pure
I presume it would still be in IO
(to access the var), so no change to the interface.
In that case I'd be concerned with what callers would see if there is nothing in the var. There are many call-sites, and I think blocking until it is available is the simplest thing to. Which is somewhat like this.
But preemptively refreshing before a conversion fails, sounds sane to do… optimally.
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.
Let's see. I was thinking that the initial Interpreter will be one constructed from genesis parameters.
It will get updated once the node has synced far enough. (Question - how far is enough?)
This would prevent the wallet from being unresponsive while the node is syncing.
b2e34a7
to
1be1ac1
Compare
315b875
to
249af6f
Compare
@@ -90,7 +92,7 @@ TxMeta | |||
txMetaWalletId W.WalletId sql=wallet_id | |||
txMetaStatus W.TxStatus sql=status | |||
txMetaDirection W.Direction sql=direction | |||
txMetaSlot W.SlotId sql=slot | |||
txMetaSlot SlotNo sql=slot |
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.
I suspect we may need manual migration
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.
Don't fret over DB migration if it's too hard. We can start from a fresh state directory if necessary.
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.
On second thought, I fear/wonder if users would silently get corrupted data, as the meaning of the slot
table has changed, but not the name.
Is there a good way to test / detect this?
Or I guess testing manually using CLI works. I tried using the Daedalus mainnet installation, and replacing the wallet and node manually, but I think too many other things have changed for it to work.
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.
If the type of the column changes, I think persistent auto migrations will either throw an exception or helpfully delete the table.
Let's decide next week whether to automatically migrate or make a fresh state directory.
630c90b
to
c2d6707
Compare
5e4b66a
to
8d0a0af
Compare
What's the benefit of wrapping the provided Interpreter in our own type? Can we use the bare Interpreter? |
The original interpreter only works with The wrapper carries the genesis start date along with it. |
== Add TimeInterpreter, necessary queries, and a way to run them Add tests comparing them with old implementation == Fundamentally change wallet to use SlotNo instead of SlotId - Patch together cardano-wallet-jormungandr to still work, despite the binary using SlotId. == Remove redundant byron code == Sync progress calculation compares times now instead of slots
8d0a0af
to
353f4b6
Compare
bors try |
tryBuild failed |
bors try |
I am seeing rare failures of this sort. I am investigating test/unit/Cardano/Pool/DB/Properties.hs:348:17:
1) Cardano.Pool.DB.Sqlite.Sqlite, Stake Pool properties, readPoolProduction for a given epoch should always give slots from given epoch
Falsifiable (after 10 tests and 1 shrink):
StakePoolsFixture {poolSlots = [(PoolId {getPoolId = "w\EOTe\227Aa\169\r=\fK%v>C\178\r/\ETX\v\FS\131>\ACK\225\aG$u\a\v>"},BlockHeader {slotNo = SlotNo {unSlotNo = 10}, blockHeight = Quantity {getQuantity = 0}, headerHash = Hash {getHash = "00000000000000000000000000000001"}, parentHeaderHash = Hash {getHash = "00000000000000000000000000000000"}}),(PoolId {getPoolId = "\138P0PcK\141\161.\a\DC1\DC3L\ESC\a\SOT\FS\US\245[\209&Q\CAN\DLEWU\249\DC1\165?"},BlockHeader {slotNo = SlotNo {unSlotNo = 0}, blockHeight = Quantity {getQuantity = 0}, headerHash = Hash {getHash = "00000000000000000000000000000001"}, parentHeaderHash = Hash {getHash = "00000000000000000000000000000000"}}),(PoolId {getPoolId = "w\EOTe\227Aa\169\r=\fK%v>C\178\r/\ETX\v\FS\131>\ACK\225\aG$u\a\v>"},BlockHeader {slotNo = SlotNo {unSlotNo = 8}, blockHeight = Quantity {getQuantity = 0}, headerHash = Hash {getHash = "00000000000000000000000000000001"}, parentHeaderHash = Hash {getHash = "00000000000000000000000000000000"}})], rollbackSlots = [SlotNo {unSlotNo = 10},SlotNo {unSlotNo = 0},SlotNo {unSlotNo = 8}]}
expected: fromList [SlotNo {unSlotNo = 0},SlotNo {unSlotNo = 8}]
but got: fromList [SlotNo {unSlotNo = 10}] |
It would group slots like: Epoch 1: SlotNo 0 SlotNo 8 Epoch 0: SlotNo 11 when it zipped the grouped slots together with the epochs. I'm not sure how it worked previously and stopped working now. I also added a somewhat ugly shrinker for the stake pool fixtures.
This reverts commit 9eb843b. That commit broke a unit test failure for a manual migration. I am not sure if the test could have been removed without consequences. But weirdly, migration seems to work smoothly without it: $ cardano-wallet-shelley-2020-07-06 serve --node-socket socket --testnet shelley_testnet-genesis.json --database wallet-db $ # Create a wallet $ cardano-wallet-shelley transaction list <WALLET ID> $ cardano-wallet-shelley serve --node-socket socket --testnet shelley_testnet-genesis.json --database wallet-db $ cardano-wallet-shelley transaction list <WALLET ID> $ # The correct slots are still shown. Looking in the DBs, it seems like wallet does detect that the schema has changed, and re-syncs from genesis.
bors try |
tryBuild succeeded |
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.
Nice work - this is a really big PR.
I have checked Cardano.Wallet.Primitive and Cardano.Wallet.Shelley.
Is there anything else I should pay attention to?
|
||
-- * Old functions | ||
-- * Legacy api |
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.
Will these all be removed in a future PR, or moved to a tests-only module?
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.
I suppose we should remove them completely, and re-write the tests to use the new ones.
Now we are testing the old ones, and that the new ones are equivalent to the old ones (Generators aren't perfect though).
defaultTTL epochLength slot = | ||
(toSlotNo epochLength slot) + 7200 | ||
defaultTTL :: SlotNo -> SlotNo | ||
defaultTTL slot = slot + 7200 |
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.
I like this. :-)
With the database migration issue, we can't re-use the We could either:
In the case of 2, the DB migration test can be disabled, because there is no migration to test. I like option 2, because there are other user stories such as transaction TTL that also need major DB schema changes. |
Migrating from 2020-07-06 works. Migrating from the current flight candidate to this PR doesn't: But in the real world, users would be upgrading from an older Daedalus Mainnet release, which might trigger automatic migration.
✔️ Regardless, I think thinking about this later is fine, as you suggested in another comment. |
bors r+ |
1901: Use SlotNo and TimeInterpreter r=Anviking a=Anviking # Issue Number ADP-356 #1868 #1869 # Overview - [x] Add TimeInterpreter, necessary queries, and a way to run them Add tests comparing them with old implementation - [x] Fundamentally change wallet to use SlotNo instead of SlotId - Patch together cardano-wallet-jormungandr to still work, despite the binary using SlotId. - [x] Remove redundant byron code - [x] Sync progress calculation compares times now instead of slots - [x] Rename the `slot` tables to `slot_no` to force automatic migration, preventing catastrophic re-interpretation of old data # Comments - Depends on #1890 <!-- Additional comments or screenshots to attach if any --> <!-- Don't forget to: ✓ Self-review your changes to make sure nothing unexpected slipped through ✓ Assign yourself to the PR ✓ Assign one or several reviewer(s) ✓ Once created, link this PR to its corresponding ticket ✓ Assign the PR to a corresponding milestone ✓ Acknowledge any changes required to the Wiki --> Co-authored-by: Johannes Lund <[email protected]>
58bff35
to
1014550
Compare
Canceled |
bors r+ |
1901: Use SlotNo and TimeInterpreter r=Anviking a=Anviking # Issue Number ADP-356 #1868 #1869 # Overview - [x] Add TimeInterpreter, necessary queries, and a way to run them Add tests comparing them with old implementation - [x] Fundamentally change wallet to use SlotNo instead of SlotId - Patch together cardano-wallet-jormungandr to still work, despite the binary using SlotId. - [x] Remove redundant byron code - [x] Sync progress calculation compares times now instead of slots - [x] Rename the `slot` tables to `slot_no` to force automatic migration, preventing catastrophic re-interpretation of old data # Comments - Depends on #1890 <!-- Additional comments or screenshots to attach if any --> <!-- Don't forget to: ✓ Self-review your changes to make sure nothing unexpected slipped through ✓ Assign yourself to the PR ✓ Assign one or several reviewer(s) ✓ Once created, link this PR to its corresponding ticket ✓ Assign the PR to a corresponding milestone ✓ Acknowledge any changes required to the Wiki --> Co-authored-by: Johannes Lund <[email protected]>
Build failed |
bors r+ |
1901: Use SlotNo and TimeInterpreter r=Anviking a=Anviking # Issue Number ADP-356 #1868 #1869 # Overview - [x] Add TimeInterpreter, necessary queries, and a way to run them Add tests comparing them with old implementation - [x] Fundamentally change wallet to use SlotNo instead of SlotId - Patch together cardano-wallet-jormungandr to still work, despite the binary using SlotId. - [x] Remove redundant byron code - [x] Sync progress calculation compares times now instead of slots - [x] Rename the `slot` tables to `slot_no` to force automatic migration, preventing catastrophic re-interpretation of old data # Comments - Depends on #1890 <!-- Additional comments or screenshots to attach if any --> <!-- Don't forget to: ✓ Self-review your changes to make sure nothing unexpected slipped through ✓ Assign yourself to the PR ✓ Assign one or several reviewer(s) ✓ Once created, link this PR to its corresponding ticket ✓ Assign the PR to a corresponding milestone ✓ Acknowledge any changes required to the Wiki --> Co-authored-by: Johannes Lund <[email protected]>
Build failed
|
bors r+ |
1901: Use SlotNo and TimeInterpreter r=Anviking a=Anviking # Issue Number ADP-356 #1868 #1869 # Overview - [x] Add TimeInterpreter, necessary queries, and a way to run them Add tests comparing them with old implementation - [x] Fundamentally change wallet to use SlotNo instead of SlotId - Patch together cardano-wallet-jormungandr to still work, despite the binary using SlotId. - [x] Remove redundant byron code - [x] Sync progress calculation compares times now instead of slots - [x] Rename the `slot` tables to `slot_no` to force automatic migration, preventing catastrophic re-interpretation of old data # Comments - Depends on #1890 <!-- Additional comments or screenshots to attach if any --> <!-- Don't forget to: ✓ Self-review your changes to make sure nothing unexpected slipped through ✓ Assign yourself to the PR ✓ Assign one or several reviewer(s) ✓ Once created, link this PR to its corresponding ticket ✓ Assign the PR to a corresponding milestone ✓ Acknowledge any changes required to the Wiki --> Co-authored-by: Johannes Lund <[email protected]>
Build failed
|
bors r+ |
Build succeeded |
Issue Number
ADP-356 #1868 #1869
Overview
Add TimeInterpreter, necessary queries, and a way to run them
Add tests comparing them with old implementation
Fundamentally change wallet to use SlotNo instead of SlotId
binary using SlotId.
Remove redundant byron code
Sync progress calculation compares times now instead of slots
Rename the
slot
tables toslot_no
to force automatic migration, preventing catastrophic re-interpretation of old dataComments