Skip to content

Commit

Permalink
Merge #3077
Browse files Browse the repository at this point in the history
3077: Split address discovery and UTxO updates in wallet model r=HeinrichApfelmus a=HeinrichApfelmus

### Issue number

ADP-1323

### 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 prepare the introduction of delta encodings in the "business logic" of the wallet, i.e. the `applyBlock` function. To facilitate keeping track of state changes, we split this function into two parts:

* `discoverAddresses` changes only the address discovery state `s` by looking at all transactions in the block.
* `applyBlockToUTxO` changes only the `UTxO` set, using the addresses discovered in the previous step.

By disentangling the changes to the wallet state, it also becomes more clear in which order the addresses within the block are discovered. Due to the nature of address discovery with an address gap, this order does matter!

### Details

* I have taken the liberty to rewrite and update the module commentary.
    * For example, the commentary to `applyOurTxToUTxO` was slightly misleading in that the function did *not* expect a precondition that the transaction `tx` is guaranteed to be relevant to the wallet. The main reason for this lack of precondition is that a `TxIn` only references an output, but does not record the address associated with that output -- thus, we cannot know whether a `TxIn` belongs to us unless we retrieve its address. In this case, we retrieve the address via the `UTxO` set that we have to carry around anyway.

### Comments

* The property tests for the wallet business logic are currently based on a small initial fragment of Mainnet. Since this is a core component of the wallet relating to asset balances, we may want to look into more elaborate generation of valid chains. Then again, combining `UTxO` sets is not rocket science, and in addition to careful code reading, the existing tests should be sufficient.
    * One idea for generating new chain fragments would be to randomize addresses within a given chain fragment.


Co-authored-by: Heinrich Apfelmus <heinrich.apfelmus@iohk.io>
Co-authored-by: Pawel Jakubas <pawel.jakubas@iohk.io>
Co-authored-by: Rodney Lorrimar <rodney.lorrimar@iohk.io>
  • Loading branch information
4 people committed Jan 19, 2022
2 parents fea6af8 + fea0c4f commit 28ced5c
Show file tree
Hide file tree
Showing 3 changed files with 334 additions and 283 deletions.

0 comments on commit 28ced5c

Please sign in to comment.