Search in sources :

Example 1 with PrivateTransactionReceipt

use of org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt in project besu by hyperledger.

the class PrivGetTransactionReceipt method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    LOG.trace("Executing {}", RpcMethod.PRIV_GET_TRANSACTION_RECEIPT.getMethodName());
    final Hash pmtTransactionHash = requestContext.getRequiredParameter(0, Hash.class);
    final String enclaveKey = privacyIdProvider.getPrivacyUserId(requestContext.getUser());
    final ExecutedPrivateTransaction privateTransaction;
    try {
        privateTransaction = privacyController.findPrivateTransactionByPmtHash(pmtTransactionHash, enclaveKey).orElse(null);
    } catch (final EnclaveClientException e) {
        return handleEnclaveException(requestContext, e);
    }
    if (privateTransaction == null) {
        return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), null);
    }
    final String contractAddress = calculateContractAddress(privateTransaction);
    LOG.trace("Calculated contractAddress: {}", contractAddress);
    final Hash blockHash = privateTransaction.getBlockHash();
    final PrivateTransactionReceipt privateTransactionReceipt = privateStateStorage.getTransactionReceipt(blockHash, pmtTransactionHash).or(() -> findPrivateReceiptByPrivateTxHash(privateStateStorage, blockHash, privateTransaction)).orElse(PrivateTransactionReceipt.FAILED);
    LOG.trace("Processed private transaction receipt");
    final PrivateTransactionReceiptResult result = buildPrivateTransactionReceiptResult(privateTransaction, privateTransactionReceipt);
    LOG.trace("Created Private Transaction Receipt Result from given Transaction Hash {}", privateTransaction.getPmtHash());
    return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), result);
}
Also used : PrivateTransactionReceiptResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult) PrivateTransactionReceipt(org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) Hash(org.hyperledger.besu.datatypes.Hash) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) EnclaveClientException(org.hyperledger.besu.enclave.EnclaveClientException)

Example 2 with PrivateTransactionReceipt

use of org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt in project besu by hyperledger.

the class FlexiblePrivacyPrecompiledContract method computePrecompile.

@Nonnull
@Override
public PrecompileContractResult computePrecompile(final Bytes input, @Nonnull final MessageFrame messageFrame) {
    if (skipContractExecution(messageFrame)) {
        return NO_RESULT;
    }
    if (input == null || (input.size() != 32 && input.size() != 64)) {
        LOG.error("Can not fetch private transaction payload with key of invalid length {}", input);
        return NO_RESULT;
    }
    final Hash pmtHash = messageFrame.getContextVariable(KEY_TRANSACTION_HASH);
    final String key = input.slice(0, 32).toBase64String();
    final ReceiveResponse receiveResponse;
    try {
        receiveResponse = getReceiveResponse(key);
    } catch (final EnclaveClientException e) {
        LOG.debug("Can not fetch private transaction payload with key {}", key, e);
        return NO_RESULT;
    }
    final BytesValueRLPInput bytesValueRLPInput = new BytesValueRLPInput(Bytes.wrap(Base64.getDecoder().decode(receiveResponse.getPayload())), false);
    final VersionedPrivateTransaction versionedPrivateTransaction = VersionedPrivateTransaction.readFrom(bytesValueRLPInput);
    final PrivateTransaction privateTransaction = versionedPrivateTransaction.getPrivateTransaction();
    final Bytes privateFrom = privateTransaction.getPrivateFrom();
    if (!privateFromMatchesSenderKey(privateFrom, receiveResponse.getSenderKey())) {
        return NO_RESULT;
    }
    final Optional<Bytes> maybeGroupId = privateTransaction.getPrivacyGroupId();
    if (maybeGroupId.isEmpty()) {
        return NO_RESULT;
    }
    final Bytes32 privacyGroupId = Bytes32.wrap(maybeGroupId.get());
    LOG.debug("Processing private transaction {} in privacy group {}", pmtHash, privacyGroupId);
    final ProcessableBlockHeader currentBlockHeader = (ProcessableBlockHeader) messageFrame.getBlockValues();
    final PrivateMetadataUpdater privateMetadataUpdater = messageFrame.getContextVariable(KEY_PRIVATE_METADATA_UPDATER);
    final Hash lastRootHash = privateStateRootResolver.resolveLastStateRoot(privacyGroupId, privateMetadataUpdater);
    final MutableWorldState disposablePrivateState = privateWorldStateArchive.getMutable(fromPlugin(lastRootHash), null).get();
    final WorldUpdater privateWorldStateUpdater = disposablePrivateState.updater();
    maybeApplyGenesisToPrivateWorldState(lastRootHash, disposablePrivateState, privateWorldStateUpdater, privacyGroupId, currentBlockHeader.getNumber());
    if (!canExecute(messageFrame, currentBlockHeader, privateTransaction, versionedPrivateTransaction.getVersion(), privacyGroupId, disposablePrivateState, privateWorldStateUpdater, privateFrom)) {
        return NO_RESULT;
    }
    final TransactionProcessingResult result = processPrivateTransaction(messageFrame, privateTransaction, privacyGroupId, privateWorldStateUpdater);
    if (result.isInvalid() || !result.isSuccessful()) {
        LOG.error("Failed to process private transaction {}: {}", pmtHash, result.getValidationResult().getErrorMessage());
        privateMetadataUpdater.putTransactionReceipt(pmtHash, new PrivateTransactionReceipt(result));
        return NO_RESULT;
    }
    sendParticipantRemovedEvent(privateTransaction);
    if (messageFrame.getContextVariable(KEY_IS_PERSISTING_PRIVATE_STATE, false)) {
        privateWorldStateUpdater.commit();
        disposablePrivateState.persist(null);
        storePrivateMetadata(pmtHash, privacyGroupId, disposablePrivateState, privateMetadataUpdater, result);
    }
    return new PrecompileContractResult(result.getOutput(), true, MessageFrame.State.CODE_EXECUTING, Optional.empty());
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) VersionedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.VersionedPrivateTransaction) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) ReceiveResponse(org.hyperledger.besu.enclave.types.ReceiveResponse) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) PrivateTransactionReceipt(org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt) Hash(org.hyperledger.besu.plugin.data.Hash) VersionedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.VersionedPrivateTransaction) Bytes32(org.apache.tuweni.bytes.Bytes32) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) Bytes(org.apache.tuweni.bytes.Bytes) ProcessableBlockHeader(org.hyperledger.besu.ethereum.core.ProcessableBlockHeader) EnclaveClientException(org.hyperledger.besu.enclave.EnclaveClientException) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) PrivateMetadataUpdater(org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater) Nonnull(javax.annotation.Nonnull)

Example 3 with PrivateTransactionReceipt

use of org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt 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 4 with PrivateTransactionReceipt

use of org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt in project besu by hyperledger.

the class PrivGetTransactionReceiptTest method transactionReceiptContainsRevertReasonWhenInvalidTransactionOccurs.

@Test
public void transactionReceiptContainsRevertReasonWhenInvalidTransactionOccurs() {
    final Transaction pmt = privateMarkerTransaction();
    final PrivateTransaction privateTransaction = privateTransactionBesu();
    final ExecutedPrivateTransaction executedPrivateTransaction = createExecutedPrivateTransaction(pmt, privateTransaction);
    when(privacyController.findPrivateTransactionByPmtHash(eq(pmt.getHash()), any())).thenReturn(Optional.of(executedPrivateTransaction));
    final PrivateTransactionReceipt privateTransactionReceiptWithRevertReason = new PrivateTransactionReceipt(1, Collections.emptyList(), Bytes.EMPTY, Optional.of(Bytes.wrap(new byte[] { (byte) 0x01 })));
    when(privateStateStorage.getTransactionReceipt(any(Bytes32.class), any(Bytes32.class))).thenReturn(Optional.of(privateTransactionReceiptWithRevertReason));
    final JsonRpcRequestContext request = requestContext(pmt.getHash());
    final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) privGetTransactionReceipt.response(request);
    final PrivateTransactionReceiptResult result = (PrivateTransactionReceiptResult) response.getResult();
    assertThat(result.getRevertReason()).isEqualTo("0x01");
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) PrivateTransactionReceiptResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult) PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) PrivateTransactionDataFixture.privateMarkerTransaction(org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture.privateMarkerTransaction) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) Transaction(org.hyperledger.besu.ethereum.core.Transaction) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) PrivateTransactionReceipt(org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.Test)

Example 5 with PrivateTransactionReceipt

use of org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt in project besu by hyperledger.

the class PrivGetTransactionReceiptTest method setUp.

@Before
public void setUp() {
    final PrivateTransactionReceipt receipt = new PrivateTransactionReceipt(1, Collections.emptyList(), Bytes.EMPTY, Optional.empty());
    when(privateStateStorage.getTransactionReceipt(any(Bytes32.class), any(Bytes32.class))).thenReturn(Optional.of(receipt));
    privGetTransactionReceipt = new PrivGetTransactionReceipt(privateStateStorage, privacyController, privacyIdProvider);
}
Also used : PrivateTransactionReceipt(org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt) Bytes32(org.apache.tuweni.bytes.Bytes32) Before(org.junit.Before)

Aggregations

PrivateTransactionReceipt (org.hyperledger.besu.ethereum.privacy.PrivateTransactionReceipt)8 Bytes32 (org.apache.tuweni.bytes.Bytes32)5 PrivateTransaction (org.hyperledger.besu.ethereum.privacy.PrivateTransaction)4 Nonnull (javax.annotation.Nonnull)3 EnclaveClientException (org.hyperledger.besu.enclave.EnclaveClientException)3 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)3 PrivateMetadataUpdater (org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater)3 TransactionProcessingResult (org.hyperledger.besu.ethereum.processing.TransactionProcessingResult)3 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)3 Bytes (org.apache.tuweni.bytes.Bytes)2 Hash (org.hyperledger.besu.datatypes.Hash)2 ReceiveResponse (org.hyperledger.besu.enclave.types.ReceiveResponse)2 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)2 PrivateTransactionReceiptResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult)2 ExecutedPrivateTransaction (org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction)2 PrivateTransactionMetadata (org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata)2 BytesValueRLPInput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput)2 Hash (org.hyperledger.besu.plugin.data.Hash)2 EnclaveIOException (org.hyperledger.besu.enclave.EnclaveIOException)1 EnclaveServerException (org.hyperledger.besu.enclave.EnclaveServerException)1