Search in sources :

Example 1 with MultiTrieStore

use of co.rsk.trie.MultiTrieStore in project rskj by rsksmart.

the class RskContext method buildAbstractTrieStore.

private TrieStore buildAbstractTrieStore(Path databasePath) {
    TrieStore newTrieStore;
    GarbageCollectorConfig gcConfig = getRskSystemProperties().garbageCollectorConfig();
    final String multiTrieStoreNamePrefix = "unitrie_";
    if (gcConfig.enabled()) {
        try {
            newTrieStore = buildMultiTrieStore(databasePath, multiTrieStoreNamePrefix, gcConfig.numberOfEpochs());
        } catch (IOException e) {
            throw new IllegalStateException("Unable to build multi trie store", e);
        }
    } else {
        Path trieStorePath = databasePath.resolve("unitrie");
        try (Stream<Path> databasePathFilesStream = Files.list(databasePath)) {
            List<Path> multiTrieStorePaths = databasePathFilesStream.filter(p -> p.getFileName().toString().startsWith(multiTrieStoreNamePrefix)).collect(Collectors.toList());
            boolean gcWasEnabled = !multiTrieStorePaths.isEmpty();
            if (gcWasEnabled) {
                LevelDbDataSource.mergeDataSources(trieStorePath, multiTrieStorePaths);
                // cleanup MultiTrieStore data sources
                multiTrieStorePaths.stream().map(Path::toString).forEach(FileUtil::recursiveDelete);
            }
        } catch (IOException e) {
            logger.error("Unable to check if GC was ever enabled", e);
        }
        newTrieStore = buildTrieStore(trieStorePath);
    }
    return newTrieStore;
}
Also used : Path(java.nio.file.Path) TxPoolModuleImpl(co.rsk.rpc.modules.txpool.TxPoolModuleImpl) ReceiptStoreImplV2(org.ethereum.db.ReceiptStoreImplV2) FileUtil(org.ethereum.util.FileUtil) Keccak256(co.rsk.crypto.Keccak256) EvmModule(co.rsk.rpc.modules.evm.EvmModule) LevelDbDataSource(org.ethereum.datasource.LevelDbDataSource) PeerClient(org.ethereum.net.client.PeerClient) DebugModuleImpl(co.rsk.rpc.modules.debug.DebugModuleImpl) Path(java.nio.file.Path) EthereumChannelInitializerFactory(org.ethereum.net.EthereumChannelInitializerFactory) co.rsk.mine(co.rsk.mine) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) MultiTrieStore(co.rsk.trie.MultiTrieStore) BtcBlockStoreWithCache(co.rsk.peg.BtcBlockStoreWithCache) Unzipper(co.rsk.db.importer.provider.Unzipper) BootstrapIndexRetriever(co.rsk.db.importer.provider.index.BootstrapIndexRetriever) StandardCharsets(java.nio.charset.StandardCharsets) co.rsk.net(co.rsk.net) HashRateCalculatorNonMining(co.rsk.metrics.HashRateCalculatorNonMining) PeerScoringReporterService(co.rsk.scoring.PeerScoringReporterService) Stream(java.util.stream.Stream) PeersInformation(co.rsk.net.sync.PeersInformation) RskModuleImpl(co.rsk.rpc.modules.rsk.RskModuleImpl) ProgramInvokeFactory(org.ethereum.vm.program.invoke.ProgramInvokeFactory) java.util(java.util) BootstrapDataProvider(co.rsk.db.importer.provider.BootstrapDataProvider) TxPoolModule(co.rsk.rpc.modules.txpool.TxPoolModule) Node(org.ethereum.net.rlpx.Node) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) BootstrapDataVerifier(co.rsk.db.importer.provider.BootstrapDataVerifier) PersonalModule(co.rsk.rpc.modules.personal.PersonalModule) PersonalModuleWalletDisabled(co.rsk.rpc.modules.personal.PersonalModuleWalletDisabled) EthereumImpl(org.ethereum.facade.EthereumImpl) RskCustomCache(co.rsk.util.RskCustomCache) org.ethereum.net.server(org.ethereum.net.server) DataSourceWithCache(org.ethereum.datasource.DataSourceWithCache) Nullable(javax.annotation.Nullable) BlockHeaderElement(co.rsk.metrics.BlockHeaderElement) SolidityCompiler(org.ethereum.solidity.compiler.SolidityCompiler) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Files(java.nio.file.Files) NodeManager(org.ethereum.net.NodeManager) EvmModuleImpl(co.rsk.rpc.modules.evm.EvmModuleImpl) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) BuildInfo(org.ethereum.util.BuildInfo) BootstrapImporter(co.rsk.db.importer.BootstrapImporter) ReceiptStore(org.ethereum.db.ReceiptStore) PeerExplorer(co.rsk.net.discovery.PeerExplorer) Paths(java.nio.file.Paths) TrieStoreImpl(co.rsk.trie.TrieStoreImpl) RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) Web3(org.ethereum.rpc.Web3) DB(org.mapdb.DB) HashRateCalculatorMining(co.rsk.metrics.HashRateCalculatorMining) BootstrapURLProvider(co.rsk.db.importer.BootstrapURLProvider) ECKey(org.ethereum.crypto.ECKey) GenesisLoader(org.ethereum.core.genesis.GenesisLoader) BlockChainLoader(org.ethereum.core.genesis.BlockChainLoader) co.rsk.core.bc(co.rsk.core.bc) MnrModule(co.rsk.rpc.modules.mnr.MnrModule) ConfigCapabilitiesImpl(org.ethereum.net.client.ConfigCapabilitiesImpl) LoggerFactory(org.slf4j.LoggerFactory) TraceModule(co.rsk.rpc.modules.trace.TraceModule) Eth62MessageFactory(org.ethereum.net.eth.message.Eth62MessageFactory) co.rsk.core(co.rsk.core) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) BlockHeaderNotificationEmitter(co.rsk.rpc.modules.eth.subscribe.BlockHeaderNotificationEmitter) UDPServer(co.rsk.net.discovery.UDPServer) ConfigCapabilities(org.ethereum.net.client.ConfigCapabilities) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) MnrModuleImpl(co.rsk.rpc.modules.mnr.MnrModuleImpl) SyncNotificationEmitter(co.rsk.rpc.modules.eth.subscribe.SyncNotificationEmitter) PunishmentParameters(co.rsk.scoring.PunishmentParameters) RskWireProtocol(co.rsk.net.eth.RskWireProtocol) PeerScoring(co.rsk.scoring.PeerScoring) Secp256k1(org.ethereum.crypto.signature.Secp256k1) CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) StaticMessages(org.ethereum.net.message.StaticMessages) PersonalModuleWalletEnabled(co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled) KademliaOptions(co.rsk.net.discovery.table.KademliaOptions) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) NodeDistanceTable(co.rsk.net.discovery.table.NodeDistanceTable) DBMaker(org.mapdb.DBMaker) MessageRecorder(co.rsk.net.eth.MessageRecorder) org.ethereum.core(org.ethereum.core) TraceModuleImpl(co.rsk.rpc.modules.trace.TraceModuleImpl) CliArgs(co.rsk.cli.CliArgs) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) DebugModule(co.rsk.rpc.modules.debug.DebugModule) HashRateCalculator(co.rsk.metrics.HashRateCalculator) BootstrapIndexCandidateSelector(co.rsk.db.importer.provider.index.BootstrapIndexCandidateSelector) co.rsk.config(co.rsk.config) BootstrapFileHandler(co.rsk.db.importer.provider.BootstrapFileHandler) co.rsk.rpc.modules.eth(co.rsk.rpc.modules.eth) PeerScoringManager(co.rsk.scoring.PeerScoringManager) Ethereum(org.ethereum.facade.Ethereum) SyncPool(org.ethereum.sync.SyncPool) WriterMessageRecorder(co.rsk.net.eth.WriterMessageRecorder) LogsNotificationEmitter(co.rsk.rpc.modules.eth.subscribe.LogsNotificationEmitter) Nonnull(javax.annotation.Nonnull) TrieStore(co.rsk.trie.TrieStore) co.rsk.db(co.rsk.db) BlocksBloomStore(co.rsk.logfilter.BlocksBloomStore) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) Logger(org.slf4j.Logger) PendingTransactionsNotificationEmitter(co.rsk.rpc.modules.eth.subscribe.PendingTransactionsNotificationEmitter) co.rsk.rpc.netty(co.rsk.rpc.netty) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GenesisLoaderImpl(org.ethereum.core.genesis.GenesisLoaderImpl) BlocksBloomService(co.rsk.logfilter.BlocksBloomService) MessageFilter(co.rsk.net.eth.MessageFilter) java.io(java.io) CacheSnapshotHandler(org.ethereum.datasource.CacheSnapshotHandler) co.rsk.rpc(co.rsk.rpc) Clock(java.time.Clock) co.rsk.validators(co.rsk.validators) ConsensusRule(org.ethereum.config.blockchain.upgrades.ConsensusRule) RskModule(co.rsk.rpc.modules.rsk.RskModule) Constants(org.ethereum.config.Constants) MultiTrieStore(co.rsk.trie.MultiTrieStore) TrieStore(co.rsk.trie.TrieStore) FileUtil(org.ethereum.util.FileUtil)

