Search in sources :

Example 1 with PrivacyGroupHeadBlockMap

use of org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap in project besu by hyperledger.

the class PrivateStateRootResolverTest method resolveCorrectRootHashWhenMultipleCommitmentsExistForPrivacyGroup.

@Test
public void resolveCorrectRootHashWhenMultipleCommitmentsExistForPrivacyGroup() {
    final PrivateStateStorage.Updater updater = privateStateStorage.updater();
    updater.putPrivateBlockMetadata(BLOCKCHAIN.getBlockByNumber(16).get().getHash(), Bytes32.wrap(privacyGroupId), new PrivateBlockMetadata(Collections.singletonList(new PrivateTransactionMetadata(BLOCK_GENERATOR.transaction().getHash(), pmt1StateHash))));
    updater.putPrivateBlockMetadata(BLOCKCHAIN.getBlockByNumber(16).get().getHash(), Bytes32.wrap(failingPrivacyGroupId), new PrivateBlockMetadata(Collections.singletonList(new PrivateTransactionMetadata(BLOCK_GENERATOR.transaction().getHash(), pmt2StateHash))));
    updater.putPrivacyGroupHeadBlockMap(BLOCKCHAIN.getChainHeadHash(), new PrivacyGroupHeadBlockMap(Collections.singletonMap(Bytes32.wrap(privacyGroupId), BLOCKCHAIN.getBlockByNumber(16).get().getHash())));
    updater.commit();
    final PrivateStateRootResolver privateStateRootResolver = new PrivateStateRootResolver(privateStateStorage);
    assertThat(privateStateRootResolver.resolveLastStateRoot(privacyGroupId, BLOCKCHAIN.getChainHeadHash())).isEqualTo(pmt1StateHash);
}
Also used : PrivateTransactionMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata) PrivateBlockMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Test(org.junit.Test)

Example 2 with PrivacyGroupHeadBlockMap

use of org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap in project besu by hyperledger.

the class PrivateTransactionLocatorTest method mockStorageWithPrivacyGroupBlockHeaderMap.

private void mockStorageWithPrivacyGroupBlockHeaderMap(final String privacyGroupId, final BlockHeader blockHeader) {
    final PrivacyGroupHeadBlockMap privacyGroupHeadBlockMap = new PrivacyGroupHeadBlockMap(Collections.singletonMap(Bytes32.wrap(Bytes.fromBase64String(privacyGroupId)), blockHeader.getHash()));
    when(privateStateStorage.getPrivacyGroupHeadBlockMap(eq(blockHeader.getHash()))).thenReturn(Optional.of(privacyGroupHeadBlockMap));
}
Also used : PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap)

Example 3 with PrivacyGroupHeadBlockMap

use of org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap in project besu by hyperledger.

the class FlexiblePrivacyPrecompiledContractTest method setUp.

