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

Variable-sized Coin serialization #2373

Draft
wants to merge 5 commits into
base: albatross
Choose a base branch
from
Draft

Conversation

sisou
Copy link
Member

@sisou sisou commented Apr 17, 2024

What's in this pull request?

This PR makes Coin serialize to a varint in transactions and accounts, both over the wire and their internal representations (history store).

Reasoning

No transactions will ever make use of the full u64 range for value, and especially not for fee. So most zero bytes for Coins in most transactions are wasted. This is especially true for signaling transactions, which have 16 zero-bytes to represent 0 value and (mostly) 0 fee. This PR reduces them to two zero bytes.

Exceptions

There are two exceptions for backwards-compatibility with PoW transactions:

  1. Coins in vesting contract creation data are still serialized with fixint::be
  2. For determining a transaction's hash, tx.serialize_content() serializes value and fee as before with fixint::be

Pull request checklist

  • All tests pass. The project builds and runs.
  • I have resolved any merge conflicts.
  • I have resolved all clippy and rustfmt warnings.

@sisou sisou self-assigned this Apr 17, 2024
Copy link
Contributor

@hrxi hrxi left a comment

Choose a reason for hiding this comment

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

Looks like a good improvement to me.

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.

None yet

2 participants