-
Notifications
You must be signed in to change notification settings - Fork 29
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
Conversation
@@ -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); |
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 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?
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. |
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.
Would it make sense to use @AutoValue
here?
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.
Sure, added @AutoValue
.
...nding/core/src/main/java/com/exonum/binding/core/transaction/InternalTransactionContext.java
Outdated
Show resolved
Hide resolved
@@ -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, |
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.
* @see ServiceRuntime#executeTransaction(Integer, int, byte[], TransactionContext, Fork, | |
* @see ServiceRuntime#executeTransaction(Integer, int, byte[], Fork, |
* | ||
* @see TransactionMessage#getServiceId() | ||
*/ | ||
Integer getServiceId(); |
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 it be null
? If not why doesn't int
?
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 can't (and having null
Integer wouldn't be friendly), must be int
, here and elsewhere.
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 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?
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.
But the builder checks (or shall check) that, doesn't it?
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 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(); |
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 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) { |
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.
Also, int here.
public Fork getFork() { | ||
return fork; | ||
} | ||
public abstract Fork getFork(); |
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.
They are already abstract and can be removed, AutoValue will infer them from the interface.
Overview
Add serviceName and serviceId to TransactionContext.
See: https://jira.bf.local/browse/ECR-3639
Definition of Done