Search in sources :

Example 11 with BlockExecutor

use of co.rsk.core.bc.BlockExecutor in project rskj by rsksmart.

the class RemascProcessMinerFeesTest method noPublisherFeeIsPaidWhenThePublisherHasNoSiblings.

@Test
public void noPublisherFeeIsPaidWhenThePublisherHasNoSiblings() throws IOException, BlockStoreException {
    BlockChainBuilder builder = new BlockChainBuilder();
    Blockchain blockchain = builder.setTesting(true).setGenesis(genesisBlock).build();
    final long NUMBER_OF_TXS_WITH_FEES = 3;
    List<Block> blocks = createSimpleBlocks(genesisBlock, 4);
    Block blockWithOneTxD = RemascTestRunner.createBlock(this.genesisBlock, blocks.get(blocks.size() - 1), PegTestUtils.createHash3(), coinbaseD, null, minerFee, 0, txValue, cowKey);
    blocks.add(blockWithOneTxD);
    Block blockWithOneTxA = RemascTestRunner.createBlock(this.genesisBlock, blockWithOneTxD, PegTestUtils.createHash3(), coinbaseA, null, minerFee, 1, txValue, cowKey);
    Block blockWithOneTxB = RemascTestRunner.createBlock(this.genesisBlock, blockWithOneTxD, PegTestUtils.createHash3(), coinbaseB, null, minerFee * 3, 1, txValue, cowKey);
    blocks.add(blockWithOneTxA);
    Block blockThatIncludesUncleC = RemascTestRunner.createBlock(this.genesisBlock, blockWithOneTxA, PegTestUtils.createHash3(), coinbaseC, Lists.newArrayList(blockWithOneTxB.getHeader()), minerFee, 2, txValue, cowKey);
    blocks.add(blockThatIncludesUncleC);
    blocks.addAll(createSimpleBlocks(blockThatIncludesUncleC, 7));
    BlockExecutor blockExecutor = new BlockExecutor(config, blockchain.getRepository(), null, blockchain.getBlockStore(), null);
    for (Block b : blocks) {
        blockExecutor.executeAndFillAll(b, blockchain.getBestBlock());
        blockchain.tryToConnect(b);
    }
    // validate that the blockchain's and REMASC's initial states are correct
    Coin cowRemainingBalance = cowInitialBalance.subtract(Coin.valueOf(minerFee * NUMBER_OF_TXS_WITH_FEES + txValue * NUMBER_OF_TXS_WITH_FEES));
    List<Long> otherAccountsBalance = new ArrayList<>(Arrays.asList(null, null, null, null));
    this.validateAccountsCurrentBalanceIsCorrect(blockchain.getRepository(), cowRemainingBalance, minerFee * NUMBER_OF_TXS_WITH_FEES, null, this.getAccountsWithExpectedBalance(otherAccountsBalance));
    this.validateRemascsStorageIsCorrect(this.getRemascStorageProvider(blockchain), Coin.ZERO, Coin.ZERO, 1L);
    // add block to pay fees of blocks on blockchain's height 4
    Block blockToPayFeesOnHeightFour = RemascTestRunner.createBlock(this.genesisBlock, blocks.get(blocks.size() - 1), PegTestUtils.createHash3(), TestUtils.randomAddress(), null, minerFee, 0, txValue, cowKey);
    blockExecutor.executeAndFillAll(blockToPayFeesOnHeightFour, blockchain.getBestBlock());
    blockchain.tryToConnect(blockToPayFeesOnHeightFour);
    Repository repository = blockchain.getRepository();
    // -- After executing REMASC's contract for paying height 4 block
    // validate that account's balances are correct
    long blockRewardOnHeightFour = minerFee / remascConfig.getSyntheticSpan();
    long remascCurrentBalance = minerFee * 3 - blockRewardOnHeightFour;
    long rskCurrentBalance = blockRewardOnHeightFour / remascConfig.getRskLabsDivisor();
    blockRewardOnHeightFour -= rskCurrentBalance;
    long federationReward = blockRewardOnHeightFour / remascConfig.getFederationDivisor();
    assertEquals(33, federationReward);
    blockRewardOnHeightFour -= federationReward;
    List<Long> otherAccountsBalanceOnHeightFour = new ArrayList<>(Arrays.asList(null, null, null, blockRewardOnHeightFour));
    this.validateAccountsCurrentBalanceIsCorrect(repository, cowRemainingBalance, remascCurrentBalance, rskCurrentBalance, this.getAccountsWithExpectedBalance(otherAccountsBalanceOnHeightFour));
    // validate that REMASC's state is correct
    blockRewardOnHeightFour = minerFee / remascConfig.getSyntheticSpan();
    Coin expectedRewardBalance = Coin.valueOf(minerFee - blockRewardOnHeightFour);
    this.validateRemascsStorageIsCorrect(this.getRemascStorageProvider(blockchain), expectedRewardBalance, Coin.ZERO, 1L);
    this.validateFederatorsBalanceIsCorrect(blockchain.getRepository(), federationReward);
}
Also used : Coin(co.rsk.core.Coin) BlockExecutor(co.rsk.core.bc.BlockExecutor) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) Test(org.junit.Test)

Example 12 with BlockExecutor

use of co.rsk.core.bc.BlockExecutor in project rskj by rsksmart.

the class WorldDslProcessor method processBlockChainCommand.

private void processBlockChainCommand(DslCommand cmd) {
    Block parent = world.getBlockByName(cmd.getArgument(0));
    int k = 1;
    while (cmd.getArgument(k) != null) {
        String name = cmd.getArgument(k);
        int difficulty = k;
        if (name != null) {
            StringTokenizer difficultyTokenizer = new StringTokenizer(name, ":");
            name = difficultyTokenizer.nextToken();
            difficulty = difficultyTokenizer.hasMoreTokens() ? parseDifficulty(difficultyTokenizer.nextToken(), k) : k;
        }
        Block block = blockBuilder.difficulty(difficulty).parent(parent).build();
        BlockExecutor executor = new BlockExecutor(new RskSystemProperties(), world.getRepository(), null, world.getBlockChain().getBlockStore(), null);
        executor.executeAndFill(block, parent);
        world.saveBlock(name, block);
        parent = block;
        k++;
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) BlockExecutor(co.rsk.core.bc.BlockExecutor) Block(org.ethereum.core.Block) RskSystemProperties(co.rsk.config.RskSystemProperties)

Example 13 with BlockExecutor

use of co.rsk.core.bc.BlockExecutor in project rskj by rsksmart.

the class WorldDslProcessor method processBlockConnectCommand.

private void processBlockConnectCommand(DslCommand cmd) {
    BlockChainImpl blockChain = world.getBlockChain();
    int nblocks = cmd.getArity();
    for (int k = 0; k < nblocks; k++) {
        String name = cmd.getArgument(k);
        Block block = world.getBlockByName(name);
        BlockExecutor executor = world.getBlockExecutor();
        executor.executeAndFill(block, blockChain.getBestBlock());
        block.seal();
        latestImportResult = blockChain.tryToConnect(block);
    }
}
Also used : BlockExecutor(co.rsk.core.bc.BlockExecutor) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) Block(org.ethereum.core.Block)

Aggregations

BlockExecutor (co.rsk.core.bc.BlockExecutor)13 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)9 Test (org.junit.Test)8 Coin (co.rsk.core.Coin)7 RskAddress (co.rsk.core.RskAddress)6 RskSystemProperties (co.rsk.config.RskSystemProperties)4 Block (org.ethereum.core.Block)3 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)2 Keccak256 (co.rsk.crypto.Keccak256)2 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)1 BlockDifficulty (co.rsk.core.BlockDifficulty)1 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)1 DownloadingBodiesSyncState (co.rsk.net.sync.DownloadingBodiesSyncState)1 PegTestUtils (co.rsk.peg.PegTestUtils)1 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1 Collectors (java.util.stream.Collectors)1