-
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
Refactor DBLayer to use in-memory Checkpoints #2942
Conversation
591dfa9
to
a08ab95
Compare
166705d
to
7a063f5
Compare
7a063f5
to
07a3cf8
Compare
f6bec2c
to
fa3161d
Compare
98e45d3
to
0d71e67
Compare
4ea79b3
to
7e42a1c
Compare
* Keep the `Checkpoints` type stupid and simple for now. It will be replaced later. * This replaces the cache of the latest checkpoint with a cache of all checkpoints. This will increase memory requirements for now, but this will go back to normal (and better) once delta encodings are integrated.
7beb6bf
to
af8b05f
Compare
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 run through logic and it seems to proceed as I would expect. If all tests pass it is giving crucial confidence that replacing SlotNo with SlotPoint and BlockHeader with ChainPoint is not doing any harm. What about db migrations? No way they are going to be affected? Maybe it would be good if @piotr-iohk plays with migrations using this branch.
I will give another look, even more detailed and style related, tomorrow (until now I was mainly occupied with how it works and why)
Thanks Pawel! 😊 The DB migrations should not be affected — this PR does not change the database format in any way. The database is actually a little buggy in that it stores a checkpoint for the first slot after genesis, I don't think that it makes to fix this in the database file format right now, because a future PR will radically change the format anyway, adding incremental updates. However, I do think that it makes sense to at least use the correct representation for the in-memory type. Unit tests will pass as long as they never try to roll back to |
This commit partially addresses the issue where the DB layer historically did not distinguish between the genesis point and the block with SlotNo 0, which comes directly after genesis. * The types of `rollbackTo` and `listCheckpoints` can now distinguish these points. * For reasons of correctness, we need to use `Slot` in the `Checkpoints` type. * However, the DB file format still uses slot numbers only. But as we want to revamp the format anyway, the plan is to keep it as it is for now, and remove the issue with the revamp.
32b569c
to
237d8ec
Compare
The genesis block has no parent block, and this fact is best represented by `Nothing` instead of a magic value `hashOfNoParent`. The magic value is still used for serialization and deserialization in the database.
237d8ec
to
46241d7
Compare
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.
lgtm
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.
Great 👍
-> SlotNo | ||
-> ExceptT ErrNoSuchWallet stm BlockHeader | ||
-- ^ Drops all checkpoints and transaction data after the given slot. | ||
-> 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.
Given that we don't require the database to be rolled back further than a few thousand blocks, a value of Origin
should never be passed for this argument of rollbackTo
.
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 agree that this will not happen in practice on testnet and mainnet. However, the ouroboros-network library does represent points on the blockchain with an explicit origin, and a rollback to genesis can happen in principle (and does happen on local test clusters). By using a representation that is more closely aligned with ouroboros-network (i.e. Slot
instead of SlotNo
), the code actually becomes simpler, as we can remove conversion functions such as
pseudoPointSlot :: ChainPoint -> SlotNo
pseudoPointSlot ChainPointAtGenesis = W.SlotNo 0
pseudoPointSlot (ChainPoint slot _) = slot
Historical hack. The DB layer can't represent 'Origin' in the database, | ||
instead we have mapped it to 'SlotNo 0', which is wrong. |
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.
It shouldn't matter; we don't need rollback to genesis.
bors merge |
Build succeeded: |
3046: Reorganize modules in Cardano.Wallet.DB.* r=HeinrichApfelmus a=HeinrichApfelmus ### Issue number ADP-1288 ### Overview Previous work in epic ADP-1043 introduced delta encodings, DBVars, and an embedding of the wallet state and its delta encodings into a database table. It's time to integrate these tools with the wallet code. To facilitate code review, the integration proceeds in a sequence of refactorings that do not change functionality and pass all unit tests. In this step, we reorganize the modules in the `Cardano.Wallet.DB.*` hierarchy; the aim is to be able to quickly swap out the implementation of the `mkStoreWalletsCheckpoints` function by changing one import. We want to keep both the previous implementation and a subsequent new implementation around for some time. ### Details * The migration function `migrateManually` is moved to a separate module `Cardano.Wallet.DB.Sqlite.Migration`. This has the beneficial side effect that this migration function cannot be accidentally be affected by refactoring in modules that are not imported by this module. * The creation of the checkpoints store, `mkStoreWalletsCheckpoints`, is moved to a separate module. We can swap out its implementation by importing a different module in the future. ### Comments Merge PR #2942 before this one, because this pull request is based on the branch of the former. Co-authored-by: Heinrich Apfelmus <[email protected]>
Issue number
ADP-1169
Overview
Previous work in epic ADP-1043 introduced delta encodings, DBVars, and an embedding of the wallet state and its delta encodings into a database table. It's time to integrate these tools with the wallet code. To facilitate code review, the integration proceeds in a sequence of refactorings that do not change functionality and pass all unit tests.
In this step, we introduce a type Checkpoints a which stores all checkpoints of the wallet state in memory. The current ad-hoc cache of the latest checkpoints is replaced by a DBVar that stores these checkpoints instead.
Details
Checkpoints
type stupid and simple for now. It will be replaced later.Comments
Merge PR #2841 before this one, because this pull request is based on the branch of the former.