@Before
public void setUp() {
    final MutableWorldState mutableWorldState = mock(MutableWorldState.class);
    when(mutableWorldState.updater()).thenReturn(mock(WorldUpdater.class));
    when(worldStateArchive.getMutable()).thenReturn(mutableWorldState);
    when(worldStateArchive.getMutable(any(), any())).thenReturn(Optional.of(mutableWorldState));
    final PrivateStateStorage.Updater storageUpdater = mock(PrivateStateStorage.Updater.class);
    when(privateStateStorage.getPrivacyGroupHeadBlockMap(any())).thenReturn(Optional.of(PrivacyGroupHeadBlockMap.empty()));
    when(privateStateStorage.getPrivateBlockMetadata(any(), any())).thenReturn(Optional.empty());
    when(storageUpdater.putPrivateBlockMetadata(nullable(Bytes32.class), nullable(Bytes32.class), any())).thenReturn(storageUpdater);
    when(storageUpdater.putPrivacyGroupHeadBlockMap(nullable(Bytes32.class), any())).thenReturn(storageUpdater);
    when(storageUpdater.putTransactionReceipt(nullable(Bytes32.class), nullable(Bytes32.class), any())).thenReturn(storageUpdater);
    when(privateStateStorage.updater()).thenReturn(storageUpdater);
    messageFrame = mock(MessageFrame.class);
    final BlockDataGenerator blockGenerator = new BlockDataGenerator();
    final Block genesis = blockGenerator.genesisBlock();
    final Block block = blockGenerator.block(new BlockDataGenerator.BlockOptions().setParentHash(genesis.getHeader().getHash()));
    when(messageFrame.getBlockValues()).thenReturn(block.getHeader());
    final PrivateMetadataUpdater privateMetadataUpdater = mock(PrivateMetadataUpdater.class);
    final PrivacyGroupHeadBlockMap privacyGroupHeadBlockMap = mock(PrivacyGroupHeadBlockMap.class);
    when(messageFrame.getContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(privateMetadataUpdater);
    when(messageFrame.hasContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(true);
    when(messageFrame.getContextVariable(KEY_IS_PERSISTING_PRIVATE_STATE, false)).thenReturn(false);
    when(privateMetadataUpdater.getPrivacyGroupHeadBlockMap()).thenReturn(privacyGroupHeadBlockMap);
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Block(org.hyperledger.besu.ethereum.core.Block) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) Bytes32(org.apache.tuweni.bytes.Bytes32) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) PrivateMetadataUpdater(org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Before(org.junit.Before)

Example 4 with PrivacyGroupHeadBlockMap

use of org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap in project besu by hyperledger.

the class PrivacyBlockProcessorTest method mustPerformRehydration.

@Test
public void mustPerformRehydration() {
    final BlockDataGenerator blockDataGenerator = new BlockDataGenerator();
    final Blockchain blockchain = mock(Blockchain.class);
    final MutableWorldState mutableWorldState = mock(MutableWorldState.class);
    when(mutableWorldState.updater()).thenReturn(mock(WorldUpdater.class));
    final Block firstBlock = blockDataGenerator.block(BlockDataGenerator.BlockOptions.create().addTransaction(PrivateTransactionDataFixture.privateMarkerTransactionOnchain()));
    final Block secondBlock = blockDataGenerator.block(BlockDataGenerator.BlockOptions.create().addTransaction(PrivateTransactionDataFixture.privateMarkerTransactionOnchainAdd()));
    when(enclave.receive(any())).thenReturn(PrivateTransactionDataFixture.generateAddToGroupReceiveResponse(PrivateTransactionDataFixture.privateTransactionBesu(), PrivateTransactionDataFixture.privateMarkerTransactionOnchain()));
    when(blockchain.getTransactionLocation(any())).thenReturn(Optional.of(new TransactionLocation(firstBlock.getHash(), 0)));
    when(blockchain.getBlockByHash(any())).thenReturn(Optional.of(firstBlock));
    when(blockchain.getBlockHeader(any())).thenReturn(Optional.of(firstBlock.getHeader()));
    final ProtocolSpec protocolSpec = mockProtocolSpec();
    when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec);
    when(publicWorldStateArchive.getMutable(any(), any())).thenReturn(Optional.of(mutableWorldState));
    final MutableWorldState mockPrivateStateArchive = mockPrivateStateArchive();
    when(privateWorldStateArchive.getMutable(any(), any())).thenReturn(Optional.of(mockPrivateStateArchive));
    final PrivacyGroupHeadBlockMap expected = new PrivacyGroupHeadBlockMap(Collections.singletonMap(VALID_BASE64_ENCLAVE_KEY, firstBlock.getHash()));
    privateStateStorage.updater().putPrivacyGroupHeadBlockMap(firstBlock.getHash(), expected).putPrivateBlockMetadata(firstBlock.getHash(), VALID_BASE64_ENCLAVE_KEY, PrivateBlockMetadata.empty()).commit();
    privacyBlockProcessor.processBlock(blockchain, mutableWorldState, secondBlock);
    verify(blockProcessor).processBlock(eq(blockchain), eq(mutableWorldState), eq(secondBlock.getHeader()), eq(secondBlock.getBody().getTransactions()), eq(secondBlock.getBody().getOmmers()), any());
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) TransactionLocation(org.hyperledger.besu.ethereum.chain.TransactionLocation) Block(org.hyperledger.besu.ethereum.core.Block) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Test(org.junit.Test)

Example 5 with PrivacyGroupHeadBlockMap

use of org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap in project besu by hyperledger.

the class PrivacyBlockProcessorTest method mustCopyPreviousPrivacyGroupBlockHeadMap.

@Test
public void mustCopyPreviousPrivacyGroupBlockHeadMap() {
    final BlockDataGenerator blockDataGenerator = new BlockDataGenerator();
    final Blockchain blockchain = mock(Blockchain.class);
    final MutableWorldState mutableWorldState = mock(MutableWorldState.class);
    final PrivacyGroupHeadBlockMap expected = new PrivacyGroupHeadBlockMap(Collections.singletonMap(Bytes32.ZERO, Hash.EMPTY));
    final Block firstBlock = blockDataGenerator.block();
    final Block secondBlock = blockDataGenerator.block(BlockDataGenerator.BlockOptions.create().setParentHash(firstBlock.getHash()));
    privacyBlockProcessor.processBlock(blockchain, mutableWorldState, firstBlock);
    privateStateStorage.updater().putPrivacyGroupHeadBlockMap(firstBlock.getHash(), expected).commit();
    privacyBlockProcessor.processBlock(blockchain, mutableWorldState, secondBlock);
    assertThat(privateStateStorage.getPrivacyGroupHeadBlockMap(secondBlock.getHash())).contains(expected);
    verify(blockProcessor).processBlock(eq(blockchain), eq(mutableWorldState), eq(firstBlock.getHeader()), eq(firstBlock.getBody().getTransactions()), eq(firstBlock.getBody().getOmmers()), any());
    verify(blockProcessor).processBlock(eq(blockchain), eq(mutableWorldState), eq(secondBlock.getHeader()), eq(secondBlock.getBody().getTransactions()), eq(secondBlock.getBody().getOmmers()), any());
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) Block(org.hyperledger.besu.ethereum.core.Block) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Test(org.junit.Test)

Aggregations

PrivacyGroupHeadBlockMap (org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap)21 PrivateStateStorage (org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage)8 Test (org.junit.Test)8 PrivateTransactionMetadata (org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata)7 Hash (org.hyperledger.besu.datatypes.Hash)6 PrivateBlockMetadata (org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata)6 Bytes32 (org.apache.tuweni.bytes.Bytes32)5 Block (org.hyperledger.besu.ethereum.core.Block)5 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)4 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)3 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)3 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)3 ArrayList (java.util.ArrayList)2 Bytes (org.apache.tuweni.bytes.Bytes)2 ReceiveResponse (org.hyperledger.besu.enclave.types.ReceiveResponse)2 TransactionLocation (org.hyperledger.besu.ethereum.chain.TransactionLocation)2 Transaction (org.hyperledger.besu.ethereum.core.Transaction)2 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1