use of co.rsk.validators.DummyBlockValidator in project rskj by rsksmart.
the class ImportLightTest method createBlockchain.
public static BlockChainImpl createBlockchain(Genesis genesis) {
RskSystemProperties config = new RskSystemProperties();
config.setBlockchainConfig(new GenesisConfig(new GenesisConfig.GenesisConstants() {
@Override
public BlockDifficulty getMinimumDifficulty() {
return new BlockDifficulty(BigInteger.ONE);
}
}));
IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
Repository repository = new RepositoryImpl(config, new TrieStoreImpl(new HashMapDB()));
EthereumListenerAdapter listener = new EthereumListenerAdapter();
KeyValueDataSource ds = new HashMapDB();
ds.init();
ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
BlockChainImpl blockchain = new BlockChainImpl(config, repository, blockStore, receiptStore, null, listener, new AdminInfo(), new DummyBlockValidator());
blockchain.setNoValidation(true);
TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, repository, null, receiptStore, null, listener, 10, 100);
blockchain.setTransactionPool(transactionPool);
Repository track = repository.startTracking();
for (RskAddress addr : genesis.getPremine().keySet()) {
track.createAccount(addr);
track.addBalance(addr, genesis.getPremine().get(addr).getAccountState().getBalance());
}
track.commit();
genesis.setStateRoot(repository.getRoot());
genesis.flushRLP();
blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
blockchain.setBestBlock(genesis);
blockchain.setTotalDifficulty(genesis.getCumulativeDifficulty());
return blockchain;
}
use of co.rsk.validators.DummyBlockValidator in project rskj by rsksmart.
the class BlockChainBuilder method build.
public BlockChainImpl build() {
BlocksIndex blocksIndex = new HashMapBlocksIndex();
if (config == null) {
config = new TestSystemProperties();
}
if (trieStore == null) {
trieStore = new TrieStoreImpl(new HashMapDB().setClearOnClose(false));
}
if (repository == null) {
repository = new MutableRepository(trieStore, new Trie(trieStore));
}
if (stateRootHandler == null) {
stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
}
if (genesis == null) {
genesis = new BlockGenerator().getGenesisBlock();
}
GenesisLoaderImpl.loadGenesisInitalState(repository, genesis);
repository.commit();
genesis.setStateRoot(repository.getRoot());
genesis.flushRLP();
BlockFactory blockFactory = new BlockFactory(config.getActivationConfig());
if (blockStore == null) {
blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), blocksIndex);
}
if (receiptStore == null) {
KeyValueDataSource ds = new HashMapDB();
ds.init();
receiptStore = new ReceiptStoreImpl(ds);
}
if (listener == null) {
listener = new BlockExecutorTest.SimpleEthereumListener();
}
if (bridgeSupportFactory == null) {
bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams()), config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
}
BlockValidatorBuilder validatorBuilder = new BlockValidatorBuilder();
validatorBuilder.addBlockRootValidationRule().addBlockUnclesValidationRule(blockStore).addBlockTxsValidationRule(trieStore).blockStore(blockStore);
BlockValidator blockValidator = validatorBuilder.build();
ReceivedTxSignatureCache receivedTxSignatureCache = new ReceivedTxSignatureCache();
BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(receivedTxSignatureCache);
TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, blockStore, receiptStore, blockFactory, new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), blockTxSignatureCache);
repositoryLocator = new RepositoryLocator(trieStore, stateRootHandler);
transactionPool = new TransactionPoolImpl(config, repositoryLocator, this.blockStore, blockFactory, new TestCompositeEthereumListener(), transactionExecutorFactory, new ReceivedTxSignatureCache(), 10, 100);
BlockExecutor blockExecutor = new BlockExecutor(config.getActivationConfig(), repositoryLocator, transactionExecutorFactory);
BlockChainImpl blockChain = new BlockChainLoader(blockStore, receiptStore, transactionPool, listener, blockValidator, blockExecutor, genesis, stateRootHandler, repositoryLocator).loadBlockchain();
if (this.testing) {
blockChain.setBlockValidator(new DummyBlockValidator());
blockChain.setNoValidation(true);
}
blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
if (this.blocks != null) {
for (Block b : this.blocks) {
blockExecutor.executeAndFillAll(b, blockChain.getBestBlock().getHeader());
blockChain.tryToConnect(b);
}
}
return blockChain;
}
use of co.rsk.validators.DummyBlockValidator in project rskj by rsksmart.
the class TestRunner method runTestCase.
public List<String> runTestCase(BlockTestCase testCase) {
/* 1 */
// Create genesis + init pre state
ValidationStats vStats = new ValidationStats();
Block genesis = build(testCase.getGenesisBlockHeader(), null, null);
TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
Repository repository = RepositoryBuilder.build(trieStore, testCase.getPre());
IndexedBlockStore blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
CompositeEthereumListener listener = new TestCompositeEthereumListener();
KeyValueDataSource ds = new HashMapDB();
ds.init();
ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(new 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, new ReceivedTxSignatureCache(), 10, 100);
BlockChainImpl blockchain = new BlockChainImpl(blockStore, receiptStore, transactionPool, null, new DummyBlockValidator(), new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(trieStore, stateRootHandler), transactionExecutorFactory), stateRootHandler);
blockchain.setNoValidation(true);
blockchain.setStatus(genesis, genesis.getCumulativeDifficulty());
/* 2 */
// Create block traffic list
List<Block> blockTraffic = new ArrayList<>();
for (BlockTck blockTck : testCase.getBlocks()) {
Block block = build(blockTck.getBlockHeader(), blockTck.getTransactions(), blockTck.getUncleHeaders());
Block tBlock = null;
try {
byte[] rlp = parseData(blockTck.getRlp());
tBlock = blockFactory.decodeBlock(rlp);
ArrayList<String> outputSummary = BlockHeaderValidator.valid(tBlock.getHeader(), block.getHeader(), null);
if (!outputSummary.isEmpty()) {
for (String output : outputSummary) logger.error("at block {}: {}", Integer.toString(blockTraffic.size()), output);
}
blockTraffic.add(tBlock);
} catch (Exception e) {
System.out.println("*** Exception");
}
}
// Inject blocks to the blockchain execution
for (Block block : blockTraffic) {
ImportResult importResult = blockchain.tryToConnect(block);
logger.debug("{} ~ {} difficulty: {} ::: {}", block.getPrintableHash(), toPrintableHash(block.getParentHash().getBytes()), block.getCumulativeDifficulty(), importResult.toString());
}
// Check state root matches last valid block
List<String> results = new ArrayList<>();
String currRoot = ByteUtil.toHexString(repository.getRoot());
byte[] bestHash = Hex.decode(testCase.getLastblockhash());
String finalRoot = ByteUtil.toHexString(blockStore.getBlockByHash(bestHash).getStateRoot());
if (validateStateRoots) {
if (!finalRoot.equals(currRoot)) {
String formattedString = String.format("Root hash doesn't match best: expected: %s current: %s", finalRoot, currRoot);
results.add(formattedString);
}
}
Repository postRepository = RepositoryBuilder.build(testCase.getPostState());
List<String> repoResults = RepositoryValidator.valid(repository, postRepository, validateStateRoots, validateBalances, null);
results.addAll(repoResults);
return results;
}
use of co.rsk.validators.DummyBlockValidator in project rskj by rsksmart.
the class BlockChainImplTest method createWithoutArgumentsAndUnusedMethods.
@Test
public void createWithoutArgumentsAndUnusedMethods() {
BlockChainImpl blockChain = new BlockChainImpl(config, null, null, null, null, null, null, new DummyBlockValidator());
blockChain.setExitOn(0);
blockChain.close();
}
use of co.rsk.validators.DummyBlockValidator in project rskj by rsksmart.
the class RskTestFactory method getBlockchain.
public BlockChainImpl getBlockchain() {
if (blockchain == null) {
blockchain = new BlockChainImpl(config, getRepository(), getBlockStore(), getReceiptStore(), // circular dependency
null, null, null, new DummyBlockValidator());
TransactionPool transactionPool = getTransactionPool();
blockchain.setTransactionPool(transactionPool);
}
return blockchain;
}
Aggregations