Search in sources :

Example 61 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class BlockExecutorTest method buildBlockExecutor.

private static BlockExecutor buildBlockExecutor(TrieStore store, RskSystemProperties config) {
    StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams());
    BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(btcBlockStoreFactory, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
    return new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(store, stateRootHandler), new TransactionExecutorFactory(config, null, null, BLOCK_FACTORY, new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), new BlockTxSignatureCache(new ReceivedTxSignatureCache())));
}
Also used : PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) Factory(co.rsk.peg.BtcBlockStoreWithCache.Factory) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) RskTestFactory(org.ethereum.util.RskTestFactory) HashMapDB(org.ethereum.datasource.HashMapDB) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory)

Example 62 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class BlockExecutorTest method validateStateRootWithRskip126DisabledAndValidStateRoot.

@Test
public void validateStateRootWithRskip126DisabledAndValidStateRoot() {
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    Trie trie = new Trie(trieStore);
    Block block = new BlockGenerator().getBlock(1);
    block.setStateRoot(trie.getHash().getBytes());
    BlockResult blockResult = new BlockResult(block, Collections.emptyList(), Collections.emptyList(), 0, Coin.ZERO, trie);
    RskSystemProperties cfg = spy(CONFIG);
    ActivationConfig activationConfig = spy(cfg.getActivationConfig());
    doReturn(false).when(activationConfig).isActive(eq(RSKIP126), anyLong());
    doReturn(activationConfig).when(cfg).getActivationConfig();
    BlockExecutor executor = buildBlockExecutor(trieStore, cfg);
    Assert.assertTrue(executor.validateStateRoot(block.getHeader(), blockResult));
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) RskSystemProperties(co.rsk.config.RskSystemProperties) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test)

Example 63 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class BlockExecutorTest method validateStateRootWithRskip126DisabledAndInvalidStateRoot.

@Test
public void validateStateRootWithRskip126DisabledAndInvalidStateRoot() {
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    Trie trie = new Trie(trieStore);
    Block block = new BlockGenerator().getBlock(1);
    block.setStateRoot(new byte[] { 1, 2, 3, 4 });
    BlockResult blockResult = new BlockResult(block, Collections.emptyList(), Collections.emptyList(), 0, Coin.ZERO, trie);
    RskSystemProperties cfg = spy(CONFIG);
    ActivationConfig activationConfig = spy(cfg.getActivationConfig());
    doReturn(false).when(activationConfig).isActive(eq(RSKIP126), anyLong());
    doReturn(activationConfig).when(cfg).getActivationConfig();
    BlockExecutor executor = buildBlockExecutor(trieStore, cfg);
    Assert.assertTrue(executor.validateStateRoot(block.getHeader(), blockResult));
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) RskSystemProperties(co.rsk.config.RskSystemProperties) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test)

Example 64 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class BlockValidatorTest method invalidUncleHasParentThatIsNotAncestor.

@Test
public void invalidUncleHasParentThatIsNotAncestor() {
    IndexedBlockStore store = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block uncle1a = blockGenerator.createChildBlock(genesis);
    Block uncle2a = blockGenerator.createChildBlock(uncle1a);
    List<BlockHeader> uncles3 = new ArrayList<>();
    uncles3.add(uncle2a.getHeader());
    uncles3.add(uncle1a.getHeader());
    Block block1 = blockGenerator.createChildBlock(genesis, null, null, 1, null);
    Block block2 = blockGenerator.createChildBlock(block1, null, null, 1, null);
    Block block3 = blockGenerator.createChildBlock(block2, null, uncles3, 1, null);
    store.saveBlock(genesis, TEST_DIFFICULTY, true);
    store.saveBlock(uncle1a, TEST_DIFFICULTY, false);
    store.saveBlock(uncle2a, TEST_DIFFICULTY, false);
    store.saveBlock(block1, TEST_DIFFICULTY, true);
    store.saveBlock(block2, TEST_DIFFICULTY, true);
    store.saveBlock(block3, TEST_DIFFICULTY, true);
    BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(store).blockStore(store).build();
    Assert.assertFalse(validator.isValid(block3));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 65 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class BlockValidatorTest method invalidUnclesUncleIncludedMultipeTimes.

@Test
public void invalidUnclesUncleIncludedMultipeTimes() {
    IndexedBlockStore store = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block uncle1a = blockGenerator.createChildBlock(genesis);
    List<BlockHeader> uncles1 = new ArrayList<>();
    uncles1.add(uncle1a.getHeader());
    uncles1.add(uncle1a.getHeader());
    Block block1 = blockGenerator.createChildBlock(genesis, null, uncles1, 1, null);
    store.saveBlock(genesis, TEST_DIFFICULTY, true);
    store.saveBlock(uncle1a, TEST_DIFFICULTY, false);
    store.saveBlock(block1, TEST_DIFFICULTY, true);
    BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(store).blockStore(store).build();
    Assert.assertFalse(validator.isValid(block1));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Aggregations

HashMapDB (org.ethereum.datasource.HashMapDB)208 Test (org.junit.Test)181 World (co.rsk.test.World)45 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)34 ReceiptStore (org.ethereum.db.ReceiptStore)34 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)34 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)29 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)27 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)27 TrieStore (co.rsk.trie.TrieStore)26 HashMapBlocksIndex (co.rsk.db.HashMapBlocksIndex)23 Trie (co.rsk.trie.Trie)21 Blockchain (org.ethereum.core.Blockchain)17 RskAddress (co.rsk.core.RskAddress)16 Transaction (org.ethereum.core.Transaction)16 DslParser (co.rsk.test.dsl.DslParser)15 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12