Bitcointalk · Protocol Buffers for Bitcoin

中本聪,2010 年 8 月 2 日

SN-1803 已核对来源,附原文与上下文。

阅读语言
中文译文

我当初没用 protocol buffers 或 boost 序列化,是因为它们看起来太复杂,没法做到绝对滴水不漏、绝对安全。它们的代码量太大,读不完,也就无法确保不存在某种能触发意外行为的输入。

我讨厌重复造轮子,是不得已才自己写序列化例程的。我们现有的序列化格式尽可能简单、扁平。输入流的构成方式没有任何多余的自由度。每个时点,数据结构里的下一个字段都是预期中的。仅有的选择权就是接收方预期中的那些。有版本号,所以可以升级。

CAddress 差不多是唯一一个留有大量保留空间的对象。(约 7 字节用于标志,12 字节留给将来可能的 IPv6 扩展)

区块和交易这类较大的东西已经没法再为体积优化多少了。它们的主体数据是哈希、密钥和签名,不可压缩。序列化开销非常小,长度字段通常只占 1 字节。

关于 Gavin 说的现有的 P2P 广播基础设施,我怀疑那东西不存在。只需要广播的 P2P 系统很少。有些库(如 Chord)试图提供分布式哈希表基础设施,但那是个巨大而困难的问题,我们不需要也不想要。那些库装起来也比我们自己的难得多。

ORIGINAL · 英文原文
The reason I didn't use protocol buffers or boost serialization is because they looked too complex to make absolutely airtight and secure.  Their code is too large to read and be sure that there's no way to form an input that would do something unexpected.

I hate reinventing the wheel and only resorted to writing my own serialization routines reluctantly.  The serialization format we have is as dead simple and flat as possible.  There is no extra freedom in the way the input stream is formed.  At each point, the next field in the data structure is expected.  The only choices given are those that the receiver is expecting.  There is versioning so upgrades are possible.

CAddress is about the only object with significant reserved space in it.  (about 7 bytes for flags and 12 bytes for possible future IPv6 expansion)

The larger things we have like blocks and transactions can't be optimized much more for size.  The bulk of their data is hashes and keys and signatures, which are uncompressible.  The serialization overhead is very small, usually 1 byte for size fields.

On Gavin's idea about an existing P2P broadcast infrastructure, I doubt one exists.  There are few P2P systems that only need broadcast.  There are some libraries like Chord that try to provide a distributed hash table infrastructure, but that's a huge difficult problem that we don't need or want.  Those libraries are also much harder to install than ourselves.
上下文
← 上一条 SN-1803 · 当前 下一条 → 在档案中查看完整主题串 →
来源
Bitcointalk 原始链接 ↗ 记录编号 SN-1803