Example 2 with MultiTrieStore

use of co.rsk.trie.MultiTrieStore in project rskj by rsksmart.

the class RskContext method buildInternalServices.

public synchronized List<InternalService> buildInternalServices() {
    checkIfNotClosed();
    List<InternalService> internalServices = new ArrayList<>();
    internalServices.add(getTransactionPool());
    internalServices.add(getChannelManager());
    internalServices.add(getNodeMessageHandler());
    internalServices.add(getPeerServer());
    boolean rpcHttpEnabled = getRskSystemProperties().isRpcHttpEnabled();
    boolean rpcWebSocketEnabled = getRskSystemProperties().isRpcWebSocketEnabled();
    boolean bloomServiceEnabled = getRskSystemProperties().bloomServiceEnabled();
    if (bloomServiceEnabled) {
        internalServices.add(new BlocksBloomService(getCompositeEthereumListener(), getBlocksBloomStore(), getBlockStore()));
    }
    if (rpcHttpEnabled || rpcWebSocketEnabled) {
        internalServices.add(getWeb3());
    }
    if (rpcHttpEnabled) {
        internalServices.add(getWeb3HttpServer());
    }
    if (rpcWebSocketEnabled) {
        internalServices.add(getWeb3WebSocketServer());
    }
    if (getRskSystemProperties().isPeerDiscoveryEnabled()) {
        internalServices.add(new UDPServer(getRskSystemProperties().getBindAddress().getHostAddress(), getRskSystemProperties().getPeerPort(), getPeerExplorer()));
    }
    if (getRskSystemProperties().isSyncEnabled()) {
        internalServices.add(getSyncPool());
    }
    if (getRskSystemProperties().isMinerServerEnabled()) {
        internalServices.add(getMinerServer());
        if (getRskSystemProperties().isMinerClientEnabled()) {
            internalServices.add(getMinerClient());
        }
    }
    NodeBlockProcessor nodeBlockProcessor = getNodeBlockProcessor();
    if (nodeBlockProcessor instanceof InternalService) {
        internalServices.add((InternalService) nodeBlockProcessor);
    }
    GarbageCollectorConfig gcConfig = getRskSystemProperties().garbageCollectorConfig();
    if (gcConfig.enabled()) {
        internalServices.add(new GarbageCollector(getCompositeEthereumListener(), gcConfig.blocksPerEpoch(), gcConfig.numberOfEpochs(), (MultiTrieStore) getTrieStore(), getBlockStore(), getRepositoryLocator()));
    }
    if (getRskSystemProperties().isPeerScoringStatsReportEnabled()) {
        internalServices.add(getPeerScoringReporterService());
    }
    internalServices.add(new BlockChainFlusher(getRskSystemProperties().flushNumberOfBlocks(), getCompositeEthereumListener(), getTrieStore(), getBlockStore(), getReceiptStore(), getBlocksBloomStore(), getStateRootsStore()));
    return Collections.unmodifiableList(internalServices);
}
Also used : UDPServer(co.rsk.net.discovery.UDPServer) MultiTrieStore(co.rsk.trie.MultiTrieStore) BlocksBloomService(co.rsk.logfilter.BlocksBloomService)

