Search in sources :

Example 6 with StateRootHandler

use of co.rsk.db.StateRootHandler in project rskj by rsksmart.

the class BlockToMineBuilderTest method setUp.

@Before
public void setUp() {
    validationRules = mock(BlockValidationRule.class);
    RepositoryLocator repositoryLocator = mock(RepositoryLocator.class);
    StateRootHandler stateRootHandler = mock(StateRootHandler.class);
    MiningConfig miningConfig = mock(MiningConfig.class);
    DifficultyCalculator difficultyCalculator = mock(DifficultyCalculator.class);
    MinimumGasPriceCalculator minimumGasPriceCalculator = mock(MinimumGasPriceCalculator.class);
    MinerUtils minerUtils = mock(MinerUtils.class);
    activationConfig = mock(ActivationConfig.class);
    blockExecutor = mock(BlockExecutor.class);
    blockBuilder = new BlockToMineBuilder(activationConfig, miningConfig, repositoryLocator, mock(BlockStore.class), mock(TransactionPool.class), difficultyCalculator, new GasLimitCalculator(Constants.mainnet()), new ForkDetectionDataCalculator(), validationRules, mock(MinerClock.class), new BlockFactory(activationConfig), blockExecutor, minimumGasPriceCalculator, minerUtils);
    BlockDifficulty blockDifficulty = mock(BlockDifficulty.class);
    Repository snapshot = mock(Repository.class);
    GasLimitConfig gasLimitConfig = new GasLimitConfig(0, 0, false);
    when(minerUtils.getAllTransactions(any())).thenReturn(new ArrayList<>());
    when(minerUtils.filterTransactions(any(), any(), any(), any(), any())).thenReturn(new ArrayList<>());
    when(repositoryLocator.snapshotAt(any())).thenReturn(snapshot);
    when(minimumGasPriceCalculator.calculate(any())).thenReturn(mock(Coin.class));
    when(stateRootHandler.translate(any())).thenReturn(TestUtils.randomHash());
    when(miningConfig.getGasLimit()).thenReturn(gasLimitConfig);
    when(miningConfig.getUncleListLimit()).thenReturn(10);
    when(miningConfig.getCoinbaseAddress()).thenReturn(TestUtils.randomAddress());
    when(difficultyCalculator.calcDifficulty(any(), any())).thenReturn(blockDifficulty);
}
Also used : BlockExecutor(co.rsk.core.bc.BlockExecutor) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) RepositoryLocator(co.rsk.db.RepositoryLocator) StateRootHandler(co.rsk.db.StateRootHandler) MiningConfig(co.rsk.config.MiningConfig) DifficultyCalculator(co.rsk.core.DifficultyCalculator) BlockDifficulty(co.rsk.core.BlockDifficulty) Coin(co.rsk.core.Coin) GasLimitConfig(co.rsk.config.GasLimitConfig) BlockValidationRule(co.rsk.validators.BlockValidationRule) Before(org.junit.Before)

Example 7 with StateRootHandler

use of co.rsk.db.StateRootHandler in project rskj by rsksmart.

the class ImportLightTest method createBlockchain.

public static BlockChainImpl createBlockchain(Genesis genesis, TestSystemProperties config, Repository repository, BlockStore blockStore, TrieStore trieStore) {
    BlockFactory blockFactory = new BlockFactory(config.getActivationConfig());
    CompositeEthereumListener listener = new TestCompositeEthereumListener();
    KeyValueDataSource ds = new HashMapDB();
    ds.init();
    ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
    ReceivedTxSignatureCache receivedTxSignatureCache = new ReceivedTxSignatureCache();
    BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(receivedTxSignatureCache);
    TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, blockStore, receiptStore, blockFactory, new ProgramInvokeFactoryImpl(), null, blockTxSignatureCache);
    StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    RepositoryLocator repositoryLocator = new RepositoryLocator(trieStore, stateRootHandler);
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, repositoryLocator, null, blockFactory, listener, transactionExecutorFactory, receivedTxSignatureCache, 10, 100);
    BlockChainImpl blockchain = new BlockChainImpl(blockStore, receiptStore, transactionPool, listener, new DummyBlockValidator(), new BlockExecutor(config.getActivationConfig(), repositoryLocator, transactionExecutorFactory), stateRootHandler);
    blockchain.setNoValidation(true);
    Repository track = repository.startTracking();
    for (Map.Entry<RskAddress, AccountState> accountsEntry : genesis.getAccounts().entrySet()) {
        RskAddress accountAddress = accountsEntry.getKey();
        track.createAccount(accountAddress);
        track.addBalance(accountAddress, accountsEntry.getValue().getBalance());
    }
    track.commit();
    genesis.setStateRoot(repository.getRoot());
    genesis.flushRLP();
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    blockchain.setStatus(genesis, genesis.getCumulativeDifficulty());
    return blockchain;
}
Also used : StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) HashMapDB(org.ethereum.datasource.HashMapDB) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) StateRootHandler(co.rsk.db.StateRootHandler) RepositoryLocator(co.rsk.db.RepositoryLocator) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) TestCompositeEthereumListener(org.ethereum.listener.TestCompositeEthereumListener) TestCompositeEthereumListener(org.ethereum.listener.TestCompositeEthereumListener) RskAddress(co.rsk.core.RskAddress) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) Map(java.util.Map) ReceiptStore(org.ethereum.db.ReceiptStore)

Example 8 with StateRootHandler

use of co.rsk.db.StateRootHandler in project rskj by rsksmart.

the class WorldDslProcessor method processBlockChainCommand.

private void processBlockChainCommand(DslCommand cmd) {
    Block parent = world.getBlockByName(cmd.getArgument(0));
    int k = 1;
    while (cmd.getArgument(k) != null) {
        String name = cmd.getArgument(k);
        int difficulty = k;
        if (name != null) {
            StringTokenizer difficultyTokenizer = new StringTokenizer(name, ":");
            name = difficultyTokenizer.nextToken();
            difficulty = difficultyTokenizer.hasMoreTokens() ? parseDifficulty(difficultyTokenizer.nextToken(), k) : k;
        }
        Block block = blockBuilder.difficulty(difficulty).parent(parent).build();
        final ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl();
        final TestSystemProperties config = new TestSystemProperties();
        StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
        BlockExecutor executor = new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(world.getTrieStore(), stateRootHandler), new TransactionExecutorFactory(config, world.getBlockStore(), null, new BlockFactory(config.getActivationConfig()), programInvokeFactory, null, world.getBlockTxSignatureCache()));
        executor.executeAndFill(block, parent.getHeader());
        world.saveBlock(name, block);
        parent = block;
        k++;
    }
}
Also used : StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) HashMapDB(org.ethereum.datasource.HashMapDB) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) StateRootHandler(co.rsk.db.StateRootHandler) RepositoryLocator(co.rsk.db.RepositoryLocator) StringTokenizer(java.util.StringTokenizer) TestSystemProperties(co.rsk.config.TestSystemProperties)

Aggregations

StateRootHandler (co.rsk.db.StateRootHandler)8 BlockExecutor (co.rsk.core.bc.BlockExecutor)7 RepositoryLocator (co.rsk.db.RepositoryLocator)6 StateRootsStoreImpl (co.rsk.db.StateRootsStoreImpl)6 HashMapDB (org.ethereum.datasource.HashMapDB)6 ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)5 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)4 TestSystemProperties (co.rsk.config.TestSystemProperties)3 BlockStore (org.ethereum.db.BlockStore)3 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)2 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)2 PrecompiledContracts (org.ethereum.vm.PrecompiledContracts)2 Before (org.junit.Before)2 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)1 GasLimitConfig (co.rsk.config.GasLimitConfig)1 MiningConfig (co.rsk.config.MiningConfig)1 BlockDifficulty (co.rsk.core.BlockDifficulty)1 Coin (co.rsk.core.Coin)1 DifficultyCalculator (co.rsk.core.DifficultyCalculator)1 RskAddress (co.rsk.core.RskAddress)1