Search in sources :

Example 1 with DefaultBlockchain

use of org.hyperledger.besu.ethereum.chain.DefaultBlockchain in project besu by hyperledger.

the class PrivacyReorgTest method reorgToShorterChain.

@Test
public void reorgToShorterChain() {
    // Setup an initial blockchain with one private transaction
    final ProtocolContext protocolContext = besuController.getProtocolContext();
    final DefaultBlockchain blockchain = (DefaultBlockchain) protocolContext.getBlockchain();
    final String firstBlockStateRoot = "0xbca927086c294984d6c2add82731c386cf2df3cd75509907dac928de12b7c472";
    final Block firstBlock = gen.block(getBlockOptionsNoTransaction(blockchain.getGenesisBlock(), firstBlockStateRoot));
    final String secondBlockStateRoot = "0xb3d70bce4428fb9b4549240b2130c4eea12c4ea36ae13108ed21289366a8d65f";
    final Block secondBlock = gen.block(getBlockOptionsWithTransaction(firstBlock, privacyMarkerTransaction, secondBlockStateRoot));
    appendBlock(besuController, blockchain, protocolContext, firstBlock);
    appendBlock(besuController, blockchain, protocolContext, secondBlock);
    assertThat(blockchain.getChainHeadBlockNumber()).isEqualTo(2);
    // Check that the private state root is not the empty state
    assertPrivateStateRoot(privateStateRootResolver, blockchain, STATE_ROOT_AFTER_TRANSACTION_APPENDED_TO_EMPTY_STATE);
    // Create parallel fork of length 1 which removes privacy marker transaction
    final Difficulty remainingDifficultyToOutpace = blockchain.getBlockByNumber(1).get().getHeader().getDifficulty().plus(blockchain.getBlockByNumber(2).get().getHeader().getDifficulty());
    final String forkBlockStateRoot = "0x5c0adcdde38d38b4365c238c4ba05bf9ebfdf506f749b884b67003f375e43e4b";
    final Block forkBlock = gen.block(getBlockOptionsNoTransactionWithDifficulty(blockchain.getGenesisBlock(), remainingDifficultyToOutpace.plus(10L), forkBlockStateRoot));
    appendBlock(besuController, blockchain, protocolContext, forkBlock);
    assertThat(blockchain.getChainHeadBlockNumber()).isEqualTo(1);
    // Check that the private state root is the empty state
    assertPrivateStateRoot(privateStateRootResolver, blockchain, EMPTY_ROOT_HASH);
}
Also used : Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Block(org.hyperledger.besu.ethereum.core.Block) DefaultBlockchain(org.hyperledger.besu.ethereum.chain.DefaultBlockchain) Test(org.junit.Test)

Example 2 with DefaultBlockchain

use of org.hyperledger.besu.ethereum.chain.DefaultBlockchain in project besu by hyperledger.

the class PrivacyReorgTest method reorgToLongerChain.

@Test
public void reorgToLongerChain() {
    // Setup an initial blockchain with one private transaction
    final ProtocolContext protocolContext = besuController.getProtocolContext();
    final DefaultBlockchain blockchain = (DefaultBlockchain) protocolContext.getBlockchain();
    final Block firstBlock = gen.block(getBlockOptionsWithTransaction(blockchain.getGenesisBlock(), privacyMarkerTransaction, FIRST_BLOCK_WITH_SINGLE_TRANSACTION_STATE_ROOT));
    appendBlock(besuController, blockchain, protocolContext, firstBlock);
    assertThat(blockchain.getChainHeadBlockNumber()).isEqualTo(1);
    // Check that the private state root is not the empty state
    assertPrivateStateRoot(privateStateRootResolver, blockchain, STATE_ROOT_AFTER_TRANSACTION_APPENDED_TO_EMPTY_STATE);
    // Create parallel fork of length 1 which removes privacy marker transaction
    final Block forkBlock = gen.block(getBlockOptionsNoTransactionWithDifficulty(blockchain.getGenesisBlock(), firstBlock.getHeader().getDifficulty().plus(10L), FIRST_BLOCK_WITH_NO_TRANSACTIONS_STATE_ROOT));
    // Check that the private state root did not change
    assertPrivateStateRoot(privateStateRootResolver, blockchain, STATE_ROOT_AFTER_TRANSACTION_APPENDED_TO_EMPTY_STATE);
    final String secondForkBlockStateRoot = "0x76b8747d05fabcc87b2cfba519da0b1359b29fe7553bfd4837746edf31fb95fc";
    final Block secondForkBlock = gen.block(getBlockOptionsNoTransactionWithDifficulty(forkBlock, forkBlock.getHeader().getDifficulty().plus(10L), secondForkBlockStateRoot));
    appendBlock(besuController, blockchain, protocolContext, forkBlock);
    appendBlock(besuController, blockchain, protocolContext, secondForkBlock);
    assertThat(blockchain.getChainHeadBlockNumber()).isEqualTo(2);
    // Check that the private state root is the empty state
    assertPrivateStateRoot(privateStateRootResolver, blockchain, EMPTY_ROOT_HASH);
    // Add another private transaction
    final String thirdForkBlockStateRoot = "0xcae9fa05107c1501c1962239f729d2f34186414abbaeb0dd1a3e0a6c899f79a3";
    final Block thirdForkBlock = gen.block(getBlockOptionsWithTransactionAndDifficulty(secondForkBlock, privacyMarkerTransaction, secondForkBlock.getHeader().getDifficulty().plus(10L), thirdForkBlockStateRoot));
    appendBlock(besuController, blockchain, protocolContext, thirdForkBlock);
    // Check that the private state did change after reorg
    assertPrivateStateRoot(privateStateRootResolver, blockchain, STATE_ROOT_AFTER_TRANSACTION_APPENDED_TO_EMPTY_STATE);
}
Also used : ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Block(org.hyperledger.besu.ethereum.core.Block) DefaultBlockchain(org.hyperledger.besu.ethereum.chain.DefaultBlockchain) Test(org.junit.Test)

