Repository navigation
Block: add getGenesis(), SPVBlockStore: use Network in constructors - #4261
msgilligan wants to merge 3 commits into
Conversation
| /** | ||
| * Get the standard full Genesis Block for a network | ||
| * @param network the network | ||
| * @return a complete block (should be treated as immutable) | ||
| */ | ||
| public static Block getGenesis(Network network) { | ||
| return NetworkParameters.of(network).getGenesisBlock(); | ||
| } | ||
|
|
There was a problem hiding this comment.
Hm, I think the special genesis block is more an artifact of a network or a block chain, but not really of a block.
So I'd argue perhaps we should have a helper in Network instead. (I'm surprised we don't have than already.)
However, even if we go ahead with this PR, I think the refactoring to introduce this method should be on a separate commit.
There was a problem hiding this comment.
So I'd argue perhaps we should have a helper in Network instead.
I think genesis block should be constructed by Block for three reasons:
- They are instances of
Blockand the standard static factory method pattern seems to apply here. - We already have several
createGenesis()static factories inBlock(immediately below this new method) - We can't put it in
NetworkbecauseBlockand other dependencies are ino.b.corenoto.b.base(notably the currentNetworkParametersconstants, thought those could be moved)
the refactoring to introduce this method should be on a separate commit.
Agree.
|
@schildbach Oops, re-requested review and I have not created a separate commit. I will do that soon. In the meantime, do my arguments for why |
|
As requested, I factored the creation of Once that is merged this can be rebased. |
This provides a factory for genesis blocks that does not require a caller to have a NetworkParameters instance. Block is the logical home for this method, because: 1. Genesis blocks are instances of `Block` and factories that provide well-known constant instances of a type make sense to place there. 2. We already have several `createGenesis()` static factories in `Block` (immediately below this new method) 3. We can't put it in `Network` because `Block` and other dependencies are in `o.b.core` not `o.b.base`.
In some classes (CheckpointManager, SPVBlockStore, and MemoryFullPrunedBlockStore) the use of Block.getGenesis() removes the last internal dependency on NetworkParameters and allows the constructor taking NetworkParameters to be replaced with one that takes Network. In FetchBlocks, PrivateKeys, and BlockFileLoaderBitcoindTest NetworkParameters is completely removed. In other classes use of Block.getGenesis() takes us closer to removing NetworkParameters, but there are other uses that must be updated first.
Existing SPVBlockStore constructors that take NetworkParameters are deprecated. Note that the RestoreFromSeed example is now able to completely remove imports of NetworkParameters and subclasses. BlockImporter can drop NetworkParameters once the MemoryFullPrunedBlockStore constructors are updated to take Network. This is a step towards our goal of (typical) applications using only (Bitcoin)Network in API calls. This also opens the possibility of migrating genesis block parameters out of network parameters.
23e2fde to
19074c2
Compare
Existing SPVBlockStore constructors that take NetworkParameters are deprecated.
Note that the RestoreFromSeed example is now able to completely remove imports of NetworkParameters and subclasses.
BlockImporter can drop NetworkParameters once the MemoryFullPrunedBlockStore constructors are updated to take Network.
This is a step towards our goal of (typical) applications using only (Bitcoin)Network in API calls.
This also opens the possibility of migrating genesis block parameters out of network parameters.