|
|
|
@ -17,25 +17,116 @@ package org.hyperledger.besu.evmtool; |
|
|
|
|
|
|
|
|
|
import org.hyperledger.besu.ethereum.chain.BlockchainStorage; |
|
|
|
|
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; |
|
|
|
|
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; |
|
|
|
|
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage; |
|
|
|
|
import org.hyperledger.besu.plugin.services.BesuConfiguration; |
|
|
|
|
import org.hyperledger.besu.plugin.services.MetricsSystem; |
|
|
|
|
import org.hyperledger.besu.plugin.services.storage.KeyValueStorage; |
|
|
|
|
import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier; |
|
|
|
|
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBKeyValueStorageFactory; |
|
|
|
|
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBMetricsFactory; |
|
|
|
|
import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBCLIOptions; |
|
|
|
|
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; |
|
|
|
|
import org.hyperledger.besu.services.kvstore.LimitedInMemoryKeyValueStorage; |
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.function.Supplier; |
|
|
|
|
import javax.inject.Named; |
|
|
|
|
import javax.inject.Singleton; |
|
|
|
|
|
|
|
|
|
import com.google.common.base.Suppliers; |
|
|
|
|
import dagger.Module; |
|
|
|
|
import dagger.Provides; |
|
|
|
|
import org.apache.logging.log4j.LogManager; |
|
|
|
|
import org.apache.logging.log4j.Logger; |
|
|
|
|
|
|
|
|
|
@SuppressWarnings("WeakerAccess") |
|
|
|
|
@SuppressWarnings({"CloseableProvides"}) |
|
|
|
|
@Module(includes = GenesisFileModule.class) |
|
|
|
|
public class DataStoreModule { |
|
|
|
|
|
|
|
|
|
private static final Logger LOG = LogManager.getLogger(); |
|
|
|
|
private final Supplier<RocksDBKeyValueStorageFactory> rocksDBFactory = |
|
|
|
|
Suppliers.memoize( |
|
|
|
|
() -> |
|
|
|
|
new RocksDBKeyValueStorageFactory( |
|
|
|
|
RocksDBCLIOptions.create()::toDomainObject, |
|
|
|
|
List.of(KeyValueSegmentIdentifier.values()), |
|
|
|
|
RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS)); |
|
|
|
|
|
|
|
|
|
@Provides |
|
|
|
|
@Singleton |
|
|
|
|
@Named("blockchain") |
|
|
|
|
KeyValueStorage provideBlockchainKeyValueStorage( |
|
|
|
|
@Named("KeyValueStorageName") final String keyValueStorageName, |
|
|
|
|
final BesuConfiguration commonConfiguration, |
|
|
|
|
final MetricsSystem metricsSystem) { |
|
|
|
|
return constructKeyValueStorage( |
|
|
|
|
keyValueStorageName, |
|
|
|
|
commonConfiguration, |
|
|
|
|
metricsSystem, |
|
|
|
|
KeyValueSegmentIdentifier.BLOCKCHAIN); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Provides |
|
|
|
|
@Singleton |
|
|
|
|
@Named("worldState") |
|
|
|
|
KeyValueStorage provideWorldStateKeyValueStorage( |
|
|
|
|
@Named("KeyValueStorageName") final String keyValueStorageName, |
|
|
|
|
final BesuConfiguration commonConfiguration, |
|
|
|
|
final MetricsSystem metricsSystem) { |
|
|
|
|
return constructKeyValueStorage( |
|
|
|
|
keyValueStorageName, |
|
|
|
|
commonConfiguration, |
|
|
|
|
metricsSystem, |
|
|
|
|
KeyValueSegmentIdentifier.WORLD_STATE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Provides |
|
|
|
|
@Singleton |
|
|
|
|
@Named("worldStatePreimage") |
|
|
|
|
KeyValueStorage provideWorldStatePreimageKeyValueStorage( |
|
|
|
|
@Named("KeyValueStorageName") final String keyValueStorageName, |
|
|
|
|
final BesuConfiguration commonConfiguration, |
|
|
|
|
final MetricsSystem metricsSystem) { |
|
|
|
|
return new LimitedInMemoryKeyValueStorage(5000); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Provides |
|
|
|
|
@SuppressWarnings("CloseableProvides") |
|
|
|
|
KeyValueStorage provideKeyValueStorage() { |
|
|
|
|
throw new RuntimeException("Abstract"); |
|
|
|
|
@Singleton |
|
|
|
|
@Named("pruning") |
|
|
|
|
KeyValueStorage providePruningKeyValueStorage( |
|
|
|
|
@Named("KeyValueStorageName") final String keyValueStorageName, |
|
|
|
|
final BesuConfiguration commonConfiguration, |
|
|
|
|
final MetricsSystem metricsSystem) { |
|
|
|
|
return constructKeyValueStorage( |
|
|
|
|
keyValueStorageName, |
|
|
|
|
commonConfiguration, |
|
|
|
|
metricsSystem, |
|
|
|
|
KeyValueSegmentIdentifier.PRUNING_STATE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private KeyValueStorage constructKeyValueStorage( |
|
|
|
|
@Named("KeyValueStorageName") final String keyValueStorageName, |
|
|
|
|
final BesuConfiguration commonConfiguration, |
|
|
|
|
final MetricsSystem metricsSystem, |
|
|
|
|
final SegmentIdentifier segment) { |
|
|
|
|
|
|
|
|
|
switch (keyValueStorageName) { |
|
|
|
|
case "rocksdb": |
|
|
|
|
return rocksDBFactory.get().create(segment, commonConfiguration, metricsSystem); |
|
|
|
|
default: |
|
|
|
|
LOG.error("Unknown key, continuing as though 'memory' was specified"); |
|
|
|
|
// fall through
|
|
|
|
|
case "memory": |
|
|
|
|
return new InMemoryKeyValueStorage(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Provides |
|
|
|
|
@Singleton |
|
|
|
|
static BlockchainStorage provideBlockchainStorage( |
|
|
|
|
final KeyValueStorage keyValueStorage, final BlockHeaderFunctions blockHashFunction) { |
|
|
|
|
@Named("blockchain") final KeyValueStorage keyValueStorage, |
|
|
|
|
final BlockHeaderFunctions blockHashFunction) { |
|
|
|
|
return new KeyValueStoragePrefixedKeyBlockchainStorage(keyValueStorage, blockHashFunction); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|