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

Serialize/deserialize Block<T> better with System.Text.Json.JsonSerializer #2756

Merged
merged 7 commits into from Jan 30, 2023

Conversation

dahlia
Copy link
Contributor

@dahlia dahlia commented Jan 27, 2023

Implemented JsonConverter for Block<T> and its fields. Here's a sample block encoded into JSON:

{
  "protocolVersion": 3,
  "hash": "cf19d54cf63979d43ed9600648cf804e0971b3ec5526c80dbbf2f5e94e89f21d",
  "signature": "3045022100a69de8d30ed85f8ca62b7371baccea30ab7aeb32b8e185a8262a5ac9a05b86cf02203292da7ef37f745245e43ffe8742ab4fbf8b6fe44071b4715173435b6fc559be",
  "preEvaluationHash": "e2edbaf65d8dfd86e40fcb8f5f21bcd54333686d9262645c4a3d873021dc4f17",
  "stateRootHash": "1b16b1df538ba12dc3f97edbb85caa7050d46c148134290feba80f8236c83db9",
  "index": 0,
  "difficulty": 0,
  "totalDifficulty": 0,
  "nonce": "8a8ae289a78cc167fcfb",
  "miner": "fa7Ef0f81CBbE231aC597b3D3625D3E92C6E9611",
  "publicKey": "0365e861c270ae24ca6217c1188e405081738a93488974da9f57c00e3f0d85567e",
  "previousHash": null,
  "timestamp": "2023-01-27T10:55:14.595683+00:00",
  "txHash": "a93128c5a2ad323c81f6d6a845bb012373ceb1992d3a62477b703809e661da47",
  "transactions": [
    {
      "id": "1d6055adbcc7e23cb8b11cda11b89fede22b647d423412e2b6508f5d90fb8ac4",
      "nonce": 0,
      "signer": "fa7Ef0f81CBbE231aC597b3D3625D3E92C6E9611",
      "updatedAddresses": [],
      "signature": "MEUCIQCk8hTFAuVi1QSe+/NHfGheMXBhLIvUGNxEQmkD7kC0zgIgHNQh0zhVBbKSLQuK6oit8ghRRERoxE7nIA26C96aVwE=",
      "customActions": [],
      "timestamp": "2023-01-27T10:55:14.560103+00:00",
      "publicKey": "0365e861c270ae24ca6217c1188e405081738a93488974da9f57c00e3f0d85567e",
      "genesisHash": null
    }
  ]
}

@dahlia dahlia self-assigned this Jan 27, 2023
@dahlia dahlia force-pushed the block-json-serialization branch 2 times, most recently from 29f71bc to 12b2661 Compare January 27, 2023 10:57
@dahlia dahlia marked this pull request as ready for review January 27, 2023 11:00
@codecov
Copy link

codecov bot commented Jan 27, 2023

Codecov Report

Merging #2756 (eca54bb) into main (a58bb1e) will decrease coverage by 0.01%.
The diff coverage is 92.30%.

❗ Current head eca54bb differs from pull request most recent head a084468. Consider uploading reports for the commit a084468 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2756      +/-   ##
==========================================
- Coverage   80.45%   80.45%   -0.01%     
==========================================
  Files         307      309       +2     
  Lines       10579    10604      +25     
==========================================
+ Hits         8511     8531      +20     
- Misses       2068     2073       +5     
Impacted Files Coverage Δ
Libplanet.Extensions.Cocona/Utils.cs 41.17% <ø> (-3.27%) ⬇️
Libplanet/Blocks/Block.cs 100.00% <ø> (ø)
Libplanet/Crypto/PublicKey.cs 84.61% <80.00%> (-0.68%) ⬇️
Libplanet/Nonce.cs 72.22% <80.00%> (+2.99%) ⬆️
...ibplanet/JsonConverters/BigIntegerJsonConverter.cs 83.33% <83.33%> (ø)
...bplanet.Extensions.Cocona/Commands/StoreCommand.cs 74.32% <100.00%> (ø)
Libplanet/Address.cs 94.36% <100.00%> (ø)
Libplanet/Blocks/BlockHash.cs 91.89% <100.00%> (ø)
Libplanet/ByteUtil.cs 95.12% <100.00%> (+0.38%) ⬆️
Libplanet/HashDigest.cs 95.00% <100.00%> (ø)
... and 8 more

@riemannulus
Copy link
Member

@dahlia
Copy link
Contributor Author

dahlia commented Jan 30, 2023

https://github.com/planetarium/libplanet/actions/runs/4023856396/jobs/6915215674 Could you check this CI?

@riemannulus I addressed the issue. Could you take a look again?

moreal
moreal previously approved these changes Jan 30, 2023
Copy link
Contributor

@moreal moreal left a comment

Choose a reason for hiding this comment

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

Just typos.

Libplanet/ByteUtil.cs Outdated Show resolved Hide resolved
CHANGES.md Outdated Show resolved Hide resolved
riemannulus
riemannulus previously approved these changes Jan 30, 2023
@dahlia dahlia dismissed stale reviews from riemannulus and moreal via a084468 January 30, 2023 04:34
@pull-request-quantifier-deprecated

This PR has 406 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Large
Size       : +329 -77
Percentile : 80.2%

Total files changed: 31

Change summary by file extension:
.json : +1 -1
.ts : +2 -1
.md : +21 -0
.cs : +305 -75

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@dahlia
Copy link
Contributor Author

dahlia commented Jan 30, 2023

@moreal All addressed. Please take a look one more tine. /cc @riemannulus

Copy link
Member

@riemannulus riemannulus left a comment

Choose a reason for hiding this comment

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

LGTM

@dahlia dahlia merged commit 34f3e59 into planetarium:main Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants