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

docs: Specification update to clean up and improve documentation for proto message definitions #388

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jsync-swirlds
Copy link
Member

@jsync-swirlds jsync-swirlds commented Jul 3, 2024

Massive update to all services proto files to update and correct in-place
specification and documentation.

Note, the rendered markdown is removed from this PR to ease review.
The full rendered markdown documents may be found here.

  • Added svg diagrams in a branch for most state objects to assist in review.
  • Cleaned up copyright headers to remove non-printing characters.
  • Began reworking documents to produce clear documentation via the most
    common document processor for protobuf
    • There are limitations that encourage a slightly different style.
    • Markdown produces the best output (with slight modifications to the template),
      so that is selected.
  • Added a modified markdown template (to work around the "sanitization" bug in
    the docs processor for markdown).
    • Now we can add most HTML tags in the markdown, allowing things like line breaks
      in attribute descriptions.
    • This allows using a line with only <br/> or <p> in place of blank
      lines (that break the markdown tables).
  • Thorough update of many proto files in state.
  • Committed a fully generated set of docs in a separate branch for review
    purposes.
  • Moved document outputs to documents/api/services to allow for other document sets
  • Removed unused imports to quiet warnings.
  • Replicate "service" documentation to the message body entries for clarity
    • Message bodies were just "see ..." references, which do not link well,
      and push content specification to the service API, which muddies both.
  • Rewrite message body documentation to content specification
  • Rewrite "service" API documentation to API specification.
  • Adjust common fields to have consistent descriptions.
  • Updated copyright header to match services standard.
    • Corrected incorrect copy-paste of older years in some files.
    • Removed hidden zero-width characters.
    • Removed unnecessary additions.
  • Adjusted query header and query response header text to be more uniform.
  • Thorough update across services proto definitions
    • State messages complete
    • Consensus service complete
    • Smart Contract service complete.
    • Crypto Service complete.
    • Miscellaneous protos complete.
    • File Service complete.
    • Freeze Service complete.
    • Transaction and records complete.
    • Synthetic node_stake_update transaction complete.
    • Query and Response complete.
    • General Queries complete.
      • Harmonized crypto_get_info and get_account_details
      • Discovered no service interface defines getByKey, we may be able to
        completely remove that query, with it's handler in network admin service,
        and just reserve the field number in query and hedera functionality henceforth.
      • Found a few more unsupported queries and marked them deprecated in the
        query.proto one-of block.
    • Network Service complete
    • Schedule Service complete
    • Token Service complete
      • Fixed the new token_reject file, which was not created according to
        the content in the HIP.
    • Utility Service complete.
    • Address Book Service complete.
      • This was a separate PR.
    • Response Code
      • Separate due to size (over 360 fields) and frequent changes.
        Will be addressed in a separate PR and HIP to minimize conflict.

@jsync-swirlds jsync-swirlds self-assigned this Jul 3, 2024
@jsync-swirlds jsync-swirlds changed the title docs: Documentation Update to clean up and improve documentation for proto message definitions docs: Specification update to clean up and improve documentation for proto message definitions Jul 11, 2024
@jsync-swirlds jsync-swirlds force-pushed the pbj-storage-spec-review branch 6 times, most recently from fb4bc88 to df235a5 Compare July 19, 2024 00:51
@jsync-swirlds jsync-swirlds force-pushed the pbj-storage-spec-review branch 4 times, most recently from 658ad21 to e4dfc42 Compare July 24, 2024 23:38
@jsync-swirlds jsync-swirlds force-pushed the pbj-storage-spec-review branch 3 times, most recently from 85a8dc1 to 99947b7 Compare August 1, 2024 18:02
@jsync-swirlds jsync-swirlds force-pushed the pbj-storage-spec-review branch 2 times, most recently from 030315e to 3c26875 Compare August 9, 2024 19:33
Copy link
Member Author

@jsync-swirlds jsync-swirlds left a comment

Choose a reason for hiding this comment

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

.

@jsync-swirlds jsync-swirlds force-pushed the pbj-storage-spec-review branch 7 times, most recently from 22a1201 to 5ffdb1c Compare August 14, 2024 23:58
@jsync-swirlds jsync-swirlds force-pushed the pbj-storage-spec-review branch 2 times, most recently from 8abac61 to 243d22f Compare August 22, 2024 21:21
@jsync-swirlds
Copy link
Member Author

I believe I've addressed or responded to each comment, thank you all for your diligence.
Please check my changes and/or responses, and resolve or comment further as needed.

@jsync-swirlds jsync-swirlds force-pushed the pbj-storage-spec-review branch 2 times, most recently from 13d4594 to 238d649 Compare November 1, 2024 20:15
@@ -33,116 +39,167 @@ option java_multiple_files = true;

/**
* Representation of a Hedera Schedule entry in the network Merkle tree.
*
* As with all network entities, a schedule has a unique entity number, which is usually given along
* with the network's shard and realm in the form of a shard.realm.number id.
*/
Copy link
Contributor

@thomas-swirlds-labs thomas-swirlds-labs Nov 4, 2024

Choose a reason for hiding this comment

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

This doesn't seem to conform to the Style Guidelines - "Include a line break (<br/>) after the first line, then a brief description, if appropriate. Not every field needs additional description, but every message does."

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I will improve this message with some clear description.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

comment boxes are limited to roughly 80 characters width. The primary
"code" interaction with proto files and markdown files is in review.
Also, some markdown processors struggle with longer lines.
- Use blank lines (with `*` prefix) for paragraph breaks in message or
Copy link
Contributor

@thomas-swirlds-labs thomas-swirlds-labs Nov 4, 2024

Choose a reason for hiding this comment

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

I think might be a little confusing. When should a message have a blank line and when should it have a <p> ?

Copy link
Member Author

Choose a reason for hiding this comment

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

All specification content should be as close to clean markdown as the current processor permits. The use of <p> in fields is necessitated by limitations of markdown tables; messages should always prefer a blank line over a <p> tag.

I'll add some clarifying text here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

* On success, the resulting TransactionReceipt contains the newly created TopicId.
* Request is [ConsensusCreateTopicTransactionBody](#proto.ConsensusCreateTopicTransactionBody)
* Create an HCS topic.
* <p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could add a section on Service definitions to the Style Guidelines. Seems messages cannot contain <p> tags but Services can is that true?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's tricky because gRPC service syntax is somewhat "bolted on" and reuses other proto syntax with different keywords.
Basically, a service is equivalent to a message; a rpc is equivalent to a field.

I'll add something to that effect to the guidelines.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

*/
int32 number = 3;
}

/**
* UNDOCUMENTED
* Submit a message for consensus.
* <p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should messages contain <p> tags or only blank lines 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, messages should just be blank lines, in order to remain clean markdown syntax.
Occasional exceptions may be required temporarily until we upgrade to a version of Java (23 or later) with the markdown syntax for Javadoc (JEP 467) available, and update PBJ to translate the documentation accordingly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

* The bytes of each uint64 or uint32 encoded for the hash input
* MUST be in Big-Endian format.
* <p>
* <hr/>
Copy link
Contributor

@thomas-swirlds-labs thomas-swirlds-labs Nov 4, 2024

Choose a reason for hiding this comment

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

Just wondering in general on the guidance of when is it advisable or appropriate to add <hr/> tags ?

Copy link
Member Author

Choose a reason for hiding this comment

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

In large blocks of documentation, it is appropriate to add hr tags to set apart large groupings of closely related items, or provide visual separation for multiple broad topics.
In general, such usage should be rare, however, as we would prefer not to need such large blocks of documentation in most situations.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

* <p>
* If the `autoRenewAccount` value for this topic is set to a valid account
* with sufficient HBAR balance to pay renewal fees when this topic
* expires, the system SHALL automatically renew this topic, extending the
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a description or a requirement?

Copy link
Member Author

Choose a reason for hiding this comment

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

Requirement, just a complex one to express.

*/
Timestamp expirationTime = 2;

/**
* The new key to control updates to the contract
* If set, modify the key that authorizes updates to the contract.
* <p>
Copy link
Contributor

@thomas-swirlds-labs thomas-swirlds-labs Nov 4, 2024

Choose a reason for hiding this comment

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

Here we have a <p> tag but in the previous field we have a <br/> ?

Copy link
Member Author

@jsync-swirlds jsync-swirlds Nov 4, 2024

Choose a reason for hiding this comment

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

This separates summary from requirements. The prior field requires more description than the summary statement, so it includes a descriptive sentence or two; this field does not require that additional descriptive content.

string memo = 9 [deprecated = true];

/**
* If set, modify the short memo for this smart contract.<br/>
Copy link
Contributor

Choose a reason for hiding this comment

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

should the <br/> be on the next line ?

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 syntax guidelines place the <br/> tag at the end of the line. This generally reads better than a tag before text on a line.
e.g.

text ending in a break.<br/>
is generally easier to read than
<br/>text starting with a break

Copy link
Member Author

Choose a reason for hiding this comment

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

Added this to guidelines.

* or more signatures.
* - The account key of the account associated to the live hash.
* - Any one key from the key list in the live hash entry.
* - Any combination of keys from the key list in the live hash entry.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

This transactionBody might be missing heading ### Block Stream Effects.

Copy link
Member Author

@jsync-swirlds jsync-swirlds Nov 4, 2024

Choose a reason for hiding this comment

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

This entire transaction is deprecated (see block on line 5), and has no block stream effects.

*/
int32 number = 3;
}

/**
* UNDOCUMENTED
* Submit a message for consensus.
* <p>
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 some heuristic around when messages should have <p> tags or should we always favour blank lines for breaks in messages?

Copy link
Member Author

Choose a reason for hiding this comment

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

Always prefer a blank line.
This line is an error that I will fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

sentences than "normal" prose. Some describe the flow as "staccato".
- Add another blank line after requirements for `message` documents only.
- Each message that represents a transaction body **must** document the
Block Stream effects with a heading `### Block Stream Effects`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could also add here that any heading such as ### Block Stream Effects should not have a <br/> since titles are block elements (like paragraphs)

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

description or requirements, not here.
- A good rule of thumb is that if this first sentence exceeds 60
characters, then it is trying to describe too much.
- Include a line break (`<br/>`) after the first line, then a brief description,
Copy link
Contributor

Choose a reason for hiding this comment

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

Additional Note: A <br/> should never be alone on a line; it should always appear at end of the line instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll update these in the HIP that defines this file, and replicate here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

Blank lines break the automated documentation generator in **fields**
because fields are output as markdown tables, and markdown tables require
each row to be a single long line.
- Be _prescriptive_ in requirements. Do not _describe_ the behavior.
Copy link
Contributor

Choose a reason for hiding this comment

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

In proto specification 2 we had the required tag but that has been removed in v3. Should every field now try to have the equivalent of either an optional or required tag in the comments e.g. "This field SHALL not be empty" or what are the guidelines around that?

Copy link
Member Author

Choose a reason for hiding this comment

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

optional still exists in proto3 and later versions (2023 edition is latest, I believe); it requests "explicit presence".
Required fields are the only ones we probably should describe, since optional is the default.
Note, PBJ currently does not support explicit presence, so that feature gap will need to be closed before we can enforce such a guideline.

How would this read, as a guideline?

The default state for any field is "optional", and all required fields should be specified as such. If the presence or absence of a field must be clear separate from the default value of that field, the field should use proto3 "explicit presence" and be marked with the optional keyword.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

*/
string memo = 2;

// The choices here are arranged by service in roughly lexicographic
Copy link
Contributor

Choose a reason for hiding this comment

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

If we can have code comments -- for example here to clarify the oneof data structure then we could maybe add a section in the style guidelines to illustrate and clarify?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, I'll work on that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

ConsensusDeleteTopicTransactionBody consensusDeleteTopic = 20;

/**
* Submit a message to a topic.<br/>
Copy link
Contributor

Choose a reason for hiding this comment

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

In the Style Guidelines it states "Include a line break (<br/>) after the first line, then a brief description, if appropriate." Is this applicable to fields as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, both messages and fields may have description, if the summary line is not sufficient.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added some clarification to the guidelines.

…message definitions

* Added svg diagrams for most state objects.
* Clean up copyright headers to remove non-printing characters.
* Began reworking documents to produce clear documentation via the most common document processor for protobuf
   * There are limitations that encourage a slightly different style.
   * Markdown produces the best output (with slight modifications to the template), so that is selected.
* Added a modified markdown template (to work around the "sanitization" bug in the docs processor for markdown).
   * Now we can add most HTML tags in the markdown, allowing things like line breaks in attribute descriptions.
   * The results are much better, might be something worth submitting as a PR upstream (along with some non-trivial examples)...
   * This allows using a line with only `<br/>` or `<p>` in place of blank lines (that break the markdown tables).
   * Ideally the go code would do this, but that's a bigger lift, this works for now.
* Thorough update of many proto files in state.
* Committed a fully generated set of docs in this branch for review purposes, will remove before completing the task.
* Moved document outputs to `documents/api/services` to allow for other document sets
* Removed unused imports to quiet warnings.
* Replicate "service" documentation to the message body entries for clarity
   * Message bodies were just "see ..." references, which do not link well, and push content specification to the service API, which muddies both.
* Rewrite message body documentation to *content* specification
* Rewrite "service" API documentation to *API* specification.
* Adjust common fields to have consistent descriptions.
Mass update of the copyright header.
* Updated copyright header to match services standard.
   * Corrected incorrect copy-paste of older years in state.
   * Removed hidden zero-width characters.
   * Removed unnecessary additions.
* Adjusted query header and query response header text to be more uniform.
* Thorough update across services proto definitions
   * State messages complete
   * Consensus service complete
   * Smart Contract service complete.
   * Crypto Service complete.
   * Miscellaneous protos complete.
   * File Service complete.
   * Freeze Service complete.
   * Transaction and records complete.
   * Synthetic node_stake_update transaction complete.
   * Query and Response complete.
   * General Queries complete.
      * Harmonized crypto_get_info and get_account_details
      * Discovered no service interface defines `getByKey`, we may
        be able to completely remove that query, with it's handler
        in network admin service, and just reserve the field number
        in query and hedera functionality henceforth.
      * Found a few more unsupported queries and marked them deprecated in
        the query.proto one-of block.
   * Network Service complete
   * Schedule Service complete
   * Token Service complete
      * Fixed the new `token_reject` file, which was not created according to
        the content in the HIP.
   * Utility Service complete.
   * Address Book Service complete.
      * Minor updates and clarification only.
   * HIP 904 additions
      * Updated all airdrop and pending airdrop entries.
   * Response Code
      * Separate due to size (iover 360 fields) and frequent
        changes.  Will be addressed in a separate PR to minimize
        conflict with ongoing services work.

Signed-off-by: Joseph Sinclair <[email protected]>
* Documentation is moved to the hip-1037-documentation branch

Signed-off-by: Joseph Sinclair <[email protected]>
 * Fixed incorrect reference in block header.
 * Improvements to style guidelines file.
 * Small review fixes.

Signed-off-by: Joseph Sinclair <[email protected]>
 * Many suggestions slightly rewritten to better match style
   guidelines.
 * Harmonized use of the `reserved` keyword.
 * Added several clarifications to style guidelines.

Signed-off-by: Joseph Sinclair <[email protected]>
Copy link
Contributor

@derektriley derektriley left a comment

Choose a reason for hiding this comment

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

Partial review of UtilService LGTM.

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.