Skip to content

Don't store transaction data in JSON #314

Description

@Endogen

JSON isn't optimal for storing tx data since it doesn't preserve the order of keys and after decoding and getting a dict out of it, we need to order it first.

Better to use one of the following alternatives:

  1. MessagePack
    Faster than JSON for both encoding and decoding, while preserving the original structure, including key order.

Example code:

import msgpack

# Serialize data
packed_data = msgpack.packb(data_dict)

# Deserialize data
unpacked_data = msgpack.unpackb(packed_data)
  1. Protocol Buffers (Protobuf)
    Is a language-neutral and platform-neutral binary serialization format. Extremely efficient and supports schema definition, which ensures data consistency and improves compatibility. Highly optimized for performance and lower payload sizes.

Protobuf requires defining a .proto schema file and generating code, so it’s a bit more setup-heavy, but given that we already use it as part of CometBFT, we should probably switch to this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions