Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Added eea_getTransactionCount Json Rpc #1861

Merged
merged 15 commits into from
Aug 26, 2019

Conversation

rain-on
Copy link
Contributor

@rain-on rain-on commented Aug 15, 2019

Exposers a Json Rpc which allows "legacy" users to query for the
nonce of a given address, in a group of private users.

Exposers a Json Rpc which allows "legacy" users to query for the
nonce of a given address, in a group of private users.
@rain-on rain-on requested a review from CjHare August 15, 2019 06:43

public static class EeaGetTransactionCountJsonBody {

final String privateFrom;
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't these be 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.

Private? yes.


public class EeaGetTransactionCount implements JsonRpcMethod {

public static class EeaGetTransactionCountJsonBody {
Copy link
Contributor

Choose a reason for hiding this comment

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

Pattern used in the JsonRpc package has the Json POJO split out into their classes and suffixed with Parameters e.g. tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters, something worth considering?

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.junit.Test;

public class EeaGetTransactionCountTest {
final Address address = Address.fromHexString("55");
Copy link
Contributor

Choose a reason for hiding this comment

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

private modifier?

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.

new EeaGetTransactionCount(new JsonRpcParameter(), enclave, privateTransactionHandler);

final JsonRpcResponse response = method.response(request);
assertThat(response).isInstanceOf(JsonRpcErrorResponse.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you expecting a specific error message here?

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.

new EeaGetTransactionCount(new JsonRpcParameter(), enclave, privateTransactionHandler);

final JsonRpcResponse response = method.response(request);
assertThat(response).isInstanceOf(JsonRpcErrorResponse.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto, is any JsonRpcErrorResponse acceptable? or do you expecting a specific message?

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.apache.logging.log4j.Logger;
import org.bouncycastle.util.Arrays;

public class EeaGetTransactionCount 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.

Think this class should be name PrivGetLegacyTransactionCount

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Talked to Madeline last night - given this capability is really required of Legacy Privacy - it belongs in the Eea namespace, and thus, the spec will need updating.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More to the point - priv_ namespace is geared toward the new Privacy Group - so having "priv" and "legacy" in a name is not a valid combination.

private long determineNonce(final EeaGetTransactionCountJsonBody getTransactionCount)
throws Exception {

final String[] groupMembers =
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps there should be a method on the PrivateTransactionHandler to get the legacy privacy group?

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 couldn't decide if this is something a PrivateTransactionHandler should know about ...

@rain-on rain-on changed the title Added priv_getLegacyTransactionCount Json Rpc Added eea_getTransactionCount Json Rpc Aug 16, 2019
import org.apache.logging.log4j.Logger;
import org.bouncycastle.util.Arrays;

public class LegacyNonceProvider {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this have the Legacy prefix, rather than Eea?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because "Legacy" is the default terminology for things which work with EEA privacy ... (i.e. internally the Privacy is deemed LEGACY or PANTHEON.

this.privateTransactionHandler = privateTransactionHandler;
}

public long determineNonce(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a more narrow exception to throw instead of Exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alas - this is an effect of Encalve throwing Exception ... this behaviour is mimic'd from other Priv Json RPC ...

final long nonce = nonceProvider.determineNonce(privateFrom, privateFor, address);
return new JsonRpcSuccessResponse(request.getId(), Quantity.create(nonce));
} catch (final Exception e) {
LOG.error("Failed to fetch group from Enclave with error " + e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think there is any need for two log statements here. Could just do LOG.error("Failed to fetch group from Enclave", e) and let log4j log the exception nicely?

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.

body = RequestBody.create(mediaType, objectMapper.writeValueAsString(content));
} catch (final JsonProcessingException e) {
final String errorMessage = "Failed to serialise request to json body.";
LOG.error(errorMessage);
Copy link
Contributor

Choose a reason for hiding this comment

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

No need log and throw the exception

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

@@ -107,7 +107,7 @@ private PrivateTransactionProcessor mockPrivateTxProcessor() {

private Enclave brokenMockEnclave() throws Exception {
Enclave mockEnclave = mock(Enclave.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

throws Exception shouldn't be needed now it's throwing the runtime EnclaveException

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 long determineNonce(
final String privateFrom, final String[] privateFor, final Address address) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Think it would have been nice if the Enclave provided a findEeaPrivacyGroup(privateFor, privateFrom) method. Probably not part of this PR though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup - this should probably be Orion.

return new JsonRpcSuccessResponse(request.getId(), Quantity.create(nonce));
} catch (final Exception e) {
LOG.error(e.getMessage(), e);
return new JsonRpcErrorResponse(request.getId(), JsonRpcError.FIND_PRIVACY_GROUP_ERROR);
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks like the wrong error type

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.

final String errorMessage =
String.format(
"Found invalid number of privacy groups (%d), expected 1.", legacyGroups.size());
LOG.error(errorMessage);
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to log and throw, perhaps just throw with the error message. Will be logged in rpc layer

@rain-on rain-on merged commit 313f48b into PegaSysEng:master Aug 26, 2019
@rain-on rain-on deleted the priv_legacygetTransactionCount branch August 26, 2019 03:08
pscott pushed a commit to pscott/pantheon that referenced this pull request Sep 2, 2019
Exposers a Json Rpc which allows "legacy" users to query for the
nonce of a given address, in a group of private users.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants