-
Notifications
You must be signed in to change notification settings - Fork 881
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
Privacy rpcs through tx handler #243
Conversation
…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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More to come.
...yperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransaction.java
Outdated
Show resolved
Hide resolved
...yperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransaction.java
Outdated
Show resolved
Hide resolved
...er/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivDistributeRawTransaction.java
Outdated
Show resolved
Hide resolved
...yperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java
Outdated
Show resolved
Hide resolved
...edger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivateTransaction.java
Outdated
Show resolved
Hide resolved
...edger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetPrivateTransaction.java
Outdated
Show resolved
Hide resolved
...rledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java
Outdated
Show resolved
Hide resolved
...dger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroupTest.java
Outdated
Show resolved
Hide resolved
...dger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroupTest.java
Outdated
Show resolved
Hide resolved
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>
ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivacyController.java
Outdated
Show resolved
Hide resolved
ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivacyController.java
Outdated
Show resolved
Hide resolved
ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/SendTransactionResponse.java
Show resolved
Hide resolved
...yperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/EeaSendRawTransaction.java
Outdated
Show resolved
Hide resolved
ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivacyController.java
Outdated
Show resolved
Hide resolved
ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivacyController.java
Outdated
Show resolved
Hide resolved
ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivacyController.java
Outdated
Show resolved
Hide resolved
ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivacyController.java
Show resolved
Hide resolved
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: final
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename "DisabledPrivacyRpcMethod"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
...g/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/PrivacySendTransaction.java
Show resolved
Hide resolved
@@ -113,7 +108,7 @@ public JsonRpcResponse getResponse() { | |||
} | |||
} | |||
|
|||
protected interface AfterTransactionValid { | |||
public interface AfterTransactionValid { |
There was a problem hiding this comment.
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....
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: final
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
...yperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivFindPrivacyGroup.java
Show resolved
Hide resolved
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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"...
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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)
ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/SendTransactionResponse.java
Show resolved
Hide resolved
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, |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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))) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
…h Enclave (hyperledger#243) Signed-off-by: Jason Frame <jasonwframe@gmail.com>
…h Enclave (hyperledger#243) Signed-off-by: Jason Frame <jasonwframe@gmail.com> Signed-off-by: edwardmack <ed@edwardmack.com>
`oneOf` fails to match when block txs is empty
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)