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