Search in sources :

Example 21 with BridgeSupportFactory

use of co.rsk.peg.BridgeSupportFactory in project rskj by rsksmart.

the class MinerHelper method processBlock.

public void processBlock(Block block, Block parent) {
    latestStateRootHash = null;
    totalGasUsed = 0;
    totalPaidFees = Coin.ZERO;
    txReceipts = new ArrayList<>();
    Repository track = repositoryLocator.startTrackingAt(parent.getHeader());
    // this variable is set before iterating transactions in case list is empty
    latestStateRootHash = track.getRoot();
    // RSK test, remove
    String stateHash1 = ByteUtil.toHexString(blockchain.getBestBlock().getStateRoot());
    String stateHash2 = ByteUtil.toHexString(repository.getRoot());
    if (stateHash1.compareTo(stateHash2) != 0) {
        logger.error("Strange state in block {} {}", block.getNumber(), block.getHash());
        panicProcessor.panic("minerserver", String.format("Strange state in block %d %s", block.getNumber(), block.getHash()));
    }
    int txindex = 0;
    BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams()), config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
    BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(new ReceivedTxSignatureCache());
    for (Transaction tx : block.getTransactionsList()) {
        TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, null, null, blockFactory, null, new PrecompiledContracts(config, bridgeSupportFactory), blockTxSignatureCache);
        TransactionExecutor executor = transactionExecutorFactory.newInstance(tx, txindex++, block.getCoinbase(), track, block, totalGasUsed);
        executor.executeTransaction();
        long gasUsed = executor.getGasUsed();
        Coin paidFees = executor.getPaidFees();
        totalGasUsed += gasUsed;
        totalPaidFees = totalPaidFees.add(paidFees);
        track.commit();
        TransactionReceipt receipt = new TransactionReceipt();
        receipt.setGasUsed(gasUsed);
        receipt.setCumulativeGas(totalGasUsed);
        latestStateRootHash = track.getRoot();
        receipt.setPostTxState(latestStateRootHash);
        receipt.setTxStatus(executor.getReceipt().isSuccessful());
        receipt.setStatus(executor.getReceipt().getStatus());
        receipt.setTransaction(tx);
        receipt.setLogInfoList(executor.getVMLogs());
        txReceipts.add(receipt);
    }
}
Also used : TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) Coin(co.rsk.core.Coin) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory)

Aggregations

BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)21 PrecompiledContracts (org.ethereum.vm.PrecompiledContracts)11 ExecutionBlockRetriever (co.rsk.rpc.ExecutionBlockRetriever)9 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)8 ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)8 Test (org.junit.Test)8 RepositoryBtcBlockStoreWithCache (co.rsk.peg.RepositoryBtcBlockStoreWithCache)7 Web3RskImpl (co.rsk.rpc.Web3RskImpl)6 DebugModule (co.rsk.rpc.modules.debug.DebugModule)6 DebugModuleImpl (co.rsk.rpc.modules.debug.DebugModuleImpl)6 PersonalModuleWalletEnabled (co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled)6 TxPoolModule (co.rsk.rpc.modules.txpool.TxPoolModule)6 TxPoolModuleImpl (co.rsk.rpc.modules.txpool.TxPoolModuleImpl)6 EthModule (co.rsk.rpc.modules.eth.EthModule)5 EthModuleWalletEnabled (co.rsk.rpc.modules.eth.EthModuleWalletEnabled)5 TestSystemProperties (co.rsk.config.TestSystemProperties)4 RskAddress (co.rsk.core.RskAddress)4 BlockExecutor (co.rsk.core.bc.BlockExecutor)4 MiningMainchainView (co.rsk.core.bc.MiningMainchainView)4 ReversibleTransactionExecutor (co.rsk.core.ReversibleTransactionExecutor)3