Example 3 with DefaultBlockchain

use of org.hyperledger.besu.ethereum.chain.DefaultBlockchain in project besu by hyperledger.

the class PrivacyReorgTest method reorgToChainAtEqualHeight.

@Test
public void reorgToChainAtEqualHeight() {
    // Setup an initial blockchain with one private transaction
    final ProtocolContext protocolContext = besuController.getProtocolContext();
    final DefaultBlockchain blockchain = (DefaultBlockchain) protocolContext.getBlockchain();
    final Block firstBlock = gen.block(getBlockOptionsWithTransaction(blockchain.getGenesisBlock(), privacyMarkerTransaction, FIRST_BLOCK_WITH_SINGLE_TRANSACTION_STATE_ROOT));
    appendBlock(besuController, blockchain, protocolContext, firstBlock);
    // Check that the private state root is not the empty state
    assertPrivateStateRoot(privateStateRootResolver, blockchain, STATE_ROOT_AFTER_TRANSACTION_APPENDED_TO_EMPTY_STATE);
    // Create parallel fork of length 1 which removes privacy marker transaction
    final Block forkBlock = gen.block(getBlockOptionsNoTransactionWithDifficulty(blockchain.getGenesisBlock(), blockchain.getChainHeadHeader().getDifficulty().plus(10L), FIRST_BLOCK_WITH_NO_TRANSACTIONS_STATE_ROOT));
    appendBlock(besuController, blockchain, protocolContext, forkBlock);
    // Check that the private state root is the empty state
    assertPrivateStateRoot(privateStateRootResolver, blockchain, EMPTY_ROOT_HASH);
}
Also used : ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Block(org.hyperledger.besu.ethereum.core.Block) DefaultBlockchain(org.hyperledger.besu.ethereum.chain.DefaultBlockchain) Test(org.junit.Test)

Example 4 with DefaultBlockchain

use of org.hyperledger.besu.ethereum.chain.DefaultBlockchain in project besu by hyperledger.

the class PrivacyReorgTest method privacyGroupHeadIsTracked.

@Test
public void privacyGroupHeadIsTracked() {
    // Setup an initial blockchain with one private transaction
    final ProtocolContext protocolContext = besuController.getProtocolContext();
    final DefaultBlockchain blockchain = (DefaultBlockchain) protocolContext.getBlockchain();
    final PrivateStateStorage privateStateStorage = privacyParameters.getPrivateStateStorage();
    final Block firstBlock = gen.block(getBlockOptionsWithTransaction(blockchain.getGenesisBlock(), privacyMarkerTransaction, FIRST_BLOCK_WITH_SINGLE_TRANSACTION_STATE_ROOT));
    appendBlock(besuController, blockchain, protocolContext, firstBlock);
    final PrivacyGroupHeadBlockMap expected = new PrivacyGroupHeadBlockMap(Collections.singletonMap(PRIVACY_GROUP_BYTES32, firstBlock.getHash()));
    assertThat(privateStateStorage.getPrivacyGroupHeadBlockMap(blockchain.getGenesisBlock().getHash())).isEmpty();
    assertThat(privateStateStorage.getPrivacyGroupHeadBlockMap(firstBlock.getHash())).isNotEmpty();
    assertThat(privateStateStorage.getPrivacyGroupHeadBlockMap(firstBlock.getHash())).contains(expected);
    final String secondBlockStateRoot = "0x57a19f52a9ff4405428b3e605e136662d5c1b6be6f84f98f3b8c42ddac5139c2";
    final Block secondBlock = gen.block(getBlockOptionsNoTransaction(firstBlock, secondBlockStateRoot));
    appendBlock(besuController, blockchain, protocolContext, secondBlock);
    assertThat(privateStateStorage.getPrivacyGroupHeadBlockMap(secondBlock.getHash())).isNotEmpty();
    assertThat(privateStateStorage.getPrivacyGroupHeadBlockMap(secondBlock.getHash())).contains(expected);
}
Also used : ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Block(org.hyperledger.besu.ethereum.core.Block) DefaultBlockchain(org.hyperledger.besu.ethereum.chain.DefaultBlockchain) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Test(org.junit.Test)

Aggregations

ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)4 DefaultBlockchain (org.hyperledger.besu.ethereum.chain.DefaultBlockchain)4 Block (org.hyperledger.besu.ethereum.core.Block)4 Test (org.junit.Test)4 Difficulty (org.hyperledger.besu.ethereum.core.Difficulty)1 PrivacyGroupHeadBlockMap (org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap)1 PrivateStateStorage (org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage)1