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

Add serviceName and serviceId to TransactionContext [ECR-3639] #1181

Merged
merged 10 commits into from
Oct 30, 2019

Conversation

MakarovS
Copy link
Contributor

@MakarovS MakarovS commented Oct 23, 2019

Overview

Add serviceName and serviceId to TransactionContext.


See: https://jira.bf.local/browse/ECR-3639

Definition of Done

  • There are no TODOs left in the code
  • Change is covered by automated tests
  • The coding guidelines are followed
  • Public API has Javadoc
  • Method preconditions are checked and documented in the Javadoc of the method
  • Changelog is updated if needed (in case of notable or breaking changes)
  • The continuous integration build passes

@coveralls
Copy link

coveralls commented Oct 23, 2019

Coverage Status

Coverage increased (+0.2%) to 86.177% when pulling 89e85c3 on ECR-3639 into 892596a on dynamic-services.

@@ -157,10 +157,13 @@ void executeTransaction(int serviceId, int txId, byte[] arguments,
Fork fork = viewFactory.createFork(forkNativeHandle, cleaner);
HashCode hash = HashCode.fromBytes(txMessageHash);
PublicKey authorPk = PublicKey.fromBytes(authorPublicKey);
String serviceName = serviceRuntime.getServiceNameById(serviceId);
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember we discussed to push the instantiation of TransactionContext inside the runtime because it already has this knowledge, the adapter will not have to request if from the runtime (and to be appropriately tested), and the runtime — provide an accessor for that. Is there a reason for the other approach?

@dmitry-timofeev
Copy link
Contributor

Q: Do we actually need to include service id? Shouldn't service name be sufficient for our purposes, as it's always known to the user (unlike service id)?

The present TransactionConverter does not include the service id (com.exonum.binding.core.service.TransactionConverter#toTransaction), so if the transaction execution logic does need the id in some operations, the converter will have to be supplied with that id, or the tx execution logic will have to access it elsewhere.

@@ -21,6 +21,7 @@
import com.exonum.binding.common.crypto.PublicKey;
import com.exonum.binding.common.hash.HashCode;
import com.exonum.binding.core.storage.database.Fork;
import java.util.Objects;

/**
* Default implementation of the transaction context.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to use @AutoValue 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.

Sure, added @AutoValue.

@@ -146,7 +146,8 @@ void stopService(int id) {
* @param txMessageHash the hash of the transaction message
* @param authorPublicKey the public key of the transaction author
* @throws TransactionExecutionException if the transaction execution failed
* @see ServiceRuntime#executeTransaction(Integer, int, byte[], TransactionContext)
* @see ServiceRuntime#executeTransaction(Integer, int, byte[], TransactionContext, Fork,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @see ServiceRuntime#executeTransaction(Integer, int, byte[], TransactionContext, Fork,
* @see ServiceRuntime#executeTransaction(Integer, int, byte[], Fork,

*
* @see TransactionMessage#getServiceId()
*/
Integer getServiceId();
Copy link
Contributor

Choose a reason for hiding this comment

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

can it be null? If not why doesn't int?

Copy link
Contributor

Choose a reason for hiding this comment

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

It can't (and having null Integer wouldn't be friendly), must be int, here and elsewhere.

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 intentionally used Integer here, so that if serviceId isn't specified, NPE would be thrown by AutoValue when creating an instance. Opposed to int, which would just set this value to 0 by default, which is error-prone. Should I keep the Integer or change it to int and validate that it was set or change it to int and not bother with that?

Copy link
Contributor

Choose a reason for hiding this comment

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

But the builder checks (or shall check) that, doesn't it?

Copy link
Contributor

Choose a reason for hiding this comment

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

The builder implementation nuances (that it uses Integer to distinguish between a set and unset value) must not affect the API.

*
* @see TransactionMessage#getServiceId()
*/
Integer getServiceId();
Copy link
Contributor

Choose a reason for hiding this comment

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

It can't (and having null Integer wouldn't be friendly), must be int, here and elsewhere.


public static InternalTransactionContext newInstance(Fork fork, HashCode hash,
PublicKey authorPk, String serviceName,
Integer serviceId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, int here.

public Fork getFork() {
return fork;
}
public abstract Fork getFork();
Copy link
Contributor

Choose a reason for hiding this comment

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

They are already abstract and can be removed, AutoValue will infer them from the interface.

@MakarovS MakarovS merged commit d627798 into dynamic-services Oct 30, 2019
@dmitry-timofeev dmitry-timofeev deleted the ECR-3639 branch October 30, 2019 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants