Search in sources :

Example 1 with StateRootHandler

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

the class RemascProcessMinerFeesTest method setup.

@Before
public void setup() {
    blockFactory = new BlockFactory(config.getActivationConfig());
    stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    blockchainBuilder = new BlockChainBuilder().setStateRootHandler(stateRootHandler).setGenesis(genesisBlock).setConfig(config).setTesting(true);
}
Also used : StateRootHandler(co.rsk.db.StateRootHandler) StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) HashMapDB(org.ethereum.datasource.HashMapDB) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) Before(org.junit.Before)

Example 2 with StateRootHandler

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

the class StateTestRunner method runImpl.

public List<String> runImpl() {
    vStats = new ValidationStats();
    logger.info("");
    trieStore = new TrieStoreImpl(new HashMapDB());
    repository = RepositoryBuilder.build(trieStore, stateTestCase.getPre());
    logger.info("loaded repository");
    transaction = TransactionBuilder.build(stateTestCase.getTransaction());
    logger.info("transaction: {}", transaction.toString());
    BlockStore blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
    StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    blockchain = new BlockChainImpl(blockStore, null, null, null, null, new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(trieStore, stateRootHandler), new TransactionExecutorFactory(config, blockStore, null, blockFactory, new ProgramInvokeFactoryImpl(), precompiledContracts, new BlockTxSignatureCache(new ReceivedTxSignatureCache()))), stateRootHandler);
    env = EnvBuilder.build(stateTestCase.getEnv());
    invokeFactory = new TestProgramInvokeFactory(env);
    block = build(env);
    block.setStateRoot(repository.getRoot());
    block.flushRLP();
    blockchain.setStatus(block, block.getCumulativeDifficulty());
    // blockchain.setProgramInvokeFactory(invokeFactory);
    // blockchain.startTracking();
    ProgramResult programResult = executeTransaction(transaction);
    trieStore.flush();
    List<LogInfo> origLogs = programResult.getLogInfoList();
    List<LogInfo> postLogs = LogBuilder.build(stateTestCase.getLogs());
    List<String> logsResult = LogsValidator.valid(origLogs, postLogs, vStats);
    Repository postRepository = RepositoryBuilder.build(stateTestCase.getPost());
    // Balances cannot be validated because has consumption for CALLs differ.
    List<String> repoResults = RepositoryValidator.valid(repository, postRepository, false, false, vStats);
    logger.info("--------- POST Validation---------");
    List<String> outputResults = OutputValidator.valid(ByteUtil.toHexString(programResult.getHReturn()), stateTestCase.getOut(), vStats);
    List<String> results = new ArrayList<>();
    results.addAll(repoResults);
    results.addAll(logsResult);
    results.addAll(outputResults);
    for (String result : results) {
        logger.error(result);
    }
    if ((vStats.storageChecks == 0) && (vStats.logChecks == 0) && (vStats.balancetChecks == 0) && (vStats.outputChecks == 0) && (vStats.blockChecks == 0)) {
        // This generally mean that the test didn't check anything
        // AccountChecks are considered not indicative of the result of the test
        logger.info("IRRELEVANT\n");
    }
    logger.info("\n\n");
    return results;
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) LogInfo(org.ethereum.vm.LogInfo) StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) ProgramResult(org.ethereum.vm.program.ProgramResult) ArrayList(java.util.ArrayList) 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) TestProgramInvokeFactory(org.ethereum.jsontestsuite.TestProgramInvokeFactory) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) ValidationStats(org.ethereum.jsontestsuite.validators.ValidationStats)

Example 3 with StateRootHandler

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

the class ExecuteBlocks method onExecute.

@Override
protected void onExecute(@Nonnull String[] args, @Nonnull RskContext ctx) throws Exception {
    BlockExecutor blockExecutor = ctx.getBlockExecutor();
    BlockStore blockStore = ctx.getBlockStore();
    TrieStore trieStore = ctx.getTrieStore();
    StateRootHandler stateRootHandler = ctx.getStateRootHandler();
    executeBlocks(args, blockExecutor, blockStore, trieStore, stateRootHandler);
}
Also used : StateRootHandler(co.rsk.db.StateRootHandler) BlockStore(org.ethereum.db.BlockStore) BlockExecutor(co.rsk.core.bc.BlockExecutor) TrieStore(co.rsk.trie.TrieStore)

Example 4 with StateRootHandler

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

the class BlockBuilder method build.

public Block build() {
    Block block = blockGenerator.createChildBlock(parent, txs, uncles, difficulty, this.minGasPrice, gasLimit);
    if (blockChain != null) {
        final TestSystemProperties config = new TestSystemProperties();
        StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
        BlockExecutor executor = new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(trieStore, stateRootHandler), new TransactionExecutorFactory(config, blockStore, null, new BlockFactory(config.getActivationConfig()), new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), new BlockTxSignatureCache(new ReceivedTxSignatureCache())));
        executor.executeAndFill(block, parent.getHeader());
    }
    return block;
}
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) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 5 with StateRootHandler

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

the class SyncProcessorTest method processBodyResponseWithTransactionAddsToBlockchain.

@Test
public void processBodyResponseWithTransactionAddsToBlockchain() {
    Account senderAccount = createAccount("sender");
    Account receiverAccount = createAccount("receiver");
    Map<RskAddress, AccountState> accounts = new HashMap<>();
    accounts.put(senderAccount.getAddress(), new AccountState(BigInteger.ZERO, Coin.valueOf(20000000)));
    accounts.put(receiverAccount.getAddress(), new AccountState(BigInteger.ZERO, Coin.ZERO));
    final NetBlockStore store = new NetBlockStore();
    BlockChainBuilder blockChainBuilder = new BlockChainBuilder();
    Blockchain blockchain = blockChainBuilder.ofSize(0, false, accounts);
    Block genesis = blockchain.getBestBlock();
    SimplePeer sender = new SimplePeer(new byte[] { 0x01 });
    Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
    List<Transaction> txs = Collections.singletonList(createTransaction(senderAccount, receiverAccount, BigInteger.valueOf(1000000), BigInteger.ZERO));
    Block block = new BlockGenerator().createChildBlock(genesis, txs, blockChainBuilder.getRepository().getRoot());
    StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams()), config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
    BlockExecutor blockExecutor = new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(blockChainBuilder.getTrieStore(), stateRootHandler), new TransactionExecutorFactory(config, blockChainBuilder.getBlockStore(), null, blockFactory, new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), new BlockTxSignatureCache(new ReceivedTxSignatureCache())));
    Assert.assertEquals(1, block.getTransactionsList().size());
    blockExecutor.executeAndFillAll(block, genesis.getHeader());
    Assert.assertEquals(21000, block.getFeesPaidToMiner().asBigInteger().intValueExact());
    Assert.assertEquals(1, block.getTransactionsList().size());
    Assert.assertEquals(1, block.getNumber());
    Assert.assertArrayEquals(blockchain.getBestBlockHash(), block.getParentHash().getBytes());
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    TestSystemProperties config = new TestSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING, DummyBlockValidator.VALID_RESULT_INSTANCE);
    SyncProcessor processor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, SyncConfiguration.IMMEDIATE_FOR_TESTING, blockFactory, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), DIFFICULTY_CALCULATOR, new PeersInformation(getChannelManager(), SyncConfiguration.IMMEDIATE_FOR_TESTING, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
    List<Transaction> transactions = block.getTransactionsList();
    List<BlockHeader> uncles = block.getUncleList();
    long lastRequestId = new Random().nextLong();
    BodyResponseMessage response = new BodyResponseMessage(lastRequestId, transactions, uncles);
    processor.registerExpectedMessage(response);
    Deque<BlockHeader> headerStack = new ArrayDeque<>();
    headerStack.add(block.getHeader());
    List<Deque<BlockHeader>> headers = new ArrayList<>();
    headers.add(headerStack);
    List<BlockIdentifier> bids = new ArrayList<>();
    bids.add(new BlockIdentifier(blockchain.getBlockByNumber(0).getHash().getBytes(), 0));
    bids.add(new BlockIdentifier(block.getHash().getBytes(), 1));
    processor.startDownloadingBodies(headers, Collections.singletonMap(sender, bids), sender);
    ((DownloadingBodiesSyncState) processor.getSyncState()).expectBodyResponseFor(lastRequestId, sender.getPeerNodeID(), block.getHeader());
    processor.processBodyResponse(sender, response);
    Assert.assertEquals(1, blockchain.getBestBlock().getNumber());
    Assert.assertArrayEquals(block.getHash().getBytes(), blockchain.getBestBlockHash());
    Assert.assertTrue(processor.getExpectedResponses().isEmpty());
}
Also used : StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) BlockStore(org.ethereum.db.BlockStore) HashMapDB(org.ethereum.datasource.HashMapDB) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) EthereumListener(org.ethereum.listener.EthereumListener) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) StateRootHandler(co.rsk.db.StateRootHandler) RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) RepositoryLocator(co.rsk.db.RepositoryLocator) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) BlockExecutor(co.rsk.core.bc.BlockExecutor) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

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