Skip to content

[kaizen] Create EmptyBlochainBranch #1044

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

Conversation

AurelienRichez
Copy link
Contributor

Description

This is a proposal to make getBestChain usage more readable.

In my current PR #1039, getBestChain returns an Option. This does not really make sense as we at least should have a genesis so we always should be able to provide some chain. However the unit tests do not always set up a genesis so this assumption is not always true, and fixing this in the tests might be tricky. This means currently we have to put up with an awkward Option and flatMaps in the code while in normal usage None would be a consistency error in the application.

This PR is a compromise where I introduce a new implementation with represent an empty chain (it always tell that a block is not in the chain). This way the interface is nicer, but we don't have to create a fully consistent test environment in unit tests. I'm not certain this is the best way because it does not exactly solves the problem at hand (we still have a concept of empty chain which does not exactly exist in the "real world"). But it seems to be that it is an easy way to have the interface we should have, with no real downside compared to a plain Option.

Any thought ?

@jvdp
Copy link
Contributor

jvdp commented Jul 8, 2021

(copied from #1043 (comment) )

The general idea makes sense to me. You (and the comment) note that there's always a genesis chain right; perhaps that could be the base case? (A branch with only the genesis block.)

@AurelienRichez AurelienRichez force-pushed the kaizen/ETCM-969-allow-empty-chain branch from 9051616 to 32d5b5b Compare July 8, 2021 13:00
@AurelienRichez
Copy link
Contributor Author

@jvdp
sorry. I had a bit of a misclick and could not reopen the original PR after a forced push

I fully agree that the base case should be a branch with one genesis block. I tried to make the unit test scenario always provide a genesis which was stored during test init, but ran into some NPEs in the initialization code. As I did not want to spend to much time rewriting the currently working tests, I thought this could be a decent compromise to have the nicer interface.

It can still be worthwhile to guarantee that there is always a genesis and remove this implementation, but at least the signature of the function won't change.

@AurelienRichez AurelienRichez merged commit 54db9c6 into refactor/ETCM-969-read-layer Jul 9, 2021
@AurelienRichez AurelienRichez deleted the kaizen/ETCM-969-allow-empty-chain branch July 9, 2021 09:09
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.

3 participants