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