Search in sources :

Example 1 with PrivateTransactionMetadata

use of org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata 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 PrivateTransactionMetadata

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

the class PrivateMetadataUpdaterTest method addingMetadataSuccessfull.

@Test
public void addingMetadataSuccessfull() {
    when(blockHeader.getHash()).thenReturn(hashBlockOne);
    pmtHash = Hash.ZERO;
    final PrivateTransactionMetadata expected = new PrivateTransactionMetadata(pmtHash, stateRoot);
    updater.addPrivateTransactionMetadata(privacyGroupId, expected);
    updater.commit();
    final Optional<PrivateBlockMetadata> privateBlockMetadata = privateStateStorage.getPrivateBlockMetadata(hashBlockOne, privacyGroupId);
    assertThat(privateBlockMetadata.get().getLatestStateRoot().get()).isEqualTo(stateRoot);
}
Also used : PrivateTransactionMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata) PrivateBlockMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata) Test(org.junit.Test)

Example 3 with PrivateTransactionMetadata

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

the class PrivacyQueriesTest method matchingLogsReturnsAllLogsThatMatchQuery.

@Test
public void matchingLogsReturnsAllLogsThatMatchQuery() {
    final BlockHeader blockHeader = new BlockHeaderTestFixture().buildHeader();
    final Hash blockHash = blockHeader.getHash();
    final LogTopic matchingTopic = LogTopic.of(Bytes32.random());
    final LogsQuery query = new LogsQuery.Builder().topics(List.of(List.of(matchingTopic))).build();
    final List<PrivateTransactionMetadata> transactionMetadataList = generatePrivateTransactionMetadataList(NUM_OF_TX_RECEIPTS);
    when(blockchainQueries.getBlockHeaderByHash(blockHash)).thenReturn(Optional.of(blockHeader));
    when(blockchainQueries.blockIsOnCanonicalChain(blockHash)).thenReturn(true);
    when(privateWorldStateReader.getPrivateTransactionMetadataList(PRIVACY_GROUP_ID, blockHash)).thenReturn(transactionMetadataList);
    mockBlockchainWithPMTs(blockHeader, transactionMetadataList);
    mockReceiptsWithLogsAndTopics(blockHash, transactionMetadataList, matchingTopic);
    final List<LogWithMetadata> logs = privacyQueries.matchingLogs(PRIVACY_GROUP_ID, blockHash, query);
    assertThat(logs).hasSize(transactionMetadataList.size());
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) LogWithMetadata(org.hyperledger.besu.ethereum.core.LogWithMetadata) PrivateTransactionMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Hash(org.hyperledger.besu.datatypes.Hash) LogTopic(org.hyperledger.besu.evm.log.LogTopic) Test(org.junit.Test)

Example 4 with PrivateTransactionMetadata

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

the class PrivacyPrecompiledContract method storePrivateMetadata.

void storePrivateMetadata(final org.hyperledger.besu.plugin.data.Hash commitmentHash, final Bytes32 privacyGroupId, final MutableWorldState disposablePrivateState, final PrivateMetadataUpdater privateMetadataUpdater, final TransactionProcessingResult result) {
    final int txStatus = result.getStatus() == TransactionProcessingResult.Status.SUCCESSFUL ? 1 : 0;
    final PrivateTransactionReceipt privateTransactionReceipt = new PrivateTransactionReceipt(txStatus, result.getLogs(), result.getOutput(), result.getRevertReason());
    privateMetadataUpdater.putTransactionReceipt(commitmentHash, privateTransactionReceipt);
    privateMetadataUpdater.updatePrivacyGroupHeadBlockMap(privacyGroupId);
    privateMetadataUpdater.addPrivateTransactionMetadata(privacyGroupId, new PrivateTransactionMetadata(fromPlugin(commitmentHash), disposablePrivateState.rootHash()));
}
Also used : PrivateTransactionReceipt(org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt) PrivateTransactionMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata)

Example 5 with PrivateTransactionMetadata

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

the class PrivateTransactionWithMetadata method readFrom.

public static PrivateTransactionWithMetadata readFrom(final RLPInput input) throws RLPException {
    input.enterList();
    final PrivateTransaction privateTransaction = PrivateTransaction.readFrom(input.readAsRlp());
    final PrivateTransactionMetadata privateTransactionMetadata = PrivateTransactionMetadata.readFrom(input.readAsRlp());
    input.leaveList();
    return new PrivateTransactionWithMetadata(privateTransaction, privateTransactionMetadata);
}
Also used : PrivateTransactionMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata)

Aggregations

PrivateTransactionMetadata (org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata)18 PrivateBlockMetadata (org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata)8 Test (org.junit.Test)8 Hash (org.hyperledger.besu.datatypes.Hash)7 PrivacyGroupHeadBlockMap (org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap)7 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)4 PrivateStateStorage (org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage)4 BlockHeaderTestFixture (org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture)3 LogWithMetadata (org.hyperledger.besu.ethereum.core.LogWithMetadata)3 LogTopic (org.hyperledger.besu.evm.log.LogTopic)3 ArrayList (java.util.ArrayList)2 ReceiveResponse (org.hyperledger.besu.enclave.types.ReceiveResponse)2 Transaction (org.hyperledger.besu.ethereum.core.Transaction)2 HashMap (java.util.HashMap)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 SendResponse (org.hyperledger.besu.enclave.types.SendResponse)1 TransactionLocation (org.hyperledger.besu.ethereum.chain.TransactionLocation)1 PrivateTransactionDataFixture.generatePrivateBlockMetadata (org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture.generatePrivateBlockMetadata)1 PrivateTransactionReceipt (org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt)1