Skip to content

Commit a1f2685

Browse files
committed
mpt: rename to prefix
1 parent ed7a185 commit a1f2685

9 files changed

Lines changed: 32 additions & 28 deletions

File tree

mpt/label.go renamed to prefix/label.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package mpt
1+
package prefix
22

33
import (
44
"bytes"
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package mptsqlite
1+
package prefixsqlite
22

33
import (
44
"context"
55
"embed"
66
"errors"
77
"slices"
88

9-
"filippo.io/torchwood/mpt"
9+
"filippo.io/torchwood/prefix"
1010
"zombiezen.com/go/sqlite"
1111
"zombiezen.com/go/sqlite/sqlitex"
1212
)
@@ -33,11 +33,11 @@ func NewSQLiteStorage(ctx context.Context, dbPath string) (*Storage, error) {
3333
labelBytes, labelBitLen := args[0].Blob(), uint32(args[1].Int64())
3434
prefixBytes, prefixBitLen := args[2].Blob(), uint32(args[3].Int64())
3535

36-
label, err := mpt.NewLabel(labelBitLen, labelBytes)
36+
label, err := prefix.NewLabel(labelBitLen, labelBytes)
3737
if err != nil {
3838
return sqlite.Value{}, err
3939
}
40-
prefix, err := mpt.NewLabel(prefixBitLen, prefixBytes)
40+
prefix, err := prefix.NewLabel(prefixBitLen, prefixBytes)
4141
if err != nil {
4242
return sqlite.Value{}, err
4343
}
@@ -76,16 +76,16 @@ func (s *Storage) Close() error {
7676
return s.pool.Close()
7777
}
7878

79-
var _ mpt.Storage = (*Storage)(nil)
79+
var _ prefix.Storage = (*Storage)(nil)
8080

81-
func (s *Storage) Load(ctx context.Context, label mpt.Label) (*mpt.Node, error) {
81+
func (s *Storage) Load(ctx context.Context, label prefix.Label) (*prefix.Node, error) {
8282
conn, err := s.pool.Take(ctx)
8383
if err != nil {
8484
return nil, err
8585
}
8686
defer s.pool.Put(conn)
8787

88-
var node *mpt.Node
88+
var node *prefix.Node
8989
if err := sqlitex.ExecuteFS(conn, sql, "load.sql", &sqlitex.ExecOptions{
9090
Args: []any{
9191
label.Bytes(),
@@ -101,23 +101,23 @@ func (s *Storage) Load(ctx context.Context, label mpt.Label) (*mpt.Node, error)
101101
}
102102

103103
if node == nil {
104-
return nil, mpt.ErrNodeNotFound
104+
return nil, prefix.ErrNodeNotFound
105105
}
106106
return node, nil
107107
}
108108

109-
func (s *Storage) LoadPath(ctx context.Context, label mpt.Label) ([]*mpt.Node, error) {
109+
func (s *Storage) LoadPath(ctx context.Context, label prefix.Label) ([]*prefix.Node, error) {
110110
conn, err := s.pool.Take(ctx)
111111
if err != nil {
112112
return nil, err
113113
}
114114
defer s.pool.Put(conn)
115115

116-
var nodes []*mpt.Node
116+
var nodes []*prefix.Node
117117
if err := sqlitex.ExecuteFS(conn, sql, "path.sql", &sqlitex.ExecOptions{
118118
Named: map[string]any{
119-
":root_label": mpt.RootLabel.Bytes(),
120-
":root_label_bit_len": mpt.RootLabel.BitLen(),
119+
":root_label": prefix.RootLabel.Bytes(),
120+
":root_label_bit_len": prefix.RootLabel.BitLen(),
121121
":label": label.Bytes(),
122122
":label_bit_len": label.BitLen(),
123123
},
@@ -137,43 +137,43 @@ func (s *Storage) LoadPath(ctx context.Context, label mpt.Label) ([]*mpt.Node, e
137137
return nodes, nil
138138
}
139139

140-
func nodeFromRow(stmt *sqlite.Stmt) (*mpt.Node, error) {
140+
func nodeFromRow(stmt *sqlite.Stmt) (*prefix.Node, error) {
141141
labelBytes := make([]byte, 32)
142142
stmt.ColumnBytes(0, labelBytes)
143143
labelBitLen := stmt.ColumnInt64(1)
144-
label, err := mpt.NewLabel(uint32(labelBitLen), labelBytes)
144+
label, err := prefix.NewLabel(uint32(labelBitLen), labelBytes)
145145
if err != nil {
146146
return nil, err
147147
}
148148

149149
leftBytes := make([]byte, 32)
150150
stmt.ColumnBytes(2, leftBytes)
151151
leftBitLen := stmt.ColumnInt64(3)
152-
left, err := mpt.NewLabel(uint32(leftBitLen), leftBytes)
152+
left, err := prefix.NewLabel(uint32(leftBitLen), leftBytes)
153153
if err != nil {
154154
return nil, err
155155
}
156156

157157
rightBytes := make([]byte, 32)
158158
stmt.ColumnBytes(4, rightBytes)
159159
rightBitLen := stmt.ColumnInt64(5)
160-
right, err := mpt.NewLabel(uint32(rightBitLen), rightBytes)
160+
right, err := prefix.NewLabel(uint32(rightBitLen), rightBytes)
161161
if err != nil {
162162
return nil, err
163163
}
164164

165165
hashBytes := make([]byte, 32)
166166
stmt.ColumnBytes(6, hashBytes)
167167

168-
return &mpt.Node{
168+
return &prefix.Node{
169169
Label: label,
170170
Left: left,
171171
Right: right,
172172
Hash: [32]byte(hashBytes),
173173
}, nil
174174
}
175175

176-
func (s *Storage) Store(ctx context.Context, nodes ...*mpt.Node) error {
176+
func (s *Storage) Store(ctx context.Context, nodes ...*prefix.Node) error {
177177
conn, err := s.pool.Take(ctx)
178178
if err != nil {
179179
return err

mpt/storage.go renamed to prefix/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package mpt
1+
package prefix
22

33
import (
44
"context"

mpt/tree.go renamed to prefix/tree.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
// Package mpt implements the Merkle Patricia Trie, an append-only compressed
2-
// key-value accumulator based on a sparse binary Merkle tree. Keys and values
3-
// are arbitrary 32-byte strings.
1+
// Package prefix implements a compressed binary Merkle trie, or prefix tree: an
2+
// append-only compressed key-value accumulator based on a sparse binary Merkle
3+
// tree. Keys and values are arbitrary 32-byte strings.
4+
//
5+
// This data structure is sometimes improperly called a "Merkle Patricia Trie",
6+
// despite not implementing the PATRICIA optimization, which elides the actual
7+
// key bits from the intermediate nodes.
48
//
59
// It is compatible with the whatsapp_v1 configuration of the akd library, with
610
// NodeHashingMode::NoLeafEpoch.
711
//
812
// This package is NOT STABLE, regardless of the module version, and the API may
913
// change without notice.
10-
package mpt
14+
package prefix
1115

1216
import (
1317
"context"

mpt/tree_test.go renamed to prefix/tree_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build go1.24
22

3-
package mpt_test
3+
package prefix_test
44

55
import (
66
"encoding/binary"
@@ -10,8 +10,8 @@ import (
1010

1111
"lukechampine.com/blake3"
1212

13-
. "filippo.io/torchwood/mpt"
14-
"filippo.io/torchwood/mpt/mptsqlite"
13+
. "filippo.io/torchwood/prefix"
14+
"filippo.io/torchwood/prefix/prefixsqlite"
1515
)
1616

1717
func testAllStorage(t *testing.T, f func(t *testing.T, newStorage func(t *testing.T) Storage)) {
@@ -23,7 +23,7 @@ func testAllStorage(t *testing.T, f func(t *testing.T, newStorage func(t *testin
2323

2424
t.Run("sqlite", func(t *testing.T) {
2525
f(t, func(t *testing.T) Storage {
26-
store, err := mptsqlite.NewSQLiteStorage(t.Context(), "file::memory:?cache=shared")
26+
store, err := prefixsqlite.NewSQLiteStorage(t.Context(), "file::memory:?cache=shared")
2727
if err != nil {
2828
t.Fatal(err)
2929
}

0 commit comments

Comments
 (0)