From 45a8a3bb32915ad1b6126023285b07cd260b2b9e Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Mon, 16 Oct 2023 15:37:40 -0400 Subject: [PATCH 001/131] WIP --- x/merkledb/codec.go | 38 ++++++++++++++++++++++++++++++++++++++ x/merkledb/db.go | 42 ++++++++++++++++++++++-------------------- x/merkledb/history.go | 7 ++++--- x/merkledb/trieview.go | 2 +- 4 files changed, 65 insertions(+), 24 deletions(-) diff --git a/x/merkledb/codec.go b/x/merkledb/codec.go index 58004aba5088..256d3e310755 100644 --- a/x/merkledb/codec.go +++ b/x/merkledb/codec.go @@ -62,11 +62,13 @@ type encoder interface { encodeDBNode(n *dbNode, factor BranchFactor) []byte // Assumes [hv] is non-nil. encodeHashValues(hv *hashValues) []byte + encodeKeyAndNode(key Path, n *dbNode, factor BranchFactor) []byte } type decoder interface { // Assumes [n] is non-nil. decodeDBNode(bytes []byte, n *dbNode, factor BranchFactor) error + decodeKeyAndNode(bytes []byte, factor BranchFactor) (Path, *node, error) } func newCodec() encoderDecoder { @@ -133,6 +135,19 @@ func (c *codecImpl) encodeHashValues(hv *hashValues) []byte { return buf.Bytes() } +func (c *codecImpl) encodeKeyAndNode(key Path, n *dbNode, factor BranchFactor) []byte { + var ( + numChildren = len(n.children) + // Estimate size of [n] to prevent memory allocations + estimatedLen = binary.MaxVarintLen64 + len(key.Bytes()) + estimatedValueLen + minVarIntLen + estimatedNodeChildLen*numChildren + buf = bytes.NewBuffer(make([]byte, 0, estimatedLen)) + ) + + c.encodePath(buf, key) + _, _ = buf.Write(c.encodeDBNode(n, factor)) // TODO improve + return buf.Bytes() +} + func (c *codecImpl) decodeDBNode(b []byte, n *dbNode, branchFactor BranchFactor) error { if minDBNodeLen > len(b) { return io.ErrUnexpectedEOF @@ -192,6 +207,29 @@ func (c *codecImpl) decodeDBNode(b []byte, n *dbNode, branchFactor BranchFactor) return nil } +func (c *codecImpl) decodeKeyAndNode(b []byte, branchFactor BranchFactor) (Path, *node, error) { + if ids.IDLen+minDBNodeLen > len(b) { + return Path{}, nil, io.ErrUnexpectedEOF + } + + src := bytes.NewReader(b) + + key, err := c.decodePath(src, branchFactor) + if err != nil { + return Path{}, nil, err + } + + nodeBytes, err := c.decodeByteSlice(src) + if err != nil { + return Path{}, nil, err + } + node, err := parseNode(key, nodeBytes) + if err != nil { + return Path{}, nil, err + } + return key, node, nil +} + func (*codecImpl) encodeBool(dst *bytes.Buffer, value bool) { bytesValue := falseBytes if value { diff --git a/x/merkledb/db.go b/x/merkledb/db.go index e5a5e1170dc8..2e9814881a66 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -41,8 +41,8 @@ const ( ) var ( - rootKey []byte - _ MerkleDB = (*merkleDB)(nil) + emptyKey []byte + _ MerkleDB = (*merkleDB)(nil) codec = newCodec() @@ -51,6 +51,7 @@ var ( intermediateNodePrefix = []byte{2} cleanShutdownKey = []byte(string(metadataPrefix) + "cleanShutdown") + rootDBKey = []byte(string(metadataPrefix) + "root") hadCleanShutdown = []byte{1} didNotHaveCleanShutdown = []byte{0} @@ -205,7 +206,7 @@ type merkleDB struct { calculateNodeIDsSema *semaphore.Weighted newPath func(p []byte) Path - rootPath Path + rootPath Path // TODO what should this be? } // New returns a new merkle database. @@ -254,7 +255,7 @@ func newDatabase( childViews: make([]*trieView, 0, defaultPreallocationSize), calculateNodeIDsSema: semaphore.NewWeighted(int64(rootGenConcurrency)), newPath: newPath, - rootPath: newPath(rootKey), + rootPath: newPath(emptyKey), } root, err := trieDB.initializeRootIfNeeded() @@ -292,7 +293,7 @@ func newDatabase( // Deletes every intermediate node and rebuilds them by re-adding every key/value. // TODO: make this more efficient by only clearing out the stale portions of the trie. func (db *merkleDB) rebuild(ctx context.Context, cacheSize int) error { - db.root = newNode(nil, db.rootPath) + db.root = newNode(nil, NewPath(emptyKey, db.valueNodeDB.branchFactor)) // Delete intermediate nodes. if err := database.ClearPrefix(db.baseDB, intermediateNodePrefix, rebuildIntermediateDeletionWriteSize); err != nil { @@ -926,7 +927,7 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e return nil } - rootChange, ok := changes.nodes[db.rootPath] + rootChange, ok := changes.nodes[changes.rootPath] if !ok { return errNoNewRoot } @@ -1151,29 +1152,30 @@ func (db *merkleDB) invalidateChildrenExcept(exception *trieView) { } func (db *merkleDB) initializeRootIfNeeded() (ids.ID, error) { - // not sure if the root exists or had a value or not - // check under both prefixes - var err error - db.root, err = db.intermediateNodeDB.Get(db.rootPath) - if err == database.ErrNotFound { - db.root, err = db.valueNodeDB.Get(db.rootPath) - } - if err == nil { - // Root already exists, so calculate its id + rootBytes, err := db.baseDB.Get(rootDBKey) + if err != nil { + if !errors.Is(err, database.ErrNotFound) { + return ids.ID{}, err + } + } else { + rootKey, root, err := codec.decodeKeyAndNode(rootBytes, db.valueNodeDB.branchFactor) + if err != nil { + return ids.ID{}, err + } + _ = rootKey // TODO remove? + db.root = root db.root.calculateID(db.metrics) return db.root.id, nil } - if err != database.ErrNotFound { - return ids.Empty, err - } // Root doesn't exist; make a new one. - db.root = newNode(nil, db.rootPath) + db.root = newNode(nil, NewPath(emptyKey, db.valueNodeDB.branchFactor)) // update its ID db.root.calculateID(db.metrics) - if err := db.intermediateNodeDB.Put(db.rootPath, db.root); err != nil { + rootBytes = codec.encodeKeyAndNode(db.root.key, &db.root.dbNode, db.valueNodeDB.branchFactor) + if err := db.baseDB.Put(rootDBKey, rootBytes); err != nil { return ids.Empty, err } diff --git a/x/merkledb/history.go b/x/merkledb/history.go index 65975f034694..6c909a7f2265 100644 --- a/x/merkledb/history.go +++ b/x/merkledb/history.go @@ -53,9 +53,10 @@ type changeSummaryAndInsertNumber struct { // Tracks all of the node and value changes that resulted in the rootID. type changeSummary struct { - rootID ids.ID - nodes map[Path]*change[*node] - values map[Path]*change[maybe.Maybe[[]byte]] + rootPath Path // TODO populate + rootID ids.ID + nodes map[Path]*change[*node] + values map[Path]*change[maybe.Maybe[[]byte]] } func newChangeSummary(estimatedSize int) *changeSummary { diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index a92970866e14..04ccbb5e28a2 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -461,7 +461,7 @@ func (t *trieView) GetRangeProof( if len(result.StartProof) == 0 && len(result.EndProof) == 0 && len(result.KeyValues) == 0 { // If the range is empty, return the root proof. - rootProof, err := t.getProof(ctx, rootKey) + rootProof, err := t.getProof(ctx, emptyKey) if err != nil { return nil, err } From c1c2d7166debb76d68baa983d805bbf617aef293 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Mon, 16 Oct 2023 15:38:56 -0400 Subject: [PATCH 002/131] WIP --- x/merkledb/codec.go | 14 +++++++------- x/merkledb/db.go | 4 +--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/x/merkledb/codec.go b/x/merkledb/codec.go index 256d3e310755..554d6cc05420 100644 --- a/x/merkledb/codec.go +++ b/x/merkledb/codec.go @@ -68,7 +68,7 @@ type encoder interface { type decoder interface { // Assumes [n] is non-nil. decodeDBNode(bytes []byte, n *dbNode, factor BranchFactor) error - decodeKeyAndNode(bytes []byte, factor BranchFactor) (Path, *node, error) + decodeKeyAndNode(bytes []byte, factor BranchFactor) (*node, error) } func newCodec() encoderDecoder { @@ -207,27 +207,27 @@ func (c *codecImpl) decodeDBNode(b []byte, n *dbNode, branchFactor BranchFactor) return nil } -func (c *codecImpl) decodeKeyAndNode(b []byte, branchFactor BranchFactor) (Path, *node, error) { +func (c *codecImpl) decodeKeyAndNode(b []byte, branchFactor BranchFactor) (*node, error) { if ids.IDLen+minDBNodeLen > len(b) { - return Path{}, nil, io.ErrUnexpectedEOF + return nil, io.ErrUnexpectedEOF } src := bytes.NewReader(b) key, err := c.decodePath(src, branchFactor) if err != nil { - return Path{}, nil, err + return nil, err } nodeBytes, err := c.decodeByteSlice(src) if err != nil { - return Path{}, nil, err + return nil, err } node, err := parseNode(key, nodeBytes) if err != nil { - return Path{}, nil, err + return nil, err } - return key, node, nil + return node, nil } func (*codecImpl) encodeBool(dst *bytes.Buffer, value bool) { diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 2e9814881a66..f9163b3ed3dc 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1158,12 +1158,10 @@ func (db *merkleDB) initializeRootIfNeeded() (ids.ID, error) { return ids.ID{}, err } } else { - rootKey, root, err := codec.decodeKeyAndNode(rootBytes, db.valueNodeDB.branchFactor) + db.root, err = codec.decodeKeyAndNode(rootBytes, db.valueNodeDB.branchFactor) if err != nil { return ids.ID{}, err } - _ = rootKey // TODO remove? - db.root = root db.root.calculateID(db.metrics) return db.root.id, nil } From fb832f768a311b63eb204d57045a0beb7c80511e Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Mon, 16 Oct 2023 15:40:40 -0400 Subject: [PATCH 003/131] nits --- x/merkledb/db.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index f9163b3ed3dc..a302c89cf8b2 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1153,11 +1153,8 @@ func (db *merkleDB) invalidateChildrenExcept(exception *trieView) { func (db *merkleDB) initializeRootIfNeeded() (ids.ID, error) { rootBytes, err := db.baseDB.Get(rootDBKey) - if err != nil { - if !errors.Is(err, database.ErrNotFound) { - return ids.ID{}, err - } - } else { + if err == nil { + // Root is on disk. db.root, err = codec.decodeKeyAndNode(rootBytes, db.valueNodeDB.branchFactor) if err != nil { return ids.ID{}, err @@ -1165,8 +1162,12 @@ func (db *merkleDB) initializeRootIfNeeded() (ids.ID, error) { db.root.calculateID(db.metrics) return db.root.id, nil } + if !errors.Is(err, database.ErrNotFound) { + return ids.ID{}, err + } - // Root doesn't exist; make a new one. + // Root not on disk; make a new one. + // TODO should we have a "fake" root? db.root = newNode(nil, NewPath(emptyKey, db.valueNodeDB.branchFactor)) // update its ID From 1866331c611d274eb73ec2dcb492d5917fdf53d5 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Mon, 16 Oct 2023 15:46:48 -0400 Subject: [PATCH 004/131] WIP --- x/merkledb/db.go | 8 +++++--- x/merkledb/trieview.go | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index a302c89cf8b2..b1cb80a9097a 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -293,7 +293,8 @@ func newDatabase( // Deletes every intermediate node and rebuilds them by re-adding every key/value. // TODO: make this more efficient by only clearing out the stale portions of the trie. func (db *merkleDB) rebuild(ctx context.Context, cacheSize int) error { - db.root = newNode(nil, NewPath(emptyKey, db.valueNodeDB.branchFactor)) + rootPath := NewPath(emptyKey, db.valueNodeDB.branchFactor) + db.root = newNode(nil, rootPath) // Delete intermediate nodes. if err := database.ClearPrefix(db.baseDB, intermediateNodePrefix, rebuildIntermediateDeletionWriteSize); err != nil { @@ -1168,7 +1169,8 @@ func (db *merkleDB) initializeRootIfNeeded() (ids.ID, error) { // Root not on disk; make a new one. // TODO should we have a "fake" root? - db.root = newNode(nil, NewPath(emptyKey, db.valueNodeDB.branchFactor)) + rootPath := NewPath(emptyKey, db.valueNodeDB.branchFactor) + db.root = newNode(nil, rootPath) // update its ID db.root.calculateID(db.metrics) @@ -1254,7 +1256,7 @@ func (db *merkleDB) getNode(key Path, hasValue bool) (*node, error) { switch { case db.closed: return nil, database.ErrClosed - case key == db.rootPath: + case key == db.root.key: return db.root, nil case hasValue: return db.valueNodeDB.Get(key) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 04ccbb5e28a2..ed985acafd11 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -145,7 +145,7 @@ func newTrieView( parentTrie TrieView, changes ViewChanges, ) (*trieView, error) { - root, err := parentTrie.getEditableNode(db.rootPath, false /* hasValue */) + root, err := parentTrie.getEditableNode(Path{} /*TODO pass root key*/, false /* hasValue */) if err != nil { if err == database.ErrNotFound { return nil, ErrNoValidRoot @@ -197,7 +197,7 @@ func newHistoricalTrieView( return nil, ErrNoValidRoot } - passedRootChange, ok := changes.nodes[db.rootPath] + passedRootChange, ok := changes.nodes[changes.rootPath] if !ok { return nil, ErrNoValidRoot } From 86161695e151e8a3f062bef57938a2b2257b6afb Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Mon, 16 Oct 2023 15:52:15 -0400 Subject: [PATCH 005/131] add getRootKey --- x/merkledb/db.go | 4 ++++ x/merkledb/trie.go | 2 ++ x/merkledb/trieview.go | 6 +++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index b1cb80a9097a..f16ef74aacd6 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1264,6 +1264,10 @@ func (db *merkleDB) getNode(key Path, hasValue bool) (*node, error) { return db.intermediateNodeDB.Get(key) } +func (db *merkleDB) getRootKey() Path { + return db.root.key +} + // Returns [key] prefixed by [prefix]. // The returned []byte is taken from [bufferPool] and // should be returned to it when the caller is done with it. diff --git a/x/merkledb/trie.go b/x/merkledb/trie.go index 998cd34f9ed2..2d0f26bf37d6 100644 --- a/x/merkledb/trie.go +++ b/x/merkledb/trie.go @@ -38,6 +38,8 @@ type ReadOnlyTrie interface { // database.ErrNotFound if the key is not present getValue(key Path) ([]byte, error) + getRootKey() Path + // get an editable copy of the node with the given key path // hasValue indicates which db to look in (value or intermediate) getEditableNode(key Path, hasValue bool) (*node, error) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index ed985acafd11..5c87d311adc6 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -145,7 +145,7 @@ func newTrieView( parentTrie TrieView, changes ViewChanges, ) (*trieView, error) { - root, err := parentTrie.getEditableNode(Path{} /*TODO pass root key*/, false /* hasValue */) + root, err := parentTrie.getEditableNode(parentTrie.getRootKey(), false /* hasValue */) if err != nil { if err == database.ErrNotFound { return nil, ErrNoValidRoot @@ -215,6 +215,10 @@ func newHistoricalTrieView( return newView, nil } +func (t *trieView) getRootKey() Path { + return t.root.key +} + // Recalculates the node IDs for all changed nodes in the trie. // Cancelling [ctx] doesn't cancel calculation. It's used only for tracing. func (t *trieView) calculateNodeIDs(ctx context.Context) error { From 4f14e23282460acbbc3faf1263587a3af4b7bcfc Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Mon, 16 Oct 2023 16:09:58 -0400 Subject: [PATCH 006/131] populate rootPath --- x/merkledb/db.go | 11 +++++------ x/merkledb/history.go | 32 +++++++++++++++++++++----------- x/merkledb/history_test.go | 2 +- x/merkledb/trieview.go | 7 ++++++- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index f16ef74aacd6..96224c1acc52 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -205,8 +205,7 @@ type merkleDB struct { // [calculateNodeIDsHelper] at any given time. calculateNodeIDsSema *semaphore.Weighted - newPath func(p []byte) Path - rootPath Path // TODO what should this be? + newPath func(p []byte) Path } // New returns a new merkle database. @@ -255,7 +254,6 @@ func newDatabase( childViews: make([]*trieView, 0, defaultPreallocationSize), calculateNodeIDsSema: semaphore.NewWeighted(int64(rootGenConcurrency)), newPath: newPath, - rootPath: newPath(emptyKey), } root, err := trieDB.initializeRootIfNeeded() @@ -265,9 +263,10 @@ func newDatabase( // add current root to history (has no changes) trieDB.history.record(&changeSummary{ - rootID: root, - values: map[Path]*change[maybe.Maybe[[]byte]]{}, - nodes: map[Path]*change[*node]{}, + rootPath: trieDB.root.key, + rootID: root, + values: map[Path]*change[maybe.Maybe[[]byte]]{}, + nodes: map[Path]*change[*node]{}, }) shutdownType, err := trieDB.baseDB.Get(cleanShutdownKey) diff --git a/x/merkledb/history.go b/x/merkledb/history.go index 6c909a7f2265..6988920ecdfd 100644 --- a/x/merkledb/history.go +++ b/x/merkledb/history.go @@ -53,13 +53,15 @@ type changeSummaryAndInsertNumber struct { // Tracks all of the node and value changes that resulted in the rootID. type changeSummary struct { - rootPath Path // TODO populate - rootID ids.ID - nodes map[Path]*change[*node] - values map[Path]*change[maybe.Maybe[[]byte]] + // The key of the root after these changes. + rootPath Path + // The ID of the trie after these changes. + rootID ids.ID + nodes map[Path]*change[*node] + values map[Path]*change[maybe.Maybe[[]byte]] } -func newChangeSummary(estimatedSize int) *changeSummary { +func newChangeSummary(estimatedSize int, endRootID ids.ID, endRootKey Path) *changeSummary { return &changeSummary{ nodes: make(map[Path]*change[*node], estimatedSize), values: make(map[Path]*change[maybe.Maybe[[]byte]], estimatedSize), @@ -92,10 +94,6 @@ func (th *trieHistory) getValueChanges( return nil, fmt.Errorf("%w but was %d", ErrInvalidMaxLength, maxLength) } - if startRoot == endRoot { - return newChangeSummary(maxLength), nil - } - // [endRootChanges] is the last change in the history resulting in [endRoot]. // TODO when we update to minimum go version 1.20.X, make this return another // wrapped error ErrNoEndRoot. In NetworkServer.HandleChangeProofRequest, if we return @@ -106,6 +104,10 @@ func (th *trieHistory) getValueChanges( return nil, fmt.Errorf("%w: end root %s not found", ErrInsufficientHistory, endRoot) } + if startRoot == endRoot { + return newChangeSummary(maxLength, endRoot, endRootChanges.rootPath), nil + } + // Confirm there's a change resulting in [startRoot] before // a change resulting in [endRoot] in the history. // [startRootChanges] is the last appearance of [startRoot]. @@ -166,7 +168,7 @@ func (th *trieHistory) getValueChanges( // last appearance (exclusive) and [endRoot]'s last appearance (inclusive), // add the changes to keys in [start, end] to [combinedChanges]. // Only the key-value pairs with the greatest [maxLength] keys will be kept. - combinedChanges = newChangeSummary(maxLength) + combinedChanges = newChangeSummary(maxLength, endRoot, Path{} /*populated last iteration*/) // The difference between the index of [startRootChanges] and [endRootChanges] in [th.history]. startToEndOffset = int(endRootChanges.insertNumber - startRootChanges.insertNumber) @@ -181,6 +183,10 @@ func (th *trieHistory) getValueChanges( for i := startRootIndex + 1; i <= endRootIndex; i++ { changes, _ := th.history.Index(i) + if i == endRootIndex { + combinedChanges.rootPath = changes.rootPath + } + // Add the changes from this commit to [combinedChanges]. for key, valueChange := range changes.values { // The key is outside the range [start, end]. @@ -240,7 +246,7 @@ func (th *trieHistory) getChangesToGetToRoot(rootID ids.ID, start maybe.Maybe[[] var ( startPath = maybe.Bind(start, th.newPath) endPath = maybe.Bind(end, th.newPath) - combinedChanges = newChangeSummary(defaultPreallocationSize) + combinedChanges = newChangeSummary(defaultPreallocationSize, rootID, Path{} /*populated first iteration*/) mostRecentChangeInsertNumber = th.nextInsertNumber - 1 mostRecentChangeIndex = th.history.Len() - 1 offset = int(mostRecentChangeInsertNumber - lastRootChange.insertNumber) @@ -253,6 +259,10 @@ func (th *trieHistory) getChangesToGetToRoot(rootID ids.ID, start maybe.Maybe[[] for i := mostRecentChangeIndex; i > lastRootChangeIndex; i-- { changes, _ := th.history.Index(i) + if i == mostRecentChangeIndex { + combinedChanges.rootPath = changes.rootPath + } + for key, changedNode := range changes.nodes { combinedChanges.nodes[key] = &change[*node]{ after: changedNode.before, diff --git a/x/merkledb/history_test.go b/x/merkledb/history_test.go index 94627aef0d90..6664ad2400ad 100644 --- a/x/merkledb/history_test.go +++ b/x/merkledb/history_test.go @@ -690,7 +690,7 @@ func TestHistoryGetChangesToRoot(t *testing.T) { name: "most recent change", rootID: changes[maxHistoryLen-1].rootID, validateFunc: func(require *require.Assertions, got *changeSummary) { - require.Equal(newChangeSummary(defaultPreallocationSize), got) + require.Equal(newChangeSummary(defaultPreallocationSize, ids.Empty /*TODO*/, Path{} /*TODO*/), got) }, }, { diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 5c87d311adc6..9ef6a89d42d2 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -153,11 +153,16 @@ func newTrieView( return nil, err } + parentRoot, err := parentTrie.GetMerkleRoot(context.Background()) + if err != nil { + return nil, err + } + newView := &trieView{ root: root, db: db, parentTrie: parentTrie, - changes: newChangeSummary(len(changes.BatchOps) + len(changes.MapOps)), + changes: newChangeSummary(len(changes.BatchOps)+len(changes.MapOps), parentRoot, root.key), } for _, op := range changes.BatchOps { From 5d9a7c1bccb42b6ef540e6f61535cf5935fd170b Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Mon, 16 Oct 2023 16:24:33 -0400 Subject: [PATCH 007/131] WIP update getPathTo --- x/merkledb/history.go | 6 ++++-- x/merkledb/trieview.go | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/x/merkledb/history.go b/x/merkledb/history.go index 6988920ecdfd..34f5087a1d3a 100644 --- a/x/merkledb/history.go +++ b/x/merkledb/history.go @@ -63,8 +63,10 @@ type changeSummary struct { func newChangeSummary(estimatedSize int, endRootID ids.ID, endRootKey Path) *changeSummary { return &changeSummary{ - nodes: make(map[Path]*change[*node], estimatedSize), - values: make(map[Path]*change[maybe.Maybe[[]byte]], estimatedSize), + rootID: endRootID, + rootPath: endRootKey, + nodes: make(map[Path]*change[*node], estimatedSize), + values: make(map[Path]*change[maybe.Maybe[[]byte]], estimatedSize), } } diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 9ef6a89d42d2..5b2d6e2a94fc 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -351,6 +351,8 @@ func (t *trieView) getProof(ctx context.Context, key []byte) (*Proof, error) { return nil, err } + // TODO handle len(proofPath) == 0 + // From root --> node from left --> right. proof.Path = make([]ProofNode, len(proofPath), len(proofPath)+1) for i, node := range proofPath { @@ -632,6 +634,10 @@ func (t *trieView) remove(key Path) error { if err != nil { return err } + if len(nodePath) == 0 { + // the key wasn't in the trie + return nil + } nodeToDelete := nodePath[len(nodePath)-1] @@ -760,12 +766,18 @@ func (t *trieView) deleteEmptyNodes(nodePath []*node) error { // The first node is the root, and the last node is either the node with the // given [key], if it's in the trie, or the node with the largest prefix of // the [key] if it isn't in the trie. -// Always returns at least the root node. func (t *trieView) getPathTo(key Path) ([]*node, error) { + if !key.HasPrefix(t.root.key) { + return nil, nil + } + if key == t.root.key { + return []*node{t.root}, nil + } + var ( // all node paths start at the root currentNode = t.root - matchedPathIndex = 0 + matchedPathIndex = t.root.key.tokensLength nodes = []*node{t.root} ) @@ -844,6 +856,10 @@ func (t *trieView) insert( return nil, err } + // TODO handle new root creation + //if len(pathToNode) == 0 { + //} + // We're inserting a node whose ancestry is [pathToNode] // so we'll need to recalculate their IDs. for _, node := range pathToNode { From 1067d7c6be9fcd8736e9c60454a0a5f5f0e76da1 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 17 Oct 2023 10:53:39 -0400 Subject: [PATCH 008/131] update insert --- x/merkledb/trieview.go | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 5b2d6e2a94fc..b7f92d9d5232 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -857,8 +857,30 @@ func (t *trieView) insert( } // TODO handle new root creation - //if len(pathToNode) == 0 { - //} + if len(pathToNode) == 0 { + // [t.root.key] isn't a prefix of [key]. + commonPrefixLength := getLengthOfCommonPrefix(t.root.key, key, 0 /*offset*/) + commonPrefix := t.root.key.Take(commonPrefixLength) + oldRoot := t.root + t.root = newNode(nil, commonPrefix) + t.root.addChild(oldRoot) + + if commonPrefix == key { + // [key] is a prefix of [t.root.key] so it should be the new root. + t.root.setValue(value) + t.recordNewNode(t.root) + return t.root, nil + } + + // Neither [key] nor [t.root.key] is a prefix of the other. + // Make a new root whose children are the old root and the new node. + t.root.addChild(oldRoot) + newValueNode := newNode(t.root, key) + newValueNode.setValue(value) + t.recordNewNode(t.root) + t.recordNewNode(newValueNode) + return newValueNode, nil + } // We're inserting a node whose ancestry is [pathToNode] // so we'll need to recalculate their IDs. @@ -961,10 +983,11 @@ func (t *trieView) recordNodeChange(after *node) error { // Records that the node associated with the given key has been deleted. // Must not be called after [calculateNodeIDs] has returned. func (t *trieView) recordNodeDeleted(after *node) error { + // TODO remove // don't delete the root. - if after.key.tokensLength == 0 { - return t.recordKeyChange(after.key, after, after.hasValue(), false /* newNode */) - } + //if after.key.tokensLength == 0 { + // return t.recordKeyChange(after.key, after, after.hasValue(), false /* newNode */) + //} return t.recordKeyChange(after.key, nil, after.hasValue(), false /* newNode */) } From f73f6d281405c5017171509642ed615fe0e143c9 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 17 Oct 2023 11:00:26 -0400 Subject: [PATCH 009/131] remove TODOs --- x/merkledb/proof.go | 2 +- x/merkledb/trieview.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/x/merkledb/proof.go b/x/merkledb/proof.go index 23cc7a3532ec..7b164529ca07 100644 --- a/x/merkledb/proof.go +++ b/x/merkledb/proof.go @@ -127,7 +127,7 @@ func (node *ProofNode) UnmarshalProto(pbNode *pb.ProofNode, bf BranchFactor) err type Proof struct { // Nodes in the proof path from root --> target key // (or node that would be where key is if it doesn't exist). - // Must always be non-empty (i.e. have the root node). + // Must always be non-empty (i.e. have the root node). TODO remove Path []ProofNode // This is a proof that [key] exists/doesn't exist. Key Path diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index b7f92d9d5232..48c03326961f 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -351,7 +351,9 @@ func (t *trieView) getProof(ctx context.Context, key []byte) (*Proof, error) { return nil, err } - // TODO handle len(proofPath) == 0 + if len(proofPath) == 0 { + return proof, nil + } // From root --> node from left --> right. proof.Path = make([]ProofNode, len(proofPath), len(proofPath)+1) @@ -856,7 +858,6 @@ func (t *trieView) insert( return nil, err } - // TODO handle new root creation if len(pathToNode) == 0 { // [t.root.key] isn't a prefix of [key]. commonPrefixLength := getLengthOfCommonPrefix(t.root.key, key, 0 /*offset*/) From f41a29f458616be71e39ae593c6e72627324eeac Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 17 Oct 2023 11:31:57 -0400 Subject: [PATCH 010/131] remove EndProof invariant on RangeProof --- x/merkledb/proof.go | 29 ++++++++++++++--------------- x/merkledb/trieview.go | 18 ++++++++++-------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/x/merkledb/proof.go b/x/merkledb/proof.go index 7b164529ca07..455b18268ddb 100644 --- a/x/merkledb/proof.go +++ b/x/merkledb/proof.go @@ -255,16 +255,12 @@ type RangeProof struct { // they are also in [EndProof]. StartProof []ProofNode - // If no upper range bound was given, [KeyValues] is empty, - // and [StartProof] is non-empty, this is empty. + // If no upper range bound was given and [KeyValues] is empty, this is empty. // - // If no upper range bound was given, [KeyValues] is empty, - // and [StartProof] is empty, this is the root. + // If no upper range bound was given and [KeyValues] is non-empty, this is + // a proof for the largest key in [KeyValues]. // - // If an upper range bound was given and [KeyValues] is empty, - // this is a proof for the upper range bound. - // - // Otherwise, this is a proof for the largest key in [KeyValues]. + // Otherwise this is a proof for the upper range bound. EndProof []ProofNode // This proof proves that the key-value pairs in [KeyValues] are in the trie. @@ -293,21 +289,24 @@ func (proof *RangeProof) Verify( return ErrStartAfterEnd case len(proof.KeyValues) == 0 && len(proof.StartProof) == 0 && len(proof.EndProof) == 0: return ErrNoMerkleProof - case end.IsNothing() && len(proof.KeyValues) == 0 && len(proof.StartProof) > 0 && len(proof.EndProof) != 0: - return ErrUnexpectedEndProof - case end.IsNothing() && len(proof.KeyValues) == 0 && len(proof.StartProof) == 0 && len(proof.EndProof) != 1: - return ErrShouldJustBeRoot + // TODO remove + //case end.IsNothing() && len(proof.KeyValues) == 0 && len(proof.StartProof) > 0 && len(proof.EndProof) != 0: + // return ErrUnexpectedEndProof + //case end.IsNothing() && len(proof.KeyValues) == 0 && len(proof.StartProof) == 0 && len(proof.EndProof) != 1: + // return ErrShouldJustBeRoot case len(proof.EndProof) == 0 && (end.HasValue() || len(proof.KeyValues) > 0): return ErrNoEndProof } // determine branch factor based on proof paths var branchFactor BranchFactor - if len(proof.StartProof) > 0 { + switch { + case len(proof.StartProof) > 0: branchFactor = proof.StartProof[0].KeyPath.branchFactor - } else { - // safe because invariants prevent both start proof and end proof from being empty at the same time + case len(proof.EndProof) > 0: branchFactor = proof.EndProof[0].KeyPath.branchFactor + default: + // TODO Get branch factor } // Make sure the key-value pairs are sorted and in [start, end]. diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 48c03326961f..c4403dc2f24e 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -338,6 +338,7 @@ func (t *trieView) GetProof(ctx context.Context, key []byte) (*Proof, error) { } // Returns a proof that [bytesPath] is in or not in trie [t]. +// TODO find places broken by this returning proofs with empty paths func (t *trieView) getProof(ctx context.Context, key []byte) (*Proof, error) { _, span := t.db.infoTracer.Start(ctx, "MerkleDB.trieview.getProof") defer span.End() @@ -472,14 +473,15 @@ func (t *trieView) GetRangeProof( result.StartProof = result.StartProof[i:] } - if len(result.StartProof) == 0 && len(result.EndProof) == 0 && len(result.KeyValues) == 0 { - // If the range is empty, return the root proof. - rootProof, err := t.getProof(ctx, emptyKey) - if err != nil { - return nil, err - } - result.EndProof = rootProof.Path - } + // TODO remove + // if len(result.StartProof) == 0 && len(result.EndProof) == 0 && len(result.KeyValues) == 0 { + // // If the range is empty, return the root proof. + // rootProof, err := t.getProof(ctx, emptyKey) + // if err != nil { + // return nil, err + // } + // result.EndProof = rootProof.Path + // } if t.isInvalid() { return nil, ErrInvalid From fc64ec30cb0363e3c869e570548913af2d05db9a Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 17 Oct 2023 12:33:43 -0400 Subject: [PATCH 011/131] all UT in merkledb pass --- x/merkledb/codec.go | 31 ++++++++++++++----------------- x/merkledb/codec_test.go | 26 ++++++++++++++++++++++++++ x/merkledb/db.go | 12 +++++++++++- x/merkledb/db_test.go | 2 +- x/merkledb/history_test.go | 3 ++- x/merkledb/proof.go | 5 +++-- x/merkledb/proof_test.go | 34 ++++++++++++++++++---------------- 7 files changed, 75 insertions(+), 38 deletions(-) diff --git a/x/merkledb/codec.go b/x/merkledb/codec.go index 554d6cc05420..94b0639c34e4 100644 --- a/x/merkledb/codec.go +++ b/x/merkledb/codec.go @@ -68,7 +68,7 @@ type encoder interface { type decoder interface { // Assumes [n] is non-nil. decodeDBNode(bytes []byte, n *dbNode, factor BranchFactor) error - decodeKeyAndNode(bytes []byte, factor BranchFactor) (*node, error) + decodeKeyAndNode(bytes []byte, n *dbNode, factor BranchFactor) (Path, error) // TODO should this return a Path? } func newCodec() encoderDecoder { @@ -148,13 +148,11 @@ func (c *codecImpl) encodeKeyAndNode(key Path, n *dbNode, factor BranchFactor) [ return buf.Bytes() } -func (c *codecImpl) decodeDBNode(b []byte, n *dbNode, branchFactor BranchFactor) error { - if minDBNodeLen > len(b) { +func (c *codecImpl) decodeDBNodeFromReader(src *bytes.Reader, n *dbNode, branchFactor BranchFactor) error { + if minDBNodeLen > src.Len() { return io.ErrUnexpectedEOF } - src := bytes.NewReader(b) - value, err := c.decodeMaybeByteSlice(src) if err != nil { return err @@ -207,27 +205,26 @@ func (c *codecImpl) decodeDBNode(b []byte, n *dbNode, branchFactor BranchFactor) return nil } -func (c *codecImpl) decodeKeyAndNode(b []byte, branchFactor BranchFactor) (*node, error) { - if ids.IDLen+minDBNodeLen > len(b) { - return nil, io.ErrUnexpectedEOF +func (c *codecImpl) decodeDBNode(b []byte, n *dbNode, branchFactor BranchFactor) error { + return c.decodeDBNodeFromReader(bytes.NewReader(b), n, branchFactor) +} + +func (c *codecImpl) decodeKeyAndNode(b []byte, n *dbNode, branchFactor BranchFactor) (Path, error) { + if minPathLen+minDBNodeLen > len(b) { + return Path{}, io.ErrUnexpectedEOF } src := bytes.NewReader(b) key, err := c.decodePath(src, branchFactor) if err != nil { - return nil, err + return Path{}, err } - nodeBytes, err := c.decodeByteSlice(src) - if err != nil { - return nil, err - } - node, err := parseNode(key, nodeBytes) - if err != nil { - return nil, err + if err := c.decodeDBNodeFromReader(src, n, branchFactor); err != nil { + return Path{}, err } - return node, nil + return key, nil } func (*codecImpl) encodeBool(dst *bytes.Buffer, value bool) { diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index 24bc6b061524..1c4aac9214d6 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -270,3 +270,29 @@ func TestCodecDecodePathLengthOverflowRegression(t *testing.T) { _, err := codec.decodePath(bytes, BranchFactor16) require.ErrorIs(t, err, io.ErrUnexpectedEOF) } + +// TODO make fuzz test +func TestEncodeDecodeKeyAndNode(t *testing.T) { + require := require.New(t) + codec := newCodec() + + for _, branchFactor := range branchFactors { + key := NewPath([]byte{1, 2, 3}, branchFactor) + expectedNode := &dbNode{ + value: maybe.Some([]byte{1}), + children: map[byte]child{ + 0: { + compressedPath: NewPath([]byte{2, 3}, branchFactor), + id: ids.GenerateTestID(), + hasValue: true, + }, + }, + } + b := codec.encodeKeyAndNode(key, expectedNode, branchFactor) + var gotNode dbNode + gotKey, err := codec.decodeKeyAndNode(b, &gotNode, branchFactor) + require.NoError(err) + require.Equal(expectedNode, &gotNode) + require.Equal(key, gotKey) + } +} diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 96224c1acc52..16d34509f119 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -972,6 +972,10 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e // Only modify in-memory state after the commit succeeds // so that we don't need to clean up on error. db.root = rootChange.after + rootKeyAndNodeBytes := codec.encodeKeyAndNode(db.root.key, &db.root.dbNode, db.valueNodeDB.branchFactor) + if err := db.baseDB.Put(rootDBKey, rootKeyAndNodeBytes); err != nil { + return err + } db.history.record(changes) return nil } @@ -1155,10 +1159,16 @@ func (db *merkleDB) initializeRootIfNeeded() (ids.ID, error) { rootBytes, err := db.baseDB.Get(rootDBKey) if err == nil { // Root is on disk. - db.root, err = codec.decodeKeyAndNode(rootBytes, db.valueNodeDB.branchFactor) + var rootDBNode dbNode + rootKey, err := codec.decodeKeyAndNode(rootBytes, &rootDBNode, db.valueNodeDB.branchFactor) if err != nil { return ids.ID{}, err } + db.root = &node{ + dbNode: rootDBNode, + key: rootKey, + } + db.root.setValueDigest() db.root.calculateID(db.metrics) return db.root.id, nil } diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index a2e1cdc30f71..26f04d253429 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -150,7 +150,7 @@ func Test_MerkleDB_DB_Load_Root_From_DB(t *testing.T) { require.NoError(db.Close()) - // reloading the db, should set the root back to the one that was saved to [baseDB] + // reloading the db should set the root back to the one that was saved to [baseDB] db, err = New( context.Background(), baseDB, diff --git a/x/merkledb/history_test.go b/x/merkledb/history_test.go index 6664ad2400ad..3828aa04af91 100644 --- a/x/merkledb/history_test.go +++ b/x/merkledb/history_test.go @@ -690,7 +690,8 @@ func TestHistoryGetChangesToRoot(t *testing.T) { name: "most recent change", rootID: changes[maxHistoryLen-1].rootID, validateFunc: func(require *require.Assertions, got *changeSummary) { - require.Equal(newChangeSummary(defaultPreallocationSize, ids.Empty /*TODO*/, Path{} /*TODO*/), got) + expected := newChangeSummary(defaultPreallocationSize, changes[maxHistoryLen-1].rootID, changes[maxHistoryLen-1].rootPath) + require.Equal(expected, got) }, }, { diff --git a/x/merkledb/proof.go b/x/merkledb/proof.go index 455b18268ddb..f018b77b9bfe 100644 --- a/x/merkledb/proof.go +++ b/x/merkledb/proof.go @@ -290,8 +290,8 @@ func (proof *RangeProof) Verify( case len(proof.KeyValues) == 0 && len(proof.StartProof) == 0 && len(proof.EndProof) == 0: return ErrNoMerkleProof // TODO remove - //case end.IsNothing() && len(proof.KeyValues) == 0 && len(proof.StartProof) > 0 && len(proof.EndProof) != 0: - // return ErrUnexpectedEndProof + case end.IsNothing() && len(proof.KeyValues) == 0 && /*len(proof.StartProof) > 0 &&*/ len(proof.EndProof) != 0: + return ErrUnexpectedEndProof //case end.IsNothing() && len(proof.KeyValues) == 0 && len(proof.StartProof) == 0 && len(proof.EndProof) != 1: // return ErrShouldJustBeRoot case len(proof.EndProof) == 0 && (end.HasValue() || len(proof.KeyValues) > 0): @@ -307,6 +307,7 @@ func (proof *RangeProof) Verify( branchFactor = proof.EndProof[0].KeyPath.branchFactor default: // TODO Get branch factor + branchFactor = BranchFactor16 } // Make sure the key-value pairs are sorted and in [start, end]. diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index b288fe74bb4f..d893c47498e6 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -304,13 +304,14 @@ func Test_RangeProof_Syntactic_Verify(t *testing.T) { proof: &RangeProof{}, expectedErr: ErrStartAfterEnd, }, - { - name: "empty", // Also tests start can be > end if end is nil - start: maybe.Some([]byte{1}), - end: maybe.Nothing[[]byte](), - proof: &RangeProof{}, - expectedErr: ErrNoMerkleProof, - }, + // TODO remove + // { + // name: "empty", // Also tests start can be > end if end is nil + // start: maybe.Some([]byte{1}), + // end: maybe.Nothing[[]byte](), + // proof: &RangeProof{}, + // expectedErr: ErrNoMerkleProof, + // }, { name: "unexpected end proof", start: maybe.Some([]byte{1}), @@ -321,15 +322,16 @@ func Test_RangeProof_Syntactic_Verify(t *testing.T) { }, expectedErr: ErrUnexpectedEndProof, }, - { - name: "should just be root", - start: maybe.Nothing[[]byte](), - end: maybe.Nothing[[]byte](), - proof: &RangeProof{ - EndProof: []ProofNode{{}, {}}, - }, - expectedErr: ErrShouldJustBeRoot, - }, + // TODO remove + // { + // name: "should just be root", + // start: maybe.Nothing[[]byte](), + // end: maybe.Nothing[[]byte](), + // proof: &RangeProof{ + // EndProof: []ProofNode{{}, {}}, + // }, + // expectedErr: ErrShouldJustBeRoot, + // }, { name: "no end proof; has end bound", start: maybe.Some([]byte{1}), From a4b76f494b427d6081afe88c349a074534e574bd Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 17 Oct 2023 12:43:43 -0400 Subject: [PATCH 012/131] appease linter --- x/merkledb/proof.go | 5 +---- x/merkledb/trieview.go | 15 +++++---------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/x/merkledb/proof.go b/x/merkledb/proof.go index f018b77b9bfe..f0fd30b73410 100644 --- a/x/merkledb/proof.go +++ b/x/merkledb/proof.go @@ -289,11 +289,8 @@ func (proof *RangeProof) Verify( return ErrStartAfterEnd case len(proof.KeyValues) == 0 && len(proof.StartProof) == 0 && len(proof.EndProof) == 0: return ErrNoMerkleProof - // TODO remove - case end.IsNothing() && len(proof.KeyValues) == 0 && /*len(proof.StartProof) > 0 &&*/ len(proof.EndProof) != 0: + case end.IsNothing() && len(proof.KeyValues) == 0 && len(proof.EndProof) != 0: return ErrUnexpectedEndProof - //case end.IsNothing() && len(proof.KeyValues) == 0 && len(proof.StartProof) == 0 && len(proof.EndProof) != 1: - // return ErrShouldJustBeRoot case len(proof.EndProof) == 0 && (end.HasValue() || len(proof.KeyValues) > 0): return ErrNoEndProof } diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index c4403dc2f24e..c16040b410c8 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -871,8 +871,7 @@ func (t *trieView) insert( if commonPrefix == key { // [key] is a prefix of [t.root.key] so it should be the new root. t.root.setValue(value) - t.recordNewNode(t.root) - return t.root, nil + return t.root, t.recordNewNode(t.root) } // Neither [key] nor [t.root.key] is a prefix of the other. @@ -880,9 +879,10 @@ func (t *trieView) insert( t.root.addChild(oldRoot) newValueNode := newNode(t.root, key) newValueNode.setValue(value) - t.recordNewNode(t.root) - t.recordNewNode(newValueNode) - return newValueNode, nil + if err := t.recordNewNode(t.root); err != nil { + return nil, err + } + return newValueNode, t.recordNewNode(newValueNode) } // We're inserting a node whose ancestry is [pathToNode] @@ -986,11 +986,6 @@ func (t *trieView) recordNodeChange(after *node) error { // Records that the node associated with the given key has been deleted. // Must not be called after [calculateNodeIDs] has returned. func (t *trieView) recordNodeDeleted(after *node) error { - // TODO remove - // don't delete the root. - //if after.key.tokensLength == 0 { - // return t.recordKeyChange(after.key, after, after.hasValue(), false /* newNode */) - //} return t.recordKeyChange(after.key, nil, after.hasValue(), false /* newNode */) } From 4275b075bb232aefa02eb530b76104c837a4fde2 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 17 Oct 2023 12:57:11 -0400 Subject: [PATCH 013/131] handle root deletion --- x/merkledb/trieview.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index c16040b410c8..becd86c48504 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -665,6 +665,10 @@ func (t *trieView) remove(key Path) error { // if the removed node has no children, the node can be removed from the trie if len(nodeToDelete.children) == 0 { + if nodeToDelete.key == t.root.key { + t.root = nil // TODO how to handle empty trie? + return nil + } return t.deleteEmptyNodes(nodePath) } From 01b9f4bd9d53f3da44ff8f3bacc2e0912146efca Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 17 Oct 2023 13:32:39 -0400 Subject: [PATCH 014/131] handle root deletion pt 2 --- x/merkledb/trieview.go | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index becd86c48504..7d5d366bbec7 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -663,18 +663,40 @@ func (t *trieView) remove(key Path) error { return err } - // if the removed node has no children, the node can be removed from the trie - if len(nodeToDelete.children) == 0 { - if nodeToDelete.key == t.root.key { + if nodeToDelete.key == t.root.key { + // We're deleting the root. + switch len(nodeToDelete.children) { + case 0: + // The trie is empty now. t.root = nil // TODO how to handle empty trie? + return t.recordNodeDeleted(nodeToDelete) + case 1: + // The root has one child, so make that child the new root. + var ( + childIndex byte + child child + ) + for childIndex, child = range nodeToDelete.children { + break + } + childKey := nodeToDelete.key.AppendExtend(childIndex, child.compressedPath) + newRoot, err := t.getNodeWithID(child.id, childKey, child.hasValue) + if err != nil { + return err + } + t.root = newRoot + return nil + default: + // The root has multiple children so we can't delete it. return nil } - return t.deleteEmptyNodes(nodePath) } - if len(nodePath) == 1 { - return nil + // if the removed node has no children, the node can be removed from the trie + if len(nodeToDelete.children) == 0 { + return t.deleteEmptyNodes(nodePath) } + parent := nodePath[len(nodePath)-2] // merge this node and its descendants into a single node if possible From 6bf8ce2fc8b5b41a5efe000b02fefd93b92f0c22 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 17 Oct 2023 13:38:16 -0400 Subject: [PATCH 015/131] comment --- x/merkledb/trieview.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 7d5d366bbec7..b6b14c475a81 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -697,6 +697,7 @@ func (t *trieView) remove(key Path) error { return t.deleteEmptyNodes(nodePath) } + // Note len(nodePath) >= 2 since [nodeToDelete.key] != [t.root.key]. parent := nodePath[len(nodePath)-2] // merge this node and its descendants into a single node if possible From 5ae830d60325afe1514904a35a88294636fdba16 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 17 Oct 2023 15:29:26 -0400 Subject: [PATCH 016/131] WIP --- x/merkledb/db.go | 96 +++++++++++++++---------------- x/merkledb/history.go | 25 +++----- x/merkledb/history_test.go | 14 ++--- x/merkledb/proof_test.go | 12 ++-- x/merkledb/trie.go | 4 +- x/merkledb/trieview.go | 113 +++++++++++++++++++++++-------------- 6 files changed, 143 insertions(+), 121 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 16d34509f119..031981872e96 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -196,7 +196,7 @@ type merkleDB struct { infoTracer trace.Tracer // The root of this trie. - root *node + root maybe.Maybe[*node] // Valid children of this trie. childViews []*trieView @@ -263,10 +263,9 @@ func newDatabase( // add current root to history (has no changes) trieDB.history.record(&changeSummary{ - rootPath: trieDB.root.key, - rootID: root, - values: map[Path]*change[maybe.Maybe[[]byte]]{}, - nodes: map[Path]*change[*node]{}, + rootID: root, + values: map[Path]*change[maybe.Maybe[[]byte]]{}, + nodes: map[Path]*change[*node]{}, }) shutdownType, err := trieDB.baseDB.Get(cleanShutdownKey) @@ -293,7 +292,7 @@ func newDatabase( // TODO: make this more efficient by only clearing out the stale portions of the trie. func (db *merkleDB) rebuild(ctx context.Context, cacheSize int) error { rootPath := NewPath(emptyKey, db.valueNodeDB.branchFactor) - db.root = newNode(nil, rootPath) + db.root = maybe.Some(newNode(nil, rootPath)) // todo what to do here? // Delete intermediate nodes. if err := database.ClearPrefix(db.baseDB, intermediateNodePrefix, rebuildIntermediateDeletionWriteSize); err != nil { @@ -581,7 +580,10 @@ func (db *merkleDB) GetMerkleRoot(ctx context.Context) (ids.ID, error) { // Assumes [db.lock] is read locked. func (db *merkleDB) getMerkleRoot() ids.ID { - return db.root.id + if db.root.IsNothing() { + return ids.Empty // TODO document this + } + return db.root.Value().id } func (db *merkleDB) GetProof(ctx context.Context, key []byte) (*Proof, error) { @@ -927,15 +929,13 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e return nil } - rootChange, ok := changes.nodes[changes.rootPath] - if !ok { - return errNoNewRoot - } - + var root *node currentValueNodeBatch := db.valueNodeDB.NewBatch() - _, nodesSpan := db.infoTracer.Start(ctx, "MerkleDB.commitChanges.writeNodes") for key, nodeChange := range changes.nodes { + if nodeChange.after != nil && nodeChange.after.id == changes.rootID { + root = nodeChange.after + } shouldAddIntermediate := nodeChange.after != nil && !nodeChange.after.hasValue() shouldDeleteIntermediate := !shouldAddIntermediate && nodeChange.before != nil && !nodeChange.before.hasValue() @@ -971,10 +971,21 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e // Only modify in-memory state after the commit succeeds // so that we don't need to clean up on error. - db.root = rootChange.after - rootKeyAndNodeBytes := codec.encodeKeyAndNode(db.root.key, &db.root.dbNode, db.valueNodeDB.branchFactor) - if err := db.baseDB.Put(rootDBKey, rootKeyAndNodeBytes); err != nil { - return err + if changes.rootID == ids.Empty { + db.root = maybe.Nothing[*node]() + if err := db.baseDB.Delete(rootDBKey); err != nil { + return err + } + } else { + db.root = maybe.Some(root) + rootKeyAndNodeBytes := codec.encodeKeyAndNode( + root.key, + &root.dbNode, + db.valueNodeDB.branchFactor, + ) + if err := db.baseDB.Put(rootDBKey, rootKeyAndNodeBytes); err != nil { + return err + } } db.history.record(changes) return nil @@ -1157,39 +1168,28 @@ func (db *merkleDB) invalidateChildrenExcept(exception *trieView) { func (db *merkleDB) initializeRootIfNeeded() (ids.ID, error) { rootBytes, err := db.baseDB.Get(rootDBKey) - if err == nil { - // Root is on disk. - var rootDBNode dbNode - rootKey, err := codec.decodeKeyAndNode(rootBytes, &rootDBNode, db.valueNodeDB.branchFactor) - if err != nil { + if err != nil { + if !errors.Is(err, database.ErrNotFound) { return ids.ID{}, err } - db.root = &node{ - dbNode: rootDBNode, - key: rootKey, - } - db.root.setValueDigest() - db.root.calculateID(db.metrics) - return db.root.id, nil + // Root isn't on disk. + return ids.Empty, nil // TODO document empty ID meaning empty trie } - if !errors.Is(err, database.ErrNotFound) { + + // Root is on disk. + var rootDBNode dbNode + rootKey, err := codec.decodeKeyAndNode(rootBytes, &rootDBNode, db.valueNodeDB.branchFactor) + if err != nil { return ids.ID{}, err } - - // Root not on disk; make a new one. - // TODO should we have a "fake" root? - rootPath := NewPath(emptyKey, db.valueNodeDB.branchFactor) - db.root = newNode(nil, rootPath) - - // update its ID - db.root.calculateID(db.metrics) - - rootBytes = codec.encodeKeyAndNode(db.root.key, &db.root.dbNode, db.valueNodeDB.branchFactor) - if err := db.baseDB.Put(rootDBKey, rootBytes); err != nil { - return ids.Empty, err + root := &node{ + dbNode: rootDBNode, + key: rootKey, } - - return db.root.id, nil + root.setValueDigest() + root.calculateID(db.metrics) + db.root = maybe.Some(root) + return root.id, nil } // Returns a view of the trie as it was when it had root [rootID] for keys within range [start, end]. @@ -1265,16 +1265,16 @@ func (db *merkleDB) getNode(key Path, hasValue bool) (*node, error) { switch { case db.closed: return nil, database.ErrClosed - case key == db.root.key: - return db.root, nil + case db.root.HasValue() && key == db.root.Value().key: + return db.root.Value(), nil case hasValue: return db.valueNodeDB.Get(key) } return db.intermediateNodeDB.Get(key) } -func (db *merkleDB) getRootKey() Path { - return db.root.key +func (db *merkleDB) getRoot() maybe.Maybe[*node] { + return db.root } // Returns [key] prefixed by [prefix]. diff --git a/x/merkledb/history.go b/x/merkledb/history.go index 34f5087a1d3a..f388ece12695 100644 --- a/x/merkledb/history.go +++ b/x/merkledb/history.go @@ -53,20 +53,17 @@ type changeSummaryAndInsertNumber struct { // Tracks all of the node and value changes that resulted in the rootID. type changeSummary struct { - // The key of the root after these changes. - rootPath Path // The ID of the trie after these changes. rootID ids.ID nodes map[Path]*change[*node] values map[Path]*change[maybe.Maybe[[]byte]] } -func newChangeSummary(estimatedSize int, endRootID ids.ID, endRootKey Path) *changeSummary { +func newChangeSummary(estimatedSize int, rootID ids.ID) *changeSummary { return &changeSummary{ - rootID: endRootID, - rootPath: endRootKey, - nodes: make(map[Path]*change[*node], estimatedSize), - values: make(map[Path]*change[maybe.Maybe[[]byte]], estimatedSize), + rootID: rootID, + nodes: make(map[Path]*change[*node], estimatedSize), + values: make(map[Path]*change[maybe.Maybe[[]byte]], estimatedSize), } } @@ -107,7 +104,7 @@ func (th *trieHistory) getValueChanges( } if startRoot == endRoot { - return newChangeSummary(maxLength, endRoot, endRootChanges.rootPath), nil + return newChangeSummary(maxLength, endRoot), nil } // Confirm there's a change resulting in [startRoot] before @@ -170,7 +167,7 @@ func (th *trieHistory) getValueChanges( // last appearance (exclusive) and [endRoot]'s last appearance (inclusive), // add the changes to keys in [start, end] to [combinedChanges]. // Only the key-value pairs with the greatest [maxLength] keys will be kept. - combinedChanges = newChangeSummary(maxLength, endRoot, Path{} /*populated last iteration*/) + combinedChanges = newChangeSummary(maxLength, endRoot) // The difference between the index of [startRootChanges] and [endRootChanges] in [th.history]. startToEndOffset = int(endRootChanges.insertNumber - startRootChanges.insertNumber) @@ -185,10 +182,6 @@ func (th *trieHistory) getValueChanges( for i := startRootIndex + 1; i <= endRootIndex; i++ { changes, _ := th.history.Index(i) - if i == endRootIndex { - combinedChanges.rootPath = changes.rootPath - } - // Add the changes from this commit to [combinedChanges]. for key, valueChange := range changes.values { // The key is outside the range [start, end]. @@ -248,7 +241,7 @@ func (th *trieHistory) getChangesToGetToRoot(rootID ids.ID, start maybe.Maybe[[] var ( startPath = maybe.Bind(start, th.newPath) endPath = maybe.Bind(end, th.newPath) - combinedChanges = newChangeSummary(defaultPreallocationSize, rootID, Path{} /*populated first iteration*/) + combinedChanges = newChangeSummary(defaultPreallocationSize, rootID) mostRecentChangeInsertNumber = th.nextInsertNumber - 1 mostRecentChangeIndex = th.history.Len() - 1 offset = int(mostRecentChangeInsertNumber - lastRootChange.insertNumber) @@ -261,10 +254,6 @@ func (th *trieHistory) getChangesToGetToRoot(rootID ids.ID, start maybe.Maybe[[] for i := mostRecentChangeIndex; i > lastRootChangeIndex; i-- { changes, _ := th.history.Index(i) - if i == mostRecentChangeIndex { - combinedChanges.rootPath = changes.rootPath - } - for key, changedNode := range changes.nodes { combinedChanges.nodes[key] = &change[*node]{ after: changedNode.before, diff --git a/x/merkledb/history_test.go b/x/merkledb/history_test.go index 3828aa04af91..bd8842837751 100644 --- a/x/merkledb/history_test.go +++ b/x/merkledb/history_test.go @@ -36,7 +36,7 @@ func Test_History_Simple(t *testing.T) { origProof, err := db.GetRangeProof(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(origProof) - origRootID := db.root.id + origRootID := db.root.Value().id require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) batch = db.NewBatch() @@ -336,7 +336,7 @@ func Test_History_RepeatedRoot(t *testing.T) { origProof, err := db.GetRangeProof(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(origProof) - origRootID := db.root.id + origRootID := db.root.Value().id require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) batch = db.NewBatch() @@ -378,7 +378,7 @@ func Test_History_ExcessDeletes(t *testing.T) { origProof, err := db.GetRangeProof(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(origProof) - origRootID := db.root.id + origRootID := db.root.Value().id require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) batch = db.NewBatch() @@ -410,7 +410,7 @@ func Test_History_DontIncludeAllNodes(t *testing.T) { origProof, err := db.GetRangeProof(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(origProof) - origRootID := db.root.id + origRootID := db.root.Value().id require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) batch = db.NewBatch() @@ -438,7 +438,7 @@ func Test_History_Branching2Nodes(t *testing.T) { origProof, err := db.GetRangeProof(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(origProof) - origRootID := db.root.id + origRootID := db.root.Value().id require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) batch = db.NewBatch() @@ -466,7 +466,7 @@ func Test_History_Branching3Nodes(t *testing.T) { origProof, err := db.GetRangeProof(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(origProof) - origRootID := db.root.id + origRootID := db.root.Value().id require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) batch = db.NewBatch() @@ -690,7 +690,7 @@ func TestHistoryGetChangesToRoot(t *testing.T) { name: "most recent change", rootID: changes[maxHistoryLen-1].rootID, validateFunc: func(require *require.Assertions, got *changeSummary) { - expected := newChangeSummary(defaultPreallocationSize, changes[maxHistoryLen-1].rootID, changes[maxHistoryLen-1].rootPath) + expected := newChangeSummary(defaultPreallocationSize, changes[maxHistoryLen-1].rootID) require.Equal(expected, got) }, }, diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index d893c47498e6..cdca1e6518e0 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -150,7 +150,7 @@ func Test_RangeProof_Extra_Value(t *testing.T) { context.Background(), maybe.Some([]byte{1}), maybe.Some([]byte{5, 5}), - db.root.id, + db.root.Value().id, )) proof.KeyValues = append(proof.KeyValues, KeyValue{Key: []byte{5}, Value: []byte{5}}) @@ -159,7 +159,7 @@ func Test_RangeProof_Extra_Value(t *testing.T) { context.Background(), maybe.Some([]byte{1}), maybe.Some([]byte{5, 5}), - db.root.id, + db.root.Value().id, ) require.ErrorIs(err, ErrInvalidProof) } @@ -536,7 +536,7 @@ func Test_RangeProof(t *testing.T) { context.Background(), maybe.Some([]byte{1}), maybe.Some([]byte{3, 5}), - db.root.id, + db.root.Value().id, )) } @@ -588,7 +588,7 @@ func Test_RangeProof_NilStart(t *testing.T) { context.Background(), maybe.Nothing[[]byte](), maybe.Some([]byte("key35")), - db.root.id, + db.root.Value().id, )) } @@ -622,7 +622,7 @@ func Test_RangeProof_NilEnd(t *testing.T) { context.Background(), maybe.Some([]byte{1}), maybe.Nothing[[]byte](), - db.root.id, + db.root.Value().id, )) } @@ -664,7 +664,7 @@ func Test_RangeProof_EmptyValues(t *testing.T) { context.Background(), maybe.Some([]byte("key1")), maybe.Some([]byte("key2")), - db.root.id, + db.root.Value().id, )) } diff --git a/x/merkledb/trie.go b/x/merkledb/trie.go index 2d0f26bf37d6..a34e22654f14 100644 --- a/x/merkledb/trie.go +++ b/x/merkledb/trie.go @@ -38,7 +38,9 @@ type ReadOnlyTrie interface { // database.ErrNotFound if the key is not present getValue(key Path) ([]byte, error) - getRootKey() Path + // If this trie is non-empty, returns the root node. + // Otherwise returns Nothing. + getRoot() maybe.Maybe[*node] // get an editable copy of the node with the given key path // hasValue indicates which db to look in (value or intermediate) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index b6b14c475a81..c0fd3f6b81ee 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -97,7 +97,7 @@ type trieView struct { db *merkleDB // The root of the trie represented by this view. - root *node + root maybe.Maybe[*node] } // NewView returns a new view on top of this Trie where the passed changes @@ -145,24 +145,31 @@ func newTrieView( parentTrie TrieView, changes ViewChanges, ) (*trieView, error) { - root, err := parentTrie.getEditableNode(parentTrie.getRootKey(), false /* hasValue */) - if err != nil { - if err == database.ErrNotFound { - return nil, ErrNoValidRoot - } - return nil, err + // root, err := parentTrie.getEditableNode(parentTrie.getRootKey(), false /* hasValue */) + // if err != nil { + // if err == database.ErrNotFound { + // return nil, ErrNoValidRoot + // } + // return nil, err + // } + root := parentTrie.getRoot() + if root.HasValue() { + root = maybe.Some(root.Value().clone()) // TODO better way of doing this? + } else { + root = maybe.Nothing[*node]() // TODO is this right? } - parentRoot, err := parentTrie.GetMerkleRoot(context.Background()) - if err != nil { - return nil, err + var rootID ids.ID + if root.HasValue() { + rootValue := root.Value() + rootID = rootValue.id } newView := &trieView{ root: root, db: db, parentTrie: parentTrie, - changes: newChangeSummary(len(changes.BatchOps)+len(changes.MapOps), parentRoot, root.key), + changes: newChangeSummary(len(changes.BatchOps)+len(changes.MapOps), rootID /*TODO fix*/), } for _, op := range changes.BatchOps { @@ -202,13 +209,16 @@ func newHistoricalTrieView( return nil, ErrNoValidRoot } - passedRootChange, ok := changes.nodes[changes.rootPath] - if !ok { - return nil, ErrNoValidRoot + root := maybe.Nothing[*node]() + for _, node := range changes.nodes { + if node.after.id == changes.rootID { + root = maybe.Some(node.after.clone()) // todo is this right? + break + } } newView := &trieView{ - root: passedRootChange.after, + root: root, db: db, parentTrie: db, changes: changes, @@ -220,8 +230,8 @@ func newHistoricalTrieView( return newView, nil } -func (t *trieView) getRootKey() Path { - return t.root.key +func (t *trieView) getRoot() maybe.Maybe[*node] { + return t.root } // Recalculates the node IDs for all changed nodes in the trie. @@ -254,10 +264,15 @@ func (t *trieView) calculateNodeIDs(ctx context.Context) error { } } + if t.root.IsNothing() { + return // TODO is this right? + } + _ = t.db.calculateNodeIDsSema.Acquire(context.Background(), 1) - t.calculateNodeIDsHelper(t.root) + root := t.root.Value() + t.calculateNodeIDsHelper(root) t.db.calculateNodeIDsSema.Release(1) - t.changes.rootID = t.root.id + t.changes.rootID = root.id // ensure no ancestor changes occurred during execution if t.isInvalid() { @@ -563,7 +578,10 @@ func (t *trieView) GetMerkleRoot(ctx context.Context) (ids.ID, error) { if err := t.calculateNodeIDs(ctx); err != nil { return ids.Empty, err } - return t.root.id, nil + if t.root.IsNothing() { + return ids.Empty, nil // TODO document/handle + } + return t.root.Value().id, nil } func (t *trieView) GetValues(ctx context.Context, keys [][]byte) ([][]byte, []error) { @@ -663,12 +681,12 @@ func (t *trieView) remove(key Path) error { return err } - if nodeToDelete.key == t.root.key { + if nodeToDelete.key == t.root.Value().key { // TODO is this right? // We're deleting the root. switch len(nodeToDelete.children) { case 0: // The trie is empty now. - t.root = nil // TODO how to handle empty trie? + t.root = maybe.Nothing[*node]() return t.recordNodeDeleted(nodeToDelete) case 1: // The root has one child, so make that child the new root. @@ -684,7 +702,7 @@ func (t *trieView) remove(key Path) error { if err != nil { return err } - t.root = newRoot + t.root = maybe.Some(newRoot) return nil default: // The root has multiple children so we can't delete it. @@ -798,18 +816,22 @@ func (t *trieView) deleteEmptyNodes(nodePath []*node) error { // given [key], if it's in the trie, or the node with the largest prefix of // the [key] if it isn't in the trie. func (t *trieView) getPathTo(key Path) ([]*node, error) { - if !key.HasPrefix(t.root.key) { + if t.root.IsNothing() { return nil, nil } - if key == t.root.key { - return []*node{t.root}, nil + root := t.root.Value() + if !key.HasPrefix(root.key) { + return nil, nil + } + if key == root.key { + return []*node{root}, nil } var ( // all node paths start at the root - currentNode = t.root - matchedPathIndex = t.root.key.tokensLength - nodes = []*node{t.root} + currentNode = root + matchedPathIndex = root.key.tokensLength + nodes = []*node{root} ) // while the entire path hasn't been matched @@ -881,6 +903,14 @@ func (t *trieView) insert( return nil, ErrNodesAlreadyCalculated } + if t.root.IsNothing() { + // the trie is empty, so create a new root node. + root := newNode(nil, key) + root.setValue(value) + t.root = maybe.Some(root) + return root, t.recordNewNode(root) + } + // find the node that most closely matches [key] pathToNode, err := t.getPathTo(key) if err != nil { @@ -888,27 +918,28 @@ func (t *trieView) insert( } if len(pathToNode) == 0 { + oldRoot := t.root.Value() // [t.root.key] isn't a prefix of [key]. - commonPrefixLength := getLengthOfCommonPrefix(t.root.key, key, 0 /*offset*/) - commonPrefix := t.root.key.Take(commonPrefixLength) - oldRoot := t.root - t.root = newNode(nil, commonPrefix) - t.root.addChild(oldRoot) + commonPrefixLength := getLengthOfCommonPrefix(oldRoot.key, key, 0 /*offset*/) + commonPrefix := oldRoot.key.Take(commonPrefixLength) + newRoot := newNode(nil, commonPrefix) + newRoot.addChild(oldRoot) + if err := t.recordNewNode(newRoot); err != nil { + return nil, err + } + t.root = maybe.Some(newRoot) if commonPrefix == key { // [key] is a prefix of [t.root.key] so it should be the new root. - t.root.setValue(value) - return t.root, t.recordNewNode(t.root) + newRoot.setValue(value) + return newRoot, t.recordNewNode(newRoot) } // Neither [key] nor [t.root.key] is a prefix of the other. // Make a new root whose children are the old root and the new node. - t.root.addChild(oldRoot) - newValueNode := newNode(t.root, key) + newRoot.addChild(oldRoot) + newValueNode := newNode(newRoot, key) newValueNode.setValue(value) - if err := t.recordNewNode(t.root); err != nil { - return nil, err - } return newValueNode, t.recordNewNode(newValueNode) } From a64dc479b4041f20cb0554c8b458bb82337c614b Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 17 Oct 2023 17:53:06 -0400 Subject: [PATCH 017/131] WIP --- x/merkledb/db.go | 9 ++++--- x/merkledb/history.go | 29 ++++++++++++++++------ x/merkledb/history_test.go | 32 +++++++++++++----------- x/merkledb/proof_test.go | 28 ++++++++++----------- x/merkledb/trie_test.go | 41 ++++++++++++++++++------------ x/merkledb/trieview.go | 51 ++++++++++++++++++-------------------- 6 files changed, 107 insertions(+), 83 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 031981872e96..fef4b808f94e 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -55,8 +55,7 @@ var ( hadCleanShutdown = []byte{1} didNotHaveCleanShutdown = []byte{0} - errSameRoot = errors.New("start and end root are the same") - errNoNewRoot = errors.New("there was no updated root in change list") + errSameRoot = errors.New("start and end root are the same") ) type ChangeProofer interface { @@ -264,6 +263,10 @@ func newDatabase( // add current root to history (has no changes) trieDB.history.record(&changeSummary{ rootID: root, + rootChange: &change[*node]{ // TODO is this right + before: nil, + after: trieDB.root.Value(), + }, values: map[Path]*change[maybe.Maybe[[]byte]]{}, nodes: map[Path]*change[*node]{}, }) @@ -971,7 +974,7 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e // Only modify in-memory state after the commit succeeds // so that we don't need to clean up on error. - if changes.rootID == ids.Empty { + if changes.rootChange.after == nil { db.root = maybe.Nothing[*node]() if err := db.baseDB.Delete(rootDBKey); err != nil { return err diff --git a/x/merkledb/history.go b/x/merkledb/history.go index f388ece12695..aac209398b7b 100644 --- a/x/merkledb/history.go +++ b/x/merkledb/history.go @@ -54,14 +54,14 @@ type changeSummaryAndInsertNumber struct { // Tracks all of the node and value changes that resulted in the rootID. type changeSummary struct { // The ID of the trie after these changes. - rootID ids.ID - nodes map[Path]*change[*node] - values map[Path]*change[maybe.Maybe[[]byte]] + rootID ids.ID + rootChange *change[*node] + nodes map[Path]*change[*node] + values map[Path]*change[maybe.Maybe[[]byte]] } -func newChangeSummary(estimatedSize int, rootID ids.ID) *changeSummary { +func newChangeSummary(estimatedSize int) *changeSummary { return &changeSummary{ - rootID: rootID, nodes: make(map[Path]*change[*node], estimatedSize), values: make(map[Path]*change[maybe.Maybe[[]byte]], estimatedSize), } @@ -104,7 +104,7 @@ func (th *trieHistory) getValueChanges( } if startRoot == endRoot { - return newChangeSummary(maxLength, endRoot), nil + return newChangeSummary(maxLength), nil } // Confirm there's a change resulting in [startRoot] before @@ -167,7 +167,7 @@ func (th *trieHistory) getValueChanges( // last appearance (exclusive) and [endRoot]'s last appearance (inclusive), // add the changes to keys in [start, end] to [combinedChanges]. // Only the key-value pairs with the greatest [maxLength] keys will be kept. - combinedChanges = newChangeSummary(maxLength, endRoot) + combinedChanges = newChangeSummary(maxLength) // The difference between the index of [startRootChanges] and [endRootChanges] in [th.history]. startToEndOffset = int(endRootChanges.insertNumber - startRootChanges.insertNumber) @@ -241,7 +241,7 @@ func (th *trieHistory) getChangesToGetToRoot(rootID ids.ID, start maybe.Maybe[[] var ( startPath = maybe.Bind(start, th.newPath) endPath = maybe.Bind(end, th.newPath) - combinedChanges = newChangeSummary(defaultPreallocationSize, rootID) + combinedChanges = newChangeSummary(defaultPreallocationSize) mostRecentChangeInsertNumber = th.nextInsertNumber - 1 mostRecentChangeIndex = th.history.Len() - 1 offset = int(mostRecentChangeInsertNumber - lastRootChange.insertNumber) @@ -251,9 +251,22 @@ func (th *trieHistory) getChangesToGetToRoot(rootID ids.ID, start maybe.Maybe[[] // Go backward from the most recent change in the history up to but // not including the last change resulting in [rootID]. // Record each change in [combinedChanges]. + var endRootKey Path for i := mostRecentChangeIndex; i > lastRootChangeIndex; i-- { changes, _ := th.history.Index(i) + if i == mostRecentChangeIndex { + combinedChanges.rootChange = &change[*node]{ + after: changes.rootChange.after, + } + endRootKey = changes.rootChange.after.key + } + if i == lastRootChangeIndex+1 { + if rootBefore, ok := changes.nodes[endRootKey]; ok { + combinedChanges.rootChange.before = rootBefore.before + } + } + for key, changedNode := range changes.nodes { combinedChanges.nodes[key] = &change[*node]{ after: changedNode.before, diff --git a/x/merkledb/history_test.go b/x/merkledb/history_test.go index bd8842837751..36b6cbb28099 100644 --- a/x/merkledb/history_test.go +++ b/x/merkledb/history_test.go @@ -655,6 +655,10 @@ func TestHistoryGetChangesToRoot(t *testing.T) { for i := 0; i < maxHistoryLen; i++ { // Fill the history changes = append(changes, &changeSummary{ rootID: ids.GenerateTestID(), + rootChange: &change[*node]{ + before: &node{id: ids.GenerateTestID()}, + after: &node{id: ids.GenerateTestID()}, + }, nodes: map[Path]*change[*node]{ history.newPath([]byte{byte(i)}): { before: &node{id: ids.GenerateTestID()}, @@ -681,23 +685,23 @@ func TestHistoryGetChangesToRoot(t *testing.T) { } tests := []test{ - { - name: "unknown root ID", - rootID: ids.GenerateTestID(), - expectedErr: ErrInsufficientHistory, - }, - { - name: "most recent change", - rootID: changes[maxHistoryLen-1].rootID, - validateFunc: func(require *require.Assertions, got *changeSummary) { - expected := newChangeSummary(defaultPreallocationSize, changes[maxHistoryLen-1].rootID) - require.Equal(expected, got) - }, - }, + // { + // name: "unknown root ID", + // rootID: ids.GenerateTestID(), + // expectedErr: ErrInsufficientHistory, + // }, + // { + // name: "most recent change", + // rootID: changes[maxHistoryLen-1].rootID, + // validateFunc: func(require *require.Assertions, got *changeSummary) { + // expected := newChangeSummary(defaultPreallocationSize) + // require.Equal(expected, got) + // }, + // }, { name: "second most recent change", rootID: changes[maxHistoryLen-2].rootID, - validateFunc: func(require *require.Assertions, got *changeSummary) { + validateFunc: func(require *require.Assertions, got *changeSummary) { // TODO add assertions for rootChange // Ensure this is the reverse of the most recent change require.Len(got.nodes, 1) require.Len(got.values, 1) diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index cdca1e6518e0..c0d1ff5c9b1b 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -269,22 +269,20 @@ func Test_Proof(t *testing.T) { require.NoError(err) require.NotNil(proof) - require.Len(proof.Path, 3) + require.Len(proof.Path, 2) - require.Equal(NewPath([]byte("key1"), BranchFactor16), proof.Path[2].KeyPath) - require.Equal(maybe.Some([]byte("value1")), proof.Path[2].ValueOrHash) + require.Equal(NewPath([]byte("key1"), BranchFactor16), proof.Path[1].KeyPath) + require.Equal(maybe.Some([]byte("value1")), proof.Path[1].ValueOrHash) - require.Equal(NewPath([]byte{}, BranchFactor16), proof.Path[0].KeyPath) - require.True(proof.Path[0].ValueOrHash.IsNothing()) + require.Equal(NewPath([]byte("key1"), BranchFactor16).Take(7), proof.Path[0].KeyPath) + require.False(proof.Path[0].ValueOrHash.HasValue()) expectedRootID, err := trie.GetMerkleRoot(context.Background()) require.NoError(err) require.NoError(proof.Verify(context.Background(), expectedRootID)) - proof.Path[0].ValueOrHash = maybe.Some([]byte("value2")) - - err = proof.Verify(context.Background(), expectedRootID) - require.ErrorIs(err, ErrInvalidProof) + proof.Path[0].KeyPath = NewPath([]byte("key1"), BranchFactor16) + require.Error(proof.Verify(context.Background(), expectedRootID)) } func Test_RangeProof_Syntactic_Verify(t *testing.T) { @@ -525,9 +523,10 @@ func Test_RangeProof(t *testing.T) { require.Equal([]byte{2}, proof.KeyValues[1].Value) require.Equal([]byte{3}, proof.KeyValues[2].Value) - require.Nil(proof.EndProof[0].KeyPath.Bytes()) - require.Equal([]byte{0}, proof.EndProof[1].KeyPath.Bytes()) - require.Equal([]byte{3}, proof.EndProof[2].KeyPath.Bytes()) + require.Len(proof.EndProof, 2) + require.Equal([]byte{0}, proof.EndProof[0].KeyPath.Bytes()) + require.Len(proof.EndProof[0].Children, 5) // 0,1,2,3,4 + require.Equal([]byte{3}, proof.EndProof[1].KeyPath.Bytes()) // only a single node here since others are duplicates in endproof require.Equal([]byte{1}, proof.StartProof[0].KeyPath.Bytes()) @@ -580,9 +579,8 @@ func Test_RangeProof_NilStart(t *testing.T) { require.Equal([]byte("value1"), proof.KeyValues[0].Value) require.Equal([]byte("value2"), proof.KeyValues[1].Value) - require.Equal(NewPath([]byte("key2"), BranchFactor16), proof.EndProof[2].KeyPath, BranchFactor16) - require.Equal(NewPath([]byte("key2"), BranchFactor16).Take(7), proof.EndProof[1].KeyPath) - require.Equal(NewPath([]byte(""), BranchFactor16), proof.EndProof[0].KeyPath, BranchFactor16) + require.Equal(NewPath([]byte("key2"), BranchFactor16), proof.EndProof[1].KeyPath, BranchFactor16) + require.Equal(NewPath([]byte("key2"), BranchFactor16).Take(7), proof.EndProof[0].KeyPath) require.NoError(proof.Verify( context.Background(), diff --git a/x/merkledb/trie_test.go b/x/merkledb/trie_test.go index d13680b0b064..99ee85deb9f0 100644 --- a/x/merkledb/trie_test.go +++ b/x/merkledb/trie_test.go @@ -32,6 +32,9 @@ func getNodeValueWithBranchFactor(t ReadOnlyTrie, key string, bf BranchFactor) ( if err != nil { return nil, err } + if len(nodePath) == 0 { + return nil, database.ErrNotFound + } closestNode := nodePath[len(nodePath)-1] if closestNode.key != path || closestNode == nil { return nil, database.ErrNotFound @@ -130,9 +133,7 @@ func TestTrieViewGetPathTo(t *testing.T) { nodePath, err := trie.getPathTo(NewPath(nil, BranchFactor16)) require.NoError(err) - // Just the root - require.Len(nodePath, 1) - require.Equal(trie.root, nodePath[0]) + require.Empty(nodePath) // Insert a key key1 := []byte{0} @@ -152,10 +153,9 @@ func TestTrieViewGetPathTo(t *testing.T) { nodePath, err = trie.getPathTo(NewPath(key1, BranchFactor16)) require.NoError(err) - // Root and 1 value - require.Len(nodePath, 2) - require.Equal(trie.root, nodePath[0]) - require.Equal(NewPath(key1, BranchFactor16), nodePath[1].key) + // 1 value + require.Len(nodePath, 1) + require.Equal(NewPath(key1, BranchFactor16), nodePath[0].key) // Insert another key which is a child of the first key2 := []byte{0, 1} @@ -174,11 +174,14 @@ func TestTrieViewGetPathTo(t *testing.T) { nodePath, err = trie.getPathTo(NewPath(key2, BranchFactor16)) require.NoError(err) - require.Len(nodePath, 3) - require.Equal(trie.root, nodePath[0]) - require.Equal(NewPath(key1, BranchFactor16), nodePath[1].key) - require.Equal(NewPath(key2, BranchFactor16), nodePath[2].key) + require.Len(nodePath, 2) + require.Equal(trie.root.Value(), nodePath[0]) + require.Equal(NewPath(key2, BranchFactor16), nodePath[1].key) + // Trie is: + // [0] + // | + // [0,1] // Insert a key which shares no prefix with the others key3 := []byte{255} trieIntf, err = trie.NewView( @@ -194,17 +197,23 @@ func TestTrieViewGetPathTo(t *testing.T) { trie = trieIntf.(*trieView) require.NoError(trie.calculateNodeIDs(context.Background())) + // Trie is: + // [] + // / \ + // [0] [255] + // | + // [0,1] nodePath, err = trie.getPathTo(NewPath(key3, BranchFactor16)) require.NoError(err) require.Len(nodePath, 2) - require.Equal(trie.root, nodePath[0]) + require.Equal(trie.root.Value(), nodePath[0]) + require.Equal(0, trie.root.Value().key.tokensLength) require.Equal(NewPath(key3, BranchFactor16), nodePath[1].key) - // Other key path not affected nodePath, err = trie.getPathTo(NewPath(key2, BranchFactor16)) require.NoError(err) require.Len(nodePath, 3) - require.Equal(trie.root, nodePath[0]) + require.Equal(trie.root.Value(), nodePath[0]) require.Equal(NewPath(key1, BranchFactor16), nodePath[1].key) require.Equal(NewPath(key2, BranchFactor16), nodePath[2].key) @@ -213,7 +222,7 @@ func TestTrieViewGetPathTo(t *testing.T) { nodePath, err = trie.getPathTo(NewPath(key4, BranchFactor16)) require.NoError(err) require.Len(nodePath, 3) - require.Equal(trie.root, nodePath[0]) + require.Equal(trie.root.Value(), nodePath[0]) require.Equal(NewPath(key1, BranchFactor16), nodePath[1].key) require.Equal(NewPath(key2, BranchFactor16), nodePath[2].key) @@ -222,7 +231,7 @@ func TestTrieViewGetPathTo(t *testing.T) { nodePath, err = trie.getPathTo(NewPath(key5, BranchFactor16)) require.NoError(err) require.Len(nodePath, 1) - require.Equal(trie.root, nodePath[0]) + require.Equal(trie.root.Value(), nodePath[0]) } func Test_Trie_ViewOnCommitedView(t *testing.T) { diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index c0fd3f6b81ee..18f3aa73425d 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -155,21 +155,13 @@ func newTrieView( root := parentTrie.getRoot() if root.HasValue() { root = maybe.Some(root.Value().clone()) // TODO better way of doing this? - } else { - root = maybe.Nothing[*node]() // TODO is this right? - } - - var rootID ids.ID - if root.HasValue() { - rootValue := root.Value() - rootID = rootValue.id } newView := &trieView{ root: root, db: db, parentTrie: parentTrie, - changes: newChangeSummary(len(changes.BatchOps)+len(changes.MapOps), rootID /*TODO fix*/), + changes: newChangeSummary(len(changes.BatchOps) + len(changes.MapOps)), } for _, op := range changes.BatchOps { @@ -209,14 +201,11 @@ func newHistoricalTrieView( return nil, ErrNoValidRoot } + // TODO is this right? root := maybe.Nothing[*node]() - for _, node := range changes.nodes { - if node.after.id == changes.rootID { - root = maybe.Some(node.after.clone()) // todo is this right? - break - } + if changes.rootChange.after != nil { + root = maybe.Some(changes.rootChange.after.clone()) } - newView := &trieView{ root: root, db: db, @@ -251,6 +240,8 @@ func (t *trieView) calculateNodeIDs(ctx context.Context) error { _, span := t.db.infoTracer.Start(ctx, "MerkleDB.trieview.calculateNodeIDs") defer span.End() + oldRoot := t.root + // add all the changed key/values to the nodes of the trie for key, change := range t.changes.values { if change.after.IsNothing() { @@ -264,16 +255,21 @@ func (t *trieView) calculateNodeIDs(ctx context.Context) error { } } - if t.root.IsNothing() { - return // TODO is this right? + if !t.root.IsNothing() { + _ = t.db.calculateNodeIDsSema.Acquire(context.Background(), 1) + root := t.root.Value() + t.calculateNodeIDsHelper(root) + t.db.calculateNodeIDsSema.Release(1) + t.changes.rootID = root.id + t.changes.rootChange = t.changes.nodes[root.key] + } else { + t.changes.rootID = ids.Empty + t.changes.rootChange = &change[*node]{ + before: oldRoot.Value(), + after: t.root.Value(), + } } - _ = t.db.calculateNodeIDsSema.Acquire(context.Background(), 1) - root := t.root.Value() - t.calculateNodeIDsHelper(root) - t.db.calculateNodeIDsSema.Release(1) - t.changes.rootID = root.id - // ensure no ancestor changes occurred during execution if t.isInvalid() { err = ErrInvalid @@ -677,9 +673,6 @@ func (t *trieView) remove(key Path) error { } nodeToDelete.setValue(maybe.Nothing[[]byte]()) - if err := t.recordNodeChange(nodeToDelete); err != nil { - return err - } if nodeToDelete.key == t.root.Value().key { // TODO is this right? // We're deleting the root. @@ -702,10 +695,14 @@ func (t *trieView) remove(key Path) error { if err != nil { return err } + if err := t.recordNodeDeleted(t.root.Value()); err != nil { + return err + } t.root = maybe.Some(newRoot) return nil default: // The root has multiple children so we can't delete it. + t.recordNodeChange(nodeToDelete) return nil } } @@ -918,8 +915,8 @@ func (t *trieView) insert( } if len(pathToNode) == 0 { - oldRoot := t.root.Value() // [t.root.key] isn't a prefix of [key]. + oldRoot := t.root.Value() commonPrefixLength := getLengthOfCommonPrefix(oldRoot.key, key, 0 /*offset*/) commonPrefix := oldRoot.key.Take(commonPrefixLength) newRoot := newNode(nil, commonPrefix) From fd8ea46df344d193b21cbb77cd66ba82320741ec Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 18 Oct 2023 10:33:37 -0400 Subject: [PATCH 018/131] WIP --- x/merkledb/db.go | 17 +++---- x/merkledb/history.go | 19 +++----- x/merkledb/history_test.go | 5 +-- x/merkledb/proof_test.go | 62 +++++++++++++++++++------ x/merkledb/trie_test.go | 92 +++++++++++++++++++++----------------- x/merkledb/trieview.go | 13 ++---- 6 files changed, 116 insertions(+), 92 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index fef4b808f94e..29161235719e 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -263,10 +263,7 @@ func newDatabase( // add current root to history (has no changes) trieDB.history.record(&changeSummary{ rootID: root, - rootChange: &change[*node]{ // TODO is this right - before: nil, - after: trieDB.root.Value(), - }, + root: trieDB.root.Value(), // TODO is this right? values: map[Path]*change[maybe.Maybe[[]byte]]{}, nodes: map[Path]*change[*node]{}, }) @@ -932,13 +929,9 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e return nil } - var root *node currentValueNodeBatch := db.valueNodeDB.NewBatch() _, nodesSpan := db.infoTracer.Start(ctx, "MerkleDB.commitChanges.writeNodes") for key, nodeChange := range changes.nodes { - if nodeChange.after != nil && nodeChange.after.id == changes.rootID { - root = nodeChange.after - } shouldAddIntermediate := nodeChange.after != nil && !nodeChange.after.hasValue() shouldDeleteIntermediate := !shouldAddIntermediate && nodeChange.before != nil && !nodeChange.before.hasValue() @@ -974,16 +967,16 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e // Only modify in-memory state after the commit succeeds // so that we don't need to clean up on error. - if changes.rootChange.after == nil { + if changes.rootID == ids.Empty { db.root = maybe.Nothing[*node]() if err := db.baseDB.Delete(rootDBKey); err != nil { return err } } else { - db.root = maybe.Some(root) + db.root = maybe.Some(changes.root) rootKeyAndNodeBytes := codec.encodeKeyAndNode( - root.key, - &root.dbNode, + changes.root.key, + &changes.root.dbNode, db.valueNodeDB.branchFactor, ) if err := db.baseDB.Put(rootDBKey, rootKeyAndNodeBytes); err != nil { diff --git a/x/merkledb/history.go b/x/merkledb/history.go index aac209398b7b..7e5f6668487c 100644 --- a/x/merkledb/history.go +++ b/x/merkledb/history.go @@ -54,10 +54,10 @@ type changeSummaryAndInsertNumber struct { // Tracks all of the node and value changes that resulted in the rootID. type changeSummary struct { // The ID of the trie after these changes. - rootID ids.ID - rootChange *change[*node] - nodes map[Path]*change[*node] - values map[Path]*change[maybe.Maybe[[]byte]] + rootID ids.ID + root *node + nodes map[Path]*change[*node] + values map[Path]*change[maybe.Maybe[[]byte]] } func newChangeSummary(estimatedSize int) *changeSummary { @@ -251,20 +251,11 @@ func (th *trieHistory) getChangesToGetToRoot(rootID ids.ID, start maybe.Maybe[[] // Go backward from the most recent change in the history up to but // not including the last change resulting in [rootID]. // Record each change in [combinedChanges]. - var endRootKey Path for i := mostRecentChangeIndex; i > lastRootChangeIndex; i-- { changes, _ := th.history.Index(i) if i == mostRecentChangeIndex { - combinedChanges.rootChange = &change[*node]{ - after: changes.rootChange.after, - } - endRootKey = changes.rootChange.after.key - } - if i == lastRootChangeIndex+1 { - if rootBefore, ok := changes.nodes[endRootKey]; ok { - combinedChanges.rootChange.before = rootBefore.before - } + combinedChanges.root = changes.root } for key, changedNode := range changes.nodes { diff --git a/x/merkledb/history_test.go b/x/merkledb/history_test.go index 36b6cbb28099..3d6eea0254ec 100644 --- a/x/merkledb/history_test.go +++ b/x/merkledb/history_test.go @@ -655,10 +655,7 @@ func TestHistoryGetChangesToRoot(t *testing.T) { for i := 0; i < maxHistoryLen; i++ { // Fill the history changes = append(changes, &changeSummary{ rootID: ids.GenerateTestID(), - rootChange: &change[*node]{ - before: &node{id: ids.GenerateTestID()}, - after: &node{id: ids.GenerateTestID()}, - }, + root: &node{id: ids.GenerateTestID()}, nodes: map[Path]*change[*node]{ history.newPath([]byte{byte(i)}): { before: &node{id: ids.GenerateTestID()}, diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index c0d1ff5c9b1b..6ad59e2dbf02 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -595,10 +595,16 @@ func Test_RangeProof_NilEnd(t *testing.T) { db, err := getBasicDB() require.NoError(err) + writeBasicBatch(t, db) require.NoError(err) - proof, err := db.GetRangeProof(context.Background(), maybe.Some([]byte{1}), maybe.Nothing[[]byte](), 2) + proof, err := db.GetRangeProof( // Should have keys [1], [2] + context.Background(), + maybe.Some([]byte{1}), + maybe.Nothing[[]byte](), + 2, + ) require.NoError(err) require.NotNil(proof) @@ -612,9 +618,8 @@ func Test_RangeProof_NilEnd(t *testing.T) { require.Equal([]byte{1}, proof.StartProof[0].KeyPath.Bytes()) - require.Nil(proof.EndProof[0].KeyPath.Bytes()) - require.Equal([]byte{0}, proof.EndProof[1].KeyPath.Bytes()) - require.Equal([]byte{2}, proof.EndProof[2].KeyPath.Bytes()) + require.Equal(db.root.Value().key, proof.EndProof[0].KeyPath) + require.Equal([]byte{2}, proof.EndProof[1].KeyPath.Bytes()) require.NoError(proof.Verify( context.Background(), @@ -654,9 +659,9 @@ func Test_RangeProof_EmptyValues(t *testing.T) { require.Len(proof.StartProof, 1) require.Equal(NewPath([]byte("key1"), BranchFactor16), proof.StartProof[0].KeyPath, BranchFactor16) - require.Len(proof.EndProof, 3) - require.Equal(NewPath([]byte("key2"), BranchFactor16), proof.EndProof[2].KeyPath, BranchFactor16) - require.Equal(NewPath([]byte{}, BranchFactor16), proof.EndProof[0].KeyPath, BranchFactor16) + require.Len(proof.EndProof, 2) + require.Equal(NewPath([]byte("key1"), BranchFactor16).Take(7), proof.EndProof[0].KeyPath, BranchFactor16) + require.Equal(NewPath([]byte("key2"), BranchFactor16), proof.EndProof[1].KeyPath, BranchFactor16) require.NoError(proof.Verify( context.Background(), @@ -668,13 +673,31 @@ func Test_RangeProof_EmptyValues(t *testing.T) { func Test_ChangeProof_Missing_History_For_EndRoot(t *testing.T) { require := require.New(t) + seed := time.Now().UnixNano() + t.Logf("Seed: %d", seed) + rand := rand.New(rand.NewSource(seed)) db, err := getBasicDB() require.NoError(err) - startRoot, err := db.GetMerkleRoot(context.Background()) - require.NoError(err) - _, err = db.GetChangeProof(context.Background(), startRoot, ids.Empty, maybe.Nothing[[]byte](), maybe.Nothing[[]byte](), 50) + roots := []ids.ID{} + for i := 0; i < defaultHistoryLength+1; i++ { + key := make([]byte, 16) + _, _ = rand.Read(key) + require.NoError(db.Put(key, nil)) + root, err := db.GetMerkleRoot(context.Background()) + require.NoError(err) + roots = append(roots, root) + } + + _, err = db.GetChangeProof( + context.Background(), + roots[0], + roots[len(roots)-1], + maybe.Nothing[[]byte](), + maybe.Nothing[[]byte](), + 50, + ) require.ErrorIs(err, ErrInsufficientHistory) } @@ -797,7 +820,7 @@ func Test_ChangeProof_Verify_Bad_Data(t *testing.T) { { name: "odd length key path with value", malform: func(proof *ChangeProof) { - proof.EndProof[1].ValueOrHash = maybe.Some([]byte{1, 2}) + proof.EndProof[0].ValueOrHash = maybe.Some([]byte{1, 2}) }, expectedErr: ErrPartialByteLengthWithValue, }, @@ -836,13 +859,26 @@ func Test_ChangeProof_Verify_Bad_Data(t *testing.T) { dbClone, err := getBasicDB() require.NoError(err) - proof, err := db.GetChangeProof(context.Background(), startRoot, endRoot, maybe.Some([]byte{2}), maybe.Some([]byte{3, 0}), 50) + proof, err := db.GetChangeProof( + context.Background(), + startRoot, + endRoot, + maybe.Some([]byte{2}), + maybe.Some([]byte{3, 0}), + 50, + ) require.NoError(err) require.NotNil(proof) tt.malform(proof) - err = dbClone.VerifyChangeProof(context.Background(), proof, maybe.Some([]byte{2}), maybe.Some([]byte{3, 0}), db.getMerkleRoot()) + err = dbClone.VerifyChangeProof( + context.Background(), + proof, + maybe.Some([]byte{2}), + maybe.Some([]byte{3, 0}), + db.getMerkleRoot(), + ) require.ErrorIs(err, tt.expectedErr) }) } diff --git a/x/merkledb/trie_test.go b/x/merkledb/trie_test.go index 99ee85deb9f0..e20473743506 100644 --- a/x/merkledb/trie_test.go +++ b/x/merkledb/trie_test.go @@ -612,12 +612,12 @@ func Test_Trie_HashCountOnBranch(t *testing.T) { // Make sure the branch node with the common prefix was created. // Note it's only created on call to GetMerkleRoot, not in NewView. - _, err = view2.getEditableNode(NewPath(keyPrefix, BranchFactor16), false) + gotRoot, err := view2.getEditableNode(NewPath(keyPrefix, BranchFactor16), false) require.NoError(err) + require.Equal(view2.getRoot().Value(), gotRoot) - // only hashes the new branch node, the new child node, and root - // shouldn't hash the existing node - require.Equal(int64(3), dbTrie.metrics.(*mockMetrics).hashCount) + // Had to hash new root and new child of root. + require.Equal(int64(2), dbTrie.metrics.(*mockMetrics).hashCount) } func Test_Trie_HashCountOnDelete(t *testing.T) { @@ -658,8 +658,8 @@ func Test_Trie_HashCountOnDelete(t *testing.T) { require.NoError(err) require.NoError(view.CommitToDB(context.Background())) - // the root is the only updated node so only one new hash - require.Equal(oldCount+1, dbTrie.metrics.(*mockMetrics).hashCount) + // The new root is key1; it didn't change so no need to do more hashes + require.Equal(oldCount, dbTrie.metrics.(*mockMetrics).hashCount) } func Test_Trie_NoExistingResidual(t *testing.T) { @@ -753,9 +753,11 @@ func Test_Trie_ChainDeletion(t *testing.T) { require.NoError(err) require.NoError(newTrie.(*trieView).calculateNodeIDs(context.Background())) - root, err := newTrie.getEditableNode(emptyPath(BranchFactor16), false) + maybeRoot := newTrie.getRoot() require.NoError(err) - require.Len(root.children, 1) + require.True(maybeRoot.HasValue()) + require.Equal([]byte("value0"), maybeRoot.Value().value.Value()) + require.Len(maybeRoot.Value().children, 1) newTrie, err = newTrie.NewView( context.Background(), @@ -770,10 +772,10 @@ func Test_Trie_ChainDeletion(t *testing.T) { ) require.NoError(err) require.NoError(newTrie.(*trieView).calculateNodeIDs(context.Background())) - root, err = newTrie.getEditableNode(emptyPath(BranchFactor16), false) - require.NoError(err) - // since all values have been deleted, the nodes should have been cleaned up - require.Empty(root.children) + + // trie should be empty + root := newTrie.getRoot() + require.False(root.HasValue()) } func Test_Trie_Invalidate_Siblings_On_Commit(t *testing.T) { @@ -820,54 +822,64 @@ func Test_Trie_NodeCollapse(t *testing.T) { require.NoError(err) require.NotNil(dbTrie) + kvs := []database.BatchOp{ + {Key: []byte("k"), Value: []byte("value0")}, + {Key: []byte("ke"), Value: []byte("value1")}, + {Key: []byte("key"), Value: []byte("value2")}, + {Key: []byte("key1"), Value: []byte("value3")}, + {Key: []byte("key2"), Value: []byte("value4")}, + } + trie, err := dbTrie.NewView( context.Background(), ViewChanges{ - BatchOps: []database.BatchOp{ - {Key: []byte("k"), Value: []byte("value0")}, - {Key: []byte("ke"), Value: []byte("value1")}, - {Key: []byte("key"), Value: []byte("value2")}, - {Key: []byte("key1"), Value: []byte("value3")}, - {Key: []byte("key2"), Value: []byte("value4")}, - }, + BatchOps: kvs, }, ) require.NoError(err) require.NoError(trie.(*trieView).calculateNodeIDs(context.Background())) - root, err := trie.getEditableNode(emptyPath(BranchFactor16), false) - require.NoError(err) - require.Len(root.children, 1) - root, err = trie.getEditableNode(emptyPath(BranchFactor16), false) - require.NoError(err) - require.Len(root.children, 1) + for _, kv := range kvs { + node, err := trie.getEditableNode(dbTrie.newPath(kv.Key), true) + require.NoError(err) - firstNode, err := trie.getEditableNode(getSingleChildPath(root), true) - require.NoError(err) - require.Len(firstNode.children, 1) + require.Equal(kv.Value, node.value.Value()) + } + + // delete some values + deletedKVs, remainingKVs := kvs[:3], kvs[3:] + deleteOps := make([]database.BatchOp, len(deletedKVs)) + for i, kv := range deletedKVs { + deleteOps[i] = database.BatchOp{ + Key: kv.Key, + Delete: true, + } + } - // delete the middle values trie, err = trie.NewView( context.Background(), ViewChanges{ - BatchOps: []database.BatchOp{ - {Key: []byte("k"), Delete: true}, - {Key: []byte("ke"), Delete: true}, - {Key: []byte("key"), Delete: true}, - }, + BatchOps: deleteOps, }, ) require.NoError(err) + require.NoError(trie.(*trieView).calculateNodeIDs(context.Background())) - root, err = trie.getEditableNode(emptyPath(BranchFactor16), false) - require.NoError(err) - require.Len(root.children, 1) + for _, kv := range deletedKVs { + _, err := trie.getEditableNode(dbTrie.newPath(kv.Key), true) + require.ErrorIs(err, database.ErrNotFound) + } + + // make sure the other values are still there + for _, kv := range remainingKVs { + node, err := trie.getEditableNode(dbTrie.newPath(kv.Key), true) + require.NoError(err) + + require.Equal(kv.Value, node.value.Value()) + } - firstNode, err = trie.getEditableNode(getSingleChildPath(root), true) - require.NoError(err) - require.Len(firstNode.children, 2) } func Test_Trie_MultipleStates(t *testing.T) { diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 18f3aa73425d..d28f2a0bfbb9 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -203,8 +203,8 @@ func newHistoricalTrieView( // TODO is this right? root := maybe.Nothing[*node]() - if changes.rootChange.after != nil { - root = maybe.Some(changes.rootChange.after.clone()) + if changes.root != nil { + root = maybe.Some(changes.root.clone()) // TODO clone needed? } newView := &trieView{ root: root, @@ -240,8 +240,6 @@ func (t *trieView) calculateNodeIDs(ctx context.Context) error { _, span := t.db.infoTracer.Start(ctx, "MerkleDB.trieview.calculateNodeIDs") defer span.End() - oldRoot := t.root - // add all the changed key/values to the nodes of the trie for key, change := range t.changes.values { if change.after.IsNothing() { @@ -261,13 +259,10 @@ func (t *trieView) calculateNodeIDs(ctx context.Context) error { t.calculateNodeIDsHelper(root) t.db.calculateNodeIDsSema.Release(1) t.changes.rootID = root.id - t.changes.rootChange = t.changes.nodes[root.key] + t.changes.root = t.root.Value() } else { t.changes.rootID = ids.Empty - t.changes.rootChange = &change[*node]{ - before: oldRoot.Value(), - after: t.root.Value(), - } + t.changes.root = nil } // ensure no ancestor changes occurred during execution From 6f9f0cfebbc0ab31b2cd857175fc335adfb406c1 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 18 Oct 2023 11:37:59 -0400 Subject: [PATCH 019/131] WIP --- x/merkledb/metrics_test.go | 6 +++--- x/merkledb/proof_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x/merkledb/metrics_test.go b/x/merkledb/metrics_test.go index 3bf5a9480a54..304c3027133b 100644 --- a/x/merkledb/metrics_test.go +++ b/x/merkledb/metrics_test.go @@ -34,20 +34,20 @@ func Test_Metrics_Basic_Usage(t *testing.T) { require.Equal(t, int64(1), db.metrics.(*mockMetrics).keyReadCount) require.Equal(t, int64(1), db.metrics.(*mockMetrics).keyWriteCount) - require.Equal(t, int64(2), db.metrics.(*mockMetrics).hashCount) + require.Equal(t, int64(1), db.metrics.(*mockMetrics).hashCount) require.NoError(t, db.Delete([]byte("key"))) require.Equal(t, int64(1), db.metrics.(*mockMetrics).keyReadCount) require.Equal(t, int64(2), db.metrics.(*mockMetrics).keyWriteCount) - require.Equal(t, int64(3), db.metrics.(*mockMetrics).hashCount) + require.Equal(t, int64(1), db.metrics.(*mockMetrics).hashCount) _, err = db.Get([]byte("key2")) require.ErrorIs(t, err, database.ErrNotFound) require.Equal(t, int64(2), db.metrics.(*mockMetrics).keyReadCount) require.Equal(t, int64(2), db.metrics.(*mockMetrics).keyWriteCount) - require.Equal(t, int64(3), db.metrics.(*mockMetrics).hashCount) + require.Equal(t, int64(1), db.metrics.(*mockMetrics).hashCount) } func Test_Metrics_Initialize(t *testing.T) { diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index 6ad59e2dbf02..8e145e9cdf53 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -62,7 +62,7 @@ func Test_Proof_Verify_Bad_Data(t *testing.T) { { name: "odd length key path with value", malform: func(proof *Proof) { - proof.Path[1].ValueOrHash = maybe.Some([]byte{1, 2}) + proof.Path[0].ValueOrHash = maybe.Some([]byte{1, 2}) }, expectedErr: ErrPartialByteLengthWithValue, }, @@ -187,7 +187,7 @@ func Test_RangeProof_Verify_Bad_Data(t *testing.T) { { name: "EndProof: odd length key path with value", malform: func(proof *RangeProof) { - proof.EndProof[1].ValueOrHash = maybe.Some([]byte{1, 2}) + proof.EndProof[0].ValueOrHash = maybe.Some([]byte{1, 2}) }, expectedErr: ErrPartialByteLengthWithValue, }, From a6d054918182b1a6c3ddb46f75a5f09c624a3eb9 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 18 Oct 2023 13:43:51 -0400 Subject: [PATCH 020/131] WIP --- x/merkledb/db.go | 10 +++--- x/merkledb/history.go | 18 ++++++---- x/merkledb/history_test.go | 6 +++- x/merkledb/trieview.go | 67 +++++++++++++++++++++++--------------- 4 files changed, 62 insertions(+), 39 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 29161235719e..ad830e09bdb9 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -263,7 +263,9 @@ func newDatabase( // add current root to history (has no changes) trieDB.history.record(&changeSummary{ rootID: root, - root: trieDB.root.Value(), // TODO is this right? + rootChange: &change[*node]{ + after: trieDB.root.Value(), // TODO is this right? + }, values: map[Path]*change[maybe.Maybe[[]byte]]{}, nodes: map[Path]*change[*node]{}, }) @@ -973,10 +975,10 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e return err } } else { - db.root = maybe.Some(changes.root) + db.root = maybe.Some(changes.rootChange.after) rootKeyAndNodeBytes := codec.encodeKeyAndNode( - changes.root.key, - &changes.root.dbNode, + changes.rootChange.after.key, + &changes.rootChange.after.dbNode, db.valueNodeDB.branchFactor, ) if err := db.baseDB.Put(rootDBKey, rootKeyAndNodeBytes); err != nil { diff --git a/x/merkledb/history.go b/x/merkledb/history.go index 7e5f6668487c..2f1ea7571ff2 100644 --- a/x/merkledb/history.go +++ b/x/merkledb/history.go @@ -54,16 +54,17 @@ type changeSummaryAndInsertNumber struct { // Tracks all of the node and value changes that resulted in the rootID. type changeSummary struct { // The ID of the trie after these changes. - rootID ids.ID - root *node - nodes map[Path]*change[*node] - values map[Path]*change[maybe.Maybe[[]byte]] + rootID ids.ID + rootChange *change[*node] + nodes map[Path]*change[*node] + values map[Path]*change[maybe.Maybe[[]byte]] } func newChangeSummary(estimatedSize int) *changeSummary { return &changeSummary{ - nodes: make(map[Path]*change[*node], estimatedSize), - values: make(map[Path]*change[maybe.Maybe[[]byte]], estimatedSize), + nodes: make(map[Path]*change[*node], estimatedSize), + values: make(map[Path]*change[maybe.Maybe[[]byte]], estimatedSize), + rootChange: &change[*node]{}, } } @@ -255,7 +256,10 @@ func (th *trieHistory) getChangesToGetToRoot(rootID ids.ID, start maybe.Maybe[[] changes, _ := th.history.Index(i) if i == mostRecentChangeIndex { - combinedChanges.root = changes.root + combinedChanges.rootChange.before = changes.rootChange.after + } + if i == lastRootChangeIndex+1 { + combinedChanges.rootChange.after = changes.rootChange.before } for key, changedNode := range changes.nodes { diff --git a/x/merkledb/history_test.go b/x/merkledb/history_test.go index 3d6eea0254ec..8380815e6ee3 100644 --- a/x/merkledb/history_test.go +++ b/x/merkledb/history_test.go @@ -655,7 +655,11 @@ func TestHistoryGetChangesToRoot(t *testing.T) { for i := 0; i < maxHistoryLen; i++ { // Fill the history changes = append(changes, &changeSummary{ rootID: ids.GenerateTestID(), - root: &node{id: ids.GenerateTestID()}, + rootChange: &change[*node]{ + before: &node{ + id: ids.GenerateTestID(), + }, + }, nodes: map[Path]*change[*node]{ history.newPath([]byte{byte(i)}): { before: &node{id: ids.GenerateTestID()}, diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index d28f2a0bfbb9..6a14f71581b5 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -203,8 +203,8 @@ func newHistoricalTrieView( // TODO is this right? root := maybe.Nothing[*node]() - if changes.root != nil { - root = maybe.Some(changes.root.clone()) // TODO clone needed? + if changes.rootChange.after != nil { + root = maybe.Some(changes.rootChange.after.clone()) // TODO clone needed? } newView := &trieView{ root: root, @@ -234,6 +234,12 @@ func (t *trieView) calculateNodeIDs(ctx context.Context) error { } defer t.nodesAlreadyCalculated.Set(true) + oldRoot := t.root.Value() + if oldRoot != nil { + // TODO is this right? + oldRoot = oldRoot.clone() + } + // We wait to create the span until after checking that we need to actually // calculateNodeIDs to make traces more useful (otherwise there may be a span // per key modified even though IDs are not re-calculated). @@ -259,10 +265,13 @@ func (t *trieView) calculateNodeIDs(ctx context.Context) error { t.calculateNodeIDsHelper(root) t.db.calculateNodeIDsSema.Release(1) t.changes.rootID = root.id - t.changes.root = t.root.Value() } else { t.changes.rootID = ids.Empty - t.changes.root = nil + } + + t.changes.rootChange = &change[*node]{ + before: oldRoot, + after: t.root.Value(), } // ensure no ancestor changes occurred during execution @@ -718,27 +727,27 @@ func (t *trieView) remove(key Path) error { return nil } -// Merges together nodes in the inclusive descendants of [node] that +// Merges together nodes in the inclusive descendnnts of [n] that // have no value and a single child into one node with a compressed // path until a node that doesn't meet those criteria is reached. -// [parent] is [node]'s parent. +// [parent] is [n]'s parent. // Assumes at least one of the following is true: -// * [node] has a value. -// * [node] has children. +// * [n] has a value. +// * [n] has children. // Must not be called after [calculateNodeIDs] has returned. -func (t *trieView) compressNodePath(parent, node *node) error { +func (t *trieView) compressNodePath(parent, n *node) error { if t.nodesAlreadyCalculated.Get() { return ErrNodesAlreadyCalculated } // don't collapse into this node if it's the root, doesn't have 1 child, or has a value - if len(node.children) != 1 || node.hasValue() { + if len(n.children) != 1 || n.hasValue() { return nil } - // delete all empty nodes with a single child under [node] - for len(node.children) == 1 && !node.hasValue() { - if err := t.recordNodeDeleted(node); err != nil { + // delete all empty nodes with a single child under [n] + for len(n.children) == 1 && !n.hasValue() { + if err := t.recordNodeDeleted(n); err != nil { return err } @@ -748,9 +757,9 @@ func (t *trieView) compressNodePath(parent, node *node) error { ) // There is only one child, but we don't know the index. // "Cycle" over the key/values to find the only child. - // Note this iteration once because len(node.children) == 1. - for index, entry := range node.children { - childPath = node.key.AppendExtend(index, entry.compressedPath) + // Note this iteration once because len(n.children) == 1. + for index, entry := range n.children { + childPath = n.key.AppendExtend(index, entry.compressedPath) childEntry = entry } @@ -758,12 +767,16 @@ func (t *trieView) compressNodePath(parent, node *node) error { if err != nil { return err } - node = nextNode + n = nextNode } // [node] is the first node with multiple children. // combine it with the [node] passed in. - parent.addChild(node) + if parent == nil { + t.root = maybe.Some[*node](n) + return nil + } + parent.addChild(n) return t.recordNodeChange(parent) } @@ -777,30 +790,30 @@ func (t *trieView) deleteEmptyNodes(nodePath []*node) error { return ErrNodesAlreadyCalculated } - node := nodePath[len(nodePath)-1] + n := nodePath[len(nodePath)-1] nextParentIndex := len(nodePath) - 2 - for ; nextParentIndex >= 0 && len(node.children) == 0 && !node.hasValue(); nextParentIndex-- { - if err := t.recordNodeDeleted(node); err != nil { + for ; nextParentIndex >= 0 && len(n.children) == 0 && !n.hasValue(); nextParentIndex-- { + if err := t.recordNodeDeleted(n); err != nil { return err } parent := nodePath[nextParentIndex] - parent.removeChild(node) + parent.removeChild(n) if err := t.recordNodeChange(parent); err != nil { return err } - node = parent + n = parent } - if nextParentIndex < 0 { - return nil + var parent *node + if nextParentIndex >= 0 { + parent = nodePath[nextParentIndex] } - parent := nodePath[nextParentIndex] - return t.compressNodePath(parent, node) + return t.compressNodePath(parent, n) } // Returns the nodes along the path to [key]. From af3f9f7b5a621d3eefa0eb710617c055d87424cc Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 18 Oct 2023 13:50:16 -0400 Subject: [PATCH 021/131] passing merkledb UT --- x/merkledb/db.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index ad830e09bdb9..3e6effa24080 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -293,8 +293,7 @@ func newDatabase( // Deletes every intermediate node and rebuilds them by re-adding every key/value. // TODO: make this more efficient by only clearing out the stale portions of the trie. func (db *merkleDB) rebuild(ctx context.Context, cacheSize int) error { - rootPath := NewPath(emptyKey, db.valueNodeDB.branchFactor) - db.root = maybe.Some(newNode(nil, rootPath)) // todo what to do here? + db.root = maybe.Nothing[*node]() // Delete intermediate nodes. if err := database.ClearPrefix(db.baseDB, intermediateNodePrefix, rebuildIntermediateDeletionWriteSize); err != nil { From 98e602873eced7b5ac324d6abb6b211e33004b8a Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 18 Oct 2023 15:37:27 -0400 Subject: [PATCH 022/131] WIP fix sync tests --- x/sync/client_test.go | 19 ++++--------------- x/sync/network_server_test.go | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/x/sync/client_test.go b/x/sync/client_test.go index 08c1a787b474..9d7d9cf53778 100644 --- a/x/sync/client_test.go +++ b/x/sync/client_test.go @@ -524,7 +524,7 @@ func TestGetChangeProof(t *testing.T) { newDefaultDBConfig(), ) require.NoError(t, err) - startRoot, err := serverDB.GetMerkleRoot(context.Background()) // TODO uncomment + startRoot, err := serverDB.GetMerkleRoot(context.Background()) require.NoError(t, err) // create changes @@ -566,6 +566,8 @@ func TestGetChangeProof(t *testing.T) { endRoot, err := serverDB.GetMerkleRoot(context.Background()) require.NoError(t, err) + fakeRootID := ids.GenerateTestID() + tests := map[string]struct { db DB request *pb.SyncGetChangeProofRequest @@ -662,24 +664,11 @@ func TestGetChangeProof(t *testing.T) { }, expectedErr: merkledb.ErrInvalidProof, }, - "range proof response happy path": { - request: &pb.SyncGetChangeProofRequest{ - // Server doesn't have the (non-existent) start root - // so should respond with range proof. - StartRootHash: ids.Empty[:], - EndRootHash: endRoot[:], - KeyLimit: defaultRequestKeyLimit, - BytesLimit: defaultRequestByteSizeLimit, - }, - modifyChangeProofResponse: nil, - expectedErr: nil, - expectRangeProof: true, - }, "range proof response; remove first key": { request: &pb.SyncGetChangeProofRequest{ // Server doesn't have the (non-existent) start root // so should respond with range proof. - StartRootHash: ids.Empty[:], + StartRootHash: fakeRootID[:], EndRootHash: endRoot[:], KeyLimit: defaultRequestKeyLimit, BytesLimit: defaultRequestByteSizeLimit, diff --git a/x/sync/network_server_test.go b/x/sync/network_server_test.go index 60555498457f..b6bc1d980146 100644 --- a/x/sync/network_server_test.go +++ b/x/sync/network_server_test.go @@ -252,7 +252,7 @@ func Test_Server_GetChangeProof(t *testing.T) { request: &pb.SyncGetChangeProofRequest{ // This root doesn't exist so server has insufficient history // to serve a change proof - StartRootHash: ids.Empty[:], + StartRootHash: fakeRootID[:], EndRootHash: endRoot[:], KeyLimit: defaultRequestKeyLimit, BytesLimit: defaultRequestByteSizeLimit, From 614cd669c39018a3099b40efc5565293fc41bd6d Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 18 Oct 2023 16:14:15 -0400 Subject: [PATCH 023/131] merkledb and sync tests pass --- x/sync/sync_test.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/x/sync/sync_test.go b/x/sync/sync_test.go index e3a363d2d4b6..17ebef315e8c 100644 --- a/x/sync/sync_test.go +++ b/x/sync/sync_test.go @@ -332,25 +332,26 @@ func Test_Sync_FindNextKey_BranchInLocal(t *testing.T) { require.NoError(db.Put([]byte{0x11}, []byte{1})) require.NoError(db.Put([]byte{0x11, 0x11}, []byte{2})) - syncRoot, err := db.GetMerkleRoot(context.Background()) + targetRoot, err := db.GetMerkleRoot(context.Background()) require.NoError(err) + proof, err := db.GetProof(context.Background(), []byte{0x11, 0x11}) require.NoError(err) syncer, err := NewManager(ManagerConfig{ DB: db, Client: NewMockClient(ctrl), - TargetRoot: syncRoot, + TargetRoot: targetRoot, SimultaneousWorkLimit: 5, Log: logging.NoLog{}, BranchFactor: merkledb.BranchFactor16, }) require.NoError(err) - require.NoError(db.Put([]byte{0x12}, []byte{4})) + require.NoError(db.Put([]byte{0x11, 0x15}, []byte{4})) nextKey, err := syncer.findNextKey(context.Background(), []byte{0x11, 0x11}, maybe.Some([]byte{0x20}), proof.Path) require.NoError(err) - require.Equal(maybe.Some([]byte{0x12}), nextKey) + require.Equal(maybe.Some([]byte{0x11, 0x15}), nextKey) } func Test_Sync_FindNextKey_BranchInReceived(t *testing.T) { @@ -365,27 +366,28 @@ func Test_Sync_FindNextKey_BranchInReceived(t *testing.T) { require.NoError(err) require.NoError(db.Put([]byte{0x11}, []byte{1})) require.NoError(db.Put([]byte{0x12}, []byte{2})) - require.NoError(db.Put([]byte{0x11, 0x11}, []byte{3})) + require.NoError(db.Put([]byte{0x12, 0xA0}, []byte{4})) - syncRoot, err := db.GetMerkleRoot(context.Background()) + targetRoot, err := db.GetMerkleRoot(context.Background()) require.NoError(err) - proof, err := db.GetProof(context.Background(), []byte{0x11, 0x11}) + + proof, err := db.GetProof(context.Background(), []byte{0x12}) require.NoError(err) syncer, err := NewManager(ManagerConfig{ DB: db, Client: NewMockClient(ctrl), - TargetRoot: syncRoot, + TargetRoot: targetRoot, SimultaneousWorkLimit: 5, Log: logging.NoLog{}, BranchFactor: merkledb.BranchFactor16, }) require.NoError(err) - require.NoError(db.Delete([]byte{0x12})) + require.NoError(db.Delete([]byte{0x12, 0xA0})) - nextKey, err := syncer.findNextKey(context.Background(), []byte{0x11, 0x11}, maybe.Some([]byte{0x20}), proof.Path) + nextKey, err := syncer.findNextKey(context.Background(), []byte{0x12}, maybe.Some([]byte{0x20}), proof.Path) require.NoError(err) - require.Equal(maybe.Some([]byte{0x12}), nextKey) + require.Equal(maybe.Some([]byte{0x12, 0xA0}), nextKey) } func Test_Sync_FindNextKey_ExtraValues(t *testing.T) { From 9f975f31cbedb9497ab507fe679250d656f14912 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 18 Oct 2023 16:30:36 -0400 Subject: [PATCH 024/131] nit --- x/merkledb/db.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 3e6effa24080..1b870c6afa48 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -968,7 +968,7 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e // Only modify in-memory state after the commit succeeds // so that we don't need to clean up on error. - if changes.rootID == ids.Empty { + if changes.rootChange.after == nil { db.root = maybe.Nothing[*node]() if err := db.baseDB.Delete(rootDBKey); err != nil { return err From d3538a8f2f34c46dbb453972a71f52d4a6f4bc3e Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 18 Oct 2023 16:33:33 -0400 Subject: [PATCH 025/131] nit --- x/merkledb/db.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 1b870c6afa48..81784c9b4c16 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -255,16 +255,15 @@ func newDatabase( newPath: newPath, } - root, err := trieDB.initializeRootIfNeeded() - if err != nil { + if err := trieDB.initializeRootIfNeeded(); err != nil { return nil, err } // add current root to history (has no changes) trieDB.history.record(&changeSummary{ - rootID: root, + rootID: trieDB.getMerkleRoot(), rootChange: &change[*node]{ - after: trieDB.root.Value(), // TODO is this right? + after: trieDB.root.Value(), }, values: map[Path]*change[maybe.Maybe[[]byte]]{}, nodes: map[Path]*change[*node]{}, @@ -1163,21 +1162,21 @@ func (db *merkleDB) invalidateChildrenExcept(exception *trieView) { } } -func (db *merkleDB) initializeRootIfNeeded() (ids.ID, error) { +func (db *merkleDB) initializeRootIfNeeded() error { rootBytes, err := db.baseDB.Get(rootDBKey) if err != nil { if !errors.Is(err, database.ErrNotFound) { - return ids.ID{}, err + return err } // Root isn't on disk. - return ids.Empty, nil // TODO document empty ID meaning empty trie + return nil // TODO document empty ID meaning empty trie } // Root is on disk. var rootDBNode dbNode rootKey, err := codec.decodeKeyAndNode(rootBytes, &rootDBNode, db.valueNodeDB.branchFactor) if err != nil { - return ids.ID{}, err + return err } root := &node{ dbNode: rootDBNode, @@ -1186,7 +1185,7 @@ func (db *merkleDB) initializeRootIfNeeded() (ids.ID, error) { root.setValueDigest() root.calculateID(db.metrics) db.root = maybe.Some(root) - return root.id, nil + return nil } // Returns a view of the trie as it was when it had root [rootID] for keys within range [start, end]. From e84d83ea999e00e6a2152a47beac431a6fa258f9 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 18 Oct 2023 16:34:15 -0400 Subject: [PATCH 026/131] comment --- x/merkledb/trie.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/merkledb/trie.go b/x/merkledb/trie.go index a34e22654f14..4ae79a961983 100644 --- a/x/merkledb/trie.go +++ b/x/merkledb/trie.go @@ -12,7 +12,8 @@ import ( ) type MerkleRootGetter interface { - // GetMerkleRoot returns the merkle root of the Trie + // GetMerkleRoot returns the merkle root of the trie. + // Returns ids.Empty if the trie is empty. GetMerkleRoot(ctx context.Context) (ids.ID, error) } From 92cd32395f74115d54df76633e9b0ac2c62f9fb3 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 18 Oct 2023 16:37:51 -0400 Subject: [PATCH 027/131] comment --- x/merkledb/db.go | 4 ++-- x/merkledb/history.go | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 81784c9b4c16..7aaa783b1c0f 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -581,7 +581,7 @@ func (db *merkleDB) GetMerkleRoot(ctx context.Context) (ids.ID, error) { // Assumes [db.lock] is read locked. func (db *merkleDB) getMerkleRoot() ids.ID { if db.root.IsNothing() { - return ids.Empty // TODO document this + return ids.Empty } return db.root.Value().id } @@ -1169,7 +1169,7 @@ func (db *merkleDB) initializeRootIfNeeded() error { return err } // Root isn't on disk. - return nil // TODO document empty ID meaning empty trie + return nil } // Root is on disk. diff --git a/x/merkledb/history.go b/x/merkledb/history.go index 2f1ea7571ff2..fd9b5c2ac794 100644 --- a/x/merkledb/history.go +++ b/x/merkledb/history.go @@ -54,7 +54,9 @@ type changeSummaryAndInsertNumber struct { // Tracks all of the node and value changes that resulted in the rootID. type changeSummary struct { // The ID of the trie after these changes. - rootID ids.ID + rootID ids.ID + // The root before/after this change. + // If the trie is empty, its root is nil here. rootChange *change[*node] nodes map[Path]*change[*node] values map[Path]*change[maybe.Maybe[[]byte]] From 888d9b9bdcbd7b631042233aeb0bd93b450d636c Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 18 Oct 2023 16:40:46 -0400 Subject: [PATCH 028/131] nit --- x/merkledb/history.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/merkledb/history.go b/x/merkledb/history.go index fd9b5c2ac794..bd668b0d8ea0 100644 --- a/x/merkledb/history.go +++ b/x/merkledb/history.go @@ -57,6 +57,7 @@ type changeSummary struct { rootID ids.ID // The root before/after this change. // If the trie is empty, its root is nil here. + // Set in [calculateNodeIDs]. rootChange *change[*node] nodes map[Path]*change[*node] values map[Path]*change[maybe.Maybe[[]byte]] From 01668e515b75774dc4ceeac0dc552b3a9486a996 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 18 Oct 2023 16:47:38 -0400 Subject: [PATCH 029/131] nits --- x/merkledb/history_test.go | 28 ++++++++++++++-------------- x/merkledb/trieview.go | 19 ++++++------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/x/merkledb/history_test.go b/x/merkledb/history_test.go index 8380815e6ee3..49222bca80f8 100644 --- a/x/merkledb/history_test.go +++ b/x/merkledb/history_test.go @@ -686,23 +686,23 @@ func TestHistoryGetChangesToRoot(t *testing.T) { } tests := []test{ - // { - // name: "unknown root ID", - // rootID: ids.GenerateTestID(), - // expectedErr: ErrInsufficientHistory, - // }, - // { - // name: "most recent change", - // rootID: changes[maxHistoryLen-1].rootID, - // validateFunc: func(require *require.Assertions, got *changeSummary) { - // expected := newChangeSummary(defaultPreallocationSize) - // require.Equal(expected, got) - // }, - // }, + { + name: "unknown root ID", + rootID: ids.GenerateTestID(), + expectedErr: ErrInsufficientHistory, + }, + { + name: "most recent change", + rootID: changes[maxHistoryLen-1].rootID, + validateFunc: func(require *require.Assertions, got *changeSummary) { + expected := newChangeSummary(defaultPreallocationSize) + require.Equal(expected, got) + }, + }, { name: "second most recent change", rootID: changes[maxHistoryLen-2].rootID, - validateFunc: func(require *require.Assertions, got *changeSummary) { // TODO add assertions for rootChange + validateFunc: func(require *require.Assertions, got *changeSummary) { // Ensure this is the reverse of the most recent change require.Len(got.nodes, 1) require.Len(got.values, 1) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 6a14f71581b5..ef1c23b2cc12 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -145,13 +145,6 @@ func newTrieView( parentTrie TrieView, changes ViewChanges, ) (*trieView, error) { - // root, err := parentTrie.getEditableNode(parentTrie.getRootKey(), false /* hasValue */) - // if err != nil { - // if err == database.ErrNotFound { - // return nil, ErrNoValidRoot - // } - // return nil, err - // } root := parentTrie.getRoot() if root.HasValue() { root = maybe.Some(root.Value().clone()) // TODO better way of doing this? @@ -201,10 +194,9 @@ func newHistoricalTrieView( return nil, ErrNoValidRoot } - // TODO is this right? root := maybe.Nothing[*node]() if changes.rootChange.after != nil { - root = maybe.Some(changes.rootChange.after.clone()) // TODO clone needed? + root = maybe.Some(changes.rootChange.after) } newView := &trieView{ root: root, @@ -236,7 +228,6 @@ func (t *trieView) calculateNodeIDs(ctx context.Context) error { oldRoot := t.root.Value() if oldRoot != nil { - // TODO is this right? oldRoot = oldRoot.clone() } @@ -579,7 +570,7 @@ func (t *trieView) GetMerkleRoot(ctx context.Context) (ids.ID, error) { return ids.Empty, err } if t.root.IsNothing() { - return ids.Empty, nil // TODO document/handle + return ids.Empty, nil } return t.root.Value().id, nil } @@ -660,6 +651,7 @@ func (t *trieView) remove(key Path) error { // the key wasn't in the trie return nil } + // [t.root] has a value. nodeToDelete := nodePath[len(nodePath)-1] @@ -678,7 +670,7 @@ func (t *trieView) remove(key Path) error { nodeToDelete.setValue(maybe.Nothing[[]byte]()) - if nodeToDelete.key == t.root.Value().key { // TODO is this right? + if nodeToDelete.key == t.root.Value().key { // We're deleting the root. switch len(nodeToDelete.children) { case 0: @@ -730,7 +722,8 @@ func (t *trieView) remove(key Path) error { // Merges together nodes in the inclusive descendnnts of [n] that // have no value and a single child into one node with a compressed // path until a node that doesn't meet those criteria is reached. -// [parent] is [n]'s parent. +// [parent] is [n]'s parent. If [parent] is nil, [n] is the root +// node and [t.root] is updated to [n]. // Assumes at least one of the following is true: // * [n] has a value. // * [n] has children. From a6c5e1f0721799415ea479b497ee3ccddac272b9 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 18 Oct 2023 16:52:51 -0400 Subject: [PATCH 030/131] appease linter --- x/merkledb/db.go | 3 +-- x/merkledb/proof_test.go | 5 +++-- x/merkledb/trie_test.go | 1 - x/merkledb/trieview.go | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 7aaa783b1c0f..04b8aff43be4 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -41,8 +41,7 @@ const ( ) var ( - emptyKey []byte - _ MerkleDB = (*merkleDB)(nil) + _ MerkleDB = (*merkleDB)(nil) codec = newCodec() diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index 8e145e9cdf53..a734ebdd3dc9 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -282,7 +282,8 @@ func Test_Proof(t *testing.T) { require.NoError(proof.Verify(context.Background(), expectedRootID)) proof.Path[0].KeyPath = NewPath([]byte("key1"), BranchFactor16) - require.Error(proof.Verify(context.Background(), expectedRootID)) + err = proof.Verify(context.Background(), expectedRootID) + require.ErrorIs(err, ErrProofNodeNotForKey) } func Test_RangeProof_Syntactic_Verify(t *testing.T) { @@ -675,7 +676,7 @@ func Test_ChangeProof_Missing_History_For_EndRoot(t *testing.T) { require := require.New(t) seed := time.Now().UnixNano() t.Logf("Seed: %d", seed) - rand := rand.New(rand.NewSource(seed)) + rand := rand.New(rand.NewSource(seed)) // #nosec G404 db, err := getBasicDB() require.NoError(err) diff --git a/x/merkledb/trie_test.go b/x/merkledb/trie_test.go index e20473743506..7696e24c9384 100644 --- a/x/merkledb/trie_test.go +++ b/x/merkledb/trie_test.go @@ -879,7 +879,6 @@ func Test_Trie_NodeCollapse(t *testing.T) { require.Equal(kv.Value, node.value.Value()) } - } func Test_Trie_MultipleStates(t *testing.T) { diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index ef1c23b2cc12..04980815d228 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -698,8 +698,7 @@ func (t *trieView) remove(key Path) error { return nil default: // The root has multiple children so we can't delete it. - t.recordNodeChange(nodeToDelete) - return nil + return t.recordNodeChange(nodeToDelete) } } From c5e8c4de51bbd7f2070cacbd3d9fc7d101b94a66 Mon Sep 17 00:00:00 2001 From: dboehm-avalabs Date: Wed, 18 Oct 2023 17:14:24 -0400 Subject: [PATCH 031/131] Update trie_test.go --- x/merkledb/trie_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/merkledb/trie_test.go b/x/merkledb/trie_test.go index 7696e24c9384..fabed205df39 100644 --- a/x/merkledb/trie_test.go +++ b/x/merkledb/trie_test.go @@ -52,6 +52,9 @@ func getNodeValueWithBranchFactor(t ReadOnlyTrie, key string, bf BranchFactor) ( if err != nil { return nil, err } + if len(nodePath) == 0 { + return nil, database.ErrNotFound + } closestNode := nodePath[len(nodePath)-1] if closestNode.key != path || closestNode == nil { return nil, database.ErrNotFound From 5a5675388aedfcff05b1a80539a436b52eecc202 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 10:39:06 -0400 Subject: [PATCH 032/131] codec cleanup --- x/merkledb/codec.go | 16 +++++++--------- x/merkledb/codec_test.go | 7 +++++-- x/merkledb/db.go | 14 +++++++++++--- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/x/merkledb/codec.go b/x/merkledb/codec.go index 94b0639c34e4..ade085a2b435 100644 --- a/x/merkledb/codec.go +++ b/x/merkledb/codec.go @@ -68,7 +68,7 @@ type encoder interface { type decoder interface { // Assumes [n] is non-nil. decodeDBNode(bytes []byte, n *dbNode, factor BranchFactor) error - decodeKeyAndNode(bytes []byte, n *dbNode, factor BranchFactor) (Path, error) // TODO should this return a Path? + decodeKeyAndNode(bytes []byte, key *Path, n *dbNode, factor BranchFactor) error } func newCodec() encoderDecoder { @@ -209,22 +209,20 @@ func (c *codecImpl) decodeDBNode(b []byte, n *dbNode, branchFactor BranchFactor) return c.decodeDBNodeFromReader(bytes.NewReader(b), n, branchFactor) } -func (c *codecImpl) decodeKeyAndNode(b []byte, n *dbNode, branchFactor BranchFactor) (Path, error) { +func (c *codecImpl) decodeKeyAndNode(b []byte, key *Path, n *dbNode, branchFactor BranchFactor) error { if minPathLen+minDBNodeLen > len(b) { - return Path{}, io.ErrUnexpectedEOF + return io.ErrUnexpectedEOF } src := bytes.NewReader(b) - key, err := c.decodePath(src, branchFactor) + var err error + *key, err = c.decodePath(src, branchFactor) if err != nil { - return Path{}, err + return err } - if err := c.decodeDBNodeFromReader(src, n, branchFactor); err != nil { - return Path{}, err - } - return key, nil + return c.decodeDBNodeFromReader(src, n, branchFactor) } func (*codecImpl) encodeBool(dst *bytes.Buffer, value bool) { diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index 1c4aac9214d6..facf5de56e7e 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -289,8 +289,11 @@ func TestEncodeDecodeKeyAndNode(t *testing.T) { }, } b := codec.encodeKeyAndNode(key, expectedNode, branchFactor) - var gotNode dbNode - gotKey, err := codec.decodeKeyAndNode(b, &gotNode, branchFactor) + var ( + gotNode dbNode + gotKey Path + ) + err := codec.decodeKeyAndNode(b, &gotKey, &gotNode, branchFactor) require.NoError(err) require.Equal(expectedNode, &gotNode) require.Equal(key, gotKey) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 04b8aff43be4..72f622010e75 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1172,11 +1172,19 @@ func (db *merkleDB) initializeRootIfNeeded() error { } // Root is on disk. - var rootDBNode dbNode - rootKey, err := codec.decodeKeyAndNode(rootBytes, &rootDBNode, db.valueNodeDB.branchFactor) - if err != nil { + var ( + rootDBNode dbNode + rootKey Path + ) + if err := codec.decodeKeyAndNode( + rootBytes, + &rootKey, + &rootDBNode, + db.valueNodeDB.branchFactor, + ); err != nil { return err } + newNode(nil, rootKey) root := &node{ dbNode: rootDBNode, key: rootKey, From 9d7477d7f3de55e26446e9950e05bb0b61dd859e Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 10:45:51 -0400 Subject: [PATCH 033/131] codec cleanup --- x/merkledb/codec.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/x/merkledb/codec.go b/x/merkledb/codec.go index ade085a2b435..9737bdd314af 100644 --- a/x/merkledb/codec.go +++ b/x/merkledb/codec.go @@ -90,26 +90,26 @@ type codecImpl struct { } func (c *codecImpl) encodeDBNode(n *dbNode, branchFactor BranchFactor) []byte { - var ( - numChildren = len(n.children) - // Estimate size of [n] to prevent memory allocations - estimatedLen = estimatedValueLen + minVarIntLen + estimatedNodeChildLen*numChildren - buf = bytes.NewBuffer(make([]byte, 0, estimatedLen)) - ) + // Estimate size of [n] to prevent memory allocations + estimatedLen := estimatedValueLen + minVarIntLen + estimatedNodeChildLen*len(n.children) + buf := bytes.NewBuffer(make([]byte, 0, estimatedLen)) + return c.encodeDBNodeToBuffer(buf, n, branchFactor) +} - c.encodeMaybeByteSlice(buf, n.value) - c.encodeUint(buf, uint64(numChildren)) +func (c *codecImpl) encodeDBNodeToBuffer(dst *bytes.Buffer, n *dbNode, branchFactor BranchFactor) []byte { + c.encodeMaybeByteSlice(dst, n.value) + c.encodeUint(dst, uint64(len(n.children))) // Note we insert children in order of increasing index // for determinism. for index := 0; BranchFactor(index) < branchFactor; index++ { if entry, ok := n.children[byte(index)]; ok { - c.encodeUint(buf, uint64(index)) - c.encodePath(buf, entry.compressedPath) - _, _ = buf.Write(entry.id[:]) - c.encodeBool(buf, entry.hasValue) + c.encodeUint(dst, uint64(index)) + c.encodePath(dst, entry.compressedPath) + _, _ = dst.Write(entry.id[:]) + c.encodeBool(dst, entry.hasValue) } } - return buf.Bytes() + return dst.Bytes() } func (c *codecImpl) encodeHashValues(hv *hashValues) []byte { @@ -144,7 +144,7 @@ func (c *codecImpl) encodeKeyAndNode(key Path, n *dbNode, factor BranchFactor) [ ) c.encodePath(buf, key) - _, _ = buf.Write(c.encodeDBNode(n, factor)) // TODO improve + c.encodeDBNodeToBuffer(buf, n, factor) return buf.Bytes() } From 34380f28734bea65c779cfc7c68747269478b12d Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 10:54:03 -0400 Subject: [PATCH 034/131] appease linter --- x/merkledb/trie_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/merkledb/trie_test.go b/x/merkledb/trie_test.go index fabed205df39..ac93534c361c 100644 --- a/x/merkledb/trie_test.go +++ b/x/merkledb/trie_test.go @@ -210,7 +210,7 @@ func TestTrieViewGetPathTo(t *testing.T) { require.NoError(err) require.Len(nodePath, 2) require.Equal(trie.root.Value(), nodePath[0]) - require.Equal(0, trie.root.Value().key.tokensLength) + require.Zero(trie.root.Value().key.tokensLength) require.Equal(NewPath(key3, BranchFactor16), nodePath[1].key) nodePath, err = trie.getPathTo(NewPath(key2, BranchFactor16)) From 82c0061a4d0cb1d9efdbe0cb0953bc9b79c27f7d Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 11:22:18 -0400 Subject: [PATCH 035/131] appease linter --- x/merkledb/codec_test.go | 3 +-- x/merkledb/history_test.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index facf5de56e7e..42efaf39b70e 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -293,8 +293,7 @@ func TestEncodeDecodeKeyAndNode(t *testing.T) { gotNode dbNode gotKey Path ) - err := codec.decodeKeyAndNode(b, &gotKey, &gotNode, branchFactor) - require.NoError(err) + require.NoError(codec.decodeKeyAndNode(b, &gotKey, &gotNode, branchFactor)) require.Equal(expectedNode, &gotNode) require.Equal(key, gotKey) } diff --git a/x/merkledb/history_test.go b/x/merkledb/history_test.go index 49222bca80f8..1799c0c27da2 100644 --- a/x/merkledb/history_test.go +++ b/x/merkledb/history_test.go @@ -13,6 +13,7 @@ import ( "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/maybe" ) @@ -780,3 +781,19 @@ func TestHistoryGetChangesToRoot(t *testing.T) { }) } } + +func TestGenerateBLSSig(t *testing.T) { + require := require.New(t) + + // Generate a key + key, err := bls.NewSecretKey() + require.NoError(err) + + // Generate a message + message := []byte("hello world") + + // Generate a signature + sig := bls.Sign(key, message) + + t.Log("Signature:", sig) +} From 14def095640c3e14830aa5e12fc2de265a3c5668 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 11:57:33 -0400 Subject: [PATCH 036/131] remove errant test --- x/merkledb/history_test.go | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/x/merkledb/history_test.go b/x/merkledb/history_test.go index 1799c0c27da2..49222bca80f8 100644 --- a/x/merkledb/history_test.go +++ b/x/merkledb/history_test.go @@ -13,7 +13,6 @@ import ( "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/maybe" ) @@ -781,19 +780,3 @@ func TestHistoryGetChangesToRoot(t *testing.T) { }) } } - -func TestGenerateBLSSig(t *testing.T) { - require := require.New(t) - - // Generate a key - key, err := bls.NewSecretKey() - require.NoError(err) - - // Generate a message - message := []byte("hello world") - - // Generate a signature - sig := bls.Sign(key, message) - - t.Log("Signature:", sig) -} From 8a412665b5c06240cf65accd097878274786a3c4 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 12:05:52 -0400 Subject: [PATCH 037/131] make test fuzz test --- x/merkledb/codec_test.go | 77 +++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index 42efaf39b70e..bfb6b85d4892 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -271,30 +271,59 @@ func TestCodecDecodePathLengthOverflowRegression(t *testing.T) { require.ErrorIs(t, err, io.ErrUnexpectedEOF) } -// TODO make fuzz test -func TestEncodeDecodeKeyAndNode(t *testing.T) { - require := require.New(t) +func FuzzEncodeDecodeKeyAndNode(f *testing.F) { + require := require.New(f) codec := newCodec() - for _, branchFactor := range branchFactors { - key := NewPath([]byte{1, 2, 3}, branchFactor) - expectedNode := &dbNode{ - value: maybe.Some([]byte{1}), - children: map[byte]child{ - 0: { - compressedPath: NewPath([]byte{2, 3}, branchFactor), - id: ids.GenerateTestID(), - hasValue: true, - }, - }, - } - b := codec.encodeKeyAndNode(key, expectedNode, branchFactor) - var ( - gotNode dbNode - gotKey Path - ) - require.NoError(codec.decodeKeyAndNode(b, &gotKey, &gotNode, branchFactor)) - require.Equal(expectedNode, &gotNode) - require.Equal(key, gotKey) - } + f.Fuzz( + func( + t *testing.T, + keyBytes []byte, + hasValue bool, + value []byte, + removeToken bool, + numChildren int, + ) { + for _, branchFactor := range branchFactors { + key := NewPath(keyBytes, branchFactor) + + if removeToken && key.tokensLength > 0 { + key = key.Skip(1) + } + + val := maybe.Nothing[[]byte]() + if hasValue { + val = maybe.Some(value) + } + + if numChildren > int(branchFactor) { + numChildren = int(branchFactor) + } + + children := map[byte]child{} + for i := 0; i < numChildren; i++ { + compressedPathBytes := make([]byte, 32) + _, _ = rand.Read(compressedPathBytes) // #nosec G404 + children[byte(i)] = child{ + compressedPath: NewPath(compressedPathBytes, branchFactor), + id: ids.GenerateTestID(), + hasValue: true, + } + } + + expectedNode := &dbNode{ + value: val, + children: children, + } + b := codec.encodeKeyAndNode(key, expectedNode, branchFactor) + var ( + gotNode dbNode + gotKey Path + ) + require.NoError(codec.decodeKeyAndNode(b, &gotKey, &gotNode, branchFactor)) + require.Equal(expectedNode, &gotNode) + require.Equal(key, gotKey) + } + }, + ) } From 41e0d8ded174ee69a7ba545a9c47d0044fb5747b Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 12:09:12 -0400 Subject: [PATCH 038/131] fix mock --- scripts/mocks.mockgen.txt | 1 - x/merkledb/mock_db.go | 396 +++++++++++++++++++------------------- 2 files changed, 203 insertions(+), 194 deletions(-) diff --git a/scripts/mocks.mockgen.txt b/scripts/mocks.mockgen.txt index 0dac9d20e298..ebd793330a51 100644 --- a/scripts/mocks.mockgen.txt +++ b/scripts/mocks.mockgen.txt @@ -49,5 +49,4 @@ github.com/ava-labs/avalanchego/vms/registry=VMGetter=vms/registry/mock_vm_gette github.com/ava-labs/avalanchego/vms/registry=VMRegisterer=vms/registry/mock_vm_registerer.go github.com/ava-labs/avalanchego/vms/registry=VMRegistry=vms/registry/mock_vm_registry.go github.com/ava-labs/avalanchego/vms=Factory,Manager=vms/mock_manager.go -github.com/ava-labs/avalanchego/x/merkledb=MerkleDB=x/merkledb/mock_db.go github.com/ava-labs/avalanchego/x/sync=Client=x/sync/mock_client.go diff --git a/x/merkledb/mock_db.go b/x/merkledb/mock_db.go index f2d8eae8a69b..6b0d991a5949 100644 --- a/x/merkledb/mock_db.go +++ b/x/merkledb/mock_db.go @@ -1,6 +1,3 @@ -// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - // Code generated by MockGen. DO NOT EDIT. // Source: github.com/ava-labs/avalanchego/x/merkledb (interfaces: MerkleDB) @@ -8,425 +5,438 @@ package merkledb import ( - context "context" - reflect "reflect" - - database "github.com/ava-labs/avalanchego/database" - ids "github.com/ava-labs/avalanchego/ids" - maybe "github.com/ava-labs/avalanchego/utils/maybe" - gomock "go.uber.org/mock/gomock" + database "github.com/ava-labs/avalanchego/database" + ids "github.com/ava-labs/avalanchego/ids" + maybe "github.com/ava-labs/avalanchego/utils/maybe" + gomock "go.uber.org/mock/gomock" + reflect "reflect" + context "context" ) // MockMerkleDB is a mock of MerkleDB interface. type MockMerkleDB struct { - ctrl *gomock.Controller - recorder *MockMerkleDBMockRecorder + ctrl *gomock.Controller + recorder *MockMerkleDBMockRecorder } // MockMerkleDBMockRecorder is the mock recorder for MockMerkleDB. type MockMerkleDBMockRecorder struct { - mock *MockMerkleDB + mock *MockMerkleDB } // NewMockMerkleDB creates a new mock instance. func NewMockMerkleDB(ctrl *gomock.Controller) *MockMerkleDB { - mock := &MockMerkleDB{ctrl: ctrl} - mock.recorder = &MockMerkleDBMockRecorder{mock} - return mock + mock := &MockMerkleDB{ctrl: ctrl} + mock.recorder = &MockMerkleDBMockRecorder{mock} + return mock } // EXPECT returns an object that allows the caller to indicate expected use. func (m *MockMerkleDB) EXPECT() *MockMerkleDBMockRecorder { - return m.recorder + return m.recorder } // Close mocks base method. func (m *MockMerkleDB) Close() error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Close") - ret0, _ := ret[0].(error) - return ret0 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Close") + ret0, _ := ret[0].(error) + return ret0 } // Close indicates an expected call of Close. func (mr *MockMerkleDBMockRecorder) Close() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockMerkleDB)(nil).Close)) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockMerkleDB)(nil).Close)) } // CommitChangeProof mocks base method. func (m *MockMerkleDB) CommitChangeProof(arg0 context.Context, arg1 *ChangeProof) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CommitChangeProof", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CommitChangeProof", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 } // CommitChangeProof indicates an expected call of CommitChangeProof. func (mr *MockMerkleDBMockRecorder) CommitChangeProof(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CommitChangeProof", reflect.TypeOf((*MockMerkleDB)(nil).CommitChangeProof), arg0, arg1) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CommitChangeProof", reflect.TypeOf((*MockMerkleDB)(nil).CommitChangeProof), arg0, arg1) } // CommitRangeProof mocks base method. func (m *MockMerkleDB) CommitRangeProof(arg0 context.Context, arg1, arg2 maybe.Maybe[[]uint8], arg3 *RangeProof) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CommitRangeProof", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(error) - return ret0 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CommitRangeProof", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(error) + return ret0 } // CommitRangeProof indicates an expected call of CommitRangeProof. func (mr *MockMerkleDBMockRecorder) CommitRangeProof(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CommitRangeProof", reflect.TypeOf((*MockMerkleDB)(nil).CommitRangeProof), arg0, arg1, arg2, arg3) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CommitRangeProof", reflect.TypeOf((*MockMerkleDB)(nil).CommitRangeProof), arg0, arg1, arg2, arg3) } // Compact mocks base method. func (m *MockMerkleDB) Compact(arg0, arg1 []byte) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Compact", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Compact", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 } // Compact indicates an expected call of Compact. func (mr *MockMerkleDBMockRecorder) Compact(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Compact", reflect.TypeOf((*MockMerkleDB)(nil).Compact), arg0, arg1) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Compact", reflect.TypeOf((*MockMerkleDB)(nil).Compact), arg0, arg1) } // Delete mocks base method. func (m *MockMerkleDB) Delete(arg0 []byte) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Delete", arg0) - ret0, _ := ret[0].(error) - return ret0 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", arg0) + ret0, _ := ret[0].(error) + return ret0 } // Delete indicates an expected call of Delete. func (mr *MockMerkleDBMockRecorder) Delete(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockMerkleDB)(nil).Delete), arg0) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockMerkleDB)(nil).Delete), arg0) } // Get mocks base method. func (m *MockMerkleDB) Get(arg0 []byte) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Get", arg0) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 } // Get indicates an expected call of Get. func (mr *MockMerkleDBMockRecorder) Get(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockMerkleDB)(nil).Get), arg0) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockMerkleDB)(nil).Get), arg0) } // GetChangeProof mocks base method. func (m *MockMerkleDB) GetChangeProof(arg0 context.Context, arg1, arg2 ids.ID, arg3, arg4 maybe.Maybe[[]uint8], arg5 int) (*ChangeProof, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetChangeProof", arg0, arg1, arg2, arg3, arg4, arg5) - ret0, _ := ret[0].(*ChangeProof) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetChangeProof", arg0, arg1, arg2, arg3, arg4, arg5) + ret0, _ := ret[0].(*ChangeProof) + ret1, _ := ret[1].(error) + return ret0, ret1 } // GetChangeProof indicates an expected call of GetChangeProof. func (mr *MockMerkleDBMockRecorder) GetChangeProof(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChangeProof", reflect.TypeOf((*MockMerkleDB)(nil).GetChangeProof), arg0, arg1, arg2, arg3, arg4, arg5) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChangeProof", reflect.TypeOf((*MockMerkleDB)(nil).GetChangeProof), arg0, arg1, arg2, arg3, arg4, arg5) } // GetMerkleRoot mocks base method. func (m *MockMerkleDB) GetMerkleRoot(arg0 context.Context) (ids.ID, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetMerkleRoot", arg0) - ret0, _ := ret[0].(ids.ID) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetMerkleRoot", arg0) + ret0, _ := ret[0].(ids.ID) + ret1, _ := ret[1].(error) + return ret0, ret1 } // GetMerkleRoot indicates an expected call of GetMerkleRoot. func (mr *MockMerkleDBMockRecorder) GetMerkleRoot(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMerkleRoot", reflect.TypeOf((*MockMerkleDB)(nil).GetMerkleRoot), arg0) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMerkleRoot", reflect.TypeOf((*MockMerkleDB)(nil).GetMerkleRoot), arg0) } // GetProof mocks base method. func (m *MockMerkleDB) GetProof(arg0 context.Context, arg1 []byte) (*Proof, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetProof", arg0, arg1) - ret0, _ := ret[0].(*Proof) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetProof", arg0, arg1) + ret0, _ := ret[0].(*Proof) + ret1, _ := ret[1].(error) + return ret0, ret1 } // GetProof indicates an expected call of GetProof. func (mr *MockMerkleDBMockRecorder) GetProof(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetProof", reflect.TypeOf((*MockMerkleDB)(nil).GetProof), arg0, arg1) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetProof", reflect.TypeOf((*MockMerkleDB)(nil).GetProof), arg0, arg1) } // GetRangeProof mocks base method. func (m *MockMerkleDB) GetRangeProof(arg0 context.Context, arg1, arg2 maybe.Maybe[[]uint8], arg3 int) (*RangeProof, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetRangeProof", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(*RangeProof) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRangeProof", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(*RangeProof) + ret1, _ := ret[1].(error) + return ret0, ret1 } // GetRangeProof indicates an expected call of GetRangeProof. func (mr *MockMerkleDBMockRecorder) GetRangeProof(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRangeProof", reflect.TypeOf((*MockMerkleDB)(nil).GetRangeProof), arg0, arg1, arg2, arg3) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRangeProof", reflect.TypeOf((*MockMerkleDB)(nil).GetRangeProof), arg0, arg1, arg2, arg3) } // GetRangeProofAtRoot mocks base method. func (m *MockMerkleDB) GetRangeProofAtRoot(arg0 context.Context, arg1 ids.ID, arg2, arg3 maybe.Maybe[[]uint8], arg4 int) (*RangeProof, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetRangeProofAtRoot", arg0, arg1, arg2, arg3, arg4) - ret0, _ := ret[0].(*RangeProof) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRangeProofAtRoot", arg0, arg1, arg2, arg3, arg4) + ret0, _ := ret[0].(*RangeProof) + ret1, _ := ret[1].(error) + return ret0, ret1 } // GetRangeProofAtRoot indicates an expected call of GetRangeProofAtRoot. func (mr *MockMerkleDBMockRecorder) GetRangeProofAtRoot(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRangeProofAtRoot", reflect.TypeOf((*MockMerkleDB)(nil).GetRangeProofAtRoot), arg0, arg1, arg2, arg3, arg4) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRangeProofAtRoot", reflect.TypeOf((*MockMerkleDB)(nil).GetRangeProofAtRoot), arg0, arg1, arg2, arg3, arg4) } // GetValue mocks base method. func (m *MockMerkleDB) GetValue(arg0 context.Context, arg1 []byte) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetValue", arg0, arg1) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetValue", arg0, arg1) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 } // GetValue indicates an expected call of GetValue. func (mr *MockMerkleDBMockRecorder) GetValue(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValue", reflect.TypeOf((*MockMerkleDB)(nil).GetValue), arg0, arg1) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValue", reflect.TypeOf((*MockMerkleDB)(nil).GetValue), arg0, arg1) } // GetValues mocks base method. func (m *MockMerkleDB) GetValues(arg0 context.Context, arg1 [][]byte) ([][]byte, []error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetValues", arg0, arg1) - ret0, _ := ret[0].([][]byte) - ret1, _ := ret[1].([]error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetValues", arg0, arg1) + ret0, _ := ret[0].([][]byte) + ret1, _ := ret[1].([]error) + return ret0, ret1 } // GetValues indicates an expected call of GetValues. func (mr *MockMerkleDBMockRecorder) GetValues(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValues", reflect.TypeOf((*MockMerkleDB)(nil).GetValues), arg0, arg1) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValues", reflect.TypeOf((*MockMerkleDB)(nil).GetValues), arg0, arg1) } // Has mocks base method. func (m *MockMerkleDB) Has(arg0 []byte) (bool, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Has", arg0) - ret0, _ := ret[0].(bool) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Has", arg0) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 } // Has indicates an expected call of Has. func (mr *MockMerkleDBMockRecorder) Has(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Has", reflect.TypeOf((*MockMerkleDB)(nil).Has), arg0) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Has", reflect.TypeOf((*MockMerkleDB)(nil).Has), arg0) } // HealthCheck mocks base method. func (m *MockMerkleDB) HealthCheck(arg0 context.Context) (interface{}, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "HealthCheck", arg0) - ret0, _ := ret[0].(interface{}) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HealthCheck", arg0) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(error) + return ret0, ret1 } // HealthCheck indicates an expected call of HealthCheck. func (mr *MockMerkleDBMockRecorder) HealthCheck(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HealthCheck", reflect.TypeOf((*MockMerkleDB)(nil).HealthCheck), arg0) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HealthCheck", reflect.TypeOf((*MockMerkleDB)(nil).HealthCheck), arg0) } // NewBatch mocks base method. func (m *MockMerkleDB) NewBatch() database.Batch { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NewBatch") - ret0, _ := ret[0].(database.Batch) - return ret0 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewBatch") + ret0, _ := ret[0].(database.Batch) + return ret0 } // NewBatch indicates an expected call of NewBatch. func (mr *MockMerkleDBMockRecorder) NewBatch() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewBatch", reflect.TypeOf((*MockMerkleDB)(nil).NewBatch)) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewBatch", reflect.TypeOf((*MockMerkleDB)(nil).NewBatch)) } // NewIterator mocks base method. func (m *MockMerkleDB) NewIterator() database.Iterator { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NewIterator") - ret0, _ := ret[0].(database.Iterator) - return ret0 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewIterator") + ret0, _ := ret[0].(database.Iterator) + return ret0 } // NewIterator indicates an expected call of NewIterator. func (mr *MockMerkleDBMockRecorder) NewIterator() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewIterator", reflect.TypeOf((*MockMerkleDB)(nil).NewIterator)) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewIterator", reflect.TypeOf((*MockMerkleDB)(nil).NewIterator)) } // NewIteratorWithPrefix mocks base method. func (m *MockMerkleDB) NewIteratorWithPrefix(arg0 []byte) database.Iterator { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NewIteratorWithPrefix", arg0) - ret0, _ := ret[0].(database.Iterator) - return ret0 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewIteratorWithPrefix", arg0) + ret0, _ := ret[0].(database.Iterator) + return ret0 } // NewIteratorWithPrefix indicates an expected call of NewIteratorWithPrefix. func (mr *MockMerkleDBMockRecorder) NewIteratorWithPrefix(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewIteratorWithPrefix", reflect.TypeOf((*MockMerkleDB)(nil).NewIteratorWithPrefix), arg0) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewIteratorWithPrefix", reflect.TypeOf((*MockMerkleDB)(nil).NewIteratorWithPrefix), arg0) } // NewIteratorWithStart mocks base method. func (m *MockMerkleDB) NewIteratorWithStart(arg0 []byte) database.Iterator { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NewIteratorWithStart", arg0) - ret0, _ := ret[0].(database.Iterator) - return ret0 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewIteratorWithStart", arg0) + ret0, _ := ret[0].(database.Iterator) + return ret0 } // NewIteratorWithStart indicates an expected call of NewIteratorWithStart. func (mr *MockMerkleDBMockRecorder) NewIteratorWithStart(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewIteratorWithStart", reflect.TypeOf((*MockMerkleDB)(nil).NewIteratorWithStart), arg0) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewIteratorWithStart", reflect.TypeOf((*MockMerkleDB)(nil).NewIteratorWithStart), arg0) } // NewIteratorWithStartAndPrefix mocks base method. func (m *MockMerkleDB) NewIteratorWithStartAndPrefix(arg0, arg1 []byte) database.Iterator { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NewIteratorWithStartAndPrefix", arg0, arg1) - ret0, _ := ret[0].(database.Iterator) - return ret0 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewIteratorWithStartAndPrefix", arg0, arg1) + ret0, _ := ret[0].(database.Iterator) + return ret0 } // NewIteratorWithStartAndPrefix indicates an expected call of NewIteratorWithStartAndPrefix. func (mr *MockMerkleDBMockRecorder) NewIteratorWithStartAndPrefix(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewIteratorWithStartAndPrefix", reflect.TypeOf((*MockMerkleDB)(nil).NewIteratorWithStartAndPrefix), arg0, arg1) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewIteratorWithStartAndPrefix", reflect.TypeOf((*MockMerkleDB)(nil).NewIteratorWithStartAndPrefix), arg0, arg1) } // NewView mocks base method. func (m *MockMerkleDB) NewView(arg0 context.Context, arg1 ViewChanges) (TrieView, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NewView", arg0, arg1) - ret0, _ := ret[0].(TrieView) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewView", arg0, arg1) + ret0, _ := ret[0].(TrieView) + ret1, _ := ret[1].(error) + return ret0, ret1 } // NewView indicates an expected call of NewView. func (mr *MockMerkleDBMockRecorder) NewView(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewView", reflect.TypeOf((*MockMerkleDB)(nil).NewView), arg0, arg1) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewView", reflect.TypeOf((*MockMerkleDB)(nil).NewView), arg0, arg1) } // PrefetchPath mocks base method. func (m *MockMerkleDB) PrefetchPath(arg0 []byte) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PrefetchPath", arg0) - ret0, _ := ret[0].(error) - return ret0 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PrefetchPath", arg0) + ret0, _ := ret[0].(error) + return ret0 } // PrefetchPath indicates an expected call of PrefetchPath. func (mr *MockMerkleDBMockRecorder) PrefetchPath(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrefetchPath", reflect.TypeOf((*MockMerkleDB)(nil).PrefetchPath), arg0) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrefetchPath", reflect.TypeOf((*MockMerkleDB)(nil).PrefetchPath), arg0) } // PrefetchPaths mocks base method. func (m *MockMerkleDB) PrefetchPaths(arg0 [][]byte) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PrefetchPaths", arg0) - ret0, _ := ret[0].(error) - return ret0 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PrefetchPaths", arg0) + ret0, _ := ret[0].(error) + return ret0 } // PrefetchPaths indicates an expected call of PrefetchPaths. func (mr *MockMerkleDBMockRecorder) PrefetchPaths(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrefetchPaths", reflect.TypeOf((*MockMerkleDB)(nil).PrefetchPaths), arg0) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrefetchPaths", reflect.TypeOf((*MockMerkleDB)(nil).PrefetchPaths), arg0) } // Put mocks base method. func (m *MockMerkleDB) Put(arg0, arg1 []byte) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Put", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Put", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 } // Put indicates an expected call of Put. func (mr *MockMerkleDBMockRecorder) Put(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Put", reflect.TypeOf((*MockMerkleDB)(nil).Put), arg0, arg1) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Put", reflect.TypeOf((*MockMerkleDB)(nil).Put), arg0, arg1) } // VerifyChangeProof mocks base method. func (m *MockMerkleDB) VerifyChangeProof(arg0 context.Context, arg1 *ChangeProof, arg2, arg3 maybe.Maybe[[]uint8], arg4 ids.ID) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "VerifyChangeProof", arg0, arg1, arg2, arg3, arg4) - ret0, _ := ret[0].(error) - return ret0 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "VerifyChangeProof", arg0, arg1, arg2, arg3, arg4) + ret0, _ := ret[0].(error) + return ret0 } // VerifyChangeProof indicates an expected call of VerifyChangeProof. func (mr *MockMerkleDBMockRecorder) VerifyChangeProof(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VerifyChangeProof", reflect.TypeOf((*MockMerkleDB)(nil).VerifyChangeProof), arg0, arg1, arg2, arg3, arg4) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VerifyChangeProof", reflect.TypeOf((*MockMerkleDB)(nil).VerifyChangeProof), arg0, arg1, arg2, arg3, arg4) } // getEditableNode mocks base method. func (m *MockMerkleDB) getEditableNode(arg0 Path, arg1 bool) (*node, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "getEditableNode", arg0, arg1) - ret0, _ := ret[0].(*node) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "getEditableNode", arg0, arg1) + ret0, _ := ret[0].(*node) + ret1, _ := ret[1].(error) + return ret0, ret1 } // getEditableNode indicates an expected call of getEditableNode. func (mr *MockMerkleDBMockRecorder) getEditableNode(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "getEditableNode", reflect.TypeOf((*MockMerkleDB)(nil).getEditableNode), arg0, arg1) + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "getEditableNode", reflect.TypeOf((*MockMerkleDB)(nil).getEditableNode), arg0, arg1) +} + +// getRoot mocks base method. +func (m *MockMerkleDB) getRoot() maybe.Maybe[*node] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "getRoot") + ret0, _ := ret[0].(maybe.Maybe[*node]) + return ret0 +} + +// getRoot indicates an expected call of getRoot. +func (mr *MockMerkleDBMockRecorder) getRoot() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "getRoot", reflect.TypeOf((*MockMerkleDB)(nil).getRoot)) } // getValue mocks base method. func (m *MockMerkleDB) getValue(arg0 Path) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "getValue", arg0) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "getValue", arg0) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 } // getValue indicates an expected call of getValue. func (mr *MockMerkleDBMockRecorder) getValue(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "getValue", reflect.TypeOf((*MockMerkleDB)(nil).getValue), arg0) -} + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "getValue", reflect.TypeOf((*MockMerkleDB)(nil).getValue), arg0) +} \ No newline at end of file From 37b12a4069c1a7d84437378e8c2e8d5262721776 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 12:15:22 -0400 Subject: [PATCH 039/131] typo --- x/merkledb/mock_db.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/merkledb/mock_db.go b/x/merkledb/mock_db.go index 6b0d991a5949..05777ff60220 100644 --- a/x/merkledb/mock_db.go +++ b/x/merkledb/mock_db.go @@ -12,7 +12,7 @@ import ( reflect "reflect" context "context" ) - + // MockMerkleDB is a mock of MerkleDB interface. type MockMerkleDB struct { ctrl *gomock.Controller From b75987fcf7391ec7af42e6e7395cdf2b263bc423 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 13:08:35 -0400 Subject: [PATCH 040/131] cleanup --- x/merkledb/db.go | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 72f622010e75..db9c61e1777d 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -194,6 +194,7 @@ type merkleDB struct { infoTracer trace.Tracer // The root of this trie. + // Nothing if the trie is empty. root maybe.Maybe[*node] // Valid children of this trie. @@ -964,26 +965,19 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e return err } - // Only modify in-memory state after the commit succeeds - // so that we don't need to clean up on error. + db.history.record(changes) + if changes.rootChange.after == nil { db.root = maybe.Nothing[*node]() - if err := db.baseDB.Delete(rootDBKey); err != nil { - return err - } - } else { - db.root = maybe.Some(changes.rootChange.after) - rootKeyAndNodeBytes := codec.encodeKeyAndNode( - changes.rootChange.after.key, - &changes.rootChange.after.dbNode, - db.valueNodeDB.branchFactor, - ) - if err := db.baseDB.Put(rootDBKey, rootKeyAndNodeBytes); err != nil { - return err - } + return db.baseDB.Delete(rootDBKey) } - db.history.record(changes) - return nil + db.root = maybe.Some(changes.rootChange.after) + rootKeyAndNodeBytes := codec.encodeKeyAndNode( + changes.rootChange.after.key, + &changes.rootChange.after.dbNode, + db.valueNodeDB.branchFactor, + ) + return db.baseDB.Put(rootDBKey, rootKeyAndNodeBytes) } // moveChildViewsToDB removes any child views from the trieToCommit and moves them to the db From b1e71e1cf47c6b5aa6d245a9c17f38ac4ce32d23 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 13:11:07 -0400 Subject: [PATCH 041/131] cleanup --- x/merkledb/codec_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index bfb6b85d4892..73a23d2476f3 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -272,7 +272,6 @@ func TestCodecDecodePathLengthOverflowRegression(t *testing.T) { } func FuzzEncodeDecodeKeyAndNode(f *testing.F) { - require := require.New(f) codec := newCodec() f.Fuzz( @@ -321,8 +320,8 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { gotKey Path ) require.NoError(codec.decodeKeyAndNode(b, &gotKey, &gotNode, branchFactor)) - require.Equal(expectedNode, &gotNode) - require.Equal(key, gotKey) + require.Equal(f, expectedNode, &gotNode) + require.Equal(f, key, gotKey) } }, ) From 2f55d7b0ae303fe65ee87a4445a620a27eae0339 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 13:14:45 -0400 Subject: [PATCH 042/131] nit --- x/merkledb/db.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index db9c61e1777d..4c2ad3afff28 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -967,10 +967,12 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e db.history.record(changes) + // Update root in database. if changes.rootChange.after == nil { db.root = maybe.Nothing[*node]() return db.baseDB.Delete(rootDBKey) } + db.root = maybe.Some(changes.rootChange.after) rootKeyAndNodeBytes := codec.encodeKeyAndNode( changes.rootChange.after.key, From c23286de0eccc92f8aea108ebe27e85a53bf5950 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 13:19:41 -0400 Subject: [PATCH 043/131] typo fix; remove unused code --- x/merkledb/codec_test.go | 2 +- x/merkledb/db.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index 73a23d2476f3..0e12f82c061e 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -319,7 +319,7 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { gotNode dbNode gotKey Path ) - require.NoError(codec.decodeKeyAndNode(b, &gotKey, &gotNode, branchFactor)) + require.NoError(f, codec.decodeKeyAndNode(b, &gotKey, &gotNode, branchFactor)) require.Equal(f, expectedNode, &gotNode) require.Equal(f, key, gotKey) } diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 4c2ad3afff28..ea428ea41342 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1180,7 +1180,6 @@ func (db *merkleDB) initializeRootIfNeeded() error { ); err != nil { return err } - newNode(nil, rootKey) root := &node{ dbNode: rootDBNode, key: rootKey, From 04ff8804d013bd454cde0cc58f6ee8204ab90fee Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 13:26:11 -0400 Subject: [PATCH 044/131] nits/cleanup --- x/merkledb/trie.go | 1 + x/merkledb/trieview.go | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/merkledb/trie.go b/x/merkledb/trie.go index 4ae79a961983..166e487f7160 100644 --- a/x/merkledb/trie.go +++ b/x/merkledb/trie.go @@ -40,6 +40,7 @@ type ReadOnlyTrie interface { getValue(key Path) ([]byte, error) // If this trie is non-empty, returns the root node. + // Must be copied before modification. // Otherwise returns Nothing. getRoot() maybe.Maybe[*node] diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 04980815d228..d09dd23a2fe6 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -145,10 +145,9 @@ func newTrieView( parentTrie TrieView, changes ViewChanges, ) (*trieView, error) { - root := parentTrie.getRoot() - if root.HasValue() { - root = maybe.Some(root.Value().clone()) // TODO better way of doing this? - } + root := maybe.Bind(parentTrie.getRoot(), func(n *node) *node { + return n.clone() + }) newView := &trieView{ root: root, From 53d49fe16cae54a4b46e3d6d9d6e3d9606d6e9ee Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 13:27:59 -0400 Subject: [PATCH 045/131] comment --- x/merkledb/history.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/merkledb/history.go b/x/merkledb/history.go index bd668b0d8ea0..72991d378557 100644 --- a/x/merkledb/history.go +++ b/x/merkledb/history.go @@ -56,7 +56,8 @@ type changeSummary struct { // The ID of the trie after these changes. rootID ids.ID // The root before/after this change. - // If the trie is empty, its root is nil here. + // If the trie is empty before (after) this change, its root + // is nil for the before (after) field. // Set in [calculateNodeIDs]. rootChange *change[*node] nodes map[Path]*change[*node] From ae615c106e3c76587f279d43629c872fa904a326 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 13:31:35 -0400 Subject: [PATCH 046/131] revert unneeded change --- x/merkledb/history.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/merkledb/history.go b/x/merkledb/history.go index 72991d378557..807cc09a5e98 100644 --- a/x/merkledb/history.go +++ b/x/merkledb/history.go @@ -98,6 +98,10 @@ func (th *trieHistory) getValueChanges( return nil, fmt.Errorf("%w but was %d", ErrInvalidMaxLength, maxLength) } + if startRoot == endRoot { + return newChangeSummary(maxLength), nil + } + // [endRootChanges] is the last change in the history resulting in [endRoot]. // TODO when we update to minimum go version 1.20.X, make this return another // wrapped error ErrNoEndRoot. In NetworkServer.HandleChangeProofRequest, if we return @@ -108,10 +112,6 @@ func (th *trieHistory) getValueChanges( return nil, fmt.Errorf("%w: end root %s not found", ErrInsufficientHistory, endRoot) } - if startRoot == endRoot { - return newChangeSummary(maxLength), nil - } - // Confirm there's a change resulting in [startRoot] before // a change resulting in [endRoot] in the history. // [startRootChanges] is the last appearance of [startRoot]. From 71fb89539d8230e1f1ef68572c4cf081a523566a Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 13:49:34 -0400 Subject: [PATCH 047/131] update getProof --- x/merkledb/proof.go | 3 ++- x/merkledb/trieview.go | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/x/merkledb/proof.go b/x/merkledb/proof.go index f0fd30b73410..682406893922 100644 --- a/x/merkledb/proof.go +++ b/x/merkledb/proof.go @@ -127,7 +127,8 @@ func (node *ProofNode) UnmarshalProto(pbNode *pb.ProofNode, bf BranchFactor) err type Proof struct { // Nodes in the proof path from root --> target key // (or node that would be where key is if it doesn't exist). - // Must always be non-empty (i.e. have the root node). TODO remove + // Empty iff the trie is empty. + // Otherwise contains at least one node (the root). Path []ProofNode // This is a proof that [key] exists/doesn't exist. Key Path diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index d09dd23a2fe6..aa9ef1236f6c 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -352,12 +352,21 @@ func (t *trieView) getProof(ctx context.Context, key []byte) (*Proof, error) { Key: t.db.newPath(key), } + if t.root.IsNothing() { + return proof, nil + } + proofPath, err := t.getPathTo(proof.Key) if err != nil { return nil, err } if len(proofPath) == 0 { + // No key in [t] is a prefix of [key]. + // The root alone proves that [key] isn't in [t]. + proof.Path = []ProofNode{ + t.root.Value().asProofNode(), + } return proof, nil } From 27c8229a007824d1eaa5e34c8e04309dd7796028 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 14:00:43 -0400 Subject: [PATCH 048/131] nit --- x/merkledb/mock_db.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/merkledb/mock_db.go b/x/merkledb/mock_db.go index 05777ff60220..6df5ed92e5bf 100644 --- a/x/merkledb/mock_db.go +++ b/x/merkledb/mock_db.go @@ -439,4 +439,4 @@ func (m *MockMerkleDB) getValue(arg0 Path) ([]byte, error) { func (mr *MockMerkleDBMockRecorder) getValue(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "getValue", reflect.TypeOf((*MockMerkleDB)(nil).getValue), arg0) -} \ No newline at end of file +} From c5a3c2aef4da2594f9b87374d3a189385a2d0cc1 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 14:54:22 -0400 Subject: [PATCH 049/131] nits --- x/merkledb/db.go | 2 +- x/merkledb/proof.go | 4 ++-- x/merkledb/proof_test.go | 4 ++-- x/sync/client_test.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index ea428ea41342..6df3c3d0620d 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1015,7 +1015,7 @@ func (db *merkleDB) VerifyChangeProof( case start.HasValue() && end.HasValue() && bytes.Compare(start.Value(), end.Value()) > 0: return ErrStartAfterEnd case proof.Empty(): - return ErrNoMerkleProof + return ErrEmptyProof case end.HasValue() && len(proof.KeyChanges) == 0 && len(proof.EndProof) == 0: // We requested an end proof but didn't get one. return ErrNoEndProof diff --git a/x/merkledb/proof.go b/x/merkledb/proof.go index 682406893922..ee6b21054755 100644 --- a/x/merkledb/proof.go +++ b/x/merkledb/proof.go @@ -33,7 +33,7 @@ var ( ErrNonIncreasingProofNodes = errors.New("each proof node key must be a strict prefix of the next") ErrExtraProofNodes = errors.New("extra proof nodes in path") ErrDataInMissingRootProof = errors.New("there should be no state or deleted keys in a change proof that had a missing root") - ErrNoMerkleProof = errors.New("empty key response must include merkle proof") + ErrEmptyProof = errors.New("proof is empty") ErrShouldJustBeRoot = errors.New("end proof should only contain root") ErrNoStartProof = errors.New("no start proof") ErrNoEndProof = errors.New("no end proof") @@ -289,7 +289,7 @@ func (proof *RangeProof) Verify( case start.HasValue() && end.HasValue() && bytes.Compare(start.Value(), end.Value()) > 0: return ErrStartAfterEnd case len(proof.KeyValues) == 0 && len(proof.StartProof) == 0 && len(proof.EndProof) == 0: - return ErrNoMerkleProof + return ErrNoProof case end.IsNothing() && len(proof.KeyValues) == 0 && len(proof.EndProof) != 0: return ErrUnexpectedEndProof case len(proof.EndProof) == 0 && (end.HasValue() || len(proof.KeyValues) > 0): diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index a734ebdd3dc9..75238b4e5ffd 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -309,7 +309,7 @@ func Test_RangeProof_Syntactic_Verify(t *testing.T) { // start: maybe.Some([]byte{1}), // end: maybe.Nothing[[]byte](), // proof: &RangeProof{}, - // expectedErr: ErrNoMerkleProof, + // expectedErr: ErrEmptyProof, // }, { name: "unexpected end proof", @@ -907,7 +907,7 @@ func Test_ChangeProof_Syntactic_Verify(t *testing.T) { proof: &ChangeProof{}, start: maybe.Nothing[[]byte](), end: maybe.Nothing[[]byte](), - expectedErr: ErrNoMerkleProof, + expectedErr: ErrEmptyProof, }, { name: "no end proof", diff --git a/x/sync/client_test.go b/x/sync/client_test.go index 9d7d9cf53778..2c7b8e1b15d5 100644 --- a/x/sync/client_test.go +++ b/x/sync/client_test.go @@ -343,7 +343,7 @@ func TestGetRangeProof(t *testing.T) { response.StartProof = nil response.EndProof = nil }, - expectedErr: merkledb.ErrNoMerkleProof, + expectedErr: merkledb.ErrEmptyProof, }, } From a0fec2417758d9578124a18641c32138573477d1 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 15:38:35 -0400 Subject: [PATCH 050/131] proof cleanup --- x/merkledb/db.go | 23 +++++++++++++++----- x/merkledb/db_test.go | 47 ++++++++++++++++++++++++++++++++++++++++ x/merkledb/proof.go | 1 + x/merkledb/proof_test.go | 2 ++ 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 6df3c3d0620d..bc087d34d621 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -43,6 +43,8 @@ const ( var ( _ MerkleDB = (*merkleDB)(nil) + ErrEmptyRootID = errors.New("rootID is empty") + codec = newCodec() metadataPrefix = []byte{0} @@ -63,6 +65,8 @@ type ChangeProofer interface { // Returns at most [maxLength] key/value pairs. // Returns [ErrInsufficientHistory] if this node has insufficient history // to generate the proof. + // Returns ErrEmptyRootID if [endRootID] is ids.Empty. + // Note that [endRootID] == ids.Empty means the trie is empty. GetChangeProof( ctx context.Context, startRootID ids.ID, @@ -99,6 +103,9 @@ type RangeProofer interface { // [start, end] when the root of the trie was [rootID]. // If [start] is Nothing, there's no lower bound on the range. // If [end] is Nothing, there's no upper bound on the range. + // Returns ErrEmptyRootID if [rootID] is ids.Empty. + // Note that [rootID] == ids.Empty means the trie is empty, and there's no notion + // of proofs for empty tries. GetRangeProofAtRoot( ctx context.Context, rootID ids.ID, @@ -642,11 +649,13 @@ func (db *merkleDB) getRangeProofAtRoot( end maybe.Maybe[[]byte], maxLength int, ) (*RangeProof, error) { - if db.closed { + switch { + case db.closed: return nil, database.ErrClosed - } - if maxLength <= 0 { + case maxLength <= 0: return nil, fmt.Errorf("%w but was %d", ErrInvalidMaxLength, maxLength) + case rootID == ids.Empty: + return nil, ErrEmptyRootID } historicalView, err := db.getHistoricalViewForRange(rootID, start, end) @@ -664,11 +673,13 @@ func (db *merkleDB) GetChangeProof( end maybe.Maybe[[]byte], maxLength int, ) (*ChangeProof, error) { - if start.HasValue() && end.HasValue() && bytes.Compare(start.Value(), end.Value()) == 1 { + switch { + case start.HasValue() && end.HasValue() && bytes.Compare(start.Value(), end.Value()) == 1: return nil, ErrStartAfterEnd - } - if startRootID == endRootID { + case startRootID == endRootID: return nil, errSameRoot + case endRootID == ids.Empty: + return nil, ErrEmptyRootID } db.commitLock.RLock() diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index 26f04d253429..f4f6c18ad16a 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -892,6 +892,11 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest, bf Br root = pastRoots[r.Intn(len(pastRoots))] } + if root == ids.Empty { + // Don't generate a proof for an empty trie. + continue + } + start := maybe.Nothing[[]byte]() if len(step.key) > 0 { start = maybe.Some(step.key) @@ -919,6 +924,11 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest, bf Br root = pastRoots[r.Intn(len(pastRoots))] } + if root == ids.Empty { + // Don't generate a proof for an empty trie. + continue + } + start := maybe.Nothing[[]byte]() if len(step.key) > 0 { start = maybe.Some(step.key) @@ -1195,3 +1205,40 @@ func insertRandomKeyValues( } } } + +func TestGetRangeProofAtRootEmptyRootID(t *testing.T) { + require := require.New(t) + + db, err := getBasicDB() + require.NoError(err) + + _, err = db.getRangeProofAtRoot( + context.Background(), + ids.Empty, + maybe.Nothing[[]byte](), + maybe.Nothing[[]byte](), + 10, + ) + require.ErrorIs(err, ErrEmptyRootID) +} + +func TestGetChangeProofEmptyRootID(t *testing.T) { + require := require.New(t) + + db, err := getBasicDB() + require.NoError(err) + + require.NoError(db.Put([]byte("key"), []byte("value"))) + + rootID := db.getMerkleRoot() + + _, err = db.GetChangeProof( + context.Background(), + rootID, + ids.Empty, + maybe.Nothing[[]byte](), + maybe.Nothing[[]byte](), + 10, + ) + require.ErrorIs(err, ErrEmptyRootID) +} diff --git a/x/merkledb/proof.go b/x/merkledb/proof.go index ee6b21054755..333c477db80c 100644 --- a/x/merkledb/proof.go +++ b/x/merkledb/proof.go @@ -146,6 +146,7 @@ func (proof *Proof) Verify(ctx context.Context, expectedRootID ids.ID) error { if len(proof.Path) == 0 { return ErrNoProof } + if err := verifyProofPath(proof.Path, maybe.Some(proof.Key)); err != nil { return err } diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index 75238b4e5ffd..d2fb7cc5dae7 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -546,6 +546,8 @@ func Test_RangeProof_BadBounds(t *testing.T) { db, err := getBasicDB() require.NoError(err) + require.NoError(db.Put(nil, nil)) + // non-nil start/end proof, err := db.GetRangeProof(context.Background(), maybe.Some([]byte{4}), maybe.Some([]byte{3}), 50) require.ErrorIs(err, ErrStartAfterEnd) From e4ea07d9adcd175e99fd9ee69187156090758cb5 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 15:44:44 -0400 Subject: [PATCH 051/131] fix test --- x/merkledb/db_test.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index f4f6c18ad16a..775c281ecfc9 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -892,11 +892,6 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest, bf Br root = pastRoots[r.Intn(len(pastRoots))] } - if root == ids.Empty { - // Don't generate a proof for an empty trie. - continue - } - start := maybe.Nothing[[]byte]() if len(step.key) > 0 { start = maybe.Some(step.key) @@ -907,6 +902,10 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest, bf Br } rangeProof, err := db.GetRangeProofAtRoot(context.Background(), root, start, end, maxProofLen) + if root == ids.Empty { + require.ErrorIs(err, ErrEmptyRootID) + continue + } require.NoError(err) require.LessOrEqual(len(rangeProof.KeyValues), maxProofLen) @@ -924,11 +923,6 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest, bf Br root = pastRoots[r.Intn(len(pastRoots))] } - if root == ids.Empty { - // Don't generate a proof for an empty trie. - continue - } - start := maybe.Nothing[[]byte]() if len(step.key) > 0 { start = maybe.Some(step.key) @@ -944,6 +938,10 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest, bf Br require.ErrorIs(err, errSameRoot) continue } + if root == ids.Empty { + require.ErrorIs(err, ErrEmptyRootID) + continue + } require.NoError(err) require.LessOrEqual(len(changeProof.KeyChanges), maxProofLen) From d57eac4f41b2635e54f425fa4deb8aaeee2e339b Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 17:11:25 -0400 Subject: [PATCH 052/131] all UT pass --- database/helpers.go | 8 + proto/pb/sync/sync.pb.go | 793 +++++++++++++++++++--------------- proto/pb/sync/sync_grpc.pb.go | 37 ++ proto/sync/sync.proto | 7 + scripts/mocks.mockgen.txt | 53 +-- x/merkledb/db.go | 28 ++ x/merkledb/mock_db.go | 22 +- x/sync/client_test.go | 14 - x/sync/db.go | 6 +- x/sync/g_db/db_client.go | 17 + x/sync/g_db/db_server.go | 18 + x/sync/manager.go | 21 + x/sync/sync_test.go | 5 + 13 files changed, 603 insertions(+), 426 deletions(-) diff --git a/database/helpers.go b/database/helpers.go index d4261920dcdf..c706b326e7c0 100644 --- a/database/helpers.go +++ b/database/helpers.go @@ -10,6 +10,7 @@ import ( "time" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils/maybe" ) const ( @@ -188,6 +189,13 @@ func AtomicClearPrefix(readerDB Iteratee, deleterDB KeyValueDeleter, prefix []by return iterator.Error() } +type ClearRanger interface { + // Deletes all key-value pairs with keys in the range [start, end]. + // If [start] is Nothing, there's no lower bound on the range. + // If [end] is Nothing, there's no upper bound on the range. + ClearRange(start, end maybe.Maybe[[]byte]) error +} + // Remove all key-value pairs from [db]. // Writes each batch when it reaches [writeSize]. func Clear(db Database, writeSize int) error { diff --git a/proto/pb/sync/sync.pb.go b/proto/pb/sync/sync.pb.go index dc0368bbf70f..46cdc513c40a 100644 --- a/proto/pb/sync/sync.pb.go +++ b/proto/pb/sync/sync.pb.go @@ -150,6 +150,61 @@ func (x *GetMerkleRootResponse) GetRootHash() []byte { return nil } +type ClearRangeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StartKey *MaybeBytes `protobuf:"bytes,1,opt,name=start_key,json=startKey,proto3" json:"start_key,omitempty"` + EndKey *MaybeBytes `protobuf:"bytes,2,opt,name=end_key,json=endKey,proto3" json:"end_key,omitempty"` +} + +func (x *ClearRangeRequest) Reset() { + *x = ClearRangeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_sync_sync_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ClearRangeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ClearRangeRequest) ProtoMessage() {} + +func (x *ClearRangeRequest) ProtoReflect() protoreflect.Message { + mi := &file_sync_sync_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ClearRangeRequest.ProtoReflect.Descriptor instead. +func (*ClearRangeRequest) Descriptor() ([]byte, []int) { + return file_sync_sync_proto_rawDescGZIP(), []int{2} +} + +func (x *ClearRangeRequest) GetStartKey() *MaybeBytes { + if x != nil { + return x.StartKey + } + return nil +} + +func (x *ClearRangeRequest) GetEndKey() *MaybeBytes { + if x != nil { + return x.EndKey + } + return nil +} + type GetProofRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -161,7 +216,7 @@ type GetProofRequest struct { func (x *GetProofRequest) Reset() { *x = GetProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[2] + mi := &file_sync_sync_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -174,7 +229,7 @@ func (x *GetProofRequest) String() string { func (*GetProofRequest) ProtoMessage() {} func (x *GetProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[2] + mi := &file_sync_sync_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -187,7 +242,7 @@ func (x *GetProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetProofRequest.ProtoReflect.Descriptor instead. func (*GetProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{2} + return file_sync_sync_proto_rawDescGZIP(), []int{3} } func (x *GetProofRequest) GetKey() []byte { @@ -208,7 +263,7 @@ type GetProofResponse struct { func (x *GetProofResponse) Reset() { *x = GetProofResponse{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[3] + mi := &file_sync_sync_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -221,7 +276,7 @@ func (x *GetProofResponse) String() string { func (*GetProofResponse) ProtoMessage() {} func (x *GetProofResponse) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[3] + mi := &file_sync_sync_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -234,7 +289,7 @@ func (x *GetProofResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetProofResponse.ProtoReflect.Descriptor instead. func (*GetProofResponse) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{3} + return file_sync_sync_proto_rawDescGZIP(), []int{4} } func (x *GetProofResponse) GetProof() *Proof { @@ -257,7 +312,7 @@ type Proof struct { func (x *Proof) Reset() { *x = Proof{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[4] + mi := &file_sync_sync_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -270,7 +325,7 @@ func (x *Proof) String() string { func (*Proof) ProtoMessage() {} func (x *Proof) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[4] + mi := &file_sync_sync_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -283,7 +338,7 @@ func (x *Proof) ProtoReflect() protoreflect.Message { // Deprecated: Use Proof.ProtoReflect.Descriptor instead. func (*Proof) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{4} + return file_sync_sync_proto_rawDescGZIP(), []int{5} } func (x *Proof) GetKey() []byte { @@ -325,7 +380,7 @@ type SyncGetChangeProofRequest struct { func (x *SyncGetChangeProofRequest) Reset() { *x = SyncGetChangeProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[5] + mi := &file_sync_sync_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -338,7 +393,7 @@ func (x *SyncGetChangeProofRequest) String() string { func (*SyncGetChangeProofRequest) ProtoMessage() {} func (x *SyncGetChangeProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[5] + mi := &file_sync_sync_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -351,7 +406,7 @@ func (x *SyncGetChangeProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use SyncGetChangeProofRequest.ProtoReflect.Descriptor instead. func (*SyncGetChangeProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{5} + return file_sync_sync_proto_rawDescGZIP(), []int{6} } func (x *SyncGetChangeProofRequest) GetStartRootHash() []byte { @@ -411,7 +466,7 @@ type SyncGetChangeProofResponse struct { func (x *SyncGetChangeProofResponse) Reset() { *x = SyncGetChangeProofResponse{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[6] + mi := &file_sync_sync_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -424,7 +479,7 @@ func (x *SyncGetChangeProofResponse) String() string { func (*SyncGetChangeProofResponse) ProtoMessage() {} func (x *SyncGetChangeProofResponse) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[6] + mi := &file_sync_sync_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -437,7 +492,7 @@ func (x *SyncGetChangeProofResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use SyncGetChangeProofResponse.ProtoReflect.Descriptor instead. func (*SyncGetChangeProofResponse) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{6} + return file_sync_sync_proto_rawDescGZIP(), []int{7} } func (m *SyncGetChangeProofResponse) GetResponse() isSyncGetChangeProofResponse_Response { @@ -492,7 +547,7 @@ type GetChangeProofRequest struct { func (x *GetChangeProofRequest) Reset() { *x = GetChangeProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[7] + mi := &file_sync_sync_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -505,7 +560,7 @@ func (x *GetChangeProofRequest) String() string { func (*GetChangeProofRequest) ProtoMessage() {} func (x *GetChangeProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[7] + mi := &file_sync_sync_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -518,7 +573,7 @@ func (x *GetChangeProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetChangeProofRequest.ProtoReflect.Descriptor instead. func (*GetChangeProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{7} + return file_sync_sync_proto_rawDescGZIP(), []int{8} } func (x *GetChangeProofRequest) GetStartRootHash() []byte { @@ -571,7 +626,7 @@ type GetChangeProofResponse struct { func (x *GetChangeProofResponse) Reset() { *x = GetChangeProofResponse{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[8] + mi := &file_sync_sync_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -584,7 +639,7 @@ func (x *GetChangeProofResponse) String() string { func (*GetChangeProofResponse) ProtoMessage() {} func (x *GetChangeProofResponse) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[8] + mi := &file_sync_sync_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -597,7 +652,7 @@ func (x *GetChangeProofResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetChangeProofResponse.ProtoReflect.Descriptor instead. func (*GetChangeProofResponse) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{8} + return file_sync_sync_proto_rawDescGZIP(), []int{9} } func (m *GetChangeProofResponse) GetResponse() isGetChangeProofResponse_Response { @@ -652,7 +707,7 @@ type VerifyChangeProofRequest struct { func (x *VerifyChangeProofRequest) Reset() { *x = VerifyChangeProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[9] + mi := &file_sync_sync_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -665,7 +720,7 @@ func (x *VerifyChangeProofRequest) String() string { func (*VerifyChangeProofRequest) ProtoMessage() {} func (x *VerifyChangeProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[9] + mi := &file_sync_sync_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -678,7 +733,7 @@ func (x *VerifyChangeProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use VerifyChangeProofRequest.ProtoReflect.Descriptor instead. func (*VerifyChangeProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{9} + return file_sync_sync_proto_rawDescGZIP(), []int{10} } func (x *VerifyChangeProofRequest) GetProof() *ChangeProof { @@ -721,7 +776,7 @@ type VerifyChangeProofResponse struct { func (x *VerifyChangeProofResponse) Reset() { *x = VerifyChangeProofResponse{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[10] + mi := &file_sync_sync_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -734,7 +789,7 @@ func (x *VerifyChangeProofResponse) String() string { func (*VerifyChangeProofResponse) ProtoMessage() {} func (x *VerifyChangeProofResponse) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[10] + mi := &file_sync_sync_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -747,7 +802,7 @@ func (x *VerifyChangeProofResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use VerifyChangeProofResponse.ProtoReflect.Descriptor instead. func (*VerifyChangeProofResponse) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{10} + return file_sync_sync_proto_rawDescGZIP(), []int{11} } func (x *VerifyChangeProofResponse) GetError() string { @@ -768,7 +823,7 @@ type CommitChangeProofRequest struct { func (x *CommitChangeProofRequest) Reset() { *x = CommitChangeProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[11] + mi := &file_sync_sync_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -781,7 +836,7 @@ func (x *CommitChangeProofRequest) String() string { func (*CommitChangeProofRequest) ProtoMessage() {} func (x *CommitChangeProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[11] + mi := &file_sync_sync_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -794,7 +849,7 @@ func (x *CommitChangeProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use CommitChangeProofRequest.ProtoReflect.Descriptor instead. func (*CommitChangeProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{11} + return file_sync_sync_proto_rawDescGZIP(), []int{12} } func (x *CommitChangeProofRequest) GetProof() *ChangeProof { @@ -821,7 +876,7 @@ type SyncGetRangeProofRequest struct { func (x *SyncGetRangeProofRequest) Reset() { *x = SyncGetRangeProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[12] + mi := &file_sync_sync_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -834,7 +889,7 @@ func (x *SyncGetRangeProofRequest) String() string { func (*SyncGetRangeProofRequest) ProtoMessage() {} func (x *SyncGetRangeProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[12] + mi := &file_sync_sync_proto_msgTypes[13] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -847,7 +902,7 @@ func (x *SyncGetRangeProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use SyncGetRangeProofRequest.ProtoReflect.Descriptor instead. func (*SyncGetRangeProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{12} + return file_sync_sync_proto_rawDescGZIP(), []int{13} } func (x *SyncGetRangeProofRequest) GetRootHash() []byte { @@ -899,7 +954,7 @@ type GetRangeProofRequest struct { func (x *GetRangeProofRequest) Reset() { *x = GetRangeProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[13] + mi := &file_sync_sync_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -912,7 +967,7 @@ func (x *GetRangeProofRequest) String() string { func (*GetRangeProofRequest) ProtoMessage() {} func (x *GetRangeProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[13] + mi := &file_sync_sync_proto_msgTypes[14] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -925,7 +980,7 @@ func (x *GetRangeProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetRangeProofRequest.ProtoReflect.Descriptor instead. func (*GetRangeProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{13} + return file_sync_sync_proto_rawDescGZIP(), []int{14} } func (x *GetRangeProofRequest) GetRootHash() []byte { @@ -967,7 +1022,7 @@ type GetRangeProofResponse struct { func (x *GetRangeProofResponse) Reset() { *x = GetRangeProofResponse{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[14] + mi := &file_sync_sync_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -980,7 +1035,7 @@ func (x *GetRangeProofResponse) String() string { func (*GetRangeProofResponse) ProtoMessage() {} func (x *GetRangeProofResponse) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[14] + mi := &file_sync_sync_proto_msgTypes[15] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -993,7 +1048,7 @@ func (x *GetRangeProofResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetRangeProofResponse.ProtoReflect.Descriptor instead. func (*GetRangeProofResponse) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{14} + return file_sync_sync_proto_rawDescGZIP(), []int{15} } func (x *GetRangeProofResponse) GetProof() *RangeProof { @@ -1016,7 +1071,7 @@ type CommitRangeProofRequest struct { func (x *CommitRangeProofRequest) Reset() { *x = CommitRangeProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[15] + mi := &file_sync_sync_proto_msgTypes[16] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1029,7 +1084,7 @@ func (x *CommitRangeProofRequest) String() string { func (*CommitRangeProofRequest) ProtoMessage() {} func (x *CommitRangeProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[15] + mi := &file_sync_sync_proto_msgTypes[16] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1042,7 +1097,7 @@ func (x *CommitRangeProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use CommitRangeProofRequest.ProtoReflect.Descriptor instead. func (*CommitRangeProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{15} + return file_sync_sync_proto_rawDescGZIP(), []int{16} } func (x *CommitRangeProofRequest) GetStartKey() *MaybeBytes { @@ -1079,7 +1134,7 @@ type ChangeProof struct { func (x *ChangeProof) Reset() { *x = ChangeProof{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[16] + mi := &file_sync_sync_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1092,7 +1147,7 @@ func (x *ChangeProof) String() string { func (*ChangeProof) ProtoMessage() {} func (x *ChangeProof) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[16] + mi := &file_sync_sync_proto_msgTypes[17] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1105,7 +1160,7 @@ func (x *ChangeProof) ProtoReflect() protoreflect.Message { // Deprecated: Use ChangeProof.ProtoReflect.Descriptor instead. func (*ChangeProof) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{16} + return file_sync_sync_proto_rawDescGZIP(), []int{17} } func (x *ChangeProof) GetStartProof() []*ProofNode { @@ -1142,7 +1197,7 @@ type RangeProof struct { func (x *RangeProof) Reset() { *x = RangeProof{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[17] + mi := &file_sync_sync_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1155,7 +1210,7 @@ func (x *RangeProof) String() string { func (*RangeProof) ProtoMessage() {} func (x *RangeProof) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[17] + mi := &file_sync_sync_proto_msgTypes[18] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1168,7 +1223,7 @@ func (x *RangeProof) ProtoReflect() protoreflect.Message { // Deprecated: Use RangeProof.ProtoReflect.Descriptor instead. func (*RangeProof) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{17} + return file_sync_sync_proto_rawDescGZIP(), []int{18} } func (x *RangeProof) GetStartProof() []*ProofNode { @@ -1205,7 +1260,7 @@ type ProofNode struct { func (x *ProofNode) Reset() { *x = ProofNode{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[18] + mi := &file_sync_sync_proto_msgTypes[19] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1218,7 +1273,7 @@ func (x *ProofNode) String() string { func (*ProofNode) ProtoMessage() {} func (x *ProofNode) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[18] + mi := &file_sync_sync_proto_msgTypes[19] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1231,7 +1286,7 @@ func (x *ProofNode) ProtoReflect() protoreflect.Message { // Deprecated: Use ProofNode.ProtoReflect.Descriptor instead. func (*ProofNode) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{18} + return file_sync_sync_proto_rawDescGZIP(), []int{19} } func (x *ProofNode) GetKey() *Path { @@ -1267,7 +1322,7 @@ type KeyChange struct { func (x *KeyChange) Reset() { *x = KeyChange{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[19] + mi := &file_sync_sync_proto_msgTypes[20] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1280,7 +1335,7 @@ func (x *KeyChange) String() string { func (*KeyChange) ProtoMessage() {} func (x *KeyChange) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[19] + mi := &file_sync_sync_proto_msgTypes[20] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1293,7 +1348,7 @@ func (x *KeyChange) ProtoReflect() protoreflect.Message { // Deprecated: Use KeyChange.ProtoReflect.Descriptor instead. func (*KeyChange) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{19} + return file_sync_sync_proto_rawDescGZIP(), []int{20} } func (x *KeyChange) GetKey() []byte { @@ -1322,7 +1377,7 @@ type Path struct { func (x *Path) Reset() { *x = Path{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[20] + mi := &file_sync_sync_proto_msgTypes[21] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1335,7 +1390,7 @@ func (x *Path) String() string { func (*Path) ProtoMessage() {} func (x *Path) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[20] + mi := &file_sync_sync_proto_msgTypes[21] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1348,7 +1403,7 @@ func (x *Path) ProtoReflect() protoreflect.Message { // Deprecated: Use Path.ProtoReflect.Descriptor instead. func (*Path) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{20} + return file_sync_sync_proto_rawDescGZIP(), []int{21} } func (x *Path) GetLength() uint64 { @@ -1379,7 +1434,7 @@ type MaybeBytes struct { func (x *MaybeBytes) Reset() { *x = MaybeBytes{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[21] + mi := &file_sync_sync_proto_msgTypes[22] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1392,7 +1447,7 @@ func (x *MaybeBytes) String() string { func (*MaybeBytes) ProtoMessage() {} func (x *MaybeBytes) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[21] + mi := &file_sync_sync_proto_msgTypes[22] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1405,7 +1460,7 @@ func (x *MaybeBytes) ProtoReflect() protoreflect.Message { // Deprecated: Use MaybeBytes.ProtoReflect.Descriptor instead. func (*MaybeBytes) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{21} + return file_sync_sync_proto_rawDescGZIP(), []int{22} } func (x *MaybeBytes) GetValue() []byte { @@ -1434,7 +1489,7 @@ type KeyValue struct { func (x *KeyValue) Reset() { *x = KeyValue{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[22] + mi := &file_sync_sync_proto_msgTypes[23] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1447,7 +1502,7 @@ func (x *KeyValue) String() string { func (*KeyValue) ProtoMessage() {} func (x *KeyValue) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[22] + mi := &file_sync_sync_proto_msgTypes[23] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1460,7 +1515,7 @@ func (x *KeyValue) ProtoReflect() protoreflect.Message { // Deprecated: Use KeyValue.ProtoReflect.Descriptor instead. func (*KeyValue) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{22} + return file_sync_sync_proto_rawDescGZIP(), []int{23} } func (x *KeyValue) GetKey() []byte { @@ -1498,212 +1553,223 @@ var file_sync_sync_proto_rawDesc = []byte{ 0x67, 0x65, 0x22, 0x34, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, - 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x22, 0x23, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x50, - 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, - 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x35, 0x0a, - 0x10, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x21, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x0b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, 0x70, - 0x72, 0x6f, 0x6f, 0x66, 0x22, 0x68, 0x0a, 0x05, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x10, 0x0a, - 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, - 0x26, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, - 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, - 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x25, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, - 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xff, - 0x01, 0x0a, 0x19, 0x53, 0x79, 0x6e, 0x63, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0f, - 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0d, 0x73, 0x74, 0x61, 0x72, 0x74, 0x52, 0x6f, 0x6f, 0x74, - 0x48, 0x61, 0x73, 0x68, 0x12, 0x22, 0x0a, 0x0d, 0x65, 0x6e, 0x64, 0x5f, 0x72, 0x6f, 0x6f, 0x74, - 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x65, 0x6e, 0x64, - 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, - 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, - 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, - 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, - 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, - 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, - 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, - 0x1f, 0x0a, 0x0b, 0x62, 0x79, 0x74, 0x65, 0x73, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x06, - 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x62, 0x79, 0x74, 0x65, 0x73, 0x4c, 0x69, 0x6d, 0x69, 0x74, - 0x22, 0x95, 0x01, 0x0a, 0x1a, 0x53, 0x79, 0x6e, 0x63, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, + 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x22, 0x6d, 0x0a, 0x11, 0x43, 0x6c, 0x65, 0x61, + 0x72, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2d, 0x0a, + 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, + 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, + 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, + 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, + 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x22, 0x23, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x50, 0x72, + 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x35, 0x0a, 0x10, + 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x21, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x0b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, 0x70, 0x72, + 0x6f, 0x6f, 0x66, 0x22, 0x68, 0x0a, 0x05, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x26, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, + 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x25, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, + 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xff, 0x01, + 0x0a, 0x19, 0x53, 0x79, 0x6e, 0x63, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0f, 0x73, + 0x74, 0x61, 0x72, 0x74, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0d, 0x73, 0x74, 0x61, 0x72, 0x74, 0x52, 0x6f, 0x6f, 0x74, 0x48, + 0x61, 0x73, 0x68, 0x12, 0x22, 0x0a, 0x0d, 0x65, 0x6e, 0x64, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, + 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x65, 0x6e, 0x64, 0x52, + 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, + 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, + 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, + 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, + 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, + 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, + 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x1f, + 0x0a, 0x0b, 0x62, 0x79, 0x74, 0x65, 0x73, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x06, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x62, 0x79, 0x74, 0x65, 0x73, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, + 0x95, 0x01, 0x0a, 0x1a, 0x53, 0x79, 0x6e, 0x63, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, + 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x36, + 0x0a, 0x0c, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, + 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x48, 0x00, 0x52, 0x0b, 0x63, 0x68, 0x61, 0x6e, 0x67, + 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x33, 0x0a, 0x0b, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x5f, + 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, + 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x48, 0x00, 0x52, + 0x0a, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x42, 0x0a, 0x0a, 0x08, 0x72, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xda, 0x01, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x43, + 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x26, 0x0a, 0x0f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, + 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0d, 0x73, 0x74, 0x61, 0x72, + 0x74, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x22, 0x0a, 0x0d, 0x65, 0x6e, 0x64, + 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x0b, 0x65, 0x6e, 0x64, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2d, 0x0a, + 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, + 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, + 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, + 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, + 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, 0x6c, + 0x69, 0x6d, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x4c, + 0x69, 0x6d, 0x69, 0x74, 0x22, 0x88, 0x01, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x36, 0x0a, 0x0c, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x48, 0x00, 0x52, 0x0b, 0x63, 0x68, 0x61, 0x6e, - 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x33, 0x0a, 0x0b, 0x72, 0x61, 0x6e, 0x67, 0x65, - 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, - 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x48, 0x00, - 0x52, 0x0a, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x42, 0x0a, 0x0a, 0x08, - 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xda, 0x01, 0x0a, 0x15, 0x47, 0x65, 0x74, - 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x72, 0x6f, 0x6f, 0x74, - 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0d, 0x73, 0x74, 0x61, - 0x72, 0x74, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x22, 0x0a, 0x0d, 0x65, 0x6e, - 0x64, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x0b, 0x65, 0x6e, 0x64, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2d, - 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, - 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, - 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, - 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, - 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, - 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, - 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x88, 0x01, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, - 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x36, 0x0a, 0x0c, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x68, - 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x48, 0x00, 0x52, 0x0b, 0x63, 0x68, 0x61, - 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2a, 0x0a, 0x10, 0x72, 0x6f, 0x6f, 0x74, - 0x5f, 0x6e, 0x6f, 0x74, 0x5f, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x08, 0x48, 0x00, 0x52, 0x0e, 0x72, 0x6f, 0x6f, 0x74, 0x4e, 0x6f, 0x74, 0x50, 0x72, 0x65, - 0x73, 0x65, 0x6e, 0x74, 0x42, 0x0a, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0xcb, 0x01, 0x0a, 0x18, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, - 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, - 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, - 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, - 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, - 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, - 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, - 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, - 0x12, 0x2c, 0x0a, 0x12, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x72, 0x6f, 0x6f, - 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x10, 0x65, 0x78, - 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x22, 0x31, - 0x0a, 0x19, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, - 0x72, 0x72, 0x6f, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, - 0x72, 0x22, 0x43, 0x0a, 0x18, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, - 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, - 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, - 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xcf, 0x01, 0x0a, 0x18, 0x53, 0x79, 0x6e, 0x63, 0x47, - 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, - 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, - 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, - 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, + 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2a, 0x0a, 0x10, 0x72, 0x6f, 0x6f, 0x74, 0x5f, + 0x6e, 0x6f, 0x74, 0x5f, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x08, 0x48, 0x00, 0x52, 0x0e, 0x72, 0x6f, 0x6f, 0x74, 0x4e, 0x6f, 0x74, 0x50, 0x72, 0x65, 0x73, + 0x65, 0x6e, 0x74, 0x42, 0x0a, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0xcb, 0x01, 0x0a, 0x18, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, + 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x05, + 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, 0x79, + 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, + 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, + 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, + 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, + 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, + 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, + 0x2c, 0x0a, 0x12, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x72, 0x6f, 0x6f, 0x74, + 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x10, 0x65, 0x78, 0x70, + 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x22, 0x31, 0x0a, + 0x19, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, + 0x72, 0x6f, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, + 0x22, 0x43, 0x0a, 0x18, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, + 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x05, + 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, 0x79, + 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, + 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xcf, 0x01, 0x0a, 0x18, 0x53, 0x79, 0x6e, 0x63, 0x47, 0x65, + 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, + 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, + 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, + 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, + 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, + 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, + 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x62, 0x79, 0x74, 0x65, 0x73, 0x5f, + 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x62, 0x79, 0x74, + 0x65, 0x73, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0xaa, 0x01, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x52, + 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2d, 0x0a, + 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, - 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, - 0x79, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, - 0x65, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x62, 0x79, 0x74, 0x65, 0x73, - 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x62, 0x79, - 0x74, 0x65, 0x73, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0xaa, 0x01, 0x0a, 0x14, 0x47, 0x65, 0x74, + 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, + 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, + 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, + 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, 0x6c, + 0x69, 0x6d, 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x4c, + 0x69, 0x6d, 0x69, 0x74, 0x22, 0x3f, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, + 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x26, 0x0a, + 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, + 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, + 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xa6, 0x01, 0x0a, 0x17, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2d, - 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x74, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, + 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, + 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, - 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, - 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, - 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, - 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, - 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, - 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x3f, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, - 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x26, - 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, - 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, - 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xa6, 0x01, 0x0a, 0x17, 0x43, 0x6f, 0x6d, 0x6d, 0x69, - 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, - 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, - 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, - 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x31, 0x0a, 0x0b, - 0x72, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x52, 0x0a, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x22, - 0x9f, 0x01, 0x0a, 0x0b, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, + 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x31, 0x0a, 0x0b, 0x72, + 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x52, 0x0a, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0x9f, + 0x01, 0x0a, 0x0b, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x30, + 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, + 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, + 0x12, 0x2c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, + 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x30, + 0x0a, 0x0b, 0x6b, 0x65, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x18, 0x03, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x43, 0x68, + 0x61, 0x6e, 0x67, 0x65, 0x52, 0x0a, 0x6b, 0x65, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, + 0x22, 0x9b, 0x01, 0x0a, 0x0a, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x30, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, - 0x30, 0x0a, 0x0b, 0x6b, 0x65, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x18, 0x03, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x43, - 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x0a, 0x6b, 0x65, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x73, 0x22, 0x9b, 0x01, 0x0a, 0x0a, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x12, 0x30, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, - 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, - 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, 0x50, 0x72, 0x6f, - 0x6f, 0x66, 0x12, 0x2c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, - 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, - 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x12, 0x2d, 0x0a, 0x0a, 0x6b, 0x65, 0x79, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x03, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x56, - 0x61, 0x6c, 0x75, 0x65, 0x52, 0x09, 0x6b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x22, - 0xd7, 0x01, 0x0a, 0x09, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x1c, 0x0a, - 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x73, 0x79, 0x6e, - 0x63, 0x2e, 0x50, 0x61, 0x74, 0x68, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x34, 0x0a, 0x0d, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x5f, 0x6f, 0x72, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, - 0x79, 0x74, 0x65, 0x73, 0x52, 0x0b, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x4f, 0x72, 0x48, 0x61, 0x73, - 0x68, 0x12, 0x39, 0x0a, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x18, 0x03, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x4e, 0x6f, 0x64, 0x65, 0x2e, 0x43, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x45, 0x6e, 0x74, - 0x72, 0x79, 0x52, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x1a, 0x3b, 0x0a, 0x0d, - 0x43, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, - 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x2d, 0x0a, 0x0a, 0x6b, 0x65, 0x79, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x03, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, + 0x6c, 0x75, 0x65, 0x52, 0x09, 0x6b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x22, 0xd7, + 0x01, 0x0a, 0x09, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x1c, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x73, 0x79, 0x6e, 0x63, + 0x2e, 0x50, 0x61, 0x74, 0x68, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x34, 0x0a, 0x0d, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x5f, 0x6f, 0x72, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, + 0x74, 0x65, 0x73, 0x52, 0x0b, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x4f, 0x72, 0x48, 0x61, 0x73, 0x68, + 0x12, 0x39, 0x0a, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, + 0x6f, 0x64, 0x65, 0x2e, 0x43, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x52, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x1a, 0x3b, 0x0a, 0x0d, 0x43, + 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x45, 0x0a, 0x09, 0x4b, 0x65, 0x79, 0x43, + 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x26, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, + 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, + 0x34, 0x0a, 0x04, 0x50, 0x61, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, + 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x45, 0x0a, 0x09, 0x4b, 0x65, 0x79, - 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x26, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, - 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x22, 0x34, 0x0a, 0x04, 0x50, 0x61, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x65, 0x6e, 0x67, - 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, - 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x41, 0x0a, 0x0a, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, - 0x79, 0x74, 0x65, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x73, - 0x5f, 0x6e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, - 0x69, 0x73, 0x4e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x22, 0x32, 0x0a, 0x08, 0x4b, 0x65, 0x79, - 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x32, 0x8a, 0x04, - 0x0a, 0x02, 0x44, 0x42, 0x12, 0x44, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, - 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, - 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, - 0x6f, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x08, 0x47, 0x65, - 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x15, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, - 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, - 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, - 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, - 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, - 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x54, 0x0a, 0x11, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, - 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, - 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, - 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x6d, - 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, - 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x48, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, - 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1a, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, - 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, - 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x49, 0x0a, 0x10, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x12, 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, - 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x76, 0x61, 0x2d, 0x6c, 0x61, 0x62, - 0x73, 0x2f, 0x61, 0x76, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x67, 0x6f, 0x2f, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x62, 0x2f, 0x73, 0x79, 0x6e, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x41, 0x0a, 0x0a, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, + 0x74, 0x65, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x73, 0x5f, + 0x6e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, + 0x73, 0x4e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x22, 0x32, 0x0a, 0x08, 0x4b, 0x65, 0x79, 0x56, + 0x61, 0x6c, 0x75, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x32, 0xc9, 0x04, 0x0a, + 0x02, 0x44, 0x42, 0x12, 0x44, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, + 0x52, 0x6f, 0x6f, 0x74, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x73, + 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, + 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3d, 0x0a, 0x0a, 0x43, 0x6c, 0x65, + 0x61, 0x72, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x17, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, + 0x6c, 0x65, 0x61, 0x72, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x39, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x15, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x73, 0x79, + 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, + 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, + 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, + 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x54, 0x0a, 0x11, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, + 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, + 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, + 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, + 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, + 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, + 0x70, 0x74, 0x79, 0x12, 0x48, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1a, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, + 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, + 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, + 0x10, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, + 0x66, 0x12, 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, + 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, + 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x76, 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, + 0x61, 0x76, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2f, 0x70, 0x62, 0x2f, 0x73, 0x79, 0x6e, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -1718,88 +1784,93 @@ func file_sync_sync_proto_rawDescGZIP() []byte { return file_sync_sync_proto_rawDescData } -var file_sync_sync_proto_msgTypes = make([]protoimpl.MessageInfo, 24) +var file_sync_sync_proto_msgTypes = make([]protoimpl.MessageInfo, 25) var file_sync_sync_proto_goTypes = []interface{}{ (*Request)(nil), // 0: sync.Request (*GetMerkleRootResponse)(nil), // 1: sync.GetMerkleRootResponse - (*GetProofRequest)(nil), // 2: sync.GetProofRequest - (*GetProofResponse)(nil), // 3: sync.GetProofResponse - (*Proof)(nil), // 4: sync.Proof - (*SyncGetChangeProofRequest)(nil), // 5: sync.SyncGetChangeProofRequest - (*SyncGetChangeProofResponse)(nil), // 6: sync.SyncGetChangeProofResponse - (*GetChangeProofRequest)(nil), // 7: sync.GetChangeProofRequest - (*GetChangeProofResponse)(nil), // 8: sync.GetChangeProofResponse - (*VerifyChangeProofRequest)(nil), // 9: sync.VerifyChangeProofRequest - (*VerifyChangeProofResponse)(nil), // 10: sync.VerifyChangeProofResponse - (*CommitChangeProofRequest)(nil), // 11: sync.CommitChangeProofRequest - (*SyncGetRangeProofRequest)(nil), // 12: sync.SyncGetRangeProofRequest - (*GetRangeProofRequest)(nil), // 13: sync.GetRangeProofRequest - (*GetRangeProofResponse)(nil), // 14: sync.GetRangeProofResponse - (*CommitRangeProofRequest)(nil), // 15: sync.CommitRangeProofRequest - (*ChangeProof)(nil), // 16: sync.ChangeProof - (*RangeProof)(nil), // 17: sync.RangeProof - (*ProofNode)(nil), // 18: sync.ProofNode - (*KeyChange)(nil), // 19: sync.KeyChange - (*Path)(nil), // 20: sync.Path - (*MaybeBytes)(nil), // 21: sync.MaybeBytes - (*KeyValue)(nil), // 22: sync.KeyValue - nil, // 23: sync.ProofNode.ChildrenEntry - (*emptypb.Empty)(nil), // 24: google.protobuf.Empty + (*ClearRangeRequest)(nil), // 2: sync.ClearRangeRequest + (*GetProofRequest)(nil), // 3: sync.GetProofRequest + (*GetProofResponse)(nil), // 4: sync.GetProofResponse + (*Proof)(nil), // 5: sync.Proof + (*SyncGetChangeProofRequest)(nil), // 6: sync.SyncGetChangeProofRequest + (*SyncGetChangeProofResponse)(nil), // 7: sync.SyncGetChangeProofResponse + (*GetChangeProofRequest)(nil), // 8: sync.GetChangeProofRequest + (*GetChangeProofResponse)(nil), // 9: sync.GetChangeProofResponse + (*VerifyChangeProofRequest)(nil), // 10: sync.VerifyChangeProofRequest + (*VerifyChangeProofResponse)(nil), // 11: sync.VerifyChangeProofResponse + (*CommitChangeProofRequest)(nil), // 12: sync.CommitChangeProofRequest + (*SyncGetRangeProofRequest)(nil), // 13: sync.SyncGetRangeProofRequest + (*GetRangeProofRequest)(nil), // 14: sync.GetRangeProofRequest + (*GetRangeProofResponse)(nil), // 15: sync.GetRangeProofResponse + (*CommitRangeProofRequest)(nil), // 16: sync.CommitRangeProofRequest + (*ChangeProof)(nil), // 17: sync.ChangeProof + (*RangeProof)(nil), // 18: sync.RangeProof + (*ProofNode)(nil), // 19: sync.ProofNode + (*KeyChange)(nil), // 20: sync.KeyChange + (*Path)(nil), // 21: sync.Path + (*MaybeBytes)(nil), // 22: sync.MaybeBytes + (*KeyValue)(nil), // 23: sync.KeyValue + nil, // 24: sync.ProofNode.ChildrenEntry + (*emptypb.Empty)(nil), // 25: google.protobuf.Empty } var file_sync_sync_proto_depIdxs = []int32{ - 12, // 0: sync.Request.range_proof_request:type_name -> sync.SyncGetRangeProofRequest - 5, // 1: sync.Request.change_proof_request:type_name -> sync.SyncGetChangeProofRequest - 4, // 2: sync.GetProofResponse.proof:type_name -> sync.Proof - 21, // 3: sync.Proof.value:type_name -> sync.MaybeBytes - 18, // 4: sync.Proof.proof:type_name -> sync.ProofNode - 21, // 5: sync.SyncGetChangeProofRequest.start_key:type_name -> sync.MaybeBytes - 21, // 6: sync.SyncGetChangeProofRequest.end_key:type_name -> sync.MaybeBytes - 16, // 7: sync.SyncGetChangeProofResponse.change_proof:type_name -> sync.ChangeProof - 17, // 8: sync.SyncGetChangeProofResponse.range_proof:type_name -> sync.RangeProof - 21, // 9: sync.GetChangeProofRequest.start_key:type_name -> sync.MaybeBytes - 21, // 10: sync.GetChangeProofRequest.end_key:type_name -> sync.MaybeBytes - 16, // 11: sync.GetChangeProofResponse.change_proof:type_name -> sync.ChangeProof - 16, // 12: sync.VerifyChangeProofRequest.proof:type_name -> sync.ChangeProof - 21, // 13: sync.VerifyChangeProofRequest.start_key:type_name -> sync.MaybeBytes - 21, // 14: sync.VerifyChangeProofRequest.end_key:type_name -> sync.MaybeBytes - 16, // 15: sync.CommitChangeProofRequest.proof:type_name -> sync.ChangeProof - 21, // 16: sync.SyncGetRangeProofRequest.start_key:type_name -> sync.MaybeBytes - 21, // 17: sync.SyncGetRangeProofRequest.end_key:type_name -> sync.MaybeBytes - 21, // 18: sync.GetRangeProofRequest.start_key:type_name -> sync.MaybeBytes - 21, // 19: sync.GetRangeProofRequest.end_key:type_name -> sync.MaybeBytes - 17, // 20: sync.GetRangeProofResponse.proof:type_name -> sync.RangeProof - 21, // 21: sync.CommitRangeProofRequest.start_key:type_name -> sync.MaybeBytes - 21, // 22: sync.CommitRangeProofRequest.end_key:type_name -> sync.MaybeBytes - 17, // 23: sync.CommitRangeProofRequest.range_proof:type_name -> sync.RangeProof - 18, // 24: sync.ChangeProof.start_proof:type_name -> sync.ProofNode - 18, // 25: sync.ChangeProof.end_proof:type_name -> sync.ProofNode - 19, // 26: sync.ChangeProof.key_changes:type_name -> sync.KeyChange - 18, // 27: sync.RangeProof.start_proof:type_name -> sync.ProofNode - 18, // 28: sync.RangeProof.end_proof:type_name -> sync.ProofNode - 22, // 29: sync.RangeProof.key_values:type_name -> sync.KeyValue - 20, // 30: sync.ProofNode.key:type_name -> sync.Path - 21, // 31: sync.ProofNode.value_or_hash:type_name -> sync.MaybeBytes - 23, // 32: sync.ProofNode.children:type_name -> sync.ProofNode.ChildrenEntry - 21, // 33: sync.KeyChange.value:type_name -> sync.MaybeBytes - 24, // 34: sync.DB.GetMerkleRoot:input_type -> google.protobuf.Empty - 2, // 35: sync.DB.GetProof:input_type -> sync.GetProofRequest - 7, // 36: sync.DB.GetChangeProof:input_type -> sync.GetChangeProofRequest - 9, // 37: sync.DB.VerifyChangeProof:input_type -> sync.VerifyChangeProofRequest - 11, // 38: sync.DB.CommitChangeProof:input_type -> sync.CommitChangeProofRequest - 13, // 39: sync.DB.GetRangeProof:input_type -> sync.GetRangeProofRequest - 15, // 40: sync.DB.CommitRangeProof:input_type -> sync.CommitRangeProofRequest - 1, // 41: sync.DB.GetMerkleRoot:output_type -> sync.GetMerkleRootResponse - 3, // 42: sync.DB.GetProof:output_type -> sync.GetProofResponse - 8, // 43: sync.DB.GetChangeProof:output_type -> sync.GetChangeProofResponse - 10, // 44: sync.DB.VerifyChangeProof:output_type -> sync.VerifyChangeProofResponse - 24, // 45: sync.DB.CommitChangeProof:output_type -> google.protobuf.Empty - 14, // 46: sync.DB.GetRangeProof:output_type -> sync.GetRangeProofResponse - 24, // 47: sync.DB.CommitRangeProof:output_type -> google.protobuf.Empty - 41, // [41:48] is the sub-list for method output_type - 34, // [34:41] is the sub-list for method input_type - 34, // [34:34] is the sub-list for extension type_name - 34, // [34:34] is the sub-list for extension extendee - 0, // [0:34] is the sub-list for field type_name + 13, // 0: sync.Request.range_proof_request:type_name -> sync.SyncGetRangeProofRequest + 6, // 1: sync.Request.change_proof_request:type_name -> sync.SyncGetChangeProofRequest + 22, // 2: sync.ClearRangeRequest.start_key:type_name -> sync.MaybeBytes + 22, // 3: sync.ClearRangeRequest.end_key:type_name -> sync.MaybeBytes + 5, // 4: sync.GetProofResponse.proof:type_name -> sync.Proof + 22, // 5: sync.Proof.value:type_name -> sync.MaybeBytes + 19, // 6: sync.Proof.proof:type_name -> sync.ProofNode + 22, // 7: sync.SyncGetChangeProofRequest.start_key:type_name -> sync.MaybeBytes + 22, // 8: sync.SyncGetChangeProofRequest.end_key:type_name -> sync.MaybeBytes + 17, // 9: sync.SyncGetChangeProofResponse.change_proof:type_name -> sync.ChangeProof + 18, // 10: sync.SyncGetChangeProofResponse.range_proof:type_name -> sync.RangeProof + 22, // 11: sync.GetChangeProofRequest.start_key:type_name -> sync.MaybeBytes + 22, // 12: sync.GetChangeProofRequest.end_key:type_name -> sync.MaybeBytes + 17, // 13: sync.GetChangeProofResponse.change_proof:type_name -> sync.ChangeProof + 17, // 14: sync.VerifyChangeProofRequest.proof:type_name -> sync.ChangeProof + 22, // 15: sync.VerifyChangeProofRequest.start_key:type_name -> sync.MaybeBytes + 22, // 16: sync.VerifyChangeProofRequest.end_key:type_name -> sync.MaybeBytes + 17, // 17: sync.CommitChangeProofRequest.proof:type_name -> sync.ChangeProof + 22, // 18: sync.SyncGetRangeProofRequest.start_key:type_name -> sync.MaybeBytes + 22, // 19: sync.SyncGetRangeProofRequest.end_key:type_name -> sync.MaybeBytes + 22, // 20: sync.GetRangeProofRequest.start_key:type_name -> sync.MaybeBytes + 22, // 21: sync.GetRangeProofRequest.end_key:type_name -> sync.MaybeBytes + 18, // 22: sync.GetRangeProofResponse.proof:type_name -> sync.RangeProof + 22, // 23: sync.CommitRangeProofRequest.start_key:type_name -> sync.MaybeBytes + 22, // 24: sync.CommitRangeProofRequest.end_key:type_name -> sync.MaybeBytes + 18, // 25: sync.CommitRangeProofRequest.range_proof:type_name -> sync.RangeProof + 19, // 26: sync.ChangeProof.start_proof:type_name -> sync.ProofNode + 19, // 27: sync.ChangeProof.end_proof:type_name -> sync.ProofNode + 20, // 28: sync.ChangeProof.key_changes:type_name -> sync.KeyChange + 19, // 29: sync.RangeProof.start_proof:type_name -> sync.ProofNode + 19, // 30: sync.RangeProof.end_proof:type_name -> sync.ProofNode + 23, // 31: sync.RangeProof.key_values:type_name -> sync.KeyValue + 21, // 32: sync.ProofNode.key:type_name -> sync.Path + 22, // 33: sync.ProofNode.value_or_hash:type_name -> sync.MaybeBytes + 24, // 34: sync.ProofNode.children:type_name -> sync.ProofNode.ChildrenEntry + 22, // 35: sync.KeyChange.value:type_name -> sync.MaybeBytes + 25, // 36: sync.DB.GetMerkleRoot:input_type -> google.protobuf.Empty + 2, // 37: sync.DB.ClearRange:input_type -> sync.ClearRangeRequest + 3, // 38: sync.DB.GetProof:input_type -> sync.GetProofRequest + 8, // 39: sync.DB.GetChangeProof:input_type -> sync.GetChangeProofRequest + 10, // 40: sync.DB.VerifyChangeProof:input_type -> sync.VerifyChangeProofRequest + 12, // 41: sync.DB.CommitChangeProof:input_type -> sync.CommitChangeProofRequest + 14, // 42: sync.DB.GetRangeProof:input_type -> sync.GetRangeProofRequest + 16, // 43: sync.DB.CommitRangeProof:input_type -> sync.CommitRangeProofRequest + 1, // 44: sync.DB.GetMerkleRoot:output_type -> sync.GetMerkleRootResponse + 25, // 45: sync.DB.ClearRange:output_type -> google.protobuf.Empty + 4, // 46: sync.DB.GetProof:output_type -> sync.GetProofResponse + 9, // 47: sync.DB.GetChangeProof:output_type -> sync.GetChangeProofResponse + 11, // 48: sync.DB.VerifyChangeProof:output_type -> sync.VerifyChangeProofResponse + 25, // 49: sync.DB.CommitChangeProof:output_type -> google.protobuf.Empty + 15, // 50: sync.DB.GetRangeProof:output_type -> sync.GetRangeProofResponse + 25, // 51: sync.DB.CommitRangeProof:output_type -> google.protobuf.Empty + 44, // [44:52] is the sub-list for method output_type + 36, // [36:44] is the sub-list for method input_type + 36, // [36:36] is the sub-list for extension type_name + 36, // [36:36] is the sub-list for extension extendee + 0, // [0:36] is the sub-list for field type_name } func init() { file_sync_sync_proto_init() } @@ -1833,7 +1904,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetProofRequest); i { + switch v := v.(*ClearRangeRequest); i { case 0: return &v.state case 1: @@ -1845,7 +1916,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetProofResponse); i { + switch v := v.(*GetProofRequest); i { case 0: return &v.state case 1: @@ -1857,7 +1928,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Proof); i { + switch v := v.(*GetProofResponse); i { case 0: return &v.state case 1: @@ -1869,7 +1940,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SyncGetChangeProofRequest); i { + switch v := v.(*Proof); i { case 0: return &v.state case 1: @@ -1881,7 +1952,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SyncGetChangeProofResponse); i { + switch v := v.(*SyncGetChangeProofRequest); i { case 0: return &v.state case 1: @@ -1893,7 +1964,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetChangeProofRequest); i { + switch v := v.(*SyncGetChangeProofResponse); i { case 0: return &v.state case 1: @@ -1905,7 +1976,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetChangeProofResponse); i { + switch v := v.(*GetChangeProofRequest); i { case 0: return &v.state case 1: @@ -1917,7 +1988,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*VerifyChangeProofRequest); i { + switch v := v.(*GetChangeProofResponse); i { case 0: return &v.state case 1: @@ -1929,7 +2000,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*VerifyChangeProofResponse); i { + switch v := v.(*VerifyChangeProofRequest); i { case 0: return &v.state case 1: @@ -1941,7 +2012,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CommitChangeProofRequest); i { + switch v := v.(*VerifyChangeProofResponse); i { case 0: return &v.state case 1: @@ -1953,7 +2024,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SyncGetRangeProofRequest); i { + switch v := v.(*CommitChangeProofRequest); i { case 0: return &v.state case 1: @@ -1965,7 +2036,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetRangeProofRequest); i { + switch v := v.(*SyncGetRangeProofRequest); i { case 0: return &v.state case 1: @@ -1977,7 +2048,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetRangeProofResponse); i { + switch v := v.(*GetRangeProofRequest); i { case 0: return &v.state case 1: @@ -1989,7 +2060,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CommitRangeProofRequest); i { + switch v := v.(*GetRangeProofResponse); i { case 0: return &v.state case 1: @@ -2001,7 +2072,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ChangeProof); i { + switch v := v.(*CommitRangeProofRequest); i { case 0: return &v.state case 1: @@ -2013,7 +2084,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RangeProof); i { + switch v := v.(*ChangeProof); i { case 0: return &v.state case 1: @@ -2025,7 +2096,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ProofNode); i { + switch v := v.(*RangeProof); i { case 0: return &v.state case 1: @@ -2037,7 +2108,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*KeyChange); i { + switch v := v.(*ProofNode); i { case 0: return &v.state case 1: @@ -2049,7 +2120,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Path); i { + switch v := v.(*KeyChange); i { case 0: return &v.state case 1: @@ -2061,7 +2132,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*MaybeBytes); i { + switch v := v.(*Path); i { case 0: return &v.state case 1: @@ -2073,6 +2144,18 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MaybeBytes); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_sync_sync_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*KeyValue); i { case 0: return &v.state @@ -2089,11 +2172,11 @@ func file_sync_sync_proto_init() { (*Request_RangeProofRequest)(nil), (*Request_ChangeProofRequest)(nil), } - file_sync_sync_proto_msgTypes[6].OneofWrappers = []interface{}{ + file_sync_sync_proto_msgTypes[7].OneofWrappers = []interface{}{ (*SyncGetChangeProofResponse_ChangeProof)(nil), (*SyncGetChangeProofResponse_RangeProof)(nil), } - file_sync_sync_proto_msgTypes[8].OneofWrappers = []interface{}{ + file_sync_sync_proto_msgTypes[9].OneofWrappers = []interface{}{ (*GetChangeProofResponse_ChangeProof)(nil), (*GetChangeProofResponse_RootNotPresent)(nil), } @@ -2103,7 +2186,7 @@ func file_sync_sync_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_sync_sync_proto_rawDesc, NumEnums: 0, - NumMessages: 24, + NumMessages: 25, NumExtensions: 0, NumServices: 1, }, diff --git a/proto/pb/sync/sync_grpc.pb.go b/proto/pb/sync/sync_grpc.pb.go index 3fb420c7273a..5338e9e2a6df 100644 --- a/proto/pb/sync/sync_grpc.pb.go +++ b/proto/pb/sync/sync_grpc.pb.go @@ -21,6 +21,7 @@ const _ = grpc.SupportPackageIsVersion7 const ( DB_GetMerkleRoot_FullMethodName = "/sync.DB/GetMerkleRoot" + DB_ClearRange_FullMethodName = "/sync.DB/ClearRange" DB_GetProof_FullMethodName = "/sync.DB/GetProof" DB_GetChangeProof_FullMethodName = "/sync.DB/GetChangeProof" DB_VerifyChangeProof_FullMethodName = "/sync.DB/VerifyChangeProof" @@ -34,6 +35,7 @@ const ( // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type DBClient interface { GetMerkleRoot(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GetMerkleRootResponse, error) + ClearRange(ctx context.Context, in *ClearRangeRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) GetProof(ctx context.Context, in *GetProofRequest, opts ...grpc.CallOption) (*GetProofResponse, error) GetChangeProof(ctx context.Context, in *GetChangeProofRequest, opts ...grpc.CallOption) (*GetChangeProofResponse, error) VerifyChangeProof(ctx context.Context, in *VerifyChangeProofRequest, opts ...grpc.CallOption) (*VerifyChangeProofResponse, error) @@ -59,6 +61,15 @@ func (c *dBClient) GetMerkleRoot(ctx context.Context, in *emptypb.Empty, opts .. return out, nil } +func (c *dBClient) ClearRange(ctx context.Context, in *ClearRangeRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, DB_ClearRange_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *dBClient) GetProof(ctx context.Context, in *GetProofRequest, opts ...grpc.CallOption) (*GetProofResponse, error) { out := new(GetProofResponse) err := c.cc.Invoke(ctx, DB_GetProof_FullMethodName, in, out, opts...) @@ -118,6 +129,7 @@ func (c *dBClient) CommitRangeProof(ctx context.Context, in *CommitRangeProofReq // for forward compatibility type DBServer interface { GetMerkleRoot(context.Context, *emptypb.Empty) (*GetMerkleRootResponse, error) + ClearRange(context.Context, *ClearRangeRequest) (*emptypb.Empty, error) GetProof(context.Context, *GetProofRequest) (*GetProofResponse, error) GetChangeProof(context.Context, *GetChangeProofRequest) (*GetChangeProofResponse, error) VerifyChangeProof(context.Context, *VerifyChangeProofRequest) (*VerifyChangeProofResponse, error) @@ -134,6 +146,9 @@ type UnimplementedDBServer struct { func (UnimplementedDBServer) GetMerkleRoot(context.Context, *emptypb.Empty) (*GetMerkleRootResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetMerkleRoot not implemented") } +func (UnimplementedDBServer) ClearRange(context.Context, *ClearRangeRequest) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ClearRange not implemented") +} func (UnimplementedDBServer) GetProof(context.Context, *GetProofRequest) (*GetProofResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetProof not implemented") } @@ -183,6 +198,24 @@ func _DB_GetMerkleRoot_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _DB_ClearRange_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ClearRangeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DBServer).ClearRange(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: DB_ClearRange_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DBServer).ClearRange(ctx, req.(*ClearRangeRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _DB_GetProof_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(GetProofRequest) if err := dec(in); err != nil { @@ -302,6 +335,10 @@ var DB_ServiceDesc = grpc.ServiceDesc{ MethodName: "GetMerkleRoot", Handler: _DB_GetMerkleRoot_Handler, }, + { + MethodName: "ClearRange", + Handler: _DB_ClearRange_Handler, + }, { MethodName: "GetProof", Handler: _DB_GetProof_Handler, diff --git a/proto/sync/sync.proto b/proto/sync/sync.proto index 32ae2f8a4849..99d473793a3f 100644 --- a/proto/sync/sync.proto +++ b/proto/sync/sync.proto @@ -21,6 +21,8 @@ message Request { service DB { rpc GetMerkleRoot(google.protobuf.Empty) returns (GetMerkleRootResponse); + rpc ClearRange(ClearRangeRequest) returns (google.protobuf.Empty); + rpc GetProof(GetProofRequest) returns (GetProofResponse); rpc GetChangeProof(GetChangeProofRequest) returns (GetChangeProofResponse); @@ -35,6 +37,11 @@ message GetMerkleRootResponse { bytes root_hash = 1; } +message ClearRangeRequest { + MaybeBytes start_key = 1; + MaybeBytes end_key = 2; +} + message GetProofRequest { bytes key = 1; } diff --git a/scripts/mocks.mockgen.txt b/scripts/mocks.mockgen.txt index ebd793330a51..766afb702c7e 100644 --- a/scripts/mocks.mockgen.txt +++ b/scripts/mocks.mockgen.txt @@ -1,52 +1 @@ -github.com/ava-labs/avalanchego/api/server=Server=api/server/mock_server.go -github.com/ava-labs/avalanchego/chains/atomic=SharedMemory=chains/atomic/mock_shared_memory.go -github.com/ava-labs/avalanchego/codec=Manager=codec/mock_manager.go -github.com/ava-labs/avalanchego/database=Batch=database/mock_batch.go -github.com/ava-labs/avalanchego/database=Iterator=database/mock_iterator.go -github.com/ava-labs/avalanchego/message=OutboundMessage=message/mock_message.go -github.com/ava-labs/avalanchego/message=OutboundMsgBuilder=message/mock_outbound_message_builder.go -github.com/ava-labs/avalanchego/network/peer=GossipTracker=network/peer/mock_gossip_tracker.go -github.com/ava-labs/avalanchego/network/p2p=Handler=network/p2p/mocks/mock_handler.go -github.com/ava-labs/avalanchego/snow/consensus/snowman=Block=snow/consensus/snowman/mock_block.go -github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex=LinearizableVM=snow/engine/avalanche/vertex/mock_vm.go -github.com/ava-labs/avalanchego/snow/engine/snowman/block=BuildBlockWithContextChainVM=snow/engine/snowman/block/mocks/build_block_with_context_vm.go -github.com/ava-labs/avalanchego/snow/engine/snowman/block=ChainVM=snow/engine/snowman/block/mocks/chain_vm.go -github.com/ava-labs/avalanchego/snow/engine/snowman/block=StateSyncableVM=snow/engine/snowman/block/mocks/state_syncable_vm.go -github.com/ava-labs/avalanchego/snow/engine/snowman/block=WithVerifyContext=snow/engine/snowman/block/mocks/with_verify_context.go -github.com/ava-labs/avalanchego/snow/networking/handler=Handler=snow/networking/handler/mock_handler.go -github.com/ava-labs/avalanchego/snow/networking/timeout=Manager=snow/networking/timeout/mock_manager.go -github.com/ava-labs/avalanchego/snow/networking/tracker=Targeter=snow/networking/tracker/mock_targeter.go -github.com/ava-labs/avalanchego/snow/networking/tracker=Tracker=snow/networking/tracker/mock_resource_tracker.go -github.com/ava-labs/avalanchego/snow/uptime=Calculator=snow/uptime/mock_calculator.go -github.com/ava-labs/avalanchego/snow/validators=Manager=snow/validators/mock_manager.go -github.com/ava-labs/avalanchego/snow/validators=State=snow/validators/mock_state.go -github.com/ava-labs/avalanchego/snow/validators=SubnetConnector=snow/validators/mock_subnet_connector.go -github.com/ava-labs/avalanchego/utils/crypto/keychain=Ledger=utils/crypto/keychain/mock_ledger.go -github.com/ava-labs/avalanchego/utils/filesystem=Reader=utils/filesystem/mock_io.go -github.com/ava-labs/avalanchego/utils/hashing=Hasher=utils/hashing/mock_hasher.go -github.com/ava-labs/avalanchego/utils/logging=Logger=utils/logging/mock_logger.go -github.com/ava-labs/avalanchego/utils/resource=User=utils/resource/mock_user.go -github.com/ava-labs/avalanchego/vms/avm/block=Block=vms/avm/block/mock_block.go -github.com/ava-labs/avalanchego/vms/avm/metrics=Metrics=vms/avm/metrics/mock_metrics.go -github.com/ava-labs/avalanchego/vms/avm/states=Chain,State,Diff=vms/avm/states/mock_states.go -github.com/ava-labs/avalanchego/vms/avm/txs/mempool=Mempool=vms/avm/txs/mempool/mock_mempool.go -github.com/ava-labs/avalanchego/vms/components/avax=TransferableIn=vms/components/avax/mock_transferable_in.go -github.com/ava-labs/avalanchego/vms/components/verify=Verifiable=vms/components/verify/mock_verifiable.go -github.com/ava-labs/avalanchego/vms/platformvm/block/executor=Manager=vms/platformvm/block/executor/mock_manager.go -github.com/ava-labs/avalanchego/vms/platformvm/block=Block=vms/platformvm/block/mock_block.go -github.com/ava-labs/avalanchego/vms/platformvm/state=Chain=vms/platformvm/state/mock_chain.go -github.com/ava-labs/avalanchego/vms/platformvm/state=Diff=vms/platformvm/state/mock_diff.go -github.com/ava-labs/avalanchego/vms/platformvm/state=StakerIterator=vms/platformvm/state/mock_staker_iterator.go -github.com/ava-labs/avalanchego/vms/platformvm/state=State=vms/platformvm/state/mock_state.go -github.com/ava-labs/avalanchego/vms/platformvm/state=Versions=vms/platformvm/state/mock_versions.go -github.com/ava-labs/avalanchego/vms/platformvm/txs/builder=Builder=vms/platformvm/txs/builder/mock_builder.go -github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool=Mempool=vms/platformvm/txs/mempool/mock_mempool.go -github.com/ava-labs/avalanchego/vms/platformvm/utxo=Verifier=vms/platformvm/utxo/mock_verifier.go -github.com/ava-labs/avalanchego/vms/proposervm/proposer=Windower=vms/proposervm/proposer/mock_windower.go -github.com/ava-labs/avalanchego/vms/proposervm/state=State=vms/proposervm/state/mock_state.go -github.com/ava-labs/avalanchego/vms/proposervm=PostForkBlock=vms/proposervm/mock_post_fork_block.go -github.com/ava-labs/avalanchego/vms/registry=VMGetter=vms/registry/mock_vm_getter.go -github.com/ava-labs/avalanchego/vms/registry=VMRegisterer=vms/registry/mock_vm_registerer.go -github.com/ava-labs/avalanchego/vms/registry=VMRegistry=vms/registry/mock_vm_registry.go -github.com/ava-labs/avalanchego/vms=Factory,Manager=vms/mock_manager.go -github.com/ava-labs/avalanchego/x/sync=Client=x/sync/mock_client.go +github.com/ava-labs/avalanchego/x/merkledb=MerkleDB=x/merkledb/mock_db.go diff --git a/x/merkledb/db.go b/x/merkledb/db.go index bc087d34d621..0731616f814e 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -135,6 +135,7 @@ type Prefetcher interface { type MerkleDB interface { database.Database + database.ClearRanger Trie MerkleRootGetter ProofGetter @@ -1286,6 +1287,33 @@ func (db *merkleDB) getRoot() maybe.Maybe[*node] { return db.root } +func (db *merkleDB) ClearRange(start, end maybe.Maybe[[]byte]) error { + db.commitLock.Lock() + defer db.commitLock.Unlock() + + keysToDelete, err := db.getKeysNotInSet(start, end, set.Set[string]{}) + if err != nil { + return err + } + + ops := make([]database.BatchOp, len(keysToDelete)) + for i, keyToDelete := range keysToDelete { + keyToDelete := keyToDelete + ops[i] = database.BatchOp{ + Key: keyToDelete, + Delete: true, + } + } + + // Don't need to lock [view] because nobody else has a reference to it. + view, err := newTrieView(db, db, ViewChanges{BatchOps: ops}) + if err != nil { + return err + } + + return view.commitToDB(context.TODO()) +} + // Returns [key] prefixed by [prefix]. // The returned []byte is taken from [bufferPool] and // should be returned to it when the caller is done with it. diff --git a/x/merkledb/mock_db.go b/x/merkledb/mock_db.go index 6df5ed92e5bf..647b7543b7d1 100644 --- a/x/merkledb/mock_db.go +++ b/x/merkledb/mock_db.go @@ -5,14 +5,14 @@ package merkledb import ( - database "github.com/ava-labs/avalanchego/database" - ids "github.com/ava-labs/avalanchego/ids" maybe "github.com/ava-labs/avalanchego/utils/maybe" gomock "go.uber.org/mock/gomock" reflect "reflect" context "context" + database "github.com/ava-labs/avalanchego/database" + ids "github.com/ava-labs/avalanchego/ids" ) - + // MockMerkleDB is a mock of MerkleDB interface. type MockMerkleDB struct { ctrl *gomock.Controller @@ -36,6 +36,20 @@ func (m *MockMerkleDB) EXPECT() *MockMerkleDBMockRecorder { return m.recorder } +// ClearRange mocks base method. +func (m *MockMerkleDB) ClearRange(arg0, arg1 maybe.Maybe[[]uint8]) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ClearRange", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// ClearRange indicates an expected call of ClearRange. +func (mr *MockMerkleDBMockRecorder) ClearRange(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClearRange", reflect.TypeOf((*MockMerkleDB)(nil).ClearRange), arg0, arg1) +} + // Close mocks base method. func (m *MockMerkleDB) Close() error { m.ctrl.T.Helper() @@ -439,4 +453,4 @@ func (m *MockMerkleDB) getValue(arg0 Path) ([]byte, error) { func (mr *MockMerkleDBMockRecorder) getValue(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "getValue", reflect.TypeOf((*MockMerkleDB)(nil).getValue), arg0) -} +} \ No newline at end of file diff --git a/x/sync/client_test.go b/x/sync/client_test.go index 2c7b8e1b15d5..d9d78a3fa2d5 100644 --- a/x/sync/client_test.go +++ b/x/sync/client_test.go @@ -331,20 +331,6 @@ func TestGetRangeProof(t *testing.T) { }, expectedErr: merkledb.ErrNoEndProof, }, - "empty proof": { - db: largeTrieDB, - request: &pb.SyncGetRangeProofRequest{ - RootHash: largeTrieRoot[:], - KeyLimit: defaultRequestKeyLimit, - BytesLimit: defaultRequestByteSizeLimit, - }, - modifyResponse: func(response *merkledb.RangeProof) { - response.KeyValues = nil - response.StartProof = nil - response.EndProof = nil - }, - expectedErr: merkledb.ErrEmptyProof, - }, } for name, test := range tests { diff --git a/x/sync/db.go b/x/sync/db.go index 94b5542e34c1..bda1130c8f33 100644 --- a/x/sync/db.go +++ b/x/sync/db.go @@ -3,9 +3,13 @@ package sync -import "github.com/ava-labs/avalanchego/x/merkledb" +import ( + "github.com/ava-labs/avalanchego/database" + "github.com/ava-labs/avalanchego/x/merkledb" +) type DB interface { + database.ClearRanger merkledb.MerkleRootGetter merkledb.ProofGetter merkledb.ChangeProofer diff --git a/x/sync/g_db/db_client.go b/x/sync/g_db/db_client.go index 8bd936a53975..4124fbcd36e4 100644 --- a/x/sync/g_db/db_client.go +++ b/x/sync/g_db/db_client.go @@ -177,3 +177,20 @@ func (c *DBClient) CommitRangeProof( }) return err } + +func (c *DBClient) ClearRange( + start maybe.Maybe[[]byte], + end maybe.Maybe[[]byte], +) error { + _, err := c.client.ClearRange(context.Background(), &pb.ClearRangeRequest{ + StartKey: &pb.MaybeBytes{ + Value: start.Value(), + IsNothing: start.IsNothing(), + }, + EndKey: &pb.MaybeBytes{ + Value: end.Value(), + IsNothing: end.IsNothing(), + }, + }) + return err +} diff --git a/x/sync/g_db/db_server.go b/x/sync/g_db/db_server.go index b6471542dcca..7bc37378281d 100644 --- a/x/sync/g_db/db_server.go +++ b/x/sync/g_db/db_server.go @@ -218,3 +218,21 @@ func (s *DBServer) CommitRangeProof( err := s.db.CommitRangeProof(ctx, start, end, &proof) return &emptypb.Empty{}, err } + +func (s *DBServer) ClearRange( + ctx context.Context, + req *pb.ClearRangeRequest, +) (*emptypb.Empty, error) { + start := maybe.Nothing[[]byte]() + if req.StartKey != nil && !req.StartKey.IsNothing { + start = maybe.Some(req.StartKey.Value) + } + + end := maybe.Nothing[[]byte]() + if req.EndKey != nil && !req.EndKey.IsNothing { + end = maybe.Some(req.EndKey.Value) + } + + err := s.db.ClearRange(start, end) + return &emptypb.Empty{}, err +} diff --git a/x/sync/manager.go b/x/sync/manager.go index 96b104fcfdd0..a4c57db911c4 100644 --- a/x/sync/manager.go +++ b/x/sync/manager.go @@ -263,6 +263,17 @@ func (m *Manager) getAndApplyChangeProof(ctx context.Context, work *workItem) { return } + if targetRootID == ids.Empty { + // The trie is empty after this change. + // Delete all the key-value pairs in the range. + if err := m.config.DB.ClearRange(work.start, work.end); err != nil { + m.setError(err) + return + } + m.completeWorkItem(ctx, work, work.end, targetRootID, nil) + return + } + changeOrRangeProof, err := m.config.Client.GetChangeProof( ctx, &pb.SyncGetChangeProofRequest{ @@ -329,6 +340,16 @@ func (m *Manager) getAndApplyChangeProof(ctx context.Context, work *workItem) { // Assumes [m.workLock] is not held. func (m *Manager) getAndApplyRangeProof(ctx context.Context, work *workItem) { targetRootID := m.getTargetRoot() + + if targetRootID == ids.Empty { + if err := m.config.DB.ClearRange(work.start, work.end); err != nil { + m.setError(err) + return + } + m.completeWorkItem(ctx, work, work.end, targetRootID, nil) + return + } + proof, err := m.config.Client.GetRangeProof(ctx, &pb.SyncGetRangeProofRequest{ RootHash: targetRootID[:], diff --git a/x/sync/sync_test.go b/x/sync/sync_test.go index 17ebef315e8c..9512cb70fc7d 100644 --- a/x/sync/sync_test.go +++ b/x/sync/sync_test.go @@ -102,14 +102,17 @@ func Test_Completion(t *testing.T) { newDefaultDBConfig(), ) require.NoError(err) + emptyRoot, err := emptyDB.GetMerkleRoot(context.Background()) require.NoError(err) + db, err := merkledb.New( context.Background(), memdb.New(), newDefaultDBConfig(), ) require.NoError(err) + syncer, err := NewManager(ManagerConfig{ DB: db, Client: newCallthroughSyncClient(ctrl, emptyDB), @@ -120,8 +123,10 @@ func Test_Completion(t *testing.T) { }) require.NoError(err) require.NotNil(syncer) + require.NoError(syncer.Start(context.Background())) require.NoError(syncer.Wait(context.Background())) + syncer.workLock.Lock() require.Zero(syncer.unprocessedWork.Len()) require.Equal(1, syncer.processedWork.Len()) From 1adbac12c63a876cffa31c8a7214a4fbafe5a58e Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 19 Oct 2023 17:15:22 -0400 Subject: [PATCH 053/131] appease linter --- x/sync/g_db/db_server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/sync/g_db/db_server.go b/x/sync/g_db/db_server.go index 7bc37378281d..f49400abfce3 100644 --- a/x/sync/g_db/db_server.go +++ b/x/sync/g_db/db_server.go @@ -220,7 +220,7 @@ func (s *DBServer) CommitRangeProof( } func (s *DBServer) ClearRange( - ctx context.Context, + _ context.Context, req *pb.ClearRangeRequest, ) (*emptypb.Empty, error) { start := maybe.Nothing[[]byte]() From 6db69f30a41559113877d3ea861f8f3b68bf4c92 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 10:21:56 -0400 Subject: [PATCH 054/131] fix mock list --- scripts/mocks.mockgen.txt | 53 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/scripts/mocks.mockgen.txt b/scripts/mocks.mockgen.txt index 766afb702c7e..ebd793330a51 100644 --- a/scripts/mocks.mockgen.txt +++ b/scripts/mocks.mockgen.txt @@ -1 +1,52 @@ -github.com/ava-labs/avalanchego/x/merkledb=MerkleDB=x/merkledb/mock_db.go +github.com/ava-labs/avalanchego/api/server=Server=api/server/mock_server.go +github.com/ava-labs/avalanchego/chains/atomic=SharedMemory=chains/atomic/mock_shared_memory.go +github.com/ava-labs/avalanchego/codec=Manager=codec/mock_manager.go +github.com/ava-labs/avalanchego/database=Batch=database/mock_batch.go +github.com/ava-labs/avalanchego/database=Iterator=database/mock_iterator.go +github.com/ava-labs/avalanchego/message=OutboundMessage=message/mock_message.go +github.com/ava-labs/avalanchego/message=OutboundMsgBuilder=message/mock_outbound_message_builder.go +github.com/ava-labs/avalanchego/network/peer=GossipTracker=network/peer/mock_gossip_tracker.go +github.com/ava-labs/avalanchego/network/p2p=Handler=network/p2p/mocks/mock_handler.go +github.com/ava-labs/avalanchego/snow/consensus/snowman=Block=snow/consensus/snowman/mock_block.go +github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex=LinearizableVM=snow/engine/avalanche/vertex/mock_vm.go +github.com/ava-labs/avalanchego/snow/engine/snowman/block=BuildBlockWithContextChainVM=snow/engine/snowman/block/mocks/build_block_with_context_vm.go +github.com/ava-labs/avalanchego/snow/engine/snowman/block=ChainVM=snow/engine/snowman/block/mocks/chain_vm.go +github.com/ava-labs/avalanchego/snow/engine/snowman/block=StateSyncableVM=snow/engine/snowman/block/mocks/state_syncable_vm.go +github.com/ava-labs/avalanchego/snow/engine/snowman/block=WithVerifyContext=snow/engine/snowman/block/mocks/with_verify_context.go +github.com/ava-labs/avalanchego/snow/networking/handler=Handler=snow/networking/handler/mock_handler.go +github.com/ava-labs/avalanchego/snow/networking/timeout=Manager=snow/networking/timeout/mock_manager.go +github.com/ava-labs/avalanchego/snow/networking/tracker=Targeter=snow/networking/tracker/mock_targeter.go +github.com/ava-labs/avalanchego/snow/networking/tracker=Tracker=snow/networking/tracker/mock_resource_tracker.go +github.com/ava-labs/avalanchego/snow/uptime=Calculator=snow/uptime/mock_calculator.go +github.com/ava-labs/avalanchego/snow/validators=Manager=snow/validators/mock_manager.go +github.com/ava-labs/avalanchego/snow/validators=State=snow/validators/mock_state.go +github.com/ava-labs/avalanchego/snow/validators=SubnetConnector=snow/validators/mock_subnet_connector.go +github.com/ava-labs/avalanchego/utils/crypto/keychain=Ledger=utils/crypto/keychain/mock_ledger.go +github.com/ava-labs/avalanchego/utils/filesystem=Reader=utils/filesystem/mock_io.go +github.com/ava-labs/avalanchego/utils/hashing=Hasher=utils/hashing/mock_hasher.go +github.com/ava-labs/avalanchego/utils/logging=Logger=utils/logging/mock_logger.go +github.com/ava-labs/avalanchego/utils/resource=User=utils/resource/mock_user.go +github.com/ava-labs/avalanchego/vms/avm/block=Block=vms/avm/block/mock_block.go +github.com/ava-labs/avalanchego/vms/avm/metrics=Metrics=vms/avm/metrics/mock_metrics.go +github.com/ava-labs/avalanchego/vms/avm/states=Chain,State,Diff=vms/avm/states/mock_states.go +github.com/ava-labs/avalanchego/vms/avm/txs/mempool=Mempool=vms/avm/txs/mempool/mock_mempool.go +github.com/ava-labs/avalanchego/vms/components/avax=TransferableIn=vms/components/avax/mock_transferable_in.go +github.com/ava-labs/avalanchego/vms/components/verify=Verifiable=vms/components/verify/mock_verifiable.go +github.com/ava-labs/avalanchego/vms/platformvm/block/executor=Manager=vms/platformvm/block/executor/mock_manager.go +github.com/ava-labs/avalanchego/vms/platformvm/block=Block=vms/platformvm/block/mock_block.go +github.com/ava-labs/avalanchego/vms/platformvm/state=Chain=vms/platformvm/state/mock_chain.go +github.com/ava-labs/avalanchego/vms/platformvm/state=Diff=vms/platformvm/state/mock_diff.go +github.com/ava-labs/avalanchego/vms/platformvm/state=StakerIterator=vms/platformvm/state/mock_staker_iterator.go +github.com/ava-labs/avalanchego/vms/platformvm/state=State=vms/platformvm/state/mock_state.go +github.com/ava-labs/avalanchego/vms/platformvm/state=Versions=vms/platformvm/state/mock_versions.go +github.com/ava-labs/avalanchego/vms/platformvm/txs/builder=Builder=vms/platformvm/txs/builder/mock_builder.go +github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool=Mempool=vms/platformvm/txs/mempool/mock_mempool.go +github.com/ava-labs/avalanchego/vms/platformvm/utxo=Verifier=vms/platformvm/utxo/mock_verifier.go +github.com/ava-labs/avalanchego/vms/proposervm/proposer=Windower=vms/proposervm/proposer/mock_windower.go +github.com/ava-labs/avalanchego/vms/proposervm/state=State=vms/proposervm/state/mock_state.go +github.com/ava-labs/avalanchego/vms/proposervm=PostForkBlock=vms/proposervm/mock_post_fork_block.go +github.com/ava-labs/avalanchego/vms/registry=VMGetter=vms/registry/mock_vm_getter.go +github.com/ava-labs/avalanchego/vms/registry=VMRegisterer=vms/registry/mock_vm_registerer.go +github.com/ava-labs/avalanchego/vms/registry=VMRegistry=vms/registry/mock_vm_registry.go +github.com/ava-labs/avalanchego/vms=Factory,Manager=vms/mock_manager.go +github.com/ava-labs/avalanchego/x/sync=Client=x/sync/mock_client.go From 47dd688c0b5a26e40ed0e09c983ba19457ab6ac5 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 10:24:27 -0400 Subject: [PATCH 055/131] comment nit --- x/merkledb/db.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 0731616f814e..f14246d8603b 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -104,8 +104,7 @@ type RangeProofer interface { // If [start] is Nothing, there's no lower bound on the range. // If [end] is Nothing, there's no upper bound on the range. // Returns ErrEmptyRootID if [rootID] is ids.Empty. - // Note that [rootID] == ids.Empty means the trie is empty, and there's no notion - // of proofs for empty tries. + // Note that [rootID] == ids.Empty means the trie is empty. GetRangeProofAtRoot( ctx context.Context, rootID ids.ID, From 3b895310b9334dddc2eee119f10ea21e6269ffed Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 10:44:29 -0400 Subject: [PATCH 056/131] TODO --> Background --- x/merkledb/db.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index f14246d8603b..a64ddc686463 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1310,7 +1310,7 @@ func (db *merkleDB) ClearRange(start, end maybe.Maybe[[]byte]) error { return err } - return view.commitToDB(context.TODO()) + return view.commitToDB(context.Background()) } // Returns [key] prefixed by [prefix]. From d6c33441a2096fe76e0b6cb1e66ee1591a4337af Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 10:48:48 -0400 Subject: [PATCH 057/131] comment --- x/merkledb/db.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index a64ddc686463..d6cb1fb2c5b9 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -104,7 +104,8 @@ type RangeProofer interface { // If [start] is Nothing, there's no lower bound on the range. // If [end] is Nothing, there's no upper bound on the range. // Returns ErrEmptyRootID if [rootID] is ids.Empty. - // Note that [rootID] == ids.Empty means the trie is empty. + // Note that [rootID] == ids.Empty means the trie is empty + // (i.e. we don't need a range proof.) GetRangeProofAtRoot( ctx context.Context, rootID ids.ID, From 860bd8a65a0df45810f3542b5aa58a93cfc6b14a Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 10:54:13 -0400 Subject: [PATCH 058/131] comment --- x/merkledb/db.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index d6cb1fb2c5b9..91153c6cc6f7 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -67,6 +67,7 @@ type ChangeProofer interface { // to generate the proof. // Returns ErrEmptyRootID if [endRootID] is ids.Empty. // Note that [endRootID] == ids.Empty means the trie is empty. + // (i.e. we don't need a range proof.) GetChangeProof( ctx context.Context, startRootID ids.ID, From 40049b5a30dfa3f9c6132827b541f1ca5f0e87a0 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 11:05:43 -0400 Subject: [PATCH 059/131] comment --- x/merkledb/db.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 91153c6cc6f7..55d9ac399a76 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -67,7 +67,7 @@ type ChangeProofer interface { // to generate the proof. // Returns ErrEmptyRootID if [endRootID] is ids.Empty. // Note that [endRootID] == ids.Empty means the trie is empty. - // (i.e. we don't need a range proof.) + // (i.e. we don't need a change proof.) GetChangeProof( ctx context.Context, startRootID ids.ID, From 3b4b83a2cf0d907b9131dc0deeb8c0b8572d0402 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 11:10:32 -0400 Subject: [PATCH 060/131] comment --- x/merkledb/db.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 55d9ac399a76..2c920a76b0d0 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -66,7 +66,7 @@ type ChangeProofer interface { // Returns [ErrInsufficientHistory] if this node has insufficient history // to generate the proof. // Returns ErrEmptyRootID if [endRootID] is ids.Empty. - // Note that [endRootID] == ids.Empty means the trie is empty. + // Note that [endRootID] == ids.Empty means the trie is empty // (i.e. we don't need a change proof.) GetChangeProof( ctx context.Context, From 0f6cc05fb320d11d664bd62b1ac33c88d19cfc84 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 11:33:25 -0400 Subject: [PATCH 061/131] fix(?) mock --- x/merkledb/mock_db.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/merkledb/mock_db.go b/x/merkledb/mock_db.go index f8684112969e..dbcc43342276 100644 --- a/x/merkledb/mock_db.go +++ b/x/merkledb/mock_db.go @@ -453,4 +453,4 @@ func (m *MockMerkleDB) getValue(arg0 Key) ([]byte, error) { func (mr *MockMerkleDBMockRecorder) getValue(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "getValue", reflect.TypeOf((*MockMerkleDB)(nil).getValue), arg0) -} \ No newline at end of file +} From 3c9fc2bbfb4e16b5d53e38b8a9a7461b7eaebfd7 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 12:22:32 -0400 Subject: [PATCH 062/131] fix(?) test --- x/merkledb/proof_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index 0425bcfcea98..e25bb140aa05 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -1687,6 +1687,9 @@ func FuzzRangeProofInvariants(f *testing.F) { if maxProofLen == 0 { t.SkipNow() } + if numKeyValues == 0 { + t.SkipNow() + } // Make sure proof bounds are valid if len(endBytes) != 0 && bytes.Compare(startBytes, endBytes) > 0 { From 605b29408767c515062f4d0296fd11182dd4c90a Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 12:53:32 -0400 Subject: [PATCH 063/131] fix(?) test --- x/merkledb/proof.go | 5 ++--- x/merkledb/proof_test.go | 9 +++++++-- x/merkledb/trie.go | 1 + x/merkledb/trieview.go | 14 ++------------ 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/x/merkledb/proof.go b/x/merkledb/proof.go index c927208e831e..b538937204a5 100644 --- a/x/merkledb/proof.go +++ b/x/merkledb/proof.go @@ -37,7 +37,6 @@ var ( ErrShouldJustBeRoot = errors.New("end proof should only contain root") ErrNoStartProof = errors.New("no start proof") ErrNoEndProof = errors.New("no end proof") - ErrNoProof = errors.New("proof has no nodes") ErrProofNodeNotForKey = errors.New("the provided node has a key that is not a prefix of the specified key") ErrProofValueDoesntMatch = errors.New("the provided value does not match the proof node for the provided key's value") ErrProofNodeHasUnincludedValue = errors.New("the provided proof has a value for a key within the range that is not present in the provided key/values") @@ -144,7 +143,7 @@ type Proof struct { func (proof *Proof) Verify(ctx context.Context, expectedRootID ids.ID) error { // Make sure the proof is well-formed. if len(proof.Path) == 0 { - return ErrNoProof + return ErrEmptyProof } if err := verifyProofPath(proof.Path, maybe.Some(proof.Key)); err != nil { @@ -290,7 +289,7 @@ func (proof *RangeProof) Verify( case start.HasValue() && end.HasValue() && bytes.Compare(start.Value(), end.Value()) > 0: return ErrStartAfterEnd case len(proof.KeyValues) == 0 && len(proof.StartProof) == 0 && len(proof.EndProof) == 0: - return ErrNoProof + return ErrEmptyProof case end.IsNothing() && len(proof.KeyValues) == 0 && len(proof.EndProof) != 0: return ErrUnexpectedEndProof case len(proof.EndProof) == 0 && (end.HasValue() || len(proof.KeyValues) > 0): diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index e25bb140aa05..ca5e5de0c007 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -24,7 +24,7 @@ import ( func Test_Proof_Empty(t *testing.T) { proof := &Proof{} err := proof.Verify(context.Background(), ids.Empty) - require.ErrorIs(t, err, ErrNoProof) + require.ErrorIs(t, err, ErrEmptyProof) } func Test_Proof_Simple(t *testing.T) { @@ -1832,7 +1832,12 @@ func FuzzProofVerification(f *testing.F) { rootID, err := db.GetMerkleRoot(context.Background()) require.NoError(err) - require.NoError(proof.Verify(context.Background(), rootID)) + err = proof.Verify(context.Background(), rootID) + if numKeyValues == 0 { + require.ErrorIs(err, ErrEmptyProof) + return + } + require.NoError(err) // Insert a new key-value pair newKey := make([]byte, 32) diff --git a/x/merkledb/trie.go b/x/merkledb/trie.go index 79225901252f..d72bd51bfb56 100644 --- a/x/merkledb/trie.go +++ b/x/merkledb/trie.go @@ -20,6 +20,7 @@ type MerkleRootGetter interface { type ProofGetter interface { // GetProof generates a proof of the value associated with a particular key, // or a proof of its absence from the trie + // The returned proof's [Path] is non-empty iff the trie is non-empty. GetProof(ctx context.Context, keyBytes []byte) (*Proof, error) } diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 386823cb30f6..1e8b7fa36173 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -342,8 +342,8 @@ func (t *trieView) GetProof(ctx context.Context, key []byte) (*Proof, error) { return t.getProof(ctx, key) } -// Returns a proof that [bytesPath] is in or not in trie [t]. -// TODO find places broken by this returning proofs with empty paths +// Returns a proof that [key] is in or not in [t]. +// The returned proof's [Path] is non-empty iff [t] is non-empty. func (t *trieView) getProof(ctx context.Context, key []byte) (*Proof, error) { _, span := t.db.infoTracer.Start(ctx, "MerkleDB.trieview.getProof") defer span.End() @@ -487,16 +487,6 @@ func (t *trieView) GetRangeProof( result.StartProof = result.StartProof[i:] } - // TODO remove - // if len(result.StartProof) == 0 && len(result.EndProof) == 0 && len(result.KeyValues) == 0 { - // // If the range is empty, return the root proof. - // rootProof, err := t.getProof(ctx, emptyKey) - // if err != nil { - // return nil, err - // } - // result.EndProof = rootProof.Path - // } - if t.isInvalid() { return nil, ErrInvalid } From 07aee5c5bff0700ccc8a71bde4ed2af6ab3ab342 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 13:07:34 -0400 Subject: [PATCH 064/131] fix(?) test --- x/merkledb/proof_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index ca5e5de0c007..796654b97326 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -1833,7 +1833,7 @@ func FuzzProofVerification(f *testing.F) { require.NoError(err) err = proof.Verify(context.Background(), rootID) - if numKeyValues == 0 { + if rootID == ids.Empty { require.ErrorIs(err, ErrEmptyProof) return } From ee838f054cc505468279d5746bce25c08d87cf3c Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 13:24:54 -0400 Subject: [PATCH 065/131] fix(?) test --- x/merkledb/codec_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index c8490e52c65a..23765aa3314d 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -283,6 +283,8 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { removeToken bool, numChildren int, ) { + require := require.New(t) + for _, branchFactor := range branchFactors { key := ToKey(keyBytes, branchFactor) @@ -319,9 +321,9 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { gotNode dbNode gotKey Key ) - require.NoError(f, codec.decodeKeyAndNode(b, &gotKey, &gotNode, branchFactor)) - require.Equal(f, expectedNode, &gotNode) - require.Equal(f, key, gotKey) + require.NoError(codec.decodeKeyAndNode(b, &gotKey, &gotNode, branchFactor)) + require.Equal(expectedNode, &gotNode) + require.Equal(key, gotKey) } }, ) From d9bfef9fa7ffb69d9690ad92071faad45866e04f Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 13:44:42 -0400 Subject: [PATCH 066/131] fix(?) test --- x/merkledb/codec_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index 23765aa3314d..d70c281f0315 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -294,6 +294,9 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { val := maybe.Nothing[[]byte]() if hasValue { + if len(value) == 0 { + value = nil + } val = maybe.Some(value) } From 404132b74f8f68fde394ad8f60f2048d90b6dfc7 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 13:54:55 -0400 Subject: [PATCH 067/131] nits --- x/merkledb/proof_test.go | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index 796654b97326..0953e6653e42 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -303,14 +303,13 @@ func Test_RangeProof_Syntactic_Verify(t *testing.T) { proof: &RangeProof{}, expectedErr: ErrStartAfterEnd, }, - // TODO remove - // { - // name: "empty", // Also tests start can be > end if end is nil - // start: maybe.Some([]byte{1}), - // end: maybe.Nothing[[]byte](), - // proof: &RangeProof{}, - // expectedErr: ErrEmptyProof, - // }, + { + name: "empty", + start: maybe.Some([]byte{1}), + end: maybe.Nothing[[]byte](), + proof: &RangeProof{}, + expectedErr: ErrEmptyProof, + }, { name: "unexpected end proof", start: maybe.Some([]byte{1}), @@ -321,16 +320,6 @@ func Test_RangeProof_Syntactic_Verify(t *testing.T) { }, expectedErr: ErrUnexpectedEndProof, }, - // TODO remove - // { - // name: "should just be root", - // start: maybe.Nothing[[]byte](), - // end: maybe.Nothing[[]byte](), - // proof: &RangeProof{ - // EndProof: []ProofNode{{}, {}}, - // }, - // expectedErr: ErrShouldJustBeRoot, - // }, { name: "no end proof; has end bound", start: maybe.Some([]byte{1}), From e8b3a9b523e71bb8cc4b746ae6808cd00d2f35e5 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 13:56:44 -0400 Subject: [PATCH 068/131] fix(?) test --- x/merkledb/proof_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index 0953e6653e42..79b2a95fa36d 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -1720,12 +1720,17 @@ func FuzzRangeProofInvariants(f *testing.F) { rootID, err := db.GetMerkleRoot(context.Background()) require.NoError(err) - require.NoError(rangeProof.Verify( + err = rangeProof.Verify( context.Background(), start, end, rootID, - )) + ) + if rootID == ids.Empty { + require.ErrorIs(err, ErrEmptyRootID) + return + } + require.NoError(err) // Make sure the start proof doesn't contain any nodes // that are in the end proof. From f669d3dc71c242ee7464161fce090e86cea94e7a Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 14:30:24 -0400 Subject: [PATCH 069/131] nit --- x/merkledb/proof.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/merkledb/proof.go b/x/merkledb/proof.go index b538937204a5..d98edf92d778 100644 --- a/x/merkledb/proof.go +++ b/x/merkledb/proof.go @@ -860,9 +860,9 @@ func addPathInfo( if existingChild, ok := n.children[index]; ok { compressedKey = existingChild.compressedKey } - childPath := key.AppendExtend(index, compressedKey) - if (shouldInsertLeftChildren && childPath.Less(insertChildrenLessThan.Value())) || - (shouldInsertRightChildren && childPath.Greater(insertChildrenGreaterThan.Value())) { + childKey := key.AppendExtend(index, compressedKey) + if (shouldInsertLeftChildren && childKey.Less(insertChildrenLessThan.Value())) || + (shouldInsertRightChildren && childKey.Greater(insertChildrenGreaterThan.Value())) { // We didn't set the other values on the child entry, but it doesn't matter. // We only need the IDs to be correct so that the calculated hash is correct. n.setChildEntry( From e52172d3632a5182d8ee5adfe50ed51b1fa6ed46 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 20 Oct 2023 15:34:00 -0400 Subject: [PATCH 070/131] add branchfactor arg to range proof verify --- x/merkledb/db_test.go | 1 + x/merkledb/history_test.go | 36 +++++++++++++++++++----------------- x/merkledb/proof.go | 13 +------------ x/merkledb/proof_test.go | 11 +++++++++-- x/sync/client.go | 4 ++++ 5 files changed, 34 insertions(+), 31 deletions(-) diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index 35eb74854679..840ec489d961 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -914,6 +914,7 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest, bf Br start, end, root, + bf, )) case opGenerateChangeProof: root, err := db.GetMerkleRoot(context.Background()) diff --git a/x/merkledb/history_test.go b/x/merkledb/history_test.go index 01b4c25ba5a6..03fa4616e518 100644 --- a/x/merkledb/history_test.go +++ b/x/merkledb/history_test.go @@ -37,7 +37,7 @@ func Test_History_Simple(t *testing.T) { require.NoError(err) require.NotNil(origProof) origRootID := db.root.Value().id - require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) batch = db.NewBatch() require.NoError(batch.Put([]byte("key"), []byte("value0"))) @@ -45,7 +45,7 @@ func Test_History_Simple(t *testing.T) { newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) - require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) batch = db.NewBatch() require.NoError(batch.Put([]byte("key1"), []byte("value1"))) @@ -54,7 +54,7 @@ func Test_History_Simple(t *testing.T) { newProof, err = db.GetRangeProofAtRoot(context.Background(), origRootID, maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) - require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) batch = db.NewBatch() require.NoError(batch.Put([]byte("k"), []byte("v"))) @@ -62,7 +62,7 @@ func Test_History_Simple(t *testing.T) { newProof, err = db.GetRangeProofAtRoot(context.Background(), origRootID, maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) - require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) batch = db.NewBatch() require.NoError(batch.Delete([]byte("k"))) @@ -78,7 +78,7 @@ func Test_History_Simple(t *testing.T) { newProof, err = db.GetRangeProofAtRoot(context.Background(), origRootID, maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) - require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) } func Test_History_Large(t *testing.T) { @@ -141,7 +141,7 @@ func Test_History_Large(t *testing.T) { require.NoError(err) require.NotNil(proof) - require.NoError(proof.Verify(context.Background(), maybe.Nothing[[]byte](), maybe.Nothing[[]byte](), roots[i])) + require.NoError(proof.Verify(context.Background(), maybe.Nothing[[]byte](), maybe.Nothing[[]byte](), roots[i], BranchFactor16)) } } } @@ -240,6 +240,7 @@ func Test_History_Trigger_History_Queue_Looping(t *testing.T) { maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, + config.BranchFactor, )) // write a new value into the db, now there should be 2 roots in the history @@ -256,6 +257,7 @@ func Test_History_Trigger_History_Queue_Looping(t *testing.T) { maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, + config.BranchFactor, )) // trigger a new root to be added to the history, which should cause rollover since there can only be 2 @@ -337,7 +339,7 @@ func Test_History_RepeatedRoot(t *testing.T) { require.NoError(err) require.NotNil(origProof) origRootID := db.root.Value().id - require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) batch = db.NewBatch() require.NoError(batch.Put([]byte("key1"), []byte("other"))) @@ -347,7 +349,7 @@ func Test_History_RepeatedRoot(t *testing.T) { newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) - require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) // revert state to be the same as in orig proof batch = db.NewBatch() @@ -359,7 +361,7 @@ func Test_History_RepeatedRoot(t *testing.T) { newProof, err = db.GetRangeProofAtRoot(context.Background(), origRootID, maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) - require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) } func Test_History_ExcessDeletes(t *testing.T) { @@ -379,7 +381,7 @@ func Test_History_ExcessDeletes(t *testing.T) { require.NoError(err) require.NotNil(origProof) origRootID := db.root.Value().id - require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) batch = db.NewBatch() require.NoError(batch.Delete([]byte("key1"))) @@ -391,7 +393,7 @@ func Test_History_ExcessDeletes(t *testing.T) { newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) - require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) } func Test_History_DontIncludeAllNodes(t *testing.T) { @@ -411,7 +413,7 @@ func Test_History_DontIncludeAllNodes(t *testing.T) { require.NoError(err) require.NotNil(origProof) origRootID := db.root.Value().id - require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) batch = db.NewBatch() require.NoError(batch.Put([]byte("z"), []byte("z"))) @@ -419,7 +421,7 @@ func Test_History_DontIncludeAllNodes(t *testing.T) { newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) - require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) } func Test_History_Branching2Nodes(t *testing.T) { @@ -439,7 +441,7 @@ func Test_History_Branching2Nodes(t *testing.T) { require.NoError(err) require.NotNil(origProof) origRootID := db.root.Value().id - require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) batch = db.NewBatch() require.NoError(batch.Put([]byte("k"), []byte("v"))) @@ -447,7 +449,7 @@ func Test_History_Branching2Nodes(t *testing.T) { newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) - require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) } func Test_History_Branching3Nodes(t *testing.T) { @@ -467,7 +469,7 @@ func Test_History_Branching3Nodes(t *testing.T) { require.NoError(err) require.NotNil(origProof) origRootID := db.root.Value().id - require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(origProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) batch = db.NewBatch() require.NoError(batch.Put([]byte("key321"), []byte("value321"))) @@ -475,7 +477,7 @@ func Test_History_Branching3Nodes(t *testing.T) { newProof, err := db.GetRangeProofAtRoot(context.Background(), origRootID, maybe.Some([]byte("k")), maybe.Some([]byte("key3")), 10) require.NoError(err) require.NotNil(newProof) - require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID)) + require.NoError(newProof.Verify(context.Background(), maybe.Some([]byte("k")), maybe.Some([]byte("key3")), origRootID, BranchFactor16)) } func Test_History_MaxLength(t *testing.T) { diff --git a/x/merkledb/proof.go b/x/merkledb/proof.go index d98edf92d778..c2351b812495 100644 --- a/x/merkledb/proof.go +++ b/x/merkledb/proof.go @@ -284,6 +284,7 @@ func (proof *RangeProof) Verify( start maybe.Maybe[[]byte], end maybe.Maybe[[]byte], expectedRootID ids.ID, + branchFactor BranchFactor, ) error { switch { case start.HasValue() && end.HasValue() && bytes.Compare(start.Value(), end.Value()) > 0: @@ -296,18 +297,6 @@ func (proof *RangeProof) Verify( return ErrNoEndProof } - // determine branch factor based on proof paths - var branchFactor BranchFactor - switch { - case len(proof.StartProof) > 0: - branchFactor = proof.StartProof[0].Key.branchFactor - case len(proof.EndProof) > 0: - branchFactor = proof.EndProof[0].Key.branchFactor - default: - // TODO Get branch factor - branchFactor = BranchFactor16 - } - // Make sure the key-value pairs are sorted and in [start, end]. if err := verifyKeyValues(proof.KeyValues, start, end); err != nil { return err diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index 79b2a95fa36d..ea216c3068cc 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -151,6 +151,7 @@ func Test_RangeProof_Extra_Value(t *testing.T) { maybe.Some([]byte{1}), maybe.Some([]byte{5, 5}), db.root.Value().id, + db.valueNodeDB.branchFactor, )) proof.KeyValues = append(proof.KeyValues, KeyValue{Key: []byte{5}, Value: []byte{5}}) @@ -160,6 +161,7 @@ func Test_RangeProof_Extra_Value(t *testing.T) { maybe.Some([]byte{1}), maybe.Some([]byte{5, 5}), db.root.Value().id, + db.valueNodeDB.branchFactor, ) require.ErrorIs(err, ErrInvalidProof) } @@ -221,7 +223,7 @@ func Test_RangeProof_Verify_Bad_Data(t *testing.T) { tt.malform(proof) - err = proof.Verify(context.Background(), maybe.Some([]byte{2}), maybe.Some([]byte{3, 0}), db.getMerkleRoot()) + err = proof.Verify(context.Background(), maybe.Some([]byte{2}), maybe.Some([]byte{3, 0}), db.getMerkleRoot(), db.valueNodeDB.branchFactor) require.ErrorIs(err, tt.expectedErr) }) } @@ -487,7 +489,7 @@ func Test_RangeProof_Syntactic_Verify(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - err := tt.proof.Verify(context.Background(), tt.start, tt.end, ids.Empty) + err := tt.proof.Verify(context.Background(), tt.start, tt.end, ids.Empty, BranchFactor16) require.ErrorIs(t, err, tt.expectedErr) }) } @@ -526,6 +528,7 @@ func Test_RangeProof(t *testing.T) { maybe.Some([]byte{1}), maybe.Some([]byte{3, 5}), db.root.Value().id, + db.valueNodeDB.branchFactor, )) } @@ -579,6 +582,7 @@ func Test_RangeProof_NilStart(t *testing.T) { maybe.Nothing[[]byte](), maybe.Some([]byte("key35")), db.root.Value().id, + db.valueNodeDB.branchFactor, )) } @@ -618,6 +622,7 @@ func Test_RangeProof_NilEnd(t *testing.T) { maybe.Some([]byte{1}), maybe.Nothing[[]byte](), db.root.Value().id, + db.valueNodeDB.branchFactor, )) } @@ -660,6 +665,7 @@ func Test_RangeProof_EmptyValues(t *testing.T) { maybe.Some([]byte("key1")), maybe.Some([]byte("key2")), db.root.Value().id, + db.valueNodeDB.branchFactor, )) } @@ -1725,6 +1731,7 @@ func FuzzRangeProofInvariants(f *testing.F) { start, end, rootID, + BranchFactor16, ) if rootID == ids.Empty { require.ErrorIs(err, ErrEmptyRootID) diff --git a/x/sync/client.go b/x/sync/client.go index 095f515d41fb..61dbccb343f4 100644 --- a/x/sync/client.go +++ b/x/sync/client.go @@ -171,6 +171,7 @@ func (c *client) GetChangeProof( startKey, endKey, req.EndRootHash, + c.branchFactor, ) if err != nil { return nil, err @@ -208,6 +209,7 @@ func verifyRangeProof( start maybe.Maybe[[]byte], end maybe.Maybe[[]byte], rootBytes []byte, + branchFactor merkledb.BranchFactor, ) error { root, err := ids.ToID(rootBytes) if err != nil { @@ -227,6 +229,7 @@ func verifyRangeProof( start, end, root, + branchFactor, ); err != nil { return fmt.Errorf("%w due to %w", errInvalidRangeProof, err) } @@ -268,6 +271,7 @@ func (c *client) GetRangeProof( startKey, endKey, req.RootHash, + c.branchFactor, ); err != nil { return nil, err } From 96e6cecabc9be7086254f5aeb42de304f1857a99 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Mon, 23 Oct 2023 10:59:32 -0400 Subject: [PATCH 071/131] refactor --- x/merkledb/codec.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/x/merkledb/codec.go b/x/merkledb/codec.go index 425d3774675a..3d23e2ab2630 100644 --- a/x/merkledb/codec.go +++ b/x/merkledb/codec.go @@ -89,9 +89,13 @@ type codecImpl struct { varIntPool sync.Pool } +func estimateDBNodeSize(numChildren int) int { + return estimatedValueLen + minVarIntLen + estimatedNodeChildLen*numChildren +} + func (c *codecImpl) encodeDBNode(n *dbNode, branchFactor BranchFactor) []byte { // Estimate size of [n] to prevent memory allocations - estimatedLen := estimatedValueLen + minVarIntLen + estimatedNodeChildLen*len(n.children) + estimatedLen := estimateDBNodeSize(len(n.children)) buf := bytes.NewBuffer(make([]byte, 0, estimatedLen)) return c.encodeDBNodeToBuffer(buf, n, branchFactor) } @@ -138,8 +142,8 @@ func (c *codecImpl) encodeHashValues(hv *hashValues) []byte { func (c *codecImpl) encodeKeyAndNode(key Key, n *dbNode, factor BranchFactor) []byte { var ( numChildren = len(n.children) - // Estimate size of [n] to prevent memory allocations - estimatedLen = binary.MaxVarintLen64 + len(key.Bytes()) + estimatedValueLen + minVarIntLen + estimatedNodeChildLen*numChildren + // Estimate size to prevent memory allocations + estimatedLen = binary.MaxVarintLen64 + len(key.Bytes()) + estimateDBNodeSize(numChildren) buf = bytes.NewBuffer(make([]byte, 0, estimatedLen)) ) From 43318e41507204afdc081eb407841619fd5f1873 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Mon, 23 Oct 2023 11:08:28 -0400 Subject: [PATCH 072/131] test cleanup --- x/merkledb/codec_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index d70c281f0315..55f0016a162d 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -300,9 +300,7 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { val = maybe.Some(value) } - if numChildren > int(branchFactor) { - numChildren = int(branchFactor) - } + numChildren %= int(branchFactor) children := map[byte]child{} for i := 0; i < numChildren; i++ { @@ -311,7 +309,7 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { children[byte(i)] = child{ compressedKey: ToKey(compressedKeyBytes, branchFactor), id: ids.GenerateTestID(), - hasValue: true, + hasValue: val.HasValue(), } } From 992f628b767487f82aeaa18b0217b7f1a3b0c906 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Mon, 23 Oct 2023 14:24:06 -0400 Subject: [PATCH 073/131] ErrEmptyRootID --> ErrEmptyProof --- x/merkledb/db.go | 17 ++++++++--------- x/merkledb/db_test.go | 8 ++++---- x/merkledb/proof_test.go | 2 +- x/merkledb/trie.go | 3 ++- x/merkledb/trieview.go | 9 ++++++++- x/sync/client.go | 7 ++----- x/sync/network_server.go | 4 ++++ 7 files changed, 29 insertions(+), 21 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 42ae4d5d7751..a608a407fc0f 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -43,8 +43,6 @@ const ( var ( _ MerkleDB = (*merkleDB)(nil) - ErrEmptyRootID = errors.New("rootID is empty") - codec = newCodec() metadataPrefix = []byte{0} @@ -65,7 +63,7 @@ type ChangeProofer interface { // Returns at most [maxLength] key/value pairs. // Returns [ErrInsufficientHistory] if this node has insufficient history // to generate the proof. - // Returns ErrEmptyRootID if [endRootID] is ids.Empty. + // Returns ErrEmptyProof if [endRootID] is ids.Empty. // Note that [endRootID] == ids.Empty means the trie is empty // (i.e. we don't need a change proof.) GetChangeProof( @@ -104,7 +102,7 @@ type RangeProofer interface { // [start, end] when the root of the trie was [rootID]. // If [start] is Nothing, there's no lower bound on the range. // If [end] is Nothing, there's no upper bound on the range. - // Returns ErrEmptyRootID if [rootID] is ids.Empty. + // Returns ErrEmptyProof if [rootID] is ids.Empty. // Note that [rootID] == ids.Empty means the trie is empty // (i.e. we don't need a range proof.) GetRangeProofAtRoot( @@ -657,7 +655,7 @@ func (db *merkleDB) getRangeProofAtRoot( case maxLength <= 0: return nil, fmt.Errorf("%w but was %d", ErrInvalidMaxLength, maxLength) case rootID == ids.Empty: - return nil, ErrEmptyRootID + return nil, ErrEmptyProof } historicalView, err := db.getHistoricalViewForRange(rootID, start, end) @@ -681,7 +679,7 @@ func (db *merkleDB) GetChangeProof( case startRootID == endRootID: return nil, errSameRoot case endRootID == ids.Empty: - return nil, ErrEmptyRootID + return nil, ErrEmptyProof } db.commitLock.RLock() @@ -1170,6 +1168,8 @@ func (db *merkleDB) invalidateChildrenExcept(exception *trieView) { } } +// If the root is on disk, set [db.root] to it. +// Otherwise leave [db.root] as Nothing. func (db *merkleDB) initializeRootIfNeeded() error { rootBytes, err := db.baseDB.Get(rootDBKey) if err != nil { @@ -1276,12 +1276,11 @@ func (db *merkleDB) getNode(key Key, hasValue bool) (*node, error) { switch { case db.closed: return nil, database.ErrClosed - case db.root.HasValue() && key == db.root.Value().key: - return db.root.Value(), nil case hasValue: return db.valueNodeDB.Get(key) + default: + return db.intermediateNodeDB.Get(key) } - return db.intermediateNodeDB.Get(key) } func (db *merkleDB) getRoot() maybe.Maybe[*node] { diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index 840ec489d961..cdfd6563d13a 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -903,7 +903,7 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest, bf Br rangeProof, err := db.GetRangeProofAtRoot(context.Background(), root, start, end, maxProofLen) if root == ids.Empty { - require.ErrorIs(err, ErrEmptyRootID) + require.ErrorIs(err, ErrEmptyProof) continue } require.NoError(err) @@ -940,7 +940,7 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest, bf Br continue } if root == ids.Empty { - require.ErrorIs(err, ErrEmptyRootID) + require.ErrorIs(err, ErrEmptyProof) continue } require.NoError(err) @@ -1218,7 +1218,7 @@ func TestGetRangeProofAtRootEmptyRootID(t *testing.T) { maybe.Nothing[[]byte](), 10, ) - require.ErrorIs(err, ErrEmptyRootID) + require.ErrorIs(err, ErrEmptyProof) } func TestGetChangeProofEmptyRootID(t *testing.T) { @@ -1239,5 +1239,5 @@ func TestGetChangeProofEmptyRootID(t *testing.T) { maybe.Nothing[[]byte](), 10, ) - require.ErrorIs(err, ErrEmptyRootID) + require.ErrorIs(err, ErrEmptyProof) } diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index ea216c3068cc..e538e96c0279 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -1734,7 +1734,7 @@ func FuzzRangeProofInvariants(f *testing.F) { BranchFactor16, ) if rootID == ids.Empty { - require.ErrorIs(err, ErrEmptyRootID) + require.ErrorIs(err, ErrEmptyProof) return } require.NoError(err) diff --git a/x/merkledb/trie.go b/x/merkledb/trie.go index d72bd51bfb56..d9105903d798 100644 --- a/x/merkledb/trie.go +++ b/x/merkledb/trie.go @@ -20,7 +20,7 @@ type MerkleRootGetter interface { type ProofGetter interface { // GetProof generates a proof of the value associated with a particular key, // or a proof of its absence from the trie - // The returned proof's [Path] is non-empty iff the trie is non-empty. + // Returns ErrEmptyTrie if the trie is empty. GetProof(ctx context.Context, keyBytes []byte) (*Proof, error) } @@ -53,6 +53,7 @@ type ReadOnlyTrie interface { // keys in range [start, end]. // If [start] is Nothing, there's no lower bound on the range. // If [end] is Nothing, there's no upper bound on the range. + // Returns ErrEmptyProof if the trie is empty. GetRangeProof(ctx context.Context, start maybe.Maybe[[]byte], end maybe.Maybe[[]byte], maxLength int) (*RangeProof, error) database.Iteratee diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 1e8b7fa36173..c36cdb92ff65 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -343,11 +343,14 @@ func (t *trieView) GetProof(ctx context.Context, key []byte) (*Proof, error) { } // Returns a proof that [key] is in or not in [t]. -// The returned proof's [Path] is non-empty iff [t] is non-empty. func (t *trieView) getProof(ctx context.Context, key []byte) (*Proof, error) { _, span := t.db.infoTracer.Start(ctx, "MerkleDB.trieview.getProof") defer span.End() + if t.root.IsNothing() { + return nil, ErrEmptyProof + } + proof := &Proof{ Key: t.db.toKey(key), } @@ -432,6 +435,10 @@ func (t *trieView) GetRangeProof( return nil, err } + if t.root.IsNothing() { + return nil, ErrEmptyProof + } + var result RangeProof result.KeyValues = make([]KeyValue, 0, initKeyValuesSize) diff --git a/x/sync/client.go b/x/sync/client.go index 61dbccb343f4..c0ae8d36cde6 100644 --- a/x/sync/client.go +++ b/x/sync/client.go @@ -256,9 +256,6 @@ func (c *client) GetRangeProof( return nil, err } - startKey := maybeBytesToMaybe(req.StartKey) - endKey := maybeBytesToMaybe(req.EndKey) - var rangeProof merkledb.RangeProof if err := rangeProof.UnmarshalProto(&rangeProofProto, c.branchFactor); err != nil { return nil, err @@ -268,8 +265,8 @@ func (c *client) GetRangeProof( ctx, &rangeProof, int(req.KeyLimit), - startKey, - endKey, + maybeBytesToMaybe(req.StartKey), + maybeBytesToMaybe(req.EndKey), req.RootHash, c.branchFactor, ); err != nil { diff --git a/x/sync/network_server.go b/x/sync/network_server.go index 6f21702ce397..765cab85c817 100644 --- a/x/sync/network_server.go +++ b/x/sync/network_server.go @@ -391,6 +391,8 @@ func validateChangeProofRequest(req *pb.SyncGetChangeProofRequest) error { return errInvalidStartRootHash case len(req.EndRootHash) != hashing.HashLen: return errInvalidEndRootHash + case bytes.Equal(req.EndRootHash, ids.Empty[:]): + return merkledb.ErrEmptyProof case req.StartKey != nil && req.StartKey.IsNothing && len(req.StartKey.Value) > 0: return errInvalidStartKey case req.EndKey != nil && req.EndKey.IsNothing && len(req.EndKey.Value) > 0: @@ -412,6 +414,8 @@ func validateRangeProofRequest(req *pb.SyncGetRangeProofRequest) error { return errInvalidKeyLimit case len(req.RootHash) != ids.IDLen: return errInvalidRootHash + case bytes.Equal(req.RootHash, ids.Empty[:]): + return merkledb.ErrEmptyProof case req.StartKey != nil && req.StartKey.IsNothing && len(req.StartKey.Value) > 0: return errInvalidStartKey case req.EndKey != nil && req.EndKey.IsNothing && len(req.EndKey.Value) > 0: From 11ee2674e6e1d1483b963725a86f24ff692002fd Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 09:42:41 -0400 Subject: [PATCH 074/131] move ClearRanger interface from database to merkledb package --- database/helpers.go | 8 -------- x/merkledb/db.go | 9 ++++++++- x/sync/db.go | 3 +-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/database/helpers.go b/database/helpers.go index c706b326e7c0..d4261920dcdf 100644 --- a/database/helpers.go +++ b/database/helpers.go @@ -10,7 +10,6 @@ import ( "time" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/utils/maybe" ) const ( @@ -189,13 +188,6 @@ func AtomicClearPrefix(readerDB Iteratee, deleterDB KeyValueDeleter, prefix []by return iterator.Error() } -type ClearRanger interface { - // Deletes all key-value pairs with keys in the range [start, end]. - // If [start] is Nothing, there's no lower bound on the range. - // If [end] is Nothing, there's no upper bound on the range. - ClearRange(start, end maybe.Maybe[[]byte]) error -} - // Remove all key-value pairs from [db]. // Writes each batch when it reaches [writeSize]. func Clear(db Database, writeSize int) error { diff --git a/x/merkledb/db.go b/x/merkledb/db.go index a608a407fc0f..c2d73b287a9d 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -119,6 +119,13 @@ type RangeProofer interface { CommitRangeProof(ctx context.Context, start, end maybe.Maybe[[]byte], proof *RangeProof) error } +type ClearRanger interface { + // Deletes all key-value pairs with keys in the range [start, end]. + // If [start] is Nothing, there's no lower bound on the range. + // If [end] is Nothing, there's no upper bound on the range. + ClearRange(start, end maybe.Maybe[[]byte]) error +} + type Prefetcher interface { // PrefetchPath attempts to load all trie nodes on the path of [key] // into the cache. @@ -134,7 +141,7 @@ type Prefetcher interface { type MerkleDB interface { database.Database - database.ClearRanger + ClearRanger Trie MerkleRootGetter ProofGetter diff --git a/x/sync/db.go b/x/sync/db.go index bda1130c8f33..c8641b310c7b 100644 --- a/x/sync/db.go +++ b/x/sync/db.go @@ -4,12 +4,11 @@ package sync import ( - "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/x/merkledb" ) type DB interface { - database.ClearRanger + merkledb.ClearRanger merkledb.MerkleRootGetter merkledb.ProofGetter merkledb.ChangeProofer From 19f9690db27c19a52d96285dea2d6acd238238dc Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 09:55:53 -0400 Subject: [PATCH 075/131] cleanup --- x/merkledb/proof.go | 3 +-- x/merkledb/proof_test.go | 7 +++++++ x/merkledb/trie.go | 2 +- x/merkledb/trieview.go | 4 ---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/x/merkledb/proof.go b/x/merkledb/proof.go index c2351b812495..22e6f1289554 100644 --- a/x/merkledb/proof.go +++ b/x/merkledb/proof.go @@ -126,8 +126,7 @@ func (node *ProofNode) UnmarshalProto(pbNode *pb.ProofNode, bf BranchFactor) err type Proof struct { // Nodes in the proof path from root --> target key // (or node that would be where key is if it doesn't exist). - // Empty iff the trie is empty. - // Otherwise contains at least one node (the root). + // Always contains at least the root. Path []ProofNode // This is a proof that [key] exists/doesn't exist. Key Key diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index e538e96c0279..751936ea60c2 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -59,6 +59,13 @@ func Test_Proof_Verify_Bad_Data(t *testing.T) { malform: func(proof *Proof) {}, expectedErr: nil, }, + { + name: "empty", + malform: func(proof *Proof) { + proof.Path = nil + }, + expectedErr: ErrEmptyProof, + }, { name: "odd length key with value", malform: func(proof *Proof) { diff --git a/x/merkledb/trie.go b/x/merkledb/trie.go index d9105903d798..1e6870df27cb 100644 --- a/x/merkledb/trie.go +++ b/x/merkledb/trie.go @@ -20,7 +20,7 @@ type MerkleRootGetter interface { type ProofGetter interface { // GetProof generates a proof of the value associated with a particular key, // or a proof of its absence from the trie - // Returns ErrEmptyTrie if the trie is empty. + // Returns ErrEmptyProof if the trie is empty. GetProof(ctx context.Context, keyBytes []byte) (*Proof, error) } diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index c36cdb92ff65..33eb18ccf7f4 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -355,10 +355,6 @@ func (t *trieView) getProof(ctx context.Context, key []byte) (*Proof, error) { Key: t.db.toKey(key), } - if t.root.IsNothing() { - return proof, nil - } - proofPath, err := t.getPathTo(proof.Key) if err != nil { return nil, err From ae6bd6415bc9fe86cba6c5918c9092306176b4de Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 10:09:02 -0400 Subject: [PATCH 076/131] nit --- x/merkledb/trieview.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 33eb18ccf7f4..dfb6ceac6e25 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -37,7 +37,7 @@ var ( ) ErrGetPathToFailure = errors.New("GetPathTo failed to return the closest node") ErrStartAfterEnd = errors.New("start key > end key") - ErrNoValidRoot = errors.New("a valid root was not provided to the trieView constructor") + ErrNoChanges = errors.New("no changes provided") ErrParentNotDatabase = errors.New("parent trie is not database") ErrNodesAlreadyCalculated = errors.New("cannot modify the trie after the node changes have been calculated") ) @@ -184,13 +184,14 @@ func newTrieView( return newView, nil } -// Creates a view of the db at a historical root using the provided changes +// Creates a view of the db at a historical root using the provided [changes]. +// Returns ErrNoChanges if [changes] is empty. func newHistoricalTrieView( db *merkleDB, changes *changeSummary, ) (*trieView, error) { if changes == nil { - return nil, ErrNoValidRoot + return nil, ErrNoChanges } root := maybe.Nothing[*node]() From 52176b76f90b7d49e6a3fa0b42e47aa7025e5628 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 10:32:31 -0400 Subject: [PATCH 077/131] add tests --- x/merkledb/proof_test.go | 9 +++++++++ x/sync/client_test.go | 14 ++++++++++++++ x/sync/g_db/db_client.go | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index 751936ea60c2..b49e285a08ef 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -186,6 +186,15 @@ func Test_RangeProof_Verify_Bad_Data(t *testing.T) { malform: func(proof *RangeProof) {}, expectedErr: nil, }, + { + name: "empty", + malform: func(proof *RangeProof) { + proof.KeyValues = nil + proof.StartProof = nil + proof.EndProof = nil + }, + expectedErr: ErrEmptyProof, + }, { name: "StartProof: last proof node has missing value", malform: func(proof *RangeProof) { diff --git a/x/sync/client_test.go b/x/sync/client_test.go index d9d78a3fa2d5..520641ec1e8f 100644 --- a/x/sync/client_test.go +++ b/x/sync/client_test.go @@ -331,6 +331,20 @@ func TestGetRangeProof(t *testing.T) { }, expectedErr: merkledb.ErrNoEndProof, }, + "empty proof": { + db: largeTrieDB, + request: &pb.SyncGetRangeProofRequest{ + RootHash: largeTrieRoot[:], + KeyLimit: defaultRequestKeyLimit, + BytesLimit: defaultRequestByteSizeLimit, + }, + modifyResponse: func(response *merkledb.RangeProof) { + response.StartProof = nil + response.EndProof = nil + response.KeyValues = nil + }, + expectedErr: merkledb.ErrEmptyProof, + }, } for name, test := range tests { diff --git a/x/sync/g_db/db_client.go b/x/sync/g_db/db_client.go index 4124fbcd36e4..f87497f3565d 100644 --- a/x/sync/g_db/db_client.go +++ b/x/sync/g_db/db_client.go @@ -135,6 +135,10 @@ func (c *DBClient) GetRangeProofAtRoot( endKey maybe.Maybe[[]byte], keyLimit int, ) (*merkledb.RangeProof, error) { + if rootID == ids.Empty { + return nil, merkledb.ErrEmptyProof + } + resp, err := c.client.GetRangeProof(ctx, &pb.GetRangeProofRequest{ RootHash: rootID[:], StartKey: &pb.MaybeBytes{ From 530b6a5570dc354a1116fca9948fe399a2725a5a Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 10:34:39 -0400 Subject: [PATCH 078/131] nit --- x/merkledb/trieview.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index dfb6ceac6e25..db872e3fd516 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -713,11 +713,7 @@ func (t *trieView) remove(key Key) error { parent := nodePath[len(nodePath)-2] // merge this node and its descendants into a single node if possible - if err = t.compressNodePath(parent, nodeToDelete); err != nil { - return err - } - - return nil + return t.compressNodePath(parent, nodeToDelete) } // Merges together nodes in the inclusive descendnnts of [n] that From 6a676c23f19e9dd611d261e35478aa64c4ad8df9 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 10:35:31 -0400 Subject: [PATCH 079/131] comment --- x/merkledb/trieview.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index db872e3fd516..2a9d14839f7c 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -710,6 +710,7 @@ func (t *trieView) remove(key Key) error { } // Note len(nodePath) >= 2 since [nodeToDelete.key] != [t.root.key]. + // i.e. [nodePath] has the root and [nodeToDelete] at a minimum. parent := nodePath[len(nodePath)-2] // merge this node and its descendants into a single node if possible From e84d1b24e092e2eac2ddbd02907ea701c4cdcd9b Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 10:35:49 -0400 Subject: [PATCH 080/131] typo --- x/merkledb/trieview.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 2a9d14839f7c..4a187f96791f 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -717,7 +717,7 @@ func (t *trieView) remove(key Key) error { return t.compressNodePath(parent, nodeToDelete) } -// Merges together nodes in the inclusive descendnnts of [n] that +// Merges together nodes in the inclusive descendants of [n] that // have no value and a single child into one node with a compressed // path until a node that doesn't meet those criteria is reached. // [parent] is [n]'s parent. If [parent] is nil, [n] is the root From bece10caafd0d38f6264001c137e9b6a0c82feaf Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 10:41:38 -0400 Subject: [PATCH 081/131] comment --- x/merkledb/trieview.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 4a187f96791f..9c4fedfbbd0c 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -811,6 +811,7 @@ func (t *trieView) deleteEmptyNodes(nodePath []*node) error { // The first node is the root, and the last node is either the node with the // given [key], if it's in the trie, or the node with the largest prefix of // the [key] if it isn't in the trie. +// Returns nil if there's no node with a prefix of [key]. func (t *trieView) getPathTo(key Key) ([]*node, error) { if t.root.IsNothing() { return nil, nil From d730b53e6673815fa66b5699f71ffae72b4174ee Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 10:54:22 -0400 Subject: [PATCH 082/131] add test --- x/sync/network_server_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/x/sync/network_server_test.go b/x/sync/network_server_test.go index b6bc1d980146..e5f00221ad9c 100644 --- a/x/sync/network_server_test.go +++ b/x/sync/network_server_test.go @@ -272,6 +272,16 @@ func Test_Server_GetChangeProof(t *testing.T) { expectedMaxResponseBytes: defaultRequestByteSizeLimit, proofNil: true, }, + "empt proof": { + request: &pb.SyncGetChangeProofRequest{ + StartRootHash: fakeRootID[:], + EndRootHash: ids.Empty[:], + KeyLimit: defaultRequestKeyLimit, + BytesLimit: defaultRequestByteSizeLimit, + }, + expectedMaxResponseBytes: defaultRequestByteSizeLimit, + proofNil: true, + }, } for name, test := range tests { From c9efc4ab1c0a7928abc329d6f9c918eb261a2ecf Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 10:55:04 -0400 Subject: [PATCH 083/131] add test --- x/sync/network_server_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/x/sync/network_server_test.go b/x/sync/network_server_test.go index e5f00221ad9c..4b4228eaf6d1 100644 --- a/x/sync/network_server_test.go +++ b/x/sync/network_server_test.go @@ -93,6 +93,14 @@ func Test_Server_GetRangeProof(t *testing.T) { }, expectedMaxResponseBytes: defaultRequestByteSizeLimit, }, + "empty proof": { + request: &pb.SyncGetRangeProofRequest{ + RootHash: ids.Empty[:], + KeyLimit: defaultRequestKeyLimit, + BytesLimit: defaultRequestByteSizeLimit, + }, + proofNil: true, + }, } for name, test := range tests { From bb70bca38ec2707340caad31d13afd8ec5cca80d Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 11:06:40 -0400 Subject: [PATCH 084/131] appease linter --- x/sync/db.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x/sync/db.go b/x/sync/db.go index c8641b310c7b..eca2b0a13c78 100644 --- a/x/sync/db.go +++ b/x/sync/db.go @@ -3,9 +3,7 @@ package sync -import ( - "github.com/ava-labs/avalanchego/x/merkledb" -) +import "github.com/ava-labs/avalanchego/x/merkledb" type DB interface { merkledb.ClearRanger From 9fc9045389b32162a9eb883791410b544ed40c3b Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 12:10:03 -0400 Subject: [PATCH 085/131] WIP don't encode node twice --- x/merkledb/codec.go | 58 +++++++++++++++++----------------------- x/merkledb/codec_test.go | 16 +++++------ x/merkledb/db.go | 19 +++++++------ 3 files changed, 41 insertions(+), 52 deletions(-) diff --git a/x/merkledb/codec.go b/x/merkledb/codec.go index 3d23e2ab2630..c9aa9030d49e 100644 --- a/x/merkledb/codec.go +++ b/x/merkledb/codec.go @@ -62,13 +62,13 @@ type encoder interface { encodeDBNode(n *dbNode, factor BranchFactor) []byte // Assumes [hv] is non-nil. encodeHashValues(hv *hashValues) []byte - encodeKeyAndNode(key Key, n *dbNode, factor BranchFactor) []byte + encodeKeyAndHasValue(key Key, hasValue bool, factor BranchFactor) []byte } type decoder interface { // Assumes [n] is non-nil. decodeDBNode(bytes []byte, n *dbNode, factor BranchFactor) error - decodeKeyAndNode(bytes []byte, key *Key, n *dbNode, factor BranchFactor) error + decodeKeyAndHasValue(bytes []byte, key *Key, hasValue *bool, factor BranchFactor) error } func newCodec() encoderDecoder { @@ -89,31 +89,26 @@ type codecImpl struct { varIntPool sync.Pool } -func estimateDBNodeSize(numChildren int) int { - return estimatedValueLen + minVarIntLen + estimatedNodeChildLen*numChildren -} - func (c *codecImpl) encodeDBNode(n *dbNode, branchFactor BranchFactor) []byte { - // Estimate size of [n] to prevent memory allocations - estimatedLen := estimateDBNodeSize(len(n.children)) - buf := bytes.NewBuffer(make([]byte, 0, estimatedLen)) - return c.encodeDBNodeToBuffer(buf, n, branchFactor) -} - -func (c *codecImpl) encodeDBNodeToBuffer(dst *bytes.Buffer, n *dbNode, branchFactor BranchFactor) []byte { - c.encodeMaybeByteSlice(dst, n.value) - c.encodeUint(dst, uint64(len(n.children))) + var ( + numChildren = len(n.children) + // Estimate size of [n] to prevent memory allocations + estimatedLen = estimatedValueLen + minVarIntLen + estimatedNodeChildLen*numChildren + buf = bytes.NewBuffer(make([]byte, 0, estimatedLen)) + ) + c.encodeMaybeByteSlice(buf, n.value) + c.encodeUint(buf, uint64(numChildren)) // Note we insert children in order of increasing index // for determinism. for index := 0; BranchFactor(index) < branchFactor; index++ { if entry, ok := n.children[byte(index)]; ok { - c.encodeUint(dst, uint64(index)) - c.encodeKey(dst, entry.compressedKey) - _, _ = dst.Write(entry.id[:]) - c.encodeBool(dst, entry.hasValue) + c.encodeUint(buf, uint64(index)) + c.encodeKey(buf, entry.compressedKey) + _, _ = buf.Write(entry.id[:]) + c.encodeBool(buf, entry.hasValue) } } - return dst.Bytes() + return buf.Bytes() } func (c *codecImpl) encodeHashValues(hv *hashValues) []byte { @@ -139,24 +134,24 @@ func (c *codecImpl) encodeHashValues(hv *hashValues) []byte { return buf.Bytes() } -func (c *codecImpl) encodeKeyAndNode(key Key, n *dbNode, factor BranchFactor) []byte { +func (c *codecImpl) encodeKeyAndHasValue(key Key, hasValue bool, factor BranchFactor) []byte { var ( - numChildren = len(n.children) - // Estimate size to prevent memory allocations - estimatedLen = binary.MaxVarintLen64 + len(key.Bytes()) + estimateDBNodeSize(numChildren) + estimatedLen = binary.MaxVarintLen64 + len(key.Bytes()) + boolLen buf = bytes.NewBuffer(make([]byte, 0, estimatedLen)) ) c.encodeKey(buf, key) - c.encodeDBNodeToBuffer(buf, n, factor) + c.encodeBool(buf, hasValue) return buf.Bytes() } -func (c *codecImpl) decodeDBNodeFromReader(src *bytes.Reader, n *dbNode, branchFactor BranchFactor) error { - if minDBNodeLen > src.Len() { +func (c *codecImpl) decodeDBNode(b []byte, n *dbNode, branchFactor BranchFactor) error { + if minDBNodeLen > len(b) { return io.ErrUnexpectedEOF } + src := bytes.NewReader(b) + value, err := c.decodeMaybeByteSlice(src) if err != nil { return err @@ -209,11 +204,7 @@ func (c *codecImpl) decodeDBNodeFromReader(src *bytes.Reader, n *dbNode, branchF return nil } -func (c *codecImpl) decodeDBNode(b []byte, n *dbNode, branchFactor BranchFactor) error { - return c.decodeDBNodeFromReader(bytes.NewReader(b), n, branchFactor) -} - -func (c *codecImpl) decodeKeyAndNode(b []byte, key *Key, n *dbNode, branchFactor BranchFactor) error { +func (c *codecImpl) decodeKeyAndHasValue(b []byte, key *Key, hasValue *bool, branchFactor BranchFactor) error { if minKeyLen+minDBNodeLen > len(b) { return io.ErrUnexpectedEOF } @@ -226,7 +217,8 @@ func (c *codecImpl) decodeKeyAndNode(b []byte, key *Key, n *dbNode, branchFactor return err } - return c.decodeDBNodeFromReader(src, n, branchFactor) + *hasValue, err = c.decodeBool(src) + return err } func (*codecImpl) encodeBool(dst *bytes.Buffer, value bool) { diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index 55f0016a162d..b9c02479de40 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -313,18 +313,16 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { } } - expectedNode := &dbNode{ - value: val, - children: children, - } - b := codec.encodeKeyAndNode(key, expectedNode, branchFactor) + hasValue := rand.Intn(2) == 1 // #nosec G404 + b := codec.encodeKeyAndHasValue(key, hasValue, branchFactor) var ( - gotNode dbNode - gotKey Key + gotKey Key + gotHasValue bool ) - require.NoError(codec.decodeKeyAndNode(b, &gotKey, &gotNode, branchFactor)) - require.Equal(expectedNode, &gotNode) + err := codec.decodeKeyAndHasValue(b, &gotKey, &gotHasValue, branchFactor) + require.NoError(err) require.Equal(key, gotKey) + require.Equal(hasValue, val.HasValue()) } }, ) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index c2d73b287a9d..f53719e78f57 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -992,9 +992,9 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e } db.root = maybe.Some(changes.rootChange.after) - rootKeyAndNodeBytes := codec.encodeKeyAndNode( + rootKeyAndNodeBytes := codec.encodeKeyAndHasValue( changes.rootChange.after.key, - &changes.rootChange.after.dbNode, + changes.rootChange.after.value.HasValue(), db.valueNodeDB.branchFactor, ) return db.baseDB.Put(rootDBKey, rootKeyAndNodeBytes) @@ -1189,22 +1189,21 @@ func (db *merkleDB) initializeRootIfNeeded() error { // Root is on disk. var ( - rootDBNode dbNode - rootKey Key + rootKey Key + rootHasValue bool ) - if err := codec.decodeKeyAndNode( + if err := codec.decodeKeyAndHasValue( rootBytes, &rootKey, - &rootDBNode, + &rootHasValue, db.valueNodeDB.branchFactor, ); err != nil { return err } - root := &node{ - dbNode: rootDBNode, - key: rootKey, + root, err := db.getEditableNode(rootKey, rootHasValue) + if err != nil { + return err } - root.setValueDigest() root.calculateID(db.metrics) db.root = maybe.Some(root) return nil From 7f142f8239c4bd38a4ea387c2a80aeaf70d3b175 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 12:54:27 -0400 Subject: [PATCH 086/131] fix test --- x/merkledb/proof_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index b49e285a08ef..10819e6ac362 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -1840,21 +1840,21 @@ func FuzzProofVerification(f *testing.F) { deletePortion, ) + if db.getMerkleRoot() == ids.Empty { + return + } + proof, err := db.GetProof( context.Background(), key, ) + require.NoError(err) rootID, err := db.GetMerkleRoot(context.Background()) require.NoError(err) - err = proof.Verify(context.Background(), rootID) - if rootID == ids.Empty { - require.ErrorIs(err, ErrEmptyProof) - return - } - require.NoError(err) + require.NoError(proof.Verify(context.Background(), rootID)) // Insert a new key-value pair newKey := make([]byte, 32) From 08b27eac79c7d440b7fe795342d7455b9e625006 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 12:56:08 -0400 Subject: [PATCH 087/131] add check for empty proof --- x/sync/g_db/db_client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/sync/g_db/db_client.go b/x/sync/g_db/db_client.go index f87497f3565d..fda9e7843fd1 100644 --- a/x/sync/g_db/db_client.go +++ b/x/sync/g_db/db_client.go @@ -47,6 +47,10 @@ func (c *DBClient) GetChangeProof( endKey maybe.Maybe[[]byte], keyLimit int, ) (*merkledb.ChangeProof, error) { + if endRootID == ids.Empty { + return nil, merkledb.ErrEmptyProof + } + resp, err := c.client.GetChangeProof(ctx, &pb.GetChangeProofRequest{ StartRootHash: startRootID[:], EndRootHash: endRootID[:], From 545df4ab0b300b758ba769c12f82b8d42ef7f4dc Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 13:03:43 -0400 Subject: [PATCH 088/131] appease linter --- x/merkledb/codec.go | 8 ++++---- x/merkledb/codec_test.go | 17 ++--------------- x/merkledb/db.go | 3 +-- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/x/merkledb/codec.go b/x/merkledb/codec.go index c9aa9030d49e..e08c8053e778 100644 --- a/x/merkledb/codec.go +++ b/x/merkledb/codec.go @@ -62,13 +62,13 @@ type encoder interface { encodeDBNode(n *dbNode, factor BranchFactor) []byte // Assumes [hv] is non-nil. encodeHashValues(hv *hashValues) []byte - encodeKeyAndHasValue(key Key, hasValue bool, factor BranchFactor) []byte + encodeKeyAndHasValue(key Key, hasValue bool) []byte } type decoder interface { // Assumes [n] is non-nil. decodeDBNode(bytes []byte, n *dbNode, factor BranchFactor) error - decodeKeyAndHasValue(bytes []byte, key *Key, hasValue *bool, factor BranchFactor) error + decodeKeyAndHasValue(bytes []byte, factor BranchFactor, key *Key, hasValue *bool) error } func newCodec() encoderDecoder { @@ -134,7 +134,7 @@ func (c *codecImpl) encodeHashValues(hv *hashValues) []byte { return buf.Bytes() } -func (c *codecImpl) encodeKeyAndHasValue(key Key, hasValue bool, factor BranchFactor) []byte { +func (c *codecImpl) encodeKeyAndHasValue(key Key, hasValue bool) []byte { var ( estimatedLen = binary.MaxVarintLen64 + len(key.Bytes()) + boolLen buf = bytes.NewBuffer(make([]byte, 0, estimatedLen)) @@ -204,7 +204,7 @@ func (c *codecImpl) decodeDBNode(b []byte, n *dbNode, branchFactor BranchFactor) return nil } -func (c *codecImpl) decodeKeyAndHasValue(b []byte, key *Key, hasValue *bool, branchFactor BranchFactor) error { +func (c *codecImpl) decodeKeyAndHasValue(b []byte, branchFactor BranchFactor, key *Key, hasValue *bool) error { if minKeyLen+minDBNodeLen > len(b) { return io.ErrUnexpectedEOF } diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index b9c02479de40..4dfbb40ec33c 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -300,26 +300,13 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { val = maybe.Some(value) } - numChildren %= int(branchFactor) - - children := map[byte]child{} - for i := 0; i < numChildren; i++ { - compressedKeyBytes := make([]byte, 32) - _, _ = rand.Read(compressedKeyBytes) // #nosec G404 - children[byte(i)] = child{ - compressedKey: ToKey(compressedKeyBytes, branchFactor), - id: ids.GenerateTestID(), - hasValue: val.HasValue(), - } - } - hasValue := rand.Intn(2) == 1 // #nosec G404 - b := codec.encodeKeyAndHasValue(key, hasValue, branchFactor) + b := codec.encodeKeyAndHasValue(key, hasValue) var ( gotKey Key gotHasValue bool ) - err := codec.decodeKeyAndHasValue(b, &gotKey, &gotHasValue, branchFactor) + err := codec.decodeKeyAndHasValue(b, branchFactor, &gotKey, &gotHasValue) require.NoError(err) require.Equal(key, gotKey) require.Equal(hasValue, val.HasValue()) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index f53719e78f57..9ed5095b8795 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -995,7 +995,6 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e rootKeyAndNodeBytes := codec.encodeKeyAndHasValue( changes.rootChange.after.key, changes.rootChange.after.value.HasValue(), - db.valueNodeDB.branchFactor, ) return db.baseDB.Put(rootDBKey, rootKeyAndNodeBytes) } @@ -1194,9 +1193,9 @@ func (db *merkleDB) initializeRootIfNeeded() error { ) if err := codec.decodeKeyAndHasValue( rootBytes, + db.valueNodeDB.branchFactor, &rootKey, &rootHasValue, - db.valueNodeDB.branchFactor, ); err != nil { return err } From 74ce29498bcdac62fcd40924dc7f674409e44b81 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 13:14:22 -0400 Subject: [PATCH 089/131] appease linter --- x/merkledb/codec_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index 4dfbb40ec33c..306ab0813fd1 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -306,8 +306,7 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { gotKey Key gotHasValue bool ) - err := codec.decodeKeyAndHasValue(b, branchFactor, &gotKey, &gotHasValue) - require.NoError(err) + require.NoError(codec.decodeKeyAndHasValue(b, branchFactor, &gotKey, &gotHasValue)) require.Equal(key, gotKey) require.Equal(hasValue, val.HasValue()) } From f938ae7fe1ab2c7cd306fb1558370801cb6c3b76 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 14:23:33 -0400 Subject: [PATCH 090/131] fix test --- x/merkledb/codec.go | 8 +++++--- x/merkledb/codec_test.go | 10 +--------- x/merkledb/proof_test.go | 19 +++++++++---------- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/x/merkledb/codec.go b/x/merkledb/codec.go index e08c8053e778..f13f181b5305 100644 --- a/x/merkledb/codec.go +++ b/x/merkledb/codec.go @@ -205,13 +205,15 @@ func (c *codecImpl) decodeDBNode(b []byte, n *dbNode, branchFactor BranchFactor) } func (c *codecImpl) decodeKeyAndHasValue(b []byte, branchFactor BranchFactor, key *Key, hasValue *bool) error { - if minKeyLen+minDBNodeLen > len(b) { + if minKeyLen+boolLen > len(b) { return io.ErrUnexpectedEOF } - src := bytes.NewReader(b) + var ( + src = bytes.NewReader(b) + err error + ) - var err error *key, err = c.decodeKey(src, branchFactor) if err != nil { return err diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index 306ab0813fd1..18387234973b 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -292,14 +292,6 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { key = key.Skip(1) } - val := maybe.Nothing[[]byte]() - if hasValue { - if len(value) == 0 { - value = nil - } - val = maybe.Some(value) - } - hasValue := rand.Intn(2) == 1 // #nosec G404 b := codec.encodeKeyAndHasValue(key, hasValue) var ( @@ -308,7 +300,7 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { ) require.NoError(codec.decodeKeyAndHasValue(b, branchFactor, &gotKey, &gotHasValue)) require.Equal(key, gotKey) - require.Equal(hasValue, val.HasValue()) + require.Equal(hasValue, gotHasValue) } }, ) diff --git a/x/merkledb/proof_test.go b/x/merkledb/proof_test.go index 10819e6ac362..53b36e185cc6 100644 --- a/x/merkledb/proof_test.go +++ b/x/merkledb/proof_test.go @@ -1731,29 +1731,28 @@ func FuzzRangeProofInvariants(f *testing.F) { end = maybe.Some(endBytes) } + rootID, err := db.GetMerkleRoot(context.Background()) + require.NoError(err) + rangeProof, err := db.GetRangeProof( context.Background(), start, end, int(maxProofLen), ) + if rootID == ids.Empty { + require.ErrorIs(err, ErrEmptyProof) + return + } require.NoError(err) - rootID, err := db.GetMerkleRoot(context.Background()) - require.NoError(err) - - err = rangeProof.Verify( + require.NoError(rangeProof.Verify( context.Background(), start, end, rootID, BranchFactor16, - ) - if rootID == ids.Empty { - require.ErrorIs(err, ErrEmptyProof) - return - } - require.NoError(err) + )) // Make sure the start proof doesn't contain any nodes // that are in the end proof. From f5c333b9bc5ac1f61b7bfb3491cab8663cfdce9c Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 24 Oct 2023 14:53:24 -0400 Subject: [PATCH 091/131] nit change var order --- x/merkledb/codec.go | 4 ++-- x/merkledb/codec_test.go | 2 +- x/merkledb/db.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/merkledb/codec.go b/x/merkledb/codec.go index f13f181b5305..d48868a06c6e 100644 --- a/x/merkledb/codec.go +++ b/x/merkledb/codec.go @@ -68,7 +68,7 @@ type encoder interface { type decoder interface { // Assumes [n] is non-nil. decodeDBNode(bytes []byte, n *dbNode, factor BranchFactor) error - decodeKeyAndHasValue(bytes []byte, factor BranchFactor, key *Key, hasValue *bool) error + decodeKeyAndHasValue(bytes []byte, key *Key, hasValue *bool, factor BranchFactor) error } func newCodec() encoderDecoder { @@ -204,7 +204,7 @@ func (c *codecImpl) decodeDBNode(b []byte, n *dbNode, branchFactor BranchFactor) return nil } -func (c *codecImpl) decodeKeyAndHasValue(b []byte, branchFactor BranchFactor, key *Key, hasValue *bool) error { +func (c *codecImpl) decodeKeyAndHasValue(b []byte, key *Key, hasValue *bool, branchFactor BranchFactor) error { if minKeyLen+boolLen > len(b) { return io.ErrUnexpectedEOF } diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index 18387234973b..1173c93350d8 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -298,7 +298,7 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { gotKey Key gotHasValue bool ) - require.NoError(codec.decodeKeyAndHasValue(b, branchFactor, &gotKey, &gotHasValue)) + require.NoError(codec.decodeKeyAndHasValue(b, &gotKey, &gotHasValue, branchFactor)) require.Equal(key, gotKey) require.Equal(hasValue, gotHasValue) } diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 9ed5095b8795..4697e7ca3cc3 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1193,9 +1193,9 @@ func (db *merkleDB) initializeRootIfNeeded() error { ) if err := codec.decodeKeyAndHasValue( rootBytes, - db.valueNodeDB.branchFactor, &rootKey, &rootHasValue, + db.valueNodeDB.branchFactor, ); err != nil { return err } From 525e33df111a25450bf06c6b2777ede944e4c3ba Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 2 Nov 2023 09:49:14 -0400 Subject: [PATCH 092/131] remove unused params --- x/merkledb/codec_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index aaea09bad334..7a8f05e2646a 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -279,9 +279,7 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { t *testing.T, keyBytes []byte, hasValue bool, - value []byte, removeToken bool, - numChildren int, ) { require := require.New(t) From bb649eafc0cc30df9c36ba1b4006ce3f4b060d47 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 2 Nov 2023 10:02:42 -0400 Subject: [PATCH 093/131] remove unused params --- x/merkledb/codec_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index 7a8f05e2646a..4fd3dd69900c 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -290,7 +290,6 @@ func FuzzEncodeDecodeKeyAndNode(f *testing.F) { key = key.Skip(1) } - hasValue := rand.Intn(2) == 1 // #nosec G404 b := codec.encodeKeyAndHasValue(key, hasValue) var ( gotKey Key From 63dd9b901fe9cfa6e780d9ce7aa1d0a05348111e Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 2 Nov 2023 11:23:22 -0400 Subject: [PATCH 094/131] ClearRange --> Clear --- proto/pb/sync/sync.pb.go | 543 ++++++++++++++++------------------ proto/pb/sync/sync_grpc.pb.go | 28 +- proto/sync/sync.proto | 7 +- x/merkledb/db.go | 15 +- x/merkledb/mock_db.go | 38 +-- x/sync/db.go | 2 +- x/sync/g_db/db_client.go | 16 +- x/sync/g_db/db_server.go | 17 +- x/sync/manager.go | 10 +- 9 files changed, 313 insertions(+), 363 deletions(-) diff --git a/proto/pb/sync/sync.pb.go b/proto/pb/sync/sync.pb.go index ed078a99473f..ffc11c72e058 100644 --- a/proto/pb/sync/sync.pb.go +++ b/proto/pb/sync/sync.pb.go @@ -150,17 +150,14 @@ func (x *GetMerkleRootResponse) GetRootHash() []byte { return nil } -type ClearRangeRequest struct { +type ClearRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - - StartKey *MaybeBytes `protobuf:"bytes,1,opt,name=start_key,json=startKey,proto3" json:"start_key,omitempty"` - EndKey *MaybeBytes `protobuf:"bytes,2,opt,name=end_key,json=endKey,proto3" json:"end_key,omitempty"` } -func (x *ClearRangeRequest) Reset() { - *x = ClearRangeRequest{} +func (x *ClearRequest) Reset() { + *x = ClearRequest{} if protoimpl.UnsafeEnabled { mi := &file_sync_sync_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -168,13 +165,13 @@ func (x *ClearRangeRequest) Reset() { } } -func (x *ClearRangeRequest) String() string { +func (x *ClearRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*ClearRangeRequest) ProtoMessage() {} +func (*ClearRequest) ProtoMessage() {} -func (x *ClearRangeRequest) ProtoReflect() protoreflect.Message { +func (x *ClearRequest) ProtoReflect() protoreflect.Message { mi := &file_sync_sync_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -186,25 +183,11 @@ func (x *ClearRangeRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use ClearRangeRequest.ProtoReflect.Descriptor instead. -func (*ClearRangeRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use ClearRequest.ProtoReflect.Descriptor instead. +func (*ClearRequest) Descriptor() ([]byte, []int) { return file_sync_sync_proto_rawDescGZIP(), []int{2} } -func (x *ClearRangeRequest) GetStartKey() *MaybeBytes { - if x != nil { - return x.StartKey - } - return nil -} - -func (x *ClearRangeRequest) GetEndKey() *MaybeBytes { - if x != nil { - return x.EndKey - } - return nil -} - type GetProofRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1553,222 +1536,216 @@ var file_sync_sync_proto_rawDesc = []byte{ 0x67, 0x65, 0x22, 0x34, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, - 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x22, 0x6d, 0x0a, 0x11, 0x43, 0x6c, 0x65, 0x61, - 0x72, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2d, 0x0a, - 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, - 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, - 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, - 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, - 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x22, 0x23, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, - 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x35, 0x0a, 0x10, - 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x21, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x0b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, 0x70, 0x72, - 0x6f, 0x6f, 0x66, 0x22, 0x68, 0x0a, 0x05, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x10, 0x0a, 0x03, - 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x26, - 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, - 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x25, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, - 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, - 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xff, 0x01, - 0x0a, 0x19, 0x53, 0x79, 0x6e, 0x63, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, - 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0f, 0x73, - 0x74, 0x61, 0x72, 0x74, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0d, 0x73, 0x74, 0x61, 0x72, 0x74, 0x52, 0x6f, 0x6f, 0x74, 0x48, - 0x61, 0x73, 0x68, 0x12, 0x22, 0x0a, 0x0d, 0x65, 0x6e, 0x64, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, - 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x65, 0x6e, 0x64, 0x52, - 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, - 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, - 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, - 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, - 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, - 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, - 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x1f, - 0x0a, 0x0b, 0x62, 0x79, 0x74, 0x65, 0x73, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x06, 0x20, - 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x62, 0x79, 0x74, 0x65, 0x73, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, - 0x95, 0x01, 0x0a, 0x1a, 0x53, 0x79, 0x6e, 0x63, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x36, - 0x0a, 0x0c, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, - 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x48, 0x00, 0x52, 0x0b, 0x63, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x33, 0x0a, 0x0b, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x5f, - 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, - 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x48, 0x00, 0x52, - 0x0a, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x42, 0x0a, 0x0a, 0x08, 0x72, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xda, 0x01, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x43, - 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x26, 0x0a, 0x0f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, - 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0d, 0x73, 0x74, 0x61, 0x72, - 0x74, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x22, 0x0a, 0x0d, 0x65, 0x6e, 0x64, - 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x0b, 0x65, 0x6e, 0x64, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2d, 0x0a, - 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, - 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, - 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, - 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, - 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, 0x6c, - 0x69, 0x6d, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x4c, - 0x69, 0x6d, 0x69, 0x74, 0x22, 0x88, 0x01, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, + 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x22, 0x0e, 0x0a, 0x0c, 0x43, 0x6c, 0x65, 0x61, + 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x23, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, + 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x35, 0x0a, + 0x10, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x21, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x0b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, 0x70, + 0x72, 0x6f, 0x6f, 0x66, 0x22, 0x68, 0x0a, 0x05, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x26, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, + 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x25, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, + 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, + 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xff, + 0x01, 0x0a, 0x19, 0x53, 0x79, 0x6e, 0x63, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, + 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0f, + 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0d, 0x73, 0x74, 0x61, 0x72, 0x74, 0x52, 0x6f, 0x6f, 0x74, + 0x48, 0x61, 0x73, 0x68, 0x12, 0x22, 0x0a, 0x0d, 0x65, 0x6e, 0x64, 0x5f, 0x72, 0x6f, 0x6f, 0x74, + 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x65, 0x6e, 0x64, + 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, + 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, + 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, + 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, + 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, + 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, + 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, + 0x1f, 0x0a, 0x0b, 0x62, 0x79, 0x74, 0x65, 0x73, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x62, 0x79, 0x74, 0x65, 0x73, 0x4c, 0x69, 0x6d, 0x69, 0x74, + 0x22, 0x95, 0x01, 0x0a, 0x1a, 0x53, 0x79, 0x6e, 0x63, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x36, 0x0a, 0x0c, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x48, 0x00, 0x52, 0x0b, 0x63, 0x68, 0x61, 0x6e, - 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2a, 0x0a, 0x10, 0x72, 0x6f, 0x6f, 0x74, 0x5f, - 0x6e, 0x6f, 0x74, 0x5f, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x08, 0x48, 0x00, 0x52, 0x0e, 0x72, 0x6f, 0x6f, 0x74, 0x4e, 0x6f, 0x74, 0x50, 0x72, 0x65, 0x73, - 0x65, 0x6e, 0x74, 0x42, 0x0a, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, - 0xcb, 0x01, 0x0a, 0x18, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x05, - 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, 0x79, - 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, - 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, - 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, - 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, - 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, - 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, - 0x2c, 0x0a, 0x12, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x72, 0x6f, 0x6f, 0x74, - 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x10, 0x65, 0x78, 0x70, - 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x22, 0x31, 0x0a, - 0x19, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, - 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, - 0x72, 0x6f, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, - 0x22, 0x43, 0x0a, 0x18, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x05, - 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, 0x79, - 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, - 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xcf, 0x01, 0x0a, 0x18, 0x53, 0x79, 0x6e, 0x63, 0x47, 0x65, - 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, - 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, - 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, - 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, - 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, - 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, - 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x62, 0x79, 0x74, 0x65, 0x73, 0x5f, - 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x62, 0x79, 0x74, - 0x65, 0x73, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0xaa, 0x01, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x52, - 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2d, 0x0a, - 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, + 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x33, 0x0a, 0x0b, 0x72, 0x61, 0x6e, 0x67, 0x65, + 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, + 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x48, 0x00, + 0x52, 0x0a, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x42, 0x0a, 0x0a, 0x08, + 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xda, 0x01, 0x0a, 0x15, 0x47, 0x65, 0x74, + 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x72, 0x6f, 0x6f, 0x74, + 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0d, 0x73, 0x74, 0x61, + 0x72, 0x74, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x22, 0x0a, 0x0d, 0x65, 0x6e, + 0x64, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x0b, 0x65, 0x6e, 0x64, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2d, + 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, + 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, + 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, + 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, + 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, + 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, + 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x88, 0x01, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, + 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x36, 0x0a, 0x0c, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x68, + 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x48, 0x00, 0x52, 0x0b, 0x63, 0x68, 0x61, + 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2a, 0x0a, 0x10, 0x72, 0x6f, 0x6f, 0x74, + 0x5f, 0x6e, 0x6f, 0x74, 0x5f, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x08, 0x48, 0x00, 0x52, 0x0e, 0x72, 0x6f, 0x6f, 0x74, 0x4e, 0x6f, 0x74, 0x50, 0x72, 0x65, + 0x73, 0x65, 0x6e, 0x74, 0x42, 0x0a, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0xcb, 0x01, 0x0a, 0x18, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, + 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, + 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, + 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, + 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, + 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, + 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, + 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, + 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, + 0x12, 0x2c, 0x0a, 0x12, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x72, 0x6f, 0x6f, + 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x10, 0x65, 0x78, + 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x22, 0x31, + 0x0a, 0x19, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, + 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, + 0x72, 0x72, 0x6f, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, + 0x72, 0x22, 0x43, 0x0a, 0x18, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, + 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, + 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x73, + 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, + 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xcf, 0x01, 0x0a, 0x18, 0x53, 0x79, 0x6e, 0x63, 0x47, + 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, + 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, + 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, + 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, - 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x07, - 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, - 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, - 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, 0x6c, - 0x69, 0x6d, 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x4c, - 0x69, 0x6d, 0x69, 0x74, 0x22, 0x3f, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x26, 0x0a, - 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, - 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x05, - 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xa6, 0x01, 0x0a, 0x17, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, + 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, + 0x79, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, + 0x65, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x62, 0x79, 0x74, 0x65, 0x73, + 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x62, 0x79, + 0x74, 0x65, 0x73, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0xaa, 0x01, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, - 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, - 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2d, + 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, - 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x31, 0x0a, 0x0b, 0x72, - 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, - 0x6f, 0x66, 0x52, 0x0a, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0x9f, - 0x01, 0x0a, 0x0b, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x30, - 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x12, 0x2c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x30, - 0x0a, 0x0b, 0x6b, 0x65, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x18, 0x03, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x43, 0x68, - 0x61, 0x6e, 0x67, 0x65, 0x52, 0x0a, 0x6b, 0x65, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, - 0x22, 0x9b, 0x01, 0x0a, 0x0a, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, + 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x29, 0x0a, + 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, + 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, + 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x6b, 0x65, 0x79, 0x5f, + 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x6b, 0x65, 0x79, + 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x3f, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, + 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x26, + 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, + 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, + 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x22, 0xa6, 0x01, 0x0a, 0x17, 0x43, 0x6f, 0x6d, 0x6d, 0x69, + 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x2d, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, + 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x08, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4b, 0x65, + 0x79, 0x12, 0x29, 0x0a, 0x07, 0x65, 0x6e, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, + 0x79, 0x74, 0x65, 0x73, 0x52, 0x06, 0x65, 0x6e, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x31, 0x0a, 0x0b, + 0x72, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, + 0x6f, 0x6f, 0x66, 0x52, 0x0a, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x22, + 0x9f, 0x01, 0x0a, 0x0b, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x30, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x2c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, - 0x2d, 0x0a, 0x0a, 0x6b, 0x65, 0x79, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x03, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, - 0x6c, 0x75, 0x65, 0x52, 0x09, 0x6b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x22, 0xd6, - 0x01, 0x0a, 0x09, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x1b, 0x0a, 0x03, - 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x73, 0x79, 0x6e, 0x63, - 0x2e, 0x4b, 0x65, 0x79, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x34, 0x0a, 0x0d, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x5f, 0x6f, 0x72, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, - 0x65, 0x73, 0x52, 0x0b, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x4f, 0x72, 0x48, 0x61, 0x73, 0x68, 0x12, - 0x39, 0x0a, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, - 0x64, 0x65, 0x2e, 0x43, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, - 0x52, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x1a, 0x3b, 0x0a, 0x0d, 0x43, 0x68, - 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, - 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x45, 0x0a, 0x09, 0x4b, 0x65, 0x79, 0x43, 0x68, - 0x61, 0x6e, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x26, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, - 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x33, - 0x0a, 0x03, 0x4b, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x14, 0x0a, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x22, 0x41, 0x0a, 0x0a, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, - 0x73, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x73, 0x5f, 0x6e, 0x6f, - 0x74, 0x68, 0x69, 0x6e, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x4e, - 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x22, 0x32, 0x0a, 0x08, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, - 0x75, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x32, 0xc9, 0x04, 0x0a, 0x02, 0x44, - 0x42, 0x12, 0x44, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, - 0x6f, 0x74, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, - 0x63, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3d, 0x0a, 0x0a, 0x43, 0x6c, 0x65, 0x61, 0x72, - 0x52, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x17, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6c, 0x65, - 0x61, 0x72, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x39, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, - 0x6f, 0x66, 0x12, 0x15, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, - 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x73, 0x79, 0x6e, 0x63, - 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x4b, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x12, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, + 0x30, 0x0a, 0x0b, 0x6b, 0x65, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x18, 0x03, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x43, + 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x0a, 0x6b, 0x65, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, + 0x73, 0x22, 0x9b, 0x01, 0x0a, 0x0a, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, + 0x12, 0x30, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x72, 0x74, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x12, 0x2c, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, + 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x6f, 0x66, + 0x12, 0x2d, 0x0a, 0x0a, 0x6b, 0x65, 0x79, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x03, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x56, + 0x61, 0x6c, 0x75, 0x65, 0x52, 0x09, 0x6b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x22, + 0xd6, 0x01, 0x0a, 0x09, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x1b, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x73, 0x79, 0x6e, + 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x34, 0x0a, 0x0d, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x5f, 0x6f, 0x72, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, + 0x74, 0x65, 0x73, 0x52, 0x0b, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x4f, 0x72, 0x48, 0x61, 0x73, 0x68, + 0x12, 0x39, 0x0a, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x4e, + 0x6f, 0x64, 0x65, 0x2e, 0x43, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x52, 0x08, 0x63, 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x1a, 0x3b, 0x0a, 0x0d, 0x43, + 0x68, 0x69, 0x6c, 0x64, 0x72, 0x65, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x45, 0x0a, 0x09, 0x4b, 0x65, 0x79, 0x43, + 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x26, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x4d, 0x61, + 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, + 0x33, 0x0a, 0x03, 0x4b, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x12, 0x14, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x22, 0x41, 0x0a, 0x0a, 0x4d, 0x61, 0x79, 0x62, 0x65, 0x42, 0x79, 0x74, + 0x65, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x73, 0x5f, 0x6e, + 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, + 0x4e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x22, 0x32, 0x0a, 0x08, 0x4b, 0x65, 0x79, 0x56, 0x61, + 0x6c, 0x75, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x32, 0xbf, 0x04, 0x0a, 0x02, + 0x44, 0x42, 0x12, 0x44, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, + 0x6f, 0x6f, 0x74, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x73, 0x79, + 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x33, 0x0a, 0x05, 0x43, 0x6c, 0x65, 0x61, + 0x72, 0x12, 0x12, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6c, 0x65, 0x61, 0x72, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x39, 0x0a, + 0x08, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x15, 0x2e, 0x73, 0x79, 0x6e, 0x63, + 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x16, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x43, + 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1b, 0x2e, 0x73, 0x79, 0x6e, + 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, + 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x54, 0x0a, 0x11, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, + 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, + 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, + 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x73, 0x79, 0x6e, + 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, + 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x11, 0x43, + 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, + 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x1c, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x54, - 0x0a, 0x11, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, - 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, - 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, - 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, - 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, - 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, - 0x79, 0x12, 0x48, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, - 0x6f, 0x66, 0x12, 0x1a, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, - 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, - 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, 0x10, 0x43, - 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, - 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, - 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x76, 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x61, 0x76, - 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, - 0x70, 0x62, 0x2f, 0x73, 0x79, 0x6e, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x48, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, + 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1a, 0x2e, 0x73, 0x79, 0x6e, 0x63, + 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, + 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x49, 0x0a, 0x10, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, + 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, + 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x2f, 0x5a, + 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x76, 0x61, 0x2d, + 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x61, 0x76, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x67, 0x6f, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x62, 0x2f, 0x73, 0x79, 0x6e, 0x63, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1787,7 +1764,7 @@ var file_sync_sync_proto_msgTypes = make([]protoimpl.MessageInfo, 25) var file_sync_sync_proto_goTypes = []interface{}{ (*Request)(nil), // 0: sync.Request (*GetMerkleRootResponse)(nil), // 1: sync.GetMerkleRootResponse - (*ClearRangeRequest)(nil), // 2: sync.ClearRangeRequest + (*ClearRequest)(nil), // 2: sync.ClearRequest (*GetProofRequest)(nil), // 3: sync.GetProofRequest (*GetProofResponse)(nil), // 4: sync.GetProofResponse (*Proof)(nil), // 5: sync.Proof @@ -1815,61 +1792,59 @@ var file_sync_sync_proto_goTypes = []interface{}{ var file_sync_sync_proto_depIdxs = []int32{ 13, // 0: sync.Request.range_proof_request:type_name -> sync.SyncGetRangeProofRequest 6, // 1: sync.Request.change_proof_request:type_name -> sync.SyncGetChangeProofRequest - 22, // 2: sync.ClearRangeRequest.start_key:type_name -> sync.MaybeBytes - 22, // 3: sync.ClearRangeRequest.end_key:type_name -> sync.MaybeBytes - 5, // 4: sync.GetProofResponse.proof:type_name -> sync.Proof - 22, // 5: sync.Proof.value:type_name -> sync.MaybeBytes - 19, // 6: sync.Proof.proof:type_name -> sync.ProofNode - 22, // 7: sync.SyncGetChangeProofRequest.start_key:type_name -> sync.MaybeBytes - 22, // 8: sync.SyncGetChangeProofRequest.end_key:type_name -> sync.MaybeBytes - 17, // 9: sync.SyncGetChangeProofResponse.change_proof:type_name -> sync.ChangeProof - 18, // 10: sync.SyncGetChangeProofResponse.range_proof:type_name -> sync.RangeProof - 22, // 11: sync.GetChangeProofRequest.start_key:type_name -> sync.MaybeBytes - 22, // 12: sync.GetChangeProofRequest.end_key:type_name -> sync.MaybeBytes - 17, // 13: sync.GetChangeProofResponse.change_proof:type_name -> sync.ChangeProof - 17, // 14: sync.VerifyChangeProofRequest.proof:type_name -> sync.ChangeProof - 22, // 15: sync.VerifyChangeProofRequest.start_key:type_name -> sync.MaybeBytes - 22, // 16: sync.VerifyChangeProofRequest.end_key:type_name -> sync.MaybeBytes - 17, // 17: sync.CommitChangeProofRequest.proof:type_name -> sync.ChangeProof - 22, // 18: sync.SyncGetRangeProofRequest.start_key:type_name -> sync.MaybeBytes - 22, // 19: sync.SyncGetRangeProofRequest.end_key:type_name -> sync.MaybeBytes - 22, // 20: sync.GetRangeProofRequest.start_key:type_name -> sync.MaybeBytes - 22, // 21: sync.GetRangeProofRequest.end_key:type_name -> sync.MaybeBytes - 18, // 22: sync.GetRangeProofResponse.proof:type_name -> sync.RangeProof - 22, // 23: sync.CommitRangeProofRequest.start_key:type_name -> sync.MaybeBytes - 22, // 24: sync.CommitRangeProofRequest.end_key:type_name -> sync.MaybeBytes - 18, // 25: sync.CommitRangeProofRequest.range_proof:type_name -> sync.RangeProof - 19, // 26: sync.ChangeProof.start_proof:type_name -> sync.ProofNode - 19, // 27: sync.ChangeProof.end_proof:type_name -> sync.ProofNode - 20, // 28: sync.ChangeProof.key_changes:type_name -> sync.KeyChange - 19, // 29: sync.RangeProof.start_proof:type_name -> sync.ProofNode - 19, // 30: sync.RangeProof.end_proof:type_name -> sync.ProofNode - 23, // 31: sync.RangeProof.key_values:type_name -> sync.KeyValue - 21, // 32: sync.ProofNode.key:type_name -> sync.Key - 22, // 33: sync.ProofNode.value_or_hash:type_name -> sync.MaybeBytes - 24, // 34: sync.ProofNode.children:type_name -> sync.ProofNode.ChildrenEntry - 22, // 35: sync.KeyChange.value:type_name -> sync.MaybeBytes - 25, // 36: sync.DB.GetMerkleRoot:input_type -> google.protobuf.Empty - 2, // 37: sync.DB.ClearRange:input_type -> sync.ClearRangeRequest - 3, // 38: sync.DB.GetProof:input_type -> sync.GetProofRequest - 8, // 39: sync.DB.GetChangeProof:input_type -> sync.GetChangeProofRequest - 10, // 40: sync.DB.VerifyChangeProof:input_type -> sync.VerifyChangeProofRequest - 12, // 41: sync.DB.CommitChangeProof:input_type -> sync.CommitChangeProofRequest - 14, // 42: sync.DB.GetRangeProof:input_type -> sync.GetRangeProofRequest - 16, // 43: sync.DB.CommitRangeProof:input_type -> sync.CommitRangeProofRequest - 1, // 44: sync.DB.GetMerkleRoot:output_type -> sync.GetMerkleRootResponse - 25, // 45: sync.DB.ClearRange:output_type -> google.protobuf.Empty - 4, // 46: sync.DB.GetProof:output_type -> sync.GetProofResponse - 9, // 47: sync.DB.GetChangeProof:output_type -> sync.GetChangeProofResponse - 11, // 48: sync.DB.VerifyChangeProof:output_type -> sync.VerifyChangeProofResponse - 25, // 49: sync.DB.CommitChangeProof:output_type -> google.protobuf.Empty - 15, // 50: sync.DB.GetRangeProof:output_type -> sync.GetRangeProofResponse - 25, // 51: sync.DB.CommitRangeProof:output_type -> google.protobuf.Empty - 44, // [44:52] is the sub-list for method output_type - 36, // [36:44] is the sub-list for method input_type - 36, // [36:36] is the sub-list for extension type_name - 36, // [36:36] is the sub-list for extension extendee - 0, // [0:36] is the sub-list for field type_name + 5, // 2: sync.GetProofResponse.proof:type_name -> sync.Proof + 22, // 3: sync.Proof.value:type_name -> sync.MaybeBytes + 19, // 4: sync.Proof.proof:type_name -> sync.ProofNode + 22, // 5: sync.SyncGetChangeProofRequest.start_key:type_name -> sync.MaybeBytes + 22, // 6: sync.SyncGetChangeProofRequest.end_key:type_name -> sync.MaybeBytes + 17, // 7: sync.SyncGetChangeProofResponse.change_proof:type_name -> sync.ChangeProof + 18, // 8: sync.SyncGetChangeProofResponse.range_proof:type_name -> sync.RangeProof + 22, // 9: sync.GetChangeProofRequest.start_key:type_name -> sync.MaybeBytes + 22, // 10: sync.GetChangeProofRequest.end_key:type_name -> sync.MaybeBytes + 17, // 11: sync.GetChangeProofResponse.change_proof:type_name -> sync.ChangeProof + 17, // 12: sync.VerifyChangeProofRequest.proof:type_name -> sync.ChangeProof + 22, // 13: sync.VerifyChangeProofRequest.start_key:type_name -> sync.MaybeBytes + 22, // 14: sync.VerifyChangeProofRequest.end_key:type_name -> sync.MaybeBytes + 17, // 15: sync.CommitChangeProofRequest.proof:type_name -> sync.ChangeProof + 22, // 16: sync.SyncGetRangeProofRequest.start_key:type_name -> sync.MaybeBytes + 22, // 17: sync.SyncGetRangeProofRequest.end_key:type_name -> sync.MaybeBytes + 22, // 18: sync.GetRangeProofRequest.start_key:type_name -> sync.MaybeBytes + 22, // 19: sync.GetRangeProofRequest.end_key:type_name -> sync.MaybeBytes + 18, // 20: sync.GetRangeProofResponse.proof:type_name -> sync.RangeProof + 22, // 21: sync.CommitRangeProofRequest.start_key:type_name -> sync.MaybeBytes + 22, // 22: sync.CommitRangeProofRequest.end_key:type_name -> sync.MaybeBytes + 18, // 23: sync.CommitRangeProofRequest.range_proof:type_name -> sync.RangeProof + 19, // 24: sync.ChangeProof.start_proof:type_name -> sync.ProofNode + 19, // 25: sync.ChangeProof.end_proof:type_name -> sync.ProofNode + 20, // 26: sync.ChangeProof.key_changes:type_name -> sync.KeyChange + 19, // 27: sync.RangeProof.start_proof:type_name -> sync.ProofNode + 19, // 28: sync.RangeProof.end_proof:type_name -> sync.ProofNode + 23, // 29: sync.RangeProof.key_values:type_name -> sync.KeyValue + 21, // 30: sync.ProofNode.key:type_name -> sync.Key + 22, // 31: sync.ProofNode.value_or_hash:type_name -> sync.MaybeBytes + 24, // 32: sync.ProofNode.children:type_name -> sync.ProofNode.ChildrenEntry + 22, // 33: sync.KeyChange.value:type_name -> sync.MaybeBytes + 25, // 34: sync.DB.GetMerkleRoot:input_type -> google.protobuf.Empty + 2, // 35: sync.DB.Clear:input_type -> sync.ClearRequest + 3, // 36: sync.DB.GetProof:input_type -> sync.GetProofRequest + 8, // 37: sync.DB.GetChangeProof:input_type -> sync.GetChangeProofRequest + 10, // 38: sync.DB.VerifyChangeProof:input_type -> sync.VerifyChangeProofRequest + 12, // 39: sync.DB.CommitChangeProof:input_type -> sync.CommitChangeProofRequest + 14, // 40: sync.DB.GetRangeProof:input_type -> sync.GetRangeProofRequest + 16, // 41: sync.DB.CommitRangeProof:input_type -> sync.CommitRangeProofRequest + 1, // 42: sync.DB.GetMerkleRoot:output_type -> sync.GetMerkleRootResponse + 25, // 43: sync.DB.Clear:output_type -> google.protobuf.Empty + 4, // 44: sync.DB.GetProof:output_type -> sync.GetProofResponse + 9, // 45: sync.DB.GetChangeProof:output_type -> sync.GetChangeProofResponse + 11, // 46: sync.DB.VerifyChangeProof:output_type -> sync.VerifyChangeProofResponse + 25, // 47: sync.DB.CommitChangeProof:output_type -> google.protobuf.Empty + 15, // 48: sync.DB.GetRangeProof:output_type -> sync.GetRangeProofResponse + 25, // 49: sync.DB.CommitRangeProof:output_type -> google.protobuf.Empty + 42, // [42:50] is the sub-list for method output_type + 34, // [34:42] is the sub-list for method input_type + 34, // [34:34] is the sub-list for extension type_name + 34, // [34:34] is the sub-list for extension extendee + 0, // [0:34] is the sub-list for field type_name } func init() { file_sync_sync_proto_init() } @@ -1903,7 +1878,7 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ClearRangeRequest); i { + switch v := v.(*ClearRequest); i { case 0: return &v.state case 1: diff --git a/proto/pb/sync/sync_grpc.pb.go b/proto/pb/sync/sync_grpc.pb.go index 5338e9e2a6df..eee9714f6d34 100644 --- a/proto/pb/sync/sync_grpc.pb.go +++ b/proto/pb/sync/sync_grpc.pb.go @@ -21,7 +21,7 @@ const _ = grpc.SupportPackageIsVersion7 const ( DB_GetMerkleRoot_FullMethodName = "/sync.DB/GetMerkleRoot" - DB_ClearRange_FullMethodName = "/sync.DB/ClearRange" + DB_Clear_FullMethodName = "/sync.DB/Clear" DB_GetProof_FullMethodName = "/sync.DB/GetProof" DB_GetChangeProof_FullMethodName = "/sync.DB/GetChangeProof" DB_VerifyChangeProof_FullMethodName = "/sync.DB/VerifyChangeProof" @@ -35,7 +35,7 @@ const ( // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type DBClient interface { GetMerkleRoot(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GetMerkleRootResponse, error) - ClearRange(ctx context.Context, in *ClearRangeRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) + Clear(ctx context.Context, in *ClearRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) GetProof(ctx context.Context, in *GetProofRequest, opts ...grpc.CallOption) (*GetProofResponse, error) GetChangeProof(ctx context.Context, in *GetChangeProofRequest, opts ...grpc.CallOption) (*GetChangeProofResponse, error) VerifyChangeProof(ctx context.Context, in *VerifyChangeProofRequest, opts ...grpc.CallOption) (*VerifyChangeProofResponse, error) @@ -61,9 +61,9 @@ func (c *dBClient) GetMerkleRoot(ctx context.Context, in *emptypb.Empty, opts .. return out, nil } -func (c *dBClient) ClearRange(ctx context.Context, in *ClearRangeRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { +func (c *dBClient) Clear(ctx context.Context, in *ClearRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { out := new(emptypb.Empty) - err := c.cc.Invoke(ctx, DB_ClearRange_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, DB_Clear_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -129,7 +129,7 @@ func (c *dBClient) CommitRangeProof(ctx context.Context, in *CommitRangeProofReq // for forward compatibility type DBServer interface { GetMerkleRoot(context.Context, *emptypb.Empty) (*GetMerkleRootResponse, error) - ClearRange(context.Context, *ClearRangeRequest) (*emptypb.Empty, error) + Clear(context.Context, *ClearRequest) (*emptypb.Empty, error) GetProof(context.Context, *GetProofRequest) (*GetProofResponse, error) GetChangeProof(context.Context, *GetChangeProofRequest) (*GetChangeProofResponse, error) VerifyChangeProof(context.Context, *VerifyChangeProofRequest) (*VerifyChangeProofResponse, error) @@ -146,8 +146,8 @@ type UnimplementedDBServer struct { func (UnimplementedDBServer) GetMerkleRoot(context.Context, *emptypb.Empty) (*GetMerkleRootResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetMerkleRoot not implemented") } -func (UnimplementedDBServer) ClearRange(context.Context, *ClearRangeRequest) (*emptypb.Empty, error) { - return nil, status.Errorf(codes.Unimplemented, "method ClearRange not implemented") +func (UnimplementedDBServer) Clear(context.Context, *ClearRequest) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method Clear not implemented") } func (UnimplementedDBServer) GetProof(context.Context, *GetProofRequest) (*GetProofResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetProof not implemented") @@ -198,20 +198,20 @@ func _DB_GetMerkleRoot_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } -func _DB_ClearRange_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ClearRangeRequest) +func _DB_Clear_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ClearRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(DBServer).ClearRange(ctx, in) + return srv.(DBServer).Clear(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: DB_ClearRange_FullMethodName, + FullMethod: DB_Clear_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(DBServer).ClearRange(ctx, req.(*ClearRangeRequest)) + return srv.(DBServer).Clear(ctx, req.(*ClearRequest)) } return interceptor(ctx, in, info, handler) } @@ -336,8 +336,8 @@ var DB_ServiceDesc = grpc.ServiceDesc{ Handler: _DB_GetMerkleRoot_Handler, }, { - MethodName: "ClearRange", - Handler: _DB_ClearRange_Handler, + MethodName: "Clear", + Handler: _DB_Clear_Handler, }, { MethodName: "GetProof", diff --git a/proto/sync/sync.proto b/proto/sync/sync.proto index 6a3f6dc23513..0f91825a7410 100644 --- a/proto/sync/sync.proto +++ b/proto/sync/sync.proto @@ -21,7 +21,7 @@ message Request { service DB { rpc GetMerkleRoot(google.protobuf.Empty) returns (GetMerkleRootResponse); - rpc ClearRange(ClearRangeRequest) returns (google.protobuf.Empty); + rpc Clear(ClearRequest) returns (google.protobuf.Empty); rpc GetProof(GetProofRequest) returns (GetProofResponse); @@ -37,10 +37,7 @@ message GetMerkleRootResponse { bytes root_hash = 1; } -message ClearRangeRequest { - MaybeBytes start_key = 1; - MaybeBytes end_key = 2; -} +message ClearRequest {} message GetProofRequest { bytes key = 1; diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 43cfe9cca05e..b3c1c59fb5df 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -119,11 +119,9 @@ type RangeProofer interface { CommitRangeProof(ctx context.Context, start, end maybe.Maybe[[]byte], proof *RangeProof) error } -type ClearRanger interface { - // Deletes all key-value pairs with keys in the range [start, end]. - // If [start] is Nothing, there's no lower bound on the range. - // If [end] is Nothing, there's no upper bound on the range. - ClearRange(start, end maybe.Maybe[[]byte]) error +type Clearer interface { + // Deletes all key/value pairs from the database. + Clear() error } type Prefetcher interface { @@ -141,7 +139,7 @@ type Prefetcher interface { type MerkleDB interface { database.Database - ClearRanger + Clearer Trie MerkleRootGetter ProofGetter @@ -1287,11 +1285,12 @@ func (db *merkleDB) getRoot() maybe.Maybe[*node] { return db.root } -func (db *merkleDB) ClearRange(start, end maybe.Maybe[[]byte]) error { +func (db *merkleDB) Clear() error { db.commitLock.Lock() defer db.commitLock.Unlock() - keysToDelete, err := db.getKeysNotInSet(start, end, set.Set[string]{}) + // TODO is it faster to clear another way? + keysToDelete, err := db.getKeysNotInSet(maybe.Nothing[[]byte](), maybe.Nothing[[]byte](), set.Set[string]{}) if err != nil { return err } diff --git a/x/merkledb/mock_db.go b/x/merkledb/mock_db.go index dbcc43342276..c4a038ab556e 100644 --- a/x/merkledb/mock_db.go +++ b/x/merkledb/mock_db.go @@ -5,12 +5,12 @@ package merkledb import ( - maybe "github.com/ava-labs/avalanchego/utils/maybe" - gomock "go.uber.org/mock/gomock" reflect "reflect" context "context" database "github.com/ava-labs/avalanchego/database" ids "github.com/ava-labs/avalanchego/ids" + maybe "github.com/ava-labs/avalanchego/utils/maybe" + gomock "go.uber.org/mock/gomock" ) // MockMerkleDB is a mock of MerkleDB interface. @@ -36,18 +36,18 @@ func (m *MockMerkleDB) EXPECT() *MockMerkleDBMockRecorder { return m.recorder } -// ClearRange mocks base method. -func (m *MockMerkleDB) ClearRange(arg0, arg1 maybe.Maybe[[]uint8]) error { +// Clear mocks base method. +func (m *MockMerkleDB) Clear() error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ClearRange", arg0, arg1) + ret := m.ctrl.Call(m, "Clear") ret0, _ := ret[0].(error) return ret0 } -// ClearRange indicates an expected call of ClearRange. -func (mr *MockMerkleDBMockRecorder) ClearRange(arg0, arg1 interface{}) *gomock.Call { +// Clear indicates an expected call of Clear. +func (mr *MockMerkleDBMockRecorder) Clear() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ClearRange", reflect.TypeOf((*MockMerkleDB)(nil).ClearRange), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clear", reflect.TypeOf((*MockMerkleDB)(nil).Clear)) } // Close mocks base method. @@ -413,11 +413,11 @@ func (mr *MockMerkleDBMockRecorder) VerifyChangeProof(arg0, arg1, arg2, arg3, ar // getEditableNode mocks base method. func (m *MockMerkleDB) getEditableNode(arg0 Key, arg1 bool) (*node, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "getEditableNode", arg0, arg1) - ret0, _ := ret[0].(*node) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "getEditableNode", arg0, arg1) + ret0, _ := ret[0].(*node) + ret1, _ := ret[1].(error) + return ret0, ret1 } // getEditableNode indicates an expected call of getEditableNode. @@ -442,15 +442,15 @@ func (mr *MockMerkleDBMockRecorder) getRoot() *gomock.Call { // getValue mocks base method. func (m *MockMerkleDB) getValue(arg0 Key) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "getValue", arg0) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "getValue", arg0) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 } // getValue indicates an expected call of getValue. func (mr *MockMerkleDBMockRecorder) getValue(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "getValue", reflect.TypeOf((*MockMerkleDB)(nil).getValue), arg0) -} +} \ No newline at end of file diff --git a/x/sync/db.go b/x/sync/db.go index eca2b0a13c78..5a0a5164c6a6 100644 --- a/x/sync/db.go +++ b/x/sync/db.go @@ -6,7 +6,7 @@ package sync import "github.com/ava-labs/avalanchego/x/merkledb" type DB interface { - merkledb.ClearRanger + merkledb.Clearer merkledb.MerkleRootGetter merkledb.ProofGetter merkledb.ChangeProofer diff --git a/x/sync/g_db/db_client.go b/x/sync/g_db/db_client.go index fda9e7843fd1..c31e218f072e 100644 --- a/x/sync/g_db/db_client.go +++ b/x/sync/g_db/db_client.go @@ -186,19 +186,7 @@ func (c *DBClient) CommitRangeProof( return err } -func (c *DBClient) ClearRange( - start maybe.Maybe[[]byte], - end maybe.Maybe[[]byte], -) error { - _, err := c.client.ClearRange(context.Background(), &pb.ClearRangeRequest{ - StartKey: &pb.MaybeBytes{ - Value: start.Value(), - IsNothing: start.IsNothing(), - }, - EndKey: &pb.MaybeBytes{ - Value: end.Value(), - IsNothing: end.IsNothing(), - }, - }) +func (c *DBClient) Clear() error { + _, err := c.client.Clear(context.Background(), &pb.ClearRequest{}) return err } diff --git a/x/sync/g_db/db_server.go b/x/sync/g_db/db_server.go index f49400abfce3..30829a0369d9 100644 --- a/x/sync/g_db/db_server.go +++ b/x/sync/g_db/db_server.go @@ -219,20 +219,9 @@ func (s *DBServer) CommitRangeProof( return &emptypb.Empty{}, err } -func (s *DBServer) ClearRange( +func (s *DBServer) Clear( _ context.Context, - req *pb.ClearRangeRequest, + req *pb.ClearRequest, ) (*emptypb.Empty, error) { - start := maybe.Nothing[[]byte]() - if req.StartKey != nil && !req.StartKey.IsNothing { - start = maybe.Some(req.StartKey.Value) - } - - end := maybe.Nothing[[]byte]() - if req.EndKey != nil && !req.EndKey.IsNothing { - end = maybe.Some(req.EndKey.Value) - } - - err := s.db.ClearRange(start, end) - return &emptypb.Empty{}, err + return &emptypb.Empty{}, s.db.Clear() } diff --git a/x/sync/manager.go b/x/sync/manager.go index 40b340fbfb0e..3ea29c86cf33 100644 --- a/x/sync/manager.go +++ b/x/sync/manager.go @@ -266,11 +266,12 @@ func (m *Manager) getAndApplyChangeProof(ctx context.Context, work *workItem) { if targetRootID == ids.Empty { // The trie is empty after this change. // Delete all the key-value pairs in the range. - if err := m.config.DB.ClearRange(work.start, work.end); err != nil { + if err := m.config.DB.Clear(); err != nil { m.setError(err) return } - m.completeWorkItem(ctx, work, work.end, targetRootID, nil) + work.start = maybe.Nothing[[]byte]() + m.completeWorkItem(ctx, work, maybe.Nothing[[]byte](), targetRootID, nil) return } @@ -342,11 +343,12 @@ func (m *Manager) getAndApplyRangeProof(ctx context.Context, work *workItem) { targetRootID := m.getTargetRoot() if targetRootID == ids.Empty { - if err := m.config.DB.ClearRange(work.start, work.end); err != nil { + if err := m.config.DB.Clear(); err != nil { m.setError(err) return } - m.completeWorkItem(ctx, work, work.end, targetRootID, nil) + work.start = maybe.Nothing[[]byte]() + m.completeWorkItem(ctx, work, maybe.Nothing[[]byte](), targetRootID, nil) return } From 7e48fc4866a8a7a405f10975ca159a98bde3d38d Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 2 Nov 2023 11:26:40 -0400 Subject: [PATCH 095/131] remove ClearRequest proto --- proto/pb/sync/sync.pb.go | 444 +++++++++++++++------------------- proto/pb/sync/sync_grpc.pb.go | 12 +- proto/sync/sync.proto | 4 +- x/sync/g_db/db_client.go | 2 +- x/sync/g_db/db_server.go | 2 +- 5 files changed, 205 insertions(+), 259 deletions(-) diff --git a/proto/pb/sync/sync.pb.go b/proto/pb/sync/sync.pb.go index ffc11c72e058..eb72e145420a 100644 --- a/proto/pb/sync/sync.pb.go +++ b/proto/pb/sync/sync.pb.go @@ -150,44 +150,6 @@ func (x *GetMerkleRootResponse) GetRootHash() []byte { return nil } -type ClearRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *ClearRequest) Reset() { - *x = ClearRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ClearRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ClearRequest) ProtoMessage() {} - -func (x *ClearRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ClearRequest.ProtoReflect.Descriptor instead. -func (*ClearRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{2} -} - type GetProofRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -199,7 +161,7 @@ type GetProofRequest struct { func (x *GetProofRequest) Reset() { *x = GetProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[3] + mi := &file_sync_sync_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -212,7 +174,7 @@ func (x *GetProofRequest) String() string { func (*GetProofRequest) ProtoMessage() {} func (x *GetProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[3] + mi := &file_sync_sync_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -225,7 +187,7 @@ func (x *GetProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetProofRequest.ProtoReflect.Descriptor instead. func (*GetProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{3} + return file_sync_sync_proto_rawDescGZIP(), []int{2} } func (x *GetProofRequest) GetKey() []byte { @@ -246,7 +208,7 @@ type GetProofResponse struct { func (x *GetProofResponse) Reset() { *x = GetProofResponse{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[4] + mi := &file_sync_sync_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -259,7 +221,7 @@ func (x *GetProofResponse) String() string { func (*GetProofResponse) ProtoMessage() {} func (x *GetProofResponse) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[4] + mi := &file_sync_sync_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -272,7 +234,7 @@ func (x *GetProofResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetProofResponse.ProtoReflect.Descriptor instead. func (*GetProofResponse) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{4} + return file_sync_sync_proto_rawDescGZIP(), []int{3} } func (x *GetProofResponse) GetProof() *Proof { @@ -295,7 +257,7 @@ type Proof struct { func (x *Proof) Reset() { *x = Proof{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[5] + mi := &file_sync_sync_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -308,7 +270,7 @@ func (x *Proof) String() string { func (*Proof) ProtoMessage() {} func (x *Proof) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[5] + mi := &file_sync_sync_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -321,7 +283,7 @@ func (x *Proof) ProtoReflect() protoreflect.Message { // Deprecated: Use Proof.ProtoReflect.Descriptor instead. func (*Proof) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{5} + return file_sync_sync_proto_rawDescGZIP(), []int{4} } func (x *Proof) GetKey() []byte { @@ -363,7 +325,7 @@ type SyncGetChangeProofRequest struct { func (x *SyncGetChangeProofRequest) Reset() { *x = SyncGetChangeProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[6] + mi := &file_sync_sync_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -376,7 +338,7 @@ func (x *SyncGetChangeProofRequest) String() string { func (*SyncGetChangeProofRequest) ProtoMessage() {} func (x *SyncGetChangeProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[6] + mi := &file_sync_sync_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -389,7 +351,7 @@ func (x *SyncGetChangeProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use SyncGetChangeProofRequest.ProtoReflect.Descriptor instead. func (*SyncGetChangeProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{6} + return file_sync_sync_proto_rawDescGZIP(), []int{5} } func (x *SyncGetChangeProofRequest) GetStartRootHash() []byte { @@ -449,7 +411,7 @@ type SyncGetChangeProofResponse struct { func (x *SyncGetChangeProofResponse) Reset() { *x = SyncGetChangeProofResponse{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[7] + mi := &file_sync_sync_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -462,7 +424,7 @@ func (x *SyncGetChangeProofResponse) String() string { func (*SyncGetChangeProofResponse) ProtoMessage() {} func (x *SyncGetChangeProofResponse) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[7] + mi := &file_sync_sync_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -475,7 +437,7 @@ func (x *SyncGetChangeProofResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use SyncGetChangeProofResponse.ProtoReflect.Descriptor instead. func (*SyncGetChangeProofResponse) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{7} + return file_sync_sync_proto_rawDescGZIP(), []int{6} } func (m *SyncGetChangeProofResponse) GetResponse() isSyncGetChangeProofResponse_Response { @@ -530,7 +492,7 @@ type GetChangeProofRequest struct { func (x *GetChangeProofRequest) Reset() { *x = GetChangeProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[8] + mi := &file_sync_sync_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -543,7 +505,7 @@ func (x *GetChangeProofRequest) String() string { func (*GetChangeProofRequest) ProtoMessage() {} func (x *GetChangeProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[8] + mi := &file_sync_sync_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -556,7 +518,7 @@ func (x *GetChangeProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetChangeProofRequest.ProtoReflect.Descriptor instead. func (*GetChangeProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{8} + return file_sync_sync_proto_rawDescGZIP(), []int{7} } func (x *GetChangeProofRequest) GetStartRootHash() []byte { @@ -609,7 +571,7 @@ type GetChangeProofResponse struct { func (x *GetChangeProofResponse) Reset() { *x = GetChangeProofResponse{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[9] + mi := &file_sync_sync_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -622,7 +584,7 @@ func (x *GetChangeProofResponse) String() string { func (*GetChangeProofResponse) ProtoMessage() {} func (x *GetChangeProofResponse) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[9] + mi := &file_sync_sync_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -635,7 +597,7 @@ func (x *GetChangeProofResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetChangeProofResponse.ProtoReflect.Descriptor instead. func (*GetChangeProofResponse) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{9} + return file_sync_sync_proto_rawDescGZIP(), []int{8} } func (m *GetChangeProofResponse) GetResponse() isGetChangeProofResponse_Response { @@ -690,7 +652,7 @@ type VerifyChangeProofRequest struct { func (x *VerifyChangeProofRequest) Reset() { *x = VerifyChangeProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[10] + mi := &file_sync_sync_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -703,7 +665,7 @@ func (x *VerifyChangeProofRequest) String() string { func (*VerifyChangeProofRequest) ProtoMessage() {} func (x *VerifyChangeProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[10] + mi := &file_sync_sync_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -716,7 +678,7 @@ func (x *VerifyChangeProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use VerifyChangeProofRequest.ProtoReflect.Descriptor instead. func (*VerifyChangeProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{10} + return file_sync_sync_proto_rawDescGZIP(), []int{9} } func (x *VerifyChangeProofRequest) GetProof() *ChangeProof { @@ -759,7 +721,7 @@ type VerifyChangeProofResponse struct { func (x *VerifyChangeProofResponse) Reset() { *x = VerifyChangeProofResponse{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[11] + mi := &file_sync_sync_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -772,7 +734,7 @@ func (x *VerifyChangeProofResponse) String() string { func (*VerifyChangeProofResponse) ProtoMessage() {} func (x *VerifyChangeProofResponse) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[11] + mi := &file_sync_sync_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -785,7 +747,7 @@ func (x *VerifyChangeProofResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use VerifyChangeProofResponse.ProtoReflect.Descriptor instead. func (*VerifyChangeProofResponse) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{11} + return file_sync_sync_proto_rawDescGZIP(), []int{10} } func (x *VerifyChangeProofResponse) GetError() string { @@ -806,7 +768,7 @@ type CommitChangeProofRequest struct { func (x *CommitChangeProofRequest) Reset() { *x = CommitChangeProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[12] + mi := &file_sync_sync_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -819,7 +781,7 @@ func (x *CommitChangeProofRequest) String() string { func (*CommitChangeProofRequest) ProtoMessage() {} func (x *CommitChangeProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[12] + mi := &file_sync_sync_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -832,7 +794,7 @@ func (x *CommitChangeProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use CommitChangeProofRequest.ProtoReflect.Descriptor instead. func (*CommitChangeProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{12} + return file_sync_sync_proto_rawDescGZIP(), []int{11} } func (x *CommitChangeProofRequest) GetProof() *ChangeProof { @@ -859,7 +821,7 @@ type SyncGetRangeProofRequest struct { func (x *SyncGetRangeProofRequest) Reset() { *x = SyncGetRangeProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[13] + mi := &file_sync_sync_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -872,7 +834,7 @@ func (x *SyncGetRangeProofRequest) String() string { func (*SyncGetRangeProofRequest) ProtoMessage() {} func (x *SyncGetRangeProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[13] + mi := &file_sync_sync_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -885,7 +847,7 @@ func (x *SyncGetRangeProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use SyncGetRangeProofRequest.ProtoReflect.Descriptor instead. func (*SyncGetRangeProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{13} + return file_sync_sync_proto_rawDescGZIP(), []int{12} } func (x *SyncGetRangeProofRequest) GetRootHash() []byte { @@ -937,7 +899,7 @@ type GetRangeProofRequest struct { func (x *GetRangeProofRequest) Reset() { *x = GetRangeProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[14] + mi := &file_sync_sync_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -950,7 +912,7 @@ func (x *GetRangeProofRequest) String() string { func (*GetRangeProofRequest) ProtoMessage() {} func (x *GetRangeProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[14] + mi := &file_sync_sync_proto_msgTypes[13] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -963,7 +925,7 @@ func (x *GetRangeProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetRangeProofRequest.ProtoReflect.Descriptor instead. func (*GetRangeProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{14} + return file_sync_sync_proto_rawDescGZIP(), []int{13} } func (x *GetRangeProofRequest) GetRootHash() []byte { @@ -1005,7 +967,7 @@ type GetRangeProofResponse struct { func (x *GetRangeProofResponse) Reset() { *x = GetRangeProofResponse{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[15] + mi := &file_sync_sync_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1018,7 +980,7 @@ func (x *GetRangeProofResponse) String() string { func (*GetRangeProofResponse) ProtoMessage() {} func (x *GetRangeProofResponse) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[15] + mi := &file_sync_sync_proto_msgTypes[14] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1031,7 +993,7 @@ func (x *GetRangeProofResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetRangeProofResponse.ProtoReflect.Descriptor instead. func (*GetRangeProofResponse) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{15} + return file_sync_sync_proto_rawDescGZIP(), []int{14} } func (x *GetRangeProofResponse) GetProof() *RangeProof { @@ -1054,7 +1016,7 @@ type CommitRangeProofRequest struct { func (x *CommitRangeProofRequest) Reset() { *x = CommitRangeProofRequest{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[16] + mi := &file_sync_sync_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1067,7 +1029,7 @@ func (x *CommitRangeProofRequest) String() string { func (*CommitRangeProofRequest) ProtoMessage() {} func (x *CommitRangeProofRequest) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[16] + mi := &file_sync_sync_proto_msgTypes[15] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1080,7 +1042,7 @@ func (x *CommitRangeProofRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use CommitRangeProofRequest.ProtoReflect.Descriptor instead. func (*CommitRangeProofRequest) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{16} + return file_sync_sync_proto_rawDescGZIP(), []int{15} } func (x *CommitRangeProofRequest) GetStartKey() *MaybeBytes { @@ -1117,7 +1079,7 @@ type ChangeProof struct { func (x *ChangeProof) Reset() { *x = ChangeProof{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[17] + mi := &file_sync_sync_proto_msgTypes[16] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1130,7 +1092,7 @@ func (x *ChangeProof) String() string { func (*ChangeProof) ProtoMessage() {} func (x *ChangeProof) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[17] + mi := &file_sync_sync_proto_msgTypes[16] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1143,7 +1105,7 @@ func (x *ChangeProof) ProtoReflect() protoreflect.Message { // Deprecated: Use ChangeProof.ProtoReflect.Descriptor instead. func (*ChangeProof) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{17} + return file_sync_sync_proto_rawDescGZIP(), []int{16} } func (x *ChangeProof) GetStartProof() []*ProofNode { @@ -1180,7 +1142,7 @@ type RangeProof struct { func (x *RangeProof) Reset() { *x = RangeProof{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[18] + mi := &file_sync_sync_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1193,7 +1155,7 @@ func (x *RangeProof) String() string { func (*RangeProof) ProtoMessage() {} func (x *RangeProof) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[18] + mi := &file_sync_sync_proto_msgTypes[17] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1206,7 +1168,7 @@ func (x *RangeProof) ProtoReflect() protoreflect.Message { // Deprecated: Use RangeProof.ProtoReflect.Descriptor instead. func (*RangeProof) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{18} + return file_sync_sync_proto_rawDescGZIP(), []int{17} } func (x *RangeProof) GetStartProof() []*ProofNode { @@ -1243,7 +1205,7 @@ type ProofNode struct { func (x *ProofNode) Reset() { *x = ProofNode{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[19] + mi := &file_sync_sync_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1256,7 +1218,7 @@ func (x *ProofNode) String() string { func (*ProofNode) ProtoMessage() {} func (x *ProofNode) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[19] + mi := &file_sync_sync_proto_msgTypes[18] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1269,7 +1231,7 @@ func (x *ProofNode) ProtoReflect() protoreflect.Message { // Deprecated: Use ProofNode.ProtoReflect.Descriptor instead. func (*ProofNode) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{19} + return file_sync_sync_proto_rawDescGZIP(), []int{18} } func (x *ProofNode) GetKey() *Key { @@ -1305,7 +1267,7 @@ type KeyChange struct { func (x *KeyChange) Reset() { *x = KeyChange{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[20] + mi := &file_sync_sync_proto_msgTypes[19] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1318,7 +1280,7 @@ func (x *KeyChange) String() string { func (*KeyChange) ProtoMessage() {} func (x *KeyChange) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[20] + mi := &file_sync_sync_proto_msgTypes[19] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1331,7 +1293,7 @@ func (x *KeyChange) ProtoReflect() protoreflect.Message { // Deprecated: Use KeyChange.ProtoReflect.Descriptor instead. func (*KeyChange) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{20} + return file_sync_sync_proto_rawDescGZIP(), []int{19} } func (x *KeyChange) GetKey() []byte { @@ -1360,7 +1322,7 @@ type Key struct { func (x *Key) Reset() { *x = Key{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[21] + mi := &file_sync_sync_proto_msgTypes[20] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1373,7 +1335,7 @@ func (x *Key) String() string { func (*Key) ProtoMessage() {} func (x *Key) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[21] + mi := &file_sync_sync_proto_msgTypes[20] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1386,7 +1348,7 @@ func (x *Key) ProtoReflect() protoreflect.Message { // Deprecated: Use Key.ProtoReflect.Descriptor instead. func (*Key) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{21} + return file_sync_sync_proto_rawDescGZIP(), []int{20} } func (x *Key) GetLength() uint64 { @@ -1417,7 +1379,7 @@ type MaybeBytes struct { func (x *MaybeBytes) Reset() { *x = MaybeBytes{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[22] + mi := &file_sync_sync_proto_msgTypes[21] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1430,7 +1392,7 @@ func (x *MaybeBytes) String() string { func (*MaybeBytes) ProtoMessage() {} func (x *MaybeBytes) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[22] + mi := &file_sync_sync_proto_msgTypes[21] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1443,7 +1405,7 @@ func (x *MaybeBytes) ProtoReflect() protoreflect.Message { // Deprecated: Use MaybeBytes.ProtoReflect.Descriptor instead. func (*MaybeBytes) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{22} + return file_sync_sync_proto_rawDescGZIP(), []int{21} } func (x *MaybeBytes) GetValue() []byte { @@ -1472,7 +1434,7 @@ type KeyValue struct { func (x *KeyValue) Reset() { *x = KeyValue{} if protoimpl.UnsafeEnabled { - mi := &file_sync_sync_proto_msgTypes[23] + mi := &file_sync_sync_proto_msgTypes[22] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1485,7 +1447,7 @@ func (x *KeyValue) String() string { func (*KeyValue) ProtoMessage() {} func (x *KeyValue) ProtoReflect() protoreflect.Message { - mi := &file_sync_sync_proto_msgTypes[23] + mi := &file_sync_sync_proto_msgTypes[22] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1498,7 +1460,7 @@ func (x *KeyValue) ProtoReflect() protoreflect.Message { // Deprecated: Use KeyValue.ProtoReflect.Descriptor instead. func (*KeyValue) Descriptor() ([]byte, []int) { - return file_sync_sync_proto_rawDescGZIP(), []int{23} + return file_sync_sync_proto_rawDescGZIP(), []int{22} } func (x *KeyValue) GetKey() []byte { @@ -1536,8 +1498,7 @@ var file_sync_sync_proto_rawDesc = []byte{ 0x67, 0x65, 0x22, 0x34, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, - 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x22, 0x0e, 0x0a, 0x0c, 0x43, 0x6c, 0x65, 0x61, - 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x23, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x50, + 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x22, 0x23, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x35, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, @@ -1705,47 +1666,47 @@ var file_sync_sync_proto_rawDesc = []byte{ 0x4e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x22, 0x32, 0x0a, 0x08, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x32, 0xbf, 0x04, 0x0a, 0x02, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x32, 0xc3, 0x04, 0x0a, 0x02, 0x44, 0x42, 0x12, 0x44, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x33, 0x0a, 0x05, 0x43, 0x6c, 0x65, 0x61, - 0x72, 0x12, 0x12, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6c, 0x65, 0x61, 0x72, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x39, 0x0a, - 0x08, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x15, 0x2e, 0x73, 0x79, 0x6e, 0x63, - 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x16, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x43, - 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1b, 0x2e, 0x73, 0x79, 0x6e, - 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, - 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x54, 0x0a, 0x11, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, - 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, - 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x73, 0x79, 0x6e, - 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, - 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x11, 0x43, - 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, - 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, - 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, - 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x48, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, - 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1a, 0x2e, 0x73, 0x79, 0x6e, 0x63, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x37, 0x0a, 0x05, 0x43, 0x6c, 0x65, 0x61, + 0x72, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, + 0x79, 0x12, 0x39, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x15, 0x2e, + 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x0e, + 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1b, + 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x73, 0x79, + 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, + 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x54, 0x0a, 0x11, 0x56, 0x65, 0x72, + 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, + 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, + 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, + 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, + 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x4b, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, + 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x48, 0x0a, 0x0d, + 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1a, 0x2e, + 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, - 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x49, 0x0a, 0x10, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, - 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x2f, 0x5a, - 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x76, 0x61, 0x2d, - 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x61, 0x76, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x67, 0x6f, - 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x62, 0x2f, 0x73, 0x79, 0x6e, 0x63, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, 0x10, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, + 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1d, 0x2e, 0x73, 0x79, 0x6e, + 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, + 0x79, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x61, 0x76, 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x61, 0x76, 0x61, 0x6c, 0x61, 0x6e, 0x63, + 0x68, 0x65, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x62, 0x2f, 0x73, 0x79, + 0x6e, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1760,86 +1721,85 @@ func file_sync_sync_proto_rawDescGZIP() []byte { return file_sync_sync_proto_rawDescData } -var file_sync_sync_proto_msgTypes = make([]protoimpl.MessageInfo, 25) +var file_sync_sync_proto_msgTypes = make([]protoimpl.MessageInfo, 24) var file_sync_sync_proto_goTypes = []interface{}{ (*Request)(nil), // 0: sync.Request (*GetMerkleRootResponse)(nil), // 1: sync.GetMerkleRootResponse - (*ClearRequest)(nil), // 2: sync.ClearRequest - (*GetProofRequest)(nil), // 3: sync.GetProofRequest - (*GetProofResponse)(nil), // 4: sync.GetProofResponse - (*Proof)(nil), // 5: sync.Proof - (*SyncGetChangeProofRequest)(nil), // 6: sync.SyncGetChangeProofRequest - (*SyncGetChangeProofResponse)(nil), // 7: sync.SyncGetChangeProofResponse - (*GetChangeProofRequest)(nil), // 8: sync.GetChangeProofRequest - (*GetChangeProofResponse)(nil), // 9: sync.GetChangeProofResponse - (*VerifyChangeProofRequest)(nil), // 10: sync.VerifyChangeProofRequest - (*VerifyChangeProofResponse)(nil), // 11: sync.VerifyChangeProofResponse - (*CommitChangeProofRequest)(nil), // 12: sync.CommitChangeProofRequest - (*SyncGetRangeProofRequest)(nil), // 13: sync.SyncGetRangeProofRequest - (*GetRangeProofRequest)(nil), // 14: sync.GetRangeProofRequest - (*GetRangeProofResponse)(nil), // 15: sync.GetRangeProofResponse - (*CommitRangeProofRequest)(nil), // 16: sync.CommitRangeProofRequest - (*ChangeProof)(nil), // 17: sync.ChangeProof - (*RangeProof)(nil), // 18: sync.RangeProof - (*ProofNode)(nil), // 19: sync.ProofNode - (*KeyChange)(nil), // 20: sync.KeyChange - (*Key)(nil), // 21: sync.Key - (*MaybeBytes)(nil), // 22: sync.MaybeBytes - (*KeyValue)(nil), // 23: sync.KeyValue - nil, // 24: sync.ProofNode.ChildrenEntry - (*emptypb.Empty)(nil), // 25: google.protobuf.Empty + (*GetProofRequest)(nil), // 2: sync.GetProofRequest + (*GetProofResponse)(nil), // 3: sync.GetProofResponse + (*Proof)(nil), // 4: sync.Proof + (*SyncGetChangeProofRequest)(nil), // 5: sync.SyncGetChangeProofRequest + (*SyncGetChangeProofResponse)(nil), // 6: sync.SyncGetChangeProofResponse + (*GetChangeProofRequest)(nil), // 7: sync.GetChangeProofRequest + (*GetChangeProofResponse)(nil), // 8: sync.GetChangeProofResponse + (*VerifyChangeProofRequest)(nil), // 9: sync.VerifyChangeProofRequest + (*VerifyChangeProofResponse)(nil), // 10: sync.VerifyChangeProofResponse + (*CommitChangeProofRequest)(nil), // 11: sync.CommitChangeProofRequest + (*SyncGetRangeProofRequest)(nil), // 12: sync.SyncGetRangeProofRequest + (*GetRangeProofRequest)(nil), // 13: sync.GetRangeProofRequest + (*GetRangeProofResponse)(nil), // 14: sync.GetRangeProofResponse + (*CommitRangeProofRequest)(nil), // 15: sync.CommitRangeProofRequest + (*ChangeProof)(nil), // 16: sync.ChangeProof + (*RangeProof)(nil), // 17: sync.RangeProof + (*ProofNode)(nil), // 18: sync.ProofNode + (*KeyChange)(nil), // 19: sync.KeyChange + (*Key)(nil), // 20: sync.Key + (*MaybeBytes)(nil), // 21: sync.MaybeBytes + (*KeyValue)(nil), // 22: sync.KeyValue + nil, // 23: sync.ProofNode.ChildrenEntry + (*emptypb.Empty)(nil), // 24: google.protobuf.Empty } var file_sync_sync_proto_depIdxs = []int32{ - 13, // 0: sync.Request.range_proof_request:type_name -> sync.SyncGetRangeProofRequest - 6, // 1: sync.Request.change_proof_request:type_name -> sync.SyncGetChangeProofRequest - 5, // 2: sync.GetProofResponse.proof:type_name -> sync.Proof - 22, // 3: sync.Proof.value:type_name -> sync.MaybeBytes - 19, // 4: sync.Proof.proof:type_name -> sync.ProofNode - 22, // 5: sync.SyncGetChangeProofRequest.start_key:type_name -> sync.MaybeBytes - 22, // 6: sync.SyncGetChangeProofRequest.end_key:type_name -> sync.MaybeBytes - 17, // 7: sync.SyncGetChangeProofResponse.change_proof:type_name -> sync.ChangeProof - 18, // 8: sync.SyncGetChangeProofResponse.range_proof:type_name -> sync.RangeProof - 22, // 9: sync.GetChangeProofRequest.start_key:type_name -> sync.MaybeBytes - 22, // 10: sync.GetChangeProofRequest.end_key:type_name -> sync.MaybeBytes - 17, // 11: sync.GetChangeProofResponse.change_proof:type_name -> sync.ChangeProof - 17, // 12: sync.VerifyChangeProofRequest.proof:type_name -> sync.ChangeProof - 22, // 13: sync.VerifyChangeProofRequest.start_key:type_name -> sync.MaybeBytes - 22, // 14: sync.VerifyChangeProofRequest.end_key:type_name -> sync.MaybeBytes - 17, // 15: sync.CommitChangeProofRequest.proof:type_name -> sync.ChangeProof - 22, // 16: sync.SyncGetRangeProofRequest.start_key:type_name -> sync.MaybeBytes - 22, // 17: sync.SyncGetRangeProofRequest.end_key:type_name -> sync.MaybeBytes - 22, // 18: sync.GetRangeProofRequest.start_key:type_name -> sync.MaybeBytes - 22, // 19: sync.GetRangeProofRequest.end_key:type_name -> sync.MaybeBytes - 18, // 20: sync.GetRangeProofResponse.proof:type_name -> sync.RangeProof - 22, // 21: sync.CommitRangeProofRequest.start_key:type_name -> sync.MaybeBytes - 22, // 22: sync.CommitRangeProofRequest.end_key:type_name -> sync.MaybeBytes - 18, // 23: sync.CommitRangeProofRequest.range_proof:type_name -> sync.RangeProof - 19, // 24: sync.ChangeProof.start_proof:type_name -> sync.ProofNode - 19, // 25: sync.ChangeProof.end_proof:type_name -> sync.ProofNode - 20, // 26: sync.ChangeProof.key_changes:type_name -> sync.KeyChange - 19, // 27: sync.RangeProof.start_proof:type_name -> sync.ProofNode - 19, // 28: sync.RangeProof.end_proof:type_name -> sync.ProofNode - 23, // 29: sync.RangeProof.key_values:type_name -> sync.KeyValue - 21, // 30: sync.ProofNode.key:type_name -> sync.Key - 22, // 31: sync.ProofNode.value_or_hash:type_name -> sync.MaybeBytes - 24, // 32: sync.ProofNode.children:type_name -> sync.ProofNode.ChildrenEntry - 22, // 33: sync.KeyChange.value:type_name -> sync.MaybeBytes - 25, // 34: sync.DB.GetMerkleRoot:input_type -> google.protobuf.Empty - 2, // 35: sync.DB.Clear:input_type -> sync.ClearRequest - 3, // 36: sync.DB.GetProof:input_type -> sync.GetProofRequest - 8, // 37: sync.DB.GetChangeProof:input_type -> sync.GetChangeProofRequest - 10, // 38: sync.DB.VerifyChangeProof:input_type -> sync.VerifyChangeProofRequest - 12, // 39: sync.DB.CommitChangeProof:input_type -> sync.CommitChangeProofRequest - 14, // 40: sync.DB.GetRangeProof:input_type -> sync.GetRangeProofRequest - 16, // 41: sync.DB.CommitRangeProof:input_type -> sync.CommitRangeProofRequest + 12, // 0: sync.Request.range_proof_request:type_name -> sync.SyncGetRangeProofRequest + 5, // 1: sync.Request.change_proof_request:type_name -> sync.SyncGetChangeProofRequest + 4, // 2: sync.GetProofResponse.proof:type_name -> sync.Proof + 21, // 3: sync.Proof.value:type_name -> sync.MaybeBytes + 18, // 4: sync.Proof.proof:type_name -> sync.ProofNode + 21, // 5: sync.SyncGetChangeProofRequest.start_key:type_name -> sync.MaybeBytes + 21, // 6: sync.SyncGetChangeProofRequest.end_key:type_name -> sync.MaybeBytes + 16, // 7: sync.SyncGetChangeProofResponse.change_proof:type_name -> sync.ChangeProof + 17, // 8: sync.SyncGetChangeProofResponse.range_proof:type_name -> sync.RangeProof + 21, // 9: sync.GetChangeProofRequest.start_key:type_name -> sync.MaybeBytes + 21, // 10: sync.GetChangeProofRequest.end_key:type_name -> sync.MaybeBytes + 16, // 11: sync.GetChangeProofResponse.change_proof:type_name -> sync.ChangeProof + 16, // 12: sync.VerifyChangeProofRequest.proof:type_name -> sync.ChangeProof + 21, // 13: sync.VerifyChangeProofRequest.start_key:type_name -> sync.MaybeBytes + 21, // 14: sync.VerifyChangeProofRequest.end_key:type_name -> sync.MaybeBytes + 16, // 15: sync.CommitChangeProofRequest.proof:type_name -> sync.ChangeProof + 21, // 16: sync.SyncGetRangeProofRequest.start_key:type_name -> sync.MaybeBytes + 21, // 17: sync.SyncGetRangeProofRequest.end_key:type_name -> sync.MaybeBytes + 21, // 18: sync.GetRangeProofRequest.start_key:type_name -> sync.MaybeBytes + 21, // 19: sync.GetRangeProofRequest.end_key:type_name -> sync.MaybeBytes + 17, // 20: sync.GetRangeProofResponse.proof:type_name -> sync.RangeProof + 21, // 21: sync.CommitRangeProofRequest.start_key:type_name -> sync.MaybeBytes + 21, // 22: sync.CommitRangeProofRequest.end_key:type_name -> sync.MaybeBytes + 17, // 23: sync.CommitRangeProofRequest.range_proof:type_name -> sync.RangeProof + 18, // 24: sync.ChangeProof.start_proof:type_name -> sync.ProofNode + 18, // 25: sync.ChangeProof.end_proof:type_name -> sync.ProofNode + 19, // 26: sync.ChangeProof.key_changes:type_name -> sync.KeyChange + 18, // 27: sync.RangeProof.start_proof:type_name -> sync.ProofNode + 18, // 28: sync.RangeProof.end_proof:type_name -> sync.ProofNode + 22, // 29: sync.RangeProof.key_values:type_name -> sync.KeyValue + 20, // 30: sync.ProofNode.key:type_name -> sync.Key + 21, // 31: sync.ProofNode.value_or_hash:type_name -> sync.MaybeBytes + 23, // 32: sync.ProofNode.children:type_name -> sync.ProofNode.ChildrenEntry + 21, // 33: sync.KeyChange.value:type_name -> sync.MaybeBytes + 24, // 34: sync.DB.GetMerkleRoot:input_type -> google.protobuf.Empty + 24, // 35: sync.DB.Clear:input_type -> google.protobuf.Empty + 2, // 36: sync.DB.GetProof:input_type -> sync.GetProofRequest + 7, // 37: sync.DB.GetChangeProof:input_type -> sync.GetChangeProofRequest + 9, // 38: sync.DB.VerifyChangeProof:input_type -> sync.VerifyChangeProofRequest + 11, // 39: sync.DB.CommitChangeProof:input_type -> sync.CommitChangeProofRequest + 13, // 40: sync.DB.GetRangeProof:input_type -> sync.GetRangeProofRequest + 15, // 41: sync.DB.CommitRangeProof:input_type -> sync.CommitRangeProofRequest 1, // 42: sync.DB.GetMerkleRoot:output_type -> sync.GetMerkleRootResponse - 25, // 43: sync.DB.Clear:output_type -> google.protobuf.Empty - 4, // 44: sync.DB.GetProof:output_type -> sync.GetProofResponse - 9, // 45: sync.DB.GetChangeProof:output_type -> sync.GetChangeProofResponse - 11, // 46: sync.DB.VerifyChangeProof:output_type -> sync.VerifyChangeProofResponse - 25, // 47: sync.DB.CommitChangeProof:output_type -> google.protobuf.Empty - 15, // 48: sync.DB.GetRangeProof:output_type -> sync.GetRangeProofResponse - 25, // 49: sync.DB.CommitRangeProof:output_type -> google.protobuf.Empty + 24, // 43: sync.DB.Clear:output_type -> google.protobuf.Empty + 3, // 44: sync.DB.GetProof:output_type -> sync.GetProofResponse + 8, // 45: sync.DB.GetChangeProof:output_type -> sync.GetChangeProofResponse + 10, // 46: sync.DB.VerifyChangeProof:output_type -> sync.VerifyChangeProofResponse + 24, // 47: sync.DB.CommitChangeProof:output_type -> google.protobuf.Empty + 14, // 48: sync.DB.GetRangeProof:output_type -> sync.GetRangeProofResponse + 24, // 49: sync.DB.CommitRangeProof:output_type -> google.protobuf.Empty 42, // [42:50] is the sub-list for method output_type 34, // [34:42] is the sub-list for method input_type 34, // [34:34] is the sub-list for extension type_name @@ -1878,18 +1838,6 @@ func file_sync_sync_proto_init() { } } file_sync_sync_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ClearRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_sync_sync_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetProofRequest); i { case 0: return &v.state @@ -1901,7 +1849,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetProofResponse); i { case 0: return &v.state @@ -1913,7 +1861,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Proof); i { case 0: return &v.state @@ -1925,7 +1873,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SyncGetChangeProofRequest); i { case 0: return &v.state @@ -1937,7 +1885,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SyncGetChangeProofResponse); i { case 0: return &v.state @@ -1949,7 +1897,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetChangeProofRequest); i { case 0: return &v.state @@ -1961,7 +1909,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetChangeProofResponse); i { case 0: return &v.state @@ -1973,7 +1921,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*VerifyChangeProofRequest); i { case 0: return &v.state @@ -1985,7 +1933,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*VerifyChangeProofResponse); i { case 0: return &v.state @@ -1997,7 +1945,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*CommitChangeProofRequest); i { case 0: return &v.state @@ -2009,7 +1957,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SyncGetRangeProofRequest); i { case 0: return &v.state @@ -2021,7 +1969,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetRangeProofRequest); i { case 0: return &v.state @@ -2033,7 +1981,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetRangeProofResponse); i { case 0: return &v.state @@ -2045,7 +1993,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*CommitRangeProofRequest); i { case 0: return &v.state @@ -2057,7 +2005,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ChangeProof); i { case 0: return &v.state @@ -2069,7 +2017,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*RangeProof); i { case 0: return &v.state @@ -2081,7 +2029,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ProofNode); i { case 0: return &v.state @@ -2093,7 +2041,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*KeyChange); i { case 0: return &v.state @@ -2105,7 +2053,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Key); i { case 0: return &v.state @@ -2117,7 +2065,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*MaybeBytes); i { case 0: return &v.state @@ -2129,7 +2077,7 @@ func file_sync_sync_proto_init() { return nil } } - file_sync_sync_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} { + file_sync_sync_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*KeyValue); i { case 0: return &v.state @@ -2146,11 +2094,11 @@ func file_sync_sync_proto_init() { (*Request_RangeProofRequest)(nil), (*Request_ChangeProofRequest)(nil), } - file_sync_sync_proto_msgTypes[7].OneofWrappers = []interface{}{ + file_sync_sync_proto_msgTypes[6].OneofWrappers = []interface{}{ (*SyncGetChangeProofResponse_ChangeProof)(nil), (*SyncGetChangeProofResponse_RangeProof)(nil), } - file_sync_sync_proto_msgTypes[9].OneofWrappers = []interface{}{ + file_sync_sync_proto_msgTypes[8].OneofWrappers = []interface{}{ (*GetChangeProofResponse_ChangeProof)(nil), (*GetChangeProofResponse_RootNotPresent)(nil), } @@ -2160,7 +2108,7 @@ func file_sync_sync_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_sync_sync_proto_rawDesc, NumEnums: 0, - NumMessages: 25, + NumMessages: 24, NumExtensions: 0, NumServices: 1, }, diff --git a/proto/pb/sync/sync_grpc.pb.go b/proto/pb/sync/sync_grpc.pb.go index eee9714f6d34..5f79687b4d01 100644 --- a/proto/pb/sync/sync_grpc.pb.go +++ b/proto/pb/sync/sync_grpc.pb.go @@ -35,7 +35,7 @@ const ( // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type DBClient interface { GetMerkleRoot(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GetMerkleRootResponse, error) - Clear(ctx context.Context, in *ClearRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) + Clear(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) GetProof(ctx context.Context, in *GetProofRequest, opts ...grpc.CallOption) (*GetProofResponse, error) GetChangeProof(ctx context.Context, in *GetChangeProofRequest, opts ...grpc.CallOption) (*GetChangeProofResponse, error) VerifyChangeProof(ctx context.Context, in *VerifyChangeProofRequest, opts ...grpc.CallOption) (*VerifyChangeProofResponse, error) @@ -61,7 +61,7 @@ func (c *dBClient) GetMerkleRoot(ctx context.Context, in *emptypb.Empty, opts .. return out, nil } -func (c *dBClient) Clear(ctx context.Context, in *ClearRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { +func (c *dBClient) Clear(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) { out := new(emptypb.Empty) err := c.cc.Invoke(ctx, DB_Clear_FullMethodName, in, out, opts...) if err != nil { @@ -129,7 +129,7 @@ func (c *dBClient) CommitRangeProof(ctx context.Context, in *CommitRangeProofReq // for forward compatibility type DBServer interface { GetMerkleRoot(context.Context, *emptypb.Empty) (*GetMerkleRootResponse, error) - Clear(context.Context, *ClearRequest) (*emptypb.Empty, error) + Clear(context.Context, *emptypb.Empty) (*emptypb.Empty, error) GetProof(context.Context, *GetProofRequest) (*GetProofResponse, error) GetChangeProof(context.Context, *GetChangeProofRequest) (*GetChangeProofResponse, error) VerifyChangeProof(context.Context, *VerifyChangeProofRequest) (*VerifyChangeProofResponse, error) @@ -146,7 +146,7 @@ type UnimplementedDBServer struct { func (UnimplementedDBServer) GetMerkleRoot(context.Context, *emptypb.Empty) (*GetMerkleRootResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetMerkleRoot not implemented") } -func (UnimplementedDBServer) Clear(context.Context, *ClearRequest) (*emptypb.Empty, error) { +func (UnimplementedDBServer) Clear(context.Context, *emptypb.Empty) (*emptypb.Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method Clear not implemented") } func (UnimplementedDBServer) GetProof(context.Context, *GetProofRequest) (*GetProofResponse, error) { @@ -199,7 +199,7 @@ func _DB_GetMerkleRoot_Handler(srv interface{}, ctx context.Context, dec func(in } func _DB_Clear_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ClearRequest) + in := new(emptypb.Empty) if err := dec(in); err != nil { return nil, err } @@ -211,7 +211,7 @@ func _DB_Clear_Handler(srv interface{}, ctx context.Context, dec func(interface{ FullMethod: DB_Clear_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(DBServer).Clear(ctx, req.(*ClearRequest)) + return srv.(DBServer).Clear(ctx, req.(*emptypb.Empty)) } return interceptor(ctx, in, info, handler) } diff --git a/proto/sync/sync.proto b/proto/sync/sync.proto index 0f91825a7410..1a799433d7e7 100644 --- a/proto/sync/sync.proto +++ b/proto/sync/sync.proto @@ -21,7 +21,7 @@ message Request { service DB { rpc GetMerkleRoot(google.protobuf.Empty) returns (GetMerkleRootResponse); - rpc Clear(ClearRequest) returns (google.protobuf.Empty); + rpc Clear(google.protobuf.Empty) returns (google.protobuf.Empty); rpc GetProof(GetProofRequest) returns (GetProofResponse); @@ -37,8 +37,6 @@ message GetMerkleRootResponse { bytes root_hash = 1; } -message ClearRequest {} - message GetProofRequest { bytes key = 1; } diff --git a/x/sync/g_db/db_client.go b/x/sync/g_db/db_client.go index c31e218f072e..df9b6e050e39 100644 --- a/x/sync/g_db/db_client.go +++ b/x/sync/g_db/db_client.go @@ -187,6 +187,6 @@ func (c *DBClient) CommitRangeProof( } func (c *DBClient) Clear() error { - _, err := c.client.Clear(context.Background(), &pb.ClearRequest{}) + _, err := c.client.Clear(context.Background(), &emptypb.Empty{}) return err } diff --git a/x/sync/g_db/db_server.go b/x/sync/g_db/db_server.go index 30829a0369d9..f5bd3fd56253 100644 --- a/x/sync/g_db/db_server.go +++ b/x/sync/g_db/db_server.go @@ -221,7 +221,7 @@ func (s *DBServer) CommitRangeProof( func (s *DBServer) Clear( _ context.Context, - req *pb.ClearRequest, + req *emptypb.Empty, ) (*emptypb.Empty, error) { return &emptypb.Empty{}, s.db.Clear() } From d1e0c5e130a299ecb5248b5733539123c93d2414 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 2 Nov 2023 11:34:47 -0400 Subject: [PATCH 096/131] appease linter --- x/sync/g_db/db_server.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/x/sync/g_db/db_server.go b/x/sync/g_db/db_server.go index f5bd3fd56253..b493474c128c 100644 --- a/x/sync/g_db/db_server.go +++ b/x/sync/g_db/db_server.go @@ -219,9 +219,6 @@ func (s *DBServer) CommitRangeProof( return &emptypb.Empty{}, err } -func (s *DBServer) Clear( - _ context.Context, - req *emptypb.Empty, -) (*emptypb.Empty, error) { +func (s *DBServer) Clear(context.Context, *emptypb.Empty) (*emptypb.Empty, error) { return &emptypb.Empty{}, s.db.Clear() } From a972cada5e27625ecc0eea5f351cc0ac142b2125 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 2 Nov 2023 11:47:10 -0400 Subject: [PATCH 097/131] add newline --- x/merkledb/mock_db.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/merkledb/mock_db.go b/x/merkledb/mock_db.go index c4a038ab556e..e07354e6b3e8 100644 --- a/x/merkledb/mock_db.go +++ b/x/merkledb/mock_db.go @@ -453,4 +453,4 @@ func (m *MockMerkleDB) getValue(arg0 Key) ([]byte, error) { func (mr *MockMerkleDBMockRecorder) getValue(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "getValue", reflect.TypeOf((*MockMerkleDB)(nil).getValue), arg0) -} \ No newline at end of file +} From c62eb9160f05337fe163c0470284d199531e0a3c Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 7 Nov 2023 17:09:31 -0500 Subject: [PATCH 098/131] remove unneeded copy --- x/merkledb/db.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 7dd917238389..27aed5ecb018 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1292,7 +1292,6 @@ func (db *merkleDB) Clear() error { ops := make([]database.BatchOp, len(keysToDelete)) for i, keyToDelete := range keysToDelete { - keyToDelete := keyToDelete ops[i] = database.BatchOp{ Key: keyToDelete, Delete: true, From 348e766bb67d2ea57aa5c5437f819180ab5d83a0 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 7 Nov 2023 18:15:24 -0500 Subject: [PATCH 099/131] don't persist whether the root key has a value --- x/merkledb/codec.go | 55 +++++++++++++--------------------------- x/merkledb/codec_test.go | 44 +++----------------------------- x/merkledb/db.go | 32 ++++++++++++----------- 3 files changed, 39 insertions(+), 92 deletions(-) diff --git a/x/merkledb/codec.go b/x/merkledb/codec.go index c87bb3c49c50..81ce39179695 100644 --- a/x/merkledb/codec.go +++ b/x/merkledb/codec.go @@ -66,13 +66,13 @@ type encoder interface { // Returns the bytes that will be hashed to generate [n]'s ID. // Assumes [n] is non-nil. encodeHashValues(n *node) []byte - encodeKeyAndHasValue(key Key, hasValue bool) []byte + encodeKey(key Key) []byte } type decoder interface { // Assumes [n] is non-nil. decodeDBNode(bytes []byte, n *dbNode) error - decodeKeyAndHasValue(bytes []byte, key *Key, hasValue *bool) error + decodeKey(bytes []byte) (Key, error) } func newCodec() encoderDecoder { @@ -109,7 +109,7 @@ func (c *codecImpl) encodeDBNode(n *dbNode) []byte { for _, index := range keys { entry := n.children[index] c.encodeUint(buf, uint64(index)) - c.encodeKey(buf, entry.compressedKey) + c.encodeKeyToBuffer(buf, entry.compressedKey) _, _ = buf.Write(entry.id[:]) c.encodeBool(buf, entry.hasValue) } @@ -135,22 +135,11 @@ func (c *codecImpl) encodeHashValues(n *node) []byte { _, _ = buf.Write(entry.id[:]) } c.encodeMaybeByteSlice(buf, n.valueDigest) - c.encodeKey(buf, n.key) + c.encodeKeyToBuffer(buf, n.key) return buf.Bytes() } -func (c *codecImpl) encodeKeyAndHasValue(key Key, hasValue bool) []byte { - var ( - estimatedLen = binary.MaxVarintLen64 + len(key.Bytes()) + boolLen - buf = bytes.NewBuffer(make([]byte, 0, estimatedLen)) - ) - - c.encodeKey(buf, key) - c.encodeBool(buf, hasValue) - return buf.Bytes() -} - func (c *codecImpl) decodeDBNode(b []byte, n *dbNode) error { if minDBNodeLen > len(b) { return io.ErrUnexpectedEOF @@ -184,7 +173,7 @@ func (c *codecImpl) decodeDBNode(b []byte, n *dbNode) error { } previousChild = index - compressedKey, err := c.decodeKey(src) + compressedKey, err := c.decodeKeyFromReader(src) if err != nil { return err } @@ -208,25 +197,6 @@ func (c *codecImpl) decodeDBNode(b []byte, n *dbNode) error { return nil } -func (c *codecImpl) decodeKeyAndHasValue(b []byte, key *Key, hasValue *bool) error { - if minKeyLen+boolLen > len(b) { - return io.ErrUnexpectedEOF - } - - var ( - src = bytes.NewReader(b) - err error - ) - - *key, err = c.decodeKey(src) - if err != nil { - return err - } - - *hasValue, err = c.decodeBool(src) - return err -} - func (*codecImpl) encodeBool(dst *bytes.Buffer, value bool) { bytesValue := falseBytes if value { @@ -361,12 +331,23 @@ func (*codecImpl) decodeID(src *bytes.Reader) (ids.ID, error) { return id, err } -func (c *codecImpl) encodeKey(dst *bytes.Buffer, key Key) { +func (c *codecImpl) encodeKey(key Key) []byte { + estimatedLen := binary.MaxVarintLen64 + len(key.Bytes()) + dst := bytes.NewBuffer(make([]byte, 0, estimatedLen)) + c.encodeKeyToBuffer(dst, key) + return dst.Bytes() +} + +func (c *codecImpl) encodeKeyToBuffer(dst *bytes.Buffer, key Key) { c.encodeUint(dst, uint64(key.length)) _, _ = dst.Write(key.Bytes()) } -func (c *codecImpl) decodeKey(src *bytes.Reader) (Key, error) { +func (c *codecImpl) decodeKey(b []byte) (Key, error) { + return c.decodeKeyFromReader(bytes.NewReader(b)) +} + +func (c *codecImpl) decodeKeyFromReader(src *bytes.Reader) (Key, error) { if minKeyLen > src.Len() { return Key{}, io.ErrUnexpectedEOF } diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index 688eeac63d58..4eb4978c2ebb 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -81,21 +81,16 @@ func FuzzCodecKey(f *testing.F) { ) { require := require.New(t) codec := codec.(*codecImpl) - reader := bytes.NewReader(b) - startLen := reader.Len() - got, err := codec.decodeKey(reader) + got, err := codec.decodeKey(b) if err != nil { t.SkipNow() } - endLen := reader.Len() - numRead := startLen - endLen // Encoding [got] should be the same as [b]. var buf bytes.Buffer - codec.encodeKey(&buf, got) + codec.encodeKey(got) bufBytes := buf.Bytes() - require.Len(bufBytes, numRead) - require.Equal(b[:numRead], bufBytes) + require.Equal(b, bufBytes) }, ) } @@ -248,37 +243,6 @@ func FuzzEncodeHashValues(f *testing.F) { func TestCodecDecodeKeyLengthOverflowRegression(t *testing.T) { codec := codec.(*codecImpl) - bytes := bytes.NewReader(binary.AppendUvarint(nil, math.MaxInt)) - _, err := codec.decodeKey(bytes) + _, err := codec.decodeKey(binary.AppendUvarint(nil, math.MaxInt)) require.ErrorIs(t, err, io.ErrUnexpectedEOF) } - -func FuzzEncodeDecodeKeyAndNode(f *testing.F) { - codec := newCodec() - - f.Fuzz( - func( - t *testing.T, - keyBytes []byte, - hasValue bool, - removeToken bool, - ) { - require := require.New(t) - - key := ToKey(keyBytes) - - if removeToken && key.length > 0 { - key = key.Skip(1) - } - - b := codec.encodeKeyAndHasValue(key, hasValue) - var ( - gotKey Key - gotHasValue bool - ) - require.NoError(codec.decodeKeyAndHasValue(b, &gotKey, &gotHasValue)) - require.Equal(key, gotKey) - require.Equal(hasValue, gotHasValue) - }, - ) -} diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 27aed5ecb018..43ea10bd1489 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -981,10 +981,7 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e } db.root = maybe.Some(changes.rootChange.after) - rootKeyAndNodeBytes := codec.encodeKeyAndHasValue( - changes.rootChange.after.key, - changes.rootChange.after.value.HasValue(), - ) + rootKeyAndNodeBytes := codec.encodeKey(changes.rootChange.after.key) return db.baseDB.Put(rootDBKey, rootKeyAndNodeBytes) } @@ -1176,20 +1173,25 @@ func (db *merkleDB) initializeRootIfNeeded() error { } // Root is on disk. - var ( - rootKey Key - rootHasValue bool - ) - if err := codec.decodeKeyAndHasValue( - rootBytes, - &rootKey, - &rootHasValue, - ); err != nil { + rootKey, err := codec.decodeKey(rootBytes) + if err != nil { return err } - root, err := db.getEditableNode(rootKey, rootHasValue) + + var root *node + + // First, see if root is an intermediate node. + root, err = db.getEditableNode(rootKey, false /* hasValue */) if err != nil { - return err + if !errors.Is(err, database.ErrNotFound) { + return err + } + + // The root must be a value node. + root, err = db.getEditableNode(rootKey, true /* hasValue */) + if err != nil { + return err + } } root.calculateID(db.metrics) db.root = maybe.Some(root) From 2f401af5162829a0927a0835e52b8d15804d7e36 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 7 Nov 2023 18:24:37 -0500 Subject: [PATCH 100/131] fix test --- x/merkledb/codec_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index 4eb4978c2ebb..f34186b44fb3 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -87,10 +87,8 @@ func FuzzCodecKey(f *testing.F) { } // Encoding [got] should be the same as [b]. - var buf bytes.Buffer - codec.encodeKey(got) - bufBytes := buf.Bytes() - require.Equal(b, bufBytes) + gotBytes := codec.encodeKey(got) + require.Equal(b, gotBytes) }, ) } From 72747e14c45c8107d8fc03b156fbfbd788ee1e4c Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 7 Nov 2023 18:31:14 -0500 Subject: [PATCH 101/131] check for additional bytes at end of decodeKey --- x/merkledb/codec.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/x/merkledb/codec.go b/x/merkledb/codec.go index 81ce39179695..75ce5696efb5 100644 --- a/x/merkledb/codec.go +++ b/x/merkledb/codec.go @@ -344,7 +344,15 @@ func (c *codecImpl) encodeKeyToBuffer(dst *bytes.Buffer, key Key) { } func (c *codecImpl) decodeKey(b []byte) (Key, error) { - return c.decodeKeyFromReader(bytes.NewReader(b)) + src := bytes.NewReader(b) + key, err := c.decodeKeyFromReader(src) + if err != nil { + return Key{}, err + } + if src.Len() != 0 { + return Key{}, errExtraSpace + } + return key, err } func (c *codecImpl) decodeKeyFromReader(src *bytes.Reader) (Key, error) { From e55499235bf10573a0ecb0f63dbcda272a95d8a0 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 8 Nov 2023 10:16:57 -0500 Subject: [PATCH 102/131] remove errant comment --- x/merkledb/trieview.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 23594937220e..31ab26e46dd6 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -709,7 +709,6 @@ func (t *trieView) remove(key Key) error { // i.e. There's the root and at least one more node. // if the removed node has no children, the node can be removed from the trie - // <<<<<<< HEAD if len(nodeToDelete.children) == 0 { if err := t.recordNodeDeleted(nodeToDelete); err != nil { return err From 974d8a39a6a2852d66828a6ea3c312997a1e32e3 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 8 Nov 2023 11:18:43 -0500 Subject: [PATCH 103/131] change rootChange from *change to change --- x/merkledb/db.go | 2 +- x/merkledb/history.go | 4 ++-- x/merkledb/history_test.go | 2 +- x/merkledb/trieview.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 43ea10bd1489..389573ca76c7 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -270,7 +270,7 @@ func newDatabase( // add current root to history (has no changes) trieDB.history.record(&changeSummary{ rootID: trieDB.getMerkleRoot(), - rootChange: &change[*node]{ + rootChange: change[*node]{ after: trieDB.root.Value(), }, values: map[Key]*change[maybe.Maybe[[]byte]]{}, diff --git a/x/merkledb/history.go b/x/merkledb/history.go index b5fed34dd61f..c40e3b6f7c86 100644 --- a/x/merkledb/history.go +++ b/x/merkledb/history.go @@ -57,7 +57,7 @@ type changeSummary struct { // If the trie is empty before (after) this change, its root // is nil for the before (after) field. // Set in [calculateNodeIDs]. - rootChange *change[*node] + rootChange change[*node] nodes map[Key]*change[*node] values map[Key]*change[maybe.Maybe[[]byte]] } @@ -66,7 +66,7 @@ func newChangeSummary(estimatedSize int) *changeSummary { return &changeSummary{ nodes: make(map[Key]*change[*node], estimatedSize), values: make(map[Key]*change[maybe.Maybe[[]byte]], estimatedSize), - rootChange: &change[*node]{}, + rootChange: change[*node]{}, } } diff --git a/x/merkledb/history_test.go b/x/merkledb/history_test.go index f3b088814e5a..79f8ebc817ce 100644 --- a/x/merkledb/history_test.go +++ b/x/merkledb/history_test.go @@ -653,7 +653,7 @@ func TestHistoryGetChangesToRoot(t *testing.T) { for i := 0; i < maxHistoryLen; i++ { // Fill the history changes = append(changes, &changeSummary{ rootID: ids.GenerateTestID(), - rootChange: &change[*node]{ + rootChange: change[*node]{ before: &node{ id: ids.GenerateTestID(), }, diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 31ab26e46dd6..840055ee8305 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -264,7 +264,7 @@ func (t *trieView) calculateNodeIDs(ctx context.Context) error { t.changes.rootID = ids.Empty } - t.changes.rootChange = &change[*node]{ + t.changes.rootChange = change[*node]{ before: oldRoot, after: t.root.Value(), } From a0473eab820a6d35145d7b92922843b2e2ac10fb Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 8 Nov 2023 11:34:41 -0500 Subject: [PATCH 104/131] change rootChange from change[*node] to change[maybe.Maybe[*node]]; nits --- x/merkledb/db.go | 12 ++++++------ x/merkledb/history.go | 6 ++---- x/merkledb/history_test.go | 6 +++--- x/merkledb/trieview.go | 15 ++++----------- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 389573ca76c7..618abc11a894 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -270,8 +270,8 @@ func newDatabase( // add current root to history (has no changes) trieDB.history.record(&changeSummary{ rootID: trieDB.getMerkleRoot(), - rootChange: change[*node]{ - after: trieDB.root.Value(), + rootChange: change[maybe.Maybe[*node]]{ + after: trieDB.root, }, values: map[Key]*change[maybe.Maybe[[]byte]]{}, nodes: map[Key]*change[*node]{}, @@ -975,13 +975,13 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e db.history.record(changes) // Update root in database. - if changes.rootChange.after == nil { - db.root = maybe.Nothing[*node]() + db.root = changes.rootChange.after + + if changes.rootChange.after.IsNothing() { return db.baseDB.Delete(rootDBKey) } - db.root = maybe.Some(changes.rootChange.after) - rootKeyAndNodeBytes := codec.encodeKey(changes.rootChange.after.key) + rootKeyAndNodeBytes := codec.encodeKey(db.root.Value().key) return db.baseDB.Put(rootDBKey, rootKeyAndNodeBytes) } diff --git a/x/merkledb/history.go b/x/merkledb/history.go index c40e3b6f7c86..7a5a35992f8d 100644 --- a/x/merkledb/history.go +++ b/x/merkledb/history.go @@ -54,10 +54,8 @@ type changeSummary struct { // The ID of the trie after these changes. rootID ids.ID // The root before/after this change. - // If the trie is empty before (after) this change, its root - // is nil for the before (after) field. // Set in [calculateNodeIDs]. - rootChange change[*node] + rootChange change[maybe.Maybe[*node]] nodes map[Key]*change[*node] values map[Key]*change[maybe.Maybe[[]byte]] } @@ -66,7 +64,7 @@ func newChangeSummary(estimatedSize int) *changeSummary { return &changeSummary{ nodes: make(map[Key]*change[*node], estimatedSize), values: make(map[Key]*change[maybe.Maybe[[]byte]], estimatedSize), - rootChange: change[*node]{}, + rootChange: change[maybe.Maybe[*node]]{}, } } diff --git a/x/merkledb/history_test.go b/x/merkledb/history_test.go index 79f8ebc817ce..d82dc36a0328 100644 --- a/x/merkledb/history_test.go +++ b/x/merkledb/history_test.go @@ -653,10 +653,10 @@ func TestHistoryGetChangesToRoot(t *testing.T) { for i := 0; i < maxHistoryLen; i++ { // Fill the history changes = append(changes, &changeSummary{ rootID: ids.GenerateTestID(), - rootChange: change[*node]{ - before: &node{ + rootChange: change[maybe.Maybe[*node]]{ + before: maybe.Some(&node{ id: ids.GenerateTestID(), - }, + }), }, nodes: map[Key]*change[*node]{ ToKey([]byte{byte(i)}): { diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 840055ee8305..f534f3618362 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -197,12 +197,8 @@ func newHistoricalTrieView( return nil, ErrNoChanges } - root := maybe.Nothing[*node]() - if changes.rootChange.after != nil { - root = maybe.Some(changes.rootChange.after) - } newView := &trieView{ - root: root, + root: changes.rootChange.after, db: db, parentTrie: db, changes: changes, @@ -230,10 +226,7 @@ func (t *trieView) calculateNodeIDs(ctx context.Context) error { } defer t.nodesAlreadyCalculated.Set(true) - oldRoot := t.root.Value() - if oldRoot != nil { - oldRoot = oldRoot.clone() - } + oldRoot := maybe.Bind(t.root, (*node).clone) // We wait to create the span until after checking that we need to actually // calculateNodeIDs to make traces more useful (otherwise there may be a span @@ -264,9 +257,9 @@ func (t *trieView) calculateNodeIDs(ctx context.Context) error { t.changes.rootID = ids.Empty } - t.changes.rootChange = change[*node]{ + t.changes.rootChange = change[maybe.Maybe[*node]]{ before: oldRoot, - after: t.root.Value(), + after: t.root, } // ensure no ancestor changes occurred during execution From 41c0b5fc12eaa414a20c06784cd131b65cfd238d Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 8 Nov 2023 12:31:36 -0500 Subject: [PATCH 105/131] nit --- x/merkledb/trieview.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index f534f3618362..20ca2a4bacf3 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -147,9 +147,7 @@ func newTrieView( parentTrie TrieView, changes ViewChanges, ) (*trieView, error) { - root := maybe.Bind(parentTrie.getRoot(), func(n *node) *node { - return n.clone() - }) + root := maybe.Bind(parentTrie.getRoot(), (*node).clone) newView := &trieView{ root: root, From 7ea00cb4ccd12457969f770bd1d0bd42efff7860 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 8 Nov 2023 12:32:00 -0500 Subject: [PATCH 106/131] nit --- x/merkledb/trieview.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 20ca2a4bacf3..3097f9163628 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -147,10 +147,8 @@ func newTrieView( parentTrie TrieView, changes ViewChanges, ) (*trieView, error) { - root := maybe.Bind(parentTrie.getRoot(), (*node).clone) - newView := &trieView{ - root: root, + root: maybe.Bind(parentTrie.getRoot(), (*node).clone), db: db, parentTrie: parentTrie, changes: newChangeSummary(len(changes.BatchOps) + len(changes.MapOps)), From 271ef1bd3e418807a835e5eeb62efa392d043326 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 8 Nov 2023 14:20:02 -0500 Subject: [PATCH 107/131] add and implement Clearer interface for merkledb --- x/merkledb/db.go | 27 +++++++++++++++++++++++++++ x/merkledb/intermediate_node_db.go | 11 +++++++++++ x/merkledb/value_node_db.go | 5 +++++ 3 files changed, 43 insertions(+) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 88dd667ae22a..2fdb59f0ea8a 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -114,6 +114,11 @@ type RangeProofer interface { CommitRangeProof(ctx context.Context, start, end maybe.Maybe[[]byte], proof *RangeProof) error } +type Clearer interface { + // Deletes all key/value pairs from the database. + Clear() error +} + type Prefetcher interface { // PrefetchPath attempts to load all trie nodes on the path of [key] // into the cache. @@ -129,6 +134,7 @@ type Prefetcher interface { type MerkleDB interface { database.Database + Clearer Trie MerkleRootGetter ProofGetter @@ -1250,6 +1256,27 @@ func (db *merkleDB) getNode(key Key, hasValue bool) (*node, error) { return db.intermediateNodeDB.Get(key) } +func (db *merkleDB) Clear() error { + db.commitLock.Lock() + defer db.commitLock.Unlock() + + db.lock.Lock() + defer db.lock.Unlock() + + if err := db.valueNodeDB.Clear(); err != nil { + return err + } + + if err := db.intermediateNodeDB.Clear(); err != nil { + return err + } + + db.root = newNode(Key{}) + db.root.calculateID(db.metrics) + + return db.intermediateNodeDB.Put(db.root.key, db.root) +} + // Returns [key] prefixed by [prefix]. // The returned []byte is taken from [bufferPool] and // should be returned to it when the caller is done with it. diff --git a/x/merkledb/intermediate_node_db.go b/x/merkledb/intermediate_node_db.go index 1602aa05bbaa..cc87edcfa927 100644 --- a/x/merkledb/intermediate_node_db.go +++ b/x/merkledb/intermediate_node_db.go @@ -146,3 +146,14 @@ func (db *intermediateNodeDB) Flush() error { func (db *intermediateNodeDB) Delete(key Key) error { return db.nodeCache.Put(key, nil) } + +func (db *intermediateNodeDB) Clear() error { + // Reset the cache. Note we don't flush because that would cause us to + // persist intermediate nodes we're about to delete. + db.nodeCache = newOnEvictCache( + db.nodeCache.maxSize, + db.nodeCache.size, + db.nodeCache.onEviction, + ) + return database.AtomicClearPrefix(db.baseDB, db.baseDB, valueNodePrefix) +} diff --git a/x/merkledb/value_node_db.go b/x/merkledb/value_node_db.go index 339fa25f78f0..406c9a986dba 100644 --- a/x/merkledb/value_node_db.go +++ b/x/merkledb/value_node_db.go @@ -89,6 +89,11 @@ func (db *valueNodeDB) Get(key Key) (*node, error) { return parseNode(key, nodeBytes) } +func (db *valueNodeDB) Clear() error { + db.nodeCache.Flush() + return database.AtomicClearPrefix(db.baseDB, db.baseDB, valueNodePrefix) +} + // Batch of database operations type valueNodeBatch struct { db *valueNodeDB From ebb4486a514f2af45b0187390c1100a0e09f4cd6 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 8 Nov 2023 14:28:23 -0500 Subject: [PATCH 108/131] nit --- x/merkledb/db.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 2fdb59f0ea8a..75ba084160bd 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1263,11 +1263,11 @@ func (db *merkleDB) Clear() error { db.lock.Lock() defer db.lock.Unlock() - if err := db.valueNodeDB.Clear(); err != nil { + if err := db.intermediateNodeDB.Clear(); err != nil { return err } - if err := db.intermediateNodeDB.Clear(); err != nil { + if err := db.valueNodeDB.Clear(); err != nil { return err } From 70d88a5abd9fe2a086f42f815ecb870af7c6d41a Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 8 Nov 2023 14:48:22 -0500 Subject: [PATCH 109/131] add tests --- x/merkledb/db_test.go | 31 +++++++++++++++++++++++++ x/merkledb/intermediate_node_db_test.go | 29 +++++++++++++++++++++++ x/merkledb/value_node_db_test.go | 31 +++++++++++++++++++++++++ 3 files changed, 91 insertions(+) diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index 2d6439fd294b..a0cd67312ff4 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -773,6 +773,37 @@ func Test_MerkleDB_Random_Insert_Ordering(t *testing.T) { } } +func TestMerkleDBClear(t *testing.T) { + require := require.New(t) + + // Make a database and insert some key-value pairs. + db, err := getBasicDB() + require.NoError(err) + + emptyRootID := db.getMerkleRoot() + + now := time.Now().UnixNano() + t.Logf("seed: %d", now) + r := rand.New(rand.NewSource(now)) // #nosec G404 + + insertRandomKeyValues( + require, + r, + []database.Database{db}, + 1_000, + 0.25, + ) + + // Clear the database. + require.NoError(db.Clear()) + + // Assert that the database is empty. + iter := db.NewIterator() + defer iter.Release() + require.False(iter.Next()) + require.Equal(emptyRootID, db.getMerkleRoot()) +} + func FuzzMerkleDBEmptyRandomizedActions(f *testing.F) { f.Fuzz( func( diff --git a/x/merkledb/intermediate_node_db_test.go b/x/merkledb/intermediate_node_db_test.go index 027798017e95..91709708f148 100644 --- a/x/merkledb/intermediate_node_db_test.go +++ b/x/merkledb/intermediate_node_db_test.go @@ -213,3 +213,32 @@ func Test_IntermediateNodeDB_ConstructDBKey_DirtyBuffer(t *testing.T) { require.Equal(intermediateNodePrefix, constructedKey[:len(intermediateNodePrefix)]) require.Equal(p.Extend(ToToken(1, 4)).Bytes(), constructedKey[len(intermediateNodePrefix):]) } + +func TestIntermediateNodeDBClear(t *testing.T) { + require := require.New(t) + cacheSize := 200 + evictionBatchSize := cacheSize + baseDB := memdb.New() + db := newIntermediateNodeDB( + baseDB, + &sync.Pool{ + New: func() interface{} { return make([]byte, 0) }, + }, + &mockMetrics{}, + cacheSize, + evictionBatchSize, + 4, + ) + + for _, b := range [][]byte{{1}, {2}, {3}} { + require.NoError(db.Put(ToKey(b), newNode(ToKey(b)))) + } + + require.NoError(db.Clear()) + + iter := baseDB.NewIteratorWithPrefix(intermediateNodePrefix) + defer iter.Release() + require.False(iter.Next()) + + require.Zero(db.nodeCache.currentSize) +} diff --git a/x/merkledb/value_node_db_test.go b/x/merkledb/value_node_db_test.go index 96c5b4b038cc..c87f0ab5ebf8 100644 --- a/x/merkledb/value_node_db_test.go +++ b/x/merkledb/value_node_db_test.go @@ -218,3 +218,34 @@ func TestValueNodeDBIterator(t *testing.T) { err := it.Error() require.ErrorIs(err, database.ErrClosed) } + +func TestValueNodeDBClear(t *testing.T) { + require := require.New(t) + cacheSize := 200 + baseDB := memdb.New() + db := newValueNodeDB( + baseDB, + &sync.Pool{ + New: func() interface{} { return make([]byte, 0) }, + }, + &mockMetrics{}, + cacheSize, + ) + + batch := db.NewBatch() + for _, b := range [][]byte{{1}, {2}, {3}} { + batch.Put(ToKey(b), newNode(ToKey(b))) + } + require.NoError(batch.Write()) + + // Assert the db is not empty + iter := baseDB.NewIteratorWithPrefix(valueNodePrefix) + require.True(iter.Next()) + iter.Release() + + require.NoError(db.Clear()) + + iter = baseDB.NewIteratorWithPrefix(valueNodePrefix) + defer iter.Release() + require.False(iter.Next()) +} From 0ae70288bd0a9a38249fe64cd92a8831be35d762 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 8 Nov 2023 16:08:13 -0500 Subject: [PATCH 110/131] add Clearer to sync.DB interface --- proto/pb/sync/sync.pb.go | 103 ++++++++++++++++++---------------- proto/pb/sync/sync_grpc.pb.go | 37 ++++++++++++ proto/sync/sync.proto | 2 + x/merkledb/mock_db.go | 14 +++++ x/sync/db.go | 1 + x/sync/g_db/db_client.go | 5 ++ x/sync/g_db/db_server.go | 4 ++ 7 files changed, 117 insertions(+), 49 deletions(-) diff --git a/proto/pb/sync/sync.pb.go b/proto/pb/sync/sync.pb.go index 92cd3d88351e..eb72e145420a 100644 --- a/proto/pb/sync/sync.pb.go +++ b/proto/pb/sync/sync.pb.go @@ -1666,44 +1666,47 @@ var file_sync_sync_proto_rawDesc = []byte{ 0x4e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x22, 0x32, 0x0a, 0x08, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x32, 0x8a, 0x04, 0x0a, 0x02, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x32, 0xc3, 0x04, 0x0a, 0x02, 0x44, 0x42, 0x12, 0x44, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x4d, 0x65, 0x72, 0x6b, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x50, - 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x15, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, - 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x73, 0x79, - 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, - 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, - 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x54, 0x0a, 0x11, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, - 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, - 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, - 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, - 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, - 0x70, 0x74, 0x79, 0x12, 0x48, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, - 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1a, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, - 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, - 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, - 0x10, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, - 0x66, 0x12, 0x1d, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, - 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, - 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x76, 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, - 0x61, 0x76, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2f, 0x70, 0x62, 0x2f, 0x73, 0x79, 0x6e, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x37, 0x0a, 0x05, 0x43, 0x6c, 0x65, 0x61, + 0x72, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, + 0x79, 0x12, 0x39, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x15, 0x2e, + 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4b, 0x0a, 0x0e, + 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1b, + 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x73, 0x79, + 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, + 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x54, 0x0a, 0x11, 0x56, 0x65, 0x72, + 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, + 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, + 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, + 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x43, 0x68, 0x61, 0x6e, + 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x4b, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, + 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1e, 0x2e, 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, + 0x69, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x48, 0x0a, 0x0d, + 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1a, 0x2e, + 0x73, 0x79, 0x6e, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x73, 0x79, 0x6e, 0x63, + 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x49, 0x0a, 0x10, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, + 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x12, 0x1d, 0x2e, 0x73, 0x79, 0x6e, + 0x63, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x72, 0x6f, + 0x6f, 0x66, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, + 0x79, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x61, 0x76, 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x61, 0x76, 0x61, 0x6c, 0x61, 0x6e, 0x63, + 0x68, 0x65, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x62, 0x2f, 0x73, 0x79, + 0x6e, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1782,21 +1785,23 @@ var file_sync_sync_proto_depIdxs = []int32{ 23, // 32: sync.ProofNode.children:type_name -> sync.ProofNode.ChildrenEntry 21, // 33: sync.KeyChange.value:type_name -> sync.MaybeBytes 24, // 34: sync.DB.GetMerkleRoot:input_type -> google.protobuf.Empty - 2, // 35: sync.DB.GetProof:input_type -> sync.GetProofRequest - 7, // 36: sync.DB.GetChangeProof:input_type -> sync.GetChangeProofRequest - 9, // 37: sync.DB.VerifyChangeProof:input_type -> sync.VerifyChangeProofRequest - 11, // 38: sync.DB.CommitChangeProof:input_type -> sync.CommitChangeProofRequest - 13, // 39: sync.DB.GetRangeProof:input_type -> sync.GetRangeProofRequest - 15, // 40: sync.DB.CommitRangeProof:input_type -> sync.CommitRangeProofRequest - 1, // 41: sync.DB.GetMerkleRoot:output_type -> sync.GetMerkleRootResponse - 3, // 42: sync.DB.GetProof:output_type -> sync.GetProofResponse - 8, // 43: sync.DB.GetChangeProof:output_type -> sync.GetChangeProofResponse - 10, // 44: sync.DB.VerifyChangeProof:output_type -> sync.VerifyChangeProofResponse - 24, // 45: sync.DB.CommitChangeProof:output_type -> google.protobuf.Empty - 14, // 46: sync.DB.GetRangeProof:output_type -> sync.GetRangeProofResponse - 24, // 47: sync.DB.CommitRangeProof:output_type -> google.protobuf.Empty - 41, // [41:48] is the sub-list for method output_type - 34, // [34:41] is the sub-list for method input_type + 24, // 35: sync.DB.Clear:input_type -> google.protobuf.Empty + 2, // 36: sync.DB.GetProof:input_type -> sync.GetProofRequest + 7, // 37: sync.DB.GetChangeProof:input_type -> sync.GetChangeProofRequest + 9, // 38: sync.DB.VerifyChangeProof:input_type -> sync.VerifyChangeProofRequest + 11, // 39: sync.DB.CommitChangeProof:input_type -> sync.CommitChangeProofRequest + 13, // 40: sync.DB.GetRangeProof:input_type -> sync.GetRangeProofRequest + 15, // 41: sync.DB.CommitRangeProof:input_type -> sync.CommitRangeProofRequest + 1, // 42: sync.DB.GetMerkleRoot:output_type -> sync.GetMerkleRootResponse + 24, // 43: sync.DB.Clear:output_type -> google.protobuf.Empty + 3, // 44: sync.DB.GetProof:output_type -> sync.GetProofResponse + 8, // 45: sync.DB.GetChangeProof:output_type -> sync.GetChangeProofResponse + 10, // 46: sync.DB.VerifyChangeProof:output_type -> sync.VerifyChangeProofResponse + 24, // 47: sync.DB.CommitChangeProof:output_type -> google.protobuf.Empty + 14, // 48: sync.DB.GetRangeProof:output_type -> sync.GetRangeProofResponse + 24, // 49: sync.DB.CommitRangeProof:output_type -> google.protobuf.Empty + 42, // [42:50] is the sub-list for method output_type + 34, // [34:42] is the sub-list for method input_type 34, // [34:34] is the sub-list for extension type_name 34, // [34:34] is the sub-list for extension extendee 0, // [0:34] is the sub-list for field type_name diff --git a/proto/pb/sync/sync_grpc.pb.go b/proto/pb/sync/sync_grpc.pb.go index 3fb420c7273a..5f79687b4d01 100644 --- a/proto/pb/sync/sync_grpc.pb.go +++ b/proto/pb/sync/sync_grpc.pb.go @@ -21,6 +21,7 @@ const _ = grpc.SupportPackageIsVersion7 const ( DB_GetMerkleRoot_FullMethodName = "/sync.DB/GetMerkleRoot" + DB_Clear_FullMethodName = "/sync.DB/Clear" DB_GetProof_FullMethodName = "/sync.DB/GetProof" DB_GetChangeProof_FullMethodName = "/sync.DB/GetChangeProof" DB_VerifyChangeProof_FullMethodName = "/sync.DB/VerifyChangeProof" @@ -34,6 +35,7 @@ const ( // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type DBClient interface { GetMerkleRoot(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GetMerkleRootResponse, error) + Clear(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) GetProof(ctx context.Context, in *GetProofRequest, opts ...grpc.CallOption) (*GetProofResponse, error) GetChangeProof(ctx context.Context, in *GetChangeProofRequest, opts ...grpc.CallOption) (*GetChangeProofResponse, error) VerifyChangeProof(ctx context.Context, in *VerifyChangeProofRequest, opts ...grpc.CallOption) (*VerifyChangeProofResponse, error) @@ -59,6 +61,15 @@ func (c *dBClient) GetMerkleRoot(ctx context.Context, in *emptypb.Empty, opts .. return out, nil } +func (c *dBClient) Clear(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, DB_Clear_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *dBClient) GetProof(ctx context.Context, in *GetProofRequest, opts ...grpc.CallOption) (*GetProofResponse, error) { out := new(GetProofResponse) err := c.cc.Invoke(ctx, DB_GetProof_FullMethodName, in, out, opts...) @@ -118,6 +129,7 @@ func (c *dBClient) CommitRangeProof(ctx context.Context, in *CommitRangeProofReq // for forward compatibility type DBServer interface { GetMerkleRoot(context.Context, *emptypb.Empty) (*GetMerkleRootResponse, error) + Clear(context.Context, *emptypb.Empty) (*emptypb.Empty, error) GetProof(context.Context, *GetProofRequest) (*GetProofResponse, error) GetChangeProof(context.Context, *GetChangeProofRequest) (*GetChangeProofResponse, error) VerifyChangeProof(context.Context, *VerifyChangeProofRequest) (*VerifyChangeProofResponse, error) @@ -134,6 +146,9 @@ type UnimplementedDBServer struct { func (UnimplementedDBServer) GetMerkleRoot(context.Context, *emptypb.Empty) (*GetMerkleRootResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetMerkleRoot not implemented") } +func (UnimplementedDBServer) Clear(context.Context, *emptypb.Empty) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method Clear not implemented") +} func (UnimplementedDBServer) GetProof(context.Context, *GetProofRequest) (*GetProofResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetProof not implemented") } @@ -183,6 +198,24 @@ func _DB_GetMerkleRoot_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _DB_Clear_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(emptypb.Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DBServer).Clear(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: DB_Clear_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DBServer).Clear(ctx, req.(*emptypb.Empty)) + } + return interceptor(ctx, in, info, handler) +} + func _DB_GetProof_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(GetProofRequest) if err := dec(in); err != nil { @@ -302,6 +335,10 @@ var DB_ServiceDesc = grpc.ServiceDesc{ MethodName: "GetMerkleRoot", Handler: _DB_GetMerkleRoot_Handler, }, + { + MethodName: "Clear", + Handler: _DB_Clear_Handler, + }, { MethodName: "GetProof", Handler: _DB_GetProof_Handler, diff --git a/proto/sync/sync.proto b/proto/sync/sync.proto index 4c4c6f434722..1a799433d7e7 100644 --- a/proto/sync/sync.proto +++ b/proto/sync/sync.proto @@ -21,6 +21,8 @@ message Request { service DB { rpc GetMerkleRoot(google.protobuf.Empty) returns (GetMerkleRootResponse); + rpc Clear(google.protobuf.Empty) returns (google.protobuf.Empty); + rpc GetProof(GetProofRequest) returns (GetProofResponse); rpc GetChangeProof(GetChangeProofRequest) returns (GetChangeProofResponse); diff --git a/x/merkledb/mock_db.go b/x/merkledb/mock_db.go index f7e35883c177..a4d1d6b6d6f3 100644 --- a/x/merkledb/mock_db.go +++ b/x/merkledb/mock_db.go @@ -40,6 +40,20 @@ func (m *MockMerkleDB) EXPECT() *MockMerkleDBMockRecorder { return m.recorder } +// Clear mocks base method. +func (m *MockMerkleDB) Clear() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Clear") + ret0, _ := ret[0].(error) + return ret0 +} + +// Clear indicates an expected call of Clear. +func (mr *MockMerkleDBMockRecorder) Clear() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clear", reflect.TypeOf((*MockMerkleDB)(nil).Clear)) +} + // Close mocks base method. func (m *MockMerkleDB) Close() error { m.ctrl.T.Helper() diff --git a/x/sync/db.go b/x/sync/db.go index 94b5542e34c1..5a0a5164c6a6 100644 --- a/x/sync/db.go +++ b/x/sync/db.go @@ -6,6 +6,7 @@ package sync import "github.com/ava-labs/avalanchego/x/merkledb" type DB interface { + merkledb.Clearer merkledb.MerkleRootGetter merkledb.ProofGetter merkledb.ChangeProofer diff --git a/x/sync/g_db/db_client.go b/x/sync/g_db/db_client.go index 9ce402f5e6ca..64e63bb76652 100644 --- a/x/sync/g_db/db_client.go +++ b/x/sync/g_db/db_client.go @@ -175,3 +175,8 @@ func (c *DBClient) CommitRangeProof( }) return err } + +func (c *DBClient) Clear() error { + _, err := c.client.Clear(context.Background(), &emptypb.Empty{}) + return err +} diff --git a/x/sync/g_db/db_server.go b/x/sync/g_db/db_server.go index da454e2d77cd..820a130bb496 100644 --- a/x/sync/g_db/db_server.go +++ b/x/sync/g_db/db_server.go @@ -216,3 +216,7 @@ func (s *DBServer) CommitRangeProof( err := s.db.CommitRangeProof(ctx, start, end, &proof) return &emptypb.Empty{}, err } + +func (s *DBServer) Clear(context.Context, *emptypb.Empty) (*emptypb.Empty, error) { + return &emptypb.Empty{}, s.db.Clear() +} From f7d401b66a84dac39a0f7b87d5ef6d0dcf1d59a3 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 8 Nov 2023 16:44:14 -0500 Subject: [PATCH 111/131] fix Clear --- x/merkledb/db.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 75ba084160bd..8131a8c4722f 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1260,21 +1260,27 @@ func (db *merkleDB) Clear() error { db.commitLock.Lock() defer db.commitLock.Unlock() - db.lock.Lock() - defer db.lock.Unlock() - - if err := db.intermediateNodeDB.Clear(); err != nil { + // TODO is it faster to clear another way? + keysToDelete, err := db.getKeysNotInSet(maybe.Nothing[[]byte](), maybe.Nothing[[]byte](), set.Set[string]{}) + if err != nil { return err } - if err := db.valueNodeDB.Clear(); err != nil { - return err + ops := make([]database.BatchOp, len(keysToDelete)) + for i, keyToDelete := range keysToDelete { + ops[i] = database.BatchOp{ + Key: keyToDelete, + Delete: true, + } } - db.root = newNode(Key{}) - db.root.calculateID(db.metrics) + // Don't need to lock [view] because nobody else has a reference to it. + view, err := newTrieView(db, db, ViewChanges{BatchOps: ops}) + if err != nil { + return err + } - return db.intermediateNodeDB.Put(db.root.key, db.root) + return view.commitToDB(context.Background()) } // Returns [key] prefixed by [prefix]. From b041f53fb2018106e69365ae9dd1408e98fcfa01 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 9 Nov 2023 12:00:09 -0500 Subject: [PATCH 112/131] WIP update test --- x/merkledb/db.go | 1 - x/merkledb/db_test.go | 85 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 8131a8c4722f..eb0be0ddbef3 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1260,7 +1260,6 @@ func (db *merkleDB) Clear() error { db.commitLock.Lock() defer db.commitLock.Unlock() - // TODO is it faster to clear another way? keysToDelete, err := db.getKeysNotInSet(maybe.Nothing[[]byte](), maybe.Nothing[[]byte](), set.Set[string]{}) if err != nil { return err diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index a0cd67312ff4..0d776c2a7009 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -30,6 +30,8 @@ import ( const defaultHistoryLength = 300 +var emptyKey Key + // newDB returns a new merkle database with the underlying type so that tests can access unexported fields func newDB(ctx context.Context, db database.Database, config Config) (*merkleDB, error) { db, err := New(ctx, db, config) @@ -794,14 +796,91 @@ func TestMerkleDBClear(t *testing.T) { 0.25, ) + // Write intermediate nodes to disk so that we can copy the + // state to inspect later. + require.NoError(db.intermediateNodeDB.Flush()) + + // Record the key-value pairs that exist. + var ( + valueKeys = []Key{} + values = [][]byte{} + valueIter = db.NewIterator() + ) + for valueIter.Next() { + valueKeys = append(valueKeys, ToKey(valueIter.Key())) + values = append(values, valueIter.Value()) + } + valueIter.Release() + + var ( + intermediateNodeKeys = []Key{} + intermediateNodeIter = db.baseDB.NewIteratorWithPrefix(intermediateNodePrefix) + intermediateNodeBytes = [][]byte{} + ) + for intermediateNodeIter.Next() { + rawKey := intermediateNodeIter.Key() + + // Remove the intermediate node prefix. + rawKey = rawKey[len(intermediateNodePrefix):] + + // Convert to a key + key := ToKey(rawKey) + + // Strip the padding + key = key.Take(key.length - db.tokenSize) + + intermediateNodeKeys = append(intermediateNodeKeys, key) + intermediateNodeBytes = append(intermediateNodeBytes, intermediateNodeIter.Value()) + } + // Clear the database. require.NoError(db.Clear()) // Assert that the database is empty. - iter := db.NewIterator() - defer iter.Release() - require.False(iter.Next()) + valueIter = db.NewIterator() + defer valueIter.Release() + require.False(valueIter.Next()) require.Equal(emptyRootID, db.getMerkleRoot()) + require.Equal(emptyKey, db.root.key) + + // Assert value nodes and value changes were recorded. + changes, ok := db.history.lastChanges[emptyRootID] + require.True(ok) + require.Len(changes.values, len(valueKeys)) + for i, valueKey := range valueKeys { + valueChange, ok := changes.values[valueKey] + require.True(ok) + require.True(valueChange.after.IsNothing()) + // Use bytes.Equal so nil and empty byte slices are treated the same. + require.True(bytes.Equal(values[i], valueChange.before.Value())) + + nodeChange, ok := changes.nodes[valueKey] + require.True(ok) + + if valueKey == emptyKey { + // The root had a value. The root should + // still exist after clearing the database. + require.NotNil(nodeChange.after) + } else { + require.Nil(nodeChange.after) + } + + delete(changes.nodes, valueKey) + } + + for i, intermediateNodeKey := range intermediateNodeKeys { + nodeChange, ok := changes.nodes[intermediateNodeKey] + require.True(ok, i) // todo remove i + + expectedNode, err := parseNode(intermediateNodeKey, intermediateNodeBytes[i]) + require.NoError(err) + + require.Equal(expectedNode, nodeChange.before) + + delete(changes.nodes, intermediateNodeKey) + } + + require.Empty(changes.nodes) } func FuzzMerkleDBEmptyRandomizedActions(f *testing.F) { From 192b2fd0ca37821748e9ad02b37bdd33c07b4e42 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 9 Nov 2023 12:36:08 -0500 Subject: [PATCH 113/131] fix test --- x/merkledb/db_test.go | 42 ++++++++++--------------- x/merkledb/intermediate_node_db_test.go | 9 ++++++ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index 0d776c2a7009..b81b9f7bc0af 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -792,7 +792,7 @@ func TestMerkleDBClear(t *testing.T) { require, r, []database.Database{db}, - 1_000, + 10, // todo make 1000 0.25, ) @@ -813,24 +813,11 @@ func TestMerkleDBClear(t *testing.T) { valueIter.Release() var ( - intermediateNodeKeys = []Key{} - intermediateNodeIter = db.baseDB.NewIteratorWithPrefix(intermediateNodePrefix) - intermediateNodeBytes = [][]byte{} + intermediateNodes = map[string][]byte{} + intermediateNodeIter = db.baseDB.NewIteratorWithPrefix(intermediateNodePrefix) ) for intermediateNodeIter.Next() { - rawKey := intermediateNodeIter.Key() - - // Remove the intermediate node prefix. - rawKey = rawKey[len(intermediateNodePrefix):] - - // Convert to a key - key := ToKey(rawKey) - - // Strip the padding - key = key.Take(key.length - db.tokenSize) - - intermediateNodeKeys = append(intermediateNodeKeys, key) - intermediateNodeBytes = append(intermediateNodeBytes, intermediateNodeIter.Value()) + intermediateNodes[string(intermediateNodeIter.Key())] = intermediateNodeIter.Value() } // Clear the database. @@ -867,20 +854,25 @@ func TestMerkleDBClear(t *testing.T) { delete(changes.nodes, valueKey) } + // [changes.nodes] only has intermediate nodes now. - for i, intermediateNodeKey := range intermediateNodeKeys { - nodeChange, ok := changes.nodes[intermediateNodeKey] - require.True(ok, i) // todo remove i + for intermediateNodeKey, intermediateNodeChange := range changes.nodes { + dbKey := string(db.intermediateNodeDB.constructDBKey(intermediateNodeKey)) - expectedNode, err := parseNode(intermediateNodeKey, intermediateNodeBytes[i]) + intermediateNodeBytes, ok := intermediateNodes[dbKey] + require.True(ok) + + intermediateNode, err := parseNode(intermediateNodeKey, intermediateNodeBytes) require.NoError(err) - require.Equal(expectedNode, nodeChange.before) + intermediateNodeChange.before.calculateID(&mockMetrics{}) + intermediateNode.calculateID(&mockMetrics{}) - delete(changes.nodes, intermediateNodeKey) - } + require.Equal(intermediateNode, intermediateNodeChange.before) - require.Empty(changes.nodes) + delete(intermediateNodes, dbKey) + } + require.Empty(intermediateNodes) } func FuzzMerkleDBEmptyRandomizedActions(f *testing.F) { diff --git a/x/merkledb/intermediate_node_db_test.go b/x/merkledb/intermediate_node_db_test.go index 91709708f148..06756014a706 100644 --- a/x/merkledb/intermediate_node_db_test.go +++ b/x/merkledb/intermediate_node_db_test.go @@ -242,3 +242,12 @@ func TestIntermediateNodeDBClear(t *testing.T) { require.Zero(db.nodeCache.currentSize) } + +func TestDeleteMe(t *testing.T) { + require := require.New(t) + + db, err := getBasicDB() + require.NoError(err) + + t.Fatal(db.intermediateNodeDB.constructDBKey(Key{})) +} From 83aca7e73a3eb7bf342ac9c97976ee0fd938dffb Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 9 Nov 2023 12:37:29 -0500 Subject: [PATCH 114/131] fix test --- x/merkledb/db_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index b81b9f7bc0af..23190de9b13d 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -792,7 +792,7 @@ func TestMerkleDBClear(t *testing.T) { require, r, []database.Database{db}, - 10, // todo make 1000 + 1_000, 0.25, ) From 778e1727762d4906b90ac9fdfc9588c40b9de917 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 9 Nov 2023 12:45:21 -0500 Subject: [PATCH 115/131] remove dummy test --- x/merkledb/intermediate_node_db_test.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/x/merkledb/intermediate_node_db_test.go b/x/merkledb/intermediate_node_db_test.go index 06756014a706..91709708f148 100644 --- a/x/merkledb/intermediate_node_db_test.go +++ b/x/merkledb/intermediate_node_db_test.go @@ -242,12 +242,3 @@ func TestIntermediateNodeDBClear(t *testing.T) { require.Zero(db.nodeCache.currentSize) } - -func TestDeleteMe(t *testing.T) { - require := require.New(t) - - db, err := getBasicDB() - require.NoError(err) - - t.Fatal(db.intermediateNodeDB.constructDBKey(Key{})) -} From 9b7fc3a29e655f77c0686d69af088266f0e7e935 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 9 Nov 2023 13:42:55 -0500 Subject: [PATCH 116/131] refactor clear --- x/merkledb/db.go | 33 ++++++++++--------- x/merkledb/db_test.go | 77 +++++-------------------------------------- 2 files changed, 26 insertions(+), 84 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index eb0be0ddbef3..d583a3a57724 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -36,6 +36,7 @@ const ( // TODO: name better rebuildViewSizeFractionOfCacheSize = 50 minRebuildViewSizePerCommit = 1000 + clearBatchSize = units.MiB rebuildIntermediateDeletionWriteSize = units.MiB valueNodePrefixLen = 1 ) @@ -1260,26 +1261,28 @@ func (db *merkleDB) Clear() error { db.commitLock.Lock() defer db.commitLock.Unlock() - keysToDelete, err := db.getKeysNotInSet(maybe.Nothing[[]byte](), maybe.Nothing[[]byte](), set.Set[string]{}) - if err != nil { - return err - } + db.lock.Lock() + defer db.lock.Unlock() - ops := make([]database.BatchOp, len(keysToDelete)) - for i, keyToDelete := range keysToDelete { - ops[i] = database.BatchOp{ - Key: keyToDelete, - Delete: true, - } + // Clear nodes from disk + if err := database.ClearPrefix(db.baseDB, valueNodePrefix, clearBatchSize); err != nil { + return err } - - // Don't need to lock [view] because nobody else has a reference to it. - view, err := newTrieView(db, db, ViewChanges{BatchOps: ops}) - if err != nil { + if err := database.ClearPrefix(db.baseDB, intermediateNodePrefix, clearBatchSize); err != nil { return err } - return view.commitToDB(context.Background()) + db.root = newNode(Key{}) + db.root.calculateID(db.metrics) + + // Reset history + db.history = newTrieHistory(db.history.maxHistoryLen) + db.history.record(&changeSummary{ + rootID: db.getMerkleRoot(), + values: map[Key]*change[maybe.Maybe[[]byte]]{}, + nodes: map[Key]*change[*node]{}, + }) + return nil } // Returns [key] prefixed by [prefix]. diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index 23190de9b13d..1462135200c7 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -796,83 +796,22 @@ func TestMerkleDBClear(t *testing.T) { 0.25, ) - // Write intermediate nodes to disk so that we can copy the - // state to inspect later. - require.NoError(db.intermediateNodeDB.Flush()) - - // Record the key-value pairs that exist. - var ( - valueKeys = []Key{} - values = [][]byte{} - valueIter = db.NewIterator() - ) - for valueIter.Next() { - valueKeys = append(valueKeys, ToKey(valueIter.Key())) - values = append(values, valueIter.Value()) - } - valueIter.Release() - - var ( - intermediateNodes = map[string][]byte{} - intermediateNodeIter = db.baseDB.NewIteratorWithPrefix(intermediateNodePrefix) - ) - for intermediateNodeIter.Next() { - intermediateNodes[string(intermediateNodeIter.Key())] = intermediateNodeIter.Value() - } - // Clear the database. require.NoError(db.Clear()) // Assert that the database is empty. - valueIter = db.NewIterator() - defer valueIter.Release() - require.False(valueIter.Next()) + iter := db.NewIterator() + defer iter.Release() + require.False(iter.Next()) require.Equal(emptyRootID, db.getMerkleRoot()) require.Equal(emptyKey, db.root.key) - // Assert value nodes and value changes were recorded. - changes, ok := db.history.lastChanges[emptyRootID] + // Assert history has only the clearing change. + require.Len(db.history.lastChanges, 1) + change, ok := db.history.lastChanges[emptyRootID] require.True(ok) - require.Len(changes.values, len(valueKeys)) - for i, valueKey := range valueKeys { - valueChange, ok := changes.values[valueKey] - require.True(ok) - require.True(valueChange.after.IsNothing()) - // Use bytes.Equal so nil and empty byte slices are treated the same. - require.True(bytes.Equal(values[i], valueChange.before.Value())) - - nodeChange, ok := changes.nodes[valueKey] - require.True(ok) - - if valueKey == emptyKey { - // The root had a value. The root should - // still exist after clearing the database. - require.NotNil(nodeChange.after) - } else { - require.Nil(nodeChange.after) - } - - delete(changes.nodes, valueKey) - } - // [changes.nodes] only has intermediate nodes now. - - for intermediateNodeKey, intermediateNodeChange := range changes.nodes { - dbKey := string(db.intermediateNodeDB.constructDBKey(intermediateNodeKey)) - - intermediateNodeBytes, ok := intermediateNodes[dbKey] - require.True(ok) - - intermediateNode, err := parseNode(intermediateNodeKey, intermediateNodeBytes) - require.NoError(err) - - intermediateNodeChange.before.calculateID(&mockMetrics{}) - intermediateNode.calculateID(&mockMetrics{}) - - require.Equal(intermediateNode, intermediateNodeChange.before) - - delete(intermediateNodes, dbKey) - } - require.Empty(intermediateNodes) + require.Empty(change.nodes) + require.Empty(change.values) } func FuzzMerkleDBEmptyRandomizedActions(f *testing.F) { From 35672c311171d7b01adccb2c7334ec15d23e699f Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 9 Nov 2023 13:43:38 -0500 Subject: [PATCH 117/131] comment --- x/merkledb/db.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index d583a3a57724..dd804e0caec8 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -116,7 +116,8 @@ type RangeProofer interface { } type Clearer interface { - // Deletes all key/value pairs from the database. + // Deletes all key/value pairs from the database + // and clears the change history. Clear() error } From 20e4a04c77ff1daf5749d017c682147a11eb10bc Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 9 Nov 2023 14:30:21 -0500 Subject: [PATCH 118/131] clear caches --- x/merkledb/db.go | 11 ++++++++++- x/merkledb/db_test.go | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 86c6100b0d71..b809663a153d 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1265,6 +1265,14 @@ func (db *merkleDB) Clear() error { db.lock.Lock() defer db.lock.Unlock() + // Clear caches + if err := db.valueNodeDB.Clear(); err != nil { + return err + } + if err := db.intermediateNodeDB.Clear(); err != nil { + return err + } + // Clear nodes from disk if err := database.ClearPrefix(db.baseDB, valueNodePrefix, clearBatchSize); err != nil { return err @@ -1273,10 +1281,11 @@ func (db *merkleDB) Clear() error { return err } + // Clear root db.root = newNode(Key{}) db.root.calculateID(db.metrics) - // Reset history + // Clear history db.history = newTrieHistory(db.history.maxHistoryLen) db.history.record(&changeSummary{ rootID: db.getMerkleRoot(), diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index 1462135200c7..a2bc4de1a274 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -806,12 +806,17 @@ func TestMerkleDBClear(t *testing.T) { require.Equal(emptyRootID, db.getMerkleRoot()) require.Equal(emptyKey, db.root.key) + // Assert caches are empty. + require.Zero(db.valueNodeDB.nodeCache.Len()) + require.Zero(db.intermediateNodeDB.nodeCache.currentSize) + // Assert history has only the clearing change. require.Len(db.history.lastChanges, 1) change, ok := db.history.lastChanges[emptyRootID] require.True(ok) require.Empty(change.nodes) require.Empty(change.values) + } func FuzzMerkleDBEmptyRandomizedActions(f *testing.F) { From 14e0e97b43ff492d065b63e7a25a82ab9fca12b6 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 9 Nov 2023 14:37:43 -0500 Subject: [PATCH 119/131] appease linter --- x/merkledb/db_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index a2bc4de1a274..be43cdaacf12 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -816,7 +816,6 @@ func TestMerkleDBClear(t *testing.T) { require.True(ok) require.Empty(change.nodes) require.Empty(change.values) - } func FuzzMerkleDBEmptyRandomizedActions(f *testing.F) { From fcf0d22352108e9ad707fefe8123494cc4805246 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 9 Nov 2023 14:59:11 -0500 Subject: [PATCH 120/131] remove redundant deletions; fix prefix --- x/merkledb/db.go | 14 +++----------- x/merkledb/db_test.go | 2 +- x/merkledb/intermediate_node_db.go | 2 +- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index e961e1ac8cfa..b1ee699bab97 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1279,7 +1279,7 @@ func (db *merkleDB) Clear() error { db.lock.Lock() defer db.lock.Unlock() - // Clear caches + // Clear nodes from disk and caches if err := db.valueNodeDB.Clear(); err != nil { return err } @@ -1287,17 +1287,9 @@ func (db *merkleDB) Clear() error { return err } - // Clear nodes from disk - if err := database.ClearPrefix(db.baseDB, valueNodePrefix, clearBatchSize); err != nil { - return err - } - if err := database.ClearPrefix(db.baseDB, intermediateNodePrefix, clearBatchSize); err != nil { - return err - } - // Clear root - db.root = newNode(Key{}) - db.root.calculateID(db.metrics) + db.sentinelNode = newNode(Key{}) + db.sentinelNode.calculateID(db.metrics) // Clear history db.history = newTrieHistory(db.history.maxHistoryLen) diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index be43cdaacf12..828a72bef7db 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -804,7 +804,7 @@ func TestMerkleDBClear(t *testing.T) { defer iter.Release() require.False(iter.Next()) require.Equal(emptyRootID, db.getMerkleRoot()) - require.Equal(emptyKey, db.root.key) + require.Equal(emptyKey, db.sentinelNode.key) // Assert caches are empty. require.Zero(db.valueNodeDB.nodeCache.Len()) diff --git a/x/merkledb/intermediate_node_db.go b/x/merkledb/intermediate_node_db.go index cc87edcfa927..91cef6242410 100644 --- a/x/merkledb/intermediate_node_db.go +++ b/x/merkledb/intermediate_node_db.go @@ -155,5 +155,5 @@ func (db *intermediateNodeDB) Clear() error { db.nodeCache.size, db.nodeCache.onEviction, ) - return database.AtomicClearPrefix(db.baseDB, db.baseDB, valueNodePrefix) + return database.AtomicClearPrefix(db.baseDB, db.baseDB, intermediateNodePrefix) } From 2b45f698ca61557156f8e6f29d8e095ca2c1ce56 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Mon, 13 Nov 2023 10:13:27 -0500 Subject: [PATCH 121/131] fix test --- x/merkledb/db_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/x/merkledb/db_test.go b/x/merkledb/db_test.go index 590ba2f1e71e..7a2a0df4c043 100644 --- a/x/merkledb/db_test.go +++ b/x/merkledb/db_test.go @@ -30,8 +30,6 @@ import ( const defaultHistoryLength = 300 -var emptyKey Key - // newDB returns a new merkle database with the underlying type so that tests can access unexported fields func newDB(ctx context.Context, db database.Database, config Config) (*merkleDB, error) { db, err := New(ctx, db, config) @@ -803,8 +801,8 @@ func TestMerkleDBClear(t *testing.T) { iter := db.NewIterator() defer iter.Release() require.False(iter.Next()) - require.Equal(emptyRootID, db.getMerkleRoot()) - require.Equal(emptyKey, db.root.Value().key) + require.Equal(ids.Empty, db.getMerkleRoot()) + require.True(db.root.IsNothing()) // Assert caches are empty. require.Zero(db.valueNodeDB.nodeCache.Len()) From da6a6708f89b220240e720333149fb73eaa0eb6c Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 1 Dec 2023 11:04:21 -0500 Subject: [PATCH 122/131] fix tests --- x/merkledb/node.go | 5 +++++ x/merkledb/trie_test.go | 42 +++++++++++++++++++++++++++++------------ x/merkledb/trieview.go | 13 ++++++++----- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/x/merkledb/node.go b/x/merkledb/node.go index 9a63ef82c4a7..d15eb6ae7e14 100644 --- a/x/merkledb/node.go +++ b/x/merkledb/node.go @@ -105,10 +105,15 @@ func (n *node) setValueDigest() { // Assumes [child]'s key is valid as a child of [n]. // That is, [n.key] is a prefix of [child.key]. func (n *node) addChild(childNode *node, tokenSize int) { + n.addChildWithID(childNode, tokenSize, ids.Empty) +} + +func (n *node) addChildWithID(childNode *node, tokenSize int, childID ids.ID) { n.setChildEntry( childNode.key.Token(n.key.length, tokenSize), &child{ compressedKey: childNode.key.Skip(n.key.length + tokenSize), + id: childID, hasValue: childNode.hasValue(), }, ) diff --git a/x/merkledb/trie_test.go b/x/merkledb/trie_test.go index 212fd8f0557b..fec8a435d60a 100644 --- a/x/merkledb/trie_test.go +++ b/x/merkledb/trie_test.go @@ -593,9 +593,9 @@ func Test_Trie_HashCountOnBranch(t *testing.T) { require.NoError(err) require.NotNil(dbTrie) - key1, key2, keyPrefix := []byte("key12"), []byte("key1F"), []byte("key1") + key1, key2, keyPrefix := []byte("12"), []byte("1F"), []byte("1") - trieIntf, err := dbTrie.NewView( + view1, err := dbTrie.NewView( context.Background(), ViewChanges{ BatchOps: []database.BatchOp{ @@ -603,11 +603,13 @@ func Test_Trie_HashCountOnBranch(t *testing.T) { }, }) require.NoError(err) - trie := trieIntf.(*trieView) + + // trie is: + // [1] // create new node with common prefix whose children // are key1, key2 - view2, err := trie.NewView( + view2, err := view1.NewView( context.Background(), ViewChanges{ BatchOps: []database.BatchOp{ @@ -616,21 +618,28 @@ func Test_Trie_HashCountOnBranch(t *testing.T) { }) require.NoError(err) + // trie is: + // [1] + // / \ + // [12] [1F] + // clear the hash count to ignore setup dbTrie.metrics.(*mockMetrics).hashCount = 0 - // force the new root to calculate + // calculate the root _, err = view2.GetMerkleRoot(context.Background()) require.NoError(err) - // Make sure the branch node with the common prefix was created. + // Make sure the root is an intermediate node with the expected common prefix. // Note it's only created on call to GetMerkleRoot, not in NewView. - gotRoot, err := view2.getEditableNode(ToKey(keyPrefix), false) + prefixNode, err := view2.getEditableNode(ToKey(keyPrefix), false) require.NoError(err) - require.Equal(view2.getRoot().Value(), gotRoot) + root := view2.getRoot().Value() + require.Equal(root, prefixNode) + require.Len(root.children, 2) - // Had to hash new root and new child of root. - require.Equal(int64(2), dbTrie.metrics.(*mockMetrics).hashCount) + // Had to hash each of the new nodes ("12" and "1F") and the new root + require.Equal(int64(3), dbTrie.metrics.(*mockMetrics).hashCount) } func Test_Trie_HashCountOnDelete(t *testing.T) { @@ -671,8 +680,17 @@ func Test_Trie_HashCountOnDelete(t *testing.T) { require.NoError(err) require.NoError(view.CommitToDB(context.Background())) - // The new root is key1; it didn't change so no need to do more hashes - require.Equal(oldCount, dbTrie.metrics.(*mockMetrics).hashCount) + // trie is: + // [key0] (first 28 bits) + // / \ + // [key1] [key2] + root := view.getRoot().Value() + expectedRootKey := ToKey([]byte("key0")).Take(28) + require.Equal(expectedRootKey, root.key) + require.Len(root.children, 2) + + // Had to hash the new root but not [key1] or [key2] nodes + require.Equal(oldCount+1, dbTrie.metrics.(*mockMetrics).hashCount) } func Test_Trie_NoExistingResidual(t *testing.T) { diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index bef3097f44f5..fee01b53d46a 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -834,11 +834,14 @@ func (t *trieView) insert( if closestNode == nil { // [t.root.key] isn't a prefix of [key]. - oldRoot := t.root.Value() - commonPrefixLength := getLengthOfCommonPrefix(oldRoot.key, key, 0 /*offset*/, t.tokenSize) - commonPrefix := oldRoot.key.Take(commonPrefixLength) - newRoot := newNode(commonPrefix) - newRoot.addChild(oldRoot, t.tokenSize) + var ( + oldRoot = t.root.Value() + commonPrefixLength = getLengthOfCommonPrefix(oldRoot.key, key, 0 /*offset*/, t.tokenSize) + commonPrefix = oldRoot.key.Take(commonPrefixLength) + newRoot = newNode(commonPrefix) + oldRootID = oldRoot.calculateID(t.db.metrics) + ) + newRoot.addChildWithID(oldRoot, t.tokenSize, oldRootID) // todo comment if err := t.recordNewNode(newRoot); err != nil { return nil, err } From 44e6667aa7b53b6275f53096329e2d522d34d0cf Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 1 Dec 2023 16:38:53 -0500 Subject: [PATCH 123/131] nits --- x/merkledb/db.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index f524aee77717..c2cbed0a317b 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -980,12 +980,12 @@ func (db *merkleDB) commitChanges(ctx context.Context, trieToCommit *trieView) e db.root = changes.rootChange.after db.rootID = changes.rootID - if changes.rootChange.after.IsNothing() { + if db.root.IsNothing() { return db.baseDB.Delete(rootDBKey) } - rootKeyAndNodeBytes := codec.encodeKey(db.root.Value().key) - return db.baseDB.Put(rootDBKey, rootKeyAndNodeBytes) + rootKey := codec.encodeKey(db.root.Value().key) + return db.baseDB.Put(rootDBKey, rootKey) } // moveChildViewsToDB removes any child views from the trieToCommit and moves them to the db From 7b99e6a44d1c6a7614859001dde8e19a027cbdf8 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 1 Dec 2023 16:42:26 -0500 Subject: [PATCH 124/131] var name nit --- x/merkledb/db.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index c2cbed0a317b..79569cdc9f62 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1166,7 +1166,7 @@ func (db *merkleDB) invalidateChildrenExcept(exception *trieView) { // If the root is on disk, set [db.root] to it. // Otherwise leave [db.root] as Nothing. func (db *merkleDB) initializeRoot() error { - rootBytes, err := db.baseDB.Get(rootDBKey) + rootKeyBytes, err := db.baseDB.Get(rootDBKey) if err != nil { if !errors.Is(err, database.ErrNotFound) { return err @@ -1176,7 +1176,7 @@ func (db *merkleDB) initializeRoot() error { } // Root is on disk. - rootKey, err := codec.decodeKey(rootBytes) + rootKey, err := codec.decodeKey(rootKeyBytes) if err != nil { return err } From 09427b4789db8aab17bd1f2482e38bb8ea90d6c3 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 1 Dec 2023 16:44:01 -0500 Subject: [PATCH 125/131] nit --- x/merkledb/db.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 79569cdc9f62..460f2aa3d437 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1181,9 +1181,8 @@ func (db *merkleDB) initializeRoot() error { return err } - var root *node - // First, see if root is an intermediate node. + var root *node root, err = db.getEditableNode(rootKey, false /* hasValue */) if err != nil { if !errors.Is(err, database.ErrNotFound) { From 3fcf63b661c513bea356a3a18f2509ab37873c4f Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 1 Dec 2023 16:54:56 -0500 Subject: [PATCH 126/131] fix insert by calculating root ID of old root --- x/merkledb/trieview.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index fee01b53d46a..4d58ccb42b89 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -855,7 +855,7 @@ func (t *trieView) insert( // Neither [key] nor [t.root.key] is a prefix of the other. // Make a new root whose children are the old root and the new node. - newRoot.addChild(oldRoot, t.tokenSize) + newRoot.addChildWithID(oldRoot, t.tokenSize, oldRootID) newValueNode := newNode(key) newValueNode.setValue(value) newRoot.addChild(newValueNode, t.tokenSize) From 33c9fd7b8b3746d3e1dc082590b9d26df2e2a7d2 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Mon, 11 Dec 2023 15:16:13 -0500 Subject: [PATCH 127/131] special case root in db.getNode --- x/merkledb/db.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 8b342fdf4fb1..1f29d1c9aed8 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -1276,6 +1276,8 @@ func (db *merkleDB) getNode(key Key, hasValue bool) (*node, error) { switch { case db.closed: return nil, database.ErrClosed + case db.root.HasValue() && key == db.root.Value().key: + return db.root.Value(), nil case hasValue: return db.valueNodeDB.Get(key) default: From 464602a7606d102e5d27c8c2d2ce675a0fd3eb97 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Mon, 11 Dec 2023 15:45:56 -0500 Subject: [PATCH 128/131] remove stalek comments --- x/merkledb/db.go | 2 -- x/merkledb/trieview.go | 1 - 2 files changed, 3 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 1f29d1c9aed8..78d7c5117435 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -601,7 +601,6 @@ func (db *merkleDB) GetProof(ctx context.Context, key []byte) (*Proof, error) { } // Assumes [db.commitLock] is read locked. -// Assumes [db.lock] is not held func (db *merkleDB) getProof(ctx context.Context, key []byte) (*Proof, error) { if db.closed { return nil, database.ErrClosed @@ -1207,7 +1206,6 @@ func (db *merkleDB) initializeRoot() error { // If [start] is Nothing, there's no lower bound on the range. // If [end] is Nothing, there's no upper bound on the range. // Assumes [db.commitLock] is read locked. -// Assumes [db.lock] isn't held. func (db *merkleDB) getHistoricalViewForRange( rootID ids.ID, start maybe.Maybe[[]byte], diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 4d58ccb42b89..48aa6b661c01 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -141,7 +141,6 @@ func (t *trieView) NewView( } // Creates a new view with the given [parentTrie]. -// Assumes [parentTrie] isn't locked. func newTrieView( db *merkleDB, parentTrie TrieView, From d35109517a4235dad52492b14484781e5fcd59b1 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Mon, 11 Dec 2023 16:12:27 -0500 Subject: [PATCH 129/131] refactor remove --- x/merkledb/trieview.go | 43 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index 48aa6b661c01..fb99b4316dd1 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -636,41 +636,6 @@ func (t *trieView) remove(key Key) error { } nodeToDelete.setValue(maybe.Nothing[[]byte]()) - if nodeToDelete.key == t.root.Value().key { - // We're deleting the root. - switch len(nodeToDelete.children) { - case 0: - // The trie is empty now. - t.root = maybe.Nothing[*node]() - return t.recordNodeDeleted(nodeToDelete) - case 1: - // The root has one child, so make that child the new root. - var ( - childIndex byte - child *child - ) - for childIndex, child = range nodeToDelete.children { - break - } - - childKey := nodeToDelete.key.Extend(ToToken(childIndex, t.tokenSize), child.compressedKey) - newRoot, err := t.getNode(childKey, child.hasValue) - if err != nil { - return err - } - if err := t.recordNodeDeleted(t.root.Value()); err != nil { - return err - } - t.root = maybe.Some(newRoot) - return nil - default: - // The root has multiple children so we can't delete it. - return t.recordNodeChange(nodeToDelete) - } - } - - // Note [parent] != nil since [nodeToDelete.key] != [t.root.key]. - // i.e. There's the root and at least one more node. // if the removed node has no children, the node can be removed from the trie if len(nodeToDelete.children) == 0 { @@ -678,6 +643,14 @@ func (t *trieView) remove(key Key) error { return err } + if nodeToDelete.key == t.root.Value().key { + // We deleted the root. The trie is empty now. + t.root = maybe.Nothing[*node]() + return nil + } + + // Note [parent] != nil since [nodeToDelete.key] != [t.root.key]. + // i.e. There's the root and at least one more node. parent.removeChild(nodeToDelete, t.tokenSize) // merge the parent node and its child into a single node if possible From 7963a0b6fb8b1053d662a0338834a3f07486bfc4 Mon Sep 17 00:00:00 2001 From: dboehm-avalabs Date: Wed, 13 Dec 2023 11:24:42 -0500 Subject: [PATCH 130/131] Update trieview.go --- x/merkledb/trieview.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index fb99b4316dd1..cc34429a8e42 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -819,19 +819,7 @@ func (t *trieView) insert( } t.root = maybe.Some(newRoot) - if commonPrefix == key { - // [key] is a prefix of [t.root.key] so it should be the new root. - newRoot.setValue(value) - return newRoot, nil - } - - // Neither [key] nor [t.root.key] is a prefix of the other. - // Make a new root whose children are the old root and the new node. - newRoot.addChildWithID(oldRoot, t.tokenSize, oldRootID) - newValueNode := newNode(key) - newValueNode.setValue(value) - newRoot.addChild(newValueNode, t.tokenSize) - return newValueNode, t.recordNewNode(newValueNode) + closestNode = newRoot } // a node with that exact key already exists so update its value From f7eb1ec5795ce007003d2834baf0588cf718ae2a Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 13 Dec 2023 17:38:24 -0500 Subject: [PATCH 131/131] re-add todo --- x/merkledb/trieview.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index cc34429a8e42..35be62f8a5f9 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -813,7 +813,14 @@ func (t *trieView) insert( newRoot = newNode(commonPrefix) oldRootID = oldRoot.calculateID(t.db.metrics) ) - newRoot.addChildWithID(oldRoot, t.tokenSize, oldRootID) // todo comment + + // Call addChildWithID instead of addChild so the old root is added + // to the new root with the correct ID. + // TODO: + // [oldRootID] shouldn't need to be calculated here. + // Either oldRootID should already be calculated or will be calculated at the end with the other nodes + // Initialize the t.changes.rootID during newTrieView and then use that here instead of oldRootID + newRoot.addChildWithID(oldRoot, t.tokenSize, oldRootID) if err := t.recordNewNode(newRoot); err != nil { return nil, err }