Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Inject StorageProvider into PantheonController instances #259

Merged
merged 8 commits into from
Nov 20, 2018

Conversation

ajsutton
Copy link
Contributor

PR description

Decouples PantheonController instances from RocksDB by injecting a StorageProvider that is used to create storage for blockchain and world state.

@ajsutton ajsutton requested a review from rain-on November 14, 2018 05:28

import java.io.Closeable;

public interface StorageProvider extends Closeable {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of our own new interface could we use a pair of javax.inject.Provider instances? Do they need to be tied like this? This would make applying a DI framework later much easier. JSR-330 annotations have no tie to a specific DI framework.

https://docs.oracle.com/javaee/6/api/javax/inject/Provider.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem with having them supplied separately is that they will also have to be closed separately which is a problem because they will often use the same backend storage (RocksDB currently) and it's the actual storage backend that really gets closed.

Copy link
Contributor

Choose a reason for hiding this comment

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

With a guice or dagger module we could aggregate the closables in the module. But we don't have that in this CL so this interface will work.


public interface StorageProvider extends Closeable {

BlockchainStorage createBlockchainStorage(ProtocolSchedule<?> protocolSchedule);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do this without the ProtocolSchedule argument? Is there a case where we don't know the protocol schedule when we are making the decisions about what kind of blockchain storage we provide? We could just curry a function taking that into the constructor and make it a provider. It's a bit of work on our end but when we go to DI the framework will wire it together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately we don't have the ProtocolSchedule available at the time we want to create the StorageProvider. The issue is that you need a BlockHashFunction to load any blocks from storage and that depends on the ProtocolSchedule. We very likely want to remove that dependency which would mean removing the hash function from Block and BlockHeader - anyone wanting the hash would have to get the BlockHashFunction from the ProtocolSchedule and pass the BlockHeader to it. That's not a simple change to make and we would need to preserve the hash caching that BlockHeader currently provides internally as it's a fairly expensive operation and is performed quite a bit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it's hard to go halfway with a DI style without a framework. A lot of these issues would melt into the module (one for each consensus protocol) but without that framework we can't go halfway. So since we don't have a forma DI framework handling the injections for us this is the engineering compromise we will need to do.


import java.io.Closeable;

public interface StorageProvider extends Closeable {
Copy link
Contributor

Choose a reason for hiding this comment

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

With a guice or dagger module we could aggregate the closables in the module. But we don't have that in this CL so this interface will work.


public interface StorageProvider extends Closeable {

BlockchainStorage createBlockchainStorage(ProtocolSchedule<?> protocolSchedule);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it's hard to go halfway with a DI style without a framework. A lot of these issues would melt into the module (one for each consensus protocol) but without that framework we can't go halfway. So since we don't have a forma DI framework handling the injections for us this is the engineering compromise we will need to do.

@ajsutton ajsutton merged commit 4d95c60 into PegaSysEng:master Nov 20, 2018
@ajsutton ajsutton deleted the storage-provider branch November 20, 2018 20:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants