以太坊账本存储探秘

2018-11-08  本文已影响0人  golang推广大使

以太坊中的一些键的构成

前一篇文章介绍了超级账本fabric的区块存储,其中有部分是索引数据库,其中索引的key非常有规律。写完后自己好奇以太坊是否有类似的东西,所以就翻看了以太坊的代码,发现了类似的东西。

go-ethereum/rawdb/schema.go中定义了以下几个全局变量,用于构造组合键

变量 备注
headHeaderKey []byte("LastHeader")
headBlockKey []byte("LastBlock")
headFastBlockKey []byte("LastFast") 存放hash至
fastTrieProgressKey []byte("TrieSync")
headerPrefix []byte("h") "h"+num(uint64 big endian)+hash ->headerKey 存放区块header的rlp编码
headerTDSuffix []byte("t") headerKey+"t"->headerTDKey 存放一个区块高度big.Int值的rlp编码
headerHashSuffix []byte("n") "h" + num(uint64 big endian)+ headerHashSuffix -> headerHashKey 存放区块hash值
headerNumberPrefix []byte("H") headerNumberPrefix + hash -> headerNumberKey 存放区块头编号的大端字节编码
blockBodyPrefix []byte("b") "b"+num(uint64 big endian)+hash->blockBodyKey 存放区块body的rlp编码值
blockReceiptsPrefix []byte("r") "r" +num(uint64 big endian)+hash 存放receipts切片的rlp编码
txLookupPrefix []byte("l") txLookupPrefix + hash-> 存放一个TxLookupEntry值的rlp编码
bloomBitsPrefix []byte("B") bloomBitsPrefix + bit (uint16 big endian) + section (uint64 big endian) + hash->
preimagePrefix []byte("secure-key-") preimagePrefix + hash -> preimage
configPrefix []byte("ethereum-config-") db配置的前缀
BloomBitsIndexPrefix []byte("iB")
databaseVerisionKey []byte("DatabaseVersion")
type TxLookupEntry struct {
    BlockHash  common.Hash
    BlockIndex uint64
    Index      uint64
}

未完待续

上一篇 下一篇

猜你喜欢

热点阅读