use of co.rsk.core.bc.BlockChainImpl in project rskj by rsksmart.
the class Web3ImplTest method createWeb3.
private Web3Impl createWeb3(Ethereum eth, World world, ReceiptStore receiptStore) {
BlockChainImpl blockChain = world.getBlockChain();
TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
return createWeb3(eth, world, transactionPool, receiptStore);
}
use of co.rsk.core.bc.BlockChainImpl in project rskj by rsksmart.
the class Web3ImplTest method createWeb3.
private Web3Impl createWeb3(World world, BlockProcessor blockProcessor, ReceiptStore receiptStore) {
BlockChainImpl blockChain = world.getBlockChain();
TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
return createWeb3(Web3Mocks.getMockEthereum(), blockChain, transactionPool, blockChain.getBlockStore(), blockProcessor, new SimpleConfigCapabilities(), receiptStore);
}
use of co.rsk.core.bc.BlockChainImpl in project rskj by rsksmart.
the class BlockChainBuilderTest method createBlockChain.
@Test
public void createBlockChain() {
BlockChainBuilder builder = new BlockChainBuilder();
BlockChainImpl blockChain = builder.build();
Assert.assertNotNull(blockChain);
Assert.assertNotNull(blockChain.getRepository());
Assert.assertNotNull(blockChain.getBlockStore());
Assert.assertNotNull(blockChain.getListener());
Assert.assertNotNull(blockChain.getBlockValidator());
}
use of co.rsk.core.bc.BlockChainImpl in project rskj by rsksmart.
the class BlockChainLoader method loadBlockchain.
public BlockChainImpl loadBlockchain() {
BlockChainImpl blockchain = new BlockChainImpl(config, repository, blockStore, receiptStore, transactionPool, listener, adminInfo, blockValidator);
if (!config.databaseReset()) {
blockStore.load();
}
Block bestBlock = blockStore.getBestBlock();
if (bestBlock == null) {
logger.info("DB is empty - adding Genesis");
BigInteger initialNonce = config.getBlockchainConfig().getCommonConstants().getInitialNonce();
Genesis genesis = GenesisLoader.loadGenesis(config, config.genesisInfo(), initialNonce, true);
for (RskAddress addr : genesis.getPremine().keySet()) {
repository.createAccount(addr);
InitialAddressState initialAddressState = genesis.getPremine().get(addr);
repository.addBalance(addr, initialAddressState.getAccountState().getBalance());
AccountState accountState = repository.getAccountState(addr);
accountState.setNonce(initialAddressState.getAccountState().getNonce());
if (initialAddressState.getContractDetails() != null) {
repository.updateContractDetails(addr, initialAddressState.getContractDetails());
accountState.setStateRoot(initialAddressState.getAccountState().getStateRoot());
accountState.setCodeHash(initialAddressState.getAccountState().getCodeHash());
}
repository.updateAccountState(addr, accountState);
}
genesis.setStateRoot(repository.getRoot());
genesis.flushRLP();
blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
blockchain.setBestBlock(genesis);
blockchain.setTotalDifficulty(genesis.getCumulativeDifficulty());
listener.onBlock(genesis, new ArrayList<TransactionReceipt>());
repository.dumpState(genesis, 0, 0, null);
logger.info("Genesis block loaded");
} else {
BlockDifficulty totalDifficulty = blockStore.getTotalDifficultyForHash(bestBlock.getHash().getBytes());
blockchain.setBestBlock(bestBlock);
blockchain.setTotalDifficulty(totalDifficulty);
logger.info("*** Loaded up to block [{}] totalDifficulty [{}] with stateRoot [{}]", blockchain.getBestBlock().getNumber(), blockchain.getTotalDifficulty().toString(), Hex.toHexString(blockchain.getBestBlock().getStateRoot()));
}
String rootHash = config.rootHashStart();
if (StringUtils.isNotBlank(rootHash)) {
// update world state by dummy hash
byte[] rootHashArray = Hex.decode(rootHash);
logger.info("Loading root hash from property file: [{}]", rootHash);
this.repository.syncToRoot(rootHashArray);
} else {
// todo this is just a workaround, move EMPTY_TRIE_HASH logic to Trie implementation
if (!Arrays.equals(blockchain.getBestBlock().getStateRoot(), EMPTY_TRIE_HASH)) {
this.repository.syncToRoot(blockchain.getBestBlock().getStateRoot());
}
}
return blockchain;
}
use of co.rsk.core.bc.BlockChainImpl in project rskj by rsksmart.
the class NodeBlockProcessorUnclesTest method addBlockWithTwoUnknownUncles.
@Test
public void addBlockWithTwoUnknownUncles() throws UnknownHostException {
BlockChainImpl blockChain = new BlockChainBuilder().build();
NodeBlockProcessor processor = createNodeBlockProcessor(blockChain);
Block genesis = processor.getBlockchain().getBestBlock();
BlockBuilder blockBuilder = new BlockBuilder(blockChain, new BlockGenerator());
Block block1 = blockBuilder.parent(genesis).build();
Block uncle1 = blockBuilder.parent(genesis).build();
Block uncle2 = blockBuilder.parent(genesis).build();
List<BlockHeader> uncles = new ArrayList<>();
uncles.add(uncle1.getHeader());
uncles.add(uncle2.getHeader());
Block block2 = blockBuilder.parent(block1).uncles(uncles).build();
processor.processBlock(null, block1);
SimpleMessageChannel sender = new SimpleMessageChannel();
processor.processBlock(sender, block2);
Assert.assertEquals(2, processor.getBlockchain().getBestBlock().getNumber());
Assert.assertArrayEquals(block2.getHash().getBytes(), processor.getBlockchain().getBestBlockHash());
Assert.assertEquals(0, sender.getGetBlockMessages().size());
}
Aggregations