From e933587b5a4b47327a49c7945d36a079807ad9b7 Mon Sep 17 00:00:00 2001 From: David Boehm <91908103+dboehm-avalabs@users.noreply.github.com> Date: Thu, 26 Oct 2023 11:40:57 -0400 Subject: [PATCH 01/19] Reduce allocations on insert and remove (#2201) Signed-off-by: David Boehm <91908103+dboehm-avalabs@users.noreply.github.com> Signed-off-by: Dan Laine Co-authored-by: Darioush Jalali Co-authored-by: Dan Laine --- x/merkledb/db.go | 17 ++-- x/merkledb/trie_test.go | 92 ++++++++++-------- x/merkledb/trieview.go | 204 +++++++++++++++------------------------- 3 files changed, 135 insertions(+), 178 deletions(-) diff --git a/x/merkledb/db.go b/x/merkledb/db.go index 247bdfbd5822..87439010b1f0 100644 --- a/x/merkledb/db.go +++ b/x/merkledb/db.go @@ -474,19 +474,14 @@ func (db *merkleDB) PrefetchPath(key []byte) error { } func (db *merkleDB) prefetchPath(view *trieView, keyBytes []byte) error { - pathToKey, err := view.getPathTo(db.toKey(keyBytes)) - if err != nil { - return err - } - for _, n := range pathToKey { - if n.hasValue() { - db.valueNodeDB.nodeCache.Put(n.key, n) - } else if err := db.intermediateNodeDB.nodeCache.Put(n.key, n); err != nil { - return err + return view.visitPathToKey(db.toKey(keyBytes), func(n *node) error { + if !n.hasValue() { + return db.intermediateNodeDB.nodeCache.Put(n.key, n) } - } - return nil + db.valueNodeDB.nodeCache.Put(n.key, n) + return nil + }) } func (db *merkleDB) Get(key []byte) ([]byte, error) { diff --git a/x/merkledb/trie_test.go b/x/merkledb/trie_test.go index bd666b44ea9e..7908c1266af7 100644 --- a/x/merkledb/trie_test.go +++ b/x/merkledb/trie_test.go @@ -23,40 +23,35 @@ func getNodeValue(t ReadOnlyTrie, key string) ([]byte, error) { } func getNodeValueWithBranchFactor(t ReadOnlyTrie, key string, bf BranchFactor) ([]byte, error) { + var view *trieView if asTrieView, ok := t.(*trieView); ok { if err := asTrieView.calculateNodeIDs(context.Background()); err != nil { return nil, err } - path := ToKey([]byte(key), bf) - nodePath, err := asTrieView.getPathTo(path) - if err != nil { - return nil, err - } - closestNode := nodePath[len(nodePath)-1] - if closestNode.key != path || closestNode == nil { - return nil, database.ErrNotFound - } - - return closestNode.value.Value(), nil + view = asTrieView } if asDatabases, ok := t.(*merkleDB); ok { - view, err := asDatabases.NewView(context.Background(), ViewChanges{}) + dbView, err := asDatabases.NewView(context.Background(), ViewChanges{}) if err != nil { return nil, err } - path := ToKey([]byte(key), bf) - nodePath, err := view.(*trieView).getPathTo(path) - if err != nil { - return nil, err - } - closestNode := nodePath[len(nodePath)-1] - if closestNode.key != path || closestNode == nil { - return nil, database.ErrNotFound - } + view = dbView.(*trieView) + } - return closestNode.value.Value(), nil + path := ToKey([]byte(key), bf) + var result *node + err := view.visitPathToKey(path, func(n *node) error { + result = n + return nil + }) + if err != nil { + return nil, err } - return nil, nil + if result.key != path || result == nil { + return nil, database.ErrNotFound + } + + return result.value.Value(), nil } func Test_GetValue_Safety(t *testing.T) { @@ -116,7 +111,7 @@ func Test_GetValues_Safety(t *testing.T) { require.Equal([]byte{0}, trieVals[0]) } -func TestTrieViewGetPathTo(t *testing.T) { +func TestTrieViewVisitPathToKey(t *testing.T) { require := require.New(t) db, err := getBasicDB() @@ -127,8 +122,11 @@ func TestTrieViewGetPathTo(t *testing.T) { require.IsType(&trieView{}, trieIntf) trie := trieIntf.(*trieView) - nodePath, err := trie.getPathTo(ToKey(nil, BranchFactor16)) - require.NoError(err) + var nodePath []*node + require.NoError(trie.visitPathToKey(ToKey(nil, BranchFactor16), func(n *node) error { + nodePath = append(nodePath, n) + return nil + })) // Just the root require.Len(nodePath, 1) @@ -149,8 +147,11 @@ func TestTrieViewGetPathTo(t *testing.T) { trie = trieIntf.(*trieView) require.NoError(trie.calculateNodeIDs(context.Background())) - nodePath, err = trie.getPathTo(ToKey(key1, BranchFactor16)) - require.NoError(err) + nodePath = make([]*node, 0, 2) + require.NoError(trie.visitPathToKey(ToKey(key1, BranchFactor16), func(n *node) error { + nodePath = append(nodePath, n) + return nil + })) // Root and 1 value require.Len(nodePath, 2) @@ -172,8 +173,11 @@ func TestTrieViewGetPathTo(t *testing.T) { trie = trieIntf.(*trieView) require.NoError(trie.calculateNodeIDs(context.Background())) - nodePath, err = trie.getPathTo(ToKey(key2, BranchFactor16)) - require.NoError(err) + nodePath = make([]*node, 0, 3) + require.NoError(trie.visitPathToKey(ToKey(key2, BranchFactor16), func(n *node) error { + nodePath = append(nodePath, n) + return nil + })) require.Len(nodePath, 3) require.Equal(trie.root, nodePath[0]) require.Equal(ToKey(key1, BranchFactor16), nodePath[1].key) @@ -194,15 +198,21 @@ func TestTrieViewGetPathTo(t *testing.T) { trie = trieIntf.(*trieView) require.NoError(trie.calculateNodeIDs(context.Background())) - nodePath, err = trie.getPathTo(ToKey(key3, BranchFactor16)) - require.NoError(err) + nodePath = make([]*node, 0, 2) + require.NoError(trie.visitPathToKey(ToKey(key3, BranchFactor16), func(n *node) error { + nodePath = append(nodePath, n) + return nil + })) require.Len(nodePath, 2) require.Equal(trie.root, nodePath[0]) require.Equal(ToKey(key3, BranchFactor16), nodePath[1].key) // Other key path not affected - nodePath, err = trie.getPathTo(ToKey(key2, BranchFactor16)) - require.NoError(err) + nodePath = make([]*node, 0, 3) + require.NoError(trie.visitPathToKey(ToKey(key2, BranchFactor16), func(n *node) error { + nodePath = append(nodePath, n) + return nil + })) require.Len(nodePath, 3) require.Equal(trie.root, nodePath[0]) require.Equal(ToKey(key1, BranchFactor16), nodePath[1].key) @@ -210,8 +220,11 @@ func TestTrieViewGetPathTo(t *testing.T) { // Gets closest node when key doesn't exist key4 := []byte{0, 1, 2} - nodePath, err = trie.getPathTo(ToKey(key4, BranchFactor16)) - require.NoError(err) + nodePath = make([]*node, 0, 3) + require.NoError(trie.visitPathToKey(ToKey(key4, BranchFactor16), func(n *node) error { + nodePath = append(nodePath, n) + return nil + })) require.Len(nodePath, 3) require.Equal(trie.root, nodePath[0]) require.Equal(ToKey(key1, BranchFactor16), nodePath[1].key) @@ -219,8 +232,11 @@ func TestTrieViewGetPathTo(t *testing.T) { // Gets just root when key doesn't exist and no key shares a prefix key5 := []byte{128} - nodePath, err = trie.getPathTo(ToKey(key5, BranchFactor16)) - require.NoError(err) + nodePath = make([]*node, 0, 1) + require.NoError(trie.visitPathToKey(ToKey(key5, BranchFactor16), func(n *node) error { + nodePath = append(nodePath, n) + return nil + })) require.Len(nodePath, 1) require.Equal(trie.root, nodePath[0]) } diff --git a/x/merkledb/trieview.go b/x/merkledb/trieview.go index d83c50901096..3422379a20cc 100644 --- a/x/merkledb/trieview.go +++ b/x/merkledb/trieview.go @@ -337,19 +337,15 @@ func (t *trieView) getProof(ctx context.Context, key []byte) (*Proof, error) { Key: t.db.toKey(key), } - proofPath, err := t.getPathTo(proof.Key) - if err != nil { + var closestNode *node + if err := t.visitPathToKey(proof.Key, func(n *node) error { + closestNode = n + proof.Path = append(proof.Path, n.asProofNode()) + return nil + }); err != nil { return nil, err } - // From root --> node from left --> right. - proof.Path = make([]ProofNode, len(proofPath), len(proofPath)+1) - for i, node := range proofPath { - proof.Path[i] = node.asProofNode() - } - - closestNode := proofPath[len(proofPath)-1] - if closestNode.key == proof.Key { // There is a node with the given [key]. proof.Value = maybe.Bind(closestNode.value, slices.Clone[[]byte]) @@ -619,46 +615,50 @@ func (t *trieView) remove(key Key) error { return ErrNodesAlreadyCalculated } - nodePath, err := t.getPathTo(key) + // confirm a node exists with a value + keyNode, err := t.getNodeWithID(ids.Empty, key, true) if err != nil { + if errors.Is(err, database.ErrNotFound) { + // key didn't exist + return nil + } return err } - nodeToDelete := nodePath[len(nodePath)-1] - - if nodeToDelete.key != key || !nodeToDelete.hasValue() { - // the key wasn't in the trie or doesn't have a value so there's nothing to do + // node doesn't contain a value + if !keyNode.hasValue() { return nil } - // A node with ancestry [nodePath] is being deleted, so we need to recalculate - // all the nodes in this path. - for _, node := range nodePath { - if err := t.recordNodeChange(node); err != nil { - return err - } + // if the node exists and contains a value + // mark all ancestor for change + // grab parent and grandparent nodes for path compression + var grandParent, parent, nodeToDelete *node + if err := t.visitPathToKey(key, func(n *node) error { + grandParent = parent + parent = nodeToDelete + nodeToDelete = n + return t.recordNodeChange(n) + }); err != nil { + return err } nodeToDelete.setValue(maybe.Nothing[[]byte]()) - if err := t.recordNodeChange(nodeToDelete); err != nil { - return err + if len(nodeToDelete.children) != 0 { + // merge this node and its child into a single node if possible + return t.compressNodePath(parent, nodeToDelete) } // if the removed node has no children, the node can be removed from the trie - if len(nodeToDelete.children) == 0 { - return t.deleteEmptyNodes(nodePath) - } - - if len(nodePath) == 1 { - return nil - } - 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 { + if err := t.recordNodeDeleted(nodeToDelete); err != nil { return err } + if parent != nil { + parent.removeChild(nodeToDelete) + // merge the parent node and its child into a single node if possible + return t.compressNodePath(grandParent, parent) + } return nil } @@ -676,117 +676,71 @@ func (t *trieView) compressNodePath(parent, node *node) error { } // 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 parent == nil || len(node.children) != 1 || node.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 { - return err - } - - var ( - childEntry child - childPath Key - ) - // 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.compressedKey) - childEntry = entry - } + if err := t.recordNodeDeleted(node); err != nil { + return err + } - nextNode, err := t.getNodeWithID(childEntry.id, childPath, childEntry.hasValue) - if err != nil { - return err - } - node = nextNode + var ( + childEntry child + childKey Key + ) + // 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 { + childKey = node.key.AppendExtend(index, entry.compressedKey) + childEntry = entry } // [node] is the first node with multiple children. // combine it with the [node] passed in. - parent.addChild(node) + parent.setChildEntry(childKey.Token(parent.key.tokenLength), + child{ + compressedKey: childKey.Skip(parent.key.tokenLength + 1), + id: childEntry.id, + hasValue: childEntry.hasValue, + }) return t.recordNodeChange(parent) } -// Starting from the last node in [nodePath], traverses toward the root -// and deletes each node that has no value and no children. -// Stops when a node with a value or children is reached. -// Assumes [nodePath] is a path from the root to a node. -// Must not be called after [calculateNodeIDs] has returned. -func (t *trieView) deleteEmptyNodes(nodePath []*node) error { - if t.nodesAlreadyCalculated.Get() { - return ErrNodesAlreadyCalculated - } - - node := 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 { - return err - } - - parent := nodePath[nextParentIndex] - - parent.removeChild(node) - if err := t.recordNodeChange(parent); err != nil { - return err - } - - node = parent - } - - if nextParentIndex < 0 { - return nil - } - parent := nodePath[nextParentIndex] - - return t.compressNodePath(parent, node) -} - // Returns the nodes along the path to [key]. // 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 Key) ([]*node, error) { +func (t *trieView) visitPathToKey(key Key, visitNode func(*node) error) error { var ( // all node paths start at the root - currentNode = t.root - matchedPathIndex = 0 - nodes = []*node{t.root} + currentNode = t.root + err error ) - + if err := visitNode(currentNode); err != nil { + return err + } // while the entire path hasn't been matched - for matchedPathIndex < key.tokenLength { + for currentNode.key.tokenLength < key.tokenLength { // confirm that a child exists and grab its ID before attempting to load it - nextChildEntry, hasChild := currentNode.children[key.Token(matchedPathIndex)] + nextChildEntry, hasChild := currentNode.children[key.Token(currentNode.key.tokenLength)] - // the current token for the child entry has now been handled, so increment the matchedPathIndex - matchedPathIndex += 1 - - if !hasChild || !key.iteratedHasPrefix(matchedPathIndex, nextChildEntry.compressedKey) { + if !hasChild || !key.iteratedHasPrefix(currentNode.key.tokenLength+1, nextChildEntry.compressedKey) { // there was no child along the path or the child that was there doesn't match the remaining path - return nodes, nil + return nil } - // the compressed path of the entry there matched the path, so increment the matched index - matchedPathIndex += nextChildEntry.compressedKey.tokenLength - // grab the next node along the path - var err error - currentNode, err = t.getNodeWithID(nextChildEntry.id, key.Take(matchedPathIndex), nextChildEntry.hasValue) + currentNode, err = t.getNodeWithID(nextChildEntry.id, key.Take(currentNode.key.tokenLength+1+nextChildEntry.compressedKey.tokenLength), nextChildEntry.hasValue) if err != nil { - return nil, err + return err + } + if err := visitNode(currentNode); err != nil { + return err } - - // add node to path - nodes = append(nodes, currentNode) } - return nodes, nil + return nil } func getLengthOfCommonPrefix(first, second Key, secondOffset int) int { @@ -829,22 +783,14 @@ func (t *trieView) insert( return nil, ErrNodesAlreadyCalculated } - // find the node that most closely matches [key] - pathToNode, err := t.getPathTo(key) - if err != nil { + var closestNode *node + if err := t.visitPathToKey(key, func(n *node) error { + closestNode = n + return t.recordNodeChange(n) + }); err != nil { return nil, err } - // We're inserting a node whose ancestry is [pathToNode] - // so we'll need to recalculate their IDs. - for _, node := range pathToNode { - if err := t.recordNodeChange(node); err != nil { - return nil, err - } - } - - closestNode := pathToNode[len(pathToNode)-1] - // a node with that exact path already exists so update its value if closestNode.key == key { closestNode.setValue(value) From fe74ed1a17e1c179585a4bd6abf014b9dabc341f Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Thu, 26 Oct 2023 12:54:34 -0400 Subject: [PATCH 02/19] `merkledb` -- shift nit (#2218) Signed-off-by: Dan Laine --- x/merkledb/key.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/merkledb/key.go b/x/merkledb/key.go index a2b6a3da065e..461372a2baa8 100644 --- a/x/merkledb/key.go +++ b/x/merkledb/key.go @@ -113,9 +113,9 @@ func (k Key) HasPrefix(prefix Key) bool { // check that the tokens in the partially filled final byte of [prefix] are // equal to the tokens in the final byte of [k]. - remainderBitsMask := byte(0xFF << (8 - remainderTokensCount*int(k.tokenBitSize))) - prefixRemainderTokens := prefix.value[len(prefix.value)-1] & remainderBitsMask - remainderTokens := k.value[len(prefix.value)-1] & remainderBitsMask + remainderBitsMask := byte(0xFF >> (remainderTokensCount * int(k.tokenBitSize))) + prefixRemainderTokens := prefix.value[len(prefix.value)-1] | remainderBitsMask + remainderTokens := k.value[len(prefix.value)-1] | remainderBitsMask if prefixRemainderTokens != remainderTokens { return false From a6448acccb259e0878225da0bea91c11fe86eeb5 Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:48:00 -0400 Subject: [PATCH 03/19] Update `golangci-lint` to `v1.55.1` (#2228) --- .golangci.yml | 2 +- api/auth/auth_test.go | 29 ++++++++++--------- config/config_test.go | 2 +- ids/id_test.go | 2 +- scripts/lint.sh | 2 +- snow/consensus/snowball/tree_test.go | 1 + utils/timer/adaptive_timeout_manager_test.go | 2 +- vms/avm/txs/import_tx.go | 2 +- vms/avm/vm.go | 2 +- vms/components/avax/base_tx.go | 2 +- vms/components/avax/utxo_id_test.go | 2 +- vms/platformvm/service.go | 2 +- .../txs/executor/standard_tx_executor.go | 2 +- vms/platformvm/utxo/handler.go | 2 +- wallet/chain/x/builder.go | 8 ++--- 15 files changed, 32 insertions(+), 30 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9f1dcc9c9389..160f617659ff 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -69,8 +69,8 @@ linters: - revive - staticcheck - stylecheck - - typecheck - tagalign + - typecheck - unconvert - unparam - unused diff --git a/api/auth/auth_test.go b/api/auth/auth_test.go index e691b11d8686..d8b7a4cca59b 100644 --- a/api/auth/auth_test.go +++ b/api/auth/auth_test.go @@ -27,6 +27,7 @@ var ( hashedPassword = password.Hash{} unAuthorizedResponseRegex = `^{"jsonrpc":"2.0","error":{"code":-32600,"message":"(.*)"},"id":1}` errTest = errors.New("non-nil error") + hostName = "http://127.0.0.1:9650" ) func init() { @@ -161,8 +162,8 @@ func TestWrapHandlerHappyPath(t *testing.T) { wrappedHandler := auth.WrapHandler(dummyHandler) for _, endpoint := range endpoints { - req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader("")) - req.Header.Add("Authorization", "Bearer "+tokenStr) + req := httptest.NewRequest(http.MethodPost, hostName+endpoint, strings.NewReader("")) + req.Header.Add("Authorization", headerValStart+tokenStr) rr := httptest.NewRecorder() wrappedHandler.ServeHTTP(rr, req) require.Equal(http.StatusOK, rr.Code) @@ -184,8 +185,8 @@ func TestWrapHandlerRevokedToken(t *testing.T) { wrappedHandler := auth.WrapHandler(dummyHandler) for _, endpoint := range endpoints { - req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader("")) - req.Header.Add("Authorization", "Bearer "+tokenStr) + req := httptest.NewRequest(http.MethodPost, hostName+endpoint, strings.NewReader("")) + req.Header.Add("Authorization", headerValStart+tokenStr) rr := httptest.NewRecorder() wrappedHandler.ServeHTTP(rr, req) require.Equal(http.StatusUnauthorized, rr.Code) @@ -209,8 +210,8 @@ func TestWrapHandlerExpiredToken(t *testing.T) { wrappedHandler := auth.WrapHandler(dummyHandler) for _, endpoint := range endpoints { - req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader("")) - req.Header.Add("Authorization", "Bearer "+tokenStr) + req := httptest.NewRequest(http.MethodPost, hostName+endpoint, strings.NewReader("")) + req.Header.Add("Authorization", headerValStart+tokenStr) rr := httptest.NewRecorder() wrappedHandler.ServeHTTP(rr, req) require.Equal(http.StatusUnauthorized, rr.Code) @@ -250,8 +251,8 @@ func TestWrapHandlerUnauthorizedEndpoint(t *testing.T) { wrappedHandler := auth.WrapHandler(dummyHandler) for _, endpoint := range unauthorizedEndpoints { - req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader("")) - req.Header.Add("Authorization", "Bearer "+tokenStr) + req := httptest.NewRequest(http.MethodPost, hostName+endpoint, strings.NewReader("")) + req.Header.Add("Authorization", headerValStart+tokenStr) rr := httptest.NewRecorder() wrappedHandler.ServeHTTP(rr, req) require.Equal(http.StatusUnauthorized, rr.Code) @@ -272,7 +273,7 @@ func TestWrapHandlerAuthEndpoint(t *testing.T) { wrappedHandler := auth.WrapHandler(dummyHandler) req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650/ext/auth", strings.NewReader("")) - req.Header.Add("Authorization", "Bearer "+tokenStr) + req.Header.Add("Authorization", headerValStart+tokenStr) rr := httptest.NewRecorder() wrappedHandler.ServeHTTP(rr, req) require.Equal(http.StatusOK, rr.Code) @@ -290,8 +291,8 @@ func TestWrapHandlerAccessAll(t *testing.T) { wrappedHandler := auth.WrapHandler(dummyHandler) for _, endpoint := range endpoints { - req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader("")) - req.Header.Add("Authorization", "Bearer "+tokenStr) + req := httptest.NewRequest(http.MethodPost, hostName+endpoint, strings.NewReader("")) + req.Header.Add("Authorization", headerValStart+tokenStr) rr := httptest.NewRecorder() wrappedHandler.ServeHTTP(rr, req) require.Equal(http.StatusOK, rr.Code) @@ -322,7 +323,7 @@ func TestWrapHandlerMutatedRevokedToken(t *testing.T) { wrappedHandler := auth.WrapHandler(dummyHandler) for _, endpoint := range endpoints { - req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader("")) + req := httptest.NewRequest(http.MethodPost, hostName+endpoint, strings.NewReader("")) req.Header.Add("Authorization", fmt.Sprintf("Bearer %s=", tokenStr)) // The appended = at the end looks like padding rr := httptest.NewRecorder() wrappedHandler.ServeHTTP(rr, req) @@ -356,8 +357,8 @@ func TestWrapHandlerInvalidSigningMethod(t *testing.T) { wrappedHandler := auth.WrapHandler(dummyHandler) for _, endpoint := range endpoints { - req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader("")) - req.Header.Add("Authorization", "Bearer "+tokenStr) + req := httptest.NewRequest(http.MethodPost, hostName+endpoint, strings.NewReader("")) + req.Header.Add("Authorization", headerValStart+tokenStr) rr := httptest.NewRecorder() wrappedHandler.ServeHTTP(rr, req) require.Equal(http.StatusUnauthorized, rr.Code) diff --git a/config/config_test.go b/config/config_test.go index 8c2498d02c75..037b8ac450cc 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -73,7 +73,7 @@ func TestGetChainConfigsFromFiles(t *testing.T) { // Create custom configs for key, value := range test.configs { chainDir := filepath.Join(chainsDir, key) - setupFile(t, chainDir, chainConfigFileName+".ex", value) + setupFile(t, chainDir, chainConfigFileName+".ex", value) //nolint:goconst } for key, value := range test.upgrades { chainDir := filepath.Join(chainsDir, key) diff --git a/ids/id_test.go b/ids/id_test.go index 0a85cead49c2..3424b17633e6 100644 --- a/ids/id_test.go +++ b/ids/id_test.go @@ -149,7 +149,7 @@ func TestIDUnmarshalJSON(t *testing.T) { func TestIDHex(t *testing.T) { id := ID{'a', 'v', 'a', ' ', 'l', 'a', 'b', 's'} - expected := "617661206c616273000000000000000000000000000000000000000000000000" //nolint:gosec + expected := "617661206c616273000000000000000000000000000000000000000000000000" require.Equal(t, expected, id.Hex()) } diff --git a/scripts/lint.sh b/scripts/lint.sh index c6417b7f51f6..a34dee76a9e8 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -32,7 +32,7 @@ fi TESTS=${TESTS:-"golangci_lint license_header require_error_is_no_funcs_as_params single_import interface_compliance_nil require_equal_zero require_len_zero require_equal_len require_nil require_no_error_inline_func"} function test_golangci_lint { - go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2 + go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.1 golangci-lint run --config .golangci.yml } diff --git a/snow/consensus/snowball/tree_test.go b/snow/consensus/snowball/tree_test.go index 4aff386174ed..8b0f6159df72 100644 --- a/snow/consensus/snowball/tree_test.go +++ b/snow/consensus/snowball/tree_test.go @@ -1,6 +1,7 @@ // Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. +//nolint:goconst package snowball import ( diff --git a/utils/timer/adaptive_timeout_manager_test.go b/utils/timer/adaptive_timeout_manager_test.go index 781686261b52..ec9964bd5a7f 100644 --- a/utils/timer/adaptive_timeout_manager_test.go +++ b/utils/timer/adaptive_timeout_manager_test.go @@ -84,7 +84,7 @@ func TestAdaptiveTimeoutManagerInit(t *testing.T) { } for _, test := range tests { - _, err := NewAdaptiveTimeoutManager(&test.config, "", prometheus.NewRegistry()) //nolint:gosec + _, err := NewAdaptiveTimeoutManager(&test.config, "", prometheus.NewRegistry()) require.ErrorIs(t, err, test.expectedErr) } } diff --git a/vms/avm/txs/import_tx.go b/vms/avm/txs/import_tx.go index 94a12442f4a8..c3066ccc5c40 100644 --- a/vms/avm/txs/import_tx.go +++ b/vms/avm/txs/import_tx.go @@ -31,7 +31,7 @@ func (t *ImportTx) InputUTXOs() []*avax.UTXOID { utxos := t.BaseTx.InputUTXOs() for _, in := range t.ImportedIns { in.Symbol = true - utxos = append(utxos, &in.UTXOID) //nolint:gosec + utxos = append(utxos, &in.UTXOID) } return utxos } diff --git a/vms/avm/vm.go b/vms/avm/vm.go index 869f62e7e39c..50bc646580a0 100644 --- a/vms/avm/vm.go +++ b/vms/avm/vm.go @@ -536,7 +536,7 @@ func (vm *VM) initGenesis(genesisBytes []byte) error { } tx := &txs.Tx{ - Unsigned: &genesisTx.CreateAssetTx, //nolint:gosec + Unsigned: &genesisTx.CreateAssetTx, } if err := vm.parser.InitializeGenesisTx(tx); err != nil { return err diff --git a/vms/components/avax/base_tx.go b/vms/components/avax/base_tx.go index a57793a48213..2bcafa24e497 100644 --- a/vms/components/avax/base_tx.go +++ b/vms/components/avax/base_tx.go @@ -35,7 +35,7 @@ type BaseTx struct { func (t *BaseTx) InputUTXOs() []*UTXOID { utxos := make([]*UTXOID, len(t.Ins)) for i, in := range t.Ins { - utxos[i] = &in.UTXOID //nolint:gosec + utxos[i] = &in.UTXOID } return utxos } diff --git a/vms/components/avax/utxo_id_test.go b/vms/components/avax/utxo_id_test.go index 5e86dfde4801..5652fa1afa69 100644 --- a/vms/components/avax/utxo_id_test.go +++ b/vms/components/avax/utxo_id_test.go @@ -99,7 +99,7 @@ func TestUTXOIDLess(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - require.Equal(t, tt.expected, tt.id1.Less(&tt.id2)) //nolint:gosec + require.Equal(t, tt.expected, tt.id1.Less(&tt.id2)) }) } } diff --git a/vms/platformvm/service.go b/vms/platformvm/service.go index 7eb0f98a2f8f..a2871faf0682 100644 --- a/vms/platformvm/service.go +++ b/vms/platformvm/service.go @@ -303,7 +303,7 @@ utxoFor: continue utxoFor } - response.UTXOIDs = append(response.UTXOIDs, &utxo.UTXOID) //nolint:gosec + response.UTXOIDs = append(response.UTXOIDs, &utxo.UTXOID) } balances := maps.Clone(lockedStakeables) diff --git a/vms/platformvm/txs/executor/standard_tx_executor.go b/vms/platformvm/txs/executor/standard_tx_executor.go index 92a4af6cc09e..2aa9e9c4a400 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor.go +++ b/vms/platformvm/txs/executor/standard_tx_executor.go @@ -155,7 +155,7 @@ func (e *StandardTxExecutor) ImportTx(tx *txs.ImportTx) error { for index, input := range tx.Ins { utxo, err := e.State.GetUTXO(input.InputID()) if err != nil { - return fmt.Errorf("failed to get UTXO %s: %w", &input.UTXOID, err) //nolint:gosec + return fmt.Errorf("failed to get UTXO %s: %w", &input.UTXOID, err) } utxos[index] = utxo } diff --git a/vms/platformvm/utxo/handler.go b/vms/platformvm/utxo/handler.go index b617783bca0b..2d652103fee2 100644 --- a/vms/platformvm/utxo/handler.go +++ b/vms/platformvm/utxo/handler.go @@ -443,7 +443,7 @@ func (h *handler) VerifySpend( if err != nil { return fmt.Errorf( "failed to read consumed UTXO %s due to: %w", - &input.UTXOID, //nolint:gosec + &input.UTXOID, err, ) } diff --git a/wallet/chain/x/builder.go b/wallet/chain/x/builder.go index ba88db984833..0b639a7776ad 100644 --- a/wallet/chain/x/builder.go +++ b/wallet/chain/x/builder.go @@ -655,7 +655,7 @@ func (b *builder) mintFTs( // add the operation to the array operations = append(operations, &txs.Operation{ Asset: utxo.Asset, - UTXOIDs: []*avax.UTXOID{&utxo.UTXOID}, //nolint:gosec + UTXOIDs: []*avax.UTXOID{&utxo.UTXOID}, Op: &secp256k1fx.MintOperation{ MintInput: secp256k1fx.Input{ SigIndices: inputSigIndices, @@ -717,7 +717,7 @@ func (b *builder) mintNFTs( operations = append(operations, &txs.Operation{ Asset: avax.Asset{ID: assetID}, UTXOIDs: []*avax.UTXOID{ - &utxo.UTXOID, //nolint:gosec + &utxo.UTXOID, }, Op: &nftfx.MintOperation{ MintInput: secp256k1fx.Input{ @@ -773,7 +773,7 @@ func (b *builder) mintProperty( operations = append(operations, &txs.Operation{ Asset: avax.Asset{ID: assetID}, UTXOIDs: []*avax.UTXOID{ - &utxo.UTXOID, //nolint:gosec + &utxo.UTXOID, }, Op: &propertyfx.MintOperation{ MintInput: secp256k1fx.Input{ @@ -829,7 +829,7 @@ func (b *builder) burnProperty( operations = append(operations, &txs.Operation{ Asset: avax.Asset{ID: assetID}, UTXOIDs: []*avax.UTXOID{ - &utxo.UTXOID, //nolint:gosec + &utxo.UTXOID, }, Op: &propertyfx.BurnOperation{ Input: secp256k1fx.Input{ From 3b213fcd0221e6d0655570c8bb4188f06cd02f95 Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:53:26 -0400 Subject: [PATCH 04/19] Add json marshal tests to existing serialization tests in `platformvm/txs` pkg (#2227) --- .../add_permissionless_delegator_tx_test.go | 279 ++++++++++++++++++ vms/platformvm/txs/base_tx_test.go | 35 ++- .../txs/remove_subnet_validator_tx_test.go | 94 ++++++ .../txs/transform_subnet_tx_test.go | 106 +++++++ 4 files changed, 507 insertions(+), 7 deletions(-) diff --git a/vms/platformvm/txs/add_permissionless_delegator_tx_test.go b/vms/platformvm/txs/add_permissionless_delegator_tx_test.go index 26e8d402bc84..821a3b7da849 100644 --- a/vms/platformvm/txs/add_permissionless_delegator_tx_test.go +++ b/vms/platformvm/txs/add_permissionless_delegator_tx_test.go @@ -4,6 +4,7 @@ package txs import ( + "encoding/json" "errors" "math" "testing" @@ -601,6 +602,145 @@ func TestAddPermissionlessPrimaryDelegatorSerialization(t *testing.T) { unsignedComplexAddPrimaryTxBytes, err := Codec.Marshal(Version, &unsignedComplexAddPrimaryTx) require.NoError(err) require.Equal(expectedUnsignedComplexAddPrimaryTxBytes, unsignedComplexAddPrimaryTxBytes) + + aliaser := ids.NewAliaser() + require.NoError(aliaser.Alias(constants.PlatformChainID, "P")) + + unsignedComplexAddPrimaryTx.InitCtx(&snow.Context{ + NetworkID: 1, + ChainID: constants.PlatformChainID, + AVAXAssetID: avaxAssetID, + BCLookup: aliaser, + }) + + unsignedComplexAddPrimaryTxJSONBytes, err := json.MarshalIndent(unsignedComplexAddPrimaryTx, "", "\t") + require.NoError(err) + require.Equal(`{ + "networkID": 1, + "blockchainID": "11111111111111111111111111111111LpoYY", + "outputs": [ + { + "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "addresses": [ + "P-avax1g32kvaugnx4tk3z4vemc3xd2hdz92enh972wxr" + ], + "amount": 1, + "locktime": 0, + "threshold": 1 + } + }, + { + "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "locktime": 87654321, + "output": { + "addresses": [], + "amount": 1, + "locktime": 12345678, + "threshold": 0 + } + } + }, + { + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "locktime": 876543210, + "output": { + "addresses": [ + "P-avax1g32kvaugnx4tk3z4vemc3xd2hdz92enh972wxr" + ], + "amount": 18446744073709551615, + "locktime": 0, + "threshold": 1 + } + } + } + ], + "inputs": [ + { + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 1, + "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "input": { + "amount": 1000000000000000, + "signatureIndices": [ + 2, + 5 + ] + } + }, + { + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 2, + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "input": { + "locktime": 876543210, + "input": { + "amount": 17293822569102704639, + "signatureIndices": [ + 0 + ] + } + } + }, + { + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 3, + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "input": { + "amount": 1152921504606846976, + "signatureIndices": [] + } + } + ], + "memo": "0xf09f98850a77656c6c2074686174277301234521", + "validator": { + "nodeID": "NodeID-2ZbTY9GatRTrfinAoYiYLcf6CvrPAUYgo", + "start": 12345, + "end": 17292345, + "weight": 5000000000000 + }, + "subnetID": "11111111111111111111111111111111LpoYY", + "stake": [ + { + "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "addresses": [ + "P-avax1g32kvaugnx4tk3z4vemc3xd2hdz92enh972wxr" + ], + "amount": 2000000000000, + "locktime": 0, + "threshold": 1 + } + }, + { + "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "locktime": 987654321, + "output": { + "addresses": [], + "amount": 3000000000000, + "locktime": 87654321, + "threshold": 0 + } + } + } + ], + "rewardsOwner": { + "addresses": [], + "locktime": 0, + "threshold": 0 + } +}`, string(unsignedComplexAddPrimaryTxJSONBytes)) } func TestAddPermissionlessSubnetDelegatorSerialization(t *testing.T) { @@ -1218,6 +1358,145 @@ func TestAddPermissionlessSubnetDelegatorSerialization(t *testing.T) { unsignedComplexAddSubnetTxBytes, err := Codec.Marshal(Version, &unsignedComplexAddSubnetTx) require.NoError(err) require.Equal(expectedUnsignedComplexAddSubnetTxBytes, unsignedComplexAddSubnetTxBytes) + + aliaser := ids.NewAliaser() + require.NoError(aliaser.Alias(constants.PlatformChainID, "P")) + + unsignedComplexAddSubnetTx.InitCtx(&snow.Context{ + NetworkID: 1, + ChainID: constants.PlatformChainID, + AVAXAssetID: avaxAssetID, + BCLookup: aliaser, + }) + + unsignedComplexAddSubnetTxJSONBytes, err := json.MarshalIndent(unsignedComplexAddSubnetTx, "", "\t") + require.NoError(err) + require.Equal(`{ + "networkID": 1, + "blockchainID": "11111111111111111111111111111111LpoYY", + "outputs": [ + { + "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "addresses": [ + "P-avax1g32kvaugnx4tk3z4vemc3xd2hdz92enh972wxr" + ], + "amount": 1, + "locktime": 0, + "threshold": 1 + } + }, + { + "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "locktime": 87654321, + "output": { + "addresses": [], + "amount": 1, + "locktime": 12345678, + "threshold": 0 + } + } + }, + { + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "locktime": 876543210, + "output": { + "addresses": [ + "P-avax1g32kvaugnx4tk3z4vemc3xd2hdz92enh972wxr" + ], + "amount": 18446744073709551600, + "locktime": 0, + "threshold": 1 + } + } + } + ], + "inputs": [ + { + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 1, + "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "input": { + "amount": 1000000000000000, + "signatureIndices": [ + 2, + 5 + ] + } + }, + { + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 2, + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "input": { + "locktime": 876543210, + "input": { + "amount": 17293822569102704639, + "signatureIndices": [ + 0 + ] + } + } + }, + { + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 3, + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "input": { + "amount": 1152921504606846976, + "signatureIndices": [] + } + } + ], + "memo": "0xf09f98850a77656c6c2074686174277301234521", + "validator": { + "nodeID": "NodeID-2ZbTY9GatRTrfinAoYiYLcf6CvrPAUYgo", + "start": 12345, + "end": 12346, + "weight": 9 + }, + "subnetID": "SkB92YpWm4UpburLz9tEKZw2i67H3FF6YkjaU4BkFUDTG9Xm", + "stake": [ + { + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "addresses": [ + "P-avax1g32kvaugnx4tk3z4vemc3xd2hdz92enh972wxr" + ], + "amount": 2, + "locktime": 0, + "threshold": 1 + } + }, + { + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "locktime": 987654321, + "output": { + "addresses": [], + "amount": 7, + "locktime": 87654321, + "threshold": 0 + } + } + } + ], + "rewardsOwner": { + "addresses": [], + "locktime": 0, + "threshold": 0 + } +}`, string(unsignedComplexAddSubnetTxJSONBytes)) } func TestAddPermissionlessDelegatorTxSyntacticVerify(t *testing.T) { diff --git a/vms/platformvm/txs/base_tx_test.go b/vms/platformvm/txs/base_tx_test.go index a2c616b7cc48..073b27f25056 100644 --- a/vms/platformvm/txs/base_tx_test.go +++ b/vms/platformvm/txs/base_tx_test.go @@ -41,13 +41,34 @@ func TestBaseTxMarshalJSON(t *testing.T) { Memo: []byte{1, 2, 3}, }} - txBytes, err := json.Marshal(tx) + txJSONBytes, err := json.MarshalIndent(tx, "", "\t") require.NoError(err) - asString := string(txBytes) - - require.Contains(asString, `"networkID":4`) - require.Contains(asString, `"blockchainID":"SYXsAycDPUu4z2ZksJD5fh5nTDcH3vCFHnpcVye5XuJ2jArg"`) - require.Contains(asString, `"inputs":[{"txID":"t64jLxDRmxo8y48WjbRALPAZuSDZ6qPVaaeDzxHA4oSojhLt","outputIndex":5,"assetID":"2KdbbWvpeAShCx5hGbtdF15FMMepq9kajsNTqVvvEbhiCRSxU","fxID":"2mB8TguRrYvbGw7G2UBqKfmL8osS7CfmzAAHSzuZK8bwpRKdY","input":{"Err":null,"Val":100}}]`) - require.Contains(asString, `"outputs":[{"assetID":"2KdbbWvpeAShCx5hGbtdF15FMMepq9kajsNTqVvvEbhiCRSxU","fxID":"2mB8TguRrYvbGw7G2UBqKfmL8osS7CfmzAAHSzuZK8bwpRKdY","output":{"Err":null,"Val":100}}]`) + require.Equal(`{ + "networkID": 4, + "blockchainID": "SYXsAycDPUu4z2ZksJD5fh5nTDcH3vCFHnpcVye5XuJ2jArg", + "outputs": [ + { + "assetID": "2KdbbWvpeAShCx5hGbtdF15FMMepq9kajsNTqVvvEbhiCRSxU", + "fxID": "2mB8TguRrYvbGw7G2UBqKfmL8osS7CfmzAAHSzuZK8bwpRKdY", + "output": { + "Err": null, + "Val": 100 + } + } + ], + "inputs": [ + { + "txID": "t64jLxDRmxo8y48WjbRALPAZuSDZ6qPVaaeDzxHA4oSojhLt", + "outputIndex": 5, + "assetID": "2KdbbWvpeAShCx5hGbtdF15FMMepq9kajsNTqVvvEbhiCRSxU", + "fxID": "2mB8TguRrYvbGw7G2UBqKfmL8osS7CfmzAAHSzuZK8bwpRKdY", + "input": { + "Err": null, + "Val": 100 + } + } + ], + "memo": "0x010203" +}`, string(txJSONBytes)) } diff --git a/vms/platformvm/txs/remove_subnet_validator_tx_test.go b/vms/platformvm/txs/remove_subnet_validator_tx_test.go index 910eb1a17838..02a9fdce7496 100644 --- a/vms/platformvm/txs/remove_subnet_validator_tx_test.go +++ b/vms/platformvm/txs/remove_subnet_validator_tx_test.go @@ -4,6 +4,7 @@ package txs import ( + "encoding/json" "errors" "testing" @@ -419,6 +420,99 @@ func TestRemoveSubnetValidatorTxSerialization(t *testing.T) { unsignedComplexRemoveValidatorTxBytes, err := Codec.Marshal(Version, &unsignedComplexRemoveValidatorTx) require.NoError(err) require.Equal(expectedUnsignedComplexRemoveValidatorTxBytes, unsignedComplexRemoveValidatorTxBytes) + + aliaser := ids.NewAliaser() + require.NoError(aliaser.Alias(constants.PlatformChainID, "P")) + + unsignedComplexRemoveValidatorTx.InitCtx(&snow.Context{ + NetworkID: 1, + ChainID: constants.PlatformChainID, + AVAXAssetID: avaxAssetID, + BCLookup: aliaser, + }) + + unsignedComplexRemoveValidatorTxJSONBytes, err := json.MarshalIndent(unsignedComplexRemoveValidatorTx, "", "\t") + require.NoError(err) + require.Equal(`{ + "networkID": 1, + "blockchainID": "11111111111111111111111111111111LpoYY", + "outputs": [ + { + "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "locktime": 87654321, + "output": { + "addresses": [], + "amount": 1, + "locktime": 12345678, + "threshold": 0 + } + } + }, + { + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "locktime": 876543210, + "output": { + "addresses": [ + "P-avax1g32kvaugnx4tk3z4vemc3xd2hdz92enh972wxr" + ], + "amount": 18446744073709551615, + "locktime": 0, + "threshold": 1 + } + } + } + ], + "inputs": [ + { + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 1, + "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "input": { + "amount": 1000000000, + "signatureIndices": [ + 2, + 5 + ] + } + }, + { + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 2, + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "input": { + "locktime": 876543210, + "input": { + "amount": 17293822569102704639, + "signatureIndices": [ + 0 + ] + } + } + }, + { + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 3, + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "input": { + "amount": 1152921504606846976, + "signatureIndices": [] + } + } + ], + "memo": "0xf09f98850a77656c6c2074686174277301234521", + "nodeID": "NodeID-2ZbTY9GatRTrfinAoYiYLcf6CvrPAUYgo", + "subnetID": "SkB92YpWm4UpburLz9tEKZw2i67H3FF6YkjaU4BkFUDTG9Xm", + "subnetAuthorization": { + "signatureIndices": [] + } +}`, string(unsignedComplexRemoveValidatorTxJSONBytes)) } func TestRemoveSubnetValidatorTxSyntacticVerify(t *testing.T) { diff --git a/vms/platformvm/txs/transform_subnet_tx_test.go b/vms/platformvm/txs/transform_subnet_tx_test.go index 6087e1ace4cb..4b88fd60ef3a 100644 --- a/vms/platformvm/txs/transform_subnet_tx_test.go +++ b/vms/platformvm/txs/transform_subnet_tx_test.go @@ -4,6 +4,7 @@ package txs import ( + "encoding/json" "testing" "github.com/stretchr/testify/require" @@ -522,6 +523,111 @@ func TestTransformSubnetTxSerialization(t *testing.T) { unsignedComplexTransformTxBytes, err := Codec.Marshal(Version, &unsignedComplexTransformTx) require.NoError(err) require.Equal(expectedUnsignedComplexTransformTxBytes, unsignedComplexTransformTxBytes) + + aliaser := ids.NewAliaser() + require.NoError(aliaser.Alias(constants.PlatformChainID, "P")) + + unsignedComplexTransformTx.InitCtx(&snow.Context{ + NetworkID: 1, + ChainID: constants.PlatformChainID, + AVAXAssetID: avaxAssetID, + BCLookup: aliaser, + }) + + unsignedComplexTransformTxJSONBytes, err := json.MarshalIndent(unsignedComplexTransformTx, "", "\t") + require.NoError(err) + require.Equal(`{ + "networkID": 1, + "blockchainID": "11111111111111111111111111111111LpoYY", + "outputs": [ + { + "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "locktime": 87654321, + "output": { + "addresses": [], + "amount": 1, + "locktime": 12345678, + "threshold": 0 + } + } + }, + { + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "locktime": 876543210, + "output": { + "addresses": [ + "P-avax1g32kvaugnx4tk3z4vemc3xd2hdz92enh972wxr" + ], + "amount": 18446744073709551615, + "locktime": 0, + "threshold": 1 + } + } + } + ], + "inputs": [ + { + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 1, + "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "input": { + "amount": 1000000000000, + "signatureIndices": [ + 2, + 5 + ] + } + }, + { + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 2, + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "input": { + "locktime": 876543210, + "input": { + "amount": 17293822569102704639, + "signatureIndices": [ + 0 + ] + } + } + }, + { + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 3, + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "input": { + "amount": 1152921504606846976, + "signatureIndices": [] + } + } + ], + "memo": "0xf09f98850a77656c6c2074686174277301234521", + "subnetID": "SkB92YpWm4UpburLz9tEKZw2i67H3FF6YkjaU4BkFUDTG9Xm", + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "initialSupply": 1152921504606846976, + "maximumSupply": 1152921504606846976, + "minConsumptionRate": 0, + "maxConsumptionRate": 0, + "minValidatorStake": 1, + "maxValidatorStake": 1152921504606846976, + "minStakeDuration": 1, + "maxStakeDuration": 1, + "minDelegationFee": 0, + "minDelegatorStake": 18446744073709551615, + "maxValidatorWeightFactor": 255, + "uptimeRequirement": 0, + "subnetAuthorization": { + "signatureIndices": [] + } +}`, string(unsignedComplexTransformTxJSONBytes)) } func TestTransformSubnetTxSyntacticVerify(t *testing.T) { From cacbb9b46e4b82420fd310af3203c72040f53b69 Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:57:56 -0400 Subject: [PATCH 05/19] Move all blst function usage to `bls` pkg (#2222) Signed-off-by: Dan Laine Co-authored-by: Dan Laine --- snow/validators/gvalidators/validator_state_client.go | 2 +- snow/validators/gvalidators/validator_state_server.go | 3 ++- snow/validators/gvalidators/validator_state_test.go | 4 ++-- tests/fixture/testnet/config.go | 2 +- utils/crypto/bls/public.go | 8 ++++++++ utils/crypto/bls/secret.go | 8 ++++++++ vms/platformvm/state/state.go | 4 ++-- vms/platformvm/vm_regression_test.go | 2 +- vms/platformvm/warp/signature_test.go | 2 +- vms/platformvm/warp/validator.go | 2 +- vms/platformvm/warp/validator_test.go | 4 ++-- 11 files changed, 29 insertions(+), 12 deletions(-) diff --git a/snow/validators/gvalidators/validator_state_client.go b/snow/validators/gvalidators/validator_state_client.go index e30f1ed712b1..51e68592c001 100644 --- a/snow/validators/gvalidators/validator_state_client.go +++ b/snow/validators/gvalidators/validator_state_client.go @@ -80,7 +80,7 @@ func (c *Client) GetValidatorSet( // and key re-verification with PublicKeyFromBytes. We can safely // assume that the BLS Public Keys are verified before being added // to the P-Chain and served by the gRPC server. - publicKey = new(bls.PublicKey).Deserialize(validator.PublicKey) + publicKey = bls.DeserializePublicKey(validator.PublicKey) if publicKey == nil { return nil, errFailedPublicKeyDeserialize } diff --git a/snow/validators/gvalidators/validator_state_server.go b/snow/validators/gvalidators/validator_state_server.go index 1de5278347fa..5f0dbc7f46c4 100644 --- a/snow/validators/gvalidators/validator_state_server.go +++ b/snow/validators/gvalidators/validator_state_server.go @@ -10,6 +10,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/validators" + "github.com/ava-labs/avalanchego/utils/crypto/bls" pb "github.com/ava-labs/avalanchego/proto/pb/validatorstate" ) @@ -71,7 +72,7 @@ func (s *Server) GetValidatorSet(ctx context.Context, req *pb.GetValidatorSetReq if vdr.PublicKey != nil { // This is a performance optimization to avoid the cost of compression // from PublicKeyToBytes. - vdrPB.PublicKey = vdr.PublicKey.Serialize() + vdrPB.PublicKey = bls.SerializePublicKey(vdr.PublicKey) } resp.Validators[i] = vdrPB i++ diff --git a/snow/validators/gvalidators/validator_state_test.go b/snow/validators/gvalidators/validator_state_test.go index 3548862dd2e2..da8a66570f0b 100644 --- a/snow/validators/gvalidators/validator_state_test.go +++ b/snow/validators/gvalidators/validator_state_test.go @@ -188,8 +188,8 @@ func TestPublicKeyDeserialize(t *testing.T) { require.NoError(err) pk := bls.PublicFromSecretKey(sk) - pkBytes := pk.Serialize() - pkDe := new(bls.PublicKey).Deserialize(pkBytes) + pkBytes := bls.SerializePublicKey(pk) + pkDe := bls.DeserializePublicKey(pkBytes) require.NotNil(pkDe) require.Equal(pk, pkDe) } diff --git a/tests/fixture/testnet/config.go b/tests/fixture/testnet/config.go index 10d51104eef4..425aa646a690 100644 --- a/tests/fixture/testnet/config.go +++ b/tests/fixture/testnet/config.go @@ -223,7 +223,7 @@ func (nc *NodeConfig) EnsureBLSSigningKey() error { if err != nil { return fmt.Errorf("failed to generate staking signer key: %w", err) } - nc.Flags[config.StakingSignerKeyContentKey] = base64.StdEncoding.EncodeToString(newKey.Serialize()) + nc.Flags[config.StakingSignerKeyContentKey] = base64.StdEncoding.EncodeToString(bls.SerializeSecretKey(newKey)) return nil } diff --git a/utils/crypto/bls/public.go b/utils/crypto/bls/public.go index 4a944f94f21a..8d8237f83d5e 100644 --- a/utils/crypto/bls/public.go +++ b/utils/crypto/bls/public.go @@ -70,3 +70,11 @@ func Verify(pk *PublicKey, sig *Signature, msg []byte) bool { func VerifyProofOfPossession(pk *PublicKey, sig *Signature, msg []byte) bool { return sig.Verify(false, pk, false, msg, ciphersuiteProofOfPossession) } + +func DeserializePublicKey(pkBytes []byte) *PublicKey { + return new(PublicKey).Deserialize(pkBytes) +} + +func SerializePublicKey(key *PublicKey) []byte { + return key.Serialize() +} diff --git a/utils/crypto/bls/secret.go b/utils/crypto/bls/secret.go index 04716ab13a48..3f385624520c 100644 --- a/utils/crypto/bls/secret.go +++ b/utils/crypto/bls/secret.go @@ -71,3 +71,11 @@ func Sign(sk *SecretKey, msg []byte) *Signature { func SignProofOfPossession(sk *SecretKey, msg []byte) *Signature { return new(Signature).Sign(sk, msg, ciphersuiteProofOfPossession) } + +func DeserializeSecretKey(pkBytes []byte) *SecretKey { + return new(SecretKey).Deserialize(pkBytes) +} + +func SerializeSecretKey(key *SecretKey) []byte { + return key.Serialize() +} diff --git a/vms/platformvm/state/state.go b/vms/platformvm/state/state.go index 4a314aba4840..23a9412f89d8 100644 --- a/vms/platformvm/state/state.go +++ b/vms/platformvm/state/state.go @@ -1322,7 +1322,7 @@ func (s *state) ApplyValidatorPublicKeyDiffs( continue } - vdr.PublicKey = new(bls.PublicKey).Deserialize(pkBytes) + vdr.PublicKey = bls.DeserializePublicKey(pkBytes) } // Note: this does not fallback to the linkeddb index because the linkeddb @@ -2060,7 +2060,7 @@ func (s *state) writeCurrentStakers(updateValidators bool, height uint64) error // diffs. err := s.flatValidatorPublicKeyDiffsDB.Put( marshalDiffKey(constants.PrimaryNetworkID, height, nodeID), - staker.PublicKey.Serialize(), + bls.SerializePublicKey(staker.PublicKey), ) if err != nil { return err diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 9427f95ffb41..41e7eafbdfe8 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -2255,7 +2255,7 @@ func checkValidatorBlsKeyIsSet( return errors.New("unexpected BLS key") case expectedBlsKey != nil && val.PublicKey == nil: return errors.New("missing BLS key") - case !bytes.Equal(expectedBlsKey.Serialize(), val.PublicKey.Serialize()): + case !bytes.Equal(bls.SerializePublicKey(expectedBlsKey), bls.SerializePublicKey(val.PublicKey)): return errors.New("incorrect BLS key") default: return nil diff --git a/vms/platformvm/warp/signature_test.go b/vms/platformvm/warp/signature_test.go index cd5e2b636c95..b3eaa88bbfe8 100644 --- a/vms/platformvm/warp/signature_test.go +++ b/vms/platformvm/warp/signature_test.go @@ -56,7 +56,7 @@ func newTestValidator() *testValidator { sk: sk, vdr: &Validator{ PublicKey: pk, - PublicKeyBytes: pk.Serialize(), + PublicKeyBytes: bls.SerializePublicKey(pk), Weight: 3, NodeIDs: []ids.NodeID{nodeID}, }, diff --git a/vms/platformvm/warp/validator.go b/vms/platformvm/warp/validator.go index d1cff89693aa..42ff34e7cb5e 100644 --- a/vms/platformvm/warp/validator.go +++ b/vms/platformvm/warp/validator.go @@ -72,7 +72,7 @@ func GetCanonicalValidatorSet( continue } - pkBytes := vdr.PublicKey.Serialize() + pkBytes := bls.SerializePublicKey(vdr.PublicKey) uniqueVdr, ok := vdrs[string(pkBytes)] if !ok { uniqueVdr = &Validator{ diff --git a/vms/platformvm/warp/validator_test.go b/vms/platformvm/warp/validator_test.go index 5c17ed6faf2e..b306c82b79f0 100644 --- a/vms/platformvm/warp/validator_test.go +++ b/vms/platformvm/warp/validator_test.go @@ -166,7 +166,7 @@ func TestFilterValidators(t *testing.T) { pk0 := bls.PublicFromSecretKey(sk0) vdr0 := &Validator{ PublicKey: pk0, - PublicKeyBytes: pk0.Serialize(), + PublicKeyBytes: bls.SerializePublicKey(pk0), Weight: 1, } @@ -175,7 +175,7 @@ func TestFilterValidators(t *testing.T) { pk1 := bls.PublicFromSecretKey(sk1) vdr1 := &Validator{ PublicKey: pk1, - PublicKeyBytes: pk1.Serialize(), + PublicKeyBytes: bls.SerializePublicKey(pk1), Weight: 2, } From a4cee60312ae606ac8b6f1b2779559423cb694f2 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Fri, 27 Oct 2023 11:37:05 -0400 Subject: [PATCH 06/19] `merkledb` -- don't pass `BranchFactor` to `encodeDBNode` (#2217) Signed-off-by: Dan Laine --- x/merkledb/codec.go | 22 +++++++++++++--------- x/merkledb/codec_test.go | 8 ++++---- x/merkledb/node.go | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/x/merkledb/codec.go b/x/merkledb/codec.go index 6420baac56e9..e7ef1eddb7f5 100644 --- a/x/merkledb/codec.go +++ b/x/merkledb/codec.go @@ -11,6 +11,9 @@ import ( "math" "sync" + "golang.org/x/exp/maps" + "golang.org/x/exp/slices" + "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/maybe" ) @@ -59,7 +62,7 @@ type encoderDecoder interface { type encoder interface { // Assumes [n] is non-nil. - encodeDBNode(n *dbNode, factor BranchFactor) []byte + encodeDBNode(n *dbNode) []byte // Assumes [hv] is non-nil. encodeHashValues(hv *hashValues) []byte } @@ -87,7 +90,7 @@ type codecImpl struct { varIntPool sync.Pool } -func (c *codecImpl) encodeDBNode(n *dbNode, branchFactor BranchFactor) []byte { +func (c *codecImpl) encodeDBNode(n *dbNode) []byte { var ( numChildren = len(n.children) // Estimate size of [n] to prevent memory allocations @@ -99,13 +102,14 @@ func (c *codecImpl) encodeDBNode(n *dbNode, branchFactor BranchFactor) []byte { 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(buf, uint64(index)) - c.encodeKey(buf, entry.compressedKey) - _, _ = buf.Write(entry.id[:]) - c.encodeBool(buf, entry.hasValue) - } + keys := maps.Keys(n.children) + slices.Sort(keys) + for _, index := range keys { + entry := n.children[index] + c.encodeUint(buf, uint64(index)) + c.encodeKey(buf, entry.compressedKey) + _, _ = buf.Write(entry.id[:]) + c.encodeBool(buf, entry.hasValue) } return buf.Bytes() } diff --git a/x/merkledb/codec_test.go b/x/merkledb/codec_test.go index a948ea520b8c..cb83e1ce582c 100644 --- a/x/merkledb/codec_test.go +++ b/x/merkledb/codec_test.go @@ -117,7 +117,7 @@ func FuzzCodecDBNodeCanonical(f *testing.F) { } // Encoding [node] should be the same as [b]. - buf := codec.encodeDBNode(node, branchFactor) + buf := codec.encodeDBNode(node) require.Equal(b, buf) } }, @@ -168,13 +168,13 @@ func FuzzCodecDBNodeDeterministic(f *testing.F) { children: children, } - nodeBytes := codec.encodeDBNode(&node, branchFactor) + nodeBytes := codec.encodeDBNode(&node) var gotNode dbNode require.NoError(codec.decodeDBNode(nodeBytes, &gotNode, branchFactor)) require.Equal(node, gotNode) - nodeBytes2 := codec.encodeDBNode(&gotNode, branchFactor) + nodeBytes2 := codec.encodeDBNode(&gotNode) require.Equal(nodeBytes, nodeBytes2) } }, @@ -196,7 +196,7 @@ func TestCodecDecodeDBNode(t *testing.T) { children: map[byte]child{}, } - nodeBytes := codec.encodeDBNode(&proof, BranchFactor16) + nodeBytes := codec.encodeDBNode(&proof) // Remove num children (0) from end nodeBytes = nodeBytes[:len(nodeBytes)-minVarIntLen] proofBytesBuf := bytes.NewBuffer(nodeBytes) diff --git a/x/merkledb/node.go b/x/merkledb/node.go index f78e4636c815..259e048c1793 100644 --- a/x/merkledb/node.go +++ b/x/merkledb/node.go @@ -81,7 +81,7 @@ func (n *node) hasValue() bool { // Returns the byte representation of this node. func (n *node) bytes() []byte { if n.nodeBytes == nil { - n.nodeBytes = codec.encodeDBNode(&n.dbNode, n.key.branchFactor) + n.nodeBytes = codec.encodeDBNode(&n.dbNode) } return n.nodeBytes From b83af9bcaa98c79414db7ec040bcf5043511edd7 Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 27 Oct 2023 17:42:03 -0400 Subject: [PATCH 07/19] Add `utils.Err` helper (#2212) Signed-off-by: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> --- api/server/metrics.go | 7 ++--- database/leveldb/metrics.go | 7 ++--- genesis/config.go | 31 +++++++++---------- indexer/index.go | 6 ++-- ipcs/eventsocket.go | 12 +++---- network/metrics.go | 7 ++--- network/network.go | 2 +- network/p2p/gossip/gossip.go | 8 ++--- network/p2p/gossip/handler.go | 8 ++--- network/peer/gossip_tracker_metrics.go | 8 ++--- .../throttling/inbound_resource_throttler.go | 7 ++--- network/throttling/outbound_msg_throttler.go | 6 ++-- node/node.go | 8 ++--- snow/consensus/metrics/polls.go | 7 ++--- snow/engine/avalanche/bootstrap/metrics.go | 6 ++-- snow/engine/common/queue/jobs.go | 6 ++-- snow/engine/common/queue/state.go | 6 ++-- snow/engine/common/tracker/peers.go | 7 ++--- snow/engine/snowman/bootstrap/metrics.go | 7 ++--- .../networking/router/chain_router_metrics.go | 7 ++--- snow/networking/tracker/resource_tracker.go | 7 ++--- utils/error.go | 13 ++++++++ utils/metric/api_interceptor.go | 7 ++--- utils/resource/metrics.go | 7 ++--- utils/timer/adaptive_timeout_manager.go | 7 ++--- vms/avm/block/parser.go | 12 +++---- vms/avm/states/state.go | 26 ++++++---------- vms/avm/txs/parser.go | 9 +++--- vms/avm/vm.go | 6 ++-- vms/components/keystore/codec.go | 9 +++--- vms/components/message/codec.go | 9 +++--- vms/example/xsvm/execute/tx.go | 5 ++- vms/example/xsvm/tx/codec.go | 9 +++--- vms/nftfx/fx.go | 6 ++-- vms/platformvm/block/builder/helpers_test.go | 5 +-- vms/platformvm/block/codec.go | 9 ++---- vms/platformvm/block/executor/helpers_test.go | 11 ++++--- vms/platformvm/metrics/metrics.go | 2 +- vms/platformvm/service.go | 29 +++++------------ vms/platformvm/state/state.go | 27 +++++----------- vms/platformvm/txs/executor/helpers_test.go | 5 +-- vms/platformvm/vm.go | 5 +-- vms/platformvm/warp/codec.go | 9 +++--- vms/platformvm/warp/payload/codec.go | 9 +++--- vms/propertyfx/fx.go | 6 ++-- vms/proposervm/block/codec.go | 9 +++--- vms/secp256k1fx/fx.go | 6 ++-- x/merkledb/metrics.go | 7 ++--- x/sync/metrics.go | 7 ++--- x/sync/peer_tracker.go | 7 ++--- 50 files changed, 181 insertions(+), 267 deletions(-) create mode 100644 utils/error.go diff --git a/api/server/metrics.go b/api/server/metrics.go index 6556c3a00763..9859494f3ae4 100644 --- a/api/server/metrics.go +++ b/api/server/metrics.go @@ -9,7 +9,7 @@ import ( "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) type metrics struct { @@ -46,13 +46,12 @@ func newMetrics(namespace string, registerer prometheus.Registerer) (*metrics, e ), } - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( registerer.Register(m.numProcessing), registerer.Register(m.numCalls), registerer.Register(m.totalDuration), ) - return m, errs.Err + return m, err } func (m *metrics) wrapHandler(chainName string, handler http.Handler) http.Handler { diff --git a/database/leveldb/metrics.go b/database/leveldb/metrics.go index 8b2971a374c9..11bca8ddb07e 100644 --- a/database/leveldb/metrics.go +++ b/database/leveldb/metrics.go @@ -10,7 +10,7 @@ import ( "github.com/syndtr/goleveldb/leveldb" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) var levelLabels = []string{"level"} @@ -180,8 +180,7 @@ func newMetrics(namespace string, reg prometheus.Registerer) (metrics, error) { currentStats: &leveldb.DBStats{}, } - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( reg.Register(m.writesDelayedCount), reg.Register(m.writesDelayedDuration), reg.Register(m.writeIsDelayed), @@ -206,7 +205,7 @@ func newMetrics(namespace string, reg prometheus.Registerer) (metrics, error) { reg.Register(m.nonLevel0Compactions), reg.Register(m.seekCompactions), ) - return m, errs.Err + return m, err } func (db *Database) updateMetrics() error { diff --git a/genesis/config.go b/genesis/config.go index c14b3b77f771..2a7063f87940 100644 --- a/genesis/config.go +++ b/genesis/config.go @@ -17,7 +17,6 @@ import ( "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/formatting/address" "github.com/ava-labs/avalanchego/utils/math" - "github.com/ava-labs/avalanchego/utils/wrappers" ) var ( @@ -172,30 +171,28 @@ func init() { unparsedFujiConfig := UnparsedConfig{} unparsedLocalConfig := UnparsedConfig{} - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( json.Unmarshal(mainnetGenesisConfigJSON, &unparsedMainnetConfig), json.Unmarshal(fujiGenesisConfigJSON, &unparsedFujiConfig), json.Unmarshal(localGenesisConfigJSON, &unparsedLocalConfig), ) - if errs.Errored() { - panic(errs.Err) + if err != nil { + panic(err) } - mainnetConfig, err := unparsedMainnetConfig.Parse() - errs.Add(err) - MainnetConfig = mainnetConfig - - fujiConfig, err := unparsedFujiConfig.Parse() - errs.Add(err) - FujiConfig = fujiConfig + MainnetConfig, err = unparsedMainnetConfig.Parse() + if err != nil { + panic(err) + } - localConfig, err := unparsedLocalConfig.Parse() - errs.Add(err) - LocalConfig = localConfig + FujiConfig, err = unparsedFujiConfig.Parse() + if err != nil { + panic(err) + } - if errs.Errored() { - panic(errs.Err) + LocalConfig, err = unparsedLocalConfig.Parse() + if err != nil { + panic(err) } } diff --git a/indexer/index.go b/indexer/index.go index fae7ebcb12e1..5361754bf73d 100644 --- a/indexer/index.go +++ b/indexer/index.go @@ -17,10 +17,10 @@ import ( "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math" "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/utils/wrappers" ) // Maximum number of containers IDs that can be fetched at a time in a call to @@ -114,14 +114,12 @@ func newIndex( // Close this index func (i *index) Close() error { - errs := wrappers.Errs{} - errs.Add( + return utils.Err( i.indexToContainer.Close(), i.containerToIndex.Close(), i.vDB.Close(), i.baseDB.Close(), ) - return errs.Err } // Index that the given transaction is accepted diff --git a/ipcs/eventsocket.go b/ipcs/eventsocket.go index 37b370c36918..109b42bb34af 100644 --- a/ipcs/eventsocket.go +++ b/ipcs/eventsocket.go @@ -11,6 +11,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/ipcs/socket" "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/wrappers" ) @@ -133,12 +134,10 @@ func newEventIPCSocket( url: url, socket: socket.NewSocket(url, ctx.log), unregisterFn: func() error { - errs := wrappers.Errs{} - errs.Add( + return utils.Err( snowmanAcceptorGroup.DeregisterAcceptor(chainID, ipcName), avalancheAcceptorGroup.DeregisterAcceptor(chainID, ipcName), ) - return errs.Err }, } @@ -175,9 +174,10 @@ func (eis *eventSocket) Accept(_ *snow.ConsensusContext, _ ids.ID, container []b // stop unregisters the event handler and closes the eventSocket func (eis *eventSocket) stop() error { eis.log.Info("closing Chain IPC") - errs := wrappers.Errs{} - errs.Add(eis.unregisterFn(), eis.socket.Close()) - return errs.Err + return utils.Err( + eis.unregisterFn(), + eis.socket.Close(), + ) } // URL returns the URL of the socket diff --git a/network/metrics.go b/network/metrics.go index b35c60f0a602..3e566a31c99f 100644 --- a/network/metrics.go +++ b/network/metrics.go @@ -11,9 +11,9 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/network/peer" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/set" - "github.com/ava-labs/avalanchego/utils/wrappers" ) type metrics struct { @@ -147,8 +147,7 @@ func newMetrics(namespace string, registerer prometheus.Registerer, initialSubne peerConnectedStartTimes: make(map[ids.NodeID]float64), } - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( registerer.Register(m.numTracked), registerer.Register(m.numPeers), registerer.Register(m.numSubnetPeers), @@ -182,7 +181,7 @@ func newMetrics(namespace string, registerer prometheus.Registerer, initialSubne m.nodeSubnetUptimeRewardingStake.WithLabelValues(subnetIDStr).Set(0) } - return m, errs.Err + return m, err } func (m *metrics) markConnected(peer peer.Peer) { diff --git a/network/network.go b/network/network.go index a0fd6cced124..3f89e0ea00ef 100644 --- a/network/network.go +++ b/network/network.go @@ -732,7 +732,6 @@ func (n *network) Peers(peerID ids.NodeID) ([]ips.ClaimedIPPort, error) { func (n *network) Dispatch() error { go n.runTimers() // Periodically perform operations go n.inboundConnUpgradeThrottler.Dispatch() - errs := wrappers.Errs{} for { // Continuously accept new connections if n.onCloseCtx.Err() != nil { break @@ -798,6 +797,7 @@ func (n *network) Dispatch() error { connected := n.connectedPeers.Sample(n.connectedPeers.Len(), peer.NoPrecondition) n.peersLock.RUnlock() + errs := wrappers.Errs{} for _, peer := range append(connecting, connected...) { errs.Add(peer.AwaitClosed(context.TODO())) } diff --git a/network/p2p/gossip/gossip.go b/network/p2p/gossip/gossip.go index 2e987e529dbe..94d49260da40 100644 --- a/network/p2p/gossip/gossip.go +++ b/network/p2p/gossip/gossip.go @@ -16,8 +16,8 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/network/p2p" "github.com/ava-labs/avalanchego/proto/pb/sdk" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/logging" - "github.com/ava-labs/avalanchego/utils/wrappers" ) var ( @@ -83,13 +83,11 @@ func NewPullGossiper[T any, U GossipableAny[T]]( }), } - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( metrics.Register(p.receivedN), metrics.Register(p.receivedBytes), ) - - return p, errs.Err + return p, err } type PullGossiper[T any, U GossipableAny[T]] struct { diff --git a/network/p2p/gossip/handler.go b/network/p2p/gossip/handler.go index 987fa2e2ed41..ecaf58434bc2 100644 --- a/network/p2p/gossip/handler.go +++ b/network/p2p/gossip/handler.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/network/p2p" "github.com/ava-labs/avalanchego/proto/pb/sdk" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) var ( @@ -52,13 +52,11 @@ func NewHandler[T Gossipable]( }), } - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( metrics.Register(h.sentN), metrics.Register(h.sentBytes), ) - - return h, errs.Err + return h, err } type Handler[T Gossipable] struct { diff --git a/network/peer/gossip_tracker_metrics.go b/network/peer/gossip_tracker_metrics.go index be167ebfec3d..e80f31765b9c 100644 --- a/network/peer/gossip_tracker_metrics.go +++ b/network/peer/gossip_tracker_metrics.go @@ -6,7 +6,7 @@ package peer import ( "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) type gossipTrackerMetrics struct { @@ -32,11 +32,9 @@ func newGossipTrackerMetrics(registerer prometheus.Registerer, namespace string) ), } - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( registerer.Register(m.trackedPeersSize), registerer.Register(m.validatorsSize), ) - - return m, errs.Err + return m, err } diff --git a/network/throttling/inbound_resource_throttler.go b/network/throttling/inbound_resource_throttler.go index a12e8562dde4..42873fe42d6a 100644 --- a/network/throttling/inbound_resource_throttler.go +++ b/network/throttling/inbound_resource_throttler.go @@ -13,8 +13,8 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/networking/tracker" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/utils/wrappers" ) const epsilon = time.Millisecond @@ -80,13 +80,12 @@ func newSystemThrottlerMetrics(namespace string, reg prometheus.Registerer) (*sy Help: "Number of nodes we're waiting to read a message from because their usage is too high", }), } - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( reg.Register(m.totalWaits), reg.Register(m.totalNoWaits), reg.Register(m.awaitingAcquire), ) - return m, errs.Err + return m, err } func NewSystemThrottler( diff --git a/network/throttling/outbound_msg_throttler.go b/network/throttling/outbound_msg_throttler.go index 62e8821660bf..6f5ad24561f3 100644 --- a/network/throttling/outbound_msg_throttler.go +++ b/network/throttling/outbound_msg_throttler.go @@ -11,10 +11,10 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/message" "github.com/ava-labs/avalanchego/snow/validators" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math" - "github.com/ava-labs/avalanchego/utils/wrappers" ) var ( @@ -204,15 +204,13 @@ func (m *outboundMsgThrottlerMetrics) initialize(namespace string, registerer pr Name: "throttler_outbound_awaiting_release", Help: "Number of messages waiting to be sent", }) - errs := wrappers.Errs{} - errs.Add( + return utils.Err( registerer.Register(m.acquireSuccesses), registerer.Register(m.acquireFailures), registerer.Register(m.remainingAtLargeBytes), registerer.Register(m.remainingVdrBytes), registerer.Register(m.awaitingRelease), ) - return errs.Err } func NewNoOutboundThrottler() OutboundMsgThrottler { diff --git a/node/node.go b/node/node.go index 4200a33699ab..abea27da15a2 100644 --- a/node/node.go +++ b/node/node.go @@ -71,7 +71,6 @@ import ( "github.com/ava-labs/avalanchego/utils/resource" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/timer" - "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms" "github.com/ava-labs/avalanchego/vms/avm" @@ -894,8 +893,7 @@ func (n *Node) initVMs() error { }) // Register the VMs that Avalanche supports - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( vmRegisterer.Register(context.TODO(), constants.PlatformVMID, &platformvm.Factory{ Config: platformconfig.Config{ Chains: n.chainManager, @@ -940,8 +938,8 @@ func (n *Node) initVMs() error { n.VMManager.RegisterFactory(context.TODO(), nftfx.ID, &nftfx.Factory{}), n.VMManager.RegisterFactory(context.TODO(), propertyfx.ID, &propertyfx.Factory{}), ) - if errs.Errored() { - return errs.Err + if err != nil { + return err } // initialize vm runtime manager diff --git a/snow/consensus/metrics/polls.go b/snow/consensus/metrics/polls.go index 188bb217ebe0..589833954f6b 100644 --- a/snow/consensus/metrics/polls.go +++ b/snow/consensus/metrics/polls.go @@ -6,7 +6,7 @@ package metrics import ( "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) var _ Polls = (*polls)(nil) @@ -38,12 +38,11 @@ func NewPolls(namespace string, reg prometheus.Registerer) (Polls, error) { Help: "Number of failed polls", }), } - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( reg.Register(p.numFailedPolls), reg.Register(p.numSuccessfulPolls), ) - return p, errs.Err + return p, err } func (p *polls) Failed() { diff --git a/snow/engine/avalanche/bootstrap/metrics.go b/snow/engine/avalanche/bootstrap/metrics.go index 2033a7764afb..b9d5824ec95a 100644 --- a/snow/engine/avalanche/bootstrap/metrics.go +++ b/snow/engine/avalanche/bootstrap/metrics.go @@ -6,7 +6,7 @@ package bootstrap import ( "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) type metrics struct { @@ -50,8 +50,7 @@ func (m *metrics) Initialize( Help: "Number of transactions accepted during bootstrapping", }) - errs := wrappers.Errs{} - errs.Add( + return utils.Err( registerer.Register(m.numFetchedVts), registerer.Register(m.numDroppedVts), registerer.Register(m.numAcceptedVts), @@ -59,5 +58,4 @@ func (m *metrics) Initialize( registerer.Register(m.numDroppedTxs), registerer.Register(m.numAcceptedTxs), ) - return errs.Err } diff --git a/snow/engine/common/queue/jobs.go b/snow/engine/common/queue/jobs.go index 728edcc98a81..5592ad822439 100644 --- a/snow/engine/common/queue/jobs.go +++ b/snow/engine/common/queue/jobs.go @@ -17,9 +17,9 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/engine/common" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/timer" - "github.com/ava-labs/avalanchego/utils/wrappers" ) const progressUpdateFrequency = 30 * time.Second @@ -425,10 +425,8 @@ func (jm *JobsWithMissing) cleanRunnableStack(ctx context.Context) error { } } - errs := wrappers.Errs{} - errs.Add( + return utils.Err( runnableJobsIter.Error(), jm.Commit(), ) - return errs.Err } diff --git a/snow/engine/common/queue/state.go b/snow/engine/common/queue/state.go index 5e5ccb232271..cae43f8c2101 100644 --- a/snow/engine/common/queue/state.go +++ b/snow/engine/common/queue/state.go @@ -15,8 +15,8 @@ import ( "github.com/ava-labs/avalanchego/database/linkeddb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/set" - "github.com/ava-labs/avalanchego/utils/wrappers" ) const ( @@ -152,14 +152,12 @@ func (s *state) Clear() error { return err } - errs := wrappers.Errs{} - errs.Add( + return utils.Err( runJobsIter.Error(), jobsIter.Error(), depsIter.Error(), missJobsIter.Error(), ) - return errs.Err } // AddRunnableJob adds [jobID] to the runnable queue diff --git a/snow/engine/common/tracker/peers.go b/snow/engine/common/tracker/peers.go index cde9eb8f6134..ad9592209a5a 100644 --- a/snow/engine/common/tracker/peers.go +++ b/snow/engine/common/tracker/peers.go @@ -11,9 +11,9 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/validators" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/set" - "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/version" ) @@ -139,8 +139,7 @@ func NewMeteredPeers(namespace string, reg prometheus.Registerer) (Peers, error) Name: "num_validators", Help: "Total number of validators", }) - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( reg.Register(percentConnected), reg.Register(totalWeight), reg.Register(numValidators), @@ -154,7 +153,7 @@ func NewMeteredPeers(namespace string, reg prometheus.Registerer) (Peers, error) totalWeight: totalWeight, numValidators: numValidators, }, - }, errs.Err + }, err } func (p *meteredPeers) OnValidatorAdded(nodeID ids.NodeID, pk *bls.PublicKey, txID ids.ID, weight uint64) { diff --git a/snow/engine/snowman/bootstrap/metrics.go b/snow/engine/snowman/bootstrap/metrics.go index 91260df3ca64..9359ecfadb19 100644 --- a/snow/engine/snowman/bootstrap/metrics.go +++ b/snow/engine/snowman/bootstrap/metrics.go @@ -6,7 +6,7 @@ package bootstrap import ( "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) type metrics struct { @@ -38,12 +38,11 @@ func newMetrics(namespace string, registerer prometheus.Registerer) (*metrics, e }), } - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( registerer.Register(m.numFetched), registerer.Register(m.numDropped), registerer.Register(m.numAccepted), registerer.Register(m.fetchETA), ) - return m, errs.Err + return m, err } diff --git a/snow/networking/router/chain_router_metrics.go b/snow/networking/router/chain_router_metrics.go index cfcc96134c29..58440377ba82 100644 --- a/snow/networking/router/chain_router_metrics.go +++ b/snow/networking/router/chain_router_metrics.go @@ -6,7 +6,7 @@ package router import ( "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) // routerMetrics about router messages @@ -40,11 +40,10 @@ func newRouterMetrics(namespace string, registerer prometheus.Registerer) (*rout }, ) - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( registerer.Register(rMetrics.outstandingRequests), registerer.Register(rMetrics.longestRunningRequest), registerer.Register(rMetrics.droppedRequests), ) - return rMetrics, errs.Err + return rMetrics, err } diff --git a/snow/networking/tracker/resource_tracker.go b/snow/networking/tracker/resource_tracker.go index 721d531eea5b..7910c2fff475 100644 --- a/snow/networking/tracker/resource_tracker.go +++ b/snow/networking/tracker/resource_tracker.go @@ -11,10 +11,10 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/linkedhashmap" "github.com/ava-labs/avalanchego/utils/math/meter" "github.com/ava-labs/avalanchego/utils/resource" - "github.com/ava-labs/avalanchego/utils/wrappers" ) const epsilon = 1e-9 @@ -321,13 +321,12 @@ func newCPUTrackerMetrics(namespace string, reg prometheus.Registerer) (*tracker Help: "Available space remaining (bytes) on the database volume", }), } - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( reg.Register(m.processingTimeMetric), reg.Register(m.cpuMetric), reg.Register(m.diskReadsMetric), reg.Register(m.diskWritesMetric), reg.Register(m.diskSpaceAvailable), ) - return m, errs.Err + return m, err } diff --git a/utils/error.go b/utils/error.go new file mode 100644 index 000000000000..b58c60cd001a --- /dev/null +++ b/utils/error.go @@ -0,0 +1,13 @@ +// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package utils + +func Err(errors ...error) error { + for _, err := range errors { + if err != nil { + return err + } + } + return nil +} diff --git a/utils/metric/api_interceptor.go b/utils/metric/api_interceptor.go index 57810fce63b5..ab8e4fd8d70c 100644 --- a/utils/metric/api_interceptor.go +++ b/utils/metric/api_interceptor.go @@ -12,7 +12,7 @@ import ( "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) type APIInterceptor interface { @@ -55,8 +55,7 @@ func NewAPIInterceptor(namespace string, registerer prometheus.Registerer) (APII []string{"method"}, ) - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( registerer.Register(requestDurationCount), registerer.Register(requestDurationSum), registerer.Register(requestErrors), @@ -65,7 +64,7 @@ func NewAPIInterceptor(namespace string, registerer prometheus.Registerer) (APII requestDurationCount: requestDurationCount, requestDurationSum: requestDurationSum, requestErrors: requestErrors, - }, errs.Err + }, err } func (*apiInterceptor) InterceptRequest(i *rpc.RequestInfo) *http.Request { diff --git a/utils/resource/metrics.go b/utils/resource/metrics.go index 96c3c21ad204..e20458c42fb1 100644 --- a/utils/resource/metrics.go +++ b/utils/resource/metrics.go @@ -6,7 +6,7 @@ package resource import ( "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) type metrics struct { @@ -60,13 +60,12 @@ func newMetrics(namespace string, registerer prometheus.Registerer) (*metrics, e []string{"processID"}, ), } - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( registerer.Register(m.numCPUCycles), registerer.Register(m.numDiskReads), registerer.Register(m.numDiskReadBytes), registerer.Register(m.numDiskWrites), registerer.Register(m.numDiskWritesBytes), ) - return m, errs.Err + return m, err } diff --git a/utils/timer/adaptive_timeout_manager.go b/utils/timer/adaptive_timeout_manager.go index 95b284a48c5f..a6d00654c064 100644 --- a/utils/timer/adaptive_timeout_manager.go +++ b/utils/timer/adaptive_timeout_manager.go @@ -12,10 +12,10 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/heap" "github.com/ava-labs/avalanchego/utils/math" "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/utils/wrappers" ) var ( @@ -138,14 +138,13 @@ func NewAdaptiveTimeoutManager( tm.timer = NewTimer(tm.timeout) tm.averager = math.NewAverager(float64(config.InitialTimeout), config.TimeoutHalflife, tm.clock.Time()) - errs := &wrappers.Errs{} - errs.Add( + err := utils.Err( metricsRegister.Register(tm.networkTimeoutMetric), metricsRegister.Register(tm.avgLatency), metricsRegister.Register(tm.numTimeouts), metricsRegister.Register(tm.numPendingTimeouts), ) - return tm, errs.Err + return tm, err } func (tm *adaptiveTimeoutManager) TimeoutDuration() time.Duration { diff --git a/vms/avm/block/parser.go b/vms/avm/block/parser.go index 4cdab44f25e2..230568149b6d 100644 --- a/vms/avm/block/parser.go +++ b/vms/avm/block/parser.go @@ -8,9 +8,9 @@ import ( "reflect" "github.com/ava-labs/avalanchego/codec" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/vms/avm/fxs" "github.com/ava-labs/avalanchego/vms/avm/txs" ) @@ -42,14 +42,13 @@ func NewParser(fxs []fxs.Fx) (Parser, error) { c := p.CodecRegistry() gc := p.GenesisCodecRegistry() - errs := wrappers.Errs{} - errs.Add( + err = utils.Err( c.RegisterType(&StandardBlock{}), gc.RegisterType(&StandardBlock{}), ) return &parser{ Parser: p, - }, errs.Err + }, err } func NewCustomParser( @@ -65,14 +64,13 @@ func NewCustomParser( c := p.CodecRegistry() gc := p.GenesisCodecRegistry() - errs := wrappers.Errs{} - errs.Add( + err = utils.Err( c.RegisterType(&StandardBlock{}), gc.RegisterType(&StandardBlock{}), ) return &parser{ Parser: p, - }, errs.Err + }, err } func (p *parser) ParseBlock(bytes []byte) (Block, error) { diff --git a/vms/avm/states/state.go b/vms/avm/states/state.go index bf1ac3cde471..1167cdb37dce 100644 --- a/vms/avm/states/state.go +++ b/vms/avm/states/state.go @@ -22,9 +22,9 @@ import ( "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/choices" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer" - "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/vms/avm/block" "github.com/ava-labs/avalanchego/vms/avm/txs" "github.com/ava-labs/avalanchego/vms/components/avax" @@ -522,8 +522,7 @@ func (s *state) CommitBatch() (database.Batch, error) { } func (s *state) Close() error { - errs := wrappers.Errs{} - errs.Add( + return utils.Err( s.utxoDB.Close(), s.statusDB.Close(), s.txDB.Close(), @@ -532,19 +531,16 @@ func (s *state) Close() error { s.singletonDB.Close(), s.db.Close(), ) - return errs.Err } func (s *state) write() error { - errs := wrappers.Errs{} - errs.Add( + return utils.Err( s.writeUTXOs(), s.writeTxs(), s.writeBlockIDs(), s.writeBlocks(), s.writeMetadata(), ) - return errs.Err } func (s *state) writeUTXOs() error { @@ -691,15 +687,14 @@ func (s *state) Prune(lock sync.Locker, log logging.Logger) error { // attempt to commit to disk while a block is concurrently being // accepted. lock.Lock() - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( s.Commit(), statusIter.Error(), txIter.Error(), ) lock.Unlock() - if errs.Errored() { - return errs.Err + if err != nil { + return err } // We release the iterators here to allow the underlying database to @@ -751,8 +746,7 @@ func (s *state) Prune(lock sync.Locker, log logging.Logger) error { lock.Lock() defer lock.Unlock() - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( s.Commit(), statusIter.Error(), txIter.Error(), @@ -769,7 +763,7 @@ func (s *state) Prune(lock sync.Locker, log logging.Logger) error { zap.Duration("duration", time.Since(startTime)), ) - return errs.Err + return err } // Assumes [lock] is unlocked. @@ -891,12 +885,10 @@ func (s *state) initTxChecksum() error { return errStatusWithoutTx } - errs := wrappers.Errs{} - errs.Add( + return utils.Err( txIt.Error(), statusIt.Error(), ) - return errs.Err } func (s *state) updateTxChecksum(modifiedID ids.ID) { diff --git a/vms/avm/txs/parser.go b/vms/avm/txs/parser.go index f5f16d59432e..def42dfed501 100644 --- a/vms/avm/txs/parser.go +++ b/vms/avm/txs/parser.go @@ -11,9 +11,9 @@ import ( "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" "github.com/ava-labs/avalanchego/codec/reflectcodec" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/vms/avm/fxs" ) @@ -64,8 +64,7 @@ func NewCustomParser( gcm := codec.NewManager(math.MaxInt32) cm := codec.NewDefaultManager() - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( c.RegisterType(&BaseTx{}), c.RegisterType(&CreateAssetTx{}), c.RegisterType(&OperationTx{}), @@ -80,8 +79,8 @@ func NewCustomParser( gc.RegisterType(&ExportTx{}), gcm.RegisterCodec(CodecVersion, gc), ) - if errs.Errored() { - return nil, errs.Err + if err != nil { + return nil, err } vm := &fxVM{ diff --git a/vms/avm/vm.go b/vms/avm/vm.go index 50bc646580a0..e115b2d6d640 100644 --- a/vms/avm/vm.go +++ b/vms/avm/vm.go @@ -29,11 +29,11 @@ import ( "github.com/ava-labs/avalanchego/snow/consensus/snowstorm" "github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex" "github.com/ava-labs/avalanchego/snow/engine/common" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/json" "github.com/ava-labs/avalanchego/utils/linkedhashmap" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/avm/block" "github.com/ava-labs/avalanchego/vms/avm/config" @@ -308,12 +308,10 @@ func (vm *VM) Shutdown(context.Context) error { return nil } - errs := wrappers.Errs{} - errs.Add( + return utils.Err( vm.state.Close(), vm.baseDB.Close(), ) - return errs.Err } func (*VM) Version(context.Context) (string, error) { diff --git a/vms/components/keystore/codec.go b/vms/components/keystore/codec.go index 6e547c9e4f86..5acb1725aa6e 100644 --- a/vms/components/keystore/codec.go +++ b/vms/components/keystore/codec.go @@ -8,7 +8,7 @@ import ( "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) const ( @@ -28,12 +28,11 @@ func init() { lc := linearcodec.NewCustomMaxLength(math.MaxUint32) LegacyCodec = codec.NewManager(math.MaxInt32) - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( Codec.RegisterCodec(CodecVersion, c), LegacyCodec.RegisterCodec(CodecVersion, lc), ) - if errs.Errored() { - panic(errs.Err) + if err != nil { + panic(err) } } diff --git a/vms/components/message/codec.go b/vms/components/message/codec.go index d41de9b2dd71..3a5eee5416ca 100644 --- a/vms/components/message/codec.go +++ b/vms/components/message/codec.go @@ -6,8 +6,8 @@ package message import ( "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/utils/wrappers" ) const ( @@ -23,12 +23,11 @@ func init() { c = codec.NewManager(maxMessageSize) lc := linearcodec.NewCustomMaxLength(maxSliceLen) - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( lc.RegisterType(&Tx{}), c.RegisterCodec(codecVersion, lc), ) - if errs.Errored() { - panic(errs.Err) + if err != nil { + panic(err) } } diff --git a/vms/example/xsvm/execute/tx.go b/vms/example/xsvm/execute/tx.go index 6c8276af8e79..01bfc1fb7d6d 100644 --- a/vms/example/xsvm/execute/tx.go +++ b/vms/example/xsvm/execute/tx.go @@ -11,6 +11,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/hashing" "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/vms/example/xsvm/state" @@ -55,14 +56,12 @@ func (t *Tx) Transfer(tf *tx.Transfer) error { return errWrongChainID } - var errs wrappers.Errs - errs.Add( + return utils.Err( state.IncrementNonce(t.Database, t.Sender, tf.Nonce), state.DecreaseBalance(t.Database, t.Sender, tf.ChainID, t.TransferFee), state.DecreaseBalance(t.Database, t.Sender, tf.AssetID, tf.Amount), state.IncreaseBalance(t.Database, tf.To, tf.AssetID, tf.Amount), ) - return errs.Err } func (t *Tx) Export(e *tx.Export) error { diff --git a/vms/example/xsvm/tx/codec.go b/vms/example/xsvm/tx/codec.go index aa8ce5738415..c91a2165f1f6 100644 --- a/vms/example/xsvm/tx/codec.go +++ b/vms/example/xsvm/tx/codec.go @@ -8,7 +8,7 @@ import ( "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) // Version is the current default codec version @@ -20,14 +20,13 @@ func init() { c := linearcodec.NewCustomMaxLength(math.MaxInt32) Codec = codec.NewManager(math.MaxInt32) - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( c.RegisterType(&Transfer{}), c.RegisterType(&Export{}), c.RegisterType(&Import{}), Codec.RegisterCodec(Version, c), ) - if errs.Errored() { - panic(errs.Err) + if err != nil { + panic(err) } } diff --git a/vms/nftfx/fx.go b/vms/nftfx/fx.go index d11e47e42be1..f56ffcc10e5d 100644 --- a/vms/nftfx/fx.go +++ b/vms/nftfx/fx.go @@ -7,7 +7,7 @@ import ( "bytes" "errors" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/components/verify" "github.com/ava-labs/avalanchego/vms/secp256k1fx" ) @@ -34,15 +34,13 @@ func (fx *Fx) Initialize(vmIntf interface{}) error { log.Debug("initializing nft fx") c := fx.VM.CodecRegistry() - errs := wrappers.Errs{} - errs.Add( + return utils.Err( c.RegisterType(&MintOutput{}), c.RegisterType(&TransferOutput{}), c.RegisterType(&MintOperation{}), c.RegisterType(&TransferOperation{}), c.RegisterType(&Credential{}), ) - return errs.Err } func (fx *Fx) VerifyOperation(txIntf, opIntf, credIntf interface{}, utxosIntf []interface{}) error { diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 58c71418b6e2..f68f0f4628e4 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -35,7 +35,6 @@ import ( "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/api" @@ -419,10 +418,8 @@ func shutdownEnvironment(env *environment) error { } } - errs := wrappers.Errs{} - errs.Add( + return utils.Err( env.state.Close(), env.baseDB.Close(), ) - return errs.Err } diff --git a/vms/platformvm/block/codec.go b/vms/platformvm/block/codec.go index efffedcb551b..1034ee9f759a 100644 --- a/vms/platformvm/block/codec.go +++ b/vms/platformvm/block/codec.go @@ -8,6 +8,7 @@ import ( "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/vms/platformvm/txs" ) @@ -53,24 +54,20 @@ func init() { // subpackage-level codecs were introduced, each handling serialization of // specific types. func RegisterApricotBlockTypes(targetCodec codec.Registry) error { - errs := wrappers.Errs{} - errs.Add( + return utils.Err( targetCodec.RegisterType(&ApricotProposalBlock{}), targetCodec.RegisterType(&ApricotAbortBlock{}), targetCodec.RegisterType(&ApricotCommitBlock{}), targetCodec.RegisterType(&ApricotStandardBlock{}), targetCodec.RegisterType(&ApricotAtomicBlock{}), ) - return errs.Err } func RegisterBanffBlockTypes(targetCodec codec.Registry) error { - errs := wrappers.Errs{} - errs.Add( + return utils.Err( targetCodec.RegisterType(&BanffProposalBlock{}), targetCodec.RegisterType(&BanffAbortBlock{}), targetCodec.RegisterType(&BanffCommitBlock{}), targetCodec.RegisterType(&BanffStandardBlock{}), ) - return errs.Err } diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 499d82669ad9..c13c4b635343 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -35,7 +35,6 @@ import ( "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/api" @@ -470,12 +469,14 @@ func shutdownEnvironment(t *environment) error { } } - errs := wrappers.Errs{} + var err error if t.state != nil { - errs.Add(t.state.Close()) + err = t.state.Close() } - errs.Add(t.baseDB.Close()) - return errs.Err + return utils.Err( + err, + t.baseDB.Close(), + ) } func addPendingValidator( diff --git a/vms/platformvm/metrics/metrics.go b/vms/platformvm/metrics/metrics.go index a73c8d168793..7c0e616dd9b2 100644 --- a/vms/platformvm/metrics/metrics.go +++ b/vms/platformvm/metrics/metrics.go @@ -110,9 +110,9 @@ func New( errs := wrappers.Errs{Err: err} apiRequestMetrics, err := metric.NewAPIInterceptor(namespace, registerer) + errs.Add(err) m.APIInterceptor = apiRequestMetrics errs.Add( - err, registerer.Register(m.timeUntilUnstake), registerer.Register(m.timeUntilSubnetUnstake), registerer.Register(m.localStake), diff --git a/vms/platformvm/service.go b/vms/platformvm/service.go index a2871faf0682..7619ee01d250 100644 --- a/vms/platformvm/service.go +++ b/vms/platformvm/service.go @@ -30,7 +30,6 @@ import ( "github.com/ava-labs/avalanchego/utils/json" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/set" - "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/keystore" "github.com/ava-labs/avalanchego/vms/platformvm/fx" @@ -1283,13 +1282,11 @@ func (s *Service) AddValidator(_ *http.Request, args *AddValidatorArgs, reply *a reply.TxID = tx.ID() reply.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr) - errs := wrappers.Errs{} - errs.Add( + return utils.Err( err, s.vm.Builder.AddUnverifiedTx(tx), user.Close(), ) - return errs.Err } // AddDelegatorArgs are the arguments to AddDelegator @@ -1395,13 +1392,11 @@ func (s *Service) AddDelegator(_ *http.Request, args *AddDelegatorArgs, reply *a reply.TxID = tx.ID() reply.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr) - errs := wrappers.Errs{} - errs.Add( + return utils.Err( err, s.vm.Builder.AddUnverifiedTx(tx), user.Close(), ) - return errs.Err } // AddSubnetValidatorArgs are the arguments to AddSubnetValidator @@ -1503,13 +1498,11 @@ func (s *Service) AddSubnetValidator(_ *http.Request, args *AddSubnetValidatorAr response.TxID = tx.ID() response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr) - errs := wrappers.Errs{} - errs.Add( + return utils.Err( err, s.vm.Builder.AddUnverifiedTx(tx), user.Close(), ) - return errs.Err } // CreateSubnetArgs are the arguments to CreateSubnet @@ -1581,13 +1574,11 @@ func (s *Service) CreateSubnet(_ *http.Request, args *CreateSubnetArgs, response response.TxID = tx.ID() response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr) - errs := wrappers.Errs{} - errs.Add( + return utils.Err( err, s.vm.Builder.AddUnverifiedTx(tx), user.Close(), ) - return errs.Err } // ExportAVAXArgs are the arguments to ExportAVAX @@ -1679,13 +1670,11 @@ func (s *Service) ExportAVAX(_ *http.Request, args *ExportAVAXArgs, response *ap response.TxID = tx.ID() response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr) - errs := wrappers.Errs{} - errs.Add( + return utils.Err( err, s.vm.Builder.AddUnverifiedTx(tx), user.Close(), ) - return errs.Err } // ImportAVAXArgs are the arguments to ImportAVAX @@ -1766,13 +1755,11 @@ func (s *Service) ImportAVAX(_ *http.Request, args *ImportAVAXArgs, response *ap response.TxID = tx.ID() response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr) - errs := wrappers.Errs{} - errs.Add( + return utils.Err( err, s.vm.Builder.AddUnverifiedTx(tx), user.Close(), ) - return errs.Err } /* @@ -1892,13 +1879,11 @@ func (s *Service) CreateBlockchain(_ *http.Request, args *CreateBlockchainArgs, response.TxID = tx.ID() response.ChangeAddr, err = s.addrManager.FormatLocalAddress(changeAddr) - errs := wrappers.Errs{} - errs.Add( + return utils.Err( err, s.vm.Builder.AddUnverifiedTx(tx), user.Close(), ) - return errs.Err } // GetBlockchainStatusArgs is the arguments for calling GetBlockchainStatus diff --git a/vms/platformvm/state/state.go b/vms/platformvm/state/state.go index 23a9412f89d8..872d9b669219 100644 --- a/vms/platformvm/state/state.go +++ b/vms/platformvm/state/state.go @@ -1404,14 +1404,12 @@ func (s *state) syncGenesis(genesisBlk block.Block, genesis *genesis.Genesis) er // Load pulls data previously stored on disk that is expected to be in memory. func (s *state) load() error { - errs := wrappers.Errs{} - errs.Add( + return utils.Err( s.loadMetadata(), s.loadCurrentValidators(), s.loadPendingValidators(), s.initValidatorSets(), ) - return errs.Err } func (s *state) loadMetadata() error { @@ -1596,14 +1594,12 @@ func (s *state) loadCurrentValidators() error { } } - errs := wrappers.Errs{} - errs.Add( + return utils.Err( validatorIt.Error(), subnetValidatorIt.Error(), delegatorIt.Error(), subnetDelegatorIt.Error(), ) - return errs.Err } func (s *state) loadPendingValidators() error { @@ -1682,14 +1678,12 @@ func (s *state) loadPendingValidators() error { } } - errs := wrappers.Errs{} - errs.Add( + return utils.Err( validatorIt.Error(), subnetValidatorIt.Error(), delegatorIt.Error(), subnetDelegatorIt.Error(), ) - return errs.Err } // Invariant: initValidatorSets requires loadCurrentValidators to have already @@ -1731,8 +1725,7 @@ func (s *state) initValidatorSets() error { } func (s *state) write(updateValidators bool, height uint64) error { - errs := wrappers.Errs{} - errs.Add( + return utils.Err( s.writeBlocks(), s.writeCurrentStakers(updateValidators, height), s.writePendingStakers(), @@ -1747,12 +1740,10 @@ func (s *state) write(updateValidators bool, height uint64) error { s.writeChains(), s.writeMetadata(), ) - return errs.Err } func (s *state) Close() error { - errs := wrappers.Errs{} - errs.Add( + return utils.Err( s.pendingSubnetValidatorBaseDB.Close(), s.pendingSubnetDelegatorBaseDB.Close(), s.pendingDelegatorBaseDB.Close(), @@ -1775,7 +1766,6 @@ func (s *state) Close() error { s.blockDB.Close(), s.blockIDDB.Close(), ) - return errs.Err } func (s *state) sync(genesis []byte) error { @@ -2537,14 +2527,13 @@ func (s *state) PruneAndIndex(lock sync.Locker, log logging.Logger) error { // attempt to commit to disk while a block is concurrently being // accepted. lock.Lock() - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( s.Commit(), blockIterator.Error(), ) lock.Unlock() - if errs.Errored() { - return errs.Err + if err != nil { + return err } // We release the iterator here to allow the underlying database to diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 74a5bb40764f..7d45f3b6c2fa 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -36,7 +36,6 @@ import ( "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/api" @@ -444,10 +443,8 @@ func shutdownEnvironment(env *environment) error { } } - errs := wrappers.Errs{} - errs.Add( + return utils.Err( env.state.Close(), env.baseDB.Close(), ) - return errs.Err } diff --git a/vms/platformvm/vm.go b/vms/platformvm/vm.go index b6e8937ecc8a..ee2fa308ebdb 100644 --- a/vms/platformvm/vm.go +++ b/vms/platformvm/vm.go @@ -29,7 +29,6 @@ import ( "github.com/ava-labs/avalanchego/utils/json" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/api" @@ -364,12 +363,10 @@ func (vm *VM) Shutdown(context.Context) error { } } - errs := wrappers.Errs{} - errs.Add( + return utils.Err( vm.state.Close(), vm.dbManager.Close(), ) - return errs.Err } func (vm *VM) ParseBlock(_ context.Context, b []byte) (snowman.Block, error) { diff --git a/vms/platformvm/warp/codec.go b/vms/platformvm/warp/codec.go index 0213a6701c6e..cf4587224751 100644 --- a/vms/platformvm/warp/codec.go +++ b/vms/platformvm/warp/codec.go @@ -8,7 +8,7 @@ import ( "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) const codecVersion = 0 @@ -20,12 +20,11 @@ func init() { c = codec.NewManager(math.MaxInt) lc := linearcodec.NewCustomMaxLength(math.MaxInt32) - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( lc.RegisterType(&BitSetSignature{}), c.RegisterCodec(codecVersion, lc), ) - if errs.Errored() { - panic(errs.Err) + if err != nil { + panic(err) } } diff --git a/vms/platformvm/warp/payload/codec.go b/vms/platformvm/warp/payload/codec.go index 31d20f6777ac..e2e8ddd7a7f5 100644 --- a/vms/platformvm/warp/payload/codec.go +++ b/vms/platformvm/warp/payload/codec.go @@ -6,8 +6,8 @@ package payload import ( "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/utils/wrappers" ) const ( @@ -27,13 +27,12 @@ func init() { c = codec.NewManager(MaxMessageSize) lc := linearcodec.NewCustomMaxLength(MaxSliceLen) - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( lc.RegisterType(&Hash{}), lc.RegisterType(&AddressedCall{}), c.RegisterCodec(codecVersion, lc), ) - if errs.Errored() { - panic(errs.Err) + if err != nil { + panic(err) } } diff --git a/vms/propertyfx/fx.go b/vms/propertyfx/fx.go index 2719c37e2972..28d211a9b5ad 100644 --- a/vms/propertyfx/fx.go +++ b/vms/propertyfx/fx.go @@ -6,7 +6,7 @@ package propertyfx import ( "errors" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/vms/components/verify" "github.com/ava-labs/avalanchego/vms/secp256k1fx" ) @@ -32,15 +32,13 @@ func (fx *Fx) Initialize(vmIntf interface{}) error { log.Debug("initializing nft fx") c := fx.VM.CodecRegistry() - errs := wrappers.Errs{} - errs.Add( + return utils.Err( c.RegisterType(&MintOutput{}), c.RegisterType(&OwnedOutput{}), c.RegisterType(&MintOperation{}), c.RegisterType(&BurnOperation{}), c.RegisterType(&Credential{}), ) - return errs.Err } func (fx *Fx) VerifyOperation(txIntf, opIntf, credIntf interface{}, utxosIntf []interface{}) error { diff --git a/vms/proposervm/block/codec.go b/vms/proposervm/block/codec.go index bf8089dbeb5a..6d68a4cc2fe7 100644 --- a/vms/proposervm/block/codec.go +++ b/vms/proposervm/block/codec.go @@ -8,7 +8,7 @@ import ( "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) const codecVersion = 0 @@ -24,13 +24,12 @@ func init() { linearCodec := linearcodec.NewCustomMaxLength(math.MaxUint32) c = codec.NewManager(math.MaxInt) - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( linearCodec.RegisterType(&statelessBlock{}), linearCodec.RegisterType(&option{}), c.RegisterCodec(codecVersion, linearCodec), ) - if errs.Errored() { - panic(errs.Err) + if err != nil { + panic(err) } } diff --git a/vms/secp256k1fx/fx.go b/vms/secp256k1fx/fx.go index 28f81218313d..e8dc6bcd9db0 100644 --- a/vms/secp256k1fx/fx.go +++ b/vms/secp256k1fx/fx.go @@ -9,9 +9,9 @@ import ( "github.com/ava-labs/avalanchego/cache" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/hashing" - "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/vms/components/verify" ) @@ -59,15 +59,13 @@ func (fx *Fx) Initialize(vmIntf interface{}) error { }, } c := fx.VM.CodecRegistry() - errs := wrappers.Errs{} - errs.Add( + return utils.Err( c.RegisterType(&TransferInput{}), c.RegisterType(&MintOutput{}), c.RegisterType(&TransferOutput{}), c.RegisterType(&MintOperation{}), c.RegisterType(&Credential{}), ) - return errs.Err } func (fx *Fx) InitializeVM(vmIntf interface{}) error { diff --git a/x/merkledb/metrics.go b/x/merkledb/metrics.go index a633b9d1bee1..d8a80a02db5a 100644 --- a/x/merkledb/metrics.go +++ b/x/merkledb/metrics.go @@ -8,7 +8,7 @@ import ( "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) var ( @@ -198,8 +198,7 @@ func newMetrics(namespace string, reg prometheus.Registerer) (merkleMetrics, err Help: "cumulative amount of misses on the view value cache", }), } - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( reg.Register(m.ioKeyWrite), reg.Register(m.ioKeyRead), reg.Register(m.hashCount), @@ -212,7 +211,7 @@ func newMetrics(namespace string, reg prometheus.Registerer) (merkleMetrics, err reg.Register(m.viewValueCacheHit), reg.Register(m.viewValueCacheMiss), ) - return &m, errs.Err + return &m, err } func (m *metrics) DatabaseNodeRead() { diff --git a/x/sync/metrics.go b/x/sync/metrics.go index fc62d7d11212..881ca37282ef 100644 --- a/x/sync/metrics.go +++ b/x/sync/metrics.go @@ -8,7 +8,7 @@ import ( "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/utils/wrappers" + "github.com/ava-labs/avalanchego/utils" ) var ( @@ -74,13 +74,12 @@ func NewMetrics(namespace string, reg prometheus.Registerer) (SyncMetrics, error Help: "cumulative amount of proof requests that were successful", }), } - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( reg.Register(m.requestsFailed), reg.Register(m.requestsMade), reg.Register(m.requestsSucceeded), ) - return &m, errs.Err + return &m, err } func (m *metrics) RequestFailed() { diff --git a/x/sync/peer_tracker.go b/x/sync/peer_tracker.go index 7c105f3363af..a1f8a66ae711 100644 --- a/x/sync/peer_tracker.go +++ b/x/sync/peer_tracker.go @@ -14,10 +14,10 @@ import ( "go.uber.org/zap" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/heap" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/set" - "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/version" safemath "github.com/ava-labs/avalanchego/utils/math" @@ -101,13 +101,12 @@ func newPeerTracker( ), } - errs := wrappers.Errs{} - errs.Add( + err := utils.Err( registerer.Register(t.numTrackedPeers), registerer.Register(t.numResponsivePeers), registerer.Register(t.averageBandwidthMetric), ) - return t, errs.Err + return t, err } // Returns true if we're not connected to enough peers. From 42d4e3ed5dee4e567fd2c122e37a340c7934d43b Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 27 Oct 2023 17:44:38 -0400 Subject: [PATCH 08/19] Enable `perfsprint` linter (#2229) --- .golangci.yml | 1 + api/keystore/service_test.go | 4 ++-- genesis/genesis_test.go | 5 +++-- node/node.go | 5 +++-- tests/fixture/testnet/local/network.go | 5 +++-- utils/crypto/bls/bls_benchmark_test.go | 8 ++++---- utils/ips/ip_port.go | 2 +- utils/ips/ip_test.go | 3 +-- utils/sampler/rand_test.go | 4 ++-- utils/set/bits.go | 4 ++-- vms/platformvm/warp/validator_test.go | 4 ++-- 11 files changed, 24 insertions(+), 21 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 160f617659ff..b5c99facb2b1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -65,6 +65,7 @@ linters: - nakedret - noctx - nolintlint + - perfsprint - prealloc - revive - staticcheck diff --git a/api/keystore/service_test.go b/api/keystore/service_test.go index a32fd6a716ad..0a3eef5687a4 100644 --- a/api/keystore/service_test.go +++ b/api/keystore/service_test.go @@ -4,7 +4,7 @@ package keystore import ( - "fmt" + "encoding/hex" "math/rand" "testing" @@ -58,7 +58,7 @@ func TestServiceCreateUser(t *testing.T) { func genStr(n int) string { b := make([]byte, n) rand.Read(b) // #nosec G404 - return fmt.Sprintf("%x", b)[:n] + return hex.EncodeToString(b)[:n] } // TestServiceCreateUserArgsCheck generates excessively long usernames or diff --git a/genesis/genesis_test.go b/genesis/genesis_test.go index 54cd7891787e..b18bc7f521a3 100644 --- a/genesis/genesis_test.go +++ b/genesis/genesis_test.go @@ -5,6 +5,7 @@ package genesis import ( "encoding/base64" + "encoding/hex" "encoding/json" "fmt" "os" @@ -244,7 +245,7 @@ func TestGenesisFromFile(t *testing.T) { genesisBytes, _, err := FromFile(test.networkID, customFile, genesisStakingCfg) require.ErrorIs(err, test.expectedErr) if test.expectedErr == nil { - genesisHash := fmt.Sprintf("%x", hashing.ComputeHash256(genesisBytes)) + genesisHash := hex.EncodeToString(hashing.ComputeHash256(genesisBytes)) require.Equal(test.expectedHash, genesisHash, "genesis hash mismatch") _, err = genesis.Parse(genesisBytes) @@ -330,7 +331,7 @@ func TestGenesisFromFlag(t *testing.T) { genesisBytes, _, err := FromFlag(test.networkID, content, genesisStakingCfg) require.ErrorIs(err, test.expectedErr) if test.expectedErr == nil { - genesisHash := fmt.Sprintf("%x", hashing.ComputeHash256(genesisBytes)) + genesisHash := hex.EncodeToString(hashing.ComputeHash256(genesisBytes)) require.Equal(test.expectedHash, genesisHash, "genesis hash mismatch") _, err = genesis.Parse(genesisBytes) diff --git a/node/node.go b/node/node.go index abea27da15a2..34293e85b0b6 100644 --- a/node/node.go +++ b/node/node.go @@ -15,6 +15,7 @@ import ( "net" "os" "path/filepath" + "strconv" "sync" "time" @@ -244,7 +245,7 @@ func (n *Node) initNetworking() error { // // 1: https://apple.stackexchange.com/questions/393715/do-you-want-the-application-main-to-accept-incoming-network-connections-pop // 2: https://github.com/golang/go/issues/56998 - listenAddress := net.JoinHostPort(n.Config.ListenHost, fmt.Sprintf("%d", currentIPPort.Port)) + listenAddress := net.JoinHostPort(n.Config.ListenHost, strconv.FormatUint(uint64(currentIPPort.Port), 10)) listener, err := net.Listen(constants.NetworkType, listenAddress) if err != nil { @@ -678,7 +679,7 @@ func (n *Node) initMetrics() { func (n *Node) initAPIServer() error { n.Log.Info("initializing API server") - listenAddress := net.JoinHostPort(n.Config.HTTPHost, fmt.Sprintf("%d", n.Config.HTTPPort)) + listenAddress := net.JoinHostPort(n.Config.HTTPHost, strconv.FormatUint(uint64(n.Config.HTTPPort), 10)) listener, err := net.Listen("tcp", listenAddress) if err != nil { return err diff --git a/tests/fixture/testnet/local/network.go b/tests/fixture/testnet/local/network.go index fa3b3d22d742..4d2df79d8f28 100644 --- a/tests/fixture/testnet/local/network.go +++ b/tests/fixture/testnet/local/network.go @@ -12,6 +12,7 @@ import ( "io/fs" "os" "path/filepath" + "strconv" "time" "github.com/ava-labs/avalanchego/config" @@ -65,7 +66,7 @@ func FindNextNetworkID(rootDir string) (uint32, string, error) { continue } - dirPath = filepath.Join(rootDir, fmt.Sprint(networkID)) + dirPath = filepath.Join(rootDir, strconv.FormatUint(uint64(networkID), 10)) err := os.Mkdir(dirPath, perms.ReadWriteExecute) if err == nil { return networkID, dirPath, nil @@ -304,7 +305,7 @@ func (ln *LocalNetwork) PopulateNodeConfig(node *LocalNode, nodeParentDir string }) // Convert the network id to a string to ensure consistency in JSON round-tripping. - flags[config.NetworkNameKey] = fmt.Sprintf("%d", ln.Genesis.NetworkID) + flags[config.NetworkNameKey] = strconv.FormatUint(uint64(ln.Genesis.NetworkID), 10) // Ensure keys are added if necessary if err := node.EnsureKeys(); err != nil { diff --git a/utils/crypto/bls/bls_benchmark_test.go b/utils/crypto/bls/bls_benchmark_test.go index a84cdadd80a5..cd3568005764 100644 --- a/utils/crypto/bls/bls_benchmark_test.go +++ b/utils/crypto/bls/bls_benchmark_test.go @@ -4,7 +4,7 @@ package bls import ( - "fmt" + "strconv" "testing" "github.com/stretchr/testify/require" @@ -31,7 +31,7 @@ func BenchmarkSign(b *testing.B) { privateKey, err := NewSecretKey() require.NoError(b, err) for _, messageSize := range sizes { - b.Run(fmt.Sprintf("%d", messageSize), func(b *testing.B) { + b.Run(strconv.Itoa(messageSize), func(b *testing.B) { message := utils.RandomBytes(messageSize) b.ResetTimer() @@ -49,7 +49,7 @@ func BenchmarkVerify(b *testing.B) { publicKey := PublicFromSecretKey(privateKey) for _, messageSize := range sizes { - b.Run(fmt.Sprintf("%d", messageSize), func(b *testing.B) { + b.Run(strconv.Itoa(messageSize), func(b *testing.B) { message := utils.RandomBytes(messageSize) signature := Sign(privateKey, message) @@ -72,7 +72,7 @@ func BenchmarkAggregatePublicKeys(b *testing.B) { } for _, size := range sizes { - b.Run(fmt.Sprintf("%d", size), func(b *testing.B) { + b.Run(strconv.Itoa(size), func(b *testing.B) { for n := 0; n < b.N; n++ { _, err := AggregatePublicKeys(keys[:size]) require.NoError(b, err) diff --git a/utils/ips/ip_port.go b/utils/ips/ip_port.go index 472b5c372a2d..3ca5bfe176d4 100644 --- a/utils/ips/ip_port.go +++ b/utils/ips/ip_port.go @@ -62,7 +62,7 @@ func (ipPort IPPort) Equal(other IPPort) bool { } func (ipPort IPPort) String() string { - return net.JoinHostPort(ipPort.IP.String(), fmt.Sprintf("%d", ipPort.Port)) + return net.JoinHostPort(ipPort.IP.String(), strconv.FormatUint(uint64(ipPort.Port), 10)) } // IsZero returns if the IP or port is zeroed out diff --git a/utils/ips/ip_test.go b/utils/ips/ip_test.go index c3c569a8ae0a..30a72017e6da 100644 --- a/utils/ips/ip_test.go +++ b/utils/ips/ip_test.go @@ -5,7 +5,6 @@ package ips import ( "encoding/json" - "fmt" "net" "strconv" "testing" @@ -61,7 +60,7 @@ func TestIPPortEqual(t *testing.T) { }, } for i, tt := range tests { - t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + t.Run(strconv.Itoa(i), func(t *testing.T) { require := require.New(t) ipPort := IPDesc{} diff --git a/utils/sampler/rand_test.go b/utils/sampler/rand_test.go index b2ef3dfb0f60..362093a695ac 100644 --- a/utils/sampler/rand_test.go +++ b/utils/sampler/rand_test.go @@ -4,9 +4,9 @@ package sampler import ( - "fmt" "math" "math/rand" + "strconv" "testing" "github.com/stretchr/testify/require" @@ -149,7 +149,7 @@ func TestRNG(t *testing.T) { }, } for i, test := range tests { - t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + t.Run(strconv.Itoa(i), func(t *testing.T) { require := require.New(t) source := &testSource{ diff --git a/utils/set/bits.go b/utils/set/bits.go index bf7f5f7b0e1f..344c8dff6781 100644 --- a/utils/set/bits.go +++ b/utils/set/bits.go @@ -4,7 +4,7 @@ package set import ( - "fmt" + "encoding/hex" "math/big" "math/bits" ) @@ -98,5 +98,5 @@ func BitsFromBytes(bytes []byte) Bits { // String returns the hex representation of this bitset func (b Bits) String() string { - return fmt.Sprintf("%x", b.bits.Bytes()) + return hex.EncodeToString(b.bits.Bytes()) } diff --git a/vms/platformvm/warp/validator_test.go b/vms/platformvm/warp/validator_test.go index b306c82b79f0..9af37aed81f6 100644 --- a/vms/platformvm/warp/validator_test.go +++ b/vms/platformvm/warp/validator_test.go @@ -5,8 +5,8 @@ package warp import ( "context" - "fmt" "math" + "strconv" "testing" "github.com/stretchr/testify/require" @@ -336,7 +336,7 @@ func BenchmarkGetCanonicalValidatorSet(b *testing.B) { }, } - b.Run(fmt.Sprintf("%d", size), func(b *testing.B) { + b.Run(strconv.Itoa(size), func(b *testing.B) { for i := 0; i < b.N; i++ { _, _, err := GetCanonicalValidatorSet(context.Background(), validatorState, pChainHeight, subnetID) require.NoError(b, err) From 66375f57eed975aebd30907394134017e374da8a Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 27 Oct 2023 18:44:34 -0400 Subject: [PATCH 09/19] Trim down size of secp256k1 `Factory` struct (#2223) Signed-off-by: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> --- genesis/genesis_local.go | 5 +- go.mod | 2 +- go.sum | 4 +- tests/e2e/c/dynamic_fees.go | 3 +- tests/e2e/c/interchain_workflow.go | 3 +- tests/e2e/p/interchain_workflow.go | 7 +- tests/e2e/p/staking_rewards.go | 13 ++- tests/e2e/static-handlers/suites.go | 3 +- tests/e2e/x/interchain_workflow.go | 3 +- tests/fixture/test_data_server_test.go | 3 +- tests/fixture/testnet/local/network.go | 3 +- utils/crypto/ledger/ledger_test.go | 4 +- utils/crypto/secp256k1/rfc6979_test.go | 3 +- utils/crypto/secp256k1/secp256k1.go | 57 +++++++----- .../secp256k1/secp256k1_benchmark_test.go | 4 +- utils/crypto/secp256k1/secp256k1_test.go | 91 ++++++++++++++----- utils/crypto/secp256k1/test_keys.go | 5 +- vms/avm/environment_test.go | 4 +- vms/avm/service_test.go | 6 +- vms/components/keystore/user.go | 9 +- vms/components/keystore/user_test.go | 6 +- vms/example/xsvm/tx/tx.go | 6 +- .../block/executor/proposal_block_test.go | 3 +- vms/platformvm/service_test.go | 5 +- .../txs/executor/create_chain_test.go | 3 +- vms/platformvm/txs/executor/helpers_test.go | 3 - vms/platformvm/txs/executor/import_test.go | 3 +- .../txs/executor/proposal_tx_executor_test.go | 2 +- .../txs/executor/standard_tx_executor_test.go | 2 +- vms/platformvm/vm_regression_test.go | 10 +- vms/platformvm/vm_test.go | 7 +- vms/secp256k1fx/fx.go | 9 +- vms/secp256k1fx/keychain.go | 4 +- vms/secp256k1fx/keychain_test.go | 12 +-- 34 files changed, 164 insertions(+), 143 deletions(-) diff --git a/genesis/genesis_local.go b/genesis/genesis_local.go index 7a136360e79a..de650009fd26 100644 --- a/genesis/genesis_local.go +++ b/genesis/genesis_local.go @@ -72,10 +72,9 @@ func init() { ewoqBytes, err := cb58.Decode(EWOQKeyStr) errs.Add(err) - factory := secp256k1.Factory{} - VMRQKey, err = factory.ToPrivateKey(vmrqBytes) + VMRQKey, err = secp256k1.ToPrivateKey(vmrqBytes) errs.Add(err) - EWOQKey, err = factory.ToPrivateKey(ewoqBytes) + EWOQKey, err = secp256k1.ToPrivateKey(ewoqBytes) errs.Add(err) if errs.Err != nil { diff --git a/go.mod b/go.mod index f351efbef090..8bcba0590042 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/DataDog/zstd v1.5.2 github.com/Microsoft/go-winio v0.5.2 github.com/NYTimes/gziphandler v1.1.1 - github.com/ava-labs/coreth v0.12.7-rc.1 + github.com/ava-labs/coreth v0.12.8-0.20231027221814-507f2239095b github.com/ava-labs/ledger-avalanche/go v0.0.0-20230105152938-00a24d05a8c7 github.com/btcsuite/btcd/btcutil v1.1.3 github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 diff --git a/go.sum b/go.sum index d301d4b6be81..f4d542b4a159 100644 --- a/go.sum +++ b/go.sum @@ -62,8 +62,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/coreth v0.12.7-rc.1 h1:fvjow2Jqkq1RNtW4v2Kx0DdTVp+3+fCY421TxpDDRfM= -github.com/ava-labs/coreth v0.12.7-rc.1/go.mod h1:sNbwitXv4AhLvWpSqy6V8yzkhGFeWBQFD31/xiRDJ5M= +github.com/ava-labs/coreth v0.12.8-0.20231027221814-507f2239095b h1:pKSpTTWvsmDJ7MUkaOPAYfN4mKgWgg4K2cm4k+tvqNI= +github.com/ava-labs/coreth v0.12.8-0.20231027221814-507f2239095b/go.mod h1:8aFn5vDkc9g7RT8bSvx9KAo2Xu4AqzwWAnfoderYPDs= github.com/ava-labs/ledger-avalanche/go v0.0.0-20230105152938-00a24d05a8c7 h1:EdxD90j5sClfL5Ngpz2TlnbnkNYdFPDXa0jDOjam65c= github.com/ava-labs/ledger-avalanche/go v0.0.0-20230105152938-00a24d05a8c7/go.mod h1:XhiXSrh90sHUbkERzaxEftCmUz53eCijshDLZ4fByVM= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= diff --git a/tests/e2e/c/dynamic_fees.go b/tests/e2e/c/dynamic_fees.go index f3a1daaf3d2c..edfbef2671a8 100644 --- a/tests/e2e/c/dynamic_fees.go +++ b/tests/e2e/c/dynamic_fees.go @@ -143,8 +143,7 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() { ginkgo.By("sending funds at the current gas price", func() { // Create a recipient address - factory := secp256k1.Factory{} - recipientKey, err := factory.NewPrivateKey() + recipientKey, err := secp256k1.NewPrivateKey() require.NoError(err) recipientEthAddress := evm.GetEthAddress(recipientKey) diff --git a/tests/e2e/c/interchain_workflow.go b/tests/e2e/c/interchain_workflow.go index 47c430d4c12a..8bed85eb1bd9 100644 --- a/tests/e2e/c/interchain_workflow.go +++ b/tests/e2e/c/interchain_workflow.go @@ -39,8 +39,7 @@ var _ = e2e.DescribeCChain("[Interchain Workflow]", func() { ginkgo.By("allocating a pre-funded key to send from and a recipient key to deliver to") senderKey := e2e.Env.AllocateFundedKey() senderEthAddress := evm.GetEthAddress(senderKey) - factory := secp256k1.Factory{} - recipientKey, err := factory.NewPrivateKey() + recipientKey, err := secp256k1.NewPrivateKey() require.NoError(err) recipientEthAddress := evm.GetEthAddress(recipientKey) diff --git a/tests/e2e/p/interchain_workflow.go b/tests/e2e/p/interchain_workflow.go index 10c15fd002a7..729418adbd97 100644 --- a/tests/e2e/p/interchain_workflow.go +++ b/tests/e2e/p/interchain_workflow.go @@ -48,8 +48,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL }) ginkgo.By("creating wallet with a funded key to send from and recipient key to deliver to") - factory := secp256k1.Factory{} - recipientKey, err := factory.NewPrivateKey() + recipientKey, err := secp256k1.NewPrivateKey() require.NoError(err) keychain := e2e.Env.NewKeychain(1) keychain.Add(recipientKey) @@ -103,7 +102,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL // doesn't break interchain transfer. endTime := startTime.Add(30 * time.Second) - rewardKey, err := factory.NewPrivateKey() + rewardKey, err := secp256k1.NewPrivateKey() require.NoError(err) const ( @@ -144,7 +143,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL // doesn't break interchain transfer. endTime := startTime.Add(15 * time.Second) - rewardKey, err := factory.NewPrivateKey() + rewardKey, err := secp256k1.NewPrivateKey() require.NoError(err) _, err = pWallet.IssueAddPermissionlessDelegatorTx( diff --git a/tests/e2e/p/staking_rewards.go b/tests/e2e/p/staking_rewards.go index 009980c71afb..df64088103ce 100644 --- a/tests/e2e/p/staking_rewards.go +++ b/tests/e2e/p/staking_rewards.go @@ -59,22 +59,21 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() { e2e.WaitForHealthy(betaNode) ginkgo.By("generating reward keys") - factory := secp256k1.Factory{} - alphaValidationRewardKey, err := factory.NewPrivateKey() + alphaValidationRewardKey, err := secp256k1.NewPrivateKey() require.NoError(err) - alphaDelegationRewardKey, err := factory.NewPrivateKey() + alphaDelegationRewardKey, err := secp256k1.NewPrivateKey() require.NoError(err) - betaValidationRewardKey, err := factory.NewPrivateKey() + betaValidationRewardKey, err := secp256k1.NewPrivateKey() require.NoError(err) - betaDelegationRewardKey, err := factory.NewPrivateKey() + betaDelegationRewardKey, err := secp256k1.NewPrivateKey() require.NoError(err) - gammaDelegationRewardKey, err := factory.NewPrivateKey() + gammaDelegationRewardKey, err := secp256k1.NewPrivateKey() require.NoError(err) - deltaDelegationRewardKey, err := factory.NewPrivateKey() + deltaDelegationRewardKey, err := secp256k1.NewPrivateKey() require.NoError(err) rewardKeys := []*secp256k1.PrivateKey{ diff --git a/tests/e2e/static-handlers/suites.go b/tests/e2e/static-handlers/suites.go index 2791f8085a80..596a79f3afda 100644 --- a/tests/e2e/static-handlers/suites.go +++ b/tests/e2e/static-handlers/suites.go @@ -115,7 +115,6 @@ var _ = ginkgo.Describe("[StaticHandlers]", func() { ginkgo.It("can make calls to platformvm static api", func() { keys := []*secp256k1.PrivateKey{} - factory := secp256k1.Factory{} for _, key := range []string{ "24jUJ9vZexUM6expyMcT48LBx27k1m7xpraoV62oSQAHdziao5", "2MMvUMsxx6zsHSNXJdFD8yc5XkancvwyKPwpw4xUK3TCGDuNBY", @@ -125,7 +124,7 @@ var _ = ginkgo.Describe("[StaticHandlers]", func() { } { privKeyBytes, err := cb58.Decode(key) require.NoError(err) - pk, err := factory.ToPrivateKey(privKeyBytes) + pk, err := secp256k1.ToPrivateKey(privKeyBytes) require.NoError(err) keys = append(keys, pk) } diff --git a/tests/e2e/x/interchain_workflow.go b/tests/e2e/x/interchain_workflow.go index 550689ff60c9..6d335199b5b9 100644 --- a/tests/e2e/x/interchain_workflow.go +++ b/tests/e2e/x/interchain_workflow.go @@ -32,8 +32,7 @@ var _ = e2e.DescribeXChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL nodeURI := e2e.Env.GetRandomNodeURI() ginkgo.By("creating wallet with a funded key to send from and recipient key to deliver to") - factory := secp256k1.Factory{} - recipientKey, err := factory.NewPrivateKey() + recipientKey, err := secp256k1.NewPrivateKey() require.NoError(err) keychain := e2e.Env.NewKeychain(1) keychain.Add(recipientKey) diff --git a/tests/fixture/test_data_server_test.go b/tests/fixture/test_data_server_test.go index daef840528b5..979c927fea7f 100644 --- a/tests/fixture/test_data_server_test.go +++ b/tests/fixture/test_data_server_test.go @@ -17,10 +17,9 @@ import ( func TestAllocateFundedKeys(t *testing.T) { require := require.New(t) - factory := secp256k1.Factory{} keys := make([]*secp256k1.PrivateKey, 5) for i := range keys { - key, err := factory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(err) keys[i] = key } diff --git a/tests/fixture/testnet/local/network.go b/tests/fixture/testnet/local/network.go index 4d2df79d8f28..4f83a7fb0869 100644 --- a/tests/fixture/testnet/local/network.go +++ b/tests/fixture/testnet/local/network.go @@ -254,10 +254,9 @@ func (ln *LocalNetwork) PopulateLocalNetworkConfig(networkID uint32, nodeCount i if keyCount > 0 { // Ensure there are keys for genesis generation to fund - factory := secp256k1.Factory{} keys := make([]*secp256k1.PrivateKey, 0, keyCount) for i := 0; i < keyCount; i++ { - key, err := factory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() if err != nil { return fmt.Errorf("failed to generate private key: %w", err) } diff --git a/utils/crypto/ledger/ledger_test.go b/utils/crypto/ledger/ledger_test.go index 1ab163c95aa4..118dc8758d1b 100644 --- a/utils/crypto/ledger/ledger_test.go +++ b/utils/crypto/ledger/ledger_test.go @@ -18,8 +18,6 @@ const ( hrp = "fuji" ) -var factory secp256k1.Factory - // TestLedger will be skipped if a ledger is not connected. func TestLedger(t *testing.T) { require := require.New(t) @@ -66,7 +64,7 @@ func TestLedger(t *testing.T) { for i, addrIndex := range indices { sig := sigs[i] - pk, err := factory.RecoverHashPublicKey(rawHash, sig) + pk, err := secp256k1.RecoverPublicKeyFromHash(rawHash, sig) require.NoError(err) require.Equal(addresses[addrIndex], pk.Address()) } diff --git a/utils/crypto/secp256k1/rfc6979_test.go b/utils/crypto/secp256k1/rfc6979_test.go index d4c0a9c45191..5d9ee8b4f033 100644 --- a/utils/crypto/secp256k1/rfc6979_test.go +++ b/utils/crypto/secp256k1/rfc6979_test.go @@ -58,7 +58,6 @@ type test struct { } func TestRFC6979Compliance(t *testing.T) { - f := Factory{} for i, tt := range rfc6979Tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { require := require.New(t) @@ -66,7 +65,7 @@ func TestRFC6979Compliance(t *testing.T) { skBytes, err := hex.DecodeString(tt.skHex) require.NoError(err) - sk, err := f.ToPrivateKey(skBytes) + sk, err := ToPrivateKey(skBytes) require.NoError(err) msgBytes := []byte(tt.msg) diff --git a/utils/crypto/secp256k1/secp256k1.go b/utils/crypto/secp256k1/secp256k1.go index 857921bf2ea5..022cce2861a0 100644 --- a/utils/crypto/secp256k1/secp256k1.go +++ b/utils/crypto/secp256k1/secp256k1.go @@ -54,16 +54,12 @@ var ( errMutatedSig = errors.New("signature was mutated from its original format") ) -type Factory struct { - Cache cache.LRU[ids.ID, *PublicKey] -} - -func (*Factory) NewPrivateKey() (*PrivateKey, error) { +func NewPrivateKey() (*PrivateKey, error) { k, err := secp256k1.GeneratePrivateKey() return &PrivateKey{sk: k}, err } -func (*Factory) ToPublicKey(b []byte) (*PublicKey, error) { +func ToPublicKey(b []byte) (*PublicKey, error) { if len(b) != PublicKeyLen { return nil, errInvalidPublicKeyLength } @@ -75,7 +71,7 @@ func (*Factory) ToPublicKey(b []byte) (*PublicKey, error) { }, err } -func (*Factory) ToPrivateKey(b []byte) (*PrivateKey, error) { +func ToPrivateKey(b []byte) (*PrivateKey, error) { if len(b) != PrivateKeyLen { return nil, errInvalidPrivateKeyLength } @@ -85,19 +81,11 @@ func (*Factory) ToPrivateKey(b []byte) (*PrivateKey, error) { }, nil } -func (f *Factory) RecoverPublicKey(msg, sig []byte) (*PublicKey, error) { - return f.RecoverHashPublicKey(hashing.ComputeHash256(msg), sig) +func RecoverPublicKey(msg, sig []byte) (*PublicKey, error) { + return RecoverPublicKeyFromHash(hashing.ComputeHash256(msg), sig) } -func (f *Factory) RecoverHashPublicKey(hash, sig []byte) (*PublicKey, error) { - cacheBytes := make([]byte, len(hash)+len(sig)) - copy(cacheBytes, hash) - copy(cacheBytes[len(hash):], sig) - id := hashing.ComputeHash256Array(cacheBytes) - if cachedPublicKey, ok := f.Cache.Get(id); ok { - return cachedPublicKey, nil - } - +func RecoverPublicKeyFromHash(hash, sig []byte) (*PublicKey, error) { if err := verifySECP256K1RSignatureFormat(sig); err != nil { return nil, err } @@ -116,9 +104,33 @@ func (f *Factory) RecoverHashPublicKey(hash, sig []byte) (*PublicKey, error) { return nil, errCompressed } - pubkey := &PublicKey{pk: rawPubkey} - f.Cache.Put(id, pubkey) - return pubkey, nil + return &PublicKey{pk: rawPubkey}, nil +} + +type RecoverCache struct { + cache.LRU[ids.ID, *PublicKey] +} + +func (r *RecoverCache) RecoverPublicKey(msg, sig []byte) (*PublicKey, error) { + return r.RecoverPublicKeyFromHash(hashing.ComputeHash256(msg), sig) +} + +func (r *RecoverCache) RecoverPublicKeyFromHash(hash, sig []byte) (*PublicKey, error) { + cacheBytes := make([]byte, len(hash)+len(sig)) + copy(cacheBytes, hash) + copy(cacheBytes[len(hash):], sig) + id := hashing.ComputeHash256Array(cacheBytes) + if cachedPublicKey, ok := r.Get(id); ok { + return cachedPublicKey, nil + } + + pubKey, err := RecoverPublicKeyFromHash(hash, sig) + if err != nil { + return nil, err + } + + r.Put(id, pubKey) + return pubKey, nil } type PublicKey struct { @@ -132,8 +144,7 @@ func (k *PublicKey) Verify(msg, sig []byte) bool { } func (k *PublicKey) VerifyHash(hash, sig []byte) bool { - factory := Factory{} - pk, err := factory.RecoverHashPublicKey(hash, sig) + pk, err := RecoverPublicKeyFromHash(hash, sig) if err != nil { return false } diff --git a/utils/crypto/secp256k1/secp256k1_benchmark_test.go b/utils/crypto/secp256k1/secp256k1_benchmark_test.go index b7f105b0dfe1..1d55f38f7d86 100644 --- a/utils/crypto/secp256k1/secp256k1_benchmark_test.go +++ b/utils/crypto/secp256k1/secp256k1_benchmark_test.go @@ -15,9 +15,7 @@ import ( func BenchmarkVerify(b *testing.B) { require := require.New(b) - f := &Factory{} - - privateKey, err := f.NewPrivateKey() + privateKey, err := NewPrivateKey() require.NoError(err) message := utils.RandomBytes(512) diff --git a/utils/crypto/secp256k1/secp256k1_test.go b/utils/crypto/secp256k1/secp256k1_test.go index 9a8dbdb89077..a2074dff5229 100644 --- a/utils/crypto/secp256k1/secp256k1_test.go +++ b/utils/crypto/secp256k1/secp256k1_test.go @@ -19,8 +19,7 @@ import ( func TestRecover(t *testing.T) { require := require.New(t) - f := Factory{} - key, err := f.NewPrivateKey() + key, err := NewPrivateKey() require.NoError(err) msg := []byte{1, 2, 3} @@ -28,38 +27,40 @@ func TestRecover(t *testing.T) { require.NoError(err) pub := key.PublicKey() - pubRec, err := f.RecoverPublicKey(msg, sig) + pubRec, err := RecoverPublicKey(msg, sig) require.NoError(err) require.Equal(pub, pubRec) + + require.True(pub.Verify(msg, sig)) } func TestCachedRecover(t *testing.T) { require := require.New(t) - f := Factory{Cache: cache.LRU[ids.ID, *PublicKey]{Size: 1}} - key, err := f.NewPrivateKey() + key, err := NewPrivateKey() require.NoError(err) msg := []byte{1, 2, 3} sig, err := key.Sign(msg) require.NoError(err) - pub1, err := f.RecoverPublicKey(msg, sig) + r := RecoverCache{LRU: cache.LRU[ids.ID, *PublicKey]{Size: 1}} + pub1, err := r.RecoverPublicKey(msg, sig) require.NoError(err) - pub2, err := f.RecoverPublicKey(msg, sig) + pub2, err := r.RecoverPublicKey(msg, sig) require.NoError(err) - require.Equal(pub1, pub2) + require.Equal(key.PublicKey(), pub1) + require.Equal(key.PublicKey(), pub2) } func TestExtensive(t *testing.T) { require := require.New(t) - f := Factory{} hash := hashing.ComputeHash256([]byte{1, 2, 3}) for i := 0; i < 1000; i++ { - key, err := f.NewPrivateKey() + key, err := NewPrivateKey() require.NoError(err) _, err = key.SignHash(hash) @@ -70,13 +71,12 @@ func TestExtensive(t *testing.T) { func TestGenRecreate(t *testing.T) { require := require.New(t) - f := Factory{} for i := 0; i < 1000; i++ { - sk, err := f.NewPrivateKey() + sk, err := NewPrivateKey() require.NoError(err) skBytes := sk.Bytes() - recoveredSk, err := f.ToPrivateKey(skBytes) + recoveredSk, err := ToPrivateKey(skBytes) require.NoError(err) require.Equal(sk.PublicKey(), recoveredSk.PublicKey()) @@ -86,8 +86,7 @@ func TestGenRecreate(t *testing.T) { func TestVerifyMutatedSignature(t *testing.T) { require := require.New(t) - f := Factory{} - sk, err := f.NewPrivateKey() + sk, err := NewPrivateKey() require.NoError(err) msg := []byte{'h', 'e', 'l', 'l', 'o'} @@ -100,15 +99,14 @@ func TestVerifyMutatedSignature(t *testing.T) { newSBytes := s.Bytes() copy(sig[32:], newSBytes[:]) - _, err = f.RecoverPublicKey(msg, sig) + _, err = RecoverPublicKey(msg, sig) require.ErrorIs(err, errMutatedSig) } func TestPrivateKeySECP256K1RUnmarshalJSON(t *testing.T) { require := require.New(t) - f := Factory{} - key, err := f.NewPrivateKey() + key, err := NewPrivateKey() require.NoError(err) keyJSON, err := key.MarshalJSON() @@ -239,13 +237,60 @@ func TestSigning(t *testing.T) { } } -func FuzzVerifySignature(f *testing.F) { - factory := Factory{} +func TestExportedMethods(t *testing.T) { + require := require.New(t) + + key := TestKeys()[0] + + pubKey := key.PublicKey() + require.Equal("111111111111111111116DBWJs", pubKey.addr.String()) + require.Equal("Q4MzFZZDPHRPAHFeDs3NiyyaZDvxHKivf", pubKey.Address().String()) + require.Equal("Q4MzFZZDPHRPAHFeDs3NiyyaZDvxHKivf", pubKey.addr.String()) + require.Equal("Q4MzFZZDPHRPAHFeDs3NiyyaZDvxHKivf", key.Address().String()) + + expectedPubKeyBytes := []byte{ + 0x03, 0x73, 0x93, 0x53, 0x47, 0x88, 0x44, 0x78, + 0xe4, 0x94, 0x5c, 0xd0, 0xfd, 0x94, 0x8e, 0xcf, + 0x08, 0x8b, 0x94, 0xdf, 0xc9, 0x20, 0x74, 0xf0, + 0xfb, 0x03, 0xda, 0x6f, 0x4d, 0xbc, 0x94, 0x35, + 0x7d, + } + require.Equal(expectedPubKeyBytes, pubKey.bytes) + + expectedPubKey, err := ToPublicKey(expectedPubKeyBytes) + require.NoError(err) + require.Equal(expectedPubKey.Address(), pubKey.Address()) + require.Equal(expectedPubKeyBytes, expectedPubKey.Bytes()) + expectedECDSAParams := struct { + X []byte + Y []byte + }{ + []byte{ + 0x73, 0x93, 0x53, 0x47, 0x88, 0x44, 0x78, 0xe4, + 0x94, 0x5c, 0xd0, 0xfd, 0x94, 0x8e, 0xcf, 0x08, + 0x8b, 0x94, 0xdf, 0xc9, 0x20, 0x74, 0xf0, 0xfb, + 0x03, 0xda, 0x6f, 0x4d, 0xbc, 0x94, 0x35, 0x7d, + }, + []byte{ + 0x78, 0xe7, 0x39, 0x45, 0x6c, 0x3b, 0xdb, 0x9e, + 0xe9, 0xb2, 0xa9, 0xf2, 0x84, 0xfa, 0x64, 0x32, + 0xd8, 0x4e, 0xf0, 0xfa, 0x3f, 0x82, 0xf5, 0x56, + 0x10, 0x40, 0x71, 0x7f, 0x1f, 0x5e, 0x8e, 0x27, + }, + } + require.Equal(expectedECDSAParams.X, pubKey.ToECDSA().X.Bytes()) + require.Equal(expectedECDSAParams.Y, pubKey.ToECDSA().Y.Bytes()) + + require.Equal(expectedECDSAParams.X, key.ToECDSA().X.Bytes()) + require.Equal(expectedECDSAParams.Y, key.ToECDSA().Y.Bytes()) +} + +func FuzzVerifySignature(f *testing.F) { f.Fuzz(func(t *testing.T, data []byte) { require := require.New(t) - privateKey, err := factory.NewPrivateKey() + privateKey, err := NewPrivateKey() require.NoError(err) publicKey := privateKey.PublicKey() @@ -253,9 +298,9 @@ func FuzzVerifySignature(f *testing.F) { sig, err := privateKey.Sign(data) require.NoError(err) - recoveredPublicKey, err := factory.RecoverPublicKey(data, sig) + recoveredPublicKey, err := RecoverPublicKey(data, sig) require.NoError(err) - require.Equal(publicKey.Bytes(), recoveredPublicKey.Bytes()) + require.Equal(publicKey, recoveredPublicKey) }) } diff --git a/utils/crypto/secp256k1/test_keys.go b/utils/crypto/secp256k1/test_keys.go index 09e484973519..3122f2617ddf 100644 --- a/utils/crypto/secp256k1/test_keys.go +++ b/utils/crypto/secp256k1/test_keys.go @@ -14,8 +14,7 @@ func TestKeys() []*PrivateKey { "ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN", "2RWLv6YVEXDiWLpaCbXhhqxtLbnFaKQsWPSSMSPhpWo47uJAeV", } - keys = make([]*PrivateKey, len(keyStrings)) - factory = Factory{} + keys = make([]*PrivateKey, len(keyStrings)) ) for i, key := range keyStrings { @@ -24,7 +23,7 @@ func TestKeys() []*PrivateKey { panic(err) } - keys[i], err = factory.ToPrivateKey(privKeyBytes) + keys[i], err = ToPrivateKey(privKeyBytes) if err != nil { panic(err) } diff --git a/vms/avm/environment_test.go b/vms/avm/environment_test.go index a75fb315ccc9..89fa15bd917c 100644 --- a/vms/avm/environment_test.go +++ b/vms/avm/environment_test.go @@ -77,15 +77,13 @@ var ( ) func init() { - factory := secp256k1.Factory{} - for _, key := range []string{ "24jUJ9vZexUM6expyMcT48LBx27k1m7xpraoV62oSQAHdziao5", "2MMvUMsxx6zsHSNXJdFD8yc5XkancvwyKPwpw4xUK3TCGDuNBY", "cxb7KpGWhDMALTjNNSJ7UQkkomPesyWAPUaWRGdyeBNzR6f35", } { keyBytes, _ := cb58.Decode(key) - pk, _ := factory.ToPrivateKey(keyBytes) + pk, _ := secp256k1.ToPrivateKey(keyBytes) keys = append(keys, pk) addrs = append(addrs, pk.PublicKey().Address()) } diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index 15ebeba2c954..67a92a663879 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -1776,8 +1776,7 @@ func TestImportExportKey(t *testing.T) { env.vm.ctx.Lock.Unlock() }() - factory := secp256k1.Factory{} - sk, err := factory.NewPrivateKey() + sk, err := secp256k1.NewPrivateKey() require.NoError(err) importArgs := &ImportKeyArgs{ @@ -1821,8 +1820,7 @@ func TestImportAVMKeyNoDuplicates(t *testing.T) { env.vm.ctx.Lock.Unlock() }() - factory := secp256k1.Factory{} - sk, err := factory.NewPrivateKey() + sk, err := secp256k1.NewPrivateKey() require.NoError(err) args := ImportKeyArgs{ UserPass: api.UserPass{ diff --git a/vms/components/keystore/user.go b/vms/components/keystore/user.go index 17c95c943555..561e2f52b819 100644 --- a/vms/components/keystore/user.go +++ b/vms/components/keystore/user.go @@ -43,8 +43,7 @@ type User interface { } type user struct { - factory secp256k1.Factory - db *encdb.Database + db *encdb.Database } // NewUserFromKeystore tracks a keystore user from the provided keystore @@ -125,7 +124,7 @@ func (u *user) GetKey(address ids.ShortID) (*secp256k1.PrivateKey, error) { if err != nil { return nil, err } - return u.factory.ToPrivateKey(bytes) + return secp256k1.ToPrivateKey(bytes) } func (u *user) Close() error { @@ -143,11 +142,9 @@ func NewKey(u User) (*secp256k1.PrivateKey, error) { // Create and store [numKeys] new keys that will be controlled by this user. func NewKeys(u User, numKeys int) ([]*secp256k1.PrivateKey, error) { - factory := secp256k1.Factory{} - keys := make([]*secp256k1.PrivateKey, numKeys) for i := range keys { - sk, err := factory.NewPrivateKey() + sk, err := secp256k1.NewPrivateKey() if err != nil { return nil, err } diff --git a/vms/components/keystore/user_test.go b/vms/components/keystore/user_test.go index a06c13a340a1..9f94cf03b7c6 100644 --- a/vms/components/keystore/user_test.go +++ b/vms/components/keystore/user_test.go @@ -37,8 +37,7 @@ func TestUserClosedDB(t *testing.T) { _, err = GetKeychain(u, nil) require.ErrorIs(err, database.ErrClosed) - factory := secp256k1.Factory{} - sk, err := factory.NewPrivateKey() + sk, err := secp256k1.NewPrivateKey() require.NoError(err) err = u.PutKeys(sk) @@ -57,8 +56,7 @@ func TestUser(t *testing.T) { require.NoError(err) require.Empty(addresses, "new user shouldn't have address") - factory := secp256k1.Factory{} - sk, err := factory.NewPrivateKey() + sk, err := secp256k1.NewPrivateKey() require.NoError(err) require.NoError(u.PutKeys(sk)) diff --git a/vms/example/xsvm/tx/tx.go b/vms/example/xsvm/tx/tx.go index 5ada3bf79129..fae58bae0806 100644 --- a/vms/example/xsvm/tx/tx.go +++ b/vms/example/xsvm/tx/tx.go @@ -10,8 +10,8 @@ import ( "github.com/ava-labs/avalanchego/utils/hashing" ) -var secp256k1r = secp256k1.Factory{ - Cache: cache.LRU[ids.ID, *secp256k1.PublicKey]{ +var secpCache = secp256k1.RecoverCache{ + LRU: cache.LRU[ids.ID, *secp256k1.PublicKey]{ Size: 2048, }, } @@ -56,7 +56,7 @@ func (tx *Tx) SenderID() (ids.ShortID, error) { return ids.ShortEmpty, err } - pk, err := secp256k1r.RecoverPublicKey(unsignedBytes, tx.Signature[:]) + pk, err := secpCache.RecoverPublicKey(unsignedBytes, tx.Signature[:]) if err != nil { return ids.ShortEmpty, err } diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 9a9dc3037287..880817414ea8 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -1143,8 +1143,7 @@ func TestBanffProposalBlockDelegatorStakers(t *testing.T) { // Add a pending validator pendingValidatorStartTime := defaultGenesisTime.Add(1 * time.Second) pendingValidatorEndTime := pendingValidatorStartTime.Add(defaultMinStakingDuration) - factory := secp256k1.Factory{} - nodeIDKey, _ := factory.NewPrivateKey() + nodeIDKey, _ := secp256k1.NewPrivateKey() rewardAddress := nodeIDKey.PublicKey().Address() nodeID := ids.NodeID(rewardAddress) diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 9836ec0a9b0a..2db9dc2fc6f4 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -99,7 +99,7 @@ func defaultAddress(t *testing.T, service *Service) { user, err := vmkeystore.NewUserFromKeystore(service.vm.ctx.Keystore, testUsername, testPassword) require.NoError(err) - pk, err := testKeyFactory.ToPrivateKey(testPrivateKey) + pk, err := secp256k1.ToPrivateKey(testPrivateKey) require.NoError(err) require.NoError(user.PutKeys(pk, keys[0])) @@ -176,8 +176,7 @@ func TestGetTxStatus(t *testing.T) { service.vm.ctx.Lock.Unlock() }() - factory := secp256k1.Factory{} - recipientKey, err := factory.NewPrivateKey() + recipientKey, err := secp256k1.NewPrivateKey() require.NoError(err) m := atomic.NewMemory(prefixdb.New([]byte{}, service.vm.dbManager.Current().Database)) diff --git a/vms/platformvm/txs/executor/create_chain_test.go b/vms/platformvm/txs/executor/create_chain_test.go index a8debf3b58bc..72315d3c4dd5 100644 --- a/vms/platformvm/txs/executor/create_chain_test.go +++ b/vms/platformvm/txs/executor/create_chain_test.go @@ -78,8 +78,7 @@ func TestCreateChainTxWrongControlSig(t *testing.T) { require.NoError(err) // Generate new, random key to sign tx with - factory := secp256k1.Factory{} - key, err := factory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(err) // Replace a valid signature with one from another key diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index 7d45f3b6c2fa..cf16196dba63 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -74,9 +74,6 @@ var ( testSubnet1 *txs.Tx testSubnet1ControlKeys = preFundedKeys[0:3] - // Used to create and use keys. - testKeyfactory secp256k1.Factory - errMissing = errors.New("missing") ) diff --git a/vms/platformvm/txs/executor/import_test.go b/vms/platformvm/txs/executor/import_test.go index 9cbe0a517ce9..3d78429cf906 100644 --- a/vms/platformvm/txs/executor/import_test.go +++ b/vms/platformvm/txs/executor/import_test.go @@ -36,8 +36,7 @@ func TestNewImportTx(t *testing.T) { expectedErr error } - factory := secp256k1.Factory{} - sourceKey, err := factory.NewPrivateKey() + sourceKey, err := secp256k1.NewPrivateKey() require.NoError(t, err) cnt := new(byte) diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index 4bebbb4105d9..0044d27a32ea 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -353,7 +353,7 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { } // Add a validator to pending validator set of primary network - key, err := testKeyfactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(err) pendingDSValidatorID := ids.NodeID(key.PublicKey().Address()) diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 5a9aaf73ed1d..5cfc420b1705 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -439,7 +439,7 @@ func TestStandardTxExecutorAddSubnetValidator(t *testing.T) { } // Add a validator to pending validator set of primary network - key, err := testKeyfactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(err) pendingDSValidatorID := ids.NodeID(key.PublicKey().Address()) diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 41e7eafbdfe8..83ac4fd71285 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -217,7 +217,7 @@ func TestAddDelegatorTxHeapCorruption(t *testing.T) { vm.ctx.Lock.Unlock() }() - key, err := testKeyFactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(err) id := key.PublicKey().Address() @@ -476,7 +476,7 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { newValidatorStartTime := vm.clock.Time().Add(executor.SyncBound).Add(1 * time.Second) newValidatorEndTime := newValidatorStartTime.Add(defaultMinStakingDuration) - key, err := testKeyFactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(err) nodeID := ids.NodeID(key.PublicKey().Address()) @@ -1153,7 +1153,7 @@ func TestAddDelegatorTxAddBeforeRemove(t *testing.T) { vm.ctx.Lock.Unlock() }() - key, err := testKeyFactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(err) id := key.PublicKey().Address() @@ -1237,7 +1237,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionNotTracked(t vm.ctx.Lock.Unlock() }() - key, err := testKeyFactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(err) id := key.PublicKey().Address() @@ -1354,7 +1354,7 @@ func TestRemovePermissionedValidatorDuringPendingToCurrentTransitionTracked(t *t vm.ctx.Lock.Unlock() }() - key, err := testKeyFactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(err) id := key.PublicKey().Address() diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 2db4146d05df..691a656af88e 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -116,9 +116,6 @@ var ( xChainID = ids.Empty.Prefix(0) cChainID = ids.Empty.Prefix(1) - // Used to create and use keys. - testKeyFactory secp256k1.Factory - errMissing = errors.New("missing") ) @@ -492,7 +489,7 @@ func TestInvalidAddValidatorCommit(t *testing.T) { startTime := defaultGenesisTime.Add(-txexecutor.SyncBound).Add(-1 * time.Second) endTime := startTime.Add(defaultMinStakingDuration) - key, _ := testKeyFactory.NewPrivateKey() + key, _ := secp256k1.NewPrivateKey() nodeID := ids.NodeID(key.PublicKey().Address()) // create invalid tx @@ -2035,7 +2032,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { vm.ctx.Lock.Unlock() }() - key, err := testKeyFactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(err) id := key.PublicKey().Address() diff --git a/vms/secp256k1fx/fx.go b/vms/secp256k1fx/fx.go index e8dc6bcd9db0..c969c9593976 100644 --- a/vms/secp256k1fx/fx.go +++ b/vms/secp256k1fx/fx.go @@ -40,8 +40,9 @@ var ( // Fx describes the secp256k1 feature extension type Fx struct { + secp256k1.RecoverCache + VM VM - SECPFactory secp256k1.Factory bootstrapped bool } @@ -53,8 +54,8 @@ func (fx *Fx) Initialize(vmIntf interface{}) error { log := fx.VM.Logger() log.Debug("initializing secp256k1 fx") - fx.SECPFactory = secp256k1.Factory{ - Cache: cache.LRU[ids.ID, *secp256k1.PublicKey]{ + fx.RecoverCache = secp256k1.RecoverCache{ + LRU: cache.LRU[ids.ID, *secp256k1.PublicKey]{ Size: defaultCacheSize, }, } @@ -200,7 +201,7 @@ func (fx *Fx) VerifyCredentials(utx UnsignedTx, in *Input, cred *Credential, out // Make sure each signature in the signature list is from an owner of // the output being consumed sig := cred.Sigs[i] - pk, err := fx.SECPFactory.RecoverHashPublicKey(txHash, sig[:]) + pk, err := fx.RecoverPublicKeyFromHash(txHash, sig[:]) if err != nil { return err } diff --git a/vms/secp256k1fx/keychain.go b/vms/secp256k1fx/keychain.go index 6d460378d697..3246ef95722d 100644 --- a/vms/secp256k1fx/keychain.go +++ b/vms/secp256k1fx/keychain.go @@ -27,7 +27,6 @@ var ( // Keychain is a collection of keys that can be used to spend outputs type Keychain struct { - factory *secp256k1.Factory avaxAddrToKeyIndex map[ids.ShortID]int ethAddrToKeyIndex map[common.Address]int @@ -41,7 +40,6 @@ type Keychain struct { // NewKeychain returns a new keychain containing [keys] func NewKeychain(keys ...*secp256k1.PrivateKey) *Keychain { kc := &Keychain{ - factory: &secp256k1.Factory{}, avaxAddrToKeyIndex: make(map[ids.ShortID]int), ethAddrToKeyIndex: make(map[common.Address]int), } @@ -90,7 +88,7 @@ func (kc Keychain) EthAddresses() set.Set[common.Address] { // New returns a newly generated private key func (kc *Keychain) New() (*secp256k1.PrivateKey, error) { - sk, err := kc.factory.NewPrivateKey() + sk, err := secp256k1.NewPrivateKey() if err != nil { return nil, err } diff --git a/vms/secp256k1fx/keychain_test.go b/vms/secp256k1fx/keychain_test.go index 888781378461..46fdb1a0695c 100644 --- a/vms/secp256k1fx/keychain_test.go +++ b/vms/secp256k1fx/keychain_test.go @@ -46,7 +46,7 @@ func TestKeychainAdd(t *testing.T) { skBytes, err := formatting.Decode(formatting.HexNC, keys[0]) require.NoError(err) - sk, err := kc.factory.ToPrivateKey(skBytes) + sk, err := secp256k1.ToPrivateKey(skBytes) require.NoError(err) kc.Add(sk) @@ -87,7 +87,7 @@ func TestKeychainMatch(t *testing.T) { skBytes, err := formatting.Decode(formatting.HexNC, keyStr) require.NoError(err) - sk, err := kc.factory.ToPrivateKey(skBytes) + sk, err := secp256k1.ToPrivateKey(skBytes) require.NoError(err) sks = append(sks, sk) } @@ -132,7 +132,7 @@ func TestKeychainSpendMint(t *testing.T) { skBytes, err := formatting.Decode(formatting.HexNC, keyStr) require.NoError(err) - sk, err := kc.factory.ToPrivateKey(skBytes) + sk, err := secp256k1.ToPrivateKey(skBytes) require.NoError(err) sks = append(sks, sk) } @@ -174,7 +174,7 @@ func TestKeychainSpendTransfer(t *testing.T) { skBytes, err := formatting.Decode(formatting.HexNC, keyStr) require.NoError(err) - sk, err := kc.factory.ToPrivateKey(skBytes) + sk, err := secp256k1.ToPrivateKey(skBytes) require.NoError(err) sks = append(sks, sk) } @@ -222,7 +222,7 @@ func TestKeychainString(t *testing.T) { skBytes, err := formatting.Decode(formatting.HexNC, keys[0]) require.NoError(err) - sk, err := kc.factory.ToPrivateKey(skBytes) + sk, err := secp256k1.ToPrivateKey(skBytes) require.NoError(err) kc.Add(sk) @@ -237,7 +237,7 @@ func TestKeychainPrefixedString(t *testing.T) { skBytes, err := formatting.Decode(formatting.HexNC, keys[0]) require.NoError(err) - sk, err := kc.factory.ToPrivateKey(skBytes) + sk, err := secp256k1.ToPrivateKey(skBytes) require.NoError(err) kc.Add(sk) From 826f9415f93c6cba04adb52767ad2e98777afba4 Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Fri, 27 Oct 2023 19:41:19 -0400 Subject: [PATCH 10/19] Fix test typos (#2233) Signed-off-by: marun Co-authored-by: marun --- vms/platformvm/txs/remove_subnet_validator_tx_test.go | 2 +- vms/platformvm/txs/transfer_subnet_ownership_tx_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vms/platformvm/txs/remove_subnet_validator_tx_test.go b/vms/platformvm/txs/remove_subnet_validator_tx_test.go index 02a9fdce7496..73f2df3cdcf2 100644 --- a/vms/platformvm/txs/remove_subnet_validator_tx_test.go +++ b/vms/platformvm/txs/remove_subnet_validator_tx_test.go @@ -263,7 +263,7 @@ func TestRemoveSubnetValidatorTxSerialization(t *testing.T) { } avax.SortTransferableOutputs(complexRemoveValidatorTx.Outs, Codec) utils.Sort(complexRemoveValidatorTx.Ins) - require.NoError(simpleRemoveValidatorTx.SyntacticVerify(&snow.Context{ + require.NoError(complexRemoveValidatorTx.SyntacticVerify(&snow.Context{ NetworkID: 1, ChainID: constants.PlatformChainID, AVAXAssetID: avaxAssetID, diff --git a/vms/platformvm/txs/transfer_subnet_ownership_tx_test.go b/vms/platformvm/txs/transfer_subnet_ownership_tx_test.go index 7e6f5835a283..e8cddeb3e1d0 100644 --- a/vms/platformvm/txs/transfer_subnet_ownership_tx_test.go +++ b/vms/platformvm/txs/transfer_subnet_ownership_tx_test.go @@ -103,7 +103,7 @@ func TestTransferSubnetOwnershipTxSerialization(t *testing.T) { expectedUnsignedSimpleTransferSubnetOwnershipTxBytes := []byte{ // Codec version 0x00, 0x00, - // RemoveSubnetValidatorTx Type ID + // TransferSubnetOwnershipTx Type ID 0x00, 0x00, 0x00, 0x21, // Mainnet network ID 0x00, 0x00, 0x00, 0x01, @@ -276,7 +276,7 @@ func TestTransferSubnetOwnershipTxSerialization(t *testing.T) { } avax.SortTransferableOutputs(complexTransferSubnetOwnershipTx.Outs, Codec) utils.Sort(complexTransferSubnetOwnershipTx.Ins) - require.NoError(simpleTransferSubnetOwnershipTx.SyntacticVerify(&snow.Context{ + require.NoError(complexTransferSubnetOwnershipTx.SyntacticVerify(&snow.Context{ NetworkID: 1, ChainID: constants.PlatformChainID, AVAXAssetID: avaxAssetID, From 5b9678936fb015d9ca838d67358235cc6fdf480c Mon Sep 17 00:00:00 2001 From: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> Date: Mon, 30 Oct 2023 16:41:51 -0400 Subject: [PATCH 11/19] P2P AppRequestFailed protobuf definition (#2111) Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> Co-authored-by: Stephen Buttolph --- proto/p2p/p2p.proto | 16 +- proto/pb/p2p/p2p.pb.go | 584 +++++++++++++++++++++++++---------------- 2 files changed, 367 insertions(+), 233 deletions(-) diff --git a/proto/p2p/p2p.proto b/proto/p2p/p2p.proto index 96f674f2fa74..9d355688bd49 100644 --- a/proto/p2p/p2p.proto +++ b/proto/p2p/p2p.proto @@ -58,6 +58,7 @@ message Message { AppGossip app_gossip = 32; PeerListAck peer_list_ack = 33; + AppRequestFailed app_request_failed = 34; } } @@ -385,7 +386,8 @@ message Chits { // AppRequest is a VM-defined request. // -// Remote peers must respond to AppRequest with corresponding AppResponse +// Remote peers must respond to AppRequest with a corresponding AppResponse or +// AppRequestFailed message AppRequest { // Chain being requested from bytes chain_id = 1; @@ -407,6 +409,18 @@ message AppResponse { bytes app_bytes = 3; } +// AppRequestFailed is a VM-defined error sent in response to AppRequest +message AppRequestFailed { + // Chain the message is for + bytes chain_id = 1; + // Request id of the original AppRequest + uint32 request_id = 2; + // VM defined error code + uint32 error_code = 3; + // VM defined error message + string error_message = 4; +} + // AppGossip is a VM-defined message message AppGossip { // Chain the message is for diff --git a/proto/pb/p2p/p2p.pb.go b/proto/pb/p2p/p2p.pb.go index 2a2bf8bb3137..89fb2e201520 100644 --- a/proto/pb/p2p/p2p.pb.go +++ b/proto/pb/p2p/p2p.pb.go @@ -109,6 +109,7 @@ type Message struct { // *Message_AppResponse // *Message_AppGossip // *Message_PeerListAck + // *Message_AppRequestFailed Message isMessage_Message `protobuf_oneof:"message"` } @@ -326,6 +327,13 @@ func (x *Message) GetPeerListAck() *PeerListAck { return nil } +func (x *Message) GetAppRequestFailed() *AppRequestFailed { + if x, ok := x.GetMessage().(*Message_AppRequestFailed); ok { + return x.AppRequestFailed + } + return nil +} + type isMessage_Message interface { isMessage_Message() } @@ -441,6 +449,10 @@ type Message_PeerListAck struct { PeerListAck *PeerListAck `protobuf:"bytes,33,opt,name=peer_list_ack,json=peerListAck,proto3,oneof"` } +type Message_AppRequestFailed struct { + AppRequestFailed *AppRequestFailed `protobuf:"bytes,34,opt,name=app_request_failed,json=appRequestFailed,proto3,oneof"` +} + func (*Message_CompressedGzip) isMessage_Message() {} func (*Message_CompressedZstd) isMessage_Message() {} @@ -491,6 +503,8 @@ func (*Message_AppGossip) isMessage_Message() {} func (*Message_PeerListAck) isMessage_Message() {} +func (*Message_AppRequestFailed) isMessage_Message() {} + // Ping reports a peer's perceived uptime percentage. // // Peers should respond to Ping with a Pong. @@ -2226,7 +2240,8 @@ func (x *Chits) GetPreferredIdAtHeight() []byte { // AppRequest is a VM-defined request. // -// Remote peers must respond to AppRequest with corresponding AppResponse +// Remote peers must respond to AppRequest with a corresponding AppResponse or +// AppRequestFailed type AppRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -2369,6 +2384,82 @@ func (x *AppResponse) GetAppBytes() []byte { return nil } +// AppRequestFailed is a VM-defined error sent in response to AppRequest +type AppRequestFailed struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Chain the message is for + ChainId []byte `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + // Request id of the original AppRequest + RequestId uint32 `protobuf:"varint,2,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"` + // VM defined error code + ErrorCode uint32 `protobuf:"varint,3,opt,name=error_code,json=errorCode,proto3" json:"error_code,omitempty"` + // VM defined error message + ErrorMessage string `protobuf:"bytes,4,opt,name=error_message,json=errorMessage,proto3" json:"error_message,omitempty"` +} + +func (x *AppRequestFailed) Reset() { + *x = AppRequestFailed{} + if protoimpl.UnsafeEnabled { + mi := &file_p2p_p2p_proto_msgTypes[26] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AppRequestFailed) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AppRequestFailed) ProtoMessage() {} + +func (x *AppRequestFailed) ProtoReflect() protoreflect.Message { + mi := &file_p2p_p2p_proto_msgTypes[26] + 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 AppRequestFailed.ProtoReflect.Descriptor instead. +func (*AppRequestFailed) Descriptor() ([]byte, []int) { + return file_p2p_p2p_proto_rawDescGZIP(), []int{26} +} + +func (x *AppRequestFailed) GetChainId() []byte { + if x != nil { + return x.ChainId + } + return nil +} + +func (x *AppRequestFailed) GetRequestId() uint32 { + if x != nil { + return x.RequestId + } + return 0 +} + +func (x *AppRequestFailed) GetErrorCode() uint32 { + if x != nil { + return x.ErrorCode + } + return 0 +} + +func (x *AppRequestFailed) GetErrorMessage() string { + if x != nil { + return x.ErrorMessage + } + return "" +} + // AppGossip is a VM-defined message type AppGossip struct { state protoimpl.MessageState @@ -2384,7 +2475,7 @@ type AppGossip struct { func (x *AppGossip) Reset() { *x = AppGossip{} if protoimpl.UnsafeEnabled { - mi := &file_p2p_p2p_proto_msgTypes[26] + mi := &file_p2p_p2p_proto_msgTypes[27] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2397,7 +2488,7 @@ func (x *AppGossip) String() string { func (*AppGossip) ProtoMessage() {} func (x *AppGossip) ProtoReflect() protoreflect.Message { - mi := &file_p2p_p2p_proto_msgTypes[26] + mi := &file_p2p_p2p_proto_msgTypes[27] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2410,7 +2501,7 @@ func (x *AppGossip) ProtoReflect() protoreflect.Message { // Deprecated: Use AppGossip.ProtoReflect.Descriptor instead. func (*AppGossip) Descriptor() ([]byte, []int) { - return file_p2p_p2p_proto_rawDescGZIP(), []int{26} + return file_p2p_p2p_proto_rawDescGZIP(), []int{27} } func (x *AppGossip) GetChainId() []byte { @@ -2431,7 +2522,7 @@ var File_p2p_p2p_proto protoreflect.FileDescriptor var file_p2p_p2p_proto_rawDesc = []byte{ 0x0a, 0x0d, 0x70, 0x32, 0x70, 0x2f, 0x70, 0x32, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, - 0x03, 0x70, 0x32, 0x70, 0x22, 0xde, 0x0a, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x03, 0x70, 0x32, 0x70, 0x22, 0xa5, 0x0b, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x29, 0x0a, 0x0f, 0x63, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x5f, 0x67, 0x7a, 0x69, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x0e, 0x63, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x47, 0x7a, 0x69, 0x70, 0x12, 0x29, 0x0a, 0x0f, 0x63, @@ -2516,236 +2607,250 @@ var file_p2p_p2p_proto_rawDesc = []byte{ 0x69, 0x70, 0x12, 0x36, 0x0a, 0x0d, 0x70, 0x65, 0x65, 0x72, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x5f, 0x61, 0x63, 0x6b, 0x18, 0x21, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x63, 0x6b, 0x48, 0x00, 0x52, 0x0b, 0x70, - 0x65, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x63, 0x6b, 0x42, 0x09, 0x0a, 0x07, 0x6d, 0x65, - 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x58, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x16, 0x0a, - 0x06, 0x75, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x75, - 0x70, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x38, 0x0a, 0x0e, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x5f, - 0x75, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, - 0x70, 0x32, 0x70, 0x2e, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x55, 0x70, 0x74, 0x69, 0x6d, 0x65, - 0x52, 0x0d, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x55, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x22, - 0x43, 0x0a, 0x0c, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x55, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x12, - 0x1b, 0x0a, 0x09, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x08, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, - 0x75, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x75, 0x70, - 0x74, 0x69, 0x6d, 0x65, 0x22, 0x58, 0x0a, 0x04, 0x50, 0x6f, 0x6e, 0x67, 0x12, 0x16, 0x0a, 0x06, - 0x75, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x75, 0x70, - 0x74, 0x69, 0x6d, 0x65, 0x12, 0x38, 0x0a, 0x0e, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x5f, 0x75, - 0x70, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x70, - 0x32, 0x70, 0x2e, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x55, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x52, - 0x0d, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x55, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x22, 0xf5, - 0x01, 0x0a, 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x6e, 0x65, - 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, - 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x6d, 0x79, 0x5f, - 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6d, 0x79, 0x54, 0x69, - 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x70, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x06, 0x69, 0x70, 0x41, 0x64, 0x64, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x69, - 0x70, 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x69, 0x70, - 0x50, 0x6f, 0x72, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x79, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, - 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6d, 0x79, 0x56, 0x65, 0x72, 0x73, - 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x0a, 0x0f, 0x6d, 0x79, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, - 0x6e, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x6d, 0x79, - 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, - 0x69, 0x67, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x73, 0x69, 0x67, 0x12, 0x27, 0x0a, - 0x0f, 0x74, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x64, 0x5f, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x73, - 0x18, 0x08, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0e, 0x74, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x64, 0x53, - 0x75, 0x62, 0x6e, 0x65, 0x74, 0x73, 0x22, 0xbd, 0x01, 0x0a, 0x0d, 0x43, 0x6c, 0x61, 0x69, 0x6d, - 0x65, 0x64, 0x49, 0x70, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x29, 0x0a, 0x10, 0x78, 0x35, 0x30, 0x39, - 0x5f, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x0f, 0x78, 0x35, 0x30, 0x39, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, - 0x61, 0x74, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x70, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x69, 0x70, 0x41, 0x64, 0x64, 0x72, 0x12, 0x17, 0x0a, 0x07, - 0x69, 0x70, 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x69, - 0x70, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, - 0x6d, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, - 0x61, 0x6d, 0x70, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, - 0x65, 0x12, 0x13, 0x0a, 0x05, 0x74, 0x78, 0x5f, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x04, 0x74, 0x78, 0x49, 0x64, 0x22, 0x48, 0x0a, 0x08, 0x50, 0x65, 0x65, 0x72, 0x4c, 0x69, - 0x73, 0x74, 0x12, 0x3c, 0x0a, 0x10, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x65, 0x64, 0x5f, 0x69, 0x70, - 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, - 0x32, 0x70, 0x2e, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x65, 0x64, 0x49, 0x70, 0x50, 0x6f, 0x72, 0x74, - 0x52, 0x0e, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x65, 0x64, 0x49, 0x70, 0x50, 0x6f, 0x72, 0x74, 0x73, - 0x22, 0x3c, 0x0a, 0x07, 0x50, 0x65, 0x65, 0x72, 0x41, 0x63, 0x6b, 0x12, 0x13, 0x0a, 0x05, 0x74, - 0x78, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x74, 0x78, 0x49, 0x64, - 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x3e, - 0x0a, 0x0b, 0x50, 0x65, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x63, 0x6b, 0x12, 0x29, 0x0a, - 0x09, 0x70, 0x65, 0x65, 0x72, 0x5f, 0x61, 0x63, 0x6b, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x0c, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x41, 0x63, 0x6b, 0x52, 0x08, - 0x70, 0x65, 0x65, 0x72, 0x41, 0x63, 0x6b, 0x73, 0x4a, 0x04, 0x08, 0x01, 0x10, 0x02, 0x22, 0x6f, - 0x0a, 0x17, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, - 0x79, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, + 0x65, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x63, 0x6b, 0x12, 0x45, 0x0a, 0x12, 0x61, 0x70, + 0x70, 0x5f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x65, 0x64, + 0x18, 0x22, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x41, 0x70, 0x70, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x48, 0x00, 0x52, + 0x10, 0x61, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x46, 0x61, 0x69, 0x6c, 0x65, + 0x64, 0x42, 0x09, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x58, 0x0a, 0x04, + 0x50, 0x69, 0x6e, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x75, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x38, 0x0a, 0x0e, + 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x5f, 0x75, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x18, 0x02, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x53, 0x75, 0x62, 0x6e, 0x65, + 0x74, 0x55, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x52, 0x0d, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x55, + 0x70, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x22, 0x43, 0x0a, 0x0c, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, + 0x55, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, + 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x73, 0x75, 0x62, 0x6e, 0x65, + 0x74, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x06, 0x75, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x22, 0x58, 0x0a, 0x04, 0x50, + 0x6f, 0x6e, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x06, 0x75, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x38, 0x0a, 0x0e, 0x73, + 0x75, 0x62, 0x6e, 0x65, 0x74, 0x5f, 0x75, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x18, 0x02, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, + 0x55, 0x70, 0x74, 0x69, 0x6d, 0x65, 0x52, 0x0d, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x55, 0x70, + 0x74, 0x69, 0x6d, 0x65, 0x73, 0x22, 0xf5, 0x01, 0x0a, 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, + 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x5f, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x49, 0x64, + 0x12, 0x17, 0x0a, 0x07, 0x6d, 0x79, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x04, 0x52, 0x06, 0x6d, 0x79, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x70, 0x5f, + 0x61, 0x64, 0x64, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x69, 0x70, 0x41, 0x64, + 0x64, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x70, 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x06, 0x69, 0x70, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, + 0x79, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x6d, 0x79, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x0a, 0x0f, 0x6d, 0x79, + 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x0d, 0x6d, 0x79, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x54, 0x69, + 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x67, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x03, 0x73, 0x69, 0x67, 0x12, 0x27, 0x0a, 0x0f, 0x74, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x64, 0x5f, + 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0e, 0x74, + 0x72, 0x61, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x73, 0x22, 0xbd, 0x01, + 0x0a, 0x0d, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x65, 0x64, 0x49, 0x70, 0x50, 0x6f, 0x72, 0x74, 0x12, + 0x29, 0x0a, 0x10, 0x78, 0x35, 0x30, 0x39, 0x5f, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, + 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0f, 0x78, 0x35, 0x30, 0x39, 0x43, + 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x70, + 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x69, 0x70, 0x41, + 0x64, 0x64, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x70, 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x69, 0x70, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x1c, 0x0a, 0x09, + 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, + 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, + 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, + 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x12, 0x13, 0x0a, 0x05, 0x74, 0x78, 0x5f, 0x69, + 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x74, 0x78, 0x49, 0x64, 0x22, 0x48, 0x0a, + 0x08, 0x50, 0x65, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x3c, 0x0a, 0x10, 0x63, 0x6c, 0x61, + 0x69, 0x6d, 0x65, 0x64, 0x5f, 0x69, 0x70, 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x65, + 0x64, 0x49, 0x70, 0x50, 0x6f, 0x72, 0x74, 0x52, 0x0e, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x65, 0x64, + 0x49, 0x70, 0x50, 0x6f, 0x72, 0x74, 0x73, 0x22, 0x3c, 0x0a, 0x07, 0x50, 0x65, 0x65, 0x72, 0x41, + 0x63, 0x6b, 0x12, 0x13, 0x0a, 0x05, 0x74, 0x78, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x04, 0x74, 0x78, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, + 0x74, 0x61, 0x6d, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, + 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x3e, 0x0a, 0x0b, 0x50, 0x65, 0x65, 0x72, 0x4c, 0x69, 0x73, + 0x74, 0x41, 0x63, 0x6b, 0x12, 0x29, 0x0a, 0x09, 0x70, 0x65, 0x65, 0x72, 0x5f, 0x61, 0x63, 0x6b, + 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x50, 0x65, + 0x65, 0x72, 0x41, 0x63, 0x6b, 0x52, 0x08, 0x70, 0x65, 0x65, 0x72, 0x41, 0x63, 0x6b, 0x73, 0x4a, + 0x04, 0x08, 0x01, 0x10, 0x02, 0x22, 0x6f, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, + 0x65, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, + 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, + 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, + 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, + 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x22, 0x6a, 0x0a, 0x14, 0x53, 0x74, 0x61, 0x74, 0x65, 0x53, + 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x12, 0x19, + 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x6d, 0x6d, + 0x61, 0x72, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x73, 0x75, 0x6d, 0x6d, 0x61, + 0x72, 0x79, 0x22, 0x89, 0x01, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, + 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x19, + 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, + 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, + 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x73, 0x18, + 0x04, 0x20, 0x03, 0x28, 0x04, 0x52, 0x07, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x73, 0x22, 0x71, + 0x0a, 0x14, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x53, + 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, + 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, + 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x73, 0x18, + 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0a, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x49, 0x64, + 0x73, 0x22, 0x9d, 0x01, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, + 0x64, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x22, - 0x6a, 0x0a, 0x14, 0x53, 0x74, 0x61, 0x74, 0x65, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x46, - 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, - 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, - 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, - 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x07, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x22, 0x89, 0x01, 0x0a, 0x17, - 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, - 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, + 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, + 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, + 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, + 0x65, 0x22, 0x75, 0x0a, 0x10, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x46, 0x72, 0x6f, + 0x6e, 0x74, 0x69, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, + 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, + 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x49, 0x64, 0x4a, 0x04, 0x08, 0x04, 0x10, 0x05, 0x22, 0xba, 0x01, 0x0a, 0x0b, 0x47, 0x65, 0x74, + 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, + 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, + 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, + 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x23, + 0x0a, 0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x73, 0x18, + 0x04, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x49, 0x64, 0x73, 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, + 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, + 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, + 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0x6f, 0x0a, 0x08, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, + 0x64, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, + 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, + 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x63, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, + 0x28, 0x0c, 0x52, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x73, + 0x4a, 0x04, 0x08, 0x04, 0x10, 0x05, 0x22, 0xb9, 0x01, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x41, 0x6e, + 0x63, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x18, 0x0a, - 0x07, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x04, 0x52, 0x07, - 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x73, 0x22, 0x71, 0x0a, 0x14, 0x41, 0x63, 0x63, 0x65, 0x70, - 0x74, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x12, + 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x21, 0x0a, + 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, + 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, + 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, + 0x70, 0x65, 0x22, 0x6b, 0x0a, 0x09, 0x41, 0x6e, 0x63, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, - 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x75, 0x6d, - 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0a, - 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x49, 0x64, 0x73, 0x22, 0x9d, 0x01, 0x0a, 0x13, 0x47, - 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, - 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, + 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0a, 0x63, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x4a, 0x04, 0x08, 0x04, 0x10, 0x05, 0x22, + 0xb0, 0x01, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, + 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, + 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, + 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x21, 0x0a, + 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, + 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, + 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, + 0x70, 0x65, 0x22, 0x8f, 0x01, 0x0a, 0x03, 0x50, 0x75, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, + 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, + 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, + 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, + 0x65, 0x72, 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, + 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, + 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, + 0x54, 0x79, 0x70, 0x65, 0x22, 0xdc, 0x01, 0x0a, 0x09, 0x50, 0x75, 0x73, 0x68, 0x51, 0x75, 0x65, + 0x72, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, - 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, - 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, - 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, - 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0x75, 0x0a, 0x10, 0x41, 0x63, - 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x12, 0x19, - 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, - 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, - 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x4a, 0x04, 0x08, 0x04, 0x10, - 0x05, 0x22, 0xba, 0x01, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, - 0x64, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x63, 0x6f, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, + 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x32, + 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x65, 0x6e, + 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x72, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x65, 0x64, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x06, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x0f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x48, 0x65, 0x69, + 0x67, 0x68, 0x74, 0x22, 0xe1, 0x01, 0x0a, 0x09, 0x50, 0x75, 0x6c, 0x6c, 0x51, 0x75, 0x65, 0x72, + 0x79, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, - 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x61, - 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0c, - 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x73, 0x12, 0x30, 0x0a, 0x0b, - 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, - 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, - 0x70, 0x65, 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0x6f, - 0x0a, 0x08, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, - 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, - 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, - 0x72, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0c, 0x63, 0x6f, 0x6e, - 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x73, 0x4a, 0x04, 0x08, 0x04, 0x10, 0x05, 0x22, - 0xb9, 0x01, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x41, 0x6e, 0x63, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x73, - 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, - 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, - 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, - 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, - 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, - 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, - 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, - 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0x6b, 0x0a, 0x09, 0x41, - 0x6e, 0x63, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, - 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, - 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, - 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, - 0x18, 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, - 0x72, 0x73, 0x4a, 0x04, 0x08, 0x04, 0x10, 0x05, 0x22, 0xb0, 0x01, 0x0a, 0x03, 0x47, 0x65, 0x74, + 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, + 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, + 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, + 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x29, 0x0a, 0x10, + 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, + 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x65, + 0x64, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0xba, 0x01, 0x0a, 0x05, 0x43, 0x68, 0x69, 0x74, + 0x73, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, + 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, + 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, 0x70, + 0x72, 0x65, 0x66, 0x65, 0x72, 0x72, 0x65, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x0b, 0x70, 0x72, 0x65, 0x66, 0x65, 0x72, 0x72, 0x65, 0x64, 0x49, 0x64, 0x12, 0x1f, + 0x0a, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x49, 0x64, 0x12, + 0x33, 0x0a, 0x16, 0x70, 0x72, 0x65, 0x66, 0x65, 0x72, 0x72, 0x65, 0x64, 0x5f, 0x69, 0x64, 0x5f, + 0x61, 0x74, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x13, 0x70, 0x72, 0x65, 0x66, 0x65, 0x72, 0x72, 0x65, 0x64, 0x49, 0x64, 0x41, 0x74, 0x48, 0x65, + 0x69, 0x67, 0x68, 0x74, 0x22, 0x7f, 0x0a, 0x0a, 0x41, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, + 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, + 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, + 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x70, 0x70, 0x5f, + 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x61, 0x70, 0x70, + 0x42, 0x79, 0x74, 0x65, 0x73, 0x22, 0x64, 0x0a, 0x0b, 0x41, 0x70, 0x70, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, + 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1b, + 0x0a, 0x09, 0x61, 0x70, 0x70, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x08, 0x61, 0x70, 0x70, 0x42, 0x79, 0x74, 0x65, 0x73, 0x22, 0x90, 0x01, 0x0a, 0x10, + 0x41, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, - 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, - 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, - 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, - 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, - 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, - 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, - 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0x8f, 0x01, 0x0a, 0x03, - 0x50, 0x75, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, - 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, - 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x0b, 0x65, - 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, - 0x32, 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, - 0x65, 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0xdc, 0x01, - 0x0a, 0x09, 0x50, 0x75, 0x73, 0x68, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x63, + 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x72, + 0x72, 0x6f, 0x72, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, + 0x65, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x72, 0x72, + 0x6f, 0x72, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x43, + 0x0a, 0x09, 0x41, 0x70, 0x70, 0x47, 0x6f, 0x73, 0x73, 0x69, 0x70, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, - 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, - 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, - 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x12, - 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, - 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, - 0x65, 0x12, 0x29, 0x0a, 0x10, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x5f, 0x68, - 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x72, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0xe1, 0x01, 0x0a, - 0x09, 0x50, 0x75, 0x6c, 0x6c, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, - 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, - 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, - 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, - 0x72, 0x49, 0x64, 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, - 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, - 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, - 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x65, 0x64, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, - 0x0f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, - 0x22, 0xba, 0x01, 0x0a, 0x05, 0x43, 0x68, 0x69, 0x74, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, - 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, - 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, 0x70, 0x72, 0x65, 0x66, 0x65, 0x72, 0x72, 0x65, - 0x64, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x70, 0x72, 0x65, 0x66, - 0x65, 0x72, 0x72, 0x65, 0x64, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x70, - 0x74, 0x65, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x61, 0x63, - 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x49, 0x64, 0x12, 0x33, 0x0a, 0x16, 0x70, 0x72, 0x65, 0x66, - 0x65, 0x72, 0x72, 0x65, 0x64, 0x5f, 0x69, 0x64, 0x5f, 0x61, 0x74, 0x5f, 0x68, 0x65, 0x69, 0x67, - 0x68, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x13, 0x70, 0x72, 0x65, 0x66, 0x65, 0x72, - 0x72, 0x65, 0x64, 0x49, 0x64, 0x41, 0x74, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0x7f, 0x0a, - 0x0a, 0x41, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x63, - 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, - 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, - 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, - 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x70, 0x70, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x61, 0x70, 0x70, 0x42, 0x79, 0x74, 0x65, 0x73, 0x22, 0x64, - 0x0a, 0x0b, 0x41, 0x70, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, - 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x70, 0x70, 0x5f, 0x62, - 0x79, 0x74, 0x65, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x61, 0x70, 0x70, 0x42, - 0x79, 0x74, 0x65, 0x73, 0x22, 0x43, 0x0a, 0x09, 0x41, 0x70, 0x70, 0x47, 0x6f, 0x73, 0x73, 0x69, - 0x70, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, - 0x61, 0x70, 0x70, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x08, 0x61, 0x70, 0x70, 0x42, 0x79, 0x74, 0x65, 0x73, 0x2a, 0x5d, 0x0a, 0x0a, 0x45, 0x6e, 0x67, - 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1b, 0x0a, 0x17, 0x45, 0x4e, 0x47, 0x49, 0x4e, - 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, - 0x45, 0x44, 0x10, 0x00, 0x12, 0x19, 0x0a, 0x15, 0x45, 0x4e, 0x47, 0x49, 0x4e, 0x45, 0x5f, 0x54, - 0x59, 0x50, 0x45, 0x5f, 0x41, 0x56, 0x41, 0x4c, 0x41, 0x4e, 0x43, 0x48, 0x45, 0x10, 0x01, 0x12, - 0x17, 0x0a, 0x13, 0x45, 0x4e, 0x47, 0x49, 0x4e, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x53, - 0x4e, 0x4f, 0x57, 0x4d, 0x41, 0x4e, 0x10, 0x02, 0x42, 0x2e, 0x5a, 0x2c, 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, 0x70, 0x32, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x70, 0x70, 0x5f, 0x62, 0x79, + 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x61, 0x70, 0x70, 0x42, 0x79, + 0x74, 0x65, 0x73, 0x2a, 0x5d, 0x0a, 0x0a, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x1b, 0x0a, 0x17, 0x45, 0x4e, 0x47, 0x49, 0x4e, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, + 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x19, + 0x0a, 0x15, 0x45, 0x4e, 0x47, 0x49, 0x4e, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x41, 0x56, + 0x41, 0x4c, 0x41, 0x4e, 0x43, 0x48, 0x45, 0x10, 0x01, 0x12, 0x17, 0x0a, 0x13, 0x45, 0x4e, 0x47, + 0x49, 0x4e, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x53, 0x4e, 0x4f, 0x57, 0x4d, 0x41, 0x4e, + 0x10, 0x02, 0x42, 0x2e, 0x5a, 0x2c, 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, 0x70, + 0x32, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -2761,7 +2866,7 @@ func file_p2p_p2p_proto_rawDescGZIP() []byte { } var file_p2p_p2p_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_p2p_p2p_proto_msgTypes = make([]protoimpl.MessageInfo, 27) +var file_p2p_p2p_proto_msgTypes = make([]protoimpl.MessageInfo, 28) var file_p2p_p2p_proto_goTypes = []interface{}{ (EngineType)(0), // 0: p2p.EngineType (*Message)(nil), // 1: p2p.Message @@ -2790,7 +2895,8 @@ var file_p2p_p2p_proto_goTypes = []interface{}{ (*Chits)(nil), // 24: p2p.Chits (*AppRequest)(nil), // 25: p2p.AppRequest (*AppResponse)(nil), // 26: p2p.AppResponse - (*AppGossip)(nil), // 27: p2p.AppGossip + (*AppRequestFailed)(nil), // 27: p2p.AppRequestFailed + (*AppGossip)(nil), // 28: p2p.AppGossip } var file_p2p_p2p_proto_depIdxs = []int32{ 2, // 0: p2p.Message.ping:type_name -> p2p.Ping @@ -2814,24 +2920,25 @@ var file_p2p_p2p_proto_depIdxs = []int32{ 24, // 18: p2p.Message.chits:type_name -> p2p.Chits 25, // 19: p2p.Message.app_request:type_name -> p2p.AppRequest 26, // 20: p2p.Message.app_response:type_name -> p2p.AppResponse - 27, // 21: p2p.Message.app_gossip:type_name -> p2p.AppGossip + 28, // 21: p2p.Message.app_gossip:type_name -> p2p.AppGossip 9, // 22: p2p.Message.peer_list_ack:type_name -> p2p.PeerListAck - 3, // 23: p2p.Ping.subnet_uptimes:type_name -> p2p.SubnetUptime - 3, // 24: p2p.Pong.subnet_uptimes:type_name -> p2p.SubnetUptime - 6, // 25: p2p.PeerList.claimed_ip_ports:type_name -> p2p.ClaimedIpPort - 8, // 26: p2p.PeerListAck.peer_acks:type_name -> p2p.PeerAck - 0, // 27: p2p.GetAcceptedFrontier.engine_type:type_name -> p2p.EngineType - 0, // 28: p2p.GetAccepted.engine_type:type_name -> p2p.EngineType - 0, // 29: p2p.GetAncestors.engine_type:type_name -> p2p.EngineType - 0, // 30: p2p.Get.engine_type:type_name -> p2p.EngineType - 0, // 31: p2p.Put.engine_type:type_name -> p2p.EngineType - 0, // 32: p2p.PushQuery.engine_type:type_name -> p2p.EngineType - 0, // 33: p2p.PullQuery.engine_type:type_name -> p2p.EngineType - 34, // [34:34] is the sub-list for method output_type - 34, // [34:34] 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 + 27, // 23: p2p.Message.app_request_failed:type_name -> p2p.AppRequestFailed + 3, // 24: p2p.Ping.subnet_uptimes:type_name -> p2p.SubnetUptime + 3, // 25: p2p.Pong.subnet_uptimes:type_name -> p2p.SubnetUptime + 6, // 26: p2p.PeerList.claimed_ip_ports:type_name -> p2p.ClaimedIpPort + 8, // 27: p2p.PeerListAck.peer_acks:type_name -> p2p.PeerAck + 0, // 28: p2p.GetAcceptedFrontier.engine_type:type_name -> p2p.EngineType + 0, // 29: p2p.GetAccepted.engine_type:type_name -> p2p.EngineType + 0, // 30: p2p.GetAncestors.engine_type:type_name -> p2p.EngineType + 0, // 31: p2p.Get.engine_type:type_name -> p2p.EngineType + 0, // 32: p2p.Put.engine_type:type_name -> p2p.EngineType + 0, // 33: p2p.PushQuery.engine_type:type_name -> p2p.EngineType + 0, // 34: p2p.PullQuery.engine_type:type_name -> p2p.EngineType + 35, // [35:35] is the sub-list for method output_type + 35, // [35:35] is the sub-list for method input_type + 35, // [35:35] is the sub-list for extension type_name + 35, // [35:35] is the sub-list for extension extendee + 0, // [0:35] is the sub-list for field type_name } func init() { file_p2p_p2p_proto_init() } @@ -3153,6 +3260,18 @@ func file_p2p_p2p_proto_init() { } } file_p2p_p2p_proto_msgTypes[26].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AppRequestFailed); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_p2p_p2p_proto_msgTypes[27].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*AppGossip); i { case 0: return &v.state @@ -3191,6 +3310,7 @@ func file_p2p_p2p_proto_init() { (*Message_AppResponse)(nil), (*Message_AppGossip)(nil), (*Message_PeerListAck)(nil), + (*Message_AppRequestFailed)(nil), } type x struct{} out := protoimpl.TypeBuilder{ @@ -3198,7 +3318,7 @@ func file_p2p_p2p_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_p2p_p2p_proto_rawDesc, NumEnums: 1, - NumMessages: 27, + NumMessages: 28, NumExtensions: 0, NumServices: 0, }, From 76d756ff6b6b919f90b80fe61d10643a56bf6a1b Mon Sep 17 00:00:00 2001 From: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:43:13 -0400 Subject: [PATCH 12/19] Remove error from Router AppGossip (#2238) Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> --- network/p2p/handler.go | 6 ++---- network/p2p/router.go | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/network/p2p/handler.go b/network/p2p/handler.go index 9212864e5436..790893142087 100644 --- a/network/p2p/handler.go +++ b/network/p2p/handler.go @@ -111,9 +111,8 @@ func (r *responder) AppRequest(ctx context.Context, nodeID ids.NodeID, requestID return r.sender.SendAppResponse(ctx, nodeID, requestID, appResponse) } -func (r *responder) AppGossip(ctx context.Context, nodeID ids.NodeID, msg []byte) error { - err := r.handler.AppGossip(ctx, nodeID, msg) - if err != nil { +func (r *responder) AppGossip(ctx context.Context, nodeID ids.NodeID, msg []byte) { + if err := r.handler.AppGossip(ctx, nodeID, msg); err != nil { r.log.Debug("failed to handle message", zap.Stringer("messageOp", message.AppGossipOp), zap.Stringer("nodeID", nodeID), @@ -121,7 +120,6 @@ func (r *responder) AppGossip(ctx context.Context, nodeID ids.NodeID, msg []byte zap.Binary("message", msg), ) } - return nil } func (r *responder) CrossChainAppRequest(ctx context.Context, chainID ids.ID, requestID uint32, deadline time.Time, request []byte) error { diff --git a/network/p2p/router.go b/network/p2p/router.go index bd1f334cda7c..1da66a7d2d4e 100644 --- a/network/p2p/router.go +++ b/network/p2p/router.go @@ -256,9 +256,7 @@ func (r *Router) AppGossip(ctx context.Context, nodeID ids.NodeID, gossip []byte return nil } - if err := handler.AppGossip(ctx, nodeID, parsedMsg); err != nil { - return err - } + handler.AppGossip(ctx, nodeID, parsedMsg) handler.metrics.appGossipTime.Observe(float64(time.Since(start))) return nil From 8d15c2294ea872569ab3669a7100ad7e81fea7b4 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Tue, 31 Oct 2023 13:28:49 -0400 Subject: [PATCH 13/19] Document host and port behavior in help text (#2236) --- config/flags.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/flags.go b/config/flags.go index 254d70fea2dd..67fe339db887 100644 --- a/config/flags.go +++ b/config/flags.go @@ -204,8 +204,8 @@ func addNodeFlags(fs *pflag.FlagSet) { fs.Uint64(OutboundThrottlerNodeMaxAtLargeBytesKey, constants.DefaultOutboundThrottlerNodeMaxAtLargeBytes, "Max number of bytes a node can take from the outbound message throttler's at-large allocation. Must be at least the max message size") // HTTP APIs - fs.String(HTTPHostKey, "127.0.0.1", "Address of the HTTP server") - fs.Uint(HTTPPortKey, DefaultHTTPPort, "Port of the HTTP server") + fs.String(HTTPHostKey, "127.0.0.1", "Address of the HTTP server. If the address is empty or a literal unspecified IP address, the server will bind on all available unicast and anycast IP addresses of the local system") + fs.Uint(HTTPPortKey, DefaultHTTPPort, "Port of the HTTP server. If the port is 0 a port number is automatically chosen") fs.Bool(HTTPSEnabledKey, false, "Upgrade the HTTP server to HTTPs") fs.String(HTTPSKeyFileKey, "", fmt.Sprintf("TLS private key file for the HTTPs server. Ignored if %s is specified", HTTPSKeyContentKey)) fs.String(HTTPSKeyContentKey, "", "Specifies base64 encoded TLS private key for the HTTPs server") @@ -248,8 +248,8 @@ func addNodeFlags(fs *pflag.FlagSet) { fs.Duration(NetworkHealthMaxOutstandingDurationKey, 5*time.Minute, "Node reports unhealthy if there has been a request outstanding for this duration") // Staking - fs.String(StakingHostKey, "", "Address of the consensus server") // Bind to all interfaces by default. - fs.Uint(StakingPortKey, DefaultStakingPort, "Port of the consensus server") + fs.String(StakingHostKey, "", "Address of the consensus server. If the address is empty or a literal unspecified IP address, the server will bind on all available unicast and anycast IP addresses of the local system") // Bind to all interfaces by default. + fs.Uint(StakingPortKey, DefaultStakingPort, "Port of the consensus server. If the port is 0 a port number is automatically chosen") fs.Bool(StakingEphemeralCertEnabledKey, false, "If true, the node uses an ephemeral staking TLS key and certificate, and has an ephemeral node ID") fs.String(StakingTLSKeyPathKey, defaultStakingTLSKeyPath, fmt.Sprintf("Path to the TLS private key for staking. Ignored if %s is specified", StakingTLSKeyContentKey)) fs.String(StakingTLSKeyContentKey, "", "Specifies base64 encoded TLS private key for staking") From 1f9df8f40543043a8024c09e196b3d92ec4df971 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 31 Oct 2023 17:10:05 -0400 Subject: [PATCH 14/19] Remove `database.Manager` (#2239) Signed-off-by: Dan Laine --- api/keystore/keystore.go | 8 +- api/keystore/service.go | 17 - api/keystore/service_test.go | 36 +- chains/linearizable_vm.go | 9 +- chains/manager.go | 37 +- database/manager/manager.go | 325 -------- database/manager/manager_test.go | 429 ---------- database/manager/versioned_database.go | 27 - go.mod | 2 +- go.sum | 4 +- node/node.go | 52 +- proto/pb/vm/vm.pb.go | 763 ++++++++---------- proto/vm/vm.proto | 9 +- snow/engine/avalanche/vertex/mock_vm.go | 4 +- snow/engine/common/test_vm.go | 6 +- snow/engine/common/vm.go | 4 +- snow/engine/snowman/block/mocks/chain_vm.go | 4 +- vms/avm/block/builder/builder_test.go | 6 +- vms/avm/environment_test.go | 14 +- .../txs/executor/semantic_verifier_test.go | 6 +- vms/avm/vm.go | 4 +- vms/avm/vm_test.go | 43 +- vms/example/xsvm/vm.go | 6 +- vms/metervm/block_vm.go | 4 +- vms/metervm/vertex_vm.go | 4 +- vms/platformvm/block/builder/helpers_test.go | 6 +- vms/platformvm/block/executor/helpers_test.go | 6 +- vms/platformvm/service_test.go | 7 +- vms/platformvm/txs/executor/helpers_test.go | 6 +- vms/platformvm/validator_set_property_test.go | 11 +- vms/platformvm/vm.go | 16 +- vms/platformvm/vm_regression_test.go | 13 +- vms/platformvm/vm_test.go | 44 +- vms/proposervm/batched_vm_test.go | 12 +- vms/proposervm/post_fork_option_test.go | 3 +- vms/proposervm/state_syncable_vm_test.go | 13 +- vms/proposervm/vm.go | 9 +- vms/proposervm/vm_regression_test.go | 11 +- vms/proposervm/vm_test.go | 64 +- vms/rpcchainvm/batched_vm_test.go | 6 +- vms/rpcchainvm/state_syncable_vm_test.go | 8 +- vms/rpcchainvm/vm_client.go | 39 +- vms/rpcchainvm/vm_server.go | 65 +- vms/rpcchainvm/with_context_vm_test.go | 6 +- vms/tracedvm/block_vm.go | 4 +- vms/tracedvm/vertex_vm.go | 4 +- 46 files changed, 586 insertions(+), 1590 deletions(-) delete mode 100644 database/manager/manager.go delete mode 100644 database/manager/manager_test.go delete mode 100644 database/manager/versioned_database.go diff --git a/api/keystore/keystore.go b/api/keystore/keystore.go index fe3bee0e9dc0..cd7f0b8a8f21 100644 --- a/api/keystore/keystore.go +++ b/api/keystore/keystore.go @@ -14,7 +14,6 @@ import ( "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/database/encdb" - "github.com/ava-labs/avalanchego/database/manager" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/json" @@ -105,13 +104,12 @@ type keystore struct { bcDB database.Database } -func New(log logging.Logger, dbManager manager.Manager) Keystore { - currentDB := dbManager.Current() +func New(log logging.Logger, db database.Database) Keystore { return &keystore{ log: log, usernameToPassword: make(map[string]*password.Hash), - userDB: prefixdb.New(usersPrefix, currentDB.Database), - bcDB: prefixdb.New(bcsPrefix, currentDB.Database), + userDB: prefixdb.New(usersPrefix, db), + bcDB: prefixdb.New(bcsPrefix, db), } } diff --git a/api/keystore/service.go b/api/keystore/service.go index c0e823c22e7f..d4c845743bbb 100644 --- a/api/keystore/service.go +++ b/api/keystore/service.go @@ -10,11 +10,8 @@ import ( "go.uber.org/zap" "github.com/ava-labs/avalanchego/api" - "github.com/ava-labs/avalanchego/database/manager" - "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/utils/formatting" "github.com/ava-labs/avalanchego/utils/logging" - "github.com/ava-labs/avalanchego/version" ) type service struct { @@ -115,17 +112,3 @@ func (s *service) ExportUser(_ *http.Request, args *ExportUserArgs, reply *Expor reply.Encoding = args.Encoding return nil } - -// CreateTestKeystore returns a new keystore that can be utilized for testing -func CreateTestKeystore() (Keystore, error) { - dbManager, err := manager.NewManagerFromDBs([]*manager.VersionedDatabase{ - { - Database: memdb.New(), - Version: version.Semantic1_0_0, - }, - }) - if err != nil { - return nil, err - } - return New(logging.NoLog{}, dbManager), nil -} diff --git a/api/keystore/service_test.go b/api/keystore/service_test.go index 0a3eef5687a4..842ab7d76cc7 100644 --- a/api/keystore/service_test.go +++ b/api/keystore/service_test.go @@ -11,8 +11,10 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/api" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/formatting" + "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/password" ) @@ -23,8 +25,7 @@ var strongPassword = "N_+=_jJ;^(<;{4,:*m6CET}'&N;83FYK.wtNpwp-Jt" // #nosec G101 func TestServiceListNoUsers(t *testing.T) { require := require.New(t) - ks, err := CreateTestKeystore() - require.NoError(err) + ks := New(logging.NoLog{}, memdb.New()) s := service{ks: ks.(*keystore)} reply := ListUsersReply{} @@ -35,8 +36,7 @@ func TestServiceListNoUsers(t *testing.T) { func TestServiceCreateUser(t *testing.T) { require := require.New(t) - ks, err := CreateTestKeystore() - require.NoError(err) + ks := New(logging.NoLog{}, memdb.New()) s := service{ks: ks.(*keystore)} { @@ -66,8 +66,7 @@ func genStr(n int) string { func TestServiceCreateUserArgsCheck(t *testing.T) { require := require.New(t) - ks, err := CreateTestKeystore() - require.NoError(err) + ks := New(logging.NoLog{}, memdb.New()) s := service{ks: ks.(*keystore)} { @@ -100,8 +99,7 @@ func TestServiceCreateUserArgsCheck(t *testing.T) { func TestServiceCreateUserWeakPassword(t *testing.T) { require := require.New(t) - ks, err := CreateTestKeystore() - require.NoError(err) + ks := New(logging.NoLog{}, memdb.New()) s := service{ks: ks.(*keystore)} { @@ -117,8 +115,7 @@ func TestServiceCreateUserWeakPassword(t *testing.T) { func TestServiceCreateDuplicate(t *testing.T) { require := require.New(t) - ks, err := CreateTestKeystore() - require.NoError(err) + ks := New(logging.NoLog{}, memdb.New()) s := service{ks: ks.(*keystore)} { @@ -140,12 +137,11 @@ func TestServiceCreateDuplicate(t *testing.T) { func TestServiceCreateUserNoName(t *testing.T) { require := require.New(t) - ks, err := CreateTestKeystore() - require.NoError(err) + ks := New(logging.NoLog{}, memdb.New()) s := service{ks: ks.(*keystore)} reply := api.EmptyReply{} - err = s.CreateUser(nil, &api.UserPass{ + err := s.CreateUser(nil, &api.UserPass{ Password: strongPassword, }, &reply) require.ErrorIs(err, errEmptyUsername) @@ -154,8 +150,7 @@ func TestServiceCreateUserNoName(t *testing.T) { func TestServiceUseBlockchainDB(t *testing.T) { require := require.New(t) - ks, err := CreateTestKeystore() - require.NoError(err) + ks := New(logging.NoLog{}, memdb.New()) s := service{ks: ks.(*keystore)} { @@ -185,8 +180,7 @@ func TestServiceExportImport(t *testing.T) { encodings := []formatting.Encoding{formatting.Hex} for _, encoding := range encodings { - ks, err := CreateTestKeystore() - require.NoError(err) + ks := New(logging.NoLog{}, memdb.New()) s := service{ks: ks.(*keystore)} { @@ -212,8 +206,7 @@ func TestServiceExportImport(t *testing.T) { exportReply := ExportUserReply{} require.NoError(s.ExportUser(nil, &exportArgs, &exportReply)) - newKS, err := CreateTestKeystore() - require.NoError(err) + newKS := New(logging.NoLog{}, memdb.New()) newS := service{ks: newKS.(*keystore)} { @@ -324,8 +317,7 @@ func TestServiceDeleteUser(t *testing.T) { t.Run(tt.desc, func(t *testing.T) { require := require.New(t) - ksIntf, err := CreateTestKeystore() - require.NoError(err) + ksIntf := New(logging.NoLog{}, memdb.New()) ks := ksIntf.(*keystore) s := service{ks: ks} @@ -333,7 +325,7 @@ func TestServiceDeleteUser(t *testing.T) { require.NoError(tt.setup(ks)) } got := &api.EmptyReply{} - err = s.DeleteUser(nil, tt.request, got) + err := s.DeleteUser(nil, tt.request, got) require.ErrorIs(err, tt.expectedErr) if tt.expectedErr != nil { return diff --git a/chains/linearizable_vm.go b/chains/linearizable_vm.go index ebe2652cfb1d..f4fc93f7a696 100644 --- a/chains/linearizable_vm.go +++ b/chains/linearizable_vm.go @@ -7,13 +7,12 @@ import ( "context" "github.com/ava-labs/avalanchego/api/metrics" + "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" - - dbManager "github.com/ava-labs/avalanchego/database/manager" ) var ( @@ -32,7 +31,7 @@ type initializeOnLinearizeVM struct { registerer metrics.OptionalGatherer ctx *snow.Context - dbManager dbManager.Manager + db database.Database genesisBytes []byte upgradeBytes []byte configBytes []byte @@ -47,7 +46,7 @@ func (vm *initializeOnLinearizeVM) Linearize(ctx context.Context, stopVertexID i return vm.vmToInitialize.Initialize( ctx, vm.ctx, - vm.dbManager, + vm.db, vm.genesisBytes, vm.upgradeBytes, vm.configBytes, @@ -74,7 +73,7 @@ func NewLinearizeOnInitializeVM(vm vertex.LinearizableVMWithEngine) *linearizeOn func (vm *linearizeOnInitializeVM) Initialize( ctx context.Context, _ *snow.Context, - _ dbManager.Manager, + _ database.Database, _ []byte, _ []byte, _ []byte, diff --git a/chains/manager.go b/chains/manager.go index 2234e82aadcc..85472e424222 100644 --- a/chains/manager.go +++ b/chains/manager.go @@ -23,6 +23,8 @@ import ( "github.com/ava-labs/avalanchego/api/metrics" "github.com/ava-labs/avalanchego/api/server" "github.com/ava-labs/avalanchego/chains/atomic" + "github.com/ava-labs/avalanchego/database" + "github.com/ava-labs/avalanchego/database/meterdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/message" @@ -57,7 +59,6 @@ import ( "github.com/ava-labs/avalanchego/vms/proposervm" "github.com/ava-labs/avalanchego/vms/tracedvm" - dbManager "github.com/ava-labs/avalanchego/database/manager" timetracker "github.com/ava-labs/avalanchego/snow/networking/tracker" aveng "github.com/ava-labs/avalanchego/snow/engine/avalanche" @@ -180,7 +181,7 @@ type ManagerConfig struct { BlockAcceptorGroup snow.AcceptorGroup TxAcceptorGroup snow.AcceptorGroup VertexAcceptorGroup snow.AcceptorGroup - DBManager dbManager.Manager + DB database.Database MsgCreator message.OutboundMsgBuilder // message creator, shared with network Router router.Router // Routes incoming messages to the appropriate chain Net network.Network // Sends consensus messages to other validators @@ -596,18 +597,16 @@ func (m *manager) createAvalancheChain( State: snow.Initializing, }) - meterDBManager, err := m.DBManager.NewMeterDBManager("db", ctx.Registerer) + meterDB, err := meterdb.New("db", ctx.Registerer, m.DB) if err != nil { return nil, err } - prefixDBManager := meterDBManager.NewPrefixDBManager(ctx.ChainID[:]) - vmDBManager := prefixDBManager.NewPrefixDBManager(vmDBPrefix) - - db := prefixDBManager.Current() - vertexDB := prefixdb.New(vertexDBPrefix, db.Database) - vertexBootstrappingDB := prefixdb.New(vertexBootstrappingDBPrefix, db.Database) - txBootstrappingDB := prefixdb.New(txBootstrappingDBPrefix, db.Database) - blockBootstrappingDB := prefixdb.New(blockBootstrappingDBPrefix, db.Database) + prefixDB := prefixdb.New(ctx.ChainID[:], meterDB) + vmDB := prefixdb.New(vmDBPrefix, prefixDB) + vertexDB := prefixdb.New(vertexDBPrefix, prefixDB) + vertexBootstrappingDB := prefixdb.New(vertexBootstrappingDBPrefix, prefixDB) + txBootstrappingDB := prefixdb.New(txBootstrappingDBPrefix, prefixDB) + blockBootstrappingDB := prefixdb.New(blockBootstrappingDBPrefix, prefixDB) vtxBlocker, err := queue.NewWithMissing(vertexBootstrappingDB, "vtx", ctx.AvalancheRegisterer) if err != nil { @@ -730,7 +729,7 @@ func (m *manager) createAvalancheChain( err = dagVM.Initialize( context.TODO(), ctx.Context, - vmDBManager, + vmDB, genesisData, chainConfig.Upgrade, chainConfig.Config, @@ -796,7 +795,7 @@ func (m *manager) createAvalancheChain( registerer: snowmanRegisterer, ctx: ctx.Context, - dbManager: vmDBManager, + db: vmDB, genesisBytes: genesisData, upgradeBytes: chainConfig.Upgrade, configBytes: chainConfig.Config, @@ -1004,15 +1003,13 @@ func (m *manager) createSnowmanChain( State: snow.Initializing, }) - meterDBManager, err := m.DBManager.NewMeterDBManager("db", ctx.Registerer) + meterDB, err := meterdb.New("db", ctx.Registerer, m.DB) if err != nil { return nil, err } - prefixDBManager := meterDBManager.NewPrefixDBManager(ctx.ChainID[:]) - vmDBManager := prefixDBManager.NewPrefixDBManager(vmDBPrefix) - - db := prefixDBManager.Current() - bootstrappingDB := prefixdb.New(bootstrappingDB, db.Database) + prefixDB := prefixdb.New(ctx.ChainID[:], meterDB) + vmDB := prefixdb.New(vmDBPrefix, prefixDB) + bootstrappingDB := prefixdb.New(bootstrappingDB, prefixDB) blocked, err := queue.NewWithMissing(bootstrappingDB, "block", ctx.Registerer) if err != nil { @@ -1145,7 +1142,7 @@ func (m *manager) createSnowmanChain( if err := vm.Initialize( context.TODO(), ctx.Context, - vmDBManager, + vmDB, genesisData, chainConfig.Upgrade, chainConfig.Config, diff --git a/database/manager/manager.go b/database/manager/manager.go deleted file mode 100644 index fd9c36969b79..000000000000 --- a/database/manager/manager.go +++ /dev/null @@ -1,325 +0,0 @@ -// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package manager - -import ( - "errors" - "fmt" - "os" - "path/filepath" - "strings" - - "github.com/prometheus/client_golang/prometheus" - - "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/corruptabledb" - "github.com/ava-labs/avalanchego/database/leveldb" - "github.com/ava-labs/avalanchego/database/memdb" - "github.com/ava-labs/avalanchego/database/meterdb" - "github.com/ava-labs/avalanchego/database/prefixdb" - "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/logging" - "github.com/ava-labs/avalanchego/utils/wrappers" - "github.com/ava-labs/avalanchego/version" -) - -var ( - errNonSortedAndUniqueDBs = errors.New("managed databases were not sorted and unique") - errNoDBs = errors.New("no dbs given") -) - -var _ Manager = (*manager)(nil) - -type Manager interface { - // Current returns the database with the current database version. - Current() *VersionedDatabase - - // Previous returns the database prior to the current database and true if a - // previous database exists. - Previous() (*VersionedDatabase, bool) - - // GetDatabases returns all the managed databases in order from current to - // the oldest version. - GetDatabases() []*VersionedDatabase - - // Close all of the databases controlled by the manager. - Close() error - - // NewPrefixDBManager returns a new database manager with each of its - // databases prefixed with [prefix]. - NewPrefixDBManager(prefix []byte) Manager - - // NewNestedPrefixDBManager returns a new database manager where each of its - // databases has the nested prefix [prefix] applied to it. - NewNestedPrefixDBManager(prefix []byte) Manager - - // NewMeterDBManager returns a new database manager with each of its - // databases wrapped with a meterdb instance to support metrics on database - // performance. - NewMeterDBManager(namespace string, registerer prometheus.Registerer) (Manager, error) - - // NewCompleteMeterDBManager wraps each database instance with a meterdb - // instance. The namespace is concatenated with the version of the database. - // Note: calling this more than once with the same [namespace] will cause a - // conflict error for the [registerer]. - NewCompleteMeterDBManager(namespace string, registerer prometheus.Registerer) (Manager, error) -} - -type manager struct { - // databases with the current version at index 0 and prior versions in - // descending order - // invariant: len(databases) > 0 - databases []*VersionedDatabase -} - -// NewLevelDB creates a database manager of levelDBs at [filePath] by creating a -// database instance from each directory with a version <= [currentVersion]. If -// [includePreviousVersions], opens previous database versions and includes them -// in the returned Manager. -func NewLevelDB( - dbDirPath string, - dbConfig []byte, - log logging.Logger, - currentVersion *version.Semantic, - namespace string, - reg prometheus.Registerer, -) (Manager, error) { - return new( - leveldb.New, - dbDirPath, - dbConfig, - log, - currentVersion, - namespace, - reg, - ) -} - -// new creates a database manager at [filePath] by creating a database instance -// from each directory with a version <= [currentVersion]. If -// [includePreviousVersions], opens previous database versions and includes them -// in the returned Manager. -func new( - newDB func(string, []byte, logging.Logger, string, prometheus.Registerer) (database.Database, error), - dbDirPath string, - dbConfig []byte, - log logging.Logger, - currentVersion *version.Semantic, - namespace string, - reg prometheus.Registerer, -) (Manager, error) { - currentDBPath := filepath.Join(dbDirPath, currentVersion.String()) - - currentDB, err := newDB(currentDBPath, dbConfig, log, namespace, reg) - if err != nil { - return nil, fmt.Errorf("couldn't create db at %s: %w", currentDBPath, err) - } - - wrappedDB := corruptabledb.New(currentDB) - - manager := &manager{ - databases: []*VersionedDatabase{ - { - Database: wrappedDB, - Version: currentVersion, - }, - }, - } - - // Open old database versions and add them to [manager] - err = filepath.Walk(dbDirPath, func(path string, info os.FileInfo, err error) error { - // the walkFn is called with a non-nil error argument if an os.Lstat - // or Readdirnames call returns an error. Both cases are considered - // fatal in the traversal. - // Reference: https://golang.org/pkg/path/filepath/#WalkFunc - if err != nil { - return err - } - // Skip the root directory - if path == dbDirPath { - return nil - } - - // If the database directory contains any files, ignore them. - if !info.IsDir() { - return nil - } - _, dbName := filepath.Split(path) - dbVersion, err := version.Parse(dbName) - if err != nil { - // If the database directory contains any directories that don't - // match the expected version format, ignore them. - return filepath.SkipDir - } - - // If [dbVersion] is greater than or equal to the specified version - // skip over creating the new database to avoid creating the same db - // twice or creating a database with a version ahead of the desired one. - if cmp := dbVersion.Compare(currentVersion); cmp >= 0 { - return filepath.SkipDir - } - - versionStr := strings.ReplaceAll(dbName, ".", "_") - var dbNamespace string - if len(namespace) > 0 { - dbNamespace = fmt.Sprintf("%s_%s", namespace, versionStr) - } else { - dbNamespace = versionStr - } - - db, err := newDB(path, dbConfig, log, dbNamespace, reg) - if err != nil { - return fmt.Errorf("couldn't create db at %s: %w", path, err) - } - - manager.databases = append(manager.databases, &VersionedDatabase{ - Database: corruptabledb.New(db), - Version: dbVersion, - }) - - return filepath.SkipDir - }) - utils.Sort(manager.databases) - - // If an error occurred walking [dbDirPath] close the - // database manager and return the original error here. - if err != nil { - _ = manager.Close() - return nil, err - } - - return manager, nil -} - -// NewMemDB returns a database manager with a single memdb instance with -// [currentVersion]. -func NewMemDB(currentVersion *version.Semantic) Manager { - return &manager{ - databases: []*VersionedDatabase{ - { - Database: memdb.New(), - Version: currentVersion, - }, - }, - } -} - -// NewManagerFromDBs -func NewManagerFromDBs(dbs []*VersionedDatabase) (Manager, error) { - if len(dbs) == 0 { - return nil, errNoDBs - } - utils.Sort(dbs) - sortedAndUnique := utils.IsSortedAndUnique(dbs) - if !sortedAndUnique { - return nil, errNonSortedAndUniqueDBs - } - return &manager{ - databases: dbs, - }, nil -} - -func (m *manager) Current() *VersionedDatabase { - return m.databases[0] -} - -func (m *manager) Previous() (*VersionedDatabase, bool) { - if len(m.databases) < 2 { - return nil, false - } - return m.databases[1], true -} - -func (m *manager) GetDatabases() []*VersionedDatabase { - return m.databases -} - -func (m *manager) Close() error { - errs := wrappers.Errs{} - for _, db := range m.databases { - errs.Add(db.Close()) - } - return errs.Err -} - -// NewPrefixDBManager creates a new manager with each database instance prefixed -// by [prefix] -func (m *manager) NewPrefixDBManager(prefix []byte) Manager { - m, _ = m.wrapManager(func(vdb *VersionedDatabase) (*VersionedDatabase, error) { - return &VersionedDatabase{ - Database: prefixdb.New(prefix, vdb.Database), - Version: vdb.Version, - }, nil - }) - return m -} - -// NewNestedPrefixDBManager creates a new manager with each database instance -// wrapped with a nested prfix of [prefix] -func (m *manager) NewNestedPrefixDBManager(prefix []byte) Manager { - m, _ = m.wrapManager(func(vdb *VersionedDatabase) (*VersionedDatabase, error) { - return &VersionedDatabase{ - Database: prefixdb.NewNested(prefix, vdb.Database), - Version: vdb.Version, - }, nil - }) - return m -} - -// NewMeterDBManager wraps the current database instance with a meterdb instance. -// Note: calling this more than once with the same [namespace] will cause a conflict error for the [registerer] -func (m *manager) NewMeterDBManager(namespace string, registerer prometheus.Registerer) (Manager, error) { - currentDB := m.Current() - currentMeterDB, err := meterdb.New(namespace, registerer, currentDB.Database) - if err != nil { - return nil, err - } - newManager := &manager{ - databases: make([]*VersionedDatabase, len(m.databases)), - } - copy(newManager.databases[1:], m.databases[1:]) - // Overwrite the current database with the meter DB - newManager.databases[0] = &VersionedDatabase{ - Database: currentMeterDB, - Version: currentDB.Version, - } - return newManager, nil -} - -// NewCompleteMeterDBManager wraps each database instance with a meterdb instance. The namespace -// is concatenated with the version of the database. Note: calling this more than once -// with the same [namespace] will cause a conflict error for the [registerer] -func (m *manager) NewCompleteMeterDBManager(namespace string, registerer prometheus.Registerer) (Manager, error) { - return m.wrapManager(func(vdb *VersionedDatabase) (*VersionedDatabase, error) { - mdb, err := meterdb.New(fmt.Sprintf("%s_%s", namespace, strings.ReplaceAll(vdb.Version.String(), ".", "_")), registerer, vdb.Database) - if err != nil { - return nil, err - } - return &VersionedDatabase{ - Database: mdb, - Version: vdb.Version, - }, nil - }) -} - -// wrapManager returns a new database manager with each managed database wrapped -// by the [wrap] function. If an error is returned by wrap, the error is -// returned immediately. If [wrap] never returns an error, then wrapManager is -// guaranteed to never return an error. The function wrap must return a database -// that can be closed without closing the underlying database. -func (m *manager) wrapManager(wrap func(db *VersionedDatabase) (*VersionedDatabase, error)) (*manager, error) { - newManager := &manager{ - databases: make([]*VersionedDatabase, 0, len(m.databases)), - } - for _, db := range m.databases { - wrappedDB, err := wrap(db) - if err != nil { - // ignore additional errors in favor of returning the original error - _ = newManager.Close() - return nil, err - } - newManager.databases = append(newManager.databases, wrappedDB) - } - return newManager, nil -} diff --git a/database/manager/manager_test.go b/database/manager/manager_test.go deleted file mode 100644 index 5e7986b27416..000000000000 --- a/database/manager/manager_test.go +++ /dev/null @@ -1,429 +0,0 @@ -// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package manager - -import ( - "os" - "path/filepath" - "testing" - - "github.com/prometheus/client_golang/prometheus" - - "github.com/stretchr/testify/require" - - "github.com/ava-labs/avalanchego/database/leveldb" - "github.com/ava-labs/avalanchego/database/memdb" - "github.com/ava-labs/avalanchego/database/meterdb" - "github.com/ava-labs/avalanchego/database/prefixdb" - "github.com/ava-labs/avalanchego/utils/logging" - "github.com/ava-labs/avalanchego/utils/metric" - "github.com/ava-labs/avalanchego/version" -) - -func TestNewSingleLevelDB(t *testing.T) { - require := require.New(t) - dir := t.TempDir() - - v1 := version.Semantic1_0_0 - - dbPath := filepath.Join(dir, v1.String()) - db, err := leveldb.New(dbPath, nil, logging.NoLog{}, "", prometheus.NewRegistry()) - require.NoError(err) - - require.NoError(db.Close()) - - manager, err := NewLevelDB(dir, nil, logging.NoLog{}, v1, "", prometheus.NewRegistry()) - require.NoError(err) - - semDB := manager.Current() - require.Zero(semDB.Version.Compare(v1)) - - _, exists := manager.Previous() - require.False(exists) - require.Len(manager.GetDatabases(), 1) - - require.NoError(manager.Close()) -} - -func TestNewCreatesSingleDB(t *testing.T) { - require := require.New(t) - - dir := t.TempDir() - - v1 := version.Semantic1_0_0 - - manager, err := NewLevelDB(dir, nil, logging.NoLog{}, v1, "", prometheus.NewRegistry()) - require.NoError(err) - - semDB := manager.Current() - require.Zero(semDB.Version.Compare(v1)) - - _, exists := manager.Previous() - require.False(exists) - - require.Len(manager.GetDatabases(), 1) - - require.NoError(manager.Close()) -} - -func TestNewInvalidMemberPresent(t *testing.T) { - require := require.New(t) - - dir := t.TempDir() - - v1 := &version.Semantic{ - Major: 1, - Minor: 1, - Patch: 0, - } - v2 := &version.Semantic{ - Major: 1, - Minor: 2, - Patch: 0, - } - - dbPath1 := filepath.Join(dir, v1.String()) - db1, err := leveldb.New(dbPath1, nil, logging.NoLog{}, "", prometheus.NewRegistry()) - require.NoError(err) - - dbPath2 := filepath.Join(dir, v2.String()) - db2, err := leveldb.New(dbPath2, nil, logging.NoLog{}, "", prometheus.NewRegistry()) - require.NoError(err) - - require.NoError(db2.Close()) - - _, err = NewLevelDB(dir, nil, logging.NoLog{}, v2, "", prometheus.NewRegistry()) - require.ErrorIs(err, leveldb.ErrCouldNotOpen) - - require.NoError(db1.Close()) - - f, err := os.Create(filepath.Join(dir, "dummy")) - require.NoError(err) - - require.NoError(f.Close()) - - db, err := NewLevelDB(dir, nil, logging.NoLog{}, v1, "", prometheus.NewRegistry()) - require.NoError(err, "expected not to error with a non-directory file being present") - - require.NoError(db.Close()) -} - -func TestNewSortsDatabases(t *testing.T) { - require := require.New(t) - - dir := t.TempDir() - - vers := []*version.Semantic{ - { - Major: 2, - Minor: 1, - Patch: 2, - }, - { - Major: 2, - Minor: 0, - Patch: 2, - }, - { - Major: 1, - Minor: 3, - Patch: 2, - }, - { - Major: 1, - Minor: 0, - Patch: 2, - }, - { - Major: 1, - Minor: 0, - Patch: 1, - }, - } - - for _, version := range vers { - dbPath := filepath.Join(dir, version.String()) - db, err := leveldb.New(dbPath, nil, logging.NoLog{}, "", prometheus.NewRegistry()) - require.NoError(err) - - require.NoError(db.Close()) - } - - manager, err := NewLevelDB(dir, nil, logging.NoLog{}, vers[0], "", prometheus.NewRegistry()) - require.NoError(err) - - defer func() { - require.NoError(manager.Close()) - }() - - semDB := manager.Current() - require.Zero(semDB.Version.Compare(vers[0])) - - prev, exists := manager.Previous() - require.True(exists) - require.Zero(prev.Version.Compare(vers[1])) - - dbs := manager.GetDatabases() - require.Len(dbs, len(vers)) - - for i, db := range dbs { - require.Zero(db.Version.Compare(vers[i])) - } -} - -func TestPrefixDBManager(t *testing.T) { - require := require.New(t) - - db := memdb.New() - - prefix0 := []byte{0} - db0 := prefixdb.New(prefix0, db) - - prefix1 := []byte{1} - db1 := prefixdb.New(prefix1, db0) - - k0 := []byte{'s', 'c', 'h', 'n', 'i'} - v0 := []byte{'t', 'z', 'e', 'l'} - k1 := []byte{'c', 'u', 'r', 'r', 'y'} - v1 := []byte{'w', 'u', 'r', 's', 't'} - - require.NoError(db0.Put(k0, v0)) - require.NoError(db1.Put(k1, v1)) - require.NoError(db0.Close()) - require.NoError(db1.Close()) - - m := &manager{databases: []*VersionedDatabase{ - { - Database: db, - Version: version.Semantic1_0_0, - }, - }} - - m0 := m.NewPrefixDBManager(prefix0) - m1 := m0.NewPrefixDBManager(prefix1) - - val, err := m0.Current().Database.Get(k0) - require.NoError(err) - require.Equal(v0, val) - - val, err = m1.Current().Database.Get(k1) - require.NoError(err) - require.Equal(v1, val) -} - -func TestNestedPrefixDBManager(t *testing.T) { - require := require.New(t) - - db := memdb.New() - - prefix0 := []byte{0} - db0 := prefixdb.NewNested(prefix0, db) - - prefix1 := []byte{1} - db1 := prefixdb.NewNested(prefix1, db0) - - k0 := []byte{'s', 'c', 'h', 'n', 'i'} - v0 := []byte{'t', 'z', 'e', 'l'} - k1 := []byte{'c', 'u', 'r', 'r', 'y'} - v1 := []byte{'w', 'u', 'r', 's', 't'} - - require.NoError(db0.Put(k0, v0)) - require.NoError(db1.Put(k1, v1)) - require.NoError(db0.Close()) - require.NoError(db1.Close()) - - m := &manager{databases: []*VersionedDatabase{ - { - Database: db, - Version: version.Semantic1_0_0, - }, - }} - - m0 := m.NewNestedPrefixDBManager(prefix0) - m1 := m0.NewNestedPrefixDBManager(prefix1) - - val, err := m0.Current().Database.Get(k0) - require.NoError(err) - require.Equal(v0, val) - - val, err = m1.Current().Database.Get(k1) - require.NoError(err) - require.Equal(v1, val) -} - -func TestMeterDBManager(t *testing.T) { - require := require.New(t) - - registry := prometheus.NewRegistry() - - m := &manager{databases: []*VersionedDatabase{ - { - Database: memdb.New(), - Version: &version.Semantic{ - Major: 2, - Minor: 0, - Patch: 0, - }, - }, - { - Database: memdb.New(), - Version: &version.Semantic{ - Major: 1, - Minor: 5, - Patch: 0, - }, - }, - { - Database: memdb.New(), - Version: version.Semantic1_0_0, - }, - }} - - // Create meterdb manager with fresh registry and confirm - // that there are no errors registering metrics for multiple - // versioned databases. - manager, err := m.NewMeterDBManager("", registry) - require.NoError(err) - - dbs := manager.GetDatabases() - require.Len(dbs, 3) - - require.IsType(&meterdb.Database{}, dbs[0].Database) - require.IsType(&memdb.Database{}, dbs[1].Database) - require.IsType(&memdb.Database{}, dbs[2].Database) - - // Confirm that the error from a name conflict is handled correctly - _, err = m.NewMeterDBManager("", registry) - require.ErrorIs(err, metric.ErrFailedRegistering) -} - -func TestCompleteMeterDBManager(t *testing.T) { - require := require.New(t) - - registry := prometheus.NewRegistry() - - m := &manager{databases: []*VersionedDatabase{ - { - Database: memdb.New(), - Version: &version.Semantic{ - Major: 2, - Minor: 0, - Patch: 0, - }, - }, - { - Database: memdb.New(), - Version: &version.Semantic{ - Major: 1, - Minor: 5, - Patch: 0, - }, - }, - { - Database: memdb.New(), - Version: version.Semantic1_0_0, - }, - }} - - // Create complete meterdb manager with fresh registry and confirm - // that there are no errors registering metrics for multiple - // versioned databases. - manager, err := m.NewCompleteMeterDBManager("", registry) - require.NoError(err) - - dbs := manager.GetDatabases() - require.Len(dbs, 3) - - require.IsType(&meterdb.Database{}, dbs[0].Database) - require.IsType(&meterdb.Database{}, dbs[1].Database) - require.IsType(&meterdb.Database{}, dbs[2].Database) - - // Confirm that the error from a name conflict is handled correctly - _, err = m.NewCompleteMeterDBManager("", registry) - require.ErrorIs(err, metric.ErrFailedRegistering) -} - -func TestNewManagerFromDBs(t *testing.T) { - require := require.New(t) - - versions := []*version.Semantic{ - { - Major: 3, - Minor: 2, - Patch: 0, - }, - { - Major: 1, - Minor: 2, - Patch: 0, - }, - { - Major: 1, - Minor: 1, - Patch: 1, - }, - } - m, err := NewManagerFromDBs( - []*VersionedDatabase{ - { - Database: memdb.New(), - Version: versions[2], - }, - { - Database: memdb.New(), - Version: versions[1], - }, - { - Database: memdb.New(), - Version: versions[0], - }, - }) - require.NoError(err) - - dbs := m.GetDatabases() - require.Len(dbs, len(versions)) - for i, db := range dbs { - require.Zero(db.Version.Compare(versions[i])) - } -} - -func TestNewManagerFromNoDBs(t *testing.T) { - require := require.New(t) - // Should error if no dbs are given - _, err := NewManagerFromDBs(nil) - require.ErrorIs(err, errNoDBs) -} - -func TestNewManagerFromNonUniqueDBs(t *testing.T) { - require := require.New(t) - - _, err := NewManagerFromDBs( - []*VersionedDatabase{ - { - Database: memdb.New(), - Version: &version.Semantic{ - Major: 1, - Minor: 1, - Patch: 0, - }, - }, - { - Database: memdb.New(), - Version: &version.Semantic{ - Major: 1, - Minor: 1, - Patch: 0, - }, // Duplicate - }, - { - Database: memdb.New(), - Version: &version.Semantic{ - Major: 1, - Minor: 2, - Patch: 0, - }, - }, - }) - require.ErrorIs(err, errNonSortedAndUniqueDBs) -} diff --git a/database/manager/versioned_database.go b/database/manager/versioned_database.go deleted file mode 100644 index 6ff983a95a92..000000000000 --- a/database/manager/versioned_database.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package manager - -import ( - "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/version" -) - -var _ utils.Sortable[*VersionedDatabase] = (*VersionedDatabase)(nil) - -type VersionedDatabase struct { - Database database.Database - Version *version.Semantic -} - -// Close the underlying database -func (db *VersionedDatabase) Close() error { - return db.Database.Close() -} - -// Note this sorts in descending order (newest version --> oldest version) -func (db *VersionedDatabase) Less(other *VersionedDatabase) bool { - return db.Version.Compare(other.Version) > 0 -} diff --git a/go.mod b/go.mod index 8bcba0590042..0494bab53992 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/DataDog/zstd v1.5.2 github.com/Microsoft/go-winio v0.5.2 github.com/NYTimes/gziphandler v1.1.1 - github.com/ava-labs/coreth v0.12.8-0.20231027221814-507f2239095b + github.com/ava-labs/coreth v0.12.8-rc.0 github.com/ava-labs/ledger-avalanche/go v0.0.0-20230105152938-00a24d05a8c7 github.com/btcsuite/btcd/btcutil v1.1.3 github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 diff --git a/go.sum b/go.sum index f4d542b4a159..10b15cd40ae7 100644 --- a/go.sum +++ b/go.sum @@ -62,8 +62,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/coreth v0.12.8-0.20231027221814-507f2239095b h1:pKSpTTWvsmDJ7MUkaOPAYfN4mKgWgg4K2cm4k+tvqNI= -github.com/ava-labs/coreth v0.12.8-0.20231027221814-507f2239095b/go.mod h1:8aFn5vDkc9g7RT8bSvx9KAo2Xu4AqzwWAnfoderYPDs= +github.com/ava-labs/coreth v0.12.8-rc.0 h1:9W3i5/6ckOifhD/jrxWwd2SOMYmCAmDG5PUJ6EHxE74= +github.com/ava-labs/coreth v0.12.8-rc.0/go.mod h1:GBH5SxHZdScSp95IijDs9+Gxw/QDIWvfoLKiJMNYLsE= github.com/ava-labs/ledger-avalanche/go v0.0.0-20230105152938-00a24d05a8c7 h1:EdxD90j5sClfL5Ngpz2TlnbnkNYdFPDXa0jDOjam65c= github.com/ava-labs/ledger-avalanche/go v0.0.0-20230105152938-00a24d05a8c7/go.mod h1:XhiXSrh90sHUbkERzaxEftCmUz53eCijshDLZ4fByVM= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= diff --git a/node/node.go b/node/node.go index 34293e85b0b6..d2ca97ae0497 100644 --- a/node/node.go +++ b/node/node.go @@ -38,8 +38,8 @@ import ( "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/database/leveldb" - "github.com/ava-labs/avalanchego/database/manager" "github.com/ava-labs/avalanchego/database/memdb" + "github.com/ava-labs/avalanchego/database/meterdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" @@ -92,7 +92,8 @@ var ( genesisHashKey = []byte("genesisID") ungracefulShutdown = []byte("ungracefulShutdown") - indexerDBPrefix = []byte{0x00} + indexerDBPrefix = []byte{0x00} + keystoreDBPrefix = []byte("keystore") errInvalidTLSKey = errors.New("invalid TLS key") errShuttingDown = errors.New("server shutting down") @@ -109,8 +110,7 @@ type Node struct { ID ids.NodeID // Storage for this node - DBManager manager.Manager - DB database.Database + DB database.Database // Profiles the process. Nil if continuous profiling is disabled. profiler profiler.ContinuousProfiler @@ -500,41 +500,32 @@ func (n *Node) Dispatch() error { */ func (n *Node) initDatabase() error { - // start the db manager - var ( - dbManager manager.Manager - err error - ) + // start the db switch n.Config.DatabaseConfig.Name { case leveldb.Name: - dbManager, err = manager.NewLevelDB(n.Config.DatabaseConfig.Path, n.Config.DatabaseConfig.Config, n.Log, version.CurrentDatabase, "db_internal", n.MetricsRegisterer) + dbPath := filepath.Join(n.Config.DatabaseConfig.Path, version.CurrentDatabase.String()) + var err error + n.DB, err = leveldb.New(dbPath, n.Config.DatabaseConfig.Config, n.Log, "db_internal", n.MetricsRegisterer) + if err != nil { + return fmt.Errorf("couldn't create db at %s: %w", dbPath, err) + } case memdb.Name: - dbManager = manager.NewMemDB(version.CurrentDatabase) + n.DB = memdb.New() default: - err = fmt.Errorf( + return fmt.Errorf( "db-type was %q but should have been one of {%s, %s}", n.Config.DatabaseConfig.Name, leveldb.Name, memdb.Name, ) } - if err != nil { - return err - } - meterDBManager, err := dbManager.NewMeterDBManager("db", n.MetricsRegisterer) + var err error + n.DB, err = meterdb.New("db", n.MetricsRegisterer, n.DB) if err != nil { return err } - n.DBManager = meterDBManager - - currentDB := dbManager.Current() - n.Log.Info("initializing database", - zap.Stringer("dbVersion", currentDB.Version), - ) - n.DB = currentDB.Database - rawExpectedGenesisHash := hashing.ComputeHash256(n.Config.GenesisBytes) rawGenesisHash, err := n.DB.Get(genesisHashKey) @@ -559,6 +550,10 @@ func (n *Node) initDatabase() error { return fmt.Errorf("db contains invalid genesis hash. DB Genesis: %s Generated Genesis: %s", genesisHash, expectedGenesisHash) } + n.Log.Info("initializing database", + zap.Stringer("genesisHash", genesisHash), + ) + ok, err := n.DB.Has(ungracefulShutdown) if err != nil { return fmt.Errorf("failed to read ungraceful shutdown key: %w", err) @@ -830,7 +825,7 @@ func (n *Node) initChainManager(avaxAssetID ids.ID) error { BlockAcceptorGroup: n.BlockAcceptorGroup, TxAcceptorGroup: n.TxAcceptorGroup, VertexAcceptorGroup: n.VertexAcceptorGroup, - DBManager: n.DBManager, + DB: n.DB, MsgCreator: n.msgCreator, Router: n.Config.ConsensusRouter, Net: n.Net, @@ -980,8 +975,7 @@ func (n *Node) initSharedMemory() { // Assumes n.APIServer is already set func (n *Node) initKeystoreAPI() error { n.Log.Info("initializing keystore") - keystoreDB := n.DBManager.NewPrefixDBManager([]byte("keystore")) - n.keystore = keystore.New(n.Log, keystoreDB) + n.keystore = keystore.New(n.Log, prefixdb.New(keystoreDBPrefix, n.DB)) handler, err := n.keystore.CreateHandler() if err != nil { return err @@ -1547,7 +1541,7 @@ func (n *Node) shutdown() { n.Log.Info("cleaning up plugin runtimes") n.runtimeManager.Stop(context.TODO()) - if n.DBManager != nil { + if n.DB != nil { if err := n.DB.Delete(ungracefulShutdown); err != nil { n.Log.Error( "failed to delete ungraceful shutdown key", @@ -1555,7 +1549,7 @@ func (n *Node) shutdown() { ) } - if err := n.DBManager.Close(); err != nil { + if err := n.DB.Close(); err != nil { n.Log.Warn("error during DB shutdown", zap.Error(err), ) diff --git a/proto/pb/vm/vm.pb.go b/proto/pb/vm/vm.pb.go index 9bb4f759ff9d..ebc64f5c3a48 100644 --- a/proto/pb/vm/vm.pb.go +++ b/proto/pb/vm/vm.pb.go @@ -232,7 +232,7 @@ func (x StateSummaryAcceptResponse_Mode) Number() protoreflect.EnumNumber { // Deprecated: Use StateSummaryAcceptResponse_Mode.Descriptor instead. func (StateSummaryAcceptResponse_Mode) EnumDescriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{46, 0} + return file_vm_vm_proto_rawDescGZIP(), []int{45, 0} } type InitializeRequest struct { @@ -246,15 +246,15 @@ type InitializeRequest struct { NodeId []byte `protobuf:"bytes,4,opt,name=node_id,json=nodeId,proto3" json:"node_id,omitempty"` // public_key is the BLS public key that would correspond with any signatures // produced by the warp messaging signer - PublicKey []byte `protobuf:"bytes,5,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` - XChainId []byte `protobuf:"bytes,6,opt,name=x_chain_id,json=xChainId,proto3" json:"x_chain_id,omitempty"` - CChainId []byte `protobuf:"bytes,7,opt,name=c_chain_id,json=cChainId,proto3" json:"c_chain_id,omitempty"` - AvaxAssetId []byte `protobuf:"bytes,8,opt,name=avax_asset_id,json=avaxAssetId,proto3" json:"avax_asset_id,omitempty"` - ChainDataDir string `protobuf:"bytes,9,opt,name=chain_data_dir,json=chainDataDir,proto3" json:"chain_data_dir,omitempty"` - GenesisBytes []byte `protobuf:"bytes,10,opt,name=genesis_bytes,json=genesisBytes,proto3" json:"genesis_bytes,omitempty"` - UpgradeBytes []byte `protobuf:"bytes,11,opt,name=upgrade_bytes,json=upgradeBytes,proto3" json:"upgrade_bytes,omitempty"` - ConfigBytes []byte `protobuf:"bytes,12,opt,name=config_bytes,json=configBytes,proto3" json:"config_bytes,omitempty"` - DbServers []*VersionedDBServer `protobuf:"bytes,13,rep,name=db_servers,json=dbServers,proto3" json:"db_servers,omitempty"` + PublicKey []byte `protobuf:"bytes,5,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` + XChainId []byte `protobuf:"bytes,6,opt,name=x_chain_id,json=xChainId,proto3" json:"x_chain_id,omitempty"` + CChainId []byte `protobuf:"bytes,7,opt,name=c_chain_id,json=cChainId,proto3" json:"c_chain_id,omitempty"` + AvaxAssetId []byte `protobuf:"bytes,8,opt,name=avax_asset_id,json=avaxAssetId,proto3" json:"avax_asset_id,omitempty"` + ChainDataDir string `protobuf:"bytes,9,opt,name=chain_data_dir,json=chainDataDir,proto3" json:"chain_data_dir,omitempty"` + GenesisBytes []byte `protobuf:"bytes,10,opt,name=genesis_bytes,json=genesisBytes,proto3" json:"genesis_bytes,omitempty"` + UpgradeBytes []byte `protobuf:"bytes,11,opt,name=upgrade_bytes,json=upgradeBytes,proto3" json:"upgrade_bytes,omitempty"` + ConfigBytes []byte `protobuf:"bytes,12,opt,name=config_bytes,json=configBytes,proto3" json:"config_bytes,omitempty"` + DbServerAddr string `protobuf:"bytes,13,opt,name=db_server_addr,json=dbServerAddr,proto3" json:"db_server_addr,omitempty"` // server_addr is the address of the gRPC server which serves // the messenger, keystore, shared memory, blockchain alias, // subnet alias, and appSender services @@ -377,11 +377,11 @@ func (x *InitializeRequest) GetConfigBytes() []byte { return nil } -func (x *InitializeRequest) GetDbServers() []*VersionedDBServer { +func (x *InitializeRequest) GetDbServerAddr() string { if x != nil { - return x.DbServers + return x.DbServerAddr } - return nil + return "" } func (x *InitializeRequest) GetServerAddr() string { @@ -470,63 +470,6 @@ func (x *InitializeResponse) GetTimestamp() *timestamppb.Timestamp { return nil } -type VersionedDBServer struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` - // server_addr is the address of the gRPC server which serves the - // Database service - ServerAddr string `protobuf:"bytes,2,opt,name=server_addr,json=serverAddr,proto3" json:"server_addr,omitempty"` -} - -func (x *VersionedDBServer) Reset() { - *x = VersionedDBServer{} - if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *VersionedDBServer) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*VersionedDBServer) ProtoMessage() {} - -func (x *VersionedDBServer) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_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 VersionedDBServer.ProtoReflect.Descriptor instead. -func (*VersionedDBServer) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{2} -} - -func (x *VersionedDBServer) GetVersion() string { - if x != nil { - return x.Version - } - return "" -} - -func (x *VersionedDBServer) GetServerAddr() string { - if x != nil { - return x.ServerAddr - } - return "" -} - type SetStateRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -538,7 +481,7 @@ type SetStateRequest struct { func (x *SetStateRequest) Reset() { *x = SetStateRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[3] + mi := &file_vm_vm_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -551,7 +494,7 @@ func (x *SetStateRequest) String() string { func (*SetStateRequest) ProtoMessage() {} func (x *SetStateRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[3] + mi := &file_vm_vm_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -564,7 +507,7 @@ func (x *SetStateRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use SetStateRequest.ProtoReflect.Descriptor instead. func (*SetStateRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{3} + return file_vm_vm_proto_rawDescGZIP(), []int{2} } func (x *SetStateRequest) GetState() State { @@ -589,7 +532,7 @@ type SetStateResponse struct { func (x *SetStateResponse) Reset() { *x = SetStateResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[4] + mi := &file_vm_vm_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -602,7 +545,7 @@ func (x *SetStateResponse) String() string { func (*SetStateResponse) ProtoMessage() {} func (x *SetStateResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[4] + mi := &file_vm_vm_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -615,7 +558,7 @@ func (x *SetStateResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use SetStateResponse.ProtoReflect.Descriptor instead. func (*SetStateResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{4} + return file_vm_vm_proto_rawDescGZIP(), []int{3} } func (x *SetStateResponse) GetLastAcceptedId() []byte { @@ -664,7 +607,7 @@ type CreateHandlersResponse struct { func (x *CreateHandlersResponse) Reset() { *x = CreateHandlersResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[5] + mi := &file_vm_vm_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -677,7 +620,7 @@ func (x *CreateHandlersResponse) String() string { func (*CreateHandlersResponse) ProtoMessage() {} func (x *CreateHandlersResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[5] + mi := &file_vm_vm_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -690,7 +633,7 @@ func (x *CreateHandlersResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use CreateHandlersResponse.ProtoReflect.Descriptor instead. func (*CreateHandlersResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{5} + return file_vm_vm_proto_rawDescGZIP(), []int{4} } func (x *CreateHandlersResponse) GetHandlers() []*Handler { @@ -711,7 +654,7 @@ type CreateStaticHandlersResponse struct { func (x *CreateStaticHandlersResponse) Reset() { *x = CreateStaticHandlersResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[6] + mi := &file_vm_vm_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -724,7 +667,7 @@ func (x *CreateStaticHandlersResponse) String() string { func (*CreateStaticHandlersResponse) ProtoMessage() {} func (x *CreateStaticHandlersResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[6] + mi := &file_vm_vm_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -737,7 +680,7 @@ func (x *CreateStaticHandlersResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use CreateStaticHandlersResponse.ProtoReflect.Descriptor instead. func (*CreateStaticHandlersResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{6} + return file_vm_vm_proto_rawDescGZIP(), []int{5} } func (x *CreateStaticHandlersResponse) GetHandlers() []*Handler { @@ -761,7 +704,7 @@ type Handler struct { func (x *Handler) Reset() { *x = Handler{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[7] + mi := &file_vm_vm_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -774,7 +717,7 @@ func (x *Handler) String() string { func (*Handler) ProtoMessage() {} func (x *Handler) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[7] + mi := &file_vm_vm_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -787,7 +730,7 @@ func (x *Handler) ProtoReflect() protoreflect.Message { // Deprecated: Use Handler.ProtoReflect.Descriptor instead. func (*Handler) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{7} + return file_vm_vm_proto_rawDescGZIP(), []int{6} } func (x *Handler) GetPrefix() string { @@ -815,7 +758,7 @@ type BuildBlockRequest struct { func (x *BuildBlockRequest) Reset() { *x = BuildBlockRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[8] + mi := &file_vm_vm_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -828,7 +771,7 @@ func (x *BuildBlockRequest) String() string { func (*BuildBlockRequest) ProtoMessage() {} func (x *BuildBlockRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[8] + mi := &file_vm_vm_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -841,7 +784,7 @@ func (x *BuildBlockRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use BuildBlockRequest.ProtoReflect.Descriptor instead. func (*BuildBlockRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{8} + return file_vm_vm_proto_rawDescGZIP(), []int{7} } func (x *BuildBlockRequest) GetPChainHeight() uint64 { @@ -868,7 +811,7 @@ type BuildBlockResponse struct { func (x *BuildBlockResponse) Reset() { *x = BuildBlockResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[9] + mi := &file_vm_vm_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -881,7 +824,7 @@ func (x *BuildBlockResponse) String() string { func (*BuildBlockResponse) ProtoMessage() {} func (x *BuildBlockResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[9] + mi := &file_vm_vm_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -894,7 +837,7 @@ func (x *BuildBlockResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use BuildBlockResponse.ProtoReflect.Descriptor instead. func (*BuildBlockResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{9} + return file_vm_vm_proto_rawDescGZIP(), []int{8} } func (x *BuildBlockResponse) GetId() []byte { @@ -950,7 +893,7 @@ type ParseBlockRequest struct { func (x *ParseBlockRequest) Reset() { *x = ParseBlockRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[10] + mi := &file_vm_vm_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -963,7 +906,7 @@ func (x *ParseBlockRequest) String() string { func (*ParseBlockRequest) ProtoMessage() {} func (x *ParseBlockRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[10] + mi := &file_vm_vm_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -976,7 +919,7 @@ func (x *ParseBlockRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ParseBlockRequest.ProtoReflect.Descriptor instead. func (*ParseBlockRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{10} + return file_vm_vm_proto_rawDescGZIP(), []int{9} } func (x *ParseBlockRequest) GetBytes() []byte { @@ -1002,7 +945,7 @@ type ParseBlockResponse struct { func (x *ParseBlockResponse) Reset() { *x = ParseBlockResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[11] + mi := &file_vm_vm_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1015,7 +958,7 @@ func (x *ParseBlockResponse) String() string { func (*ParseBlockResponse) ProtoMessage() {} func (x *ParseBlockResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[11] + mi := &file_vm_vm_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1028,7 +971,7 @@ func (x *ParseBlockResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ParseBlockResponse.ProtoReflect.Descriptor instead. func (*ParseBlockResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{11} + return file_vm_vm_proto_rawDescGZIP(), []int{10} } func (x *ParseBlockResponse) GetId() []byte { @@ -1084,7 +1027,7 @@ type GetBlockRequest struct { func (x *GetBlockRequest) Reset() { *x = GetBlockRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[12] + mi := &file_vm_vm_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1097,7 +1040,7 @@ func (x *GetBlockRequest) String() string { func (*GetBlockRequest) ProtoMessage() {} func (x *GetBlockRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[12] + mi := &file_vm_vm_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1110,7 +1053,7 @@ func (x *GetBlockRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetBlockRequest.ProtoReflect.Descriptor instead. func (*GetBlockRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{12} + return file_vm_vm_proto_rawDescGZIP(), []int{11} } func (x *GetBlockRequest) GetId() []byte { @@ -1138,7 +1081,7 @@ type GetBlockResponse struct { func (x *GetBlockResponse) Reset() { *x = GetBlockResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[13] + mi := &file_vm_vm_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1151,7 +1094,7 @@ func (x *GetBlockResponse) String() string { func (*GetBlockResponse) ProtoMessage() {} func (x *GetBlockResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[13] + mi := &file_vm_vm_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1164,7 +1107,7 @@ func (x *GetBlockResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetBlockResponse.ProtoReflect.Descriptor instead. func (*GetBlockResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{13} + return file_vm_vm_proto_rawDescGZIP(), []int{12} } func (x *GetBlockResponse) GetParentId() []byte { @@ -1227,7 +1170,7 @@ type SetPreferenceRequest struct { func (x *SetPreferenceRequest) Reset() { *x = SetPreferenceRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[14] + mi := &file_vm_vm_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1240,7 +1183,7 @@ func (x *SetPreferenceRequest) String() string { func (*SetPreferenceRequest) ProtoMessage() {} func (x *SetPreferenceRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[14] + mi := &file_vm_vm_proto_msgTypes[13] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1253,7 +1196,7 @@ func (x *SetPreferenceRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use SetPreferenceRequest.ProtoReflect.Descriptor instead. func (*SetPreferenceRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{14} + return file_vm_vm_proto_rawDescGZIP(), []int{13} } func (x *SetPreferenceRequest) GetId() []byte { @@ -1277,7 +1220,7 @@ type BlockVerifyRequest struct { func (x *BlockVerifyRequest) Reset() { *x = BlockVerifyRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[15] + mi := &file_vm_vm_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1290,7 +1233,7 @@ func (x *BlockVerifyRequest) String() string { func (*BlockVerifyRequest) ProtoMessage() {} func (x *BlockVerifyRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[15] + mi := &file_vm_vm_proto_msgTypes[14] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1303,7 +1246,7 @@ func (x *BlockVerifyRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use BlockVerifyRequest.ProtoReflect.Descriptor instead. func (*BlockVerifyRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{15} + return file_vm_vm_proto_rawDescGZIP(), []int{14} } func (x *BlockVerifyRequest) GetBytes() []byte { @@ -1331,7 +1274,7 @@ type BlockVerifyResponse struct { func (x *BlockVerifyResponse) Reset() { *x = BlockVerifyResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[16] + mi := &file_vm_vm_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1344,7 +1287,7 @@ func (x *BlockVerifyResponse) String() string { func (*BlockVerifyResponse) ProtoMessage() {} func (x *BlockVerifyResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[16] + mi := &file_vm_vm_proto_msgTypes[15] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1357,7 +1300,7 @@ func (x *BlockVerifyResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use BlockVerifyResponse.ProtoReflect.Descriptor instead. func (*BlockVerifyResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{16} + return file_vm_vm_proto_rawDescGZIP(), []int{15} } func (x *BlockVerifyResponse) GetTimestamp() *timestamppb.Timestamp { @@ -1378,7 +1321,7 @@ type BlockAcceptRequest struct { func (x *BlockAcceptRequest) Reset() { *x = BlockAcceptRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[17] + mi := &file_vm_vm_proto_msgTypes[16] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1391,7 +1334,7 @@ func (x *BlockAcceptRequest) String() string { func (*BlockAcceptRequest) ProtoMessage() {} func (x *BlockAcceptRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[17] + mi := &file_vm_vm_proto_msgTypes[16] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1404,7 +1347,7 @@ func (x *BlockAcceptRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use BlockAcceptRequest.ProtoReflect.Descriptor instead. func (*BlockAcceptRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{17} + return file_vm_vm_proto_rawDescGZIP(), []int{16} } func (x *BlockAcceptRequest) GetId() []byte { @@ -1425,7 +1368,7 @@ type BlockRejectRequest struct { func (x *BlockRejectRequest) Reset() { *x = BlockRejectRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[18] + mi := &file_vm_vm_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1438,7 +1381,7 @@ func (x *BlockRejectRequest) String() string { func (*BlockRejectRequest) ProtoMessage() {} func (x *BlockRejectRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[18] + mi := &file_vm_vm_proto_msgTypes[17] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1451,7 +1394,7 @@ func (x *BlockRejectRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use BlockRejectRequest.ProtoReflect.Descriptor instead. func (*BlockRejectRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{18} + return file_vm_vm_proto_rawDescGZIP(), []int{17} } func (x *BlockRejectRequest) GetId() []byte { @@ -1472,7 +1415,7 @@ type HealthResponse struct { func (x *HealthResponse) Reset() { *x = HealthResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[19] + mi := &file_vm_vm_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1485,7 +1428,7 @@ func (x *HealthResponse) String() string { func (*HealthResponse) ProtoMessage() {} func (x *HealthResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[19] + mi := &file_vm_vm_proto_msgTypes[18] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1498,7 +1441,7 @@ func (x *HealthResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use HealthResponse.ProtoReflect.Descriptor instead. func (*HealthResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{19} + return file_vm_vm_proto_rawDescGZIP(), []int{18} } func (x *HealthResponse) GetDetails() []byte { @@ -1519,7 +1462,7 @@ type VersionResponse struct { func (x *VersionResponse) Reset() { *x = VersionResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[20] + mi := &file_vm_vm_proto_msgTypes[19] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1532,7 +1475,7 @@ func (x *VersionResponse) String() string { func (*VersionResponse) ProtoMessage() {} func (x *VersionResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[20] + mi := &file_vm_vm_proto_msgTypes[19] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1545,7 +1488,7 @@ func (x *VersionResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use VersionResponse.ProtoReflect.Descriptor instead. func (*VersionResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{20} + return file_vm_vm_proto_rawDescGZIP(), []int{19} } func (x *VersionResponse) GetVersion() string { @@ -1573,7 +1516,7 @@ type AppRequestMsg struct { func (x *AppRequestMsg) Reset() { *x = AppRequestMsg{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[21] + mi := &file_vm_vm_proto_msgTypes[20] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1586,7 +1529,7 @@ func (x *AppRequestMsg) String() string { func (*AppRequestMsg) ProtoMessage() {} func (x *AppRequestMsg) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[21] + mi := &file_vm_vm_proto_msgTypes[20] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1599,7 +1542,7 @@ func (x *AppRequestMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use AppRequestMsg.ProtoReflect.Descriptor instead. func (*AppRequestMsg) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{21} + return file_vm_vm_proto_rawDescGZIP(), []int{20} } func (x *AppRequestMsg) GetNodeId() []byte { @@ -1644,7 +1587,7 @@ type AppRequestFailedMsg struct { func (x *AppRequestFailedMsg) Reset() { *x = AppRequestFailedMsg{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[22] + mi := &file_vm_vm_proto_msgTypes[21] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1657,7 +1600,7 @@ func (x *AppRequestFailedMsg) String() string { func (*AppRequestFailedMsg) ProtoMessage() {} func (x *AppRequestFailedMsg) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[22] + mi := &file_vm_vm_proto_msgTypes[21] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1670,7 +1613,7 @@ func (x *AppRequestFailedMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use AppRequestFailedMsg.ProtoReflect.Descriptor instead. func (*AppRequestFailedMsg) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{22} + return file_vm_vm_proto_rawDescGZIP(), []int{21} } func (x *AppRequestFailedMsg) GetNodeId() []byte { @@ -1703,7 +1646,7 @@ type AppResponseMsg struct { func (x *AppResponseMsg) Reset() { *x = AppResponseMsg{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[23] + mi := &file_vm_vm_proto_msgTypes[22] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1716,7 +1659,7 @@ func (x *AppResponseMsg) String() string { func (*AppResponseMsg) ProtoMessage() {} func (x *AppResponseMsg) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[23] + mi := &file_vm_vm_proto_msgTypes[22] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1729,7 +1672,7 @@ func (x *AppResponseMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use AppResponseMsg.ProtoReflect.Descriptor instead. func (*AppResponseMsg) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{23} + return file_vm_vm_proto_rawDescGZIP(), []int{22} } func (x *AppResponseMsg) GetNodeId() []byte { @@ -1767,7 +1710,7 @@ type AppGossipMsg struct { func (x *AppGossipMsg) Reset() { *x = AppGossipMsg{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[24] + mi := &file_vm_vm_proto_msgTypes[23] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1780,7 +1723,7 @@ func (x *AppGossipMsg) String() string { func (*AppGossipMsg) ProtoMessage() {} func (x *AppGossipMsg) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[24] + mi := &file_vm_vm_proto_msgTypes[23] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1793,7 +1736,7 @@ func (x *AppGossipMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use AppGossipMsg.ProtoReflect.Descriptor instead. func (*AppGossipMsg) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{24} + return file_vm_vm_proto_rawDescGZIP(), []int{23} } func (x *AppGossipMsg) GetNodeId() []byte { @@ -1828,7 +1771,7 @@ type CrossChainAppRequestMsg struct { func (x *CrossChainAppRequestMsg) Reset() { *x = CrossChainAppRequestMsg{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[25] + mi := &file_vm_vm_proto_msgTypes[24] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1841,7 +1784,7 @@ func (x *CrossChainAppRequestMsg) String() string { func (*CrossChainAppRequestMsg) ProtoMessage() {} func (x *CrossChainAppRequestMsg) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[25] + mi := &file_vm_vm_proto_msgTypes[24] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1854,7 +1797,7 @@ func (x *CrossChainAppRequestMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use CrossChainAppRequestMsg.ProtoReflect.Descriptor instead. func (*CrossChainAppRequestMsg) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{25} + return file_vm_vm_proto_rawDescGZIP(), []int{24} } func (x *CrossChainAppRequestMsg) GetChainId() []byte { @@ -1899,7 +1842,7 @@ type CrossChainAppRequestFailedMsg struct { func (x *CrossChainAppRequestFailedMsg) Reset() { *x = CrossChainAppRequestFailedMsg{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[26] + mi := &file_vm_vm_proto_msgTypes[25] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1912,7 +1855,7 @@ func (x *CrossChainAppRequestFailedMsg) String() string { func (*CrossChainAppRequestFailedMsg) ProtoMessage() {} func (x *CrossChainAppRequestFailedMsg) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[26] + mi := &file_vm_vm_proto_msgTypes[25] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1925,7 +1868,7 @@ func (x *CrossChainAppRequestFailedMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use CrossChainAppRequestFailedMsg.ProtoReflect.Descriptor instead. func (*CrossChainAppRequestFailedMsg) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{26} + return file_vm_vm_proto_rawDescGZIP(), []int{25} } func (x *CrossChainAppRequestFailedMsg) GetChainId() []byte { @@ -1958,7 +1901,7 @@ type CrossChainAppResponseMsg struct { func (x *CrossChainAppResponseMsg) Reset() { *x = CrossChainAppResponseMsg{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[27] + mi := &file_vm_vm_proto_msgTypes[26] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1971,7 +1914,7 @@ func (x *CrossChainAppResponseMsg) String() string { func (*CrossChainAppResponseMsg) ProtoMessage() {} func (x *CrossChainAppResponseMsg) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[27] + mi := &file_vm_vm_proto_msgTypes[26] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1984,7 +1927,7 @@ func (x *CrossChainAppResponseMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use CrossChainAppResponseMsg.ProtoReflect.Descriptor instead. func (*CrossChainAppResponseMsg) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{27} + return file_vm_vm_proto_rawDescGZIP(), []int{26} } func (x *CrossChainAppResponseMsg) GetChainId() []byte { @@ -2020,7 +1963,7 @@ type ConnectedRequest struct { func (x *ConnectedRequest) Reset() { *x = ConnectedRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[28] + mi := &file_vm_vm_proto_msgTypes[27] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2033,7 +1976,7 @@ func (x *ConnectedRequest) String() string { func (*ConnectedRequest) ProtoMessage() {} func (x *ConnectedRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[28] + mi := &file_vm_vm_proto_msgTypes[27] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2046,7 +1989,7 @@ func (x *ConnectedRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ConnectedRequest.ProtoReflect.Descriptor instead. func (*ConnectedRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{28} + return file_vm_vm_proto_rawDescGZIP(), []int{27} } func (x *ConnectedRequest) GetNodeId() []byte { @@ -2074,7 +2017,7 @@ type DisconnectedRequest struct { func (x *DisconnectedRequest) Reset() { *x = DisconnectedRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[29] + mi := &file_vm_vm_proto_msgTypes[28] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2087,7 +2030,7 @@ func (x *DisconnectedRequest) String() string { func (*DisconnectedRequest) ProtoMessage() {} func (x *DisconnectedRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[29] + mi := &file_vm_vm_proto_msgTypes[28] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2100,7 +2043,7 @@ func (x *DisconnectedRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use DisconnectedRequest.ProtoReflect.Descriptor instead. func (*DisconnectedRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{29} + return file_vm_vm_proto_rawDescGZIP(), []int{28} } func (x *DisconnectedRequest) GetNodeId() []byte { @@ -2124,7 +2067,7 @@ type GetAncestorsRequest struct { func (x *GetAncestorsRequest) Reset() { *x = GetAncestorsRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[30] + mi := &file_vm_vm_proto_msgTypes[29] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2137,7 +2080,7 @@ func (x *GetAncestorsRequest) String() string { func (*GetAncestorsRequest) ProtoMessage() {} func (x *GetAncestorsRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[30] + mi := &file_vm_vm_proto_msgTypes[29] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2150,7 +2093,7 @@ func (x *GetAncestorsRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetAncestorsRequest.ProtoReflect.Descriptor instead. func (*GetAncestorsRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{30} + return file_vm_vm_proto_rawDescGZIP(), []int{29} } func (x *GetAncestorsRequest) GetBlkId() []byte { @@ -2192,7 +2135,7 @@ type GetAncestorsResponse struct { func (x *GetAncestorsResponse) Reset() { *x = GetAncestorsResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[31] + mi := &file_vm_vm_proto_msgTypes[30] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2205,7 +2148,7 @@ func (x *GetAncestorsResponse) String() string { func (*GetAncestorsResponse) ProtoMessage() {} func (x *GetAncestorsResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[31] + mi := &file_vm_vm_proto_msgTypes[30] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2218,7 +2161,7 @@ func (x *GetAncestorsResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetAncestorsResponse.ProtoReflect.Descriptor instead. func (*GetAncestorsResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{31} + return file_vm_vm_proto_rawDescGZIP(), []int{30} } func (x *GetAncestorsResponse) GetBlksBytes() [][]byte { @@ -2239,7 +2182,7 @@ type BatchedParseBlockRequest struct { func (x *BatchedParseBlockRequest) Reset() { *x = BatchedParseBlockRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[32] + mi := &file_vm_vm_proto_msgTypes[31] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2252,7 +2195,7 @@ func (x *BatchedParseBlockRequest) String() string { func (*BatchedParseBlockRequest) ProtoMessage() {} func (x *BatchedParseBlockRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[32] + mi := &file_vm_vm_proto_msgTypes[31] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2265,7 +2208,7 @@ func (x *BatchedParseBlockRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use BatchedParseBlockRequest.ProtoReflect.Descriptor instead. func (*BatchedParseBlockRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{32} + return file_vm_vm_proto_rawDescGZIP(), []int{31} } func (x *BatchedParseBlockRequest) GetRequest() [][]byte { @@ -2286,7 +2229,7 @@ type BatchedParseBlockResponse struct { func (x *BatchedParseBlockResponse) Reset() { *x = BatchedParseBlockResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[33] + mi := &file_vm_vm_proto_msgTypes[32] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2299,7 +2242,7 @@ func (x *BatchedParseBlockResponse) String() string { func (*BatchedParseBlockResponse) ProtoMessage() {} func (x *BatchedParseBlockResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[33] + mi := &file_vm_vm_proto_msgTypes[32] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2312,7 +2255,7 @@ func (x *BatchedParseBlockResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use BatchedParseBlockResponse.ProtoReflect.Descriptor instead. func (*BatchedParseBlockResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{33} + return file_vm_vm_proto_rawDescGZIP(), []int{32} } func (x *BatchedParseBlockResponse) GetResponse() []*ParseBlockResponse { @@ -2333,7 +2276,7 @@ type VerifyHeightIndexResponse struct { func (x *VerifyHeightIndexResponse) Reset() { *x = VerifyHeightIndexResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[34] + mi := &file_vm_vm_proto_msgTypes[33] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2346,7 +2289,7 @@ func (x *VerifyHeightIndexResponse) String() string { func (*VerifyHeightIndexResponse) ProtoMessage() {} func (x *VerifyHeightIndexResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[34] + mi := &file_vm_vm_proto_msgTypes[33] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2359,7 +2302,7 @@ func (x *VerifyHeightIndexResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use VerifyHeightIndexResponse.ProtoReflect.Descriptor instead. func (*VerifyHeightIndexResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{34} + return file_vm_vm_proto_rawDescGZIP(), []int{33} } func (x *VerifyHeightIndexResponse) GetErr() Error { @@ -2380,7 +2323,7 @@ type GetBlockIDAtHeightRequest struct { func (x *GetBlockIDAtHeightRequest) Reset() { *x = GetBlockIDAtHeightRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[35] + mi := &file_vm_vm_proto_msgTypes[34] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2393,7 +2336,7 @@ func (x *GetBlockIDAtHeightRequest) String() string { func (*GetBlockIDAtHeightRequest) ProtoMessage() {} func (x *GetBlockIDAtHeightRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[35] + mi := &file_vm_vm_proto_msgTypes[34] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2406,7 +2349,7 @@ func (x *GetBlockIDAtHeightRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetBlockIDAtHeightRequest.ProtoReflect.Descriptor instead. func (*GetBlockIDAtHeightRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{35} + return file_vm_vm_proto_rawDescGZIP(), []int{34} } func (x *GetBlockIDAtHeightRequest) GetHeight() uint64 { @@ -2428,7 +2371,7 @@ type GetBlockIDAtHeightResponse struct { func (x *GetBlockIDAtHeightResponse) Reset() { *x = GetBlockIDAtHeightResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[36] + mi := &file_vm_vm_proto_msgTypes[35] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2441,7 +2384,7 @@ func (x *GetBlockIDAtHeightResponse) String() string { func (*GetBlockIDAtHeightResponse) ProtoMessage() {} func (x *GetBlockIDAtHeightResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[36] + mi := &file_vm_vm_proto_msgTypes[35] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2454,7 +2397,7 @@ func (x *GetBlockIDAtHeightResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetBlockIDAtHeightResponse.ProtoReflect.Descriptor instead. func (*GetBlockIDAtHeightResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{36} + return file_vm_vm_proto_rawDescGZIP(), []int{35} } func (x *GetBlockIDAtHeightResponse) GetBlkId() []byte { @@ -2482,7 +2425,7 @@ type GatherResponse struct { func (x *GatherResponse) Reset() { *x = GatherResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[37] + mi := &file_vm_vm_proto_msgTypes[36] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2495,7 +2438,7 @@ func (x *GatherResponse) String() string { func (*GatherResponse) ProtoMessage() {} func (x *GatherResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[37] + mi := &file_vm_vm_proto_msgTypes[36] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2508,7 +2451,7 @@ func (x *GatherResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GatherResponse.ProtoReflect.Descriptor instead. func (*GatherResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{37} + return file_vm_vm_proto_rawDescGZIP(), []int{36} } func (x *GatherResponse) GetMetricFamilies() []*_go.MetricFamily { @@ -2530,7 +2473,7 @@ type StateSyncEnabledResponse struct { func (x *StateSyncEnabledResponse) Reset() { *x = StateSyncEnabledResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[38] + mi := &file_vm_vm_proto_msgTypes[37] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2543,7 +2486,7 @@ func (x *StateSyncEnabledResponse) String() string { func (*StateSyncEnabledResponse) ProtoMessage() {} func (x *StateSyncEnabledResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[38] + mi := &file_vm_vm_proto_msgTypes[37] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2556,7 +2499,7 @@ func (x *StateSyncEnabledResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use StateSyncEnabledResponse.ProtoReflect.Descriptor instead. func (*StateSyncEnabledResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{38} + return file_vm_vm_proto_rawDescGZIP(), []int{37} } func (x *StateSyncEnabledResponse) GetEnabled() bool { @@ -2587,7 +2530,7 @@ type GetOngoingSyncStateSummaryResponse struct { func (x *GetOngoingSyncStateSummaryResponse) Reset() { *x = GetOngoingSyncStateSummaryResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[39] + mi := &file_vm_vm_proto_msgTypes[38] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2600,7 +2543,7 @@ func (x *GetOngoingSyncStateSummaryResponse) String() string { func (*GetOngoingSyncStateSummaryResponse) ProtoMessage() {} func (x *GetOngoingSyncStateSummaryResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[39] + mi := &file_vm_vm_proto_msgTypes[38] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2613,7 +2556,7 @@ func (x *GetOngoingSyncStateSummaryResponse) ProtoReflect() protoreflect.Message // Deprecated: Use GetOngoingSyncStateSummaryResponse.ProtoReflect.Descriptor instead. func (*GetOngoingSyncStateSummaryResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{39} + return file_vm_vm_proto_rawDescGZIP(), []int{38} } func (x *GetOngoingSyncStateSummaryResponse) GetId() []byte { @@ -2658,7 +2601,7 @@ type GetLastStateSummaryResponse struct { func (x *GetLastStateSummaryResponse) Reset() { *x = GetLastStateSummaryResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[40] + mi := &file_vm_vm_proto_msgTypes[39] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2671,7 +2614,7 @@ func (x *GetLastStateSummaryResponse) String() string { func (*GetLastStateSummaryResponse) ProtoMessage() {} func (x *GetLastStateSummaryResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[40] + mi := &file_vm_vm_proto_msgTypes[39] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2684,7 +2627,7 @@ func (x *GetLastStateSummaryResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetLastStateSummaryResponse.ProtoReflect.Descriptor instead. func (*GetLastStateSummaryResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{40} + return file_vm_vm_proto_rawDescGZIP(), []int{39} } func (x *GetLastStateSummaryResponse) GetId() []byte { @@ -2726,7 +2669,7 @@ type ParseStateSummaryRequest struct { func (x *ParseStateSummaryRequest) Reset() { *x = ParseStateSummaryRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[41] + mi := &file_vm_vm_proto_msgTypes[40] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2739,7 +2682,7 @@ func (x *ParseStateSummaryRequest) String() string { func (*ParseStateSummaryRequest) ProtoMessage() {} func (x *ParseStateSummaryRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[41] + mi := &file_vm_vm_proto_msgTypes[40] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2752,7 +2695,7 @@ func (x *ParseStateSummaryRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ParseStateSummaryRequest.ProtoReflect.Descriptor instead. func (*ParseStateSummaryRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{41} + return file_vm_vm_proto_rawDescGZIP(), []int{40} } func (x *ParseStateSummaryRequest) GetBytes() []byte { @@ -2775,7 +2718,7 @@ type ParseStateSummaryResponse struct { func (x *ParseStateSummaryResponse) Reset() { *x = ParseStateSummaryResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[42] + mi := &file_vm_vm_proto_msgTypes[41] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2788,7 +2731,7 @@ func (x *ParseStateSummaryResponse) String() string { func (*ParseStateSummaryResponse) ProtoMessage() {} func (x *ParseStateSummaryResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[42] + mi := &file_vm_vm_proto_msgTypes[41] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2801,7 +2744,7 @@ func (x *ParseStateSummaryResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ParseStateSummaryResponse.ProtoReflect.Descriptor instead. func (*ParseStateSummaryResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{42} + return file_vm_vm_proto_rawDescGZIP(), []int{41} } func (x *ParseStateSummaryResponse) GetId() []byte { @@ -2836,7 +2779,7 @@ type GetStateSummaryRequest struct { func (x *GetStateSummaryRequest) Reset() { *x = GetStateSummaryRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[43] + mi := &file_vm_vm_proto_msgTypes[42] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2849,7 +2792,7 @@ func (x *GetStateSummaryRequest) String() string { func (*GetStateSummaryRequest) ProtoMessage() {} func (x *GetStateSummaryRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[43] + mi := &file_vm_vm_proto_msgTypes[42] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2862,7 +2805,7 @@ func (x *GetStateSummaryRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetStateSummaryRequest.ProtoReflect.Descriptor instead. func (*GetStateSummaryRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{43} + return file_vm_vm_proto_rawDescGZIP(), []int{42} } func (x *GetStateSummaryRequest) GetHeight() uint64 { @@ -2885,7 +2828,7 @@ type GetStateSummaryResponse struct { func (x *GetStateSummaryResponse) Reset() { *x = GetStateSummaryResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[44] + mi := &file_vm_vm_proto_msgTypes[43] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2898,7 +2841,7 @@ func (x *GetStateSummaryResponse) String() string { func (*GetStateSummaryResponse) ProtoMessage() {} func (x *GetStateSummaryResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[44] + mi := &file_vm_vm_proto_msgTypes[43] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2911,7 +2854,7 @@ func (x *GetStateSummaryResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetStateSummaryResponse.ProtoReflect.Descriptor instead. func (*GetStateSummaryResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{44} + return file_vm_vm_proto_rawDescGZIP(), []int{43} } func (x *GetStateSummaryResponse) GetId() []byte { @@ -2946,7 +2889,7 @@ type StateSummaryAcceptRequest struct { func (x *StateSummaryAcceptRequest) Reset() { *x = StateSummaryAcceptRequest{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[45] + mi := &file_vm_vm_proto_msgTypes[44] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2959,7 +2902,7 @@ func (x *StateSummaryAcceptRequest) String() string { func (*StateSummaryAcceptRequest) ProtoMessage() {} func (x *StateSummaryAcceptRequest) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[45] + mi := &file_vm_vm_proto_msgTypes[44] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2972,7 +2915,7 @@ func (x *StateSummaryAcceptRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use StateSummaryAcceptRequest.ProtoReflect.Descriptor instead. func (*StateSummaryAcceptRequest) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{45} + return file_vm_vm_proto_rawDescGZIP(), []int{44} } func (x *StateSummaryAcceptRequest) GetBytes() []byte { @@ -2994,7 +2937,7 @@ type StateSummaryAcceptResponse struct { func (x *StateSummaryAcceptResponse) Reset() { *x = StateSummaryAcceptResponse{} if protoimpl.UnsafeEnabled { - mi := &file_vm_vm_proto_msgTypes[46] + mi := &file_vm_vm_proto_msgTypes[45] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -3007,7 +2950,7 @@ func (x *StateSummaryAcceptResponse) String() string { func (*StateSummaryAcceptResponse) ProtoMessage() {} func (x *StateSummaryAcceptResponse) ProtoReflect() protoreflect.Message { - mi := &file_vm_vm_proto_msgTypes[46] + mi := &file_vm_vm_proto_msgTypes[45] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -3020,7 +2963,7 @@ func (x *StateSummaryAcceptResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use StateSummaryAcceptResponse.ProtoReflect.Descriptor instead. func (*StateSummaryAcceptResponse) Descriptor() ([]byte, []int) { - return file_vm_vm_proto_rawDescGZIP(), []int{46} + return file_vm_vm_proto_rawDescGZIP(), []int{45} } func (x *StateSummaryAcceptResponse) GetMode() StateSummaryAcceptResponse_Mode { @@ -3047,7 +2990,7 @@ var file_vm_vm_proto_rawDesc = []byte{ 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x22, 0x69, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x22, 0xec, 0x03, 0x0a, 0x11, 0x49, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, + 0x6f, 0x74, 0x6f, 0x22, 0xdc, 0x03, 0x0a, 0x11, 0x49, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x75, 0x62, 0x6e, @@ -3072,11 +3015,10 @@ var file_vm_vm_proto_rawDesc = []byte{ 0x79, 0x74, 0x65, 0x73, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0c, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, - 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x34, 0x0a, 0x0a, 0x64, - 0x62, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x18, 0x0d, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x15, 0x2e, 0x76, 0x6d, 0x2e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x64, 0x44, 0x42, - 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x09, 0x64, 0x62, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x61, 0x64, 0x64, 0x72, + 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x24, 0x0a, 0x0e, 0x64, + 0x62, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x0d, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0c, 0x64, 0x62, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, + 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x22, 0xdd, 0x01, 0x0a, 0x12, 0x49, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x28, 0x0a, 0x10, 0x6c, 0x61, 0x73, @@ -3092,12 +3034,7 @@ var file_vm_vm_proto_rawDesc = []byte{ 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, - 0x6d, 0x70, 0x22, 0x4e, 0x0a, 0x11, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x64, 0x44, - 0x42, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, - 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, - 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x61, 0x64, 0x64, 0x72, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, - 0x64, 0x72, 0x22, 0x32, 0x0a, 0x0f, 0x53, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, + 0x6d, 0x70, 0x22, 0x32, 0x0a, 0x0f, 0x53, 0x65, 0x74, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x09, 0x2e, 0x76, 0x6d, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0xdb, 0x01, 0x0a, 0x10, 0x53, 0x65, 0x74, 0x53, 0x74, @@ -3545,7 +3482,7 @@ func file_vm_vm_proto_rawDescGZIP() []byte { } var file_vm_vm_proto_enumTypes = make([]protoimpl.EnumInfo, 4) -var file_vm_vm_proto_msgTypes = make([]protoimpl.MessageInfo, 47) +var file_vm_vm_proto_msgTypes = make([]protoimpl.MessageInfo, 46) var file_vm_vm_proto_goTypes = []interface{}{ (State)(0), // 0: vm.State (Status)(0), // 1: vm.Status @@ -3553,155 +3490,153 @@ var file_vm_vm_proto_goTypes = []interface{}{ (StateSummaryAcceptResponse_Mode)(0), // 3: vm.StateSummaryAcceptResponse.Mode (*InitializeRequest)(nil), // 4: vm.InitializeRequest (*InitializeResponse)(nil), // 5: vm.InitializeResponse - (*VersionedDBServer)(nil), // 6: vm.VersionedDBServer - (*SetStateRequest)(nil), // 7: vm.SetStateRequest - (*SetStateResponse)(nil), // 8: vm.SetStateResponse - (*CreateHandlersResponse)(nil), // 9: vm.CreateHandlersResponse - (*CreateStaticHandlersResponse)(nil), // 10: vm.CreateStaticHandlersResponse - (*Handler)(nil), // 11: vm.Handler - (*BuildBlockRequest)(nil), // 12: vm.BuildBlockRequest - (*BuildBlockResponse)(nil), // 13: vm.BuildBlockResponse - (*ParseBlockRequest)(nil), // 14: vm.ParseBlockRequest - (*ParseBlockResponse)(nil), // 15: vm.ParseBlockResponse - (*GetBlockRequest)(nil), // 16: vm.GetBlockRequest - (*GetBlockResponse)(nil), // 17: vm.GetBlockResponse - (*SetPreferenceRequest)(nil), // 18: vm.SetPreferenceRequest - (*BlockVerifyRequest)(nil), // 19: vm.BlockVerifyRequest - (*BlockVerifyResponse)(nil), // 20: vm.BlockVerifyResponse - (*BlockAcceptRequest)(nil), // 21: vm.BlockAcceptRequest - (*BlockRejectRequest)(nil), // 22: vm.BlockRejectRequest - (*HealthResponse)(nil), // 23: vm.HealthResponse - (*VersionResponse)(nil), // 24: vm.VersionResponse - (*AppRequestMsg)(nil), // 25: vm.AppRequestMsg - (*AppRequestFailedMsg)(nil), // 26: vm.AppRequestFailedMsg - (*AppResponseMsg)(nil), // 27: vm.AppResponseMsg - (*AppGossipMsg)(nil), // 28: vm.AppGossipMsg - (*CrossChainAppRequestMsg)(nil), // 29: vm.CrossChainAppRequestMsg - (*CrossChainAppRequestFailedMsg)(nil), // 30: vm.CrossChainAppRequestFailedMsg - (*CrossChainAppResponseMsg)(nil), // 31: vm.CrossChainAppResponseMsg - (*ConnectedRequest)(nil), // 32: vm.ConnectedRequest - (*DisconnectedRequest)(nil), // 33: vm.DisconnectedRequest - (*GetAncestorsRequest)(nil), // 34: vm.GetAncestorsRequest - (*GetAncestorsResponse)(nil), // 35: vm.GetAncestorsResponse - (*BatchedParseBlockRequest)(nil), // 36: vm.BatchedParseBlockRequest - (*BatchedParseBlockResponse)(nil), // 37: vm.BatchedParseBlockResponse - (*VerifyHeightIndexResponse)(nil), // 38: vm.VerifyHeightIndexResponse - (*GetBlockIDAtHeightRequest)(nil), // 39: vm.GetBlockIDAtHeightRequest - (*GetBlockIDAtHeightResponse)(nil), // 40: vm.GetBlockIDAtHeightResponse - (*GatherResponse)(nil), // 41: vm.GatherResponse - (*StateSyncEnabledResponse)(nil), // 42: vm.StateSyncEnabledResponse - (*GetOngoingSyncStateSummaryResponse)(nil), // 43: vm.GetOngoingSyncStateSummaryResponse - (*GetLastStateSummaryResponse)(nil), // 44: vm.GetLastStateSummaryResponse - (*ParseStateSummaryRequest)(nil), // 45: vm.ParseStateSummaryRequest - (*ParseStateSummaryResponse)(nil), // 46: vm.ParseStateSummaryResponse - (*GetStateSummaryRequest)(nil), // 47: vm.GetStateSummaryRequest - (*GetStateSummaryResponse)(nil), // 48: vm.GetStateSummaryResponse - (*StateSummaryAcceptRequest)(nil), // 49: vm.StateSummaryAcceptRequest - (*StateSummaryAcceptResponse)(nil), // 50: vm.StateSummaryAcceptResponse - (*timestamppb.Timestamp)(nil), // 51: google.protobuf.Timestamp - (*_go.MetricFamily)(nil), // 52: io.prometheus.client.MetricFamily - (*emptypb.Empty)(nil), // 53: google.protobuf.Empty + (*SetStateRequest)(nil), // 6: vm.SetStateRequest + (*SetStateResponse)(nil), // 7: vm.SetStateResponse + (*CreateHandlersResponse)(nil), // 8: vm.CreateHandlersResponse + (*CreateStaticHandlersResponse)(nil), // 9: vm.CreateStaticHandlersResponse + (*Handler)(nil), // 10: vm.Handler + (*BuildBlockRequest)(nil), // 11: vm.BuildBlockRequest + (*BuildBlockResponse)(nil), // 12: vm.BuildBlockResponse + (*ParseBlockRequest)(nil), // 13: vm.ParseBlockRequest + (*ParseBlockResponse)(nil), // 14: vm.ParseBlockResponse + (*GetBlockRequest)(nil), // 15: vm.GetBlockRequest + (*GetBlockResponse)(nil), // 16: vm.GetBlockResponse + (*SetPreferenceRequest)(nil), // 17: vm.SetPreferenceRequest + (*BlockVerifyRequest)(nil), // 18: vm.BlockVerifyRequest + (*BlockVerifyResponse)(nil), // 19: vm.BlockVerifyResponse + (*BlockAcceptRequest)(nil), // 20: vm.BlockAcceptRequest + (*BlockRejectRequest)(nil), // 21: vm.BlockRejectRequest + (*HealthResponse)(nil), // 22: vm.HealthResponse + (*VersionResponse)(nil), // 23: vm.VersionResponse + (*AppRequestMsg)(nil), // 24: vm.AppRequestMsg + (*AppRequestFailedMsg)(nil), // 25: vm.AppRequestFailedMsg + (*AppResponseMsg)(nil), // 26: vm.AppResponseMsg + (*AppGossipMsg)(nil), // 27: vm.AppGossipMsg + (*CrossChainAppRequestMsg)(nil), // 28: vm.CrossChainAppRequestMsg + (*CrossChainAppRequestFailedMsg)(nil), // 29: vm.CrossChainAppRequestFailedMsg + (*CrossChainAppResponseMsg)(nil), // 30: vm.CrossChainAppResponseMsg + (*ConnectedRequest)(nil), // 31: vm.ConnectedRequest + (*DisconnectedRequest)(nil), // 32: vm.DisconnectedRequest + (*GetAncestorsRequest)(nil), // 33: vm.GetAncestorsRequest + (*GetAncestorsResponse)(nil), // 34: vm.GetAncestorsResponse + (*BatchedParseBlockRequest)(nil), // 35: vm.BatchedParseBlockRequest + (*BatchedParseBlockResponse)(nil), // 36: vm.BatchedParseBlockResponse + (*VerifyHeightIndexResponse)(nil), // 37: vm.VerifyHeightIndexResponse + (*GetBlockIDAtHeightRequest)(nil), // 38: vm.GetBlockIDAtHeightRequest + (*GetBlockIDAtHeightResponse)(nil), // 39: vm.GetBlockIDAtHeightResponse + (*GatherResponse)(nil), // 40: vm.GatherResponse + (*StateSyncEnabledResponse)(nil), // 41: vm.StateSyncEnabledResponse + (*GetOngoingSyncStateSummaryResponse)(nil), // 42: vm.GetOngoingSyncStateSummaryResponse + (*GetLastStateSummaryResponse)(nil), // 43: vm.GetLastStateSummaryResponse + (*ParseStateSummaryRequest)(nil), // 44: vm.ParseStateSummaryRequest + (*ParseStateSummaryResponse)(nil), // 45: vm.ParseStateSummaryResponse + (*GetStateSummaryRequest)(nil), // 46: vm.GetStateSummaryRequest + (*GetStateSummaryResponse)(nil), // 47: vm.GetStateSummaryResponse + (*StateSummaryAcceptRequest)(nil), // 48: vm.StateSummaryAcceptRequest + (*StateSummaryAcceptResponse)(nil), // 49: vm.StateSummaryAcceptResponse + (*timestamppb.Timestamp)(nil), // 50: google.protobuf.Timestamp + (*_go.MetricFamily)(nil), // 51: io.prometheus.client.MetricFamily + (*emptypb.Empty)(nil), // 52: google.protobuf.Empty } var file_vm_vm_proto_depIdxs = []int32{ - 6, // 0: vm.InitializeRequest.db_servers:type_name -> vm.VersionedDBServer - 51, // 1: vm.InitializeResponse.timestamp:type_name -> google.protobuf.Timestamp - 0, // 2: vm.SetStateRequest.state:type_name -> vm.State - 51, // 3: vm.SetStateResponse.timestamp:type_name -> google.protobuf.Timestamp - 11, // 4: vm.CreateHandlersResponse.handlers:type_name -> vm.Handler - 11, // 5: vm.CreateStaticHandlersResponse.handlers:type_name -> vm.Handler - 51, // 6: vm.BuildBlockResponse.timestamp:type_name -> google.protobuf.Timestamp - 1, // 7: vm.ParseBlockResponse.status:type_name -> vm.Status - 51, // 8: vm.ParseBlockResponse.timestamp:type_name -> google.protobuf.Timestamp - 1, // 9: vm.GetBlockResponse.status:type_name -> vm.Status - 51, // 10: vm.GetBlockResponse.timestamp:type_name -> google.protobuf.Timestamp - 2, // 11: vm.GetBlockResponse.err:type_name -> vm.Error - 51, // 12: vm.BlockVerifyResponse.timestamp:type_name -> google.protobuf.Timestamp - 51, // 13: vm.AppRequestMsg.deadline:type_name -> google.protobuf.Timestamp - 51, // 14: vm.CrossChainAppRequestMsg.deadline:type_name -> google.protobuf.Timestamp - 15, // 15: vm.BatchedParseBlockResponse.response:type_name -> vm.ParseBlockResponse - 2, // 16: vm.VerifyHeightIndexResponse.err:type_name -> vm.Error - 2, // 17: vm.GetBlockIDAtHeightResponse.err:type_name -> vm.Error - 52, // 18: vm.GatherResponse.metric_families:type_name -> io.prometheus.client.MetricFamily - 2, // 19: vm.StateSyncEnabledResponse.err:type_name -> vm.Error - 2, // 20: vm.GetOngoingSyncStateSummaryResponse.err:type_name -> vm.Error - 2, // 21: vm.GetLastStateSummaryResponse.err:type_name -> vm.Error - 2, // 22: vm.ParseStateSummaryResponse.err:type_name -> vm.Error - 2, // 23: vm.GetStateSummaryResponse.err:type_name -> vm.Error - 3, // 24: vm.StateSummaryAcceptResponse.mode:type_name -> vm.StateSummaryAcceptResponse.Mode - 2, // 25: vm.StateSummaryAcceptResponse.err:type_name -> vm.Error - 4, // 26: vm.VM.Initialize:input_type -> vm.InitializeRequest - 7, // 27: vm.VM.SetState:input_type -> vm.SetStateRequest - 53, // 28: vm.VM.Shutdown:input_type -> google.protobuf.Empty - 53, // 29: vm.VM.CreateHandlers:input_type -> google.protobuf.Empty - 53, // 30: vm.VM.CreateStaticHandlers:input_type -> google.protobuf.Empty - 32, // 31: vm.VM.Connected:input_type -> vm.ConnectedRequest - 33, // 32: vm.VM.Disconnected:input_type -> vm.DisconnectedRequest - 12, // 33: vm.VM.BuildBlock:input_type -> vm.BuildBlockRequest - 14, // 34: vm.VM.ParseBlock:input_type -> vm.ParseBlockRequest - 16, // 35: vm.VM.GetBlock:input_type -> vm.GetBlockRequest - 18, // 36: vm.VM.SetPreference:input_type -> vm.SetPreferenceRequest - 53, // 37: vm.VM.Health:input_type -> google.protobuf.Empty - 53, // 38: vm.VM.Version:input_type -> google.protobuf.Empty - 25, // 39: vm.VM.AppRequest:input_type -> vm.AppRequestMsg - 26, // 40: vm.VM.AppRequestFailed:input_type -> vm.AppRequestFailedMsg - 27, // 41: vm.VM.AppResponse:input_type -> vm.AppResponseMsg - 28, // 42: vm.VM.AppGossip:input_type -> vm.AppGossipMsg - 53, // 43: vm.VM.Gather:input_type -> google.protobuf.Empty - 29, // 44: vm.VM.CrossChainAppRequest:input_type -> vm.CrossChainAppRequestMsg - 30, // 45: vm.VM.CrossChainAppRequestFailed:input_type -> vm.CrossChainAppRequestFailedMsg - 31, // 46: vm.VM.CrossChainAppResponse:input_type -> vm.CrossChainAppResponseMsg - 34, // 47: vm.VM.GetAncestors:input_type -> vm.GetAncestorsRequest - 36, // 48: vm.VM.BatchedParseBlock:input_type -> vm.BatchedParseBlockRequest - 53, // 49: vm.VM.VerifyHeightIndex:input_type -> google.protobuf.Empty - 39, // 50: vm.VM.GetBlockIDAtHeight:input_type -> vm.GetBlockIDAtHeightRequest - 53, // 51: vm.VM.StateSyncEnabled:input_type -> google.protobuf.Empty - 53, // 52: vm.VM.GetOngoingSyncStateSummary:input_type -> google.protobuf.Empty - 53, // 53: vm.VM.GetLastStateSummary:input_type -> google.protobuf.Empty - 45, // 54: vm.VM.ParseStateSummary:input_type -> vm.ParseStateSummaryRequest - 47, // 55: vm.VM.GetStateSummary:input_type -> vm.GetStateSummaryRequest - 19, // 56: vm.VM.BlockVerify:input_type -> vm.BlockVerifyRequest - 21, // 57: vm.VM.BlockAccept:input_type -> vm.BlockAcceptRequest - 22, // 58: vm.VM.BlockReject:input_type -> vm.BlockRejectRequest - 49, // 59: vm.VM.StateSummaryAccept:input_type -> vm.StateSummaryAcceptRequest - 5, // 60: vm.VM.Initialize:output_type -> vm.InitializeResponse - 8, // 61: vm.VM.SetState:output_type -> vm.SetStateResponse - 53, // 62: vm.VM.Shutdown:output_type -> google.protobuf.Empty - 9, // 63: vm.VM.CreateHandlers:output_type -> vm.CreateHandlersResponse - 10, // 64: vm.VM.CreateStaticHandlers:output_type -> vm.CreateStaticHandlersResponse - 53, // 65: vm.VM.Connected:output_type -> google.protobuf.Empty - 53, // 66: vm.VM.Disconnected:output_type -> google.protobuf.Empty - 13, // 67: vm.VM.BuildBlock:output_type -> vm.BuildBlockResponse - 15, // 68: vm.VM.ParseBlock:output_type -> vm.ParseBlockResponse - 17, // 69: vm.VM.GetBlock:output_type -> vm.GetBlockResponse - 53, // 70: vm.VM.SetPreference:output_type -> google.protobuf.Empty - 23, // 71: vm.VM.Health:output_type -> vm.HealthResponse - 24, // 72: vm.VM.Version:output_type -> vm.VersionResponse - 53, // 73: vm.VM.AppRequest:output_type -> google.protobuf.Empty - 53, // 74: vm.VM.AppRequestFailed:output_type -> google.protobuf.Empty - 53, // 75: vm.VM.AppResponse:output_type -> google.protobuf.Empty - 53, // 76: vm.VM.AppGossip:output_type -> google.protobuf.Empty - 41, // 77: vm.VM.Gather:output_type -> vm.GatherResponse - 53, // 78: vm.VM.CrossChainAppRequest:output_type -> google.protobuf.Empty - 53, // 79: vm.VM.CrossChainAppRequestFailed:output_type -> google.protobuf.Empty - 53, // 80: vm.VM.CrossChainAppResponse:output_type -> google.protobuf.Empty - 35, // 81: vm.VM.GetAncestors:output_type -> vm.GetAncestorsResponse - 37, // 82: vm.VM.BatchedParseBlock:output_type -> vm.BatchedParseBlockResponse - 38, // 83: vm.VM.VerifyHeightIndex:output_type -> vm.VerifyHeightIndexResponse - 40, // 84: vm.VM.GetBlockIDAtHeight:output_type -> vm.GetBlockIDAtHeightResponse - 42, // 85: vm.VM.StateSyncEnabled:output_type -> vm.StateSyncEnabledResponse - 43, // 86: vm.VM.GetOngoingSyncStateSummary:output_type -> vm.GetOngoingSyncStateSummaryResponse - 44, // 87: vm.VM.GetLastStateSummary:output_type -> vm.GetLastStateSummaryResponse - 46, // 88: vm.VM.ParseStateSummary:output_type -> vm.ParseStateSummaryResponse - 48, // 89: vm.VM.GetStateSummary:output_type -> vm.GetStateSummaryResponse - 20, // 90: vm.VM.BlockVerify:output_type -> vm.BlockVerifyResponse - 53, // 91: vm.VM.BlockAccept:output_type -> google.protobuf.Empty - 53, // 92: vm.VM.BlockReject:output_type -> google.protobuf.Empty - 50, // 93: vm.VM.StateSummaryAccept:output_type -> vm.StateSummaryAcceptResponse - 60, // [60:94] is the sub-list for method output_type - 26, // [26:60] is the sub-list for method input_type - 26, // [26:26] is the sub-list for extension type_name - 26, // [26:26] is the sub-list for extension extendee - 0, // [0:26] is the sub-list for field type_name + 50, // 0: vm.InitializeResponse.timestamp:type_name -> google.protobuf.Timestamp + 0, // 1: vm.SetStateRequest.state:type_name -> vm.State + 50, // 2: vm.SetStateResponse.timestamp:type_name -> google.protobuf.Timestamp + 10, // 3: vm.CreateHandlersResponse.handlers:type_name -> vm.Handler + 10, // 4: vm.CreateStaticHandlersResponse.handlers:type_name -> vm.Handler + 50, // 5: vm.BuildBlockResponse.timestamp:type_name -> google.protobuf.Timestamp + 1, // 6: vm.ParseBlockResponse.status:type_name -> vm.Status + 50, // 7: vm.ParseBlockResponse.timestamp:type_name -> google.protobuf.Timestamp + 1, // 8: vm.GetBlockResponse.status:type_name -> vm.Status + 50, // 9: vm.GetBlockResponse.timestamp:type_name -> google.protobuf.Timestamp + 2, // 10: vm.GetBlockResponse.err:type_name -> vm.Error + 50, // 11: vm.BlockVerifyResponse.timestamp:type_name -> google.protobuf.Timestamp + 50, // 12: vm.AppRequestMsg.deadline:type_name -> google.protobuf.Timestamp + 50, // 13: vm.CrossChainAppRequestMsg.deadline:type_name -> google.protobuf.Timestamp + 14, // 14: vm.BatchedParseBlockResponse.response:type_name -> vm.ParseBlockResponse + 2, // 15: vm.VerifyHeightIndexResponse.err:type_name -> vm.Error + 2, // 16: vm.GetBlockIDAtHeightResponse.err:type_name -> vm.Error + 51, // 17: vm.GatherResponse.metric_families:type_name -> io.prometheus.client.MetricFamily + 2, // 18: vm.StateSyncEnabledResponse.err:type_name -> vm.Error + 2, // 19: vm.GetOngoingSyncStateSummaryResponse.err:type_name -> vm.Error + 2, // 20: vm.GetLastStateSummaryResponse.err:type_name -> vm.Error + 2, // 21: vm.ParseStateSummaryResponse.err:type_name -> vm.Error + 2, // 22: vm.GetStateSummaryResponse.err:type_name -> vm.Error + 3, // 23: vm.StateSummaryAcceptResponse.mode:type_name -> vm.StateSummaryAcceptResponse.Mode + 2, // 24: vm.StateSummaryAcceptResponse.err:type_name -> vm.Error + 4, // 25: vm.VM.Initialize:input_type -> vm.InitializeRequest + 6, // 26: vm.VM.SetState:input_type -> vm.SetStateRequest + 52, // 27: vm.VM.Shutdown:input_type -> google.protobuf.Empty + 52, // 28: vm.VM.CreateHandlers:input_type -> google.protobuf.Empty + 52, // 29: vm.VM.CreateStaticHandlers:input_type -> google.protobuf.Empty + 31, // 30: vm.VM.Connected:input_type -> vm.ConnectedRequest + 32, // 31: vm.VM.Disconnected:input_type -> vm.DisconnectedRequest + 11, // 32: vm.VM.BuildBlock:input_type -> vm.BuildBlockRequest + 13, // 33: vm.VM.ParseBlock:input_type -> vm.ParseBlockRequest + 15, // 34: vm.VM.GetBlock:input_type -> vm.GetBlockRequest + 17, // 35: vm.VM.SetPreference:input_type -> vm.SetPreferenceRequest + 52, // 36: vm.VM.Health:input_type -> google.protobuf.Empty + 52, // 37: vm.VM.Version:input_type -> google.protobuf.Empty + 24, // 38: vm.VM.AppRequest:input_type -> vm.AppRequestMsg + 25, // 39: vm.VM.AppRequestFailed:input_type -> vm.AppRequestFailedMsg + 26, // 40: vm.VM.AppResponse:input_type -> vm.AppResponseMsg + 27, // 41: vm.VM.AppGossip:input_type -> vm.AppGossipMsg + 52, // 42: vm.VM.Gather:input_type -> google.protobuf.Empty + 28, // 43: vm.VM.CrossChainAppRequest:input_type -> vm.CrossChainAppRequestMsg + 29, // 44: vm.VM.CrossChainAppRequestFailed:input_type -> vm.CrossChainAppRequestFailedMsg + 30, // 45: vm.VM.CrossChainAppResponse:input_type -> vm.CrossChainAppResponseMsg + 33, // 46: vm.VM.GetAncestors:input_type -> vm.GetAncestorsRequest + 35, // 47: vm.VM.BatchedParseBlock:input_type -> vm.BatchedParseBlockRequest + 52, // 48: vm.VM.VerifyHeightIndex:input_type -> google.protobuf.Empty + 38, // 49: vm.VM.GetBlockIDAtHeight:input_type -> vm.GetBlockIDAtHeightRequest + 52, // 50: vm.VM.StateSyncEnabled:input_type -> google.protobuf.Empty + 52, // 51: vm.VM.GetOngoingSyncStateSummary:input_type -> google.protobuf.Empty + 52, // 52: vm.VM.GetLastStateSummary:input_type -> google.protobuf.Empty + 44, // 53: vm.VM.ParseStateSummary:input_type -> vm.ParseStateSummaryRequest + 46, // 54: vm.VM.GetStateSummary:input_type -> vm.GetStateSummaryRequest + 18, // 55: vm.VM.BlockVerify:input_type -> vm.BlockVerifyRequest + 20, // 56: vm.VM.BlockAccept:input_type -> vm.BlockAcceptRequest + 21, // 57: vm.VM.BlockReject:input_type -> vm.BlockRejectRequest + 48, // 58: vm.VM.StateSummaryAccept:input_type -> vm.StateSummaryAcceptRequest + 5, // 59: vm.VM.Initialize:output_type -> vm.InitializeResponse + 7, // 60: vm.VM.SetState:output_type -> vm.SetStateResponse + 52, // 61: vm.VM.Shutdown:output_type -> google.protobuf.Empty + 8, // 62: vm.VM.CreateHandlers:output_type -> vm.CreateHandlersResponse + 9, // 63: vm.VM.CreateStaticHandlers:output_type -> vm.CreateStaticHandlersResponse + 52, // 64: vm.VM.Connected:output_type -> google.protobuf.Empty + 52, // 65: vm.VM.Disconnected:output_type -> google.protobuf.Empty + 12, // 66: vm.VM.BuildBlock:output_type -> vm.BuildBlockResponse + 14, // 67: vm.VM.ParseBlock:output_type -> vm.ParseBlockResponse + 16, // 68: vm.VM.GetBlock:output_type -> vm.GetBlockResponse + 52, // 69: vm.VM.SetPreference:output_type -> google.protobuf.Empty + 22, // 70: vm.VM.Health:output_type -> vm.HealthResponse + 23, // 71: vm.VM.Version:output_type -> vm.VersionResponse + 52, // 72: vm.VM.AppRequest:output_type -> google.protobuf.Empty + 52, // 73: vm.VM.AppRequestFailed:output_type -> google.protobuf.Empty + 52, // 74: vm.VM.AppResponse:output_type -> google.protobuf.Empty + 52, // 75: vm.VM.AppGossip:output_type -> google.protobuf.Empty + 40, // 76: vm.VM.Gather:output_type -> vm.GatherResponse + 52, // 77: vm.VM.CrossChainAppRequest:output_type -> google.protobuf.Empty + 52, // 78: vm.VM.CrossChainAppRequestFailed:output_type -> google.protobuf.Empty + 52, // 79: vm.VM.CrossChainAppResponse:output_type -> google.protobuf.Empty + 34, // 80: vm.VM.GetAncestors:output_type -> vm.GetAncestorsResponse + 36, // 81: vm.VM.BatchedParseBlock:output_type -> vm.BatchedParseBlockResponse + 37, // 82: vm.VM.VerifyHeightIndex:output_type -> vm.VerifyHeightIndexResponse + 39, // 83: vm.VM.GetBlockIDAtHeight:output_type -> vm.GetBlockIDAtHeightResponse + 41, // 84: vm.VM.StateSyncEnabled:output_type -> vm.StateSyncEnabledResponse + 42, // 85: vm.VM.GetOngoingSyncStateSummary:output_type -> vm.GetOngoingSyncStateSummaryResponse + 43, // 86: vm.VM.GetLastStateSummary:output_type -> vm.GetLastStateSummaryResponse + 45, // 87: vm.VM.ParseStateSummary:output_type -> vm.ParseStateSummaryResponse + 47, // 88: vm.VM.GetStateSummary:output_type -> vm.GetStateSummaryResponse + 19, // 89: vm.VM.BlockVerify:output_type -> vm.BlockVerifyResponse + 52, // 90: vm.VM.BlockAccept:output_type -> google.protobuf.Empty + 52, // 91: vm.VM.BlockReject:output_type -> google.protobuf.Empty + 49, // 92: vm.VM.StateSummaryAccept:output_type -> vm.StateSummaryAcceptResponse + 59, // [59:93] is the sub-list for method output_type + 25, // [25:59] is the sub-list for method input_type + 25, // [25:25] is the sub-list for extension type_name + 25, // [25:25] is the sub-list for extension extendee + 0, // [0:25] is the sub-list for field type_name } func init() { file_vm_vm_proto_init() } @@ -3735,18 +3670,6 @@ func file_vm_vm_proto_init() { } } file_vm_vm_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*VersionedDBServer); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_vm_vm_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SetStateRequest); i { case 0: return &v.state @@ -3758,7 +3681,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SetStateResponse); i { case 0: return &v.state @@ -3770,7 +3693,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*CreateHandlersResponse); i { case 0: return &v.state @@ -3782,7 +3705,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*CreateStaticHandlersResponse); i { case 0: return &v.state @@ -3794,7 +3717,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Handler); i { case 0: return &v.state @@ -3806,7 +3729,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*BuildBlockRequest); i { case 0: return &v.state @@ -3818,7 +3741,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*BuildBlockResponse); i { case 0: return &v.state @@ -3830,7 +3753,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ParseBlockRequest); i { case 0: return &v.state @@ -3842,7 +3765,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ParseBlockResponse); i { case 0: return &v.state @@ -3854,7 +3777,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetBlockRequest); i { case 0: return &v.state @@ -3866,7 +3789,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetBlockResponse); i { case 0: return &v.state @@ -3878,7 +3801,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SetPreferenceRequest); i { case 0: return &v.state @@ -3890,7 +3813,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*BlockVerifyRequest); i { case 0: return &v.state @@ -3902,7 +3825,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*BlockVerifyResponse); i { case 0: return &v.state @@ -3914,7 +3837,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*BlockAcceptRequest); i { case 0: return &v.state @@ -3926,7 +3849,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*BlockRejectRequest); i { case 0: return &v.state @@ -3938,7 +3861,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*HealthResponse); i { case 0: return &v.state @@ -3950,7 +3873,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*VersionResponse); i { case 0: return &v.state @@ -3962,7 +3885,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*AppRequestMsg); i { case 0: return &v.state @@ -3974,7 +3897,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*AppRequestFailedMsg); i { case 0: return &v.state @@ -3986,7 +3909,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*AppResponseMsg); i { case 0: return &v.state @@ -3998,7 +3921,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[24].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*AppGossipMsg); i { case 0: return &v.state @@ -4010,7 +3933,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[25].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[24].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*CrossChainAppRequestMsg); i { case 0: return &v.state @@ -4022,7 +3945,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[26].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[25].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*CrossChainAppRequestFailedMsg); i { case 0: return &v.state @@ -4034,7 +3957,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[27].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[26].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*CrossChainAppResponseMsg); i { case 0: return &v.state @@ -4046,7 +3969,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[28].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[27].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ConnectedRequest); i { case 0: return &v.state @@ -4058,7 +3981,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[29].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[28].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*DisconnectedRequest); i { case 0: return &v.state @@ -4070,7 +3993,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[30].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[29].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetAncestorsRequest); i { case 0: return &v.state @@ -4082,7 +4005,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[31].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[30].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetAncestorsResponse); i { case 0: return &v.state @@ -4094,7 +4017,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[32].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[31].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*BatchedParseBlockRequest); i { case 0: return &v.state @@ -4106,7 +4029,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[33].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[32].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*BatchedParseBlockResponse); i { case 0: return &v.state @@ -4118,7 +4041,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[34].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[33].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*VerifyHeightIndexResponse); i { case 0: return &v.state @@ -4130,7 +4053,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[35].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[34].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetBlockIDAtHeightRequest); i { case 0: return &v.state @@ -4142,7 +4065,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[36].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[35].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetBlockIDAtHeightResponse); i { case 0: return &v.state @@ -4154,7 +4077,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[37].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[36].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GatherResponse); i { case 0: return &v.state @@ -4166,7 +4089,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[38].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[37].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*StateSyncEnabledResponse); i { case 0: return &v.state @@ -4178,7 +4101,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[39].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[38].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetOngoingSyncStateSummaryResponse); i { case 0: return &v.state @@ -4190,7 +4113,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[40].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[39].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetLastStateSummaryResponse); i { case 0: return &v.state @@ -4202,7 +4125,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[41].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[40].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ParseStateSummaryRequest); i { case 0: return &v.state @@ -4214,7 +4137,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[42].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[41].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ParseStateSummaryResponse); i { case 0: return &v.state @@ -4226,7 +4149,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[43].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[42].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetStateSummaryRequest); i { case 0: return &v.state @@ -4238,7 +4161,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[44].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[43].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetStateSummaryResponse); i { case 0: return &v.state @@ -4250,7 +4173,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[45].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[44].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*StateSummaryAcceptRequest); i { case 0: return &v.state @@ -4262,7 +4185,7 @@ func file_vm_vm_proto_init() { return nil } } - file_vm_vm_proto_msgTypes[46].Exporter = func(v interface{}, i int) interface{} { + file_vm_vm_proto_msgTypes[45].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*StateSummaryAcceptResponse); i { case 0: return &v.state @@ -4275,15 +4198,15 @@ func file_vm_vm_proto_init() { } } } - file_vm_vm_proto_msgTypes[8].OneofWrappers = []interface{}{} - file_vm_vm_proto_msgTypes[15].OneofWrappers = []interface{}{} + file_vm_vm_proto_msgTypes[7].OneofWrappers = []interface{}{} + file_vm_vm_proto_msgTypes[14].OneofWrappers = []interface{}{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_vm_vm_proto_rawDesc, NumEnums: 4, - NumMessages: 47, + NumMessages: 46, NumExtensions: 0, NumServices: 1, }, diff --git a/proto/vm/vm.proto b/proto/vm/vm.proto index e005dabf66e9..0eca74b46041 100644 --- a/proto/vm/vm.proto +++ b/proto/vm/vm.proto @@ -127,7 +127,7 @@ message InitializeRequest { bytes genesis_bytes = 10; bytes upgrade_bytes = 11; bytes config_bytes = 12; - repeated VersionedDBServer db_servers = 13; + string db_server_addr = 13; // server_addr is the address of the gRPC server which serves // the messenger, keystore, shared memory, blockchain alias, // subnet alias, and appSender services @@ -142,13 +142,6 @@ message InitializeResponse { google.protobuf.Timestamp timestamp = 5; } -message VersionedDBServer { - string version = 1; - // server_addr is the address of the gRPC server which serves the - // Database service - string server_addr = 2; -} - message SetStateRequest { State state = 1; } diff --git a/snow/engine/avalanche/vertex/mock_vm.go b/snow/engine/avalanche/vertex/mock_vm.go index 973ba6690801..b8d2637c7311 100644 --- a/snow/engine/avalanche/vertex/mock_vm.go +++ b/snow/engine/avalanche/vertex/mock_vm.go @@ -13,7 +13,7 @@ import ( reflect "reflect" time "time" - manager "github.com/ava-labs/avalanchego/database/manager" + database "github.com/ava-labs/avalanchego/database" ids "github.com/ava-labs/avalanchego/ids" snow "github.com/ava-labs/avalanchego/snow" snowman "github.com/ava-labs/avalanchego/snow/consensus/snowman" @@ -263,7 +263,7 @@ func (mr *MockLinearizableVMMockRecorder) HealthCheck(arg0 interface{}) *gomock. } // Initialize mocks base method. -func (m *MockLinearizableVM) Initialize(arg0 context.Context, arg1 *snow.Context, arg2 manager.Manager, arg3, arg4, arg5 []byte, arg6 chan<- common.Message, arg7 []*common.Fx, arg8 common.AppSender) error { +func (m *MockLinearizableVM) Initialize(arg0 context.Context, arg1 *snow.Context, arg2 database.Database, arg3, arg4, arg5 []byte, arg6 chan<- common.Message, arg7 []*common.Fx, arg8 common.AppSender) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Initialize", arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ret0, _ := ret[0].(error) diff --git a/snow/engine/common/test_vm.go b/snow/engine/common/test_vm.go index 254401388e6e..9d1a77ef2a9f 100644 --- a/snow/engine/common/test_vm.go +++ b/snow/engine/common/test_vm.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/version" @@ -49,7 +49,7 @@ type TestVM struct { CantAppRequest, CantAppResponse, CantAppGossip, CantAppRequestFailed, CantCrossChainAppRequest, CantCrossChainAppResponse, CantCrossChainAppRequestFailed bool - InitializeF func(ctx context.Context, chainCtx *snow.Context, db manager.Manager, genesisBytes []byte, upgradeBytes []byte, configBytes []byte, msgChan chan<- Message, fxs []*Fx, appSender AppSender) error + InitializeF func(ctx context.Context, chainCtx *snow.Context, db database.Database, genesisBytes []byte, upgradeBytes []byte, configBytes []byte, msgChan chan<- Message, fxs []*Fx, appSender AppSender) error SetStateF func(ctx context.Context, state snow.State) error ShutdownF func(context.Context) error CreateHandlersF func(context.Context) (map[string]http.Handler, error) @@ -89,7 +89,7 @@ func (vm *TestVM) Default(cant bool) { func (vm *TestVM) Initialize( ctx context.Context, chainCtx *snow.Context, - db manager.Manager, + db database.Database, genesisBytes, upgradeBytes, configBytes []byte, diff --git a/snow/engine/common/vm.go b/snow/engine/common/vm.go index 07cfe1272a6c..e77bdd552bbf 100644 --- a/snow/engine/common/vm.go +++ b/snow/engine/common/vm.go @@ -8,7 +8,7 @@ import ( "net/http" "github.com/ava-labs/avalanchego/api/health" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/validators" ) @@ -47,7 +47,7 @@ type VM interface { Initialize( ctx context.Context, chainCtx *snow.Context, - dbManager manager.Manager, + db database.Database, genesisBytes []byte, upgradeBytes []byte, configBytes []byte, diff --git a/snow/engine/snowman/block/mocks/chain_vm.go b/snow/engine/snowman/block/mocks/chain_vm.go index bea5f558d89b..2a2446a94ee5 100644 --- a/snow/engine/snowman/block/mocks/chain_vm.go +++ b/snow/engine/snowman/block/mocks/chain_vm.go @@ -13,7 +13,7 @@ import ( reflect "reflect" time "time" - manager "github.com/ava-labs/avalanchego/database/manager" + database "github.com/ava-labs/avalanchego/database" ids "github.com/ava-labs/avalanchego/ids" snow "github.com/ava-labs/avalanchego/snow" snowman "github.com/ava-labs/avalanchego/snow/consensus/snowman" @@ -262,7 +262,7 @@ func (mr *MockChainVMMockRecorder) HealthCheck(arg0 interface{}) *gomock.Call { } // Initialize mocks base method. -func (m *MockChainVM) Initialize(arg0 context.Context, arg1 *snow.Context, arg2 manager.Manager, arg3, arg4, arg5 []byte, arg6 chan<- common.Message, arg7 []*common.Fx, arg8 common.AppSender) error { +func (m *MockChainVM) Initialize(arg0 context.Context, arg1 *snow.Context, arg2 database.Database, arg3, arg4, arg5 []byte, arg6 chan<- common.Message, arg7 []*common.Fx, arg8 common.AppSender) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Initialize", arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ret0, _ := ret[0].(error) diff --git a/vms/avm/block/builder/builder_test.go b/vms/avm/block/builder/builder_test.go index 244b5db71561..fdab9d6cf064 100644 --- a/vms/avm/block/builder/builder_test.go +++ b/vms/avm/block/builder/builder_test.go @@ -16,7 +16,7 @@ import ( "go.uber.org/mock/gomock" "github.com/ava-labs/avalanchego/codec" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" @@ -26,7 +26,6 @@ import ( "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/avm/block" "github.com/ava-labs/avalanchego/vms/avm/fxs" "github.com/ava-labs/avalanchego/vms/avm/metrics" @@ -525,8 +524,7 @@ func TestBlockBuilderAddLocalTx(t *testing.T) { Codec: parser.Codec(), } - baseDBManager := manager.NewMemDB(version.Semantic1_0_0) - baseDB := versiondb.New(baseDBManager.Current().Database) + baseDB := versiondb.New(memdb.New()) state, err := states.New(baseDB, parser, registerer, trackChecksums) require.NoError(err) diff --git a/vms/avm/environment_test.go b/vms/avm/environment_test.go index 89fa15bd917c..e1e9e29f630e 100644 --- a/vms/avm/environment_test.go +++ b/vms/avm/environment_test.go @@ -15,7 +15,7 @@ import ( "github.com/ava-labs/avalanchego/api/keystore" "github.com/ava-labs/avalanchego/chains/atomic" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" @@ -28,8 +28,8 @@ import ( "github.com/ava-labs/avalanchego/utils/formatting/address" "github.com/ava-labs/avalanchego/utils/json" "github.com/ava-labs/avalanchego/utils/linkedhashmap" + "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/sampler" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/avm/block/executor" "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/fxs" @@ -133,17 +133,15 @@ func setup(tb testing.TB, c *envConfig) *environment { genesisBytes := buildGenesisTestWithArgs(tb, genesisArgs) ctx := newContext(tb) - baseDBManager := manager.NewMemDB(version.Semantic1_0_0) - - m := atomic.NewMemory(prefixdb.New([]byte{0}, baseDBManager.Current().Database)) + baseDB := memdb.New() + m := atomic.NewMemory(prefixdb.New([]byte{0}, baseDB)) ctx.SharedMemory = m.NewSharedMemory(ctx.ChainID) // NB: this lock is intentionally left locked when this function returns. // The caller of this function is responsible for unlocking. ctx.Lock.Lock() - userKeystore, err := keystore.CreateTestKeystore() - require.NoError(err) + userKeystore := keystore.New(logging.NoLog{}, memdb.New()) ctx.Keystore = userKeystore.NewBlockchainKeyStore(ctx.ChainID) for _, user := range c.keystoreUsers { @@ -181,7 +179,7 @@ func setup(tb testing.TB, c *envConfig) *environment { require.NoError(vm.Initialize( context.Background(), ctx, - baseDBManager.NewPrefixDBManager([]byte{1}), + prefixdb.New([]byte{1}, baseDB), genesisBytes, nil, configBytes, diff --git a/vms/avm/txs/executor/semantic_verifier_test.go b/vms/avm/txs/executor/semantic_verifier_test.go index f73fb47a9a9b..72638762c39b 100644 --- a/vms/avm/txs/executor/semantic_verifier_test.go +++ b/vms/avm/txs/executor/semantic_verifier_test.go @@ -13,7 +13,7 @@ import ( "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/validators" @@ -21,7 +21,6 @@ import ( "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/avm/fxs" "github.com/ava-labs/avalanchego/vms/avm/states" "github.com/ava-labs/avalanchego/vms/avm/txs" @@ -882,8 +881,7 @@ func TestSemanticVerifierImportTx(t *testing.T) { validatorState.EXPECT().GetSubnetID(gomock.Any(), ctx.CChainID).AnyTimes().Return(ctx.SubnetID, nil) ctx.ValidatorState = validatorState - baseDBManager := manager.NewMemDB(version.Semantic1_0_0) - m := atomic.NewMemory(prefixdb.New([]byte{0}, baseDBManager.Current().Database)) + m := atomic.NewMemory(prefixdb.New([]byte{0}, memdb.New())) ctx.SharedMemory = m.NewSharedMemory(ctx.ChainID) typeToFxIndex := make(map[reflect.Type]int) diff --git a/vms/avm/vm.go b/vms/avm/vm.go index e115b2d6d640..cae4514ff3a6 100644 --- a/vms/avm/vm.go +++ b/vms/avm/vm.go @@ -20,7 +20,6 @@ import ( "github.com/ava-labs/avalanchego/cache" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/pubsub" @@ -144,7 +143,7 @@ type Config struct { func (vm *VM) Initialize( _ context.Context, ctx *snow.Context, - dbManager manager.Manager, + db database.Database, genesisBytes []byte, _ []byte, configBytes []byte, @@ -181,7 +180,6 @@ func (vm *VM) Initialize( vm.AddressManager = avax.NewAddressManager(ctx) vm.Aliaser = ids.NewAliaser() - db := dbManager.Current().Database vm.ctx = ctx vm.appSender = appSender vm.baseDB = db diff --git a/vms/avm/vm_test.go b/vms/avm/vm_test.go index 10a8ed50d051..3b4dc9558807 100644 --- a/vms/avm/vm_test.go +++ b/vms/avm/vm_test.go @@ -13,12 +13,11 @@ import ( "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/fxs" "github.com/ava-labs/avalanchego/vms/avm/txs" @@ -42,14 +41,14 @@ func TestInvalidGenesis(t *testing.T) { err := vm.Initialize( context.Background(), - ctx, // context - manager.NewMemDB(version.Semantic1_0_0), // dbManager - nil, // genesisState - nil, // upgradeBytes - nil, // configBytes - make(chan common.Message, 1), // engineMessenger - nil, // fxs - nil, // AppSender + ctx, // context + memdb.New(), // database + nil, // genesisState + nil, // upgradeBytes + nil, // configBytes + make(chan common.Message, 1), // engineMessenger + nil, // fxs + nil, // AppSender ) require.ErrorIs(err, codec.ErrCantUnpackVersion) } @@ -68,12 +67,12 @@ func TestInvalidFx(t *testing.T) { genesisBytes := buildGenesisTest(t) err := vm.Initialize( context.Background(), - ctx, // context - manager.NewMemDB(version.Semantic1_0_0), // dbManager - genesisBytes, // genesisState - nil, // upgradeBytes - nil, // configBytes - make(chan common.Message, 1), // engineMessenger + ctx, // context + memdb.New(), // database + genesisBytes, // genesisState + nil, // upgradeBytes + nil, // configBytes + make(chan common.Message, 1), // engineMessenger []*common.Fx{ // fxs nil, }, @@ -96,12 +95,12 @@ func TestFxInitializationFailure(t *testing.T) { genesisBytes := buildGenesisTest(t) err := vm.Initialize( context.Background(), - ctx, // context - manager.NewMemDB(version.Semantic1_0_0), // dbManager - genesisBytes, // genesisState - nil, // upgradeBytes - nil, // configBytes - make(chan common.Message, 1), // engineMessenger + ctx, // context + memdb.New(), // database + genesisBytes, // genesisState + nil, // upgradeBytes + nil, // configBytes + make(chan common.Message, 1), // engineMessenger []*common.Fx{{ // fxs ID: ids.Empty, Fx: &FxTest{ diff --git a/vms/example/xsvm/vm.go b/vms/example/xsvm/vm.go index f164787e9972..3150fc59b481 100644 --- a/vms/example/xsvm/vm.go +++ b/vms/example/xsvm/vm.go @@ -13,7 +13,6 @@ import ( "go.uber.org/zap" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" @@ -52,7 +51,7 @@ type VM struct { func (vm *VM) Initialize( _ context.Context, chainContext *snow.Context, - dbManager manager.Manager, + db database.Database, genesisBytes []byte, _ []byte, _ []byte, @@ -67,8 +66,7 @@ func (vm *VM) Initialize( ) vm.chainContext = chainContext - vm.db = dbManager.Current().Database - + vm.db = db g, err := genesis.Parse(genesisBytes) if err != nil { return fmt.Errorf("failed to parse genesis bytes: %w", err) diff --git a/vms/metervm/block_vm.go b/vms/metervm/block_vm.go index 89200c3561cf..8f9fee1e247d 100644 --- a/vms/metervm/block_vm.go +++ b/vms/metervm/block_vm.go @@ -9,7 +9,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/ava-labs/avalanchego/api/metrics" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/consensus/snowman" @@ -50,7 +50,7 @@ func NewBlockVM(vm block.ChainVM) block.ChainVM { func (vm *blockVM) Initialize( ctx context.Context, chainCtx *snow.Context, - db manager.Manager, + db database.Database, genesisBytes, upgradeBytes, configBytes []byte, diff --git a/vms/metervm/vertex_vm.go b/vms/metervm/vertex_vm.go index aa8a0e71d3d5..827bb535fcbd 100644 --- a/vms/metervm/vertex_vm.go +++ b/vms/metervm/vertex_vm.go @@ -9,7 +9,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/ava-labs/avalanchego/api/metrics" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/consensus/snowstorm" "github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex" @@ -37,7 +37,7 @@ type vertexVM struct { func (vm *vertexVM) Initialize( ctx context.Context, chainCtx *snow.Context, - db manager.Manager, + db database.Database, genesisBytes, upgradeBytes, configBytes []byte, diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index f68f0f4628e4..187c0eb92a70 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -18,7 +18,7 @@ import ( "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" @@ -35,7 +35,6 @@ import ( "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/api" "github.com/ava-labs/avalanchego/vms/platformvm/config" @@ -115,8 +114,7 @@ func newEnvironment(t *testing.T) *environment { } res.isBootstrapped.Set(true) - baseDBManager := manager.NewMemDB(version.Semantic1_0_0) - res.baseDB = versiondb.New(baseDBManager.Current().Database) + res.baseDB = versiondb.New(memdb.New()) res.ctx, res.msm = defaultCtx(res.baseDB) res.ctx.Lock.Lock() diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index c13c4b635343..7d5a67566472 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -19,6 +19,7 @@ import ( "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" "github.com/ava-labs/avalanchego/database" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" @@ -35,7 +36,6 @@ import ( "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/api" "github.com/ava-labs/avalanchego/vms/platformvm/config" @@ -50,7 +50,6 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/utxo" "github.com/ava-labs/avalanchego/vms/secp256k1fx" - db_manager "github.com/ava-labs/avalanchego/database/manager" p_tx_builder "github.com/ava-labs/avalanchego/vms/platformvm/txs/builder" pvalidators "github.com/ava-labs/avalanchego/vms/platformvm/validators" ) @@ -134,8 +133,7 @@ func newEnvironment(t *testing.T, ctrl *gomock.Controller) *environment { } res.isBootstrapped.Set(true) - baseDBManager := db_manager.NewMemDB(version.Semantic1_0_0) - res.baseDB = versiondb.New(baseDBManager.Current().Database) + res.baseDB = versiondb.New(memdb.New()) res.ctx = defaultCtx(res.baseDB) res.fx = defaultFx(res.clk, res.ctx.Log, res.isBootstrapped.Get()) diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 2db9dc2fc6f4..b3eebf31659d 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -23,7 +23,7 @@ import ( "github.com/ava-labs/avalanchego/cache" "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" @@ -35,7 +35,6 @@ import ( "github.com/ava-labs/avalanchego/utils/formatting" "github.com/ava-labs/avalanchego/utils/json" "github.com/ava-labs/avalanchego/utils/logging" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/block" "github.com/ava-labs/avalanchego/vms/platformvm/state" @@ -77,7 +76,7 @@ func defaultService(t *testing.T) (*Service, *mutableSharedMemory) { vm, _, mutableSharedMemory := defaultVM(t) vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - ks := keystore.New(logging.NoLog{}, manager.NewMemDB(version.Semantic1_0_0)) + ks := keystore.New(logging.NoLog{}, memdb.New()) require.NoError(t, ks.CreateUser(testUsername, testPassword)) vm.ctx.Keystore = ks.NewBlockchainKeyStore(vm.ctx.ChainID) @@ -179,7 +178,7 @@ func TestGetTxStatus(t *testing.T) { recipientKey, err := secp256k1.NewPrivateKey() require.NoError(err) - m := atomic.NewMemory(prefixdb.New([]byte{}, service.vm.dbManager.Current().Database)) + m := atomic.NewMemory(prefixdb.New([]byte{}, service.vm.db)) sm := m.NewSharedMemory(service.vm.ctx.ChainID) peerSharedMemory := m.NewSharedMemory(xChainID) diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index cf16196dba63..aee0d184d5f8 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -20,7 +20,7 @@ import ( "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" @@ -36,7 +36,6 @@ import ( "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/api" "github.com/ava-labs/avalanchego/vms/platformvm/config" @@ -117,8 +116,7 @@ func newEnvironment(t *testing.T, postBanff, postCortina bool) *environment { config := defaultConfig(postBanff, postCortina) clk := defaultClock(postBanff || postCortina) - baseDBManager := manager.NewMemDB(version.CurrentDatabase) - baseDB := versiondb.New(baseDBManager.Current().Database) + baseDB := versiondb.New(memdb.New()) ctx, msm := defaultCtx(baseDB) fx := defaultFx(clk, ctx.Log, isBootstrapped.Get()) diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index d984a1a986b0..fab84cc6d50b 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -20,7 +20,7 @@ import ( "github.com/ava-labs/avalanchego/chains" "github.com/ava-labs/avalanchego/chains/atomic" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" @@ -36,7 +36,6 @@ import ( "github.com/ava-labs/avalanchego/utils/json" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/api" "github.com/ava-labs/avalanchego/vms/platformvm/block" @@ -748,9 +747,9 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { }} vm.clock.Set(forkTime.Add(time.Second)) - baseDBManager := manager.NewMemDB(version.Semantic1_0_0) - chainDBManager := baseDBManager.NewPrefixDBManager([]byte{0}) - atomicDB := prefixdb.New([]byte{1}, baseDBManager.Current().Database) + baseDB := memdb.New() + chainDB := prefixdb.New([]byte{0}, baseDB) + atomicDB := prefixdb.New([]byte{1}, baseDB) msgChan := make(chan common.Message, 1) ctx := defaultContext(t) @@ -774,7 +773,7 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) { err = vm.Initialize( context.Background(), ctx, - chainDBManager, + chainDB, genesisBytes, nil, nil, diff --git a/vms/platformvm/vm.go b/vms/platformvm/vm.go index ee2fa308ebdb..c1a911f5b919 100644 --- a/vms/platformvm/vm.go +++ b/vms/platformvm/vm.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/cache" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/consensus/snowman" @@ -72,8 +72,8 @@ type VM struct { uptimeManager uptime.Manager // The context of this vm - ctx *snow.Context - dbManager manager.Manager + ctx *snow.Context + db database.Database state state.State @@ -95,7 +95,7 @@ type VM struct { func (vm *VM) Initialize( ctx context.Context, chainCtx *snow.Context, - dbManager manager.Manager, + db database.Database, genesisBytes []byte, _ []byte, configBytes []byte, @@ -123,7 +123,7 @@ func (vm *VM) Initialize( } vm.ctx = chainCtx - vm.dbManager = dbManager + vm.db = db vm.codecRegistry = linearcodec.NewDefault() vm.fx = &secp256k1fx.Fx{} @@ -134,7 +134,7 @@ func (vm *VM) Initialize( rewards := reward.NewCalculator(vm.RewardConfig) vm.state, err = state.New( - vm.dbManager.Current().Database, + vm.db, genesisBytes, registerer, &vm.Config, @@ -339,7 +339,7 @@ func (vm *VM) SetState(_ context.Context, state snow.State) error { // Shutdown this blockchain func (vm *VM) Shutdown(context.Context) error { - if vm.dbManager == nil { + if vm.db == nil { return nil } @@ -365,7 +365,7 @@ func (vm *VM) Shutdown(context.Context) error { return utils.Err( vm.state.Close(), - vm.dbManager.Close(), + vm.db.Close(), ) } diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 83ac4fd71285..8416c4114662 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/chains" "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/choices" @@ -29,7 +29,6 @@ import ( "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/block" "github.com/ava-labs/avalanchego/vms/platformvm/config" @@ -343,8 +342,8 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { require := require.New(t) _, genesisBytes := defaultGenesis(t) - baseDBManager := manager.NewMemDB(version.Semantic1_0_0) - atomicDB := prefixdb.New([]byte{1}, baseDBManager.Current().Database) + baseDB := memdb.New() + atomicDB := prefixdb.New([]byte{1}, baseDB) vm := &VM{Config: config.Config{ Chains: chains.TestManager, @@ -367,7 +366,7 @@ func TestUnverifiedParentPanicRegression(t *testing.T) { require.NoError(vm.Initialize( context.Background(), ctx, - baseDBManager, + baseDB, genesisBytes, nil, nil, @@ -652,7 +651,7 @@ func TestRejectedStateRegressionInvalidValidatorTimestamp(t *testing.T) { vm.Config.Validators = validators.NewManager() execCfg, _ := config.GetExecutionConfig(nil) newState, err := state.New( - vm.dbManager.Current().Database, + vm.db, nil, prometheus.NewRegistry(), &vm.Config, @@ -961,7 +960,7 @@ func TestRejectedStateRegressionInvalidValidatorReward(t *testing.T) { vm.Config.Validators = validators.NewManager() execCfg, _ := config.GetExecutionConfig(nil) newState, err := state.New( - vm.dbManager.Current().Database, + vm.db, nil, prometheus.NewRegistry(), &vm.Config, diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 691a656af88e..7b0bbba58cdf 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/chains" "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/message" @@ -315,9 +315,9 @@ func defaultVM(t *testing.T) (*VM, database.Database, *mutableSharedMemory) { BanffTime: banffForkTime, }} - baseDBManager := manager.NewMemDB(version.Semantic1_0_0) - chainDBManager := baseDBManager.NewPrefixDBManager([]byte{0}) - atomicDB := prefixdb.New([]byte{1}, baseDBManager.Current().Database) + db := memdb.New() + chainDB := prefixdb.New([]byte{0}, db) + atomicDB := prefixdb.New([]byte{1}, db) vm.clock.Set(banffForkTime.Add(time.Second)) msgChan := make(chan common.Message, 1) @@ -341,7 +341,7 @@ func defaultVM(t *testing.T) (*VM, database.Database, *mutableSharedMemory) { require.NoError(vm.Initialize( context.Background(), ctx, - chainDBManager, + chainDB, genesisBytes, nil, nil, @@ -371,7 +371,7 @@ func defaultVM(t *testing.T) (*VM, database.Database, *mutableSharedMemory) { require.NoError(blk.Accept(context.Background())) require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) - return vm, baseDBManager.Current().Database, msm + return vm, db, msm } // Ensure genesis state is parsed from bytes and stored correctly @@ -1172,9 +1172,9 @@ func TestOptimisticAtomicImport(t *testing.T) { func TestRestartFullyAccepted(t *testing.T) { require := require.New(t) _, genesisBytes := defaultGenesis(t) - db := manager.NewMemDB(version.Semantic1_0_0) + db := memdb.New() - firstDB := db.NewPrefixDBManager([]byte{}) + firstDB := prefixdb.New([]byte{}, db) firstVM := &VM{Config: config.Config{ Chains: chains.TestManager, Validators: validators.NewManager(), @@ -1187,8 +1187,8 @@ func TestRestartFullyAccepted(t *testing.T) { firstCtx := defaultContext(t) - baseDBManager := manager.NewMemDB(version.Semantic1_0_0) - atomicDB := prefixdb.New([]byte{1}, baseDBManager.Current().Database) + baseDB := memdb.New() + atomicDB := prefixdb.New([]byte{1}, baseDB) m := atomic.NewMemory(atomicDB) msm := &mutableSharedMemory{ SharedMemory: m.NewSharedMemory(firstCtx.ChainID), @@ -1279,7 +1279,7 @@ func TestRestartFullyAccepted(t *testing.T) { secondCtx.Lock.Unlock() }() - secondDB := db.NewPrefixDBManager([]byte{}) + secondDB := prefixdb.New([]byte{}, db) secondMsgChan := make(chan common.Message, 1) require.NoError(secondVM.Initialize( context.Background(), @@ -1304,10 +1304,9 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { _, genesisBytes := defaultGenesis(t) - baseDBManager := manager.NewMemDB(version.Semantic1_0_0) - vmDBManager := baseDBManager.NewPrefixDBManager([]byte("vm")) - bootstrappingDB := prefixdb.New([]byte("bootstrapping"), baseDBManager.Current().Database) - + baseDB := memdb.New() + vmDB := prefixdb.New([]byte("vm"), baseDB) + bootstrappingDB := prefixdb.New([]byte("bootstrapping"), baseDB) blocked, err := queue.NewWithMissing(bootstrappingDB, "", prometheus.NewRegistry()) require.NoError(err) @@ -1325,7 +1324,7 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { vm.clock.Set(initialClkTime) ctx := defaultContext(t) - atomicDB := prefixdb.New([]byte{1}, baseDBManager.Current().Database) + atomicDB := prefixdb.New([]byte{1}, baseDB) m := atomic.NewMemory(atomicDB) msm := &mutableSharedMemory{ SharedMemory: m.NewSharedMemory(ctx.ChainID), @@ -1340,7 +1339,7 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { require.NoError(vm.Initialize( context.Background(), ctx, - vmDBManager, + vmDB, genesisBytes, nil, nil, @@ -1630,7 +1629,6 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { func TestUnverifiedParent(t *testing.T) { require := require.New(t) _, genesisBytes := defaultGenesis(t) - dbManager := manager.NewMemDB(version.Semantic1_0_0) vm := &VM{Config: config.Config{ Chains: chains.TestManager, @@ -1655,7 +1653,7 @@ func TestUnverifiedParent(t *testing.T) { require.NoError(vm.Initialize( context.Background(), ctx, - dbManager, + memdb.New(), genesisBytes, nil, nil, @@ -1787,9 +1785,9 @@ func TestMaxStakeAmount(t *testing.T) { func TestUptimeDisallowedWithRestart(t *testing.T) { require := require.New(t) _, genesisBytes := defaultGenesis(t) - db := manager.NewMemDB(version.Semantic1_0_0) + db := memdb.New() - firstDB := db.NewPrefixDBManager([]byte{}) + firstDB := prefixdb.New([]byte{}, db) const firstUptimePercentage = 20 // 20% firstVM := &VM{Config: config.Config{ Chains: chains.TestManager, @@ -1833,7 +1831,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { firstCtx.Lock.Unlock() // Restart the VM with a larger uptime requirement - secondDB := db.NewPrefixDBManager([]byte{}) + secondDB := prefixdb.New([]byte{}, db) const secondUptimePercentage = 21 // 21% > firstUptimePercentage, so uptime for reward is not met now secondVM := &VM{Config: config.Config{ Chains: chains.TestManager, @@ -1925,7 +1923,7 @@ func TestUptimeDisallowedWithRestart(t *testing.T) { func TestUptimeDisallowedAfterNeverConnecting(t *testing.T) { require := require.New(t) _, genesisBytes := defaultGenesis(t) - db := manager.NewMemDB(version.Semantic1_0_0) + db := memdb.New() vm := &VM{Config: config.Config{ Chains: chains.TestManager, diff --git a/vms/proposervm/batched_vm_test.go b/vms/proposervm/batched_vm_test.go index 76f5e7ca31b8..499025c6b2f4 100644 --- a/vms/proposervm/batched_vm_test.go +++ b/vms/proposervm/batched_vm_test.go @@ -11,7 +11,9 @@ import ( "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database" + "github.com/ava-labs/avalanchego/database/memdb" + "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" @@ -21,7 +23,6 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/math" "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/proposervm/proposer" ) @@ -984,7 +985,7 @@ func initTestRemoteProposerVM( coreVM.InitializeF = func( context.Context, *snow.Context, - manager.Manager, + database.Database, []byte, []byte, []byte, @@ -1061,13 +1062,10 @@ func initTestRemoteProposerVM( ctx.NodeID = ids.NodeIDFromCert(pTestCert) ctx.ValidatorState = valState - dummyDBManager := manager.NewMemDB(version.Semantic1_0_0) - // make sure that DBs are compressed correctly - dummyDBManager = dummyDBManager.NewPrefixDBManager([]byte{}) require.NoError(proVM.Initialize( context.Background(), ctx, - dummyDBManager, + prefixdb.New([]byte{}, memdb.New()), // make sure that DBs are compressed correctly initialState, nil, nil, diff --git a/vms/proposervm/post_fork_option_test.go b/vms/proposervm/post_fork_option_test.go index d713faffb551..09fe29730b6f 100644 --- a/vms/proposervm/post_fork_option_test.go +++ b/vms/proposervm/post_fork_option_test.go @@ -12,7 +12,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" @@ -672,7 +671,7 @@ func TestOptionTimestampValidity(t *testing.T) { coreVM.InitializeF = func( context.Context, *snow.Context, - manager.Manager, + database.Database, []byte, []byte, []byte, diff --git a/vms/proposervm/state_syncable_vm_test.go b/vms/proposervm/state_syncable_vm_test.go index 888ea5ebeee3..826f8b877987 100644 --- a/vms/proposervm/state_syncable_vm_test.go +++ b/vms/proposervm/state_syncable_vm_test.go @@ -11,14 +11,14 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" + "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/proposervm/summary" statelessblock "github.com/ava-labs/avalanchego/vms/proposervm/block" @@ -51,7 +51,7 @@ func helperBuildStateSyncTestObjects(t *testing.T) (*fullVM, *VM) { HeightV: 0, BytesV: []byte("genesis state"), } - innerVM.InitializeF = func(context.Context, *snow.Context, manager.Manager, + innerVM.InitializeF = func(context.Context, *snow.Context, database.Database, []byte, []byte, []byte, chan<- common.Message, []*common.Fx, common.AppSender, ) error { @@ -67,10 +67,7 @@ func helperBuildStateSyncTestObjects(t *testing.T) (*fullVM, *VM) { return innerGenesisBlk, nil } - // createVM - dbManager := manager.NewMemDB(version.Semantic1_0_0) - dbManager = dbManager.NewPrefixDBManager([]byte{}) - + // create the VM vm := New( innerVM, time.Time{}, @@ -87,7 +84,7 @@ func helperBuildStateSyncTestObjects(t *testing.T) (*fullVM, *VM) { require.NoError(vm.Initialize( context.Background(), ctx, - dbManager, + prefixdb.New([]byte{}, memdb.New()), innerGenesisBlk.Bytes(), nil, nil, diff --git a/vms/proposervm/vm.go b/vms/proposervm/vm.go index a101be86f574..ae9691ab380e 100644 --- a/vms/proposervm/vm.go +++ b/vms/proposervm/vm.go @@ -18,7 +18,6 @@ import ( "github.com/ava-labs/avalanchego/cache" "github.com/ava-labs/avalanchego/cache/metercacher" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" @@ -167,7 +166,7 @@ func New( func (vm *VM) Initialize( ctx context.Context, chainCtx *snow.Context, - dbManager manager.Manager, + db database.Database, genesisBytes []byte, upgradeBytes []byte, configBytes []byte, @@ -193,9 +192,7 @@ func (vm *VM) Initialize( chainCtx.Metrics = optionalGatherer vm.ctx = chainCtx - rawDB := dbManager.Current().Database - prefixDB := prefixdb.New(dbPrefix, rawDB) - vm.db = versiondb.New(prefixDB) + vm.db = versiondb.New(prefixdb.New(dbPrefix, db)) baseState, err := state.NewMetered(vm.db, "state", registerer) if err != nil { return err @@ -237,7 +234,7 @@ func (vm *VM) Initialize( err = vm.ChainVM.Initialize( ctx, chainCtx, - dbManager, + db, genesisBytes, upgradeBytes, configBytes, diff --git a/vms/proposervm/vm_regression_test.go b/vms/proposervm/vm_regression_test.go index 351d63459ab4..0a27c43e112a 100644 --- a/vms/proposervm/vm_regression_test.go +++ b/vms/proposervm/vm_regression_test.go @@ -11,11 +11,12 @@ import ( "github.com/stretchr/testify/require" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database" + "github.com/ava-labs/avalanchego/database/memdb" + "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" - "github.com/ava-labs/avalanchego/version" ) func TestProposerVMInitializeShouldFailIfInnerVMCantVerifyItsHeightIndex(t *testing.T) { @@ -36,7 +37,7 @@ func TestProposerVMInitializeShouldFailIfInnerVMCantVerifyItsHeightIndex(t *test return customError } - innerVM.InitializeF = func(context.Context, *snow.Context, manager.Manager, + innerVM.InitializeF = func(context.Context, *snow.Context, database.Database, []byte, []byte, []byte, chan<- common.Message, []*common.Fx, common.AppSender, ) error { @@ -58,14 +59,12 @@ func TestProposerVMInitializeShouldFailIfInnerVMCantVerifyItsHeightIndex(t *test }() ctx := snow.DefaultContextTest() - dummyDBManager := manager.NewMemDB(version.Semantic1_0_0) - dummyDBManager = dummyDBManager.NewPrefixDBManager([]byte{}) initialState := []byte("genesis state") err := proVM.Initialize( context.Background(), ctx, - dummyDBManager, + prefixdb.New([]byte{}, memdb.New()), initialState, nil, nil, diff --git a/vms/proposervm/vm_test.go b/vms/proposervm/vm_test.go index 102ec2b37a33..b3c22862f9bf 100644 --- a/vms/proposervm/vm_test.go +++ b/vms/proposervm/vm_test.go @@ -17,7 +17,8 @@ import ( "go.uber.org/mock/gomock" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" + "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" @@ -29,7 +30,6 @@ import ( "github.com/ava-labs/avalanchego/staking" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/timer/mockable" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/proposervm/proposer" "github.com/ava-labs/avalanchego/vms/proposervm/state" @@ -80,7 +80,7 @@ func initTestProposerVM( *validators.TestState, *VM, *snowman.TestBlock, - manager.Manager, + database.Database, ) { require := require.New(t) @@ -106,7 +106,7 @@ func initTestProposerVM( }, } - coreVM.InitializeF = func(context.Context, *snow.Context, manager.Manager, + coreVM.InitializeF = func(context.Context, *snow.Context, database.Database, []byte, []byte, []byte, chan<- common.Message, []*common.Fx, common.AppSender, ) error { @@ -177,8 +177,7 @@ func initTestProposerVM( ctx.NodeID = ids.NodeIDFromCert(pTestCert) ctx.ValidatorState = valState - dummyDBManager := manager.NewMemDB(version.Semantic1_0_0) - dummyDBManager = dummyDBManager.NewPrefixDBManager([]byte{}) + db := prefixdb.New([]byte{0}, memdb.New()) // signal height index is complete coreVM.VerifyHeightIndexF = func(context.Context) error { @@ -188,7 +187,7 @@ func initTestProposerVM( require.NoError(proVM.Initialize( context.Background(), ctx, - dummyDBManager, + db, initialState, nil, nil, @@ -203,7 +202,7 @@ func initTestProposerVM( require.NoError(proVM.SetState(context.Background(), snow.NormalOp)) require.NoError(proVM.SetPreference(context.Background(), coreGenBlk.IDV)) - return coreVM, valState, proVM, coreGenBlk, dummyDBManager + return coreVM, valState, proVM, coreGenBlk, db } // VM.BuildBlock tests section @@ -905,14 +904,13 @@ func TestExpiredBuildBlock(t *testing.T) { ctx.NodeID = ids.NodeIDFromCert(pTestCert) ctx.ValidatorState = valState - dbManager := manager.NewMemDB(version.Semantic1_0_0) toEngine := make(chan common.Message, 1) var toScheduler chan<- common.Message coreVM.InitializeF = func( _ context.Context, _ *snow.Context, - _ manager.Manager, + _ database.Database, _ []byte, _ []byte, _ []byte, @@ -931,7 +929,7 @@ func TestExpiredBuildBlock(t *testing.T) { require.NoError(proVM.Initialize( context.Background(), ctx, - dbManager, + memdb.New(), nil, nil, nil, @@ -1200,7 +1198,7 @@ func TestInnerVMRollback(t *testing.T) { coreVM.InitializeF = func( context.Context, *snow.Context, - manager.Manager, + database.Database, []byte, []byte, []byte, @@ -1214,7 +1212,7 @@ func TestInnerVMRollback(t *testing.T) { return nil } - dbManager := manager.NewMemDB(version.Semantic1_0_0) + db := memdb.New() proVM := New( coreVM, @@ -1229,7 +1227,7 @@ func TestInnerVMRollback(t *testing.T) { require.NoError(proVM.Initialize( context.Background(), ctx, - dbManager, + db, nil, nil, nil, @@ -1316,7 +1314,7 @@ func TestInnerVMRollback(t *testing.T) { require.NoError(proVM.Initialize( context.Background(), ctx, - dbManager, + db, nil, nil, nil, @@ -1769,7 +1767,7 @@ func TestRejectedHeightNotIndexed(t *testing.T) { }, } - coreVM.InitializeF = func(context.Context, *snow.Context, manager.Manager, + coreVM.InitializeF = func(context.Context, *snow.Context, database.Database, []byte, []byte, []byte, chan<- common.Message, []*common.Fx, common.AppSender, ) error { @@ -1839,13 +1837,10 @@ func TestRejectedHeightNotIndexed(t *testing.T) { ctx.NodeID = ids.NodeIDFromCert(pTestCert) ctx.ValidatorState = valState - dummyDBManager := manager.NewMemDB(version.Semantic1_0_0) - // make sure that DBs are compressed correctly - dummyDBManager = dummyDBManager.NewPrefixDBManager([]byte{}) require.NoError(proVM.Initialize( context.Background(), ctx, - dummyDBManager, + prefixdb.New([]byte{}, memdb.New()), // make sure that DBs are compressed correctly initialState, nil, nil, @@ -1973,7 +1968,7 @@ func TestRejectedOptionHeightNotIndexed(t *testing.T) { }, } - coreVM.InitializeF = func(context.Context, *snow.Context, manager.Manager, + coreVM.InitializeF = func(context.Context, *snow.Context, database.Database, []byte, []byte, []byte, chan<- common.Message, []*common.Fx, common.AppSender, ) error { @@ -2043,13 +2038,10 @@ func TestRejectedOptionHeightNotIndexed(t *testing.T) { ctx.NodeID = ids.NodeIDFromCert(pTestCert) ctx.ValidatorState = valState - dummyDBManager := manager.NewMemDB(version.Semantic1_0_0) - // make sure that DBs are compressed correctly - dummyDBManager = dummyDBManager.NewPrefixDBManager([]byte{}) require.NoError(proVM.Initialize( context.Background(), ctx, - dummyDBManager, + prefixdb.New([]byte{}, memdb.New()), // make sure that DBs are compressed correctly initialState, nil, nil, @@ -2169,10 +2161,6 @@ func TestVMInnerBlkCache(t *testing.T) { pTestCert, ) - dummyDBManager := manager.NewMemDB(version.Semantic1_0_0) - // make sure that DBs are compressed correctly - dummyDBManager = dummyDBManager.NewPrefixDBManager([]byte{}) - innerVM.EXPECT().Initialize( gomock.Any(), gomock.Any(), @@ -2200,7 +2188,7 @@ func TestVMInnerBlkCache(t *testing.T) { require.NoError(vm.Initialize( context.Background(), ctx, - dummyDBManager, + prefixdb.New([]byte{}, memdb.New()), // make sure that DBs are compressed correctly nil, nil, nil, @@ -2402,9 +2390,8 @@ func TestVM_VerifyBlockWithContext(t *testing.T) { pTestCert, ) - dummyDBManager := manager.NewMemDB(version.Semantic1_0_0) // make sure that DBs are compressed correctly - dummyDBManager = dummyDBManager.NewPrefixDBManager([]byte{}) + db := prefixdb.New([]byte{}, memdb.New()) innerVM.EXPECT().Initialize( gomock.Any(), @@ -2433,7 +2420,7 @@ func TestVM_VerifyBlockWithContext(t *testing.T) { require.NoError(vm.Initialize( context.Background(), snowCtx, - dummyDBManager, + db, nil, nil, nil, @@ -2552,7 +2539,7 @@ func TestHistoricalBlockDeletion(t *testing.T) { coreVM := &block.TestVM{ TestVM: common.TestVM{ T: t, - InitializeF: func(context.Context, *snow.Context, manager.Manager, []byte, []byte, []byte, chan<- common.Message, []*common.Fx, common.AppSender) error { + InitializeF: func(context.Context, *snow.Context, database.Database, []byte, []byte, []byte, chan<- common.Message, []*common.Fx, common.AppSender) error { return nil }, }, @@ -2601,9 +2588,8 @@ func TestHistoricalBlockDeletion(t *testing.T) { }, } - dummyDBManager := manager.NewMemDB(version.Semantic1_0_0) // make sure that DBs are compressed correctly - dummyDBManager = dummyDBManager.NewPrefixDBManager([]byte{}) + db := prefixdb.New([]byte{}, memdb.New()) proVM := New( coreVM, @@ -2618,7 +2604,7 @@ func TestHistoricalBlockDeletion(t *testing.T) { require.NoError(proVM.Initialize( context.Background(), ctx, - dummyDBManager, + db, initialState, nil, nil, @@ -2716,7 +2702,7 @@ func TestHistoricalBlockDeletion(t *testing.T) { require.NoError(proVM.Initialize( context.Background(), ctx, - dummyDBManager, + db, initialState, nil, nil, @@ -2758,7 +2744,7 @@ func TestHistoricalBlockDeletion(t *testing.T) { require.NoError(proVM.Initialize( context.Background(), ctx, - dummyDBManager, + db, initialState, nil, nil, diff --git a/vms/rpcchainvm/batched_vm_test.go b/vms/rpcchainvm/batched_vm_test.go index dbadedad988f..817037dc6e3e 100644 --- a/vms/rpcchainvm/batched_vm_test.go +++ b/vms/rpcchainvm/batched_vm_test.go @@ -12,14 +12,13 @@ import ( "go.uber.org/mock/gomock" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/engine/snowman/block/mocks" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/chain" ) @@ -88,9 +87,8 @@ func TestBatchedParseBlockCaching(t *testing.T) { defer stopper.Stop(context.Background()) ctx := snow.DefaultContextTest() - dbManager := manager.NewMemDB(version.Semantic1_0_0) - require.NoError(vm.Initialize(context.Background(), ctx, dbManager, nil, nil, nil, nil, nil, nil)) + require.NoError(vm.Initialize(context.Background(), ctx, memdb.New(), nil, nil, nil, nil, nil, nil)) // Call should parse the first block blk, err := vm.ParseBlock(context.Background(), blkBytes1) diff --git a/vms/rpcchainvm/state_syncable_vm_test.go b/vms/rpcchainvm/state_syncable_vm_test.go index ffd486df94eb..241062616c9b 100644 --- a/vms/rpcchainvm/state_syncable_vm_test.go +++ b/vms/rpcchainvm/state_syncable_vm_test.go @@ -13,7 +13,8 @@ import ( "go.uber.org/mock/gomock" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" + "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" @@ -21,7 +22,6 @@ import ( "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/engine/snowman/block/mocks" "github.com/ava-labs/avalanchego/utils/logging" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/rpcchainvm/grpcutils" "github.com/ava-labs/avalanchego/vms/rpcchainvm/runtime" "github.com/ava-labs/avalanchego/vms/rpcchainvm/runtime/subprocess" @@ -471,10 +471,8 @@ func TestLastAcceptedBlockPostStateSummaryAccept(t *testing.T) { // Step 1: initialize VM and check initial LastAcceptedBlock ctx := snow.DefaultContextTest() - dbManager := manager.NewMemDB(version.Semantic1_0_0) - dbManager = dbManager.NewPrefixDBManager([]byte{}) - require.NoError(vm.Initialize(context.Background(), ctx, dbManager, nil, nil, nil, nil, nil, nil)) + require.NoError(vm.Initialize(context.Background(), ctx, prefixdb.New([]byte{}, memdb.New()), nil, nil, nil, nil, nil, nil)) blkID, err := vm.LastAccepted(context.Background()) require.NoError(err) diff --git a/vms/rpcchainvm/vm_client.go b/vms/rpcchainvm/vm_client.go index 430bb18201a5..9a7823979348 100644 --- a/vms/rpcchainvm/vm_client.go +++ b/vms/rpcchainvm/vm_client.go @@ -29,7 +29,6 @@ import ( "github.com/ava-labs/avalanchego/api/metrics" "github.com/ava-labs/avalanchego/chains/atomic/gsharedmemory" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" "github.com/ava-labs/avalanchego/database/rpcdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/ids/galiasreader" @@ -129,7 +128,7 @@ func (vm *VMClient) SetProcess(runtime runtime.Stopper, pid int, processTracker func (vm *VMClient) Initialize( ctx context.Context, chainCtx *snow.Context, - dbManager manager.Manager, + db database.Database, genesisBytes []byte, upgradeBytes []byte, configBytes []byte, @@ -155,33 +154,21 @@ func (vm *VMClient) Initialize( return err } - // Initialize and serve each database and construct the db manager - // initialize request parameters - versionedDBs := dbManager.GetDatabases() - versionedDBServers := make([]*vmpb.VersionedDBServer, len(versionedDBs)) - for i, semDB := range versionedDBs { - dbVersion := semDB.Version.String() - serverListener, err := grpcutils.NewListener() - if err != nil { - return err - } - serverAddr := serverListener.Addr().String() - - go grpcutils.Serve(serverListener, vm.newDBServer(semDB.Database)) - chainCtx.Log.Info("grpc: serving database", - zap.String("version", dbVersion), - zap.String("address", serverAddr), - ) - - versionedDBServers[i] = &vmpb.VersionedDBServer{ - ServerAddr: serverAddr, - Version: dbVersion, - } + // Initialize the database + dbServerListener, err := grpcutils.NewListener() + if err != nil { + return err } + dbServerAddr := dbServerListener.Addr().String() + + go grpcutils.Serve(dbServerListener, vm.newDBServer(db)) + chainCtx.Log.Info("grpc: serving database", + zap.String("address", dbServerAddr), + ) vm.messenger = messenger.NewServer(toEngine) vm.keystore = gkeystore.NewServer(chainCtx.Keystore) - vm.sharedMemory = gsharedmemory.NewServer(chainCtx.SharedMemory, dbManager.Current().Database) + vm.sharedMemory = gsharedmemory.NewServer(chainCtx.SharedMemory, db) vm.bcLookup = galiasreader.NewServer(chainCtx.BCLookup) vm.appSender = appsender.NewServer(appSender) vm.validatorStateServer = gvalidators.NewServer(chainCtx.ValidatorState) @@ -211,7 +198,7 @@ func (vm *VMClient) Initialize( GenesisBytes: genesisBytes, UpgradeBytes: upgradeBytes, ConfigBytes: configBytes, - DbServers: versionedDBServers, + DbServerAddr: dbServerAddr, ServerAddr: serverAddr, }) if err != nil { diff --git a/vms/rpcchainvm/vm_server.go b/vms/rpcchainvm/vm_server.go index 6f78009d0f41..7ee82a241506 100644 --- a/vms/rpcchainvm/vm_server.go +++ b/vms/rpcchainvm/vm_server.go @@ -21,8 +21,8 @@ import ( "github.com/ava-labs/avalanchego/api/keystore/gkeystore" "github.com/ava-labs/avalanchego/api/metrics" "github.com/ava-labs/avalanchego/chains/atomic/gsharedmemory" + "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/database/corruptabledb" - "github.com/ava-labs/avalanchego/database/manager" "github.com/ava-labs/avalanchego/database/rpcdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/ids/galiasreader" @@ -75,7 +75,7 @@ type VMServer struct { allowShutdown *utils.Atomic[bool] processMetrics prometheus.Gatherer - dbManager manager.Manager + db database.Database log logging.Logger serverCloser grpcutils.ServerCloser @@ -150,40 +150,19 @@ func (vm *VMServer) Initialize(ctx context.Context, req *vmpb.InitializeRequest) // Register metrics for each Go plugin processes vm.processMetrics = registerer - // Dial each database in the request and construct the database manager - versionedDBs := make([]*manager.VersionedDatabase, len(req.DbServers)) - for i, vDBReq := range req.DbServers { - version, err := version.Parse(vDBReq.Version) - if err != nil { - // Ignore closing errors to return the original error - _ = vm.connCloser.Close() - return nil, err - } - - clientConn, err := grpcutils.Dial( - vDBReq.ServerAddr, - grpcutils.WithChainUnaryInterceptor(grpcClientMetrics.UnaryClientInterceptor()), - grpcutils.WithChainStreamInterceptor(grpcClientMetrics.StreamClientInterceptor()), - ) - if err != nil { - // Ignore closing errors to return the original error - _ = vm.connCloser.Close() - return nil, err - } - vm.connCloser.Add(clientConn) - db := rpcdb.NewClient(rpcdbpb.NewDatabaseClient(clientConn)) - versionedDBs[i] = &manager.VersionedDatabase{ - Database: corruptabledb.New(db), - Version: version, - } - } - dbManager, err := manager.NewManagerFromDBs(versionedDBs) + // Dial the database + dbClientConn, err := grpcutils.Dial( + req.DbServerAddr, + grpcutils.WithChainUnaryInterceptor(grpcClientMetrics.UnaryClientInterceptor()), + grpcutils.WithChainStreamInterceptor(grpcClientMetrics.StreamClientInterceptor()), + ) if err != nil { - // Ignore closing errors to return the original error - _ = vm.connCloser.Close() return nil, err } - vm.dbManager = dbManager + vm.connCloser.Add(dbClientConn) + vm.db = corruptabledb.New( + rpcdb.NewClient(rpcdbpb.NewDatabaseClient(dbClientConn)), + ) // TODO: Allow the logger to be configured by the client vm.log = logging.NewLogger( @@ -259,7 +238,7 @@ func (vm *VMServer) Initialize(ctx context.Context, req *vmpb.InitializeRequest) ChainDataDir: req.ChainDataDir, } - if err := vm.vm.Initialize(ctx, vm.ctx, dbManager, req.GenesisBytes, req.UpgradeBytes, req.ConfigBytes, toEngine, nil, appSenderClient); err != nil { + if err := vm.vm.Initialize(ctx, vm.ctx, vm.db, req.GenesisBytes, req.UpgradeBytes, req.ConfigBytes, toEngine, nil, appSenderClient); err != nil { // Ignore errors closing resources to return the original error _ = vm.connCloser.Close() close(vm.closed) @@ -518,7 +497,7 @@ func (vm *VMServer) Health(ctx context.Context, _ *emptypb.Empty) (*vmpb.HealthR if err != nil { return &vmpb.HealthResponse{}, err } - dbHealth, err := vm.dbHealthChecks(ctx) + dbHealth, err := vm.db.HealthCheck(ctx) if err != nil { return &vmpb.HealthResponse{}, err } @@ -533,22 +512,6 @@ func (vm *VMServer) Health(ctx context.Context, _ *emptypb.Empty) (*vmpb.HealthR }, err } -func (vm *VMServer) dbHealthChecks(ctx context.Context) (interface{}, error) { - details := make(map[string]interface{}, len(vm.dbManager.GetDatabases())) - - // Check Database health - for _, client := range vm.dbManager.GetDatabases() { - // Shared gRPC client don't close - health, err := client.Database.HealthCheck(ctx) - if err != nil { - return nil, fmt.Errorf("failed to check db health %q: %w", client.Version.String(), err) - } - details[client.Version.String()] = health - } - - return details, nil -} - func (vm *VMServer) Version(ctx context.Context, _ *emptypb.Empty) (*vmpb.VersionResponse, error) { version, err := vm.vm.Version(ctx) return &vmpb.VersionResponse{ diff --git a/vms/rpcchainvm/with_context_vm_test.go b/vms/rpcchainvm/with_context_vm_test.go index a6d72e1a64bb..65d1e4396964 100644 --- a/vms/rpcchainvm/with_context_vm_test.go +++ b/vms/rpcchainvm/with_context_vm_test.go @@ -12,13 +12,12 @@ import ( "go.uber.org/mock/gomock" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/engine/snowman/block/mocks" - "github.com/ava-labs/avalanchego/version" ) var ( @@ -100,9 +99,8 @@ func TestContextVMSummary(t *testing.T) { defer stopper.Stop(context.Background()) ctx := snow.DefaultContextTest() - dbManager := manager.NewMemDB(version.Semantic1_0_0) - require.NoError(vm.Initialize(context.Background(), ctx, dbManager, nil, nil, nil, nil, nil, nil)) + require.NoError(vm.Initialize(context.Background(), ctx, memdb.New(), nil, nil, nil, nil, nil, nil)) blkIntf, err := vm.BuildBlockWithContext(context.Background(), blockContext) require.NoError(err) diff --git a/vms/tracedvm/block_vm.go b/vms/tracedvm/block_vm.go index b82466f3a420..969a6bc09637 100644 --- a/vms/tracedvm/block_vm.go +++ b/vms/tracedvm/block_vm.go @@ -11,7 +11,7 @@ import ( oteltrace "go.opentelemetry.io/otel/trace" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/consensus/snowman" @@ -100,7 +100,7 @@ func NewBlockVM(vm block.ChainVM, name string, tracer trace.Tracer) block.ChainV func (vm *blockVM) Initialize( ctx context.Context, chainCtx *snow.Context, - db manager.Manager, + db database.Database, genesisBytes, upgradeBytes, configBytes []byte, diff --git a/vms/tracedvm/vertex_vm.go b/vms/tracedvm/vertex_vm.go index 9c23f882ea40..53189f5cee70 100644 --- a/vms/tracedvm/vertex_vm.go +++ b/vms/tracedvm/vertex_vm.go @@ -10,7 +10,7 @@ import ( oteltrace "go.opentelemetry.io/otel/trace" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/consensus/snowstorm" "github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex" @@ -35,7 +35,7 @@ func NewVertexVM(vm vertex.LinearizableVMWithEngine, tracer trace.Tracer) vertex func (vm *vertexVM) Initialize( ctx context.Context, chainCtx *snow.Context, - db manager.Manager, + db database.Database, genesisBytes, upgradeBytes, configBytes []byte, From 047d493084c9e5cad6ecf98ea9e4ee3e19b4c460 Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Tue, 31 Oct 2023 18:14:14 -0400 Subject: [PATCH 15/19] Add `BaseTx` support to platformvm (#2232) Signed-off-by: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> --- vms/platformvm/metrics/tx_metrics.go | 9 +- vms/platformvm/txs/base_tx.go | 6 + vms/platformvm/txs/base_tx_test.go | 450 ++++++++++++++++-- vms/platformvm/txs/builder/builder.go | 51 ++ vms/platformvm/txs/builder/mock_builder.go | 16 + vms/platformvm/txs/codec.go | 6 +- .../txs/executor/atomic_tx_executor.go | 4 + .../txs/executor/proposal_tx_executor.go | 4 + .../txs/executor/standard_tx_executor.go | 31 ++ .../txs/executor/tx_mempool_verifier.go | 4 + vms/platformvm/txs/mempool/issuer.go | 5 + vms/platformvm/txs/mempool/remover.go | 5 + vms/platformvm/txs/visitor.go | 1 + vms/platformvm/vm_test.go | 75 +++ wallet/chain/p/backend_visitor.go | 4 + wallet/chain/p/signer_visitor.go | 8 + 16 files changed, 641 insertions(+), 38 deletions(-) diff --git a/vms/platformvm/metrics/tx_metrics.go b/vms/platformvm/metrics/tx_metrics.go index 17d6a090957b..9ed07bce7ec9 100644 --- a/vms/platformvm/metrics/tx_metrics.go +++ b/vms/platformvm/metrics/tx_metrics.go @@ -28,7 +28,8 @@ type txMetrics struct { numTransformSubnetTxs, numAddPermissionlessValidatorTxs, numAddPermissionlessDelegatorTxs, - numTransferSubnetOwnershipTxs prometheus.Counter + numTransferSubnetOwnershipTxs, + numBaseTxs prometheus.Counter } func newTxMetrics( @@ -51,6 +52,7 @@ func newTxMetrics( numAddPermissionlessValidatorTxs: newTxMetric(namespace, "add_permissionless_validator", registerer, &errs), numAddPermissionlessDelegatorTxs: newTxMetric(namespace, "add_permissionless_delegator", registerer, &errs), numTransferSubnetOwnershipTxs: newTxMetric(namespace, "transfer_subnet_ownership", registerer, &errs), + numBaseTxs: newTxMetric(namespace, "base", registerer, &errs), } return m, errs.Err } @@ -139,3 +141,8 @@ func (m *txMetrics) TransferSubnetOwnershipTx(*txs.TransferSubnetOwnershipTx) er m.numTransferSubnetOwnershipTxs.Inc() return nil } + +func (m *txMetrics) BaseTx(*txs.BaseTx) error { + m.numBaseTxs.Inc() + return nil +} diff --git a/vms/platformvm/txs/base_tx.go b/vms/platformvm/txs/base_tx.go index 2aa95f56cc68..5ffb308fe425 100644 --- a/vms/platformvm/txs/base_tx.go +++ b/vms/platformvm/txs/base_tx.go @@ -16,6 +16,8 @@ import ( ) var ( + _ UnsignedTx = (*BaseTx)(nil) + ErrNilTx = errors.New("tx is nil") errOutputsNotSorted = errors.New("outputs not sorted") @@ -96,3 +98,7 @@ func (tx *BaseTx) SyntacticVerify(ctx *snow.Context) error { return nil } } + +func (tx *BaseTx) Visit(visitor Visitor) error { + return visitor.BaseTx(tx) +} diff --git a/vms/platformvm/txs/base_tx_test.go b/vms/platformvm/txs/base_tx_test.go index 073b27f25056..c6cba1570312 100644 --- a/vms/platformvm/txs/base_tx_test.go +++ b/vms/platformvm/txs/base_tx_test.go @@ -10,65 +10,443 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/utils" + "github.com/ava-labs/avalanchego/utils/constants" + "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/avax" + "github.com/ava-labs/avalanchego/vms/platformvm/stakeable" + "github.com/ava-labs/avalanchego/vms/secp256k1fx" + "github.com/ava-labs/avalanchego/vms/types" ) -func TestBaseTxMarshalJSON(t *testing.T) { +func TestBaseTxSerialization(t *testing.T) { require := require.New(t) - blockchainID := ids.ID{1} - utxoTxID := ids.ID{2} - assetID := ids.ID{3} - fxID := ids.ID{4} - tx := &BaseTx{BaseTx: avax.BaseTx{ - BlockchainID: blockchainID, - NetworkID: 4, - Ins: []*avax.TransferableInput{ - { - FxID: fxID, - UTXOID: avax.UTXOID{TxID: utxoTxID, OutputIndex: 5}, - Asset: avax.Asset{ID: assetID}, - In: &avax.TestTransferable{Val: 100}, + addr := ids.ShortID{ + 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, + 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, + 0x44, 0x55, 0x66, 0x77, + } + + avaxAssetID, err := ids.FromString("FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z") + require.NoError(err) + + customAssetID := ids.ID{ + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + } + + txID := ids.ID{ + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + } + + simpleBaseTx := &BaseTx{ + BaseTx: avax.BaseTx{ + NetworkID: constants.MainnetID, + BlockchainID: constants.PlatformChainID, + Outs: []*avax.TransferableOutput{}, + Ins: []*avax.TransferableInput{ + { + UTXOID: avax.UTXOID{ + TxID: txID, + OutputIndex: 1, + }, + Asset: avax.Asset{ + ID: avaxAssetID, + }, + In: &secp256k1fx.TransferInput{ + Amt: units.MilliAvax, + Input: secp256k1fx.Input{ + SigIndices: []uint32{5}, + }, + }, + }, }, + Memo: types.JSONByteSlice{}, }, - Outs: []*avax.TransferableOutput{ - { - FxID: fxID, - Asset: avax.Asset{ID: assetID}, - Out: &avax.TestTransferable{Val: 100}, + } + require.NoError(simpleBaseTx.SyntacticVerify(&snow.Context{ + NetworkID: 1, + ChainID: constants.PlatformChainID, + AVAXAssetID: avaxAssetID, + })) + + expectedUnsignedSimpleBaseTxBytes := []byte{ + // Codec version + 0x00, 0x00, + // BaseTx Type ID + 0x00, 0x00, 0x00, 0x22, + // Mainnet network ID + 0x00, 0x00, 0x00, 0x01, + // P-chain blockchain ID + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Number of outputs + 0x00, 0x00, 0x00, 0x00, + // Number of inputs + 0x00, 0x00, 0x00, 0x01, + // Inputs[0] + // TxID + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + // Tx output index + 0x00, 0x00, 0x00, 0x01, + // Mainnet AVAX assetID + 0x21, 0xe6, 0x73, 0x17, 0xcb, 0xc4, 0xbe, 0x2a, + 0xeb, 0x00, 0x67, 0x7a, 0xd6, 0x46, 0x27, 0x78, + 0xa8, 0xf5, 0x22, 0x74, 0xb9, 0xd6, 0x05, 0xdf, + 0x25, 0x91, 0xb2, 0x30, 0x27, 0xa8, 0x7d, 0xff, + // secp256k1fx transfer input type ID + 0x00, 0x00, 0x00, 0x05, + // input amount = 1 MilliAvax + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x42, 0x40, + // number of signatures needed in input + 0x00, 0x00, 0x00, 0x01, + // index of signer + 0x00, 0x00, 0x00, 0x05, + // length of memo + 0x00, 0x00, 0x00, 0x00, + } + var unsignedSimpleBaseTx UnsignedTx = simpleBaseTx + unsignedSimpleBaseTxBytes, err := Codec.Marshal(Version, &unsignedSimpleBaseTx) + require.NoError(err) + require.Equal(expectedUnsignedSimpleBaseTxBytes, unsignedSimpleBaseTxBytes) + + complexBaseTx := &BaseTx{ + BaseTx: avax.BaseTx{ + NetworkID: constants.MainnetID, + BlockchainID: constants.PlatformChainID, + Outs: []*avax.TransferableOutput{ + { + Asset: avax.Asset{ + ID: avaxAssetID, + }, + Out: &stakeable.LockOut{ + Locktime: 87654321, + TransferableOut: &secp256k1fx.TransferOutput{ + Amt: 1, + OutputOwners: secp256k1fx.OutputOwners{ + Locktime: 12345678, + Threshold: 0, + Addrs: []ids.ShortID{}, + }, + }, + }, + }, + { + Asset: avax.Asset{ + ID: customAssetID, + }, + Out: &stakeable.LockOut{ + Locktime: 876543210, + TransferableOut: &secp256k1fx.TransferOutput{ + Amt: 0xffffffffffffffff, + OutputOwners: secp256k1fx.OutputOwners{ + Locktime: 0, + Threshold: 1, + Addrs: []ids.ShortID{ + addr, + }, + }, + }, + }, + }, + }, + Ins: []*avax.TransferableInput{ + { + UTXOID: avax.UTXOID{ + TxID: txID, + OutputIndex: 1, + }, + Asset: avax.Asset{ + ID: avaxAssetID, + }, + In: &secp256k1fx.TransferInput{ + Amt: units.Avax, + Input: secp256k1fx.Input{ + SigIndices: []uint32{2, 5}, + }, + }, + }, + { + UTXOID: avax.UTXOID{ + TxID: txID, + OutputIndex: 2, + }, + Asset: avax.Asset{ + ID: customAssetID, + }, + In: &stakeable.LockIn{ + Locktime: 876543210, + TransferableIn: &secp256k1fx.TransferInput{ + Amt: 0xefffffffffffffff, + Input: secp256k1fx.Input{ + SigIndices: []uint32{0}, + }, + }, + }, + }, + { + UTXOID: avax.UTXOID{ + TxID: txID, + OutputIndex: 3, + }, + Asset: avax.Asset{ + ID: customAssetID, + }, + In: &secp256k1fx.TransferInput{ + Amt: 0x1000000000000000, + Input: secp256k1fx.Input{ + SigIndices: []uint32{}, + }, + }, + }, }, + Memo: types.JSONByteSlice("😅\nwell that's\x01\x23\x45!"), }, - Memo: []byte{1, 2, 3}, - }} + } + avax.SortTransferableOutputs(complexBaseTx.Outs, Codec) + utils.Sort(complexBaseTx.Ins) + require.NoError(complexBaseTx.SyntacticVerify(&snow.Context{ + NetworkID: 1, + ChainID: constants.PlatformChainID, + AVAXAssetID: avaxAssetID, + })) - txJSONBytes, err := json.MarshalIndent(tx, "", "\t") + expectedUnsignedComplexBaseTxBytes := []byte{ + // Codec version + 0x00, 0x00, + // BaseTx Type ID + 0x00, 0x00, 0x00, 0x22, + // Mainnet network ID + 0x00, 0x00, 0x00, 0x01, + // P-chain blockchain ID + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Number of outputs + 0x00, 0x00, 0x00, 0x02, + // Outputs[0] + // Mainnet AVAX assetID + 0x21, 0xe6, 0x73, 0x17, 0xcb, 0xc4, 0xbe, 0x2a, + 0xeb, 0x00, 0x67, 0x7a, 0xd6, 0x46, 0x27, 0x78, + 0xa8, 0xf5, 0x22, 0x74, 0xb9, 0xd6, 0x05, 0xdf, + 0x25, 0x91, 0xb2, 0x30, 0x27, 0xa8, 0x7d, 0xff, + // Stakeable locked output type ID + 0x00, 0x00, 0x00, 0x16, + // Locktime + 0x00, 0x00, 0x00, 0x00, 0x05, 0x39, 0x7f, 0xb1, + // secp256k1fx transfer output type ID + 0x00, 0x00, 0x00, 0x07, + // amount + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + // secp256k1fx output locktime + 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x61, 0x4e, + // threshold + 0x00, 0x00, 0x00, 0x00, + // number of addresses + 0x00, 0x00, 0x00, 0x00, + // Outputs[1] + // custom asset ID + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + // Stakeable locked output type ID + 0x00, 0x00, 0x00, 0x16, + // Locktime + 0x00, 0x00, 0x00, 0x00, 0x34, 0x3e, 0xfc, 0xea, + // secp256k1fx transfer output type ID + 0x00, 0x00, 0x00, 0x07, + // amount + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + // secp256k1fx output locktime + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // threshold + 0x00, 0x00, 0x00, 0x01, + // number of addresses + 0x00, 0x00, 0x00, 0x01, + // address[0] + 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, + 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, + 0x44, 0x55, 0x66, 0x77, + // number of inputs + 0x00, 0x00, 0x00, 0x03, + // inputs[0] + // TxID + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + // Tx output index + 0x00, 0x00, 0x00, 0x01, + // Mainnet AVAX assetID + 0x21, 0xe6, 0x73, 0x17, 0xcb, 0xc4, 0xbe, 0x2a, + 0xeb, 0x00, 0x67, 0x7a, 0xd6, 0x46, 0x27, 0x78, + 0xa8, 0xf5, 0x22, 0x74, 0xb9, 0xd6, 0x05, 0xdf, + 0x25, 0x91, 0xb2, 0x30, 0x27, 0xa8, 0x7d, 0xff, + // secp256k1fx transfer input type ID + 0x00, 0x00, 0x00, 0x05, + // input amount = 1 Avax + 0x00, 0x00, 0x00, 0x00, 0x3b, 0x9a, 0xca, 0x00, + // number of signatures needed in input + 0x00, 0x00, 0x00, 0x02, + // index of first signer + 0x00, 0x00, 0x00, 0x02, + // index of second signer + 0x00, 0x00, 0x00, 0x05, + // inputs[1] + // TxID + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + // Tx output index + 0x00, 0x00, 0x00, 0x02, + // Custom asset ID + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + // Stakeable locked input type ID + 0x00, 0x00, 0x00, 0x15, + // Locktime + 0x00, 0x00, 0x00, 0x00, 0x34, 0x3e, 0xfc, 0xea, + // secp256k1fx transfer input type ID + 0x00, 0x00, 0x00, 0x05, + // input amount + 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + // number of signatures needed in input + 0x00, 0x00, 0x00, 0x01, + // index of signer + 0x00, 0x00, 0x00, 0x00, + // inputs[2] + // TxID + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, + // Tx output index + 0x00, 0x00, 0x00, 0x03, + // custom asset ID + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + 0x99, 0x77, 0x55, 0x77, 0x11, 0x33, 0x55, 0x31, + // secp256k1fx transfer input type ID + 0x00, 0x00, 0x00, 0x05, + // input amount + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // number of signatures needed in input + 0x00, 0x00, 0x00, 0x00, + // length of memo + 0x00, 0x00, 0x00, 0x14, + // memo + 0xf0, 0x9f, 0x98, 0x85, 0x0a, 0x77, 0x65, 0x6c, + 0x6c, 0x20, 0x74, 0x68, 0x61, 0x74, 0x27, 0x73, + 0x01, 0x23, 0x45, 0x21, + } + var unsignedComplexBaseTx UnsignedTx = complexBaseTx + unsignedComplexBaseTxBytes, err := Codec.Marshal(Version, &unsignedComplexBaseTx) require.NoError(err) + require.Equal(expectedUnsignedComplexBaseTxBytes, unsignedComplexBaseTxBytes) + aliaser := ids.NewAliaser() + require.NoError(aliaser.Alias(constants.PlatformChainID, "P")) + + unsignedComplexBaseTx.InitCtx(&snow.Context{ + NetworkID: 1, + ChainID: constants.PlatformChainID, + AVAXAssetID: avaxAssetID, + BCLookup: aliaser, + }) + + unsignedComplexBaseTxJSONBytes, err := json.MarshalIndent(unsignedComplexBaseTx, "", "\t") + require.NoError(err) require.Equal(`{ - "networkID": 4, - "blockchainID": "SYXsAycDPUu4z2ZksJD5fh5nTDcH3vCFHnpcVye5XuJ2jArg", + "networkID": 1, + "blockchainID": "11111111111111111111111111111111LpoYY", "outputs": [ { - "assetID": "2KdbbWvpeAShCx5hGbtdF15FMMepq9kajsNTqVvvEbhiCRSxU", - "fxID": "2mB8TguRrYvbGw7G2UBqKfmL8osS7CfmzAAHSzuZK8bwpRKdY", + "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", "output": { - "Err": null, - "Val": 100 + "locktime": 87654321, + "output": { + "addresses": [], + "amount": 1, + "locktime": 12345678, + "threshold": 0 + } + } + }, + { + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "output": { + "locktime": 876543210, + "output": { + "addresses": [ + "P-avax1g32kvaugnx4tk3z4vemc3xd2hdz92enh972wxr" + ], + "amount": 18446744073709551615, + "locktime": 0, + "threshold": 1 + } } } ], "inputs": [ { - "txID": "t64jLxDRmxo8y48WjbRALPAZuSDZ6qPVaaeDzxHA4oSojhLt", - "outputIndex": 5, - "assetID": "2KdbbWvpeAShCx5hGbtdF15FMMepq9kajsNTqVvvEbhiCRSxU", - "fxID": "2mB8TguRrYvbGw7G2UBqKfmL8osS7CfmzAAHSzuZK8bwpRKdY", + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 1, + "assetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "input": { + "amount": 1000000000, + "signatureIndices": [ + 2, + 5 + ] + } + }, + { + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 2, + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", + "input": { + "locktime": 876543210, + "input": { + "amount": 17293822569102704639, + "signatureIndices": [ + 0 + ] + } + } + }, + { + "txID": "2wiU5PnFTjTmoAXGZutHAsPF36qGGyLHYHj9G1Aucfmb3JFFGN", + "outputIndex": 3, + "assetID": "2Ab62uWwJw1T6VvmKD36ufsiuGZuX1pGykXAvPX1LtjTRHxwcc", + "fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ", "input": { - "Err": null, - "Val": 100 + "amount": 1152921504606846976, + "signatureIndices": [] } } ], - "memo": "0x010203" -}`, string(txJSONBytes)) + "memo": "0xf09f98850a77656c6c2074686174277301234521" +}`, string(unsignedComplexBaseTxJSONBytes)) } diff --git a/vms/platformvm/txs/builder/builder.go b/vms/platformvm/txs/builder/builder.go index 3f13ec2ecad9..6c796d085abb 100644 --- a/vms/platformvm/txs/builder/builder.go +++ b/vms/platformvm/txs/builder/builder.go @@ -92,6 +92,17 @@ type DecisionTxBuilder interface { keys []*secp256k1.PrivateKey, changeAddr ids.ShortID, ) (*txs.Tx, error) + + // amount: amount the sender is sending + // owner: recipient of the funds + // keys: keys to sign the tx and pay the amount + // changeAddr: address to send change to, if there is any + NewBaseTx( + amount uint64, + owner secp256k1fx.OutputOwners, + keys []*secp256k1.PrivateKey, + changeAddr ids.ShortID, + ) (*txs.Tx, error) } type ProposalTxBuilder interface { @@ -661,3 +672,43 @@ func (b *builder) NewTransferSubnetOwnershipTx( } return tx, tx.SyntacticVerify(b.ctx) } + +func (b *builder) NewBaseTx( + amount uint64, + owner secp256k1fx.OutputOwners, + keys []*secp256k1.PrivateKey, + changeAddr ids.ShortID, +) (*txs.Tx, error) { + toBurn, err := math.Add64(amount, b.cfg.TxFee) + if err != nil { + return nil, fmt.Errorf("amount (%d) + tx fee(%d) overflows", amount, b.cfg.TxFee) + } + ins, outs, _, signers, err := b.Spend(b.state, keys, 0, toBurn, changeAddr) + if err != nil { + return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err) + } + + outs = append(outs, &avax.TransferableOutput{ + Asset: avax.Asset{ID: b.ctx.AVAXAssetID}, + Out: &secp256k1fx.TransferOutput{ + Amt: amount, + OutputOwners: owner, + }, + }) + + avax.SortTransferableOutputs(outs, txs.Codec) + + utx := &txs.BaseTx{ + BaseTx: avax.BaseTx{ + NetworkID: b.ctx.NetworkID, + BlockchainID: b.ctx.ChainID, + Ins: ins, + Outs: outs, + }, + } + tx, err := txs.NewSigned(utx, txs.Codec, signers) + if err != nil { + return nil, err + } + return tx, tx.SyntacticVerify(b.ctx) +} diff --git a/vms/platformvm/txs/builder/mock_builder.go b/vms/platformvm/txs/builder/mock_builder.go index 79291afb7cd7..19f74a7bed2f 100644 --- a/vms/platformvm/txs/builder/mock_builder.go +++ b/vms/platformvm/txs/builder/mock_builder.go @@ -14,6 +14,7 @@ import ( ids "github.com/ava-labs/avalanchego/ids" secp256k1 "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" txs "github.com/ava-labs/avalanchego/vms/platformvm/txs" + secp256k1fx "github.com/ava-labs/avalanchego/vms/secp256k1fx" gomock "go.uber.org/mock/gomock" ) @@ -100,6 +101,21 @@ func (mr *MockBuilderMockRecorder) NewAdvanceTimeTx(arg0 interface{}) *gomock.Ca return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAdvanceTimeTx", reflect.TypeOf((*MockBuilder)(nil).NewAdvanceTimeTx), arg0) } +// NewBaseTx mocks base method. +func (m *MockBuilder) NewBaseTx(arg0 uint64, arg1 secp256k1fx.OutputOwners, arg2 []*secp256k1.PrivateKey, arg3 ids.ShortID) (*txs.Tx, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewBaseTx", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(*txs.Tx) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// NewBaseTx indicates an expected call of NewBaseTx. +func (mr *MockBuilderMockRecorder) NewBaseTx(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewBaseTx", reflect.TypeOf((*MockBuilder)(nil).NewBaseTx), arg0, arg1, arg2, arg3) +} + // NewCreateChainTx mocks base method. func (m *MockBuilder) NewCreateChainTx(arg0 ids.ID, arg1 []byte, arg2 ids.ID, arg3 []ids.ID, arg4 string, arg5 []*secp256k1.PrivateKey, arg6 ids.ShortID) (*txs.Tx, error) { m.ctrl.T.Helper() diff --git a/vms/platformvm/txs/codec.go b/vms/platformvm/txs/codec.go index 1d4eac1f700e..d743376d1acb 100644 --- a/vms/platformvm/txs/codec.go +++ b/vms/platformvm/txs/codec.go @@ -8,6 +8,7 @@ import ( "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/vms/platformvm/signer" "github.com/ava-labs/avalanchego/vms/platformvm/stakeable" @@ -103,5 +104,8 @@ func RegisterUnsignedTxsTypes(targetCodec linearcodec.Codec) error { } func RegisterDUnsignedTxsTypes(targetCodec linearcodec.Codec) error { - return targetCodec.RegisterType(&TransferSubnetOwnershipTx{}) + return utils.Err( + targetCodec.RegisterType(&TransferSubnetOwnershipTx{}), + targetCodec.RegisterType(&BaseTx{}), + ) } diff --git a/vms/platformvm/txs/executor/atomic_tx_executor.go b/vms/platformvm/txs/executor/atomic_tx_executor.go index 09d374b3a395..3b7dc60ec173 100644 --- a/vms/platformvm/txs/executor/atomic_tx_executor.go +++ b/vms/platformvm/txs/executor/atomic_tx_executor.go @@ -76,6 +76,10 @@ func (*AtomicTxExecutor) AddPermissionlessDelegatorTx(*txs.AddPermissionlessDele return ErrWrongTxType } +func (*AtomicTxExecutor) BaseTx(*txs.BaseTx) error { + return ErrWrongTxType +} + func (e *AtomicTxExecutor) ImportTx(tx *txs.ImportTx) error { return e.atomicTx(tx) } diff --git a/vms/platformvm/txs/executor/proposal_tx_executor.go b/vms/platformvm/txs/executor/proposal_tx_executor.go index dd66815b9c8f..bd329b3f2576 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor.go @@ -101,6 +101,10 @@ func (*ProposalTxExecutor) TransferSubnetOwnershipTx(*txs.TransferSubnetOwnershi return ErrWrongTxType } +func (*ProposalTxExecutor) BaseTx(*txs.BaseTx) error { + return ErrWrongTxType +} + func (e *ProposalTxExecutor) AddValidatorTx(tx *txs.AddValidatorTx) error { // AddValidatorTx is a proposal transaction until the Banff fork // activation. Following the activation, AddValidatorTxs must be issued into diff --git a/vms/platformvm/txs/executor/standard_tx_executor.go b/vms/platformvm/txs/executor/standard_tx_executor.go index 2aa9e9c4a400..22bab59afd3b 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor.go +++ b/vms/platformvm/txs/executor/standard_tx_executor.go @@ -514,3 +514,34 @@ func (e *StandardTxExecutor) TransferSubnetOwnershipTx(tx *txs.TransferSubnetOwn return nil } + +func (e *StandardTxExecutor) BaseTx(tx *txs.BaseTx) error { + if !e.Backend.Config.IsDActivated(e.State.GetTimestamp()) { + return ErrDUpgradeNotActive + } + + // Verify the tx is well-formed + if err := e.Tx.SyntacticVerify(e.Ctx); err != nil { + return err + } + + // Verify the flowcheck + if err := e.FlowChecker.VerifySpend( + tx, + e.State, + tx.Ins, + tx.Outs, + e.Tx.Creds, + map[ids.ID]uint64{ + e.Ctx.AVAXAssetID: e.Config.TxFee, + }, + ); err != nil { + return err + } + + // Consume the UTXOS + avax.Consume(e.State, tx.Ins) + // Produce the UTXOS + avax.Produce(e.State, e.Tx.ID(), tx.Outs) + return nil +} diff --git a/vms/platformvm/txs/executor/tx_mempool_verifier.go b/vms/platformvm/txs/executor/tx_mempool_verifier.go index aa8d1dfaeb86..6704ccbd0489 100644 --- a/vms/platformvm/txs/executor/tx_mempool_verifier.go +++ b/vms/platformvm/txs/executor/tx_mempool_verifier.go @@ -78,6 +78,10 @@ func (v *MempoolTxVerifier) TransferSubnetOwnershipTx(tx *txs.TransferSubnetOwne return v.standardTx(tx) } +func (v *MempoolTxVerifier) BaseTx(tx *txs.BaseTx) error { + return v.standardTx(tx) +} + func (v *MempoolTxVerifier) standardTx(tx txs.UnsignedTx) error { baseState, err := v.standardBaseState() if err != nil { diff --git a/vms/platformvm/txs/mempool/issuer.go b/vms/platformvm/txs/mempool/issuer.go index e24afb5282da..b56c10190cf8 100644 --- a/vms/platformvm/txs/mempool/issuer.go +++ b/vms/platformvm/txs/mempool/issuer.go @@ -79,6 +79,11 @@ func (i *issuer) TransferSubnetOwnershipTx(*txs.TransferSubnetOwnershipTx) error return nil } +func (i *issuer) BaseTx(*txs.BaseTx) error { + i.m.addDecisionTx(i.tx) + return nil +} + func (i *issuer) AddPermissionlessValidatorTx(*txs.AddPermissionlessValidatorTx) error { i.m.addStakerTx(i.tx) return nil diff --git a/vms/platformvm/txs/mempool/remover.go b/vms/platformvm/txs/mempool/remover.go index e418cf46c342..b21071b16465 100644 --- a/vms/platformvm/txs/mempool/remover.go +++ b/vms/platformvm/txs/mempool/remover.go @@ -62,6 +62,11 @@ func (r *remover) TransferSubnetOwnershipTx(*txs.TransferSubnetOwnershipTx) erro return nil } +func (r *remover) BaseTx(*txs.BaseTx) error { + r.m.removeDecisionTxs([]*txs.Tx{r.tx}) + return nil +} + func (r *remover) AddPermissionlessValidatorTx(*txs.AddPermissionlessValidatorTx) error { r.m.removeStakerTx(r.tx) return nil diff --git a/vms/platformvm/txs/visitor.go b/vms/platformvm/txs/visitor.go index 5476d73c7e86..05a21c355801 100644 --- a/vms/platformvm/txs/visitor.go +++ b/vms/platformvm/txs/visitor.go @@ -19,4 +19,5 @@ type Visitor interface { AddPermissionlessValidatorTx(*AddPermissionlessValidatorTx) error AddPermissionlessDelegatorTx(*AddPermissionlessDelegatorTx) error TransferSubnetOwnershipTx(*TransferSubnetOwnershipTx) error + BaseTx(*BaseTx) error } diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 7b0bbba58cdf..ea8d43891dd6 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -2188,3 +2188,78 @@ func TestTransferSubnetOwnershipTx(t *testing.T) { } require.Equal(expectedOwner, subnetOwner) } + +func TestBaseTx(t *testing.T) { + require := require.New(t) + vm, _, _ := defaultVM(t) + vm.ctx.Lock.Lock() + defer func() { + require.NoError(vm.Shutdown(context.Background())) + vm.ctx.Lock.Unlock() + }() + + sendAmt := uint64(100000) + changeAddr := ids.ShortEmpty + + baseTx, err := vm.txBuilder.NewBaseTx( + sendAmt, + secp256k1fx.OutputOwners{ + Threshold: 1, + Addrs: []ids.ShortID{ + keys[1].Address(), + }, + }, + []*secp256k1.PrivateKey{keys[0]}, + changeAddr, + ) + require.NoError(err) + + totalInputAmt := uint64(0) + key0InputAmt := uint64(0) + for inputID := range baseTx.Unsigned.InputIDs() { + utxo, err := vm.state.GetUTXO(inputID) + require.NoError(err) + require.IsType(&secp256k1fx.TransferOutput{}, utxo.Out) + castOut := utxo.Out.(*secp256k1fx.TransferOutput) + if castOut.AddressesSet().Equals(set.Of(keys[0].Address())) { + key0InputAmt += castOut.Amt + } + totalInputAmt += castOut.Amt + } + require.Equal(totalInputAmt, key0InputAmt) + + totalOutputAmt := uint64(0) + key0OutputAmt := uint64(0) + key1OutputAmt := uint64(0) + changeAddrOutputAmt := uint64(0) + for _, output := range baseTx.Unsigned.Outputs() { + require.IsType(&secp256k1fx.TransferOutput{}, output.Out) + castOut := output.Out.(*secp256k1fx.TransferOutput) + if castOut.AddressesSet().Equals(set.Of(keys[0].Address())) { + key0OutputAmt += castOut.Amt + } + if castOut.AddressesSet().Equals(set.Of(keys[1].Address())) { + key1OutputAmt += castOut.Amt + } + if castOut.AddressesSet().Equals(set.Of(changeAddr)) { + changeAddrOutputAmt += castOut.Amt + } + totalOutputAmt += castOut.Amt + } + require.Equal(totalOutputAmt, key0OutputAmt+key1OutputAmt+changeAddrOutputAmt) + + require.Equal(vm.TxFee, totalInputAmt-totalOutputAmt) + require.Equal(sendAmt, key1OutputAmt) + + require.NoError(vm.Builder.AddUnverifiedTx(baseTx)) + baseTxBlock, err := vm.Builder.BuildBlock(context.Background()) + require.NoError(err) + + baseTxRawBlock := baseTxBlock.(*blockexecutor.Block).Block + require.IsType(&block.BanffStandardBlock{}, baseTxRawBlock) + require.Contains(baseTxRawBlock.Txs(), baseTx) + + require.NoError(baseTxBlock.Verify(context.Background())) + require.NoError(baseTxBlock.Accept(context.Background())) + require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) +} diff --git a/wallet/chain/p/backend_visitor.go b/wallet/chain/p/backend_visitor.go index da2fc591ecd5..57d602354428 100644 --- a/wallet/chain/p/backend_visitor.go +++ b/wallet/chain/p/backend_visitor.go @@ -58,6 +58,10 @@ func (b *backendVisitor) TransferSubnetOwnershipTx(tx *txs.TransferSubnetOwnersh return b.baseTx(&tx.BaseTx) } +func (b *backendVisitor) BaseTx(tx *txs.BaseTx) error { + return b.baseTx(tx) +} + func (b *backendVisitor) ImportTx(tx *txs.ImportTx) error { err := b.b.removeUTXOs( b.ctx, diff --git a/wallet/chain/p/signer_visitor.go b/wallet/chain/p/signer_visitor.go index 6df1687400ac..9dd6018ea2e3 100644 --- a/wallet/chain/p/signer_visitor.go +++ b/wallet/chain/p/signer_visitor.go @@ -51,6 +51,14 @@ func (*signerVisitor) RewardValidatorTx(*txs.RewardValidatorTx) error { return errUnsupportedTxType } +func (s *signerVisitor) BaseTx(tx *txs.BaseTx) error { + txSigners, err := s.getSigners(constants.PlatformChainID, tx.Ins) + if err != nil { + return err + } + return sign(s.tx, false, txSigners) +} + func (s *signerVisitor) AddValidatorTx(tx *txs.AddValidatorTx) error { txSigners, err := s.getSigners(constants.PlatformChainID, tx.Ins) if err != nil { From 4957ccb4ee4fc4a8f8fe2a0ae02237d83b3574f9 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Tue, 31 Oct 2023 18:38:57 -0400 Subject: [PATCH 16/19] Add `pebble` as valid value for `--db-type`. (#2244) Signed-off-by: Dan Laine Co-authored-by: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Co-authored-by: Stephen Buttolph --- config/flags.go | 3 ++- database/pebble/db.go | 20 +++++++++++++------- database/pebble/db_test.go | 2 +- node/node.go | 15 +++++++++++++-- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/config/flags.go b/config/flags.go index 67fe339db887..9fce19ae501f 100644 --- a/config/flags.go +++ b/config/flags.go @@ -15,6 +15,7 @@ import ( "github.com/ava-labs/avalanchego/database/leveldb" "github.com/ava-labs/avalanchego/database/memdb" + "github.com/ava-labs/avalanchego/database/pebble" "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/snow/consensus/snowball" "github.com/ava-labs/avalanchego/trace" @@ -103,7 +104,7 @@ func addNodeFlags(fs *pflag.FlagSet) { fs.Uint64(AddSubnetDelegatorFeeKey, genesis.LocalParams.AddSubnetDelegatorFee, "Transaction fee, in nAVAX, for transactions that add new subnet delegators") // Database - fs.String(DBTypeKey, leveldb.Name, fmt.Sprintf("Database type to use. Should be one of {%s, %s}", leveldb.Name, memdb.Name)) + fs.String(DBTypeKey, leveldb.Name, fmt.Sprintf("Database type to use. Must be one of {%s, %s, %s}", leveldb.Name, memdb.Name, pebble.Name)) fs.String(DBPathKey, defaultDBDir, "Path to database directory") fs.String(DBConfigFileKey, "", fmt.Sprintf("Path to database config file. Ignored if %s is specified", DBConfigContentKey)) fs.String(DBConfigContentKey, "", "Specifies base64 encoded database config content") diff --git a/database/pebble/db.go b/database/pebble/db.go index 13ab1db04977..7aa718082a35 100644 --- a/database/pebble/db.go +++ b/database/pebble/db.go @@ -24,9 +24,13 @@ import ( "github.com/ava-labs/avalanchego/utils/units" ) -// pebbleByteOverHead is the number of bytes of constant overhead that -// should be added to a batch size per operation. -const pebbleByteOverHead = 8 +const ( + Name = "pebble" + + // pebbleByteOverHead is the number of bytes of constant overhead that + // should be added to a batch size per operation. + pebbleByteOverHead = 8 +) var ( _ database.Database = (*Database)(nil) @@ -73,10 +77,12 @@ type Config struct { } // TODO: Add metrics -func New(file string, configBytes []byte, log logging.Logger, _ string, _ prometheus.Registerer) (*Database, error) { - var cfg Config - if err := json.Unmarshal(configBytes, &cfg); err != nil { - return nil, err +func New(file string, configBytes []byte, log logging.Logger, _ string, _ prometheus.Registerer) (database.Database, error) { + cfg := DefaultConfig + if len(configBytes) > 0 { + if err := json.Unmarshal(configBytes, &cfg); err != nil { + return nil, err + } } opts := &pebble.Options{ diff --git a/database/pebble/db_test.go b/database/pebble/db_test.go index c72a9d687c88..cba67a79a88f 100644 --- a/database/pebble/db_test.go +++ b/database/pebble/db_test.go @@ -18,7 +18,7 @@ func newDB(t testing.TB) *Database { folder := t.TempDir() db, err := New(folder, DefaultConfigBytes, logging.NoLog{}, "pebble", prometheus.NewRegistry()) require.NoError(t, err) - return db + return db.(*Database) } func TestInterface(t *testing.T) { diff --git a/node/node.go b/node/node.go index d2ca97ae0497..cad0073899b8 100644 --- a/node/node.go +++ b/node/node.go @@ -40,6 +40,7 @@ import ( "github.com/ava-labs/avalanchego/database/leveldb" "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/meterdb" + "github.com/ava-labs/avalanchego/database/pebble" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" @@ -503,20 +504,30 @@ func (n *Node) initDatabase() error { // start the db switch n.Config.DatabaseConfig.Name { case leveldb.Name: + // Prior to v1.10.15, the only on-disk database was leveldb, and its + // files went to [dbPath]/[networkID]/v1.4.5. dbPath := filepath.Join(n.Config.DatabaseConfig.Path, version.CurrentDatabase.String()) var err error n.DB, err = leveldb.New(dbPath, n.Config.DatabaseConfig.Config, n.Log, "db_internal", n.MetricsRegisterer) if err != nil { - return fmt.Errorf("couldn't create db at %s: %w", dbPath, err) + return fmt.Errorf("couldn't create leveldb at %s: %w", dbPath, err) } case memdb.Name: n.DB = memdb.New() + case pebble.Name: + dbPath := filepath.Join(n.Config.DatabaseConfig.Path, pebble.Name) + var err error + n.DB, err = pebble.New(dbPath, n.Config.DatabaseConfig.Config, n.Log, "db_internal", n.MetricsRegisterer) + if err != nil { + return fmt.Errorf("couldn't create pebbledb at %s: %w", dbPath, err) + } default: return fmt.Errorf( - "db-type was %q but should have been one of {%s, %s}", + "db-type was %q but should have been one of {%s, %s, %s}", n.Config.DatabaseConfig.Name, leveldb.Name, memdb.Name, + pebble.Name, ) } From 36d1630b7901b27bfe1642f873731292c385702e Mon Sep 17 00:00:00 2001 From: Cesar <137245636+nytzuga@users.noreply.github.com> Date: Wed, 1 Nov 2023 22:44:14 -0300 Subject: [PATCH 17/19] Add nullable option to codec (#2171) Signed-off-by: Cesar <137245636+nytzuga@users.noreply.github.com> Co-authored-by: Stephen Buttolph Co-authored-by: Dan Laine --- codec/reflectcodec/struct_fielder.go | 19 ++- codec/reflectcodec/type_codec.go | 217 ++++++++++++++++++-------- codec/reflectcodec/type_codec_test.go | 30 ++++ codec/test_codec.go | 94 +++++++++-- 4 files changed, 283 insertions(+), 77 deletions(-) create mode 100644 codec/reflectcodec/type_codec_test.go diff --git a/codec/reflectcodec/struct_fielder.go b/codec/reflectcodec/struct_fielder.go index 27edb58a1793..d266b60a3ebf 100644 --- a/codec/reflectcodec/struct_fielder.go +++ b/codec/reflectcodec/struct_fielder.go @@ -18,6 +18,10 @@ const ( // TagValue is the value the tag must have to be serialized. TagValue = "true" + + // TagValue is the value the tag must have to be serialized, this variant + // includes the nullable option + TagWithNullableValue = "true,nullable" ) var _ StructFielder = (*structFielder)(nil) @@ -25,6 +29,7 @@ var _ StructFielder = (*structFielder)(nil) type FieldDesc struct { Index int MaxSliceLen uint32 + Nullable bool } // StructFielder handles discovery of serializable fields in a struct. @@ -82,10 +87,19 @@ func (s *structFielder) GetSerializedFields(t reflect.Type) ([]FieldDesc, error) // Multiple tags per fields can be specified. // Serialize/Deserialize field if it has // any tag with the right value - captureField := false + var ( + captureField bool + nullable bool + ) for _, tag := range s.tags { - if field.Tag.Get(tag) == TagValue { + switch field.Tag.Get(tag) { + case TagValue: + captureField = true + case TagWithNullableValue: captureField = true + nullable = true + } + if captureField { break } } @@ -107,6 +121,7 @@ func (s *structFielder) GetSerializedFields(t reflect.Type) ([]FieldDesc, error) serializedFields = append(serializedFields, FieldDesc{ Index: i, MaxSliceLen: maxSliceLen, + Nullable: nullable, }) } s.serializedFieldIndices[t] = serializedFields // cache result diff --git a/codec/reflectcodec/type_codec.go b/codec/reflectcodec/type_codec.go index ac9ca25c16e7..9f9037f43d4e 100644 --- a/codec/reflectcodec/type_codec.go +++ b/codec/reflectcodec/type_codec.go @@ -13,18 +13,23 @@ import ( "golang.org/x/exp/slices" "github.com/ava-labs/avalanchego/codec" + "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/wrappers" ) -// DefaultTagName that enables serialization. -const DefaultTagName = "serialize" +const ( + // DefaultTagName that enables serialization. + DefaultTagName = "serialize" + initialSliceLen = 16 +) var ( _ codec.Codec = (*genericCodec)(nil) - errMarshalNil = errors.New("can't marshal nil pointer or interface") - errUnmarshalNil = errors.New("can't unmarshal nil") - errNeedPointer = errors.New("argument to unmarshal must be a pointer") + errMarshalNil = errors.New("can't marshal nil pointer or interface") + errUnmarshalNil = errors.New("can't unmarshal nil") + errNeedPointer = errors.New("argument to unmarshal must be a pointer") + errRecursiveInterfaceTypes = errors.New("recursive interface types") ) type TypeCodec interface { @@ -85,12 +90,18 @@ func (c *genericCodec) Size(value interface{}) (int, error) { return 0, errMarshalNil // can't marshal nil } - size, _, err := c.size(reflect.ValueOf(value)) + size, _, err := c.size(reflect.ValueOf(value), false /*=nullable*/, nil /*=typeStack*/) return size, err } -// size returns the size of the value along with whether the value is constant sized. -func (c *genericCodec) size(value reflect.Value) (int, bool, error) { +// size returns the size of the value along with whether the value is constant +// sized. This function takes into account a `nullable` property which allows +// pointers and interfaces to serialize nil values +func (c *genericCodec) size( + value reflect.Value, + nullable bool, + typeStack set.Set[reflect.Type], +) (int, bool, error) { switch valueKind := value.Kind(); valueKind { case reflect.Uint8: return wrappers.ByteLen, true, nil @@ -114,24 +125,41 @@ func (c *genericCodec) size(value reflect.Value) (int, bool, error) { return wrappers.StringLen(value.String()), false, nil case reflect.Ptr: if value.IsNil() { - // Can't marshal nil pointers (but nil slices are fine) - return 0, false, errMarshalNil + if !nullable { + return 0, false, errMarshalNil + } + return wrappers.BoolLen, false, nil + } + + size, constSize, err := c.size(value.Elem(), false /*=nullable*/, typeStack) + if nullable { + return wrappers.BoolLen + size, false, err } - return c.size(value.Elem()) + return size, constSize, err case reflect.Interface: if value.IsNil() { - // Can't marshal nil interfaces (but nil slices are fine) - return 0, false, errMarshalNil + if !nullable { + return 0, false, errMarshalNil + } + return wrappers.BoolLen, false, nil } + underlyingValue := value.Interface() underlyingType := reflect.TypeOf(underlyingValue) + if typeStack.Contains(underlyingType) { + return 0, false, fmt.Errorf("%w: %s", errRecursiveInterfaceTypes, underlyingType) + } + typeStack.Add(underlyingType) + prefixSize := c.typer.PrefixSize(underlyingType) - valueSize, _, err := c.size(value.Elem()) - if err != nil { - return 0, false, err + valueSize, _, err := c.size(value.Elem(), false /*=nullable*/, typeStack) + + typeStack.Remove(underlyingType) + if nullable { + return wrappers.BoolLen + prefixSize + valueSize, false, err } - return prefixSize + valueSize, false, nil + return prefixSize + valueSize, false, err case reflect.Slice: numElts := value.Len() @@ -139,7 +167,7 @@ func (c *genericCodec) size(value reflect.Value) (int, bool, error) { return wrappers.IntLen, false, nil } - size, constSize, err := c.size(value.Index(0)) + size, constSize, err := c.size(value.Index(0), nullable, typeStack) if err != nil { return 0, false, err } @@ -151,7 +179,7 @@ func (c *genericCodec) size(value reflect.Value) (int, bool, error) { } for i := 1; i < numElts; i++ { - innerSize, _, err := c.size(value.Index(i)) + innerSize, _, err := c.size(value.Index(i), nullable, typeStack) if err != nil { return 0, false, err } @@ -165,7 +193,7 @@ func (c *genericCodec) size(value reflect.Value) (int, bool, error) { return 0, true, nil } - size, constSize, err := c.size(value.Index(0)) + size, constSize, err := c.size(value.Index(0), nullable, typeStack) if err != nil { return 0, false, err } @@ -177,7 +205,7 @@ func (c *genericCodec) size(value reflect.Value) (int, bool, error) { } for i := 1; i < numElts; i++ { - innerSize, _, err := c.size(value.Index(i)) + innerSize, _, err := c.size(value.Index(i), nullable, typeStack) if err != nil { return 0, false, err } @@ -196,7 +224,7 @@ func (c *genericCodec) size(value reflect.Value) (int, bool, error) { constSize = true ) for _, fieldDesc := range serializedFields { - innerSize, innerConstSize, err := c.size(value.Field(fieldDesc.Index)) + innerSize, innerConstSize, err := c.size(value.Field(fieldDesc.Index), fieldDesc.Nullable, typeStack) if err != nil { return 0, false, err } @@ -211,11 +239,11 @@ func (c *genericCodec) size(value reflect.Value) (int, bool, error) { return wrappers.IntLen, false, nil } - keySize, keyConstSize, err := c.size(iter.Key()) + keySize, keyConstSize, err := c.size(iter.Key(), false /*=nullable*/, typeStack) if err != nil { return 0, false, err } - valueSize, valueConstSize, err := c.size(iter.Value()) + valueSize, valueConstSize, err := c.size(iter.Value(), nullable, typeStack) if err != nil { return 0, false, err } @@ -230,7 +258,7 @@ func (c *genericCodec) size(value reflect.Value) (int, bool, error) { totalValueSize = valueSize ) for iter.Next() { - valueSize, _, err := c.size(iter.Value()) + valueSize, _, err := c.size(iter.Value(), nullable, typeStack) if err != nil { return 0, false, err } @@ -244,7 +272,7 @@ func (c *genericCodec) size(value reflect.Value) (int, bool, error) { totalKeySize = keySize ) for iter.Next() { - keySize, _, err := c.size(iter.Key()) + keySize, _, err := c.size(iter.Key(), false /*=nullable*/, typeStack) if err != nil { return 0, false, err } @@ -255,11 +283,11 @@ func (c *genericCodec) size(value reflect.Value) (int, bool, error) { default: totalSize := wrappers.IntLen + keySize + valueSize for iter.Next() { - keySize, _, err := c.size(iter.Key()) + keySize, _, err := c.size(iter.Key(), false /*=nullable*/, typeStack) if err != nil { return 0, false, err } - valueSize, _, err := c.size(iter.Value()) + valueSize, _, err := c.size(iter.Value(), nullable, typeStack) if err != nil { return 0, false, err } @@ -279,13 +307,19 @@ func (c *genericCodec) MarshalInto(value interface{}, p *wrappers.Packer) error return errMarshalNil // can't marshal nil } - return c.marshal(reflect.ValueOf(value), p, c.maxSliceLen) + return c.marshal(reflect.ValueOf(value), p, c.maxSliceLen, false /*=nullable*/, nil /*=typeStack*/) } // marshal writes the byte representation of [value] to [p] -// [value]'s underlying value must not be a nil pointer or interface +// // c.lock should be held for the duration of this function -func (c *genericCodec) marshal(value reflect.Value, p *wrappers.Packer, maxSliceLen uint32) error { +func (c *genericCodec) marshal( + value reflect.Value, + p *wrappers.Packer, + maxSliceLen uint32, + nullable bool, + typeStack set.Set[reflect.Type], +) error { switch valueKind := value.Kind(); valueKind { case reflect.Uint8: p.PackByte(uint8(value.Uint())) @@ -318,22 +352,41 @@ func (c *genericCodec) marshal(value reflect.Value, p *wrappers.Packer, maxSlice p.PackBool(value.Bool()) return p.Err case reflect.Ptr: - if value.IsNil() { // Can't marshal nil (except nil slices) + isNil := value.IsNil() + if nullable { + p.PackBool(isNil) + if isNil || p.Err != nil { + return p.Err + } + } else if isNil { return errMarshalNil } - return c.marshal(value.Elem(), p, c.maxSliceLen) + + return c.marshal(value.Elem(), p, c.maxSliceLen, false /*=nullable*/, typeStack) case reflect.Interface: - if value.IsNil() { // Can't marshal nil (except nil slices) + isNil := value.IsNil() + if nullable { + p.PackBool(isNil) + if isNil || p.Err != nil { + return p.Err + } + } else if isNil { return errMarshalNil } + underlyingValue := value.Interface() underlyingType := reflect.TypeOf(underlyingValue) + if typeStack.Contains(underlyingType) { + return fmt.Errorf("%w: %s", errRecursiveInterfaceTypes, underlyingType) + } + typeStack.Add(underlyingType) if err := c.typer.PackPrefix(p, underlyingType); err != nil { return err } - if err := c.marshal(value.Elem(), p, c.maxSliceLen); err != nil { + if err := c.marshal(value.Elem(), p, c.maxSliceLen, false /*=nullable*/, typeStack); err != nil { return err } + typeStack.Remove(underlyingType) return p.Err case reflect.Slice: numElts := value.Len() // # elements in the slice/array. 0 if this slice is nil. @@ -361,7 +414,7 @@ func (c *genericCodec) marshal(value reflect.Value, p *wrappers.Packer, maxSlice return p.Err } for i := 0; i < numElts; i++ { // Process each element in the slice - if err := c.marshal(value.Index(i), p, c.maxSliceLen); err != nil { + if err := c.marshal(value.Index(i), p, c.maxSliceLen, nullable, typeStack); err != nil { return err } } @@ -381,7 +434,7 @@ func (c *genericCodec) marshal(value reflect.Value, p *wrappers.Packer, maxSlice ) } for i := 0; i < numElts; i++ { // Process each element in the array - if err := c.marshal(value.Index(i), p, c.maxSliceLen); err != nil { + if err := c.marshal(value.Index(i), p, c.maxSliceLen, nullable, typeStack); err != nil { return err } } @@ -392,7 +445,7 @@ func (c *genericCodec) marshal(value reflect.Value, p *wrappers.Packer, maxSlice return err } for _, fieldDesc := range serializedFields { // Go through all fields of this struct that are serialized - if err := c.marshal(value.Field(fieldDesc.Index), p, fieldDesc.MaxSliceLen); err != nil { // Serialize the field and write to byte array + if err := c.marshal(value.Field(fieldDesc.Index), p, fieldDesc.MaxSliceLen, fieldDesc.Nullable, typeStack); err != nil { // Serialize the field and write to byte array return err } } @@ -423,7 +476,7 @@ func (c *genericCodec) marshal(value reflect.Value, p *wrappers.Packer, maxSlice startOffset := p.Offset endOffset := p.Offset for i, key := range keys { - if err := c.marshal(key, p, c.maxSliceLen); err != nil { + if err := c.marshal(key, p, c.maxSliceLen, false /*=nullable*/, typeStack); err != nil { return err } if p.Err != nil { @@ -456,7 +509,7 @@ func (c *genericCodec) marshal(value reflect.Value, p *wrappers.Packer, maxSlice } // serialize and pack value - if err := c.marshal(value.MapIndex(key.key), p, c.maxSliceLen); err != nil { + if err := c.marshal(value.MapIndex(key.key), p, c.maxSliceLen, nullable, typeStack); err != nil { return err } } @@ -467,8 +520,8 @@ func (c *genericCodec) marshal(value reflect.Value, p *wrappers.Packer, maxSlice } } -// Unmarshal unmarshals [bytes] into [dest], where -// [dest] must be a pointer or interface +// Unmarshal unmarshals [bytes] into [dest], where [dest] must be a pointer or +// interface func (c *genericCodec) Unmarshal(bytes []byte, dest interface{}) error { if dest == nil { return errUnmarshalNil @@ -481,7 +534,7 @@ func (c *genericCodec) Unmarshal(bytes []byte, dest interface{}) error { if destPtr.Kind() != reflect.Ptr { return errNeedPointer } - if err := c.unmarshal(&p, destPtr.Elem(), c.maxSliceLen); err != nil { + if err := c.unmarshal(&p, destPtr.Elem(), c.maxSliceLen, false /*=nullable*/, nil /*=typeStack*/); err != nil { return err } if p.Offset != len(bytes) { @@ -495,8 +548,19 @@ func (c *genericCodec) Unmarshal(bytes []byte, dest interface{}) error { } // Unmarshal from p.Bytes into [value]. [value] must be addressable. +// +// The [nullable] property affects how pointers and interfaces are unmarshalled, +// as an extra byte would be used to unmarshal nil values for pointers and +// interaces +// // c.lock should be held for the duration of this function -func (c *genericCodec) unmarshal(p *wrappers.Packer, value reflect.Value, maxSliceLen uint32) error { +func (c *genericCodec) unmarshal( + p *wrappers.Packer, + value reflect.Value, + maxSliceLen uint32, + nullable bool, + typeStack set.Set[reflect.Type], +) error { switch value.Kind() { case reflect.Uint8: value.SetUint(uint64(p.UnpackByte())) @@ -573,18 +637,22 @@ func (c *genericCodec) unmarshal(p *wrappers.Packer, value reflect.Value, maxSli } numElts := int(numElts32) + sliceType := value.Type() + innerType := sliceType.Elem() + // If this is a slice of bytes, manually unpack the bytes rather // than calling unmarshal on each byte. This improves performance. - if elemKind := value.Type().Elem().Kind(); elemKind == reflect.Uint8 { + if elemKind := innerType.Kind(); elemKind == reflect.Uint8 { value.SetBytes(p.UnpackFixedBytes(numElts)) return p.Err } - // set [value] to be a slice of the appropriate type/capacity (right now it is nil) - value.Set(reflect.MakeSlice(value.Type(), numElts, numElts)) - // Unmarshal each element into the appropriate index of the slice + // Unmarshal each element and append it into the slice. + value.Set(reflect.MakeSlice(sliceType, 0, initialSliceLen)) + zeroValue := reflect.Zero(innerType) for i := 0; i < numElts; i++ { - if err := c.unmarshal(p, value.Index(i), c.maxSliceLen); err != nil { - return fmt.Errorf("couldn't unmarshal slice element: %w", err) + value.Set(reflect.Append(value, zeroValue)) + if err := c.unmarshal(p, value.Index(i), c.maxSliceLen, nullable, typeStack); err != nil { + return err } } return nil @@ -601,8 +669,8 @@ func (c *genericCodec) unmarshal(p *wrappers.Packer, value reflect.Value, maxSli return nil } for i := 0; i < numElts; i++ { - if err := c.unmarshal(p, value.Index(i), c.maxSliceLen); err != nil { - return fmt.Errorf("couldn't unmarshal array element: %w", err) + if err := c.unmarshal(p, value.Index(i), c.maxSliceLen, nullable, typeStack); err != nil { + return err } } return nil @@ -613,15 +681,29 @@ func (c *genericCodec) unmarshal(p *wrappers.Packer, value reflect.Value, maxSli } return nil case reflect.Interface: + if nullable { + isNil := p.UnpackBool() + if isNil || p.Err != nil { + return p.Err + } + } + intfImplementor, err := c.typer.UnpackPrefix(p, value.Type()) if err != nil { return err } + intfImplementorType := intfImplementor.Type() + if typeStack.Contains(intfImplementorType) { + return fmt.Errorf("%w: %s", errRecursiveInterfaceTypes, intfImplementorType) + } + typeStack.Add(intfImplementorType) + // Unmarshal into the struct - if err := c.unmarshal(p, intfImplementor, c.maxSliceLen); err != nil { - return fmt.Errorf("couldn't unmarshal interface: %w", err) + if err := c.unmarshal(p, intfImplementor, c.maxSliceLen, false /*=nullable*/, typeStack); err != nil { + return err } - // And assign the filled struct to the value + + typeStack.Remove(intfImplementorType) value.Set(intfImplementor) return nil case reflect.Struct: @@ -632,19 +714,26 @@ func (c *genericCodec) unmarshal(p *wrappers.Packer, value reflect.Value, maxSli } // Go through the fields and umarshal into them for _, fieldDesc := range serializedFieldIndices { - if err := c.unmarshal(p, value.Field(fieldDesc.Index), fieldDesc.MaxSliceLen); err != nil { - return fmt.Errorf("couldn't unmarshal struct: %w", err) + if err := c.unmarshal(p, value.Field(fieldDesc.Index), fieldDesc.MaxSliceLen, fieldDesc.Nullable, typeStack); err != nil { + return err } } return nil case reflect.Ptr: + if nullable { + isNil := p.UnpackBool() + if isNil || p.Err != nil { + return p.Err + } + } + // Get the type this pointer points to t := value.Type().Elem() // Create a new pointer to a new value of the underlying type v := reflect.New(t) // Fill the value - if err := c.unmarshal(p, v.Elem(), c.maxSliceLen); err != nil { - return fmt.Errorf("couldn't unmarshal pointer: %w", err) + if err := c.unmarshal(p, v.Elem(), c.maxSliceLen, false /*=nullable*/, typeStack); err != nil { + return err } // Assign to the top-level struct's member value.Set(v) @@ -671,15 +760,15 @@ func (c *genericCodec) unmarshal(p *wrappers.Packer, value reflect.Value, maxSli ) // Set [value] to be a new map of the appropriate type. - value.Set(reflect.MakeMapWithSize(mapType, numElts)) + value.Set(reflect.MakeMap(mapType)) for i := 0; i < numElts; i++ { mapKey := reflect.New(mapKeyType).Elem() keyStartOffset := p.Offset - if err := c.unmarshal(p, mapKey, c.maxSliceLen); err != nil { - return fmt.Errorf("couldn't unmarshal map key (%s): %w", mapKeyType, err) + if err := c.unmarshal(p, mapKey, c.maxSliceLen, false /*=nullable*/, typeStack); err != nil { + return err } // Get the key's byte representation and check that the new key is @@ -696,8 +785,8 @@ func (c *genericCodec) unmarshal(p *wrappers.Packer, value reflect.Value, maxSli // Get the value mapValue := reflect.New(mapValueType).Elem() - if err := c.unmarshal(p, mapValue, c.maxSliceLen); err != nil { - return fmt.Errorf("couldn't unmarshal map value for key %s: %w", mapKey, err) + if err := c.unmarshal(p, mapValue, c.maxSliceLen, nullable, typeStack); err != nil { + return err } // Assign the key-value pair in the map diff --git a/codec/reflectcodec/type_codec_test.go b/codec/reflectcodec/type_codec_test.go new file mode 100644 index 000000000000..42b256c4a6c9 --- /dev/null +++ b/codec/reflectcodec/type_codec_test.go @@ -0,0 +1,30 @@ +// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package reflectcodec + +import ( + "reflect" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestSizeWithNil(t *testing.T) { + require := require.New(t) + var x *int32 + y := int32(1) + c := genericCodec{} + _, _, err := c.size(reflect.ValueOf(x), false /*=nullable*/, nil /*=typeStack*/) + require.ErrorIs(err, errMarshalNil) + len, _, err := c.size(reflect.ValueOf(x), true /*=nullable*/, nil /*=typeStack*/) + require.Empty(err) + require.Equal(1, len) + x = &y + len, _, err = c.size(reflect.ValueOf(y), true /*=nullable*/, nil /*=typeStack*/) + require.Empty(err) + require.Equal(4, len) + len, _, err = c.size(reflect.ValueOf(x), true /*=nullable*/, nil /*=typeStack*/) + require.Empty(err) + require.Equal(5, len) +} diff --git a/codec/test_codec.go b/codec/test_codec.go index 7177e08e81b1..341912a823af 100644 --- a/codec/test_codec.go +++ b/codec/test_codec.go @@ -23,6 +23,7 @@ var ( TestBigArray, TestPointerToStruct, TestSliceOfStruct, + TestStructWithNullable, TestInterface, TestSliceOfInterface, TestArrayOfInterface, @@ -63,7 +64,8 @@ type Foo interface { } type MyInnerStruct struct { - Str string `serialize:"true"` + Str string `serialize:"true"` + NumberNotProvided *int32 `serialize:"true,nullable"` } func (*MyInnerStruct) Foo() int { @@ -86,6 +88,15 @@ type MyInnerStruct3 struct { F Foo `serialize:"true"` } +type MyStructWithNullable struct { + Interface any `serialize:"true,nullable"` + Int32 *int32 `serialize:"true,nullable"` + Int64 *int64 `serialize:"true,nullable"` + Int32Slice []*int32 `serialize:"true,nullable"` + Int32Array [2]*int32 `serialize:"true,nullable"` + Int32Map map[int32]*int32 `serialize:"true,nullable"` +} + type myStruct struct { InnerStruct MyInnerStruct `serialize:"true"` InnerStruct2 *MyInnerStruct `serialize:"true"` @@ -145,21 +156,23 @@ func TestStruct(codec GeneralCodec, t testing.TB) { myMap7["key"] = "value" myMap7[int32(1)] = int32(2) + number := int32(8) + myStructInstance := myStruct{ - InnerStruct: MyInnerStruct{"hello"}, - InnerStruct2: &MyInnerStruct{"yello"}, + InnerStruct: MyInnerStruct{"hello", nil}, + InnerStruct2: &MyInnerStruct{"yello", nil}, Member1: 1, Member2: 2, MySlice: []byte{1, 2, 3, 4}, MySlice2: []string{"one", "two", "three"}, - MySlice3: []MyInnerStruct{{"abc"}, {"ab"}, {"c"}}, + MySlice3: []MyInnerStruct{{"abc", nil}, {"ab", &number}, {"c", nil}}, MySlice4: []*MyInnerStruct2{{true}, {}}, MySlice5: []Foo{&MyInnerStruct2{true}, &MyInnerStruct2{}}, MyArray: [4]byte{5, 6, 7, 8}, MyArray2: [5]string{"four", "five", "six", "seven"}, - MyArray3: [3]MyInnerStruct{{"d"}, {"e"}, {"f"}}, + MyArray3: [3]MyInnerStruct{{"d", nil}, {"e", nil}, {"f", nil}}, MyArray4: [2]*MyInnerStruct2{{}, {true}}, - MyInterface: &MyInnerStruct{"yeet"}, + MyInterface: &MyInnerStruct{"yeet", &number}, InnerStruct3: MyInnerStruct3{ Str: "str", M1: MyInnerStruct{ @@ -414,20 +427,79 @@ func TestPointerToStruct(codec GeneralCodec, t testing.TB) { require.Equal(myPtr, myPtrUnmarshaled) } +func TestStructWithNullable(codec GeneralCodec, t testing.TB) { + require := require.New(t) + n1 := int32(5) + n2 := int64(10) + struct1 := MyStructWithNullable{ + Interface: nil, + Int32: &n1, + Int64: &n2, + Int32Slice: []*int32{ + nil, + nil, + &n1, + }, + Int32Array: [2]*int32{ + nil, + &n1, + }, + Int32Map: map[int32]*int32{ + 1: nil, + 2: &n1, + }, + } + + require.NoError(codec.RegisterType(&MyStructWithNullable{})) + manager := NewDefaultManager() + require.NoError(manager.RegisterCodec(0, codec)) + + bytes, err := manager.Marshal(0, struct1) + require.NoError(err) + + bytesLen, err := manager.Size(0, struct1) + require.NoError(err) + require.Len(bytes, bytesLen) + + var struct1Unmarshaled MyStructWithNullable + version, err := manager.Unmarshal(bytes, &struct1Unmarshaled) + require.NoError(err) + require.Zero(version) + require.Equal(struct1, struct1Unmarshaled) + + struct1 = MyStructWithNullable{ + Int32Slice: []*int32{}, + Int32Map: map[int32]*int32{}, + } + bytes, err = manager.Marshal(0, struct1) + require.NoError(err) + + bytesLen, err = manager.Size(0, struct1) + require.NoError(err) + require.Len(bytes, bytesLen) + + var struct1Unmarshaled2 MyStructWithNullable + version, err = manager.Unmarshal(bytes, &struct1Unmarshaled2) + require.NoError(err) + require.Zero(version) + require.Equal(struct1, struct1Unmarshaled2) +} + // Test marshalling a slice of structs func TestSliceOfStruct(codec GeneralCodec, t testing.TB) { require := require.New(t) - + n1 := int32(-1) + n2 := int32(0xff) mySlice := []MyInnerStruct3{ { Str: "One", - M1: MyInnerStruct{"Two"}, - F: &MyInnerStruct{"Three"}, + M1: MyInnerStruct{"Two", &n1}, + F: &MyInnerStruct{"Three", &n2}, }, { Str: "Four", - M1: MyInnerStruct{"Five"}, - F: &MyInnerStruct{"Six"}, + M1: MyInnerStruct{"Five", nil}, + F: &MyInnerStruct{"Six", nil}, }, } require.NoError(codec.RegisterType(&MyInnerStruct{})) From 20f3580b4912f29adc602ad883e84897f0965cc1 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Wed, 1 Nov 2023 22:11:47 -0400 Subject: [PATCH 18/19] Update versions for v1.10.15 (#2245) --- RELEASES.md | 36 ++++++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 4 ++-- proto/README.md | 2 +- version/compatibility.json | 3 +++ version/constants.go | 4 ++-- 6 files changed, 45 insertions(+), 6 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 31d9e3605dce..13d983cf2803 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,5 +1,41 @@ # Release Notes +## [v1.10.15](https://github.com/ava-labs/avalanchego/releases/tag/v1.10.15) + +This version is backwards compatible to [v1.10.0](https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0). It is optional, but encouraged. + +The plugin version is updated to `30` all plugins must update to be compatible. + +### Configs + +- Added `pebble` as an allowed option to `--db-type` + +### Fixes + +- Fixed C-chain tracer API panic + +### What's Changed + +- Reduce allocations on insert and remove by @dboehm-avalabs in https://github.com/ava-labs/avalanchego/pull/2201 +- `merkledb` -- shift nit by @danlaine in https://github.com/ava-labs/avalanchego/pull/2218 +- Update `golangci-lint` to `v1.55.1` by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2228 +- Add json marshal tests to existing serialization tests in `platformvm/txs` pkg by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2227 +- Move all blst function usage to `bls` pkg by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2222 +- `merkledb` -- don't pass `BranchFactor` to `encodeDBNode` by @danlaine in https://github.com/ava-labs/avalanchego/pull/2217 +- Add `utils.Err` helper by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2212 +- Enable `perfsprint` linter by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2229 +- Trim down size of secp256k1 `Factory` struct by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2223 +- Fix test typos by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2233 +- P2P AppRequestFailed protobuf definition by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2111 +- Remove error from Router AppGossip by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2238 +- Document host and port behavior in help text by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2236 +- Remove `database.Manager` by @danlaine in https://github.com/ava-labs/avalanchego/pull/2239 +- Add `BaseTx` support to platformvm by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2232 +- Add `pebble` as valid value for `--db-type`. by @danlaine in https://github.com/ava-labs/avalanchego/pull/2244 +- Add nullable option to codec by @nytzuga in https://github.com/ava-labs/avalanchego/pull/2171 + +**Full Changelog**: https://github.com/ava-labs/avalanchego/compare/v1.10.14...v1.10.15 + ## [v1.10.14](https://github.com/ava-labs/avalanchego/releases/tag/v1.10.14) This version is backwards compatible to [v1.10.0](https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0). It is optional, but encouraged. diff --git a/go.mod b/go.mod index 0494bab53992..3117c0edf3e1 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/DataDog/zstd v1.5.2 github.com/Microsoft/go-winio v0.5.2 github.com/NYTimes/gziphandler v1.1.1 - github.com/ava-labs/coreth v0.12.8-rc.0 + github.com/ava-labs/coreth v0.12.8-rc.1 github.com/ava-labs/ledger-avalanche/go v0.0.0-20230105152938-00a24d05a8c7 github.com/btcsuite/btcd/btcutil v1.1.3 github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 diff --git a/go.sum b/go.sum index 10b15cd40ae7..0ad1313cd1b7 100644 --- a/go.sum +++ b/go.sum @@ -62,8 +62,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/coreth v0.12.8-rc.0 h1:9W3i5/6ckOifhD/jrxWwd2SOMYmCAmDG5PUJ6EHxE74= -github.com/ava-labs/coreth v0.12.8-rc.0/go.mod h1:GBH5SxHZdScSp95IijDs9+Gxw/QDIWvfoLKiJMNYLsE= +github.com/ava-labs/coreth v0.12.8-rc.1 h1:tvJcxQTQzxIQqx8TnrxdyMhZYbdsMaiy6AEiOyjvaa4= +github.com/ava-labs/coreth v0.12.8-rc.1/go.mod h1:GBH5SxHZdScSp95IijDs9+Gxw/QDIWvfoLKiJMNYLsE= github.com/ava-labs/ledger-avalanche/go v0.0.0-20230105152938-00a24d05a8c7 h1:EdxD90j5sClfL5Ngpz2TlnbnkNYdFPDXa0jDOjam65c= github.com/ava-labs/ledger-avalanche/go v0.0.0-20230105152938-00a24d05a8c7/go.mod h1:XhiXSrh90sHUbkERzaxEftCmUz53eCijshDLZ4fByVM= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= diff --git a/proto/README.md b/proto/README.md index 51cf916dd7d8..34d4228571eb 100644 --- a/proto/README.md +++ b/proto/README.md @@ -1,6 +1,6 @@ # Avalanche gRPC -Now Serving: **Protocol Version 29** +Now Serving: **Protocol Version 30** Protobuf files are hosted at [https://buf.build/ava-labs/avalanche](https://buf.build/ava-labs/avalanche) and diff --git a/version/compatibility.json b/version/compatibility.json index 0d8382e21678..9a63fba3eafc 100644 --- a/version/compatibility.json +++ b/version/compatibility.json @@ -1,4 +1,7 @@ { + "30": [ + "v1.10.15" + ], "29": [ "v1.10.13", "v1.10.14" diff --git a/version/constants.go b/version/constants.go index 5cccb035d810..690e68b3505f 100644 --- a/version/constants.go +++ b/version/constants.go @@ -14,14 +14,14 @@ import ( // RPCChainVMProtocol should be bumped anytime changes are made which require // the plugin vm to upgrade to latest avalanchego release to be compatible. -const RPCChainVMProtocol uint = 29 +const RPCChainVMProtocol uint = 30 // These are globals that describe network upgrades and node versions var ( Current = &Semantic{ Major: 1, Minor: 10, - Patch: 14, + Patch: 15, } CurrentApp = &Application{ Major: Current.Major, From 03bc2b04579eb87ab9653c2480c385af2ea21675 Mon Sep 17 00:00:00 2001 From: evlekht Date: Thu, 7 Mar 2024 18:10:40 +0400 Subject: [PATCH 19/19] [AVAX] Post Merge fixes for Cortina 15 (v1.10.15) --- codec/reflectcodec/struct_fielder.go | 4 +- codec/reflectcodec/type_codec.go | 2 +- go.mod | 2 +- go.sum | 4 +- tests/e2e/x/transfer/virtuous.go | 2 +- tools/cert/main.go | 3 +- .../crypto/secp256k1/camino_secp256k1_test.go | 3 +- utils/nodeid/camino_helpers.go | 6 +-- version/compatibility.json | 2 +- vms/platformvm/camino_helpers_test.go | 15 +++---- vms/platformvm/camino_service.go | 8 ++-- vms/platformvm/camino_vm_test.go | 4 +- vms/platformvm/metrics/camino_tx_metrics.go | 11 ----- vms/platformvm/state/camino_test.go | 12 ++--- vms/platformvm/state/mock_chain.go | 2 +- vms/platformvm/state/mock_diff.go | 2 +- vms/platformvm/state/mock_state.go | 2 +- vms/platformvm/txs/base_tx_test.go | 4 +- vms/platformvm/txs/builder/camino_builder.go | 32 ------------- .../txs/builder/camino_builder_test.go | 2 +- .../txs/builder/camino_helpers_test.go | 15 +++---- vms/platformvm/txs/camino_base_tx.go | 8 ---- vms/platformvm/txs/codec.go | 6 +-- .../txs/executor/camino_helpers_test.go | 13 +++--- .../txs/executor/camino_tx_executor.go | 45 +++++++++++-------- .../txs/executor/camino_tx_executor_test.go | 12 ++--- vms/platformvm/txs/executor/camino_visitor.go | 16 ------- .../txs/executor/dac/camino_helpers_test.go | 4 +- vms/platformvm/txs/mempool/camino_visitor.go | 10 ----- vms/platformvm/utxo/camino_helpers_test.go | 3 +- vms/platformvm/utxo/camino_locked.go | 4 +- vms/platformvm/utxo/camino_locked_test.go | 16 +++---- vms/secp256k1fx/camino_credential.go | 2 +- vms/secp256k1fx/camino_fx.go | 2 +- vms/secp256k1fx/camino_fx_test.go | 3 +- vms/secp256k1fx/camino_keychain_test.go | 8 ++-- wallet/chain/p/camino_visitor.go | 12 ----- 37 files changed, 95 insertions(+), 206 deletions(-) delete mode 100644 vms/platformvm/txs/camino_base_tx.go diff --git a/codec/reflectcodec/struct_fielder.go b/codec/reflectcodec/struct_fielder.go index d406c72caf4a..a250666da783 100644 --- a/codec/reflectcodec/struct_fielder.go +++ b/codec/reflectcodec/struct_fielder.go @@ -32,7 +32,7 @@ var _ StructFielder = (*structFielder)(nil) type FieldDesc struct { Index int MaxSliceLen uint32 - Nullable bool + Nullable bool UpgradeVersion uint16 } @@ -150,7 +150,7 @@ func (s *structFielder) GetSerializedFields(t reflect.Type) (*SerializedFields, serializedFields.Fields = append(serializedFields.Fields, FieldDesc{ Index: i, MaxSliceLen: maxSliceLen, - Nullable: nullable, + Nullable: nullable, UpgradeVersion: upgradeVersion, }) } diff --git a/codec/reflectcodec/type_codec.go b/codec/reflectcodec/type_codec.go index 0a9fb1d748bb..d3c8aa673007 100644 --- a/codec/reflectcodec/type_codec.go +++ b/codec/reflectcodec/type_codec.go @@ -241,7 +241,7 @@ func (c *genericCodec) size( size += wrappers.LongLen } } - + for _, fieldDesc := range serializedFields.Fields { if fieldDesc.UpgradeVersion > upgradeVersion { break diff --git a/go.mod b/go.mod index d4eeea604eb2..e471049c208d 100644 --- a/go.mod +++ b/go.mod @@ -161,4 +161,4 @@ require ( replace github.com/ava-labs/avalanche-ledger-go => github.com/chain4travel/camino-ledger-go v0.0.13-c4t -replace github.com/ava-labs/coreth => github.com/chain4travel/caminoethvm v1.1.14-rc0 +replace github.com/ava-labs/coreth => github.com/chain4travel/caminoethvm v1.1.15-rc1 diff --git a/go.sum b/go.sum index c1aab72e97ec..229374b176e1 100644 --- a/go.sum +++ b/go.sum @@ -104,8 +104,8 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/chain4travel/caminoethvm v1.1.14-rc0 h1:MqCeMYzPSiaJnlaapLL2RYxcnZXh34g7P0WlaUdy50E= -github.com/chain4travel/caminoethvm v1.1.14-rc0/go.mod h1:vaF3LIgjGW1povg11ZAsnY+iWMuBrhsNWz5JBtpOu80= +github.com/chain4travel/caminoethvm v1.1.15-rc1 h1:zZ3kcN0FJGTgmTnfw5drrb+V10wiR0tho/m3/Jy9iS0= +github.com/chain4travel/caminoethvm v1.1.15-rc1/go.mod h1:aXs2X5y4BVp+fGUk4sR1rk1qHmrtTl6NxTJPhUVw3P0= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= diff --git a/tests/e2e/x/transfer/virtuous.go b/tests/e2e/x/transfer/virtuous.go index db0d2ef3c56d..2bfb4f7eaf01 100644 --- a/tests/e2e/x/transfer/virtuous.go +++ b/tests/e2e/x/transfer/virtuous.go @@ -38,7 +38,7 @@ import ( const ( totalRounds = 50 - metricBlksProcessing = "camino_X_blks_processing" //nolint:gosec + metricBlksProcessing = "camino_X_blks_processing" metricBlksAccepted = "camino_X_blks_accepted_count" ) diff --git a/tools/cert/main.go b/tools/cert/main.go index 4b6e2e5abbb2..010e9b9bce91 100644 --- a/tools/cert/main.go +++ b/tools/cert/main.go @@ -8,6 +8,7 @@ import ( "fmt" "os" "path" + "strconv" "strings" "github.com/decred/dcrd/dcrec/secp256k1/v4" @@ -53,7 +54,7 @@ func main() { num := "" for i := 1; i <= count; i++ { if count > 1 { - num = fmt.Sprintf("%d", i) + num = strconv.Itoa(i) } keyPath := path.Join(destPath, fmt.Sprintf(keyFile, num)) diff --git a/utils/crypto/secp256k1/camino_secp256k1_test.go b/utils/crypto/secp256k1/camino_secp256k1_test.go index 5f64c4bc1b54..3698ea19488e 100644 --- a/utils/crypto/secp256k1/camino_secp256k1_test.go +++ b/utils/crypto/secp256k1/camino_secp256k1_test.go @@ -66,13 +66,12 @@ func newCertAndKeyBytesWithNoExt() ([]byte, []byte, error) { } func getPublicKey(t *testing.T, tlsCert *tls.Certificate) []byte { - secp256Factory := Factory{} var nodePrivateKey *PrivateKey rsaPrivateKey, ok := tlsCert.PrivateKey.(*rsa.PrivateKey) require.True(t, ok) secpPrivateKey := RsaPrivateKeyToSecp256PrivateKey(rsaPrivateKey) - nodePrivateKey, err := secp256Factory.ToPrivateKey(secpPrivateKey.Serialize()) + nodePrivateKey, err := ToPrivateKey(secpPrivateKey.Serialize()) require.NoError(t, err) return nodePrivateKey.PublicKey().Address().Bytes() } diff --git a/utils/nodeid/camino_helpers.go b/utils/nodeid/camino_helpers.go index 515afd043cef..fc990477dbdf 100644 --- a/utils/nodeid/camino_helpers.go +++ b/utils/nodeid/camino_helpers.go @@ -19,7 +19,6 @@ func LoadLocalCaminoNodeKeysAndIDs(localStakingPath string) ([]*secp256k1.Privat nodeIDs := make([]ids.NodeID, localNodesCount) for index := 0; index < localNodesCount; index++ { - secp256Factory := secp256k1.Factory{} var nodePrivateKey *secp256k1.PrivateKey cert, err := staking.LoadTLSCertFromFiles( @@ -34,7 +33,7 @@ func LoadLocalCaminoNodeKeysAndIDs(localStakingPath string) ([]*secp256k1.Privat panic("Wrong private key type") } secpPrivateKey := secp256k1.RsaPrivateKeyToSecp256PrivateKey(rsaKey) - nodePrivateKey, err = secp256Factory.ToPrivateKey(secpPrivateKey.Serialize()) + nodePrivateKey, err = secp256k1.ToPrivateKey(secpPrivateKey.Serialize()) if err != nil { panic(err) } @@ -46,8 +45,7 @@ func LoadLocalCaminoNodeKeysAndIDs(localStakingPath string) ([]*secp256k1.Privat } func GenerateCaminoNodeKeyAndID() (*secp256k1.PrivateKey, ids.NodeID) { - secp256Factory := secp256k1.Factory{} - nodePrivateKey, err := secp256Factory.NewPrivateKey() + nodePrivateKey, err := secp256k1.NewPrivateKey() if err != nil { panic("Couldn't generate private key") } diff --git a/version/compatibility.json b/version/compatibility.json index 8da83ecef7b2..6b226af6cd92 100644 --- a/version/compatibility.json +++ b/version/compatibility.json @@ -1,6 +1,6 @@ { "30": [ - "v1.10.15" + "v1.1.15" ], "29": [ "v1.1.14", diff --git a/vms/platformvm/camino_helpers_test.go b/vms/platformvm/camino_helpers_test.go index f3a544bdaaeb..d5571b7245fe 100644 --- a/vms/platformvm/camino_helpers_test.go +++ b/vms/platformvm/camino_helpers_test.go @@ -13,7 +13,7 @@ import ( "github.com/ava-labs/avalanchego/api/keystore" "github.com/ava-labs/avalanchego/chains" "github.com/ava-labs/avalanchego/chains/atomic" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" @@ -28,7 +28,6 @@ import ( "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/nodeid" "github.com/ava-labs/avalanchego/utils/units" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" as "github.com/ava-labs/avalanchego/vms/platformvm/addrstate" "github.com/ava-labs/avalanchego/vms/platformvm/api" @@ -68,7 +67,7 @@ func defaultCaminoService(t *testing.T, camino api.Camino, utxos []api.UTXO) *Ca vm.ctx.Lock.Lock() defer vm.ctx.Lock.Unlock() - ks := keystore.New(logging.NoLog{}, manager.NewMemDB(version.Semantic1_0_0)) + ks := keystore.New(logging.NoLog{}, memdb.New()) require.NoError(t, ks.CreateUser(testUsername, testPassword)) vm.ctx.Keystore = ks.NewBlockchainKeyStore(vm.ctx.ChainID) return &CaminoService{ @@ -84,9 +83,9 @@ func newCaminoVM(t *testing.T, genesisConfig api.Camino, genesisUTXOs []api.UTXO vm := &VM{Config: defaultCaminoConfig()} - baseDBManager := manager.NewMemDB(version.Semantic1_0_0) - chainDBManager := baseDBManager.NewPrefixDBManager([]byte{0}) - atomicDB := prefixdb.New([]byte{1}, baseDBManager.Current().Database) + db := memdb.New() + chainDB := prefixdb.New([]byte{0}, db) + atomicDB := prefixdb.New([]byte{1}, db) if startTime == nil { startTime = &defaultStartTime @@ -114,7 +113,7 @@ func newCaminoVM(t *testing.T, genesisConfig api.Camino, genesisUTXOs []api.UTXO require.NoError(vm.Initialize( context.Background(), ctx, - chainDBManager, + chainDB, genesisBytes, nil, nil, @@ -239,7 +238,7 @@ func newCaminoGenesisWithUTXOs(t *testing.T, caminoGenesisConfig api.Camino, gen func generateKeyAndOwner(t *testing.T) (*secp256k1.PrivateKey, ids.ShortID, secp256k1fx.OutputOwners) { t.Helper() - key, err := testKeyFactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(t, err) addr := key.Address() return key, addr, secp256k1fx.OutputOwners{ diff --git a/vms/platformvm/camino_service.go b/vms/platformvm/camino_service.go index bff9bf98cbf5..d8bc61e1cb52 100644 --- a/vms/platformvm/camino_service.go +++ b/vms/platformvm/camino_service.go @@ -137,7 +137,7 @@ utxoFor: continue utxoFor } - utxoIDs = append(utxoIDs, &utxo.UTXOID) //nolint:gosec + utxoIDs = append(utxoIDs, &utxo.UTXOID) } response.camino = GetBalanceResponseV2{balances, unlockedOutputs, bondedOutputs, depositedOutputs, depositedBondedOutputs, utxoIDs} @@ -601,7 +601,7 @@ func (s *CaminoService) Claim(_ *http.Request, args *ClaimArgs, reply *api.JSONT type TransferArgs struct { api.UserPass api.JSONFromAddrs - Change platformapi.Owner `json:"change"` + Change string `json:"change"` TransferTo platformapi.Owner `json:"transferTo"` Amount json.Uint64 `json:"amount"` } @@ -618,7 +618,7 @@ func (s *CaminoService) Transfer(_ *http.Request, args *TransferArgs, reply *api return err } - change, err := s.secpOwnerFromAPI(&args.Change) + _, change, err := s.addrManager.ParseAddress(args.Change) if err != nil { return fmt.Errorf(errInvalidChangeAddr, err) } @@ -631,7 +631,7 @@ func (s *CaminoService) Transfer(_ *http.Request, args *TransferArgs, reply *api // Create the transaction tx, err := s.vm.txBuilder.NewBaseTx( uint64(args.Amount), - transferTo, + *transferTo, privKeys, change, ) diff --git a/vms/platformvm/camino_vm_test.go b/vms/platformvm/camino_vm_test.go index 6e186a3c3b74..7d938bb8d821 100644 --- a/vms/platformvm/camino_vm_test.go +++ b/vms/platformvm/camino_vm_test.go @@ -48,7 +48,7 @@ func TestRemoveDeferredValidator(t *testing.T) { rootAdminKey := caminoPreFundedKeys[0] adminProposerKey := caminoPreFundedKeys[0] - consortiumMemberKey, err := testKeyFactory.NewPrivateKey() + consortiumMemberKey, err := secp256k1.NewPrivateKey() require.NoError(err) outputOwners := &secp256k1fx.OutputOwners{ @@ -227,7 +227,7 @@ func TestRemoveReactivatedValidator(t *testing.T) { rootAdminKey := caminoPreFundedKeys[0] adminProposerKey := caminoPreFundedKeys[0] - consortiumMemberKey, err := testKeyFactory.NewPrivateKey() + consortiumMemberKey, err := secp256k1.NewPrivateKey() require.NoError(err) outputOwners := &secp256k1fx.OutputOwners{ diff --git a/vms/platformvm/metrics/camino_tx_metrics.go b/vms/platformvm/metrics/camino_tx_metrics.go index 71ea338a0924..402588d6c11c 100644 --- a/vms/platformvm/metrics/camino_tx_metrics.go +++ b/vms/platformvm/metrics/camino_tx_metrics.go @@ -20,7 +20,6 @@ type caminoTxMetrics struct { numClaimTxs, numRegisterNodeTxs, numRewardsImportTxs, - numBaseTxs, numMultisigAliasTxs, numAddDepositOfferTxs, numAddProposalTxs, @@ -47,7 +46,6 @@ func newCaminoTxMetrics( numClaimTxs: newTxMetric(namespace, "claim", registerer, &errs), numRegisterNodeTxs: newTxMetric(namespace, "register_node", registerer, &errs), numRewardsImportTxs: newTxMetric(namespace, "rewards_import", registerer, &errs), - numBaseTxs: newTxMetric(namespace, "base", registerer, &errs), numMultisigAliasTxs: newTxMetric(namespace, "multisig_alias", registerer, &errs), numAddDepositOfferTxs: newTxMetric(namespace, "add_deposit_offer", registerer, &errs), numAddProposalTxs: newTxMetric(namespace, "add_proposal", registerer, &errs), @@ -83,10 +81,6 @@ func (*txMetrics) RewardsImportTx(*txs.RewardsImportTx) error { return nil } -func (*txMetrics) BaseTx(*txs.BaseTx) error { - return nil -} - func (*txMetrics) MultisigAliasTx(*txs.MultisigAliasTx) error { return nil } @@ -139,11 +133,6 @@ func (m *caminoTxMetrics) RewardsImportTx(*txs.RewardsImportTx) error { return nil } -func (m *caminoTxMetrics) BaseTx(*txs.BaseTx) error { - m.numBaseTxs.Inc() - return nil -} - func (m *caminoTxMetrics) MultisigAliasTx(*txs.MultisigAliasTx) error { m.numMultisigAliasTxs.Inc() return nil diff --git a/vms/platformvm/state/camino_test.go b/vms/platformvm/state/camino_test.go index 572638f11462..86d725e9ca8d 100644 --- a/vms/platformvm/state/camino_test.go +++ b/vms/platformvm/state/camino_test.go @@ -11,13 +11,12 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/require" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/prefixdb" - "github.com/ava-labs/avalanchego/database/versiondb" root_genesis "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/utils/wrappers" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" as "github.com/ava-labs/avalanchego/vms/platformvm/addrstate" "github.com/ava-labs/avalanchego/vms/platformvm/deposit" @@ -25,8 +24,6 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/reward" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/secp256k1fx" - - db_manager "github.com/ava-labs/avalanchego/database/manager" ) const ( @@ -167,9 +164,8 @@ func getExpectedSupply( func TestSyncGenesis(t *testing.T) { require := require.New(t) s, _ := newInitializedState(require) - baseDBManager := db_manager.NewMemDB(version.Semantic1_0_0) - baseDB := versiondb.New(baseDBManager.Current().Database) - validatorsDB := prefixdb.New(validatorsPrefix, baseDB) + db := memdb.New() + validatorsDB := prefixdb.New(validatorsPrefix, db) var ( id = ids.GenerateTestID() @@ -255,7 +251,7 @@ func TestSyncGenesis(t *testing.T) { }, }, depositTxs, initialAdmin), }, - cs: *wrappers.IgnoreError(newCaminoState(baseDB, validatorsDB, prometheus.NewRegistry())).(*caminoState), + cs: *wrappers.IgnoreError(newCaminoState(db, validatorsDB, prometheus.NewRegistry())).(*caminoState), want: caminoDiff{ modifiedAddressStates: map[ids.ShortID]as.AddressState{initialAdmin: as.AddressStateRoleAdmin, shortID: as.AddressStateRoleKYC}, modifiedDepositOffers: map[ids.ID]*deposit.Offer{ diff --git a/vms/platformvm/state/mock_chain.go b/vms/platformvm/state/mock_chain.go index 11b76d71bc9a..e25d3c75d747 100644 --- a/vms/platformvm/state/mock_chain.go +++ b/vms/platformvm/state/mock_chain.go @@ -14,12 +14,12 @@ import ( ids "github.com/ava-labs/avalanchego/ids" set "github.com/ava-labs/avalanchego/utils/set" avax "github.com/ava-labs/avalanchego/vms/components/avax" - fx "github.com/ava-labs/avalanchego/vms/platformvm/fx" multisig "github.com/ava-labs/avalanchego/vms/components/multisig" addrstate "github.com/ava-labs/avalanchego/vms/platformvm/addrstate" config "github.com/ava-labs/avalanchego/vms/platformvm/config" dac "github.com/ava-labs/avalanchego/vms/platformvm/dac" deposit "github.com/ava-labs/avalanchego/vms/platformvm/deposit" + fx "github.com/ava-labs/avalanchego/vms/platformvm/fx" locked "github.com/ava-labs/avalanchego/vms/platformvm/locked" status "github.com/ava-labs/avalanchego/vms/platformvm/status" txs "github.com/ava-labs/avalanchego/vms/platformvm/txs" diff --git a/vms/platformvm/state/mock_diff.go b/vms/platformvm/state/mock_diff.go index 04d1161c9f98..859b1deabfd7 100644 --- a/vms/platformvm/state/mock_diff.go +++ b/vms/platformvm/state/mock_diff.go @@ -14,12 +14,12 @@ import ( ids "github.com/ava-labs/avalanchego/ids" set "github.com/ava-labs/avalanchego/utils/set" avax "github.com/ava-labs/avalanchego/vms/components/avax" - fx "github.com/ava-labs/avalanchego/vms/platformvm/fx" multisig "github.com/ava-labs/avalanchego/vms/components/multisig" addrstate "github.com/ava-labs/avalanchego/vms/platformvm/addrstate" config "github.com/ava-labs/avalanchego/vms/platformvm/config" dac "github.com/ava-labs/avalanchego/vms/platformvm/dac" deposit "github.com/ava-labs/avalanchego/vms/platformvm/deposit" + fx "github.com/ava-labs/avalanchego/vms/platformvm/fx" locked "github.com/ava-labs/avalanchego/vms/platformvm/locked" status "github.com/ava-labs/avalanchego/vms/platformvm/status" txs "github.com/ava-labs/avalanchego/vms/platformvm/txs" diff --git a/vms/platformvm/state/mock_state.go b/vms/platformvm/state/mock_state.go index de76e4529999..0d7c5baae594 100644 --- a/vms/platformvm/state/mock_state.go +++ b/vms/platformvm/state/mock_state.go @@ -22,10 +22,10 @@ import ( multisig "github.com/ava-labs/avalanchego/vms/components/multisig" addrstate "github.com/ava-labs/avalanchego/vms/platformvm/addrstate" block "github.com/ava-labs/avalanchego/vms/platformvm/block" - fx "github.com/ava-labs/avalanchego/vms/platformvm/fx" config "github.com/ava-labs/avalanchego/vms/platformvm/config" dac "github.com/ava-labs/avalanchego/vms/platformvm/dac" deposit "github.com/ava-labs/avalanchego/vms/platformvm/deposit" + fx "github.com/ava-labs/avalanchego/vms/platformvm/fx" locked "github.com/ava-labs/avalanchego/vms/platformvm/locked" status "github.com/ava-labs/avalanchego/vms/platformvm/status" txs "github.com/ava-labs/avalanchego/vms/platformvm/txs" diff --git a/vms/platformvm/txs/base_tx_test.go b/vms/platformvm/txs/base_tx_test.go index c6cba1570312..42b2662c1a58 100644 --- a/vms/platformvm/txs/base_tx_test.go +++ b/vms/platformvm/txs/base_tx_test.go @@ -81,7 +81,7 @@ func TestBaseTxSerialization(t *testing.T) { // Codec version 0x00, 0x00, // BaseTx Type ID - 0x00, 0x00, 0x00, 0x22, + 0x00, 0x00, 0x20, 0x8, // Mainnet network ID 0x00, 0x00, 0x00, 0x01, // P-chain blockchain ID @@ -227,7 +227,7 @@ func TestBaseTxSerialization(t *testing.T) { // Codec version 0x00, 0x00, // BaseTx Type ID - 0x00, 0x00, 0x00, 0x22, + 0x00, 0x00, 0x20, 0x8, // Mainnet network ID 0x00, 0x00, 0x00, 0x01, // P-chain blockchain ID diff --git a/vms/platformvm/txs/builder/camino_builder.go b/vms/platformvm/txs/builder/camino_builder.go index 327831b0cb27..80a0adee0f52 100644 --- a/vms/platformvm/txs/builder/camino_builder.go +++ b/vms/platformvm/txs/builder/camino_builder.go @@ -97,13 +97,6 @@ type CaminoTxBuilder interface { change *secp256k1fx.OutputOwners, ) (*txs.Tx, error) - NewBaseTx( - amount uint64, - transferTo *secp256k1fx.OutputOwners, - keys []*secp256k1.PrivateKey, - change *secp256k1fx.OutputOwners, - ) (*txs.Tx, error) - NewRewardsImportTx() (*txs.Tx, error) NewSystemUnlockDepositTx( @@ -570,31 +563,6 @@ func (b *caminoBuilder) NewRegisterNodeTx( return tx, tx.SyntacticVerify(b.ctx) } -func (b *caminoBuilder) NewBaseTx( - amount uint64, - transferTo *secp256k1fx.OutputOwners, - keys []*secp256k1.PrivateKey, - change *secp256k1fx.OutputOwners, -) (*txs.Tx, error) { - ins, outs, signers, _, err := b.Lock(b.state, keys, amount, b.cfg.TxFee, locked.StateUnlocked, transferTo, change, 0) - if err != nil { - return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err) - } - - utx := &txs.BaseTx{BaseTx: avax.BaseTx{ - NetworkID: b.ctx.NetworkID, - BlockchainID: b.ctx.ChainID, - Ins: ins, - Outs: outs, - }} - - tx, err := txs.NewSigned(utx, txs.Codec, signers) - if err != nil { - return nil, err - } - return tx, tx.SyntacticVerify(b.ctx) -} - func (b *caminoBuilder) NewRewardsImportTx() (*txs.Tx, error) { caminoGenesis, err := b.state.CaminoConfig() if err != nil { diff --git a/vms/platformvm/txs/builder/camino_builder_test.go b/vms/platformvm/txs/builder/camino_builder_test.go index d99fba192978..351d6caae43a 100644 --- a/vms/platformvm/txs/builder/camino_builder_test.go +++ b/vms/platformvm/txs/builder/camino_builder_test.go @@ -180,7 +180,7 @@ func TestUnlockDepositTx(t *testing.T) { MaxDuration: 60, }}, } - testKey, err := testKeyfactory.NewPrivateKey() + testKey, err := secp256k1.NewPrivateKey() require.NoError(t, err) outputOwners := secp256k1fx.OutputOwners{ diff --git a/vms/platformvm/txs/builder/camino_helpers_test.go b/vms/platformvm/txs/builder/camino_helpers_test.go index 473ea80f8776..34c08e4627a6 100644 --- a/vms/platformvm/txs/builder/camino_helpers_test.go +++ b/vms/platformvm/txs/builder/camino_helpers_test.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/prefixdb" "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" @@ -35,7 +35,6 @@ import ( "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/utils/wrappers" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/api" "github.com/ava-labs/avalanchego/vms/platformvm/caminoconfig" @@ -75,7 +74,6 @@ var ( testCaminoSubnet1ControlKeys = caminoPreFundedKeys[0:3] lastAcceptedID = ids.GenerateTestID() testSubnet1 *txs.Tx - testKeyfactory secp256k1.Factory errMissing = errors.New("missing") ) @@ -119,8 +117,7 @@ func newCaminoEnvironment(postBanff bool, caminoGenesisConf api.Camino) *caminoE config := defaultCaminoConfig(postBanff) clk := defaultClock(postBanff) - baseDBManager := manager.NewMemDB(version.CurrentDatabase) - baseDB := versiondb.New(baseDBManager.Current().Database) + baseDB := versiondb.New(memdb.New()) ctx, msm := defaultCtx(baseDB) fx := defaultFx(clk, ctx.Log, isBootstrapped.Get()) @@ -182,8 +179,7 @@ func newCaminoBuilder(postBanff bool, state state.State) (*caminoBuilder, *versi config := defaultCaminoConfig(postBanff) clk := defaultClock(postBanff) - baseDBManager := manager.NewMemDB(version.CurrentDatabase) - baseDB := versiondb.New(baseDBManager.Current().Database) + baseDB := versiondb.New(memdb.New()) ctx, _ := defaultCtx(baseDB) fx := defaultFx(clk, ctx.Log, isBootstrapped.Get()) @@ -515,7 +511,7 @@ func generateTestUTXO(txID ids.ID, assetID ids.ID, amount uint64, outputOwners s } func generateKeyAndOwner() (*secp256k1.PrivateKey, ids.ShortID, secp256k1fx.OutputOwners) { - key, err := testKeyfactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() if err != nil { panic(err) } @@ -568,8 +564,7 @@ func newCaminoBuilderWithMocks(postBanff bool, state state.State, sharedMemory a config := defaultCaminoConfig(postBanff) clk := defaultClock(postBanff) - baseDBManager := manager.NewMemDB(version.CurrentDatabase) - baseDB := versiondb.New(baseDBManager.Current().Database) + baseDB := versiondb.New(memdb.New()) ctx, _ := defaultCtx(baseDB) if sharedMemory != nil { diff --git a/vms/platformvm/txs/camino_base_tx.go b/vms/platformvm/txs/camino_base_tx.go deleted file mode 100644 index 8e8930a6dd0e..000000000000 --- a/vms/platformvm/txs/camino_base_tx.go +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (C) 2022-2023, Chain4Travel AG. All rights reserved. -// See the file LICENSE for licensing terms. - -package txs - -func (tx *BaseTx) Visit(visitor Visitor) error { - return visitor.BaseTx(tx) -} diff --git a/vms/platformvm/txs/codec.go b/vms/platformvm/txs/codec.go index 4ce801c37f6b..5efe9d7e382f 100644 --- a/vms/platformvm/txs/codec.go +++ b/vms/platformvm/txs/codec.go @@ -18,7 +18,6 @@ import ( "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" - "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/vms/components/multisig" "github.com/ava-labs/avalanchego/vms/platformvm/dac" @@ -147,8 +146,5 @@ func RegisterUnsignedTxsTypes(targetCodec linearcodec.CaminoCodec) error { } func RegisterDUnsignedTxsTypes(targetCodec linearcodec.Codec) error { - return utils.Err( - targetCodec.RegisterType(&TransferSubnetOwnershipTx{}), - targetCodec.RegisterType(&BaseTx{}), - ) + return targetCodec.RegisterType(&TransferSubnetOwnershipTx{}) } diff --git a/vms/platformvm/txs/executor/camino_helpers_test.go b/vms/platformvm/txs/executor/camino_helpers_test.go index 48bfddcffc06..972d2c755b4c 100644 --- a/vms/platformvm/txs/executor/camino_helpers_test.go +++ b/vms/platformvm/txs/executor/camino_helpers_test.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/chains" "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/database" - "github.com/ava-labs/avalanchego/database/manager" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" @@ -34,7 +34,6 @@ import ( "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/utils/wrappers" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/multisig" "github.com/ava-labs/avalanchego/vms/platformvm/api" @@ -101,8 +100,7 @@ func newCaminoEnvironment(postBanff, addSubnet bool, caminoGenesisConf api.Camin config := defaultCaminoConfig(postBanff) clk := defaultClock(postBanff) - baseDBManager := manager.NewMemDB(version.CurrentDatabase) - baseDB := versiondb.New(baseDBManager.Current().Database) + baseDB := versiondb.New(memdb.New()) ctx, msm := defaultCtx(baseDB) fx := defaultFx(clk, ctx.Log, isBootstrapped.Get()) @@ -529,7 +527,7 @@ func generateInsFromUTXOsWithSigIndices(utxos []*avax.UTXO, sigIndices []uint32) } func generateKeyAndOwner(t *testing.T) (*secp256k1.PrivateKey, ids.ShortID, secp256k1fx.OutputOwners) { - key, err := testKeyfactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(t, err) addr := key.Address() return key, addr, secp256k1fx.OutputOwners{ @@ -568,7 +566,7 @@ func generateMsigAliasAndKeys(t *testing.T, threshold, addrsCount uint32, sorted } for i := uint32(0); i < addrsCount; i++ { - key, err := testKeyfactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(t, err) msgOwners.Owners.Addrs[i] = key.Address() msgOwners.Keys[i] = key @@ -623,8 +621,7 @@ func newCaminoEnvironmentWithMocks( clk := defaultClock(true) - baseDBManager := manager.NewMemDB(version.CurrentDatabase) - baseDB := versiondb.New(baseDBManager.Current().Database) + baseDB := versiondb.New(memdb.New()) ctx, msm := defaultCtx(baseDB) fx := defaultFx(clk, ctx.Log, isBootstrapped.Get()) diff --git a/vms/platformvm/txs/executor/camino_tx_executor.go b/vms/platformvm/txs/executor/camino_tx_executor.go index d2e7c24959c9..1fe36dee313e 100644 --- a/vms/platformvm/txs/executor/camino_tx_executor.go +++ b/vms/platformvm/txs/executor/camino_tx_executor.go @@ -1483,33 +1483,40 @@ func (e *CaminoStandardTxExecutor) RewardsImportTx(tx *txs.RewardsImportTx) erro } func (e *CaminoStandardTxExecutor) BaseTx(tx *txs.BaseTx) error { - if err := e.Tx.SyntacticVerify(e.Ctx); err != nil { + caminoConfig, err := e.State.CaminoConfig() + if err != nil { return err } + if !caminoConfig.LockModeBondDeposit { + return e.StandardTxExecutor.BaseTx(tx) + } + if err := locked.VerifyNoLocks(tx.Ins, tx.Outs); err != nil { return err } - if e.Bootstrapped.Get() { - baseFee, err := e.State.GetBaseFee() - if err != nil { - return err - } + if err := e.Tx.SyntacticVerify(e.Ctx); err != nil { + return err + } - if err := e.FlowChecker.VerifyLock( - tx, - e.State, - tx.Ins, - tx.Outs, - e.Tx.Creds, - 0, - baseFee, - e.Ctx.AVAXAssetID, - locked.StateUnlocked, - ); err != nil { - return fmt.Errorf("%w: %w", ErrFlowCheckFailed, err) - } + baseFee, err := e.State.GetBaseFee() + if err != nil { + return err + } + + if err := e.FlowChecker.VerifyLock( + tx, + e.State, + tx.Ins, + tx.Outs, + e.Tx.Creds, + 0, + baseFee, + e.Ctx.AVAXAssetID, + locked.StateUnlocked, + ); err != nil { + return fmt.Errorf("%w: %w", ErrFlowCheckFailed, err) } avax.Consume(e.State, tx.Ins) diff --git a/vms/platformvm/txs/executor/camino_tx_executor_test.go b/vms/platformvm/txs/executor/camino_tx_executor_test.go index 35421fa5099e..d14fcf525589 100644 --- a/vms/platformvm/txs/executor/camino_tx_executor_test.go +++ b/vms/platformvm/txs/executor/camino_tx_executor_test.go @@ -3035,7 +3035,7 @@ func TestCaminoStandardTxExecutorDepositTx(t *testing.T) { for phaseIndex, phase := range phases { t.Run(fmt.Sprintf("%s, %s", phase.name, name), func(t *testing.T) { env := newCaminoEnvironmentWithMocks(tt.caminoGenesisConf, nil) - defer func() { require.NoError(t, shutdownCaminoEnvironment(env)) }() //nolint:lint + defer func() { require.NoError(t, shutdownCaminoEnvironment(env)) }() phase.prepare(env, tt.chaintime) @@ -3400,7 +3400,7 @@ func TestCaminoStandardTxExecutorUnlockDepositTx(t *testing.T) { t.Run(name, func(t *testing.T) { require := require.New(t) env := newCaminoEnvironmentWithMocks(caminoGenesisConf, nil) - defer func() { require.NoError(shutdownCaminoEnvironment(env)) }() //nolint:lint + defer func() { require.NoError(shutdownCaminoEnvironment(env)) }() tt.utx.BlockchainID = env.ctx.ChainID tt.utx.NetworkID = env.ctx.NetworkID @@ -4261,7 +4261,7 @@ func TestCaminoStandardTxExecutorClaimTx(t *testing.T) { t.Run(name, func(t *testing.T) { require := require.New(t) env := newCaminoEnvironmentWithMocks(caminoGenesisConf, nil) - defer func() { require.NoError(shutdownCaminoEnvironment(env)) }() //nolint:lint + defer func() { require.NoError(shutdownCaminoEnvironment(env)) }() // ensuring that ins and outs from test case are sorted, signing tx @@ -4576,7 +4576,7 @@ func TestCaminoStandardTxExecutorRegisterNodeTx(t *testing.T) { for name, tt := range tests { t.Run(name, func(t *testing.T) { env := newCaminoEnvironmentWithMocks(caminoGenesisConf, nil) - defer func() { require.NoError(t, shutdownCaminoEnvironment(env)) }() //nolint:lint + defer func() { require.NoError(t, shutdownCaminoEnvironment(env)) }() utx := tt.utx() avax.SortTransferableInputsWithSigners(utx.Ins, tt.signers) @@ -4862,7 +4862,7 @@ func TestCaminoStandardTxExecutorRewardsImportTx(t *testing.T) { ctrl := gomock.NewController(t) env := newCaminoEnvironmentWithMocks(caminoGenesisConf, tt.sharedMemory(t, ctrl, tt.utxos)) - defer func() { require.NoError(shutdownCaminoEnvironment(env)) }() //nolint:lint + defer func() { require.NoError(shutdownCaminoEnvironment(env)) }() utx := tt.utx(tt.utxos) avax.SortTransferableInputsWithSigners(utx.Ins, tt.signers) @@ -5514,7 +5514,7 @@ func TestCaminoStandardTxExecutorMultisigAliasTx(t *testing.T) { require := require.New(t) env := newCaminoEnvironmentWithMocks(caminoGenesisConf, nil) - defer func() { require.NoError(shutdownCaminoEnvironment(env)) }() //nolint:lint + defer func() { require.NoError(shutdownCaminoEnvironment(env)) }() avax.SortTransferableInputsWithSigners(tt.utx.Ins, tt.signers) diff --git a/vms/platformvm/txs/executor/camino_visitor.go b/vms/platformvm/txs/executor/camino_visitor.go index 21c34cb42db2..ea04fb46c808 100644 --- a/vms/platformvm/txs/executor/camino_visitor.go +++ b/vms/platformvm/txs/executor/camino_visitor.go @@ -33,10 +33,6 @@ func (*StandardTxExecutor) RewardsImportTx(*txs.RewardsImportTx) error { return ErrWrongTxType } -func (*StandardTxExecutor) BaseTx(*txs.BaseTx) error { - return ErrWrongTxType -} - func (*StandardTxExecutor) MultisigAliasTx(*txs.MultisigAliasTx) error { return ErrWrongTxType } @@ -83,10 +79,6 @@ func (*ProposalTxExecutor) RewardsImportTx(*txs.RewardsImportTx) error { return ErrWrongTxType } -func (*ProposalTxExecutor) BaseTx(*txs.BaseTx) error { - return ErrWrongTxType -} - func (*ProposalTxExecutor) MultisigAliasTx(*txs.MultisigAliasTx) error { return ErrWrongTxType } @@ -133,10 +125,6 @@ func (*AtomicTxExecutor) RewardsImportTx(*txs.RewardsImportTx) error { return ErrWrongTxType } -func (*AtomicTxExecutor) BaseTx(*txs.BaseTx) error { - return ErrWrongTxType -} - func (*AtomicTxExecutor) MultisigAliasTx(*txs.MultisigAliasTx) error { return ErrWrongTxType } @@ -183,10 +171,6 @@ func (v *MempoolTxVerifier) RewardsImportTx(tx *txs.RewardsImportTx) error { return v.standardTx(tx) } -func (v *MempoolTxVerifier) BaseTx(tx *txs.BaseTx) error { - return v.standardTx(tx) -} - func (v *MempoolTxVerifier) MultisigAliasTx(tx *txs.MultisigAliasTx) error { return v.standardTx(tx) } diff --git a/vms/platformvm/txs/executor/dac/camino_helpers_test.go b/vms/platformvm/txs/executor/dac/camino_helpers_test.go index dc7347778f3d..35cb5c6d417c 100644 --- a/vms/platformvm/txs/executor/dac/camino_helpers_test.go +++ b/vms/platformvm/txs/executor/dac/camino_helpers_test.go @@ -39,8 +39,6 @@ var ( cChainID = ids.Empty.Prefix(1) avaxAssetID = ids.ID{'y', 'e', 'e', 't'} - testKeyfactory secp256k1.Factory - errMissing = errors.New("missing") ) @@ -210,7 +208,7 @@ func generateTestInFromUTXO(utxo *avax.UTXO, sigIndices []uint32) *avax.Transfer } func generateKeyAndOwner(t *testing.T) (*secp256k1.PrivateKey, ids.ShortID, secp256k1fx.OutputOwners) { - key, err := testKeyfactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(t, err) addr := key.Address() return key, addr, secp256k1fx.OutputOwners{ diff --git a/vms/platformvm/txs/mempool/camino_visitor.go b/vms/platformvm/txs/mempool/camino_visitor.go index 3037f7791360..662b041e91b6 100644 --- a/vms/platformvm/txs/mempool/camino_visitor.go +++ b/vms/platformvm/txs/mempool/camino_visitor.go @@ -43,11 +43,6 @@ func (i *issuer) RewardsImportTx(*txs.RewardsImportTx) error { return nil } -func (i *issuer) BaseTx(*txs.BaseTx) error { - i.m.addDecisionTx(i.tx) - return nil -} - func (i *issuer) MultisigAliasTx(*txs.MultisigAliasTx) error { i.m.addDecisionTx(i.tx) return nil @@ -104,11 +99,6 @@ func (r *remover) RewardsImportTx(*txs.RewardsImportTx) error { return nil } -func (r *remover) BaseTx(*txs.BaseTx) error { - r.m.removeDecisionTxs([]*txs.Tx{r.tx}) - return nil -} - func (r *remover) MultisigAliasTx(*txs.MultisigAliasTx) error { r.m.removeDecisionTxs([]*txs.Tx{r.tx}) return nil diff --git a/vms/platformvm/utxo/camino_helpers_test.go b/vms/platformvm/utxo/camino_helpers_test.go index 6801a939453b..ae1fa3ba3647 100644 --- a/vms/platformvm/utxo/camino_helpers_test.go +++ b/vms/platformvm/utxo/camino_helpers_test.go @@ -340,8 +340,7 @@ func generateTestStakeableOut(assetID ids.ID, amount, locktime uint64, outputOwn func generateOwnersAndSig(tx txs.UnsignedTx) (secp256k1fx.OutputOwners, *secp256k1fx.Credential) { txHash := hashing.ComputeHash256(tx.Bytes()) - cryptFactory := secp256k1.Factory{} - key, err := cryptFactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() if err != nil { panic(err) } diff --git a/vms/platformvm/utxo/camino_locked.go b/vms/platformvm/utxo/camino_locked.go index 5f3e3b9e46cf..38904de56eed 100644 --- a/vms/platformvm/utxo/camino_locked.go +++ b/vms/platformvm/utxo/camino_locked.go @@ -789,7 +789,7 @@ func (h *handler) VerifyLock( if err != nil { return fmt.Errorf( "failed to read consumed UTXO %s due to: %w", - &input.UTXOID, //nolint:gosec + &input.UTXOID, err, ) } @@ -1042,7 +1042,7 @@ func (h *handler) VerifyUnlockDeposit( if err != nil { return fmt.Errorf( "failed to read consumed UTXO %s due to: %w", - &input.UTXOID, //nolint:gosec + &input.UTXOID, err, ) } diff --git a/vms/platformvm/utxo/camino_locked_test.go b/vms/platformvm/utxo/camino_locked_test.go index 7edc57a29de5..78164f4871e2 100644 --- a/vms/platformvm/utxo/camino_locked_test.go +++ b/vms/platformvm/utxo/camino_locked_test.go @@ -13,12 +13,12 @@ import ( "go.uber.org/mock/gomock" "github.com/ava-labs/avalanchego/database" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/set" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/multisig" "github.com/ava-labs/avalanchego/vms/components/verify" @@ -28,16 +28,13 @@ import ( "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/secp256k1fx" - - db_manager "github.com/ava-labs/avalanchego/database/manager" ) func TestUnlockUTXOs(t *testing.T) { testHandler := defaultCaminoHandler(t) ctx := testHandler.ctx - cryptFactory := secp256k1.Factory{} - key, err := cryptFactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(t, err) address := key.PublicKey().Address() outputOwners := secp256k1fx.OutputOwners{ @@ -164,14 +161,12 @@ func TestLock(t *testing.T) { config := defaultConfig() ctx := snow.DefaultContextTest() - baseDBManager := db_manager.NewMemDB(version.Semantic1_0_0) - baseDB := versiondb.New(baseDBManager.Current().Database) + baseDB := versiondb.New(memdb.New()) rewardsCalc := reward.NewCalculator(config.RewardConfig) testState := defaultState(config, ctx, baseDB, rewardsCalc) - cryptFactory := secp256k1.Factory{} - key, err := cryptFactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(t, err) address := key.PublicKey().Address() outputOwners := secp256k1fx.OutputOwners{ @@ -921,8 +916,7 @@ func TestVerifyLockUTXOs(t *testing.T) { func TestGetDepositUnlockableAmounts(t *testing.T) { config := defaultConfig() ctx := snow.DefaultContextTest() - baseDBManager := db_manager.NewMemDB(version.Semantic1_0_0) - baseDB := versiondb.New(baseDBManager.Current().Database) + baseDB := versiondb.New(memdb.New()) rewardsCalc := reward.NewCalculator(config.RewardConfig) addr0 := ids.GenerateTestShortID() addresses := set.NewSet[ids.ShortID](0) diff --git a/vms/secp256k1fx/camino_credential.go b/vms/secp256k1fx/camino_credential.go index 221a74dedd5c..6ab3eca18ae5 100644 --- a/vms/secp256k1fx/camino_credential.go +++ b/vms/secp256k1fx/camino_credential.go @@ -51,7 +51,7 @@ func (mcr *MultisigCredential) MarshalJSON() ([]byte, error) { if err = json.Unmarshal(b, &jsonFieldMap); err != nil { return nil, err } - jsonFieldMap["sigIdxs"] = mcr.SigIdxs //nolint:gosec + jsonFieldMap["sigIdxs"] = mcr.SigIdxs return json.Marshal(jsonFieldMap) } diff --git a/vms/secp256k1fx/camino_fx.go b/vms/secp256k1fx/camino_fx.go index f1a8c459654d..1058affc47c9 100644 --- a/vms/secp256k1fx/camino_fx.go +++ b/vms/secp256k1fx/camino_fx.go @@ -112,7 +112,7 @@ func (fx *Fx) RecoverAddresses(msg []byte, verifies []verify.Verifiable) (Recove if visited[sig] { continue } - pk, err := fx.SECPFactory.RecoverHashPublicKey(txHash, sig[:]) + pk, err := fx.RecoverPublicKeyFromHash(txHash, sig[:]) if err != nil { return nil, err } diff --git a/vms/secp256k1fx/camino_fx_test.go b/vms/secp256k1fx/camino_fx_test.go index e106653d81d2..10642e59df59 100644 --- a/vms/secp256k1fx/camino_fx_test.go +++ b/vms/secp256k1fx/camino_fx_test.go @@ -327,8 +327,7 @@ func defaultFx(t *testing.T) *Fx { func generateKey(t *testing.T) (*secp256k1.PrivateKey, ids.ShortID) { require := require.New(t) - secpFactory := secp256k1.Factory{} - key, err := secpFactory.NewPrivateKey() + key, err := secp256k1.NewPrivateKey() require.NoError(err) return key, key.Address() } diff --git a/vms/secp256k1fx/camino_keychain_test.go b/vms/secp256k1fx/camino_keychain_test.go index 95f58ce5ef3c..395a62b34da2 100644 --- a/vms/secp256k1fx/camino_keychain_test.go +++ b/vms/secp256k1fx/camino_keychain_test.go @@ -44,7 +44,7 @@ func TestSpendMultiSigNoMSig(t *testing.T) { for _, keyStr := range keys { skBytes, err := formatting.Decode(formatting.HexNC, keyStr) require.NoError(err) - sk, err := kc.factory.ToPrivateKey(skBytes) + sk, err := secp256k1.ToPrivateKey(skBytes) require.NoError(err) kc.Add(sk) addresses = append(addresses, sk.PublicKey().Address()) @@ -78,7 +78,7 @@ func TestSpendMultiSigMSig(t *testing.T) { for _, keyStr := range keys { skBytes, err := formatting.Decode(formatting.HexNC, keyStr) require.NoError(err) - sk, err := kc.factory.ToPrivateKey(skBytes) + sk, err := secp256k1.ToPrivateKey(skBytes) require.NoError(err) kc.Add(sk) addresses = append(addresses, sk.PublicKey().Address()) @@ -146,7 +146,7 @@ func TestSpendMultiSigCycle(t *testing.T) { for _, keyStr := range keys { skBytes, err := formatting.Decode(formatting.HexNC, keyStr) require.NoError(err) - sk, err := kc.factory.ToPrivateKey(skBytes) + sk, err := secp256k1.ToPrivateKey(skBytes) require.NoError(err) kc.Add(sk) addresses = append(addresses, sk.PublicKey().Address()) @@ -185,7 +185,7 @@ func TestUnverifiedNestedOwner(t *testing.T) { skBytes, err := formatting.Decode(formatting.HexNC, keyStr) require.NoError(err) - sk, err := kc.factory.ToPrivateKey(skBytes) + sk, err := secp256k1.ToPrivateKey(skBytes) require.NoError(err) // Only one signer for this test if i == 1 { diff --git a/wallet/chain/p/camino_visitor.go b/wallet/chain/p/camino_visitor.go index f22d361e55c3..66ce3b2ea9c3 100644 --- a/wallet/chain/p/camino_visitor.go +++ b/wallet/chain/p/camino_visitor.go @@ -34,10 +34,6 @@ func (*backendVisitor) RewardsImportTx(*txs.RewardsImportTx) error { return errUnsupportedTxType } -func (b *backendVisitor) BaseTx(tx *txs.BaseTx) error { - return b.baseTx(tx) -} - func (b *backendVisitor) MultisigAliasTx(tx *txs.MultisigAliasTx) error { return b.baseTx(&tx.BaseTx) } @@ -104,14 +100,6 @@ func (*signerVisitor) RewardsImportTx(*txs.RewardsImportTx) error { return errUnsupportedTxType } -func (s *signerVisitor) BaseTx(tx *txs.BaseTx) error { - txSigners, err := s.getSigners(constants.PlatformChainID, tx.Ins) - if err != nil { - return err - } - return sign(s.tx, false, txSigners) -} - func (s *signerVisitor) MultisigAliasTx(tx *txs.MultisigAliasTx) error { txSigners, err := s.getSigners(constants.PlatformChainID, tx.Ins) if err != nil {