Search in sources :

Example 16 with BlockFactory

use of org.ethereum.core.BlockFactory in project rskj by rsksmart.

the class AltBN128Test method executeCode.

private Program executeCode(String code) {
    VmConfig vmConfig = config.getVmConfig();
    BlockFactory blockFactory = new BlockFactory(config.getActivationConfig());
    ProgramInvokeMockImpl invoke = new ProgramInvokeMockImpl();
    BytecodeCompiler compiler = new BytecodeCompiler();
    byte[] compiledCode = compiler.compile(code);
    VM vm = new VM(vmConfig, precompiledContracts);
    Program program = new Program(vmConfig, precompiledContracts, blockFactory, activations, compiledCode, invoke, null, new HashSet<>());
    vm.play(program);
    return program;
}
Also used : ProgramInvokeMockImpl(org.ethereum.vm.program.invoke.ProgramInvokeMockImpl) Program(org.ethereum.vm.program.Program) BlockFactory(org.ethereum.core.BlockFactory) VM(org.ethereum.vm.VM) BytecodeCompiler(co.rsk.vm.BytecodeCompiler) VmConfig(co.rsk.config.VmConfig)

Example 17 with BlockFactory

use of org.ethereum.core.BlockFactory in project rskj by rsksmart.

the class EnvironmentUtils method mineBlockWithCoinbaseTransaction.

private static Block mineBlockWithCoinbaseTransaction(TestSystemProperties config, Block parent) {
    BlockGenerator blockGenerator = new BlockGenerator(config.getNetworkConstants(), config.getActivationConfig());
    byte[] prefix = new byte[1000];
    byte[] compressedTag = org.bouncycastle.util.Arrays.concatenate(prefix, RskMiningConstants.RSK_TAG);
    Keccak256 blockMergedMiningHash = new Keccak256(parent.getHashForMergedMining());
    co.rsk.bitcoinj.core.NetworkParameters bitcoinNetworkParameters = co.rsk.bitcoinj.params.RegTestParams.get();
    co.rsk.bitcoinj.core.BtcTransaction bitcoinMergedMiningCoinbaseTransaction = MinerUtils.getBitcoinMergedMiningCoinbaseTransaction(bitcoinNetworkParameters, blockMergedMiningHash.getBytes());
    co.rsk.bitcoinj.core.BtcBlock bitcoinMergedMiningBlock = MinerUtils.getBitcoinMergedMiningBlock(bitcoinNetworkParameters, bitcoinMergedMiningCoinbaseTransaction);
    BigInteger targetBI = DifficultyUtils.difficultyToTarget(parent.getDifficulty());
    new BlockMiner(config.getActivationConfig()).findNonce(bitcoinMergedMiningBlock, targetBI);
    // We need to clone to allow modifications
    Block newBlock = new BlockFactory(config.getActivationConfig()).cloneBlockForModification(blockGenerator.createChildBlock(parent, new ArrayList<>(), new ArrayList<>(), parent.getDifficulty().asBigInteger().longValue(), MIN_GAS_PRICE, parent.getGasLimit()));
    newBlock.setBitcoinMergedMiningHeader(bitcoinMergedMiningBlock.cloneAsHeader().bitcoinSerialize());
    byte[] merkleProof = MinerUtils.buildMerkleProof(config.getActivationConfig(), pb -> pb.buildFromBlock(bitcoinMergedMiningBlock), newBlock.getNumber());
    byte[] additionalTag = Arrays.concatenate(ADDITIONAL_TAG, blockMergedMiningHash.getBytes());
    byte[] mergedMiningTx = org.bouncycastle.util.Arrays.concatenate(compressedTag, blockMergedMiningHash.getBytes(), additionalTag);
    newBlock.setBitcoinMergedMiningCoinbaseTransaction(mergedMiningTx);
    newBlock.setBitcoinMergedMiningMerkleProof(merkleProof);
    return newBlock;
}
Also used : BlockFactory(org.ethereum.core.BlockFactory) ArrayList(java.util.ArrayList) Keccak256(co.rsk.crypto.Keccak256) BlockMiner(co.rsk.blockchain.utils.BlockMiner) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BigInteger(java.math.BigInteger) Block(org.ethereum.core.Block)

Example 18 with BlockFactory

use of org.ethereum.core.BlockFactory in project rskj by rsksmart.

the class SimpleAsyncNode method createNode.

public static SimpleAsyncNode createNode(Blockchain blockchain, SyncConfiguration syncConfiguration, org.ethereum.db.BlockStore indexedBlockStore) {
    NetBlockStore blockStore = new NetBlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    BlockSyncService blockSyncService = new BlockSyncService(config, blockStore, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    NodeBlockProcessor processor = new NodeBlockProcessor(blockStore, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    DummyBlockValidationRule blockValidationRule = new DummyBlockValidationRule();
    PeerScoringManager peerScoringManager = RskMockFactory.getPeerScoringManager();
    SimpleChannelManager channelManager = new SimpleChannelManager();
    BlockFactory blockFactory = new BlockFactory(config.getActivationConfig());
    SyncProcessor syncProcessor = new SyncProcessor(blockchain, indexedBlockStore, mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, blockFactory, blockValidationRule, new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), new DifficultyCalculator(config.getActivationConfig(), config.getNetworkConstants()), new PeersInformation(channelManager, syncConfiguration, blockchain, peerScoringManager), mock(Genesis.class), mock(EthereumListener.class));
    NodeMessageHandler handler = new NodeMessageHandler(config, processor, syncProcessor, channelManager, null, peerScoringManager, mock(StatusResolver.class));
    return new SimpleAsyncNode(handler, blockchain, syncProcessor, channelManager);
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) BlockFactory(org.ethereum.core.BlockFactory) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) DifficultyCalculator(co.rsk.core.DifficultyCalculator) PeersInformation(co.rsk.net.sync.PeersInformation) Genesis(org.ethereum.core.Genesis)

Example 19 with BlockFactory

use of org.ethereum.core.BlockFactory in project rskj by rsksmart.

the class OneAsyncNodeTest method createNode.

private static SimpleAsyncNode createNode() {
    final World world = new World();
    final NetBlockStore store = new NetBlockStore();
    final Blockchain blockchain = world.getBlockChain();
    TestSystemProperties config = new TestSystemProperties();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    SimpleChannelManager channelManager = new SimpleChannelManager();
    SyncProcessor syncProcessor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, new BlockFactory(config.getActivationConfig()), new DummyBlockValidationRule(), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), new DifficultyCalculator(config.getActivationConfig(), config.getNetworkConstants()), new PeersInformation(channelManager, syncConfiguration, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
    NodeMessageHandler handler = new NodeMessageHandler(config, processor, syncProcessor, channelManager, null, RskMockFactory.getPeerScoringManager(), mock(StatusResolver.class));
    return new SimpleAsyncNode(handler, blockchain, syncProcessor, channelManager);
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) BlockFactory(org.ethereum.core.BlockFactory) Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) DifficultyCalculator(co.rsk.core.DifficultyCalculator) PeersInformation(co.rsk.net.sync.PeersInformation) Genesis(org.ethereum.core.Genesis) TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 20 with BlockFactory

use of org.ethereum.core.BlockFactory in project rskj by rsksmart.

the class BlockDifficultyValidationRuleTest method setUp.

@Before
public void setUp() {
    activationConfig = ActivationConfigsForTest.all();
    networkConstants = Constants.regtest();
    blockFactory = new BlockFactory(activationConfig);
}
Also used : BlockFactory(org.ethereum.core.BlockFactory) Before(org.junit.Before)

Aggregations

BlockFactory (org.ethereum.core.BlockFactory)20 Test (org.junit.Test)7 Block (org.ethereum.core.Block)6 TestSystemProperties (co.rsk.config.TestSystemProperties)4 BlockHeader (org.ethereum.core.BlockHeader)4 Blockchain (org.ethereum.core.Blockchain)4 Before (org.junit.Before)4 RskContext (co.rsk.RskContext)3 DifficultyCalculator (co.rsk.core.DifficultyCalculator)3 Keccak256 (co.rsk.crypto.Keccak256)3 World (co.rsk.test.World)3 NodeStopper (co.rsk.util.NodeStopper)3 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)3 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)3 HashMapDB (org.ethereum.datasource.HashMapDB)3 BlockStore (org.ethereum.db.BlockStore)3 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)2 BlockMiner (co.rsk.blockchain.utils.BlockMiner)2 ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)2 PeersInformation (co.rsk.net.sync.PeersInformation)2