mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 12:16:44 +00:00
Update history_trienode.go
This commit is contained in:
parent
cb97c48cb6
commit
d34de11c66
1 changed files with 8 additions and 4 deletions
|
|
@ -219,16 +219,18 @@ func (h *trienodeHistory) encode() ([]byte, []byte, []byte, error) {
|
||||||
binary.Write(&headerSection, binary.BigEndian, h.meta.block) // 8 byte
|
binary.Write(&headerSection, binary.BigEndian, h.meta.block) // 8 byte
|
||||||
|
|
||||||
for _, owner := range h.owners {
|
for _, owner := range h.owners {
|
||||||
|
paths := h.nodeList[owner]
|
||||||
|
restartCount := (len(paths) + trienodeDataBlockRestartLen - 1) / trienodeDataBlockRestartLen
|
||||||
// Fill the key section with node index
|
// Fill the key section with node index
|
||||||
var (
|
var (
|
||||||
prevKey []byte
|
prevKey []byte
|
||||||
restarts []uint32
|
restarts = make([]uint32, 0, restartCount*2)
|
||||||
prefixLen int
|
prefixLen int
|
||||||
|
|
||||||
internalKeyOffset uint32 // key offset within the trie data internally
|
internalKeyOffset uint32 // key offset within the trie data internally
|
||||||
internalValOffset uint32 // value offset within the trie data internally
|
internalValOffset uint32 // value offset within the trie data internally
|
||||||
)
|
)
|
||||||
for i, path := range h.nodeList[owner] {
|
for i, path := range paths {
|
||||||
key := []byte(path)
|
key := []byte(path)
|
||||||
|
|
||||||
// Track the internal key and value offsets at the beginning of the
|
// Track the internal key and value offsets at the beginning of the
|
||||||
|
|
@ -269,11 +271,13 @@ func (h *trienodeHistory) encode() ([]byte, []byte, []byte, error) {
|
||||||
|
|
||||||
// Encode trailer, the number of restart sections is len(restarts))/2,
|
// Encode trailer, the number of restart sections is len(restarts))/2,
|
||||||
// as we track the offsets of both key and value sections.
|
// as we track the offsets of both key and value sections.
|
||||||
var trailer []byte
|
trailer := make([]byte, 0, 4*(len(restarts)+1))
|
||||||
for _, number := range append(restarts, uint32(len(restarts))/2) {
|
for _, number := range restarts {
|
||||||
binary.BigEndian.PutUint32(buf[:4], number)
|
binary.BigEndian.PutUint32(buf[:4], number)
|
||||||
trailer = append(trailer, buf[:4]...)
|
trailer = append(trailer, buf[:4]...)
|
||||||
}
|
}
|
||||||
|
binary.BigEndian.PutUint32(buf[:4], uint32(len(restarts))/2)
|
||||||
|
trailer = append(trailer, buf[:4]...)
|
||||||
if _, err := keySection.Write(trailer); err != nil {
|
if _, err := keySection.Write(trailer); err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue