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

[ADP-3031] Simplify checkpoint pruning, take 3 #3988

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

HeinrichApfelmus
Copy link
Contributor

@HeinrichApfelmus HeinrichApfelmus commented Jun 7, 2023

Overview

In this pull request, we consolidate and simplify the creation and pruning of checkpoints.

Specifically, we introduce a function extendAndPrune that computes a delta which

  • adds new checkpoints
  • prunes the existing checkpoints

based on their block height.

Details

  • The mechanism for creating checkpoints has changed. Specifically, when synchronizing the chain far away from the tip, at most two checkpoints are kept: genesis and the latest synchronization point. We only keep multiple checkpoints when we are within epochStability of the tip, as we expect rollbacks only then.
  • The CheckpointPolicy is tested in the existing module Cardano.Wallet.Checkpoints.PolicySpec.

Comments

Issue Number

ADP-3031

@HeinrichApfelmus HeinrichApfelmus force-pushed the HeinrichApfelmus/ADP-3031/extendAndPrune branch 2 times, most recently from 04c6b27 to bce22c4 Compare June 7, 2023 14:51
@HeinrichApfelmus HeinrichApfelmus self-assigned this Jun 7, 2023
@HeinrichApfelmus HeinrichApfelmus force-pushed the HeinrichApfelmus/ADP-3031/extendAndPrune branch 2 times, most recently from f13c81d to 332bef7 Compare June 7, 2023 15:31
it "actually prunes checkpoints" $
property prop_doesPrune
it "keeps the tip of the chain" $
property prop_keepTip
Copy link
Contributor

Choose a reason for hiding this comment

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

if I understand well we are always going to keep
(a) genesis
(b) latest tip
(c) some checkpoints ONLY within stability epoch (I mean this range defined by security parameter that limits depth of rollbacks)
What about adding properties checking that :
(a) genesis cp is always there
(b) after pruning we can only have at most genesis (either it is in stability window or not) and checkpoints within the stability window
(c) variate stability window explicitly ((i) all possible cps are within it, (ii) stability window is proper subset of all possible checkpoints)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about adding properties checking that :

Well, these properties are properties of the specific policy argument, not of the extendAndPrune function. It's enough to test that extendPrune does use the policy, and then rely on the properties of the specific policy to get a specific result. The specific properties are tested here:

https://github.com/input-output-hk/cardano-wallet/blob/0c2382c373f76e808fd3472b78d1ce98c7770618/lib/wallet/test/unit/Cardano/Wallet/Checkpoints/PolicySpec.hs#L52-L66

I can add a test that sparseArithmetic does keep genesis.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added a test that sparseArithmetic does keep genesis.

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.

Nice PR! I like when code cutting > code added :-)
I left some suggestion for additional property tests.

@HeinrichApfelmus HeinrichApfelmus force-pushed the HeinrichApfelmus/ADP-3031/extendAndPrune branch from 332bef7 to 68ea3ad Compare June 12, 2023 13:30
@HeinrichApfelmus
Copy link
Contributor Author

bors merge

iohk-bors bot added a commit that referenced this pull request Jun 12, 2023
3988: [ADP-3031] Simplify checkpoint pruning, take 3 r=HeinrichApfelmus a=HeinrichApfelmus

### Overview


In this pull request, we consolidate and simplify the creation and pruning of checkpoints.

Specifically, we introduce a function `extendAndPrune` that computes a delta which

* adds new checkpoints
* prunes the existing checkpoints

based on their block height.

### Details

* The mechanism for creating checkpoints has changed. Specifically, when synchronizing the chain far away from the `tip`, at most two checkpoints are kept: genesis and the latest synchronization point. We only keep multiple checkpoints when we are within `epochStability` of the tip, as we expect rollbacks only then.
* The `CheckpointPolicy` is tested in the existing module `Cardano.Wallet.Checkpoints.PolicySpec`.

### Comments

* This task evolved out of ADP-1497. Previous attempts to implement this are
    * #3159
    * #3369 

### Issue Number

ADP-3031

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

iohk-bors bot commented Jun 12, 2023

Build failed:

@HeinrichApfelmus
Copy link
Contributor Author

It looks like some integration tests have become more flaky with this change. 🤔

  • TRANS_NEW_JOIN_01a fails in 3/3 runs
  • BYRON_MIGRATE_02 fails in 1/3 runs
  • NEW_SHELLEY_TRANSACTIONS fails in 1/3 runs
  • TRANS_LIST_RANGE_01 fails in 1/3 runs
  • TRANS_ASSETS_CREATE_02c fails in 1/3 runs

Investigating.

@HeinrichApfelmus HeinrichApfelmus force-pushed the HeinrichApfelmus/ADP-3031/extendAndPrune branch from 3bb2e47 to 06e21e0 Compare June 14, 2023 13:31
@HeinrichApfelmus
Copy link
Contributor Author

The integration test TRANS_NEW_JOIN_01a contains a few race conditions. For example, it assumed that a transaction that was submitted to the node would immediately be included in the blockchain, but that is not the case.

@HeinrichApfelmus HeinrichApfelmus force-pushed the HeinrichApfelmus/ADP-3031/extendAndPrune branch from 06e21e0 to 750fe7d Compare June 14, 2023 22:17
@HeinrichApfelmus HeinrichApfelmus force-pushed the HeinrichApfelmus/ADP-3031/extendAndPrune branch from 750fe7d to 6e32039 Compare June 15, 2023 11:10
pools <- filter won'tRetire . map getApiT . snd <$>
unsafeRequest @[ApiT StakePool] ctx
(Link.listStakePools arbitraryStake) Empty
let pool1:pool2:_ = map (view #id) pools
Copy link
Contributor

Choose a reason for hiding this comment

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

good catch and observation!

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!

@HeinrichApfelmus
Copy link
Contributor Author

bors merge

iohk-bors bot added a commit that referenced this pull request Jun 16, 2023
3988: [ADP-3031] Simplify checkpoint pruning, take 3 r=HeinrichApfelmus a=HeinrichApfelmus

### Overview


In this pull request, we consolidate and simplify the creation and pruning of checkpoints.

Specifically, we introduce a function `extendAndPrune` that computes a delta which

* adds new checkpoints
* prunes the existing checkpoints

based on their block height.

### Details

* The mechanism for creating checkpoints has changed. Specifically, when synchronizing the chain far away from the `tip`, at most two checkpoints are kept: genesis and the latest synchronization point. We only keep multiple checkpoints when we are within `epochStability` of the tip, as we expect rollbacks only then.
* The `CheckpointPolicy` is tested in the existing module `Cardano.Wallet.Checkpoints.PolicySpec`.

### Comments

* This task evolved out of ADP-1497. Previous attempts to implement this are
    * #3159
    * #3369 

### Issue Number

ADP-3031

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

iohk-bors bot commented Jun 16, 2023

Build failed:

@HeinrichApfelmus
Copy link
Contributor Author

bors merge

iohk-bors bot added a commit that referenced this pull request Jun 16, 2023
3988: [ADP-3031] Simplify checkpoint pruning, take 3 r=HeinrichApfelmus a=HeinrichApfelmus

### Overview


In this pull request, we consolidate and simplify the creation and pruning of checkpoints.

Specifically, we introduce a function `extendAndPrune` that computes a delta which

* adds new checkpoints
* prunes the existing checkpoints

based on their block height.

### Details

* The mechanism for creating checkpoints has changed. Specifically, when synchronizing the chain far away from the `tip`, at most two checkpoints are kept: genesis and the latest synchronization point. We only keep multiple checkpoints when we are within `epochStability` of the tip, as we expect rollbacks only then.
* The `CheckpointPolicy` is tested in the existing module `Cardano.Wallet.Checkpoints.PolicySpec`.

### Comments

* This task evolved out of ADP-1497. Previous attempts to implement this are
    * #3159
    * #3369 

### Issue Number

ADP-3031

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

iohk-bors bot commented Jun 16, 2023

Build failed:

@HeinrichApfelmus
Copy link
Contributor Author

bors merge

iohk-bors bot added a commit that referenced this pull request Jun 16, 2023
3988: [ADP-3031] Simplify checkpoint pruning, take 3 r=HeinrichApfelmus a=HeinrichApfelmus

### Overview


In this pull request, we consolidate and simplify the creation and pruning of checkpoints.

Specifically, we introduce a function `extendAndPrune` that computes a delta which

* adds new checkpoints
* prunes the existing checkpoints

based on their block height.

### Details

* The mechanism for creating checkpoints has changed. Specifically, when synchronizing the chain far away from the `tip`, at most two checkpoints are kept: genesis and the latest synchronization point. We only keep multiple checkpoints when we are within `epochStability` of the tip, as we expect rollbacks only then.
* The `CheckpointPolicy` is tested in the existing module `Cardano.Wallet.Checkpoints.PolicySpec`.

### Comments

* This task evolved out of ADP-1497. Previous attempts to implement this are
    * #3159
    * #3369 

### Issue Number

ADP-3031

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

iohk-bors bot commented Jun 16, 2023

Build failed:

@HeinrichApfelmus
Copy link
Contributor Author

bors merge

iohk-bors bot added a commit that referenced this pull request Jun 16, 2023
3988: [ADP-3031] Simplify checkpoint pruning, take 3 r=HeinrichApfelmus a=HeinrichApfelmus

### Overview


In this pull request, we consolidate and simplify the creation and pruning of checkpoints.

Specifically, we introduce a function `extendAndPrune` that computes a delta which

* adds new checkpoints
* prunes the existing checkpoints

based on their block height.

### Details

* The mechanism for creating checkpoints has changed. Specifically, when synchronizing the chain far away from the `tip`, at most two checkpoints are kept: genesis and the latest synchronization point. We only keep multiple checkpoints when we are within `epochStability` of the tip, as we expect rollbacks only then.
* The `CheckpointPolicy` is tested in the existing module `Cardano.Wallet.Checkpoints.PolicySpec`.

### Comments

* This task evolved out of ADP-1497. Previous attempts to implement this are
    * #3159
    * #3369 

### Issue Number

ADP-3031

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

iohk-bors bot commented Jun 16, 2023

Build failed:

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