Skip to content

Commit b2b8076

Browse files
committed
move error definitions to doc.go (#158)
1 parent e767b0c commit b2b8076

File tree

3 files changed

+49
-22
lines changed

3 files changed

+49
-22
lines changed

doc.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// This is free and unencumbered software released into the public domain.
2+
//
3+
// Anyone is free to copy, modify, publish, use, compile, sell, or
4+
// distribute this software, either in source code form or as a compiled
5+
// binary, for any purpose, commercial or non-commercial, and by any
6+
// means.
7+
//
8+
// In jurisdictions that recognize copyright laws, the author or authors
9+
// of this software dedicate any and all copyright interest in the
10+
// software to the public domain. We make this dedication for the benefit
11+
// of the public at large and to the detriment of our heirs and
12+
// successors. We intend this dedication to be an overt act of
13+
// relinquishment in perpetuity of all present and future rights to this
14+
// software under copyright law.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
// OTHER DEALINGS IN THE SOFTWARE.
23+
//
24+
// For more information, please refer to <https://unlicense.org>
25+
26+
package verkle
27+
28+
import "errors"
29+
30+
var (
31+
errInsertIntoHash = errors.New("trying to insert into hashed node")
32+
errDeleteNonExistent = errors.New("trying to delete non-existent leaf")
33+
errDeleteHash = errors.New("trying to delete from a hashed subtree")
34+
errReadFromInvalid = errors.New("trying to read from an invalid child")
35+
errSerializeHashedNode = errors.New("trying to serialized a hashed node")
36+
errNotSupportedInStateless = errors.New("not implemented in stateless")
37+
)
38+
39+
const (
40+
// Extension status
41+
extStatusAbsentEmpty = byte(iota) // missing child node along the path
42+
extStatusAbsentOther // path led to a node with a different stem
43+
extStatusPresent // stem was present
44+
)

stateless.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type StatelessNode struct {
4444
stem []byte
4545

4646
// node depth in the tree, in bits
47-
depth int
47+
depth byte
4848

4949
// child count, used for the special case in
5050
// commitment calculations.
@@ -60,8 +60,6 @@ type StatelessNode struct {
6060
committer Committer
6161
}
6262

63-
var errNotSupportedInStateless = errors.New("not implemented in stateless")
64-
6563
func NewStateless() *StatelessNode {
6664
return &StatelessNode{
6765
children: make(map[byte]*StatelessNode),
@@ -274,7 +272,7 @@ func (n *StatelessNode) ComputeCommitment() *Fr {
274272
count1, count2 := 0, 0
275273
var poly, c1poly, c2poly [256]Fr
276274
poly[0].SetUint64(1)
277-
fromBytes(&poly[1], n.stem)
275+
FromBytes(&poly[1], n.stem)
278276

279277
for idx, val := range n.values {
280278
if idx < 128 {
@@ -309,12 +307,12 @@ func (n *StatelessNode) ComputeCommitment() *Fr {
309307
return n.hash
310308
}
311309

312-
func (*StatelessNode) GetCommitmentsAlongPath([]byte) *ProofElements {
310+
func (*StatelessNode) GetCommitmentsAlongPath([]byte) (*ProofElements, byte, []byte) {
313311
panic("not supported in stateless mode")
314312
}
315313

316314
func (*StatelessNode) Serialize() ([]byte, error) {
317-
return nil, errors.New("not supported")
315+
return nil, errNotSupportedInStateless
318316
}
319317

320318
func (n *StatelessNode) Copy() VerkleNode {

tree.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,6 @@ const (
131131
leafRLPType byte = 2
132132
)
133133

134-
var (
135-
errInsertIntoHash = errors.New("trying to insert into hashed node")
136-
errDeleteNonExistent = errors.New("trying to delete non-existent leaf")
137-
errDeleteHash = errors.New("trying to delete from a hashed subtree")
138-
errReadFromInvalid = errors.New("trying to read from an invalid child")
139-
errSerializeHashedNode = errors.New("trying to serialized a hashed node")
140-
)
141-
142-
const (
143-
// Extension status
144-
extStatusAbsentEmpty = byte(iota) // missing child node along the path
145-
extStatusAbsentOther // path led to a node with a different stem
146-
extStatusPresent // stem was present
147-
)
148-
149134
type (
150135
// Represents an internal node at any level
151136
InternalNode struct {
@@ -475,7 +460,7 @@ func (n *InternalNode) ComputeCommitment() *Fr {
475460
// Special cases of a node with no children: either it's
476461
// an empty root, or it's an invalid node.
477462
if n.count == 0 {
478-
if n.depth != byte(0) {
463+
if n.depth != 0 {
479464
panic("internal node should be empty node")
480465
}
481466

0 commit comments

Comments
 (0)