use of co.rsk.core.bc.BlockChainStatus in project rskj by rsksmart.
the class DslFilesTest method runLogs01Resource.
@Test
public void runLogs01Resource() throws FileNotFoundException, DslProcessorException {
DslParser parser = DslParser.fromResource("dsl/logs01.txt");
World world = new World();
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);
// the transaction receipt should have three logs
BlockChainStatus status = world.getBlockChain().getStatus();
Assert.assertEquals(1, status.getBestBlockNumber());
Block block = status.getBestBlock();
Assert.assertEquals(1, block.getTransactionsList().size());
byte[] txhash = block.getTransactionsList().get(0).getHash().getBytes();
TransactionInfo txinfo = world.getBlockChain().getTransactionInfo(txhash);
// only three events, raised by
// Counter constructor
// Counter getValue
// Creator constructor
Assert.assertEquals(3, txinfo.getReceipt().getLogInfoList().size());
// only one topic in each event
Assert.assertEquals(1, txinfo.getReceipt().getLogInfoList().get(0).getTopics().size());
Assert.assertEquals(1, txinfo.getReceipt().getLogInfoList().get(1).getTopics().size());
Assert.assertEquals(1, txinfo.getReceipt().getLogInfoList().get(2).getTopics().size());
// the topics are different
DataWord topic1 = txinfo.getReceipt().getLogInfoList().get(0).getTopics().get(0);
DataWord topic2 = txinfo.getReceipt().getLogInfoList().get(1).getTopics().get(0);
DataWord topic3 = txinfo.getReceipt().getLogInfoList().get(2).getTopics().get(0);
Assert.assertNotEquals(topic1, topic2);
Assert.assertNotEquals(topic1, topic3);
Assert.assertNotEquals(topic2, topic3);
// only the third log was directly produced by the created contract
byte[] contractAddress = txinfo.getReceipt().getTransaction().getContractAddress().getBytes();
Assert.assertFalse(Arrays.equals(contractAddress, txinfo.getReceipt().getLogInfoList().get(0).getAddress()));
Assert.assertFalse(Arrays.equals(contractAddress, txinfo.getReceipt().getLogInfoList().get(1).getAddress()));
Assert.assertTrue(Arrays.equals(contractAddress, txinfo.getReceipt().getLogInfoList().get(2).getAddress()));
}
use of co.rsk.core.bc.BlockChainStatus in project rskj by rsksmart.
the class SnapshotManagerTest method revertToSnapshotClearingTransactionPool.
@Test
public void revertToSnapshotClearingTransactionPool() {
Blockchain blockchain = createBlockchain();
addBlocks(blockchain, 10);
BlockChainStatus status = blockchain.getStatus();
SnapshotManager manager = new SnapshotManager();
int snapshotId = manager.takeSnapshot(blockchain);
addBlocks(blockchain, 20);
manager.takeSnapshot(blockchain);
Assert.assertEquals(2, manager.getSnapshots().size());
TransactionPool transactionPool = blockchain.getTransactionPool();
Assert.assertNotNull(transactionPool);
List<Transaction> txs = new ArrayList<>();
txs.add(createSampleTransaction());
txs.add(createSampleTransaction());
transactionPool.addTransactions(txs);
Assert.assertFalse(transactionPool.getPendingTransactions().isEmpty());
Assert.assertFalse(transactionPool.getPendingTransactions().isEmpty());
Assert.assertEquals(30, blockchain.getStatus().getBestBlockNumber());
Assert.assertTrue(manager.revertToSnapshot(blockchain, snapshotId));
BlockChainStatus newStatus = blockchain.getStatus();
Assert.assertEquals(status.getBestBlockNumber(), newStatus.getBestBlockNumber());
Assert.assertEquals(status.getTotalDifficulty(), newStatus.getTotalDifficulty());
Assert.assertEquals(status.getBestBlock().getHash(), newStatus.getBestBlock().getHash());
Assert.assertTrue(blockchain.getTransactionPool().getPendingTransactions().isEmpty());
Assert.assertEquals(1, manager.getSnapshots().size());
for (int k = 11; k <= 30; k++) Assert.assertTrue(blockchain.getBlocksByNumber(k).isEmpty());
}
use of co.rsk.core.bc.BlockChainStatus in project rskj by rsksmart.
the class NodeMessageHandler method sendStatusToAll.
private synchronized void sendStatusToAll() {
BlockChainStatus blockChainStatus = this.blockProcessor.getBlockchain().getStatus();
Block block = blockChainStatus.getBestBlock();
BlockDifficulty totalDifficulty = blockChainStatus.getTotalDifficulty();
Status status = new Status(block.getNumber(), block.getHash().getBytes(), block.getParentHash().getBytes(), totalDifficulty);
logger.trace("Sending status best block to all {} {}", status.getBestBlockNumber(), Hex.toHexString(status.getBestBlockHash()).substring(0, 8));
this.channelManager.broadcastStatus(status);
}
use of co.rsk.core.bc.BlockChainStatus in project rskj by rsksmart.
the class RskWireProtocol method sendStatus.
/**
***********************
* Message Sending *
************************
*/
@Override
public void sendStatus() {
byte protocolVersion = version.getCode();
int networkId = config.networkId();
BlockChainStatus blockChainStatus = this.blockchain.getStatus();
Block bestBlock = blockChainStatus.getBestBlock();
BlockDifficulty totalDifficulty = blockChainStatus.getTotalDifficulty();
// Original status
Genesis genesis = GenesisLoader.loadGenesis(config, config.genesisInfo(), config.getBlockchainConfig().getCommonConstants().getInitialNonce(), true);
org.ethereum.net.eth.message.StatusMessage msg = new org.ethereum.net.eth.message.StatusMessage(protocolVersion, networkId, ByteUtil.bigIntegerToBytes(totalDifficulty.asBigInteger()), bestBlock.getHash().getBytes(), genesis.getHash().getBytes());
sendMessage(msg);
// RSK new protocol send status
Status status = new Status(bestBlock.getNumber(), bestBlock.getHash().getBytes(), bestBlock.getParentHash().getBytes(), totalDifficulty);
RskMessage rskmessage = new RskMessage(config, new StatusMessage(status));
loggerNet.trace("Sending status best block {} to {}", status.getBestBlockNumber(), this.messageSender.getPeerNodeID().toString());
sendMessage(rskmessage);
ethState = EthState.STATUS_SENT;
}
use of co.rsk.core.bc.BlockChainStatus in project rskj by rsksmart.
the class SnapshotManagerTest method resetSnapshotClearingTransactionPool.
@Test
public void resetSnapshotClearingTransactionPool() {
Blockchain blockchain = createBlockchain();
Block genesis = blockchain.getBestBlock();
BlockDifficulty genesisDifficulty = blockchain.getStatus().getTotalDifficulty();
addBlocks(blockchain, 10);
BlockChainStatus status = blockchain.getStatus();
Assert.assertEquals(10, status.getBestBlockNumber());
TransactionPool transactionPool = blockchain.getTransactionPool();
Assert.assertNotNull(transactionPool);
List<Transaction> txs = new ArrayList<>();
txs.add(createSampleTransaction());
txs.add(createSampleTransaction());
transactionPool.addTransactions(txs);
Assert.assertFalse(transactionPool.getPendingTransactions().isEmpty());
Assert.assertFalse(transactionPool.getPendingTransactions().isEmpty());
SnapshotManager manager = new SnapshotManager();
manager.takeSnapshot(blockchain);
Assert.assertFalse(manager.getSnapshots().isEmpty());
Assert.assertTrue(manager.resetSnapshots(blockchain));
Assert.assertTrue(manager.getSnapshots().isEmpty());
Assert.assertTrue(manager.resetSnapshots(blockchain));
BlockChainStatus newStatus = blockchain.getStatus();
Assert.assertEquals(0, newStatus.getBestBlockNumber());
Assert.assertEquals(genesisDifficulty, newStatus.getTotalDifficulty());
Assert.assertEquals(genesis.getHash(), newStatus.getBestBlock().getHash());
Assert.assertTrue(blockchain.getTransactionPool().getPendingTransactions().isEmpty());
Assert.assertTrue(manager.getSnapshots().isEmpty());
for (int k = 1; k <= 10; k++) Assert.assertTrue(blockchain.getBlocksByNumber(k).isEmpty());
}
Aggregations