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
Write the Genesis block in the BlockStorage #306
Conversation
Fixed the integration tests. |
Codecov Report
@@ Coverage Diff @@
## v0.x.x #306 +/- ##
==========================================
- Coverage 81.7% 81.26% -0.44%
==========================================
Files 49 49
Lines 2552 2583 +31
==========================================
+ Hits 2085 2099 +14
- Misses 467 484 +17
Continue to review full report at Codecov.
|
source/agora/node/BlockStorage.d
Outdated
@@ -188,21 +194,32 @@ public class BlockStorage : IBlockStorage | |||
|
|||
if (!this.path.exists) | |||
mkdirRecurse(this.path); |
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'd say this should be moved to load
as well
source/agora/node/BlockStorage.d
Outdated
|
||
***************************************************************************/ | ||
|
||
public bool isEmpty () | ||
public bool load () |
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 looks like the return value is only used in tests ? I don't think we need this information to be honest, it looks like a leaky abstraction...
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.
Like I mentioned before, I need to add the UTXO set from the genesis block in the UTXO PR.
I should only add the UTXOs if the genesis block was added for the very first time.
Ok put this on hold, I've got a simpler idea I'll work on later. |
So, there is a better way to do what I wanted. The ledger should check if the UTXO database is empty. If it's empty, it can walk through the ledger storage and add each block's UTXOs. Simple. Unblocked. |
Of course, it may be more efficient to get the mempool from the network in some cases, but for starters we can do it this way. |
If the UTXOSet is empty, it will need to be rebuilt. Therefore we need to know its length.
Updated. There are no boolean return values anymore. It should be looked at commit by commit. I still need to add one more test: if the UTXOSet was empty but the blockchain in the storage had multiple blocks, the UTXOSet should be properly re-built. |
source/agora/node/Ledger.d
Outdated
scope (failure) assert(0); | ||
|
||
// add the new UTXOs | ||
block.txs.each!(tx => this.utxo_set.updateUtxoCache(tx)); |
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.
UTXO
, will need a rename
Consistency with acronym naming.
Rebuild the UTXOSet from the blockchain which was loaded from disk. This will also allow moving the adding of the genesis block back to the BlockStorage.
Move the loading code into a separate load() method, and get rid of the empty() method. Loading should ideally never be done in the constructor. Fixes bosagora#286
Updated with a test-case. |
Fixes #286
This or #194 will need a rebase depending on which gets pulled first. So I'll mark this a blocked for now.