add JSON-RPC method to call /storeraw on GoQuorum enclave (#1859)

* added GoQuorumStoreRawPrivateTransaction that can send a payload to Tessera for storing

Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/1888/head
Sally MacFarlane 4 years ago committed by GitHub
parent a30d8accb1
commit 1de067b473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      enclave/src/integration-test/java/org/hyperledger/besu/enclave/GoQuorumEnclaveTest.java
  2. 11
      enclave/src/main/java/org/hyperledger/besu/enclave/GoQuorumEnclave.java
  3. 29
      enclave/src/main/java/org/hyperledger/besu/enclave/types/GoQuorumStoreRawRequest.java
  4. 31
      enclave/src/main/java/org/hyperledger/besu/enclave/types/StoreRawResponse.java
  5. 1
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java
  6. 65
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/GoQuorumStoreRawPrivateTransaction.java
  7. 4
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/GoQuorumJsonRpcPrivacyMethods.java
  8. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java

@ -22,6 +22,7 @@ import static org.mockito.Mockito.when;
import org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse; import org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse;
import org.hyperledger.besu.enclave.types.SendResponse; import org.hyperledger.besu.enclave.types.SendResponse;
import org.hyperledger.besu.enclave.types.StoreRawResponse;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -95,6 +96,17 @@ public class GoQuorumEnclaveTest {
assertThat(sr.getKey()).isEqualTo(KEY); assertThat(sr.getKey()).isEqualTo(KEY);
} }
@Test
public void storeRawTransaction() {
when(vertxTransmitter.post(any(), any(), ArgumentMatchers.contains("/storeraw"), any()))
.thenReturn(new StoreRawResponse(KEY));
final StoreRawResponse sr =
enclave.storeRaw(
"tQEmN0d/xXJZs5OMgl8QVBIyYxu1XubAKehsSYbcOjbxai+QJQpEOs6ghrYAZizLtnM4EJdMyVeVrxO3cA9JJA==");
assertThat(sr.getKey()).isEqualTo(KEY);
}
@Test @Test
public void upcheckReturnsFalseIfNoResponseReceived() throws URISyntaxException { public void upcheckReturnsFalseIfNoResponseReceived() throws URISyntaxException {
final Vertx vertx = Vertx.vertx(); final Vertx vertx = Vertx.vertx();

@ -18,8 +18,10 @@ import org.hyperledger.besu.enclave.RequestTransmitter.ResponseBodyHandler;
import org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse; import org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse;
import org.hyperledger.besu.enclave.types.GoQuorumSendRequest; import org.hyperledger.besu.enclave.types.GoQuorumSendRequest;
import org.hyperledger.besu.enclave.types.GoQuorumSendSignedRequest; import org.hyperledger.besu.enclave.types.GoQuorumSendSignedRequest;
import org.hyperledger.besu.enclave.types.GoQuorumStoreRawRequest;
import org.hyperledger.besu.enclave.types.ReceiveRequest; import org.hyperledger.besu.enclave.types.ReceiveRequest;
import org.hyperledger.besu.enclave.types.SendResponse; import org.hyperledger.besu.enclave.types.SendResponse;
import org.hyperledger.besu.enclave.types.StoreRawResponse;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -69,6 +71,15 @@ public class GoQuorumEnclave {
(statusCode, body) -> handleJsonResponse(statusCode, body, SendResponse.class, 201)); (statusCode, body) -> handleJsonResponse(statusCode, body, SendResponse.class, 201));
} }
public StoreRawResponse storeRaw(final String payload) {
final GoQuorumStoreRawRequest request = new GoQuorumStoreRawRequest(payload);
return post(
JSON,
request,
"/storeraw",
(statusCode, body) -> handleJsonResponse(statusCode, body, StoreRawResponse.class, 200));
}
public GoQuorumReceiveResponse receive(final String payloadKey) { public GoQuorumReceiveResponse receive(final String payloadKey) {
final ReceiveRequest request = new ReceiveRequest(payloadKey); final ReceiveRequest request = new ReceiveRequest(payloadKey);
return get( return get(

@ -0,0 +1,29 @@
/*
* Copyright ConsenSys AG.
*
* 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.enclave.types;
import com.fasterxml.jackson.annotation.JsonProperty;
public class GoQuorumStoreRawRequest {
private final String payload;
public GoQuorumStoreRawRequest(@JsonProperty(value = "payload") final String payload) {
this.payload = payload;
}
public String getPayload() {
return payload;
}
}

@ -0,0 +1,31 @@
/*
* Copyright ConsenSys AG.
*
* 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.enclave.types;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
public class StoreRawResponse {
private final String key;
@JsonCreator
public StoreRawResponse(@JsonProperty("key") final String key) {
this.key = key;
}
public String getKey() {
return key;
}
}

@ -42,6 +42,7 @@ public enum RpcMethod {
DEBUG_TRACE_TRANSACTION("debug_traceTransaction"), DEBUG_TRACE_TRANSACTION("debug_traceTransaction"),
DEBUG_BATCH_RAW_TRANSACTION("debug_batchSendRawTransaction"), DEBUG_BATCH_RAW_TRANSACTION("debug_batchSendRawTransaction"),
DEBUG_GET_BAD_BLOCKS("debug_getBadBlocks"), DEBUG_GET_BAD_BLOCKS("debug_getBadBlocks"),
GOQUORUM_STORE_RAW("goquorum_storeRaw"),
PRIV_CALL("priv_call"), PRIV_CALL("priv_call"),
PRIV_GET_PRIVATE_TRANSACTION("priv_getPrivateTransaction"), PRIV_GET_PRIVATE_TRANSACTION("priv_getPrivateTransaction"),
PRIV_GET_TRANSACTION_COUNT("priv_getTransactionCount"), PRIV_GET_TRANSACTION_COUNT("priv_getTransactionCount"),

@ -0,0 +1,65 @@
/*
* Copyright ConsenSys AG.
*
* 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.ethereum.api.jsonrpc.internal.privacy.methods.priv;
import static org.apache.logging.log4j.LogManager.getLogger;
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcEnclaveErrorConverter.convertEnclaveInvalidReason;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.DECODE_ERROR;
import org.hyperledger.besu.enclave.GoQuorumEnclave;
import org.hyperledger.besu.enclave.types.StoreRawResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
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.rlp.RLPException;
import org.apache.logging.log4j.Logger;
public class GoQuorumStoreRawPrivateTransaction implements JsonRpcMethod {
private static final Logger LOG = getLogger();
private final GoQuorumEnclave enclave;
public GoQuorumStoreRawPrivateTransaction(final GoQuorumEnclave enclave) {
this.enclave = enclave;
}
@Override
public String getName() {
return RpcMethod.GOQUORUM_STORE_RAW.getMethodName();
}
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final Object id = requestContext.getRequest().getId();
final String payload = requestContext.getRequiredParameter(0, String.class);
try {
LOG.debug("sending payload " + payload);
final StoreRawResponse storeRawResponse = enclave.storeRaw(payload);
String enclaveLookupId = storeRawResponse.getKey();
LOG.debug("got key from GoQuorum enclave " + enclaveLookupId);
return new JsonRpcSuccessResponse(id, enclaveLookupId);
} catch (final IllegalArgumentException | RLPException e) {
LOG.error(e);
return new JsonRpcErrorResponse(id, DECODE_ERROR);
} catch (final Exception e) {
return new JsonRpcErrorResponse(id, convertEnclaveInvalidReason(e.getMessage()));
}
}
}

@ -19,6 +19,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.EnclavePublicKeyProvider; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.EnclavePublicKeyProvider;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.eea.GoQuorumSendRawPrivateTransaction; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.eea.GoQuorumSendRawPrivateTransaction;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.GoQuorumStoreRawPrivateTransaction;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries; import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.core.GoQuorumPrivacyParameters; import org.hyperledger.besu.ethereum.core.GoQuorumPrivacyParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.PrivacyParameters;
@ -50,7 +51,8 @@ public class GoQuorumJsonRpcPrivacyMethods extends PrivacyApiGroupJsonRpcMethods
if (goQuorumParameters.isPresent()) { if (goQuorumParameters.isPresent()) {
return mapOf( return mapOf(
new GoQuorumSendRawPrivateTransaction( new GoQuorumSendRawPrivateTransaction(
goQuorumParameters.get().enclave(), getTransactionPool(), enclavePublicKeyProvider)); goQuorumParameters.get().enclave(), getTransactionPool(), enclavePublicKeyProvider),
new GoQuorumStoreRawPrivateTransaction(goQuorumParameters.get().enclave()));
} else { } else {
return Collections.emptyMap(); return Collections.emptyMap();
} }

@ -150,12 +150,14 @@ public abstract class PrivacyApiGroupJsonRpcMethods extends ApiGroupJsonRpcMetho
private JsonRpcMethod createPrivacyMethod( private JsonRpcMethod createPrivacyMethod(
final PrivacyParameters privacyParameters, final JsonRpcMethod rpcMethod) { final PrivacyParameters privacyParameters, final JsonRpcMethod rpcMethod) {
if (rpcMethod.getName().equals(RpcMethod.ETH_SEND_RAW_PRIVATE_TRANSACTION.getMethodName())) { final String methodName = rpcMethod.getName();
if (methodName.equals(RpcMethod.ETH_SEND_RAW_PRIVATE_TRANSACTION.getMethodName())
|| methodName.equals(RpcMethod.GOQUORUM_STORE_RAW.getMethodName())) {
return rpcMethod; return rpcMethod;
} else if (privacyParameters.isEnabled() && privacyParameters.isMultiTenancyEnabled()) { } else if (privacyParameters.isEnabled() && privacyParameters.isMultiTenancyEnabled()) {
return new MultiTenancyRpcMethodDecorator(rpcMethod); return new MultiTenancyRpcMethodDecorator(rpcMethod);
} else if (!privacyParameters.isEnabled()) { } else if (!privacyParameters.isEnabled()) {
return new DisabledPrivacyRpcMethod(rpcMethod.getName()); return new DisabledPrivacyRpcMethod(methodName);
} else { } else {
return rpcMethod; return rpcMethod;
} }

Loading…
Cancel
Save