mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-12 09:51:36 +00:00
Gballet asked on PR #34055 to unexport nodeRef, nodeKind, and makeRef (comments 3099846639, 3099847640, 3100717855) — none are used outside trie/bintrie. Cascade to the internal-only support symbols and methods: NodeKind → nodeKind KindEmpty/... → kindEmpty/... NodeRef → nodeRef EmptyRef → emptyRef MakeRef → makeRef NodeStore.Root → deleted; inlined to s.root field access (same pkg) NodeStore.SetRoot → deleted; inlined to s.root = ref NodeStore.ComputeHash/SerializeNode/DeserializeNode(WithHash)/ CollectNodes/ToDot/GetHeight → lowercased All 9 method signatures took or returned nodeRef so their export would have tripped revive:unexported-return after the type rename. Zero external callers means no API break. The private deserializeNode helper was renamed to decodeNode to free the name for the newly-private deserializeNode public function. Pure rename; no behaviour change.
47 lines
1.7 KiB
Go
47 lines
1.7 KiB
Go
// Copyright 2025 go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package bintrie
|
|
|
|
import "github.com/ethereum/go-ethereum/common"
|
|
|
|
// zero is the zero value for a 32-byte array.
|
|
var zero [32]byte
|
|
|
|
const (
|
|
StemNodeWidth = 256 // Number of children per leaf node
|
|
StemSize = 31 // Number of bytes to travel before reaching a group of leaves
|
|
NodeTypeBytes = 1 // Size of node type prefix in serialization
|
|
HashSize = 32 // Size of a hash in bytes
|
|
StemBitmapSize = 32 // Size of the bitmap in a stem node (256 values = 32 bytes)
|
|
)
|
|
|
|
const (
|
|
nodeTypeStem = iota + 1
|
|
nodeTypeInternal
|
|
)
|
|
|
|
// DeserializeAndHash deserializes a node from bytes and returns its hash.
|
|
// This is a convenience function for external callers that need to compute
|
|
// the hash of a serialized node without maintaining a NodeStore.
|
|
func DeserializeAndHash(blob []byte, depth int) (common.Hash, error) {
|
|
s := NewNodeStore()
|
|
ref, err := s.deserializeNode(blob, depth)
|
|
if err != nil {
|
|
return common.Hash{}, err
|
|
}
|
|
return s.computeHash(ref), nil
|
|
}
|