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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations