Skip to content
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

Improve Remasc storage before 0.5.0 activation #793

Merged
merged 5 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 0 additions & 143 deletions rskj-core/src/main/java/co/rsk/DoPrune.java

This file was deleted.

16 changes: 0 additions & 16 deletions rskj-core/src/main/java/co/rsk/FullNodeRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import co.rsk.config.RskSystemProperties;
import co.rsk.core.Rsk;
import co.rsk.db.PruneConfiguration;
import co.rsk.db.PruneService;
import co.rsk.mine.MinerClient;
import co.rsk.mine.MinerServer;
import co.rsk.mine.TxBuilder;
Expand All @@ -40,7 +38,6 @@
import org.ethereum.rpc.Web3;
import org.ethereum.sync.SyncPool;
import org.ethereum.util.BuildInfo;
import org.ethereum.vm.PrecompiledContracts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -73,8 +70,6 @@ public class FullNodeRunner implements NodeRunner {
private final TransactionGateway transactionGateway;
private final BuildInfo buildInfo;

private final PruneService pruneService;

@Autowired
public FullNodeRunner(
Rsk rsk,
Expand Down Expand Up @@ -115,9 +110,6 @@ public FullNodeRunner(
this.peerClientFactory = peerClientFactory;
this.transactionGateway = transactionGateway;
this.buildInfo = buildInfo;

PruneConfiguration pruneConfiguration = rskSystemProperties.getPruneConfiguration();
this.pruneService = new PruneService(pruneConfiguration, rskSystemProperties, blockchain, PrecompiledContracts.REMASC_ADDR);
}

@Override
Expand Down Expand Up @@ -179,10 +171,6 @@ public void run() throws Exception {
}
}

if (rskSystemProperties.isPruneEnabled()) {
pruneService.start();
}

logger.info("done");
}

Expand Down Expand Up @@ -232,10 +220,6 @@ private void waitRskSyncDone() throws InterruptedException {
public void stop() {
logger.info("Shutting down RSK node");

if (rskSystemProperties.isPruneEnabled()) {
pruneService.stop();
}

syncPool.stop();

boolean rpcHttpEnabled = rskSystemProperties.isRpcHttpEnabled();
Expand Down
16 changes: 14 additions & 2 deletions rskj-core/src/main/java/co/rsk/RskContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import co.rsk.core.DifficultyCalculator;
import co.rsk.core.RskFactory;
import co.rsk.core.bc.BlockValidatorImpl;
import co.rsk.db.StateRootHandler;
import co.rsk.validators.BlockParentDependantValidationRule;
import co.rsk.validators.BlockValidationRule;
import co.rsk.validators.BlockValidator;
Expand Down Expand Up @@ -61,6 +62,7 @@ public class RskContext {
private ReceiptStore receiptStore;
private ProgramInvokeFactoryImpl programInvokeFactory;
private TransactionPool transactionPool;
private StateRootHandler stateRootHandler;

public RskContext(String[] args) {
this(new CliArgs.Parser<>(
Expand Down Expand Up @@ -92,13 +94,22 @@ private BlockChainLoader getBlockChainLoader() {
getTransactionPool(),
getCompositeEthereumListener(),
getBlockValidator(),
getGenesis()
getGenesis(),
getStateRootHandler()
);
}

return blockChainLoader;
}

public StateRootHandler getStateRootHandler() {
if (stateRootHandler == null) {
stateRootHandler = factory.getStateRootHandler(getRskSystemProperties());
}

return stateRootHandler;
}

public TransactionPool getTransactionPool() {
if (transactionPool == null) {
transactionPool = factory.getTransactionPool(
Expand Down Expand Up @@ -160,7 +171,8 @@ private BlockParentDependantValidationRule getBlockParentDependantValidationRule
blockParentDependantValidationRule = factory.blockParentDependantValidationRule(
getRepository(),
getRskSystemProperties(),
getDifficultyCalculator()
getDifficultyCalculator(),
getStateRootHandler()
);
}

Expand Down
24 changes: 0 additions & 24 deletions rskj-core/src/main/java/co/rsk/config/RskSystemProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package co.rsk.config;

import co.rsk.core.RskAddress;
import co.rsk.db.PruneConfiguration;
import co.rsk.rpc.ModuleDescription;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigObject;
Expand Down Expand Up @@ -319,29 +318,6 @@ public VmConfig getVmConfig() {
return new VmConfig(vmTrace(), vmTraceInitStorageLimit(), dumpBlock(), dumpStyle());
}

// New prune service properties
public boolean isPruneEnabled() {
return configFromFiles.getBoolean("prune.enabled");
}

public int getPruneNoBlocksToCopy() {
return configFromFiles.getInt("prune.blocks.toCopy");
}

public int getPruneNoBlocksToWait() {
return configFromFiles.getInt("prune.blocks.toWait");
}

public int getPruneNoBlocksToAvoidForks() {
return configFromFiles.getInt("prune.blocks.toAvoidForks");
}

public PruneConfiguration getPruneConfiguration() {
return new PruneConfiguration(this.getPruneNoBlocksToCopy(),
this.getPruneNoBlocksToAvoidForks(),
this.getPruneNoBlocksToWait());
}

public long peerDiscoveryCleanPeriod() {
return PD_DEFAULT_CLEAN_PERIOD;
}
Expand Down
18 changes: 16 additions & 2 deletions rskj-core/src/main/java/co/rsk/core/RskFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import co.rsk.core.bc.TransactionPoolImpl;
import co.rsk.crypto.Keccak256;
import co.rsk.db.RepositoryImpl;
import co.rsk.db.StateRootHandler;
import co.rsk.metrics.BlockHeaderElement;
import co.rsk.logfilter.BlocksBloomStore;
import co.rsk.metrics.HashRateCalculator;
Expand Down Expand Up @@ -544,8 +545,9 @@ public Repository repository(RskSystemProperties config) {
public BlockParentDependantValidationRule blockParentDependantValidationRule(
Repository repository,
RskSystemProperties config,
DifficultyCalculator difficultyCalculator) {
BlockTxsValidationRule blockTxsValidationRule = new BlockTxsValidationRule(repository);
DifficultyCalculator difficultyCalculator,
StateRootHandler stateRootHandler) {
BlockTxsValidationRule blockTxsValidationRule = new BlockTxsValidationRule(repository, stateRootHandler);
BlockTxsFieldsValidationRule blockTxsFieldsValidationRule = new BlockTxsFieldsValidationRule();
PrevMinGasPriceRule prevMinGasPriceRule = new PrevMinGasPriceRule();
BlockParentNumberRule parentNumberRule = new BlockParentNumberRule();
Expand Down Expand Up @@ -681,6 +683,11 @@ public ParentBlockHeaderValidator parentHeaderValidator(RskSystemProperties conf
return new ParentBlockHeaderValidator(rules);
}

@Bean
public StateRootHandler getStateRootHandler(RskSystemProperties config) {
return buildStateRootHandler(config);
}

public ReceiptStore buildReceiptStore(String databaseDir) {
KeyValueDataSource ds = new LevelDbDataSource("receipts", databaseDir);
ds.init();
Expand Down Expand Up @@ -729,6 +736,13 @@ public static org.ethereum.db.BlockStore buildBlockStore(String databaseDir) {
return new IndexedBlockStore(indexMap, blocksDB, indexDB);
}

public StateRootHandler buildStateRootHandler(RskSystemProperties config) {
KeyValueDataSource stateRootsDB = new LevelDbDataSource("stateRoots", config.databaseDir());
stateRootsDB.init();

return new StateRootHandler(config, stateRootsDB, new HashMap<>());
}

private KeyValueDataSource makeDataSource(String name, String databaseDir) {
KeyValueDataSource ds = new LevelDbDataSource(name, databaseDir);
ds.init();
Expand Down
Loading