Aggregations

BlocksBloomService (co.rsk.logfilter.BlocksBloomService)2 UDPServer (co.rsk.net.discovery.UDPServer)2 NetworkParameters (co.rsk.bitcoinj.core.NetworkParameters)1 CliArgs (co.rsk.cli.CliArgs)1 co.rsk.config (co.rsk.config)1 co.rsk.core (co.rsk.core)1 co.rsk.core.bc (co.rsk.core.bc)1 Keccak256 (co.rsk.crypto.Keccak256)1 co.rsk.db (co.rsk.db)1 BootstrapImporter (co.rsk.db.importer.BootstrapImporter)1 BootstrapURLProvider (co.rsk.db.importer.BootstrapURLProvider)1 BootstrapDataProvider (co.rsk.db.importer.provider.BootstrapDataProvider)1 BootstrapDataVerifier (co.rsk.db.importer.provider.BootstrapDataVerifier)1 BootstrapFileHandler (co.rsk.db.importer.provider.BootstrapFileHandler)1 Unzipper (co.rsk.db.importer.provider.Unzipper)1 BootstrapIndexCandidateSelector (co.rsk.db.importer.provider.index.BootstrapIndexCandidateSelector)1 BootstrapIndexRetriever (co.rsk.db.importer.provider.index.BootstrapIndexRetriever)1 BlocksBloomStore (co.rsk.logfilter.BlocksBloomStore)1 BlockHeaderElement (co.rsk.metrics.BlockHeaderElement)1 HashRateCalculator (co.rsk.metrics.HashRateCalculator)1