Skip to content

Conversation

dmitry-timofeev
Copy link
Contributor

@dmitry-timofeev dmitry-timofeev commented Aug 23, 2019

Overview

Support the new, protobuf-based, message format.

There are a couple of questions for discussion marked as todos.

The definitions are as of exonum/exonum@84ead61
and will be subsequently patched to work well with Java codegen. The corresponding commit
may be skipped (b0448c7 )


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

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

*/
final class ParsedTransactionMessage implements TransactionMessage {

private final Consensus.SignedMessage signedMessage;
Copy link
Contributor

@bullet-tooth bullet-tooth Aug 27, 2019

Choose a reason for hiding this comment

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

It's little confusing that we need references to Consensus.SignedMessage and SignedMessage.

* {@link Consensus.SignedMessage}; or if the payload of the message is not
* {@link Consensus.ExonumMessage}
*/
public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException {
Copy link
Contributor

Choose a reason for hiding this comment

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

this class has package private level but methods are public

import com.google.protobuf.InvalidProtocolBufferException;

/**
* A wrapper around {@link Consensus.SignedMessage} protobuf message containing
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear what is the purpose of this class and where it can be helpful. As I can see in PassedMessage we can get everything we need from the protobuf 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.

🤷‍♂ The line below says " which converts protobuf types into internal types." That is its main purpose.

You do need such a class, unless you are fine with such client code:

PublicKey authorPk = PublicKey.fromBytes(message.getAuthor()
        .toByteArray());

Can you spot a mistake in this snippet — it compiles, will not throw in runtime, but is incorrect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On top of that — it stores ExonumMessage as ByteString, which is even less intuitive to use.

@coveralls
Copy link

coveralls commented Aug 27, 2019

Coverage Status

Coverage decreased (-0.1%) to 85.599% when pulling d85deb7 on dmitry-timofeev:new-message-format-ECR-3473 into ad72643 on exonum:dynamic-services.

Copy link
Contributor

@MakarovS MakarovS left a comment

Choose a reason for hiding this comment

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

👍
Changelog update?


@Override
public byte[] getPayload() {
// todo: Return as ByteString? Add getPayloadAs(MessageType)?
Copy link
Contributor

Choose a reason for hiding this comment

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

Why'd we need to return ByteString 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.

I think that if we encourage the use of protobuf then the payload is likely a serialized protobuf message. A message type can be created both from a byte array and a ByteString. The latter will not require two extra copies. The downside is that we use a protobuf type in a TransactionMessage interface — but as all the messages are in protobuf now, we can probably live with that.

exonum.Signature signature = 3;
}

// List of consensus messages
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't there a way to reuse same proto messages from core?

Copy link
Contributor

Choose a reason for hiding this comment

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

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 added them (and a patch atop of them) as separate commits to be able to re-apply easily (hopefully, to a separate repo and not to the re-imported definitions 🙃 ).

/**
* A funnel for ByteStrings which puts their bytes to the sink without copying.
*/
enum ByteStringFunnel implements Funnel<ByteString> {
Copy link
Contributor

@MakarovS MakarovS Aug 28, 2019

Choose a reason for hiding this comment

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

Should we create a task for using ByteStringFunnel in places where we currently use

Hashing.defaultHashFunction().newHasher()
        .putBytes(v.toByteArray())
        .hash();

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've found only a single such usage, and decided to inline the #getAsReadonlyByteBuffer instead of making the funnel public.

Import protobuf definitions of Exonum messages required to
create transaction messages. We need to copy these definitions
until a separate repo with them is created: ECR-3472

The definitions are as of exonum/84ead6191173138f96feabadd3033b3f9aa42368
and will be subsequently patched to work well with Java codegen.
Specify the Java package in which the compiler shall place the generated
classes.

This patch shall be re-applied when messages are updated (copied over
again) or when they finally find their home (ECR-3472).
Add support for new protocol buffers-based
message format. SignedMessage supports
any Exonum message; whilst TransactionMessage
(including ParsedTransactionMessage) represent
a transaction message and allow to access
any properties of the transaction.

As transaction payloads (arguments) are often
protocol buffer messages, some methods
now have protobuf-specific overloads for
higher convenience
(e.g., TransactionMessage.Builder#payload).
@dmitry-timofeev dmitry-timofeev force-pushed the new-message-format-ECR-3473 branch from e7a3dde to d85deb7 Compare September 24, 2019 14:00
@dmitry-timofeev dmitry-timofeev merged commit 09cf61e into exonum:dynamic-services Sep 24, 2019
@dmitry-timofeev dmitry-timofeev deleted the new-message-format-ECR-3473 branch September 24, 2019 14:47
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.

5 participants