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

Implemented priv_getLogs #686

Merged
merged 7 commits into from Apr 14, 2020

Conversation

lucassaldanha
Copy link
Member

@lucassaldanha lucassaldanha commented Apr 8, 2020

Implemented priv_getLogs. This JSON-RPC method is similar to eth_getLogs, but used to read logs from private transaction receipts.

Closes #628

@lucassaldanha lucassaldanha force-pushed the priv_getLogs branch 2 times, most recently from 4af9d1c to 9a59768 Compare April 8, 2020 22:52
Signed-off-by: Lucas Saldanha <lucas.saldanha@consensys.net>
Signed-off-by: Lucas Saldanha <lucas.saldanha@consensys.net>
@@ -73,6 +73,14 @@ public Hash getBlockhash() {
return blockhash;
}

public boolean isValid() {
if (!getFromBlock().isLatest() && !getToBlock().isLatest() && getBlockhash() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The filter parameters are a bit confusing. I understand that one of them has to be set, but what takes precedence if a from/to is set and the hash as well? Should that fail?

Copy link
Member Author

Choose a reason for hiding this comment

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

The rules are confusing. Basically, if from/to aren't latest, you can't specify the blockhash.
To be frank, I think we have a bug in this validation. When I compare with the JSON-RPC spec.

The spec says that you can't use fromBlock/toBlock with blockhash at all.

I've talked to Madeline about it and she will raise a JI to review and fix this behaviour.

We are using the exact same logic as eth_getLogs. That's why we decided to keep the same behaviour until we review it. And, if we need to change anything, we change in both methods in the future.

return Collections.emptyList();
}

final List<PrivateTransactionMetadata> privateTransactionMetadatas =
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't you just call it "privateTransactionMetadataList"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

final List<PrivateTransactionMetadata> privateTransactionMetadatas =
privateWorldStateReader.getPrivateTransactionsMetadata(privacyGroupId, blockHash);

final List<PrivateTransactionReceipt> privateTransactionReceipts =
Copy link
Contributor

Choose a reason for hiding this comment

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

privateTransactionReceiptList?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

public void privacyGroupIdIsRequired() {
final JsonRpcRequestContext request = privGetLogRequest(null, mock(FilterParameter.class));

final Throwable thrown = catchThrowable(() -> method.response(request));
Copy link
Contributor

Choose a reason for hiding this comment

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

You should just use assertThatThrownBy() ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Duh! I always forget about it! Done!

public void filterParameterIsRequired() {
final JsonRpcRequestContext request = privGetLogRequest(PRIVACY_GROUP_ID, null);

final Throwable thrown = catchThrowable(() -> method.response(request));
Copy link
Contributor

Choose a reason for hiding this comment

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

s.a.

privGetLogRequestWithUser(PRIVACY_GROUP_ID, filterParameter, user);
final Throwable thrown = catchThrowable(() -> method.response(request));

assertThat(thrown).isInstanceOf(MultiTenancyValidationException.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

assertThatThrownBy?

@@ -236,7 +236,8 @@ private void verifyPrivateFromMatchesEnclavePublicKey(
}
}

private void verifyPrivacyGroupContainsEnclavePublicKey(
@Override
public void verifyPrivacyGroupContainsEnclavePublicKey(
final String privacyGroupId, final String enclavePublicKey) {
final PrivacyGroup privacyGroup = enclave.retrievePrivacyGroup(privacyGroupId);
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 sure that the privacyGroup cannot be null?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, if it is null you won't find any matching privacy group, right?

And in the json-rpc method we are make the privacy group id a required parameter. I don't think we need to be extra defensive here in this internal class.

@@ -46,4 +54,20 @@ public PrivateWorldStateReader(
.flatMap(worldState -> Optional.ofNullable(worldState.get(contractAddress)))
.flatMap(account -> Optional.ofNullable(account.getCode()));
}

public List<PrivateTransactionMetadata> getPrivateTransactionsMetadata(
Copy link
Contributor

Choose a reason for hiding this comment

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

should that be "getPrivateTransactionMetadataList"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@Test
public void verifyPrivacyGroupMatchesEnclaveKeySucceeds() {
final PrivacyGroup privacyGroup =
new PrivacyGroup(PRIVACY_GROUP_ID, Type.PANTHEON, "", "", List.of(ENCLAVE_PUBLIC_KEY1));
Copy link
Contributor

Choose a reason for hiding this comment

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

Could create a const privacy group ... The same one is used twice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done :)

Signed-off-by: Lucas Saldanha <lucas.saldanha@consensys.net>
Signed-off-by: Lucas Saldanha <lucas.saldanha@consensys.net>
Signed-off-by: Lucas Saldanha <lucas.saldanha@consensys.net>
@MadelineMurray MadelineMurray mentioned this pull request Apr 14, 2020
3 tasks
Signed-off-by: Lucas Saldanha <lucas.saldanha@consensys.net>
final PrivateTransactionManager privateTransactionManager =
new LegacyPrivateTransactionManager(
besu, GAS_PROVIDER, senderCredentials, chainId, privateFrom, privateFor);
PrivateTransactionManager privateTransactionManager;
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 be final

Signed-off-by: Lucas Saldanha <lucas.saldanha@consensys.net>
@lucassaldanha lucassaldanha merged commit ba6f656 into hyperledger:master Apr 14, 2020
@lucassaldanha lucassaldanha deleted the priv_getLogs branch April 14, 2020 20:49
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.

Implement priv_getLogs
2 participants