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:
- 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)
- 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.
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:
Faster than JSON for both encoding and decoding, while preserving the original structure, including key order.
Example code:
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.