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

Privacy rpcs through tx handler #243

Merged
merged 36 commits into from
Dec 19, 2019

Conversation

jframe
Copy link
Contributor

@jframe jframe commented Dec 9, 2019

PR description

Change privacy RPCs so they go through the privateTransactionHandler instead of directly to the enclave. This is necessary so that multi-tenancy validation rules can be added and done before the request is made to the enclave.

Fixed Issue(s)

…ad directly through the enclave

Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
@jframe jframe marked this pull request as ready for review December 9, 2019 04:53
@jframe jframe requested review from mark-terry and rain-on December 9, 2019 04:54
Copy link
Contributor

@rain-on rain-on left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More to come.

Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
"/send",
(statusCode, body) -> handleJsonResponse(statusCode, body, SendResponse.class));
}

public ReceiveResponse receive(final ReceiveRequest content) {
public SendResponse sendBesu(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: sendBesu? you're sending Besu somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

public PrivacyGroup createPrivacyGroup(final CreatePrivacyGroupRequest content) {
public PrivacyGroup createPrivacyGroup(
final String[] addresses, final String from, final String name, final String description) {
final CreatePrivacyGroupRequest createPrivacyGroupRequest =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: does this need a "from"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Orion createPrivacyGroup request requires a from

"/createPrivacyGroup",
(statusCode, body) -> handleJsonResponse(statusCode, body, PrivacyGroup.class));
}

public String deletePrivacyGroup(final DeletePrivacyGroupRequest content) {
public String deletePrivacyGroup(final String privacyGroupId, final String from) {
DeletePrivacyGroupRequest deletePrivacyGroupRequest =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: final

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"/deletePrivacyGroup",
(statusCode, body) -> handleJsonResponse(statusCode, body, String.class));
}

public PrivacyGroup[] findPrivacyGroup(final FindPrivacyGroupRequest content) {
public PrivacyGroup[] findPrivacyGroup(final String[] addresses) {
final FindPrivacyGroupRequest findPrivacyGroupRequest = new FindPrivacyGroupRequest(addresses);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: here and elsewhere you can probably name the variable just request or content the extra naming isn't adding value in this context

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


public abstract class PrivacyApiMethod implements JsonRpcMethod {
public class DisabledPrivacyMethod implements JsonRpcMethod {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename "DisabledPrivacyRpcMethod"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -113,7 +108,7 @@ public JsonRpcResponse getResponse() {
}
}

protected interface AfterTransactionValid {
public interface AfterTransactionValid {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could have a @FunctionalInterface
nit: Probably badly named, the class is just ResponseSupplier - which get USED if a Transaction is valid....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. got rid of this and just used a supplier

Signed-off-by: Jason Frame <jasonwframe@gmail.com>
this.enclave = privacyParameters.getEnclave();
public PrivDeletePrivacyGroup(
final PrivacyParameters privacyParameters, final PrivacyController privacyController) {
this.privacyParameters = privacyParameters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the privacy Params are ONLY required for the logging ... can it be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -42,39 +46,30 @@ public String getName() {
}

@Override
public JsonRpcResponse doResponse(final JsonRpcRequestContext requestContext) {
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
PrivateTransaction privateTransaction;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: final

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

super(privacyParameters, privateTransactionHandler, transactionPool);
final TransactionPool transactionPool, final PrivacyController privacyController) {
this.privacyController = privacyController;
this.privacySendTransaction = new PrivacySendTransaction(privacyController, transactionPool);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is a bit weak - i.e. surely this should not need a TransactionPool (given its only distributing)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;

public class PrivGetPrivacyPrecompileAddress extends PrivacyApiMethod {
public class PrivGetPrivacyPrecompileAddress implements JsonRpcMethod {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not your problem - but I wonder if this should have been a "ConstantResponseRpc" - which takes a name and a value .... maybe a more reusable concept.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think there are any other APIs like this that I can see. Hopefully if one is added a ConstantResponseRpc can be added a reused for this and whatever we add.

privacyParameters, protocolSchedule.getChainId(), markerTransactionFactory);

return create(privateTransactionHandler);
return create(privacyController).entrySet().stream()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to imply that all APIs are created, then on a one-by-one basis, they are replaced with "Disabled" ...
spose the nice thing is this class doesn't need to know which APIs exist, so new ones can be added "for free"...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's not quite as efficient but it's much simpler in code and it ensures that all privacy APIs are handled in a uniform way. With the benefit that you just add a new privacy API and the disabling will just work.

return sendResponse.getKey();
final SendResponse sendResponse = sendRequest(privateTransaction);
final String enclaveKey = sendResponse.getKey();
if (privateTransaction.getPrivacyGroupId().isPresent()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we raise a ticket to determine the group directly from the txn - rather than uploading to enclave first?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think would form part of https://jira.hyperledger.org/browse/BESU-156 which will do the validation before sending to the enclave. Perhaps it might need to a seperate ticket though.

@@ -173,4 +178,38 @@ public long getSenderNonce(final Address sender, final String privacyGroupId) {
// private state does not exist
Account.DEFAULT_NONCE);
}

private SendResponse sendRequest(final PrivateTransaction privateTransaction) {
final BytesValueRLPOutput bvrlp = new BytesValueRLPOutput();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should just be an RlpOutput object (newed as a BytesValueRlpOutput) - and probalby needs a nicer name - even its its just rlpOutput

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (privateFor.isEmpty()) {
privateFor.add(BytesValues.asBase64String(privateTransaction.getPrivateFrom()));
}
return enclave.sendLegacy(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can sendLegacy just be "send" - the params should identify what's happening (then we can hide legacy/pantheon style from the API)

Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: Jason Frame <jasonwframe@gmail.com>
private final String from;
private final String name;
private final String description;

@JsonCreator
public CreatePrivacyGroupRequest(
@JsonProperty("addresses") final String[] addresses,
@JsonProperty("addresses") final List<String> addresses,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work? I'm assuming we used an array originally because of some reason ..? (I prefer the list ... just want to make sure)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jackson will automatically serialise/deserialise lists for us. And some of the privacy requests were using lists as well.

public void invalidTransactionIsSentToTransactionPool() {
when(privateTxHandler.sendTransaction(any(PrivateTransaction.class)))
public void invalidTransactionIsNotSentToTransactionPool() {
when(privateController.sendTransaction(any(PrivateTransaction.class)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit/YMMV: private or privacyController?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that should be privacyController. done

Signed-off-by: Jason Frame <jasonwframe@gmail.com>
@jframe jframe merged commit a0e8714 into hyperledger:master Dec 19, 2019
@jframe jframe deleted the privacy_rpcs_through_tx_handler branch December 19, 2019 00:47
edwardmack pushed a commit to ChainSafe/besu that referenced this pull request Feb 4, 2020
…h Enclave (hyperledger#243)

Signed-off-by: Jason Frame <jasonwframe@gmail.com>
edwardmack pushed a commit to ChainSafe/besu that referenced this pull request Feb 4, 2020
…h Enclave (hyperledger#243)

Signed-off-by: Jason Frame <jasonwframe@gmail.com>
Signed-off-by: edwardmack <ed@edwardmack.com>
siladu pushed a commit to siladu/besu that referenced this pull request Oct 28, 2024
`oneOf` fails to match when block txs is empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants