Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracing private transactions feature #6161

Merged
merged 21 commits into from
Aug 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added acceptance test
Signed-off-by: Nischal Sharma <nischal@web3labs.com>
NickSneo committed Aug 1, 2024
commit 2a589dc05b558082c1468cfdb5bef9ae09007802
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
package org.hyperledger.besu.tests.acceptance.dsl.privacy.transaction;

import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.privacy.PrivacyGroupUtil;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.condition.PrivGetTransactionReceiptTransaction;
@@ -25,6 +26,7 @@
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivGetCodeTransaction;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivGetLogsTransaction;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivGetTransaction;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivTraceTransaction;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.filter.PrivGetFilterChangesTransaction;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.filter.PrivGetFilterLogsTransaction;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.filter.PrivNewFilterTransaction;
@@ -115,6 +117,11 @@ public PrivGetLogsTransaction privGetLogs(
return new PrivGetLogsTransaction(privacyGroupId, filterParameter);
}

public PrivTraceTransaction privTraceTrasnaction(
NickSneo marked this conversation as resolved.
Show resolved Hide resolved
final String privacyGroupId, final Hash transactionhash) {
return new PrivTraceTransaction(privacyGroupId, transactionhash);
}

public RemoveFromFlexiblePrivacyGroupTransaction removeFromPrivacyGroup(
final String privacyGroupId,
final String remover,
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright contributors to Hyperledger Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy;

import static org.assertj.core.api.Assertions.assertThat;

import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction;

import java.io.IOException;

public class PrivTraceTransaction implements Transaction<String> {

private final String privacyGroupId;
private final Hash transactionHash;

public PrivTraceTransaction(final String privacyGroupId, final Hash transactionHash) {
this.privacyGroupId = privacyGroupId;
this.transactionHash = transactionHash;
}

@Override
public String execute(final NodeRequests node) {
try {
final PrivacyRequestFactory.PrivTraceTransaction response =
node.privacy().privTraceTransaction(privacyGroupId, transactionHash).send();

assertThat(response).as("check response is not null").isNotNull();
assertThat(response.getResult()).as("check result in response isn't null").isNotNull();
NickSneo marked this conversation as resolved.
Show resolved Hide resolved

return response.getRawResponse();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -109,6 +109,8 @@ public static class GetPrivacyPrecompileAddressResponse extends Response<Address
public static class GetPrivateTransactionResponse
extends Response<PrivateTransactionGroupResponse> {}

public static class PrivTraceTransaction extends Response<String> {}

public static class CreatePrivacyGroupResponse extends Response<String> {}

public static class DeletePrivacyGroupResponse extends Response<String> {}
@@ -455,6 +457,16 @@ public Request<?, EthLog> privGetLogs(
"priv_getLogs", Arrays.asList(privacyGroupId, filterParameter), web3jService, EthLog.class);
}

public Request<?, PrivTraceTransaction> privTraceTransaction(
final String privacyGroupId, final Hash transactionHash) {

return new Request<>(
"priv_traceTransaction",
Arrays.asList(privacyGroupId, transactionHash),
web3jService,
PrivTraceTransaction.class);
}

public Request<?, EthFilter> privNewFilter(
final String privacyGroupId, final LogFilterJsonParameter filterParameter) {
return new Request<>(
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright contributors to Hyperledger Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.tests.acceptance.privacy;

import static org.assertj.core.api.Assertions.assertThat;
import static org.web3j.utils.Restriction.UNRESTRICTED;

import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.ParameterizedEnclaveTestBase;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode;
import org.hyperledger.besu.tests.acceptance.dsl.privacy.account.PrivacyAccountResolver;
import org.hyperledger.besu.tests.web3j.generated.SimpleStorage;
import org.hyperledger.enclave.testutil.EnclaveEncryptorType;
import org.hyperledger.enclave.testutil.EnclaveType;

import java.io.IOException;
import java.math.BigInteger;
import java.util.Optional;

import org.junit.Test;
import org.web3j.utils.Restriction;

public class PrivTraceTransactionAcceptanceTest extends ParameterizedEnclaveTestBase {

private final PrivacyNode node;

public PrivTraceTransactionAcceptanceTest(
final Restriction restriction,
final EnclaveType enclaveType,
final EnclaveEncryptorType enclaveEncryptorType)
throws IOException {

super(restriction, enclaveType, enclaveEncryptorType);

node =
privacyBesu.createPrivateTransactionEnabledMinerNode(
restriction + "-node",
PrivacyAccountResolver.ALICE.resolve(enclaveEncryptorType),
enclaveType,
Optional.empty(),
false,
false,
restriction == UNRESTRICTED);

privacyCluster.start(node);
}

@Test
public void getTransactionTrace() {
final String privacyGroupId = createPrivacyGroup();
final SimpleStorage simpleStorageContract = deploySimpleStorageContract(privacyGroupId);

/*
Updating the contract value
*/
Hash transactionHash = doTransaction(privacyGroupId, simpleStorageContract, 1);

final String result =
node.execute(privacyTransactions.privTraceTrasnaction(privacyGroupId, transactionHash));
NickSneo marked this conversation as resolved.
Show resolved Hide resolved

assertThat(result).isNotNull();
System.out.println("privTransactionTrace = " + result);
}

NickSneo marked this conversation as resolved.
Show resolved Hide resolved
private String createPrivacyGroup() {
return node.execute(createPrivacyGroup("myGroupName", "my group description", node));
}

private SimpleStorage deploySimpleStorageContract(final String privacyGroupId) {
final SimpleStorage simpleStorage =
node.execute(
privateContractTransactions.createSmartContractWithPrivacyGroupId(
SimpleStorage.class,
node.getTransactionSigningKey(),
restriction,
node.getEnclaveKey(),
privacyGroupId));

privateContractVerifier
.validPrivateContractDeployed(
simpleStorage.getContractAddress(), node.getAddress().toString())
.verify(simpleStorage);

return simpleStorage;
}

private Hash doTransaction(
final String privacyGroupId, final SimpleStorage simpleStorageContract, final int value) {
final String transactionHash =
node.execute(
privateContractTransactions.callSmartContractWithPrivacyGroupId(
simpleStorageContract.getContractAddress(),
simpleStorageContract.set(BigInteger.valueOf(value)).encodeFunctionCall(),
node.getTransactionSigningKey(),
restriction,
node.getEnclaveKey(),
privacyGroupId));

return Hash.fromHexString(transactionHash);
}
}