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

Open
wants to merge 6 commits into
base: albatross
Choose a base branch
from

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 transaction will likely ever make use of the full u64 range for its 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.

Drawbacks

  • A transaction could increase in size when adding or increasing the fee, requiring to increase the fee again if targeting a specific fee-per-byte.

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.

@sisou sisou added the testnet-restart Change breaks the protocol and requires a testnet restart label Aug 1, 2024
@sisou sisou force-pushed the soeren/variable-size-coin branch from fc78f99 to aa4382b Compare August 23, 2024 10:15
@sisou sisou marked this pull request as ready for review August 23, 2024 10:16
@sisou sisou force-pushed the soeren/variable-size-coin branch from 8d391d9 to c12d921 Compare November 5, 2024 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testnet-restart Change breaks the protocol and requires a testnet restart
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants