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

Restrict Checkpoints to be constructible from genesis only #3048

Merged
merged 1 commit into from
Dec 16, 2021

Conversation

HeinrichApfelmus
Copy link
Contributor

@HeinrichApfelmus HeinrichApfelmus commented Dec 8, 2021

Issue number

ADP-1043

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 implement a suggestion that came up during review where we remove the singleton function in favor of fromGenesis, making sure that the Checkpoints structure always contains a checkpoint for the genesis block.

Details

  • The initializeWallet function will now throw an exception if it is incorrectly called with a checkpoint that is not at the genesis block.
  • Many unit tests are adapted to use the InitialCheckpoint generator in order to comply with the above restriction.

Comments

Merge PR #3046 before this one, because this pull request is based on the branch of the former.

@HeinrichApfelmus HeinrichApfelmus force-pushed the HeinrichApfelmus/ADP-1043/fromGenesis branch from d6b8b31 to 941980f Compare December 9, 2021 12:15
Base automatically changed from HeinrichApfelmus/ADP-1043/1288-reorganize-modules to master December 10, 2021 10:14
@HeinrichApfelmus HeinrichApfelmus force-pushed the HeinrichApfelmus/ADP-1043/fromGenesis branch 2 times, most recently from 78b88ca to e2d8e6c Compare December 10, 2021 16:24
@HeinrichApfelmus HeinrichApfelmus force-pushed the HeinrichApfelmus/ADP-1043/fromGenesis branch from e2d8e6c to c54becd Compare December 14, 2021 12:12
Copy link
Contributor

@paweljakubas paweljakubas left a comment

Choose a reason for hiding this comment

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

LGTM! Left several suggestions. Maybe you will find defining new sum error in putCheckpoint method of DBLayer interface reasonable. I feel we should not differentiate no wallet and no genesis from each other in a sense they are both very serious/critical and if so why not to treat them on the same level ;-)

The function `fromGenesis` replaces the `singleton` function.
@HeinrichApfelmus HeinrichApfelmus force-pushed the HeinrichApfelmus/ADP-1043/fromGenesis branch from 163c67a to d68b1e5 Compare December 16, 2021 13:29
@HeinrichApfelmus
Copy link
Contributor Author

bors merge

iohk-bors bot added a commit that referenced this pull request Dec 16, 2021
3048: Restrict `Checkpoints` to be constructible from genesis only r=HeinrichApfelmus a=HeinrichApfelmus

### Issue number

ADP-1043

### 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 implement a suggestion that came up during review where we remove the `singleton` function in favor of `fromGenesis`, making sure that the `Checkpoints` structure always contains a checkpoint for the genesis block.

### Details

* The `initializeWallet` function will now throw an exception if it is incorrectly called with a checkpoint that is not at the genesis block.
* Many unit tests are adapted to use the `InitialCheckpoint` generator in order to comply with the above restriction.

### Comments

Merge PR #3046 before this one, because this pull request is based on the branch of the former.


Co-authored-by: Heinrich Apfelmus <[email protected]>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Dec 16, 2021

Build failed:

src/Test/Integration/Scenario/CLI/Shelley/Transactions.hs:244:59:
--
  | 1) CLI Specifications, SHELLEY_CLI_TRANSACTIONS, TRANS_CREATE_06 - Invalid amount, []
  | uncaught exception: IOException of type ResourceVanished
  | fd:191: hFlush: resource vanished (Broken pipe)

#2855

@HeinrichApfelmus
Copy link
Contributor Author

bors retry

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Dec 16, 2021

Build succeeded:

@iohk-bors iohk-bors bot merged commit 87d06f9 into master Dec 16, 2021
@iohk-bors iohk-bors bot deleted the HeinrichApfelmus/ADP-1043/fromGenesis branch December 16, 2021 17:04
iohk-bors bot added a commit that referenced this pull request Dec 22, 2021
3056: Introduce `Prologue` and `Discoveries` of an address book r=HeinrichApfelmus a=HeinrichApfelmus

### Issue number

ADP-1043

### 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 begin refactoring the address discovery state (the `s` in `Wallet s`). First, I would like to update our nomenclature and call this state an *address book*. Second, we introduce two new data families `Prologue s` and `Discoveries s`, with the intention that any address book is isomorphic to a pair of these two types, that is `s ~ (Prologue s, Discoveries s)`. The idea is that the Prologue of the address book contains "static" information such as public keys or the address gap (default 20), while the Discoveries of the address book contains information that was gathered during on-chain address discovery.

### Details

* We introduce a type class `AddressBookIso` which provides the isomorphism `s ~ (Prologue s, Discoveries s)`.
* For this pull request, we avoid making any changes to the `AddressDiscovery.*` hierarchy. Instead, the isomorphisms are implemented using newly defined data families whose representation is close to the types in the database.
* The implementation for the sequential states uses `liftPaymentAddress` to convert the payment part to and from the `Address` type. This is ok when convering to/from the database layer, but does not make sense for in-memory data structures. Therefore, further work in this epic will introduce changes in the `AddressDiscovery.*` hierarchy.

### Comments

* The overall goal is that, in a future PR, we can represent the wallet state along the lines of `WalletState s ~ (Prologue s, Checkpoints (BlockHeader, UTxO, Discoveries s) `.
* Merge PR #3048 before this one, because this pull request is based on the branch of the former.

Co-authored-by: Heinrich Apfelmus <[email protected]>
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 this pull request may close these issues.

2 participants