From 128757d430b7ee96edc5ebbac68056232fb53431 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Wed, 25 Oct 2023 02:03:45 +0300 Subject: [PATCH 01/25] Move the overridden manager into the node (#2199) Signed-off-by: Ceyhun Onur Co-authored-by: Alberto Benegiamo Co-authored-by: Stephen Buttolph --- chains/manager.go | 12 ++---- node/node.go | 4 +- .../validators => node}/overridden_manager.go | 17 ++++---- .../overridden_manager_test.go | 40 +++++++++++++++++-- snow/networking/benchlist/manager.go | 10 +---- 5 files changed, 53 insertions(+), 30 deletions(-) rename {snow/validators => node}/overridden_manager.go (83%) rename {snow/validators => node}/overridden_manager_test.go (57%) diff --git a/chains/manager.go b/chains/manager.go index 5b0101b62392..2234e82aadcc 100644 --- a/chains/manager.go +++ b/chains/manager.go @@ -531,19 +531,13 @@ func (m *manager) buildChain(chainParams ChainParameters, sb subnets.Subnet) (*c } } - vdrs := m.Validators - if !m.SybilProtectionEnabled { - // If sybil protection is disabled, everyone validates every chain - vdrs = validators.NewOverriddenManager(constants.PrimaryNetworkID, vdrs) - } - var chain *chain switch vm := vm.(type) { case vertex.LinearizableVMWithEngine: chain, err = m.createAvalancheChain( ctx, chainParams.GenesisData, - vdrs, + m.Validators, vm, fxs, sb, @@ -552,7 +546,7 @@ func (m *manager) buildChain(chainParams ChainParameters, sb subnets.Subnet) (*c return nil, fmt.Errorf("error while creating new avalanche vm %w", err) } case block.ChainVM: - beacons := vdrs + beacons := m.Validators if chainParams.ID == constants.PlatformChainID { beacons = chainParams.CustomBeacons } @@ -560,7 +554,7 @@ func (m *manager) buildChain(chainParams ChainParameters, sb subnets.Subnet) (*c chain, err = m.createSnowmanChain( ctx, chainParams.GenesisData, - vdrs, + m.Validators, beacons, vm, fxs, diff --git a/node/node.go b/node/node.go index 4a1e67259679..a2c41f83c623 100644 --- a/node/node.go +++ b/node/node.go @@ -290,7 +290,6 @@ func (n *Node) initNetworking() error { // Configure benchlist n.Config.BenchlistConfig.Validators = n.vdrs n.Config.BenchlistConfig.Benchable = n.Config.ConsensusRouter - n.Config.BenchlistConfig.SybilProtectionEnabled = n.Config.SybilProtectionEnabled n.benchlistManager = benchlist.NewManager(&n.Config.BenchlistConfig) n.uptimeCalculator = uptime.NewLockedCalculator() @@ -1401,6 +1400,9 @@ func (n *Node) Initialize( } n.vdrs = validators.NewManager() + if !n.Config.SybilProtectionEnabled { + n.vdrs = newOverriddenManager(constants.PrimaryNetworkID, n.vdrs) + } if err := n.initResourceManager(n.MetricsRegisterer); err != nil { return fmt.Errorf("problem initializing resource manager: %w", err) } diff --git a/snow/validators/overridden_manager.go b/node/overridden_manager.go similarity index 83% rename from snow/validators/overridden_manager.go rename to node/overridden_manager.go index bcafb3bd2946..91d8c198a4c3 100644 --- a/snow/validators/overridden_manager.go +++ b/node/overridden_manager.go @@ -1,21 +1,22 @@ // Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package validators +package node import ( "fmt" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/set" ) -var _ Manager = (*overriddenManager)(nil) +var _ validators.Manager = (*overriddenManager)(nil) -// NewOverriddenManager returns a Manager that overrides of all calls to the +// newOverriddenManager returns a Manager that overrides of all calls to the // underlying Manager to only operate on the validators in [subnetID]. -func NewOverriddenManager(subnetID ids.ID, manager Manager) Manager { +func newOverriddenManager(subnetID ids.ID, manager validators.Manager) *overriddenManager { return &overriddenManager{ subnetID: subnetID, manager: manager, @@ -27,7 +28,7 @@ func NewOverriddenManager(subnetID ids.ID, manager Manager) Manager { // subnetID here is typically the primary network ID, as it has the superset of // all subnet validators. type overriddenManager struct { - manager Manager + manager validators.Manager subnetID ids.ID } @@ -43,7 +44,7 @@ func (o *overriddenManager) GetWeight(_ ids.ID, nodeID ids.NodeID) uint64 { return o.manager.GetWeight(o.subnetID, nodeID) } -func (o *overriddenManager) GetValidator(_ ids.ID, nodeID ids.NodeID) (*Validator, bool) { +func (o *overriddenManager) GetValidator(_ ids.ID, nodeID ids.NodeID) (*validators.Validator, bool) { return o.manager.GetValidator(o.subnetID, nodeID) } @@ -67,11 +68,11 @@ func (o *overriddenManager) Sample(_ ids.ID, size int) ([]ids.NodeID, error) { return o.manager.Sample(o.subnetID, size) } -func (o *overriddenManager) GetMap(ids.ID) map[ids.NodeID]*GetValidatorOutput { +func (o *overriddenManager) GetMap(ids.ID) map[ids.NodeID]*validators.GetValidatorOutput { return o.manager.GetMap(o.subnetID) } -func (o *overriddenManager) RegisterCallbackListener(_ ids.ID, listener SetCallbackListener) { +func (o *overriddenManager) RegisterCallbackListener(_ ids.ID, listener validators.SetCallbackListener) { o.manager.RegisterCallbackListener(o.subnetID, listener) } diff --git a/snow/validators/overridden_manager_test.go b/node/overridden_manager_test.go similarity index 57% rename from snow/validators/overridden_manager_test.go rename to node/overridden_manager_test.go index 2d904ee7fa59..79f03579a5d0 100644 --- a/snow/validators/overridden_manager_test.go +++ b/node/overridden_manager_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package validators +package node import ( "math" @@ -10,8 +10,42 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/snow/validators" ) +func TestOverriddenManager(t *testing.T) { + require := require.New(t) + + nodeID0 := ids.GenerateTestNodeID() + nodeID1 := ids.GenerateTestNodeID() + subnetID0 := ids.GenerateTestID() + subnetID1 := ids.GenerateTestID() + + m := validators.NewManager() + require.NoError(m.AddStaker(subnetID0, nodeID0, nil, ids.Empty, 1)) + require.NoError(m.AddStaker(subnetID1, nodeID1, nil, ids.Empty, 1)) + + om := newOverriddenManager(subnetID0, m) + _, ok := om.GetValidator(subnetID0, nodeID0) + require.True(ok) + _, ok = om.GetValidator(subnetID0, nodeID1) + require.False(ok) + _, ok = om.GetValidator(subnetID1, nodeID0) + require.True(ok) + _, ok = om.GetValidator(subnetID1, nodeID1) + require.False(ok) + + require.NoError(om.RemoveWeight(subnetID1, nodeID0, 1)) + _, ok = om.GetValidator(subnetID0, nodeID0) + require.False(ok) + _, ok = om.GetValidator(subnetID0, nodeID1) + require.False(ok) + _, ok = om.GetValidator(subnetID1, nodeID0) + require.False(ok) + _, ok = om.GetValidator(subnetID1, nodeID1) + require.False(ok) +} + func TestOverriddenString(t *testing.T) { require := require.New(t) @@ -24,12 +58,12 @@ func TestOverriddenString(t *testing.T) { subnetID1, err := ids.FromString("2mcwQKiD8VEspmMJpL1dc7okQQ5dDVAWeCBZ7FWBFAbxpv3t7w") require.NoError(err) - m := NewManager() + m := validators.NewManager() require.NoError(m.AddStaker(subnetID0, nodeID0, nil, ids.Empty, 1)) require.NoError(m.AddStaker(subnetID0, nodeID1, nil, ids.Empty, math.MaxInt64-1)) require.NoError(m.AddStaker(subnetID1, nodeID1, nil, ids.Empty, 1)) - om := NewOverriddenManager(subnetID0, m) + om := newOverriddenManager(subnetID0, m) expected := "Overridden Validator Manager (SubnetID = TtF4d2QWbk5vzQGTEPrN48x6vwgAoAmKQ9cbp79inpQmcRKES): Validator Manager: (Size = 2)\n" + " Subnet[TtF4d2QWbk5vzQGTEPrN48x6vwgAoAmKQ9cbp79inpQmcRKES]: Validator Set: (Size = 2, Weight = 9223372036854775807)\n" + " Validator[0]: NodeID-111111111111111111116DBWJs, 1\n" + diff --git a/snow/networking/benchlist/manager.go b/snow/networking/benchlist/manager.go index 537b67863a41..7a42e8245267 100644 --- a/snow/networking/benchlist/manager.go +++ b/snow/networking/benchlist/manager.go @@ -10,7 +10,6 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/validators" - "github.com/ava-labs/avalanchego/utils/constants" ) var _ Manager = (*manager)(nil) @@ -42,7 +41,6 @@ type Manager interface { type Config struct { Benchable Benchable `json:"-"` Validators validators.Manager `json:"-"` - SybilProtectionEnabled bool `json:"-"` Threshold int `json:"threshold"` MinimumFailingDuration time.Duration `json:"minimumFailingDuration"` Duration time.Duration `json:"duration"` @@ -110,16 +108,10 @@ func (m *manager) RegisterChain(ctx *snow.ConsensusContext) error { return nil } - vdrs := m.config.Validators - if !m.config.SybilProtectionEnabled { - // If sybil protection is disabled, everyone validates every chain - vdrs = validators.NewOverriddenManager(constants.PrimaryNetworkID, vdrs) - } - benchlist, err := NewBenchlist( ctx, m.config.Benchable, - vdrs, + m.config.Validators, m.config.Threshold, m.config.MinimumFailingDuration, m.config.Duration, From cd77a1e85315bec8f1a5444543b03fac50dfd363 Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Wed, 25 Oct 2023 13:27:43 -0400 Subject: [PATCH 02/25] Remove `aggregate` struct (#2213) --- utils/wrappers/errors.go | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/utils/wrappers/errors.go b/utils/wrappers/errors.go index 1f0f19846ffe..641734da16c0 100644 --- a/utils/wrappers/errors.go +++ b/utils/wrappers/errors.go @@ -3,10 +3,6 @@ package wrappers -import "strings" - -var _ error = (*aggregate)(nil) - type Errs struct{ Err error } func (errs *Errs) Errored() bool { @@ -23,28 +19,3 @@ func (errs *Errs) Add(errors ...error) { } } } - -// NewAggregate returns an aggregate error from a list of errors -func NewAggregate(errs []error) error { - err := &aggregate{errs} - if len(err.Errors()) == 0 { - return nil - } - return err -} - -type aggregate struct{ errs []error } - -// Error returns the slice of errors with comma separated messsages wrapped in brackets -// [ error string 0 ], [ error string 1 ] ... -func (a *aggregate) Error() string { - errString := make([]string, len(a.errs)) - for i, err := range a.errs { - errString[i] = "[" + err.Error() + "]" - } - return strings.Join(errString, ",") -} - -func (a *aggregate) Errors() []error { - return a.errs -} From de168b17155830f1de9fbcfdc4893cb5d2a05094 Mon Sep 17 00:00:00 2001 From: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:47:48 -0400 Subject: [PATCH 03/25] Add log for ungraceful shutdown on startup (#2215) Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> --- node/node.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/node/node.go b/node/node.go index a2c41f83c623..4200a33699ab 100644 --- a/node/node.go +++ b/node/node.go @@ -89,7 +89,9 @@ import ( ) var ( - genesisHashKey = []byte("genesisID") + genesisHashKey = []byte("genesisID") + ungracefulShutdown = []byte("ungracefulShutdown") + indexerDBPrefix = []byte{0x00} errInvalidTLSKey = errors.New("invalid TLS key") @@ -556,6 +558,23 @@ func (n *Node) initDatabase() error { if genesisHash != expectedGenesisHash { return fmt.Errorf("db contains invalid genesis hash. DB Genesis: %s Generated Genesis: %s", genesisHash, expectedGenesisHash) } + + ok, err := n.DB.Has(ungracefulShutdown) + if err != nil { + return fmt.Errorf("failed to read ungraceful shutdown key: %w", err) + } + + if ok { + n.Log.Warn("detected previous ungraceful shutdown") + } + + if err := n.DB.Put(ungracefulShutdown, nil); err != nil { + return fmt.Errorf( + "failed to write ungraceful shutdown key at: %w", + err, + ) + } + return nil } @@ -1530,6 +1549,13 @@ func (n *Node) shutdown() { n.runtimeManager.Stop(context.TODO()) if n.DBManager != nil { + if err := n.DB.Delete(ungracefulShutdown); err != nil { + n.Log.Error( + "failed to delete ungraceful shutdown key", + zap.Error(err), + ) + } + if err := n.DBManager.Close(); err != nil { n.Log.Warn("error during DB shutdown", zap.Error(err), From 150ffae2e917659db7b0f9e683dd34073f4f94c5 Mon Sep 17 00:00:00 2001 From: Dan Laine Date: Wed, 25 Oct 2023 16:39:10 -0400 Subject: [PATCH 04/25] Add pebble database implementation (#1999) Co-authored-by: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Co-authored-by: Stephen Buttolph --- database/iterator.go | 2 + database/pebble/batch.go | 111 +++++++++++++ database/pebble/batch_test.go | 47 ++++++ database/pebble/db.go | 292 ++++++++++++++++++++++++++++++++++ database/pebble/db_test.go | 147 +++++++++++++++++ database/pebble/iterator.go | 133 ++++++++++++++++ database/test_database.go | 8 + go.mod | 8 +- go.sum | 13 +- 9 files changed, 753 insertions(+), 8 deletions(-) create mode 100644 database/pebble/batch.go create mode 100644 database/pebble/batch_test.go create mode 100644 database/pebble/db.go create mode 100644 database/pebble/db_test.go create mode 100644 database/pebble/iterator.go diff --git a/database/iterator.go b/database/iterator.go index 3cfd075cc9d3..c83ceac49639 100644 --- a/database/iterator.go +++ b/database/iterator.go @@ -34,10 +34,12 @@ type Iterator interface { // Key returns the key of the current key/value pair, or nil if done. // If the database is closed, must still report the current contents. + // Behavior is undefined after Release is called. Key() []byte // Value returns the value of the current key/value pair, or nil if done. // If the database is closed, must still report the current contents. + // Behavior is undefined after Release is called. Value() []byte // Release releases associated resources. Release should always succeed and diff --git a/database/pebble/batch.go b/database/pebble/batch.go new file mode 100644 index 000000000000..b6c9d283b64d --- /dev/null +++ b/database/pebble/batch.go @@ -0,0 +1,111 @@ +// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package pebble + +import ( + "fmt" + + "github.com/cockroachdb/pebble" + + "github.com/ava-labs/avalanchego/database" +) + +var _ database.Batch = (*batch)(nil) + +// Not safe for concurrent use. +type batch struct { + batch *pebble.Batch + db *Database + size int + + // True iff [batch] has been written to the database + // since the last time [Reset] was called. + written bool +} + +func (db *Database) NewBatch() database.Batch { + return &batch{ + db: db, + batch: db.pebbleDB.NewBatch(), + } +} + +func (b *batch) Put(key, value []byte) error { + b.size += len(key) + len(value) + pebbleByteOverHead + return b.batch.Set(key, value, pebble.Sync) +} + +func (b *batch) Delete(key []byte) error { + b.size += len(key) + pebbleByteOverHead + return b.batch.Delete(key, pebble.Sync) +} + +func (b *batch) Size() int { + return b.size +} + +// Assumes [b.db.lock] is not held. +func (b *batch) Write() error { + b.db.lock.RLock() + defer b.db.lock.RUnlock() + + // Committing to a closed database makes pebble panic + // so make sure [b.db] isn't closed. + if b.db.closed { + return database.ErrClosed + } + + if !b.written { + // This batch has not been written to the database yet. + if err := updateError(b.batch.Commit(pebble.Sync)); err != nil { + return err + } + b.written = true + return nil + } + + // pebble doesn't support writing a batch twice so we have to clone + // [b] and commit the clone. + batchClone := b.db.pebbleDB.NewBatch() + + // Copy the batch. + if err := batchClone.Apply(b.batch, nil); err != nil { + return err + } + + // Commit the new batch. + return updateError(batchClone.Commit(pebble.Sync)) +} + +func (b *batch) Reset() { + b.batch.Reset() + b.written = false + b.size = 0 +} + +func (b *batch) Replay(w database.KeyValueWriterDeleter) error { + reader := b.batch.Reader() + for { + kind, k, v, ok := reader.Next() + if !ok { + return nil + } + switch kind { + case pebble.InternalKeyKindSet: + if err := w.Put(k, v); err != nil { + return err + } + case pebble.InternalKeyKindDelete: + if err := w.Delete(k); err != nil { + return err + } + default: + return fmt.Errorf("%w: %v", errInvalidOperation, kind) + } + } +} + +func (b *batch) Inner() database.Batch { + return b +} diff --git a/database/pebble/batch_test.go b/database/pebble/batch_test.go new file mode 100644 index 000000000000..a84134708956 --- /dev/null +++ b/database/pebble/batch_test.go @@ -0,0 +1,47 @@ +// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package pebble + +import ( + "testing" + + "github.com/prometheus/client_golang/prometheus" + + "github.com/stretchr/testify/require" + + "github.com/ava-labs/avalanchego/utils/logging" +) + +// Note: TestInterface tests other batch functionality. +func TestBatch(t *testing.T) { + require := require.New(t) + dirName := t.TempDir() + + db, err := New(dirName, DefaultConfigBytes, logging.NoLog{}, "", prometheus.NewRegistry()) + require.NoError(err) + + batchIntf := db.NewBatch() + batch, ok := batchIntf.(*batch) + require.True(ok) + + require.False(batch.written) + + key1, value1 := []byte("key1"), []byte("value1") + require.NoError(batch.Put(key1, value1)) + require.Equal(len(key1)+len(value1)+pebbleByteOverHead, batch.Size()) + + require.NoError(batch.Write()) + + require.True(batch.written) + + got, err := db.Get(key1) + require.NoError(err) + require.Equal(value1, got) + + batch.Reset() + require.False(batch.written) + require.Zero(batch.Size()) + + require.NoError(db.Close()) +} diff --git a/database/pebble/db.go b/database/pebble/db.go new file mode 100644 index 000000000000..13ab1db04977 --- /dev/null +++ b/database/pebble/db.go @@ -0,0 +1,292 @@ +// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package pebble + +import ( + "bytes" + "context" + "encoding/json" + "errors" + "sync" + + "github.com/cockroachdb/pebble" + + "github.com/prometheus/client_golang/prometheus" + + "golang.org/x/exp/slices" + + "go.uber.org/zap" + + "github.com/ava-labs/avalanchego/database" + "github.com/ava-labs/avalanchego/utils/logging" + "github.com/ava-labs/avalanchego/utils/set" + "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 + +var ( + _ database.Database = (*Database)(nil) + + errInvalidOperation = errors.New("invalid operation") + + defaultCacheSize = 512 * units.MiB + DefaultConfig = Config{ + CacheSize: defaultCacheSize, + BytesPerSync: 512 * units.KiB, + WALBytesPerSync: 0, // Default to no background syncing. + MemTableStopWritesThreshold: 8, + MemTableSize: defaultCacheSize / 4, + MaxOpenFiles: 4096, + MaxConcurrentCompactions: 1, + } + + DefaultConfigBytes []byte +) + +func init() { + var err error + DefaultConfigBytes, err = json.Marshal(DefaultConfig) + if err != nil { + panic(err) + } +} + +type Database struct { + lock sync.RWMutex + pebbleDB *pebble.DB + closed bool + openIterators set.Set[*iter] +} + +type Config struct { + CacheSize int `json:"cacheSize"` + BytesPerSync int `json:"bytesPerSync"` + WALBytesPerSync int `json:"walBytesPerSync"` // 0 means no background syncing + MemTableStopWritesThreshold int `json:"memTableStopWritesThreshold"` + MemTableSize int `json:"memTableSize"` + MaxOpenFiles int `json:"maxOpenFiles"` + MaxConcurrentCompactions int `json:"maxConcurrentCompactions"` +} + +// 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 + } + + opts := &pebble.Options{ + Cache: pebble.NewCache(int64(cfg.CacheSize)), + BytesPerSync: cfg.BytesPerSync, + Comparer: pebble.DefaultComparer, + WALBytesPerSync: cfg.WALBytesPerSync, + MemTableStopWritesThreshold: cfg.MemTableStopWritesThreshold, + MemTableSize: cfg.MemTableSize, + MaxOpenFiles: cfg.MaxOpenFiles, + MaxConcurrentCompactions: func() int { return cfg.MaxConcurrentCompactions }, + } + opts.Experimental.ReadSamplingMultiplier = -1 // Disable seek compaction + + log.Info( + "opening pebble", + zap.Reflect("config", cfg), + ) + + db, err := pebble.Open(file, opts) + return &Database{ + pebbleDB: db, + openIterators: set.Set[*iter]{}, + }, err +} + +func (db *Database) Close() error { + db.lock.Lock() + defer db.lock.Unlock() + + if db.closed { + return database.ErrClosed + } + + db.closed = true + + for iter := range db.openIterators { + iter.lock.Lock() + iter.release() + iter.lock.Unlock() + } + db.openIterators.Clear() + + return updateError(db.pebbleDB.Close()) +} + +func (db *Database) HealthCheck(_ context.Context) (interface{}, error) { + db.lock.RLock() + defer db.lock.RUnlock() + + if db.closed { + return nil, database.ErrClosed + } + return nil, nil +} + +func (db *Database) Has(key []byte) (bool, error) { + db.lock.RLock() + defer db.lock.RUnlock() + + if db.closed { + return false, database.ErrClosed + } + + _, closer, err := db.pebbleDB.Get(key) + if err == pebble.ErrNotFound { + return false, nil + } + if err != nil { + return false, updateError(err) + } + return true, closer.Close() +} + +func (db *Database) Get(key []byte) ([]byte, error) { + db.lock.RLock() + defer db.lock.RUnlock() + + if db.closed { + return nil, database.ErrClosed + } + + data, closer, err := db.pebbleDB.Get(key) + if err != nil { + return nil, updateError(err) + } + return slices.Clone(data), closer.Close() +} + +func (db *Database) Put(key []byte, value []byte) error { + db.lock.RLock() + defer db.lock.RUnlock() + + if db.closed { + return database.ErrClosed + } + + return updateError(db.pebbleDB.Set(key, value, pebble.Sync)) +} + +func (db *Database) Delete(key []byte) error { + db.lock.RLock() + defer db.lock.RUnlock() + + if db.closed { + return database.ErrClosed + } + + return updateError(db.pebbleDB.Delete(key, pebble.Sync)) +} + +func (db *Database) Compact(start []byte, end []byte) error { + db.lock.RLock() + defer db.lock.RUnlock() + + if db.closed { + return database.ErrClosed + } + + if end == nil { + // The database.Database spec treats a nil [limit] as a key after all keys + // but pebble treats a nil [limit] as a key before all keys in Compact. + // Use the greatest key in the database as the [limit] to get the desired behavior. + it := db.pebbleDB.NewIter(&pebble.IterOptions{}) + + if !it.Last() { + // The database is empty. + return it.Close() + } + + end = it.Key() + if err := it.Close(); err != nil { + return err + } + } + + if pebble.DefaultComparer.Compare(start, end) >= 1 { + // pebble requires [start] < [end] + return nil + } + + return updateError(db.pebbleDB.Compact(start, end, true /* parallelize */)) +} + +func (db *Database) NewIterator() database.Iterator { + return db.NewIteratorWithStartAndPrefix(nil, nil) +} + +func (db *Database) NewIteratorWithStart(start []byte) database.Iterator { + return db.NewIteratorWithStartAndPrefix(start, nil) +} + +func (db *Database) NewIteratorWithPrefix(prefix []byte) database.Iterator { + return db.NewIteratorWithStartAndPrefix(nil, prefix) +} + +func (db *Database) NewIteratorWithStartAndPrefix(start, prefix []byte) database.Iterator { + db.lock.Lock() + defer db.lock.Unlock() + + if db.closed { + return &iter{ + db: db, + closed: true, + err: database.ErrClosed, + } + } + + iter := &iter{ + db: db, + iter: db.pebbleDB.NewIter(keyRange(start, prefix)), + } + db.openIterators.Add(iter) + return iter +} + +// Converts a pebble-specific error to its Avalanche equivalent, if applicable. +func updateError(err error) error { + switch err { + case pebble.ErrClosed: + return database.ErrClosed + case pebble.ErrNotFound: + return database.ErrNotFound + default: + return err + } +} + +func keyRange(start, prefix []byte) *pebble.IterOptions { + opt := &pebble.IterOptions{ + LowerBound: prefix, + UpperBound: prefixToUpperBound(prefix), + } + if bytes.Compare(start, prefix) == 1 { + opt.LowerBound = start + } + return opt +} + +// Returns an upper bound that stops after all keys with the given [prefix]. +// Assumes the Database uses bytes.Compare for key comparison and not a custom +// comparer. +func prefixToUpperBound(prefix []byte) []byte { + for i := len(prefix) - 1; i >= 0; i-- { + if prefix[i] != 0xFF { + upperBound := make([]byte, i+1) + copy(upperBound, prefix) + upperBound[i]++ + return upperBound + } + } + return nil +} diff --git a/database/pebble/db_test.go b/database/pebble/db_test.go new file mode 100644 index 000000000000..c72a9d687c88 --- /dev/null +++ b/database/pebble/db_test.go @@ -0,0 +1,147 @@ +// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package pebble + +import ( + "testing" + + "github.com/prometheus/client_golang/prometheus" + + "github.com/stretchr/testify/require" + + "github.com/ava-labs/avalanchego/database" + "github.com/ava-labs/avalanchego/utils/logging" +) + +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 +} + +func TestInterface(t *testing.T) { + for _, test := range database.Tests { + db := newDB(t) + test(t, db) + _ = db.Close() + } +} + +func FuzzKeyValue(f *testing.F) { + db := newDB(f) + database.FuzzKeyValue(f, db) + _ = db.Close() +} + +func FuzzNewIteratorWithPrefix(f *testing.F) { + db := newDB(f) + database.FuzzNewIteratorWithPrefix(f, db) + _ = db.Close() +} + +func BenchmarkInterface(b *testing.B) { + for _, size := range database.BenchmarkSizes { + keys, values := database.SetupBenchmark(b, size[0], size[1], size[2]) + for _, bench := range database.Benchmarks { + db := newDB(b) + bench(b, db, "pebble", keys, values) + _ = db.Close() + } + } +} + +func TestKeyRange(t *testing.T) { + require := require.New(t) + + type test struct { + start []byte + prefix []byte + expectedLower []byte + expectedUpper []byte + } + + tests := []test{ + { + start: nil, + prefix: nil, + expectedLower: nil, + expectedUpper: nil, + }, + { + start: nil, + prefix: []byte{}, + expectedLower: []byte{}, + expectedUpper: nil, + }, + { + start: nil, + prefix: []byte{0x00}, + expectedLower: []byte{0x00}, + expectedUpper: []byte{0x01}, + }, + { + start: []byte{0x00, 0x02}, + prefix: []byte{0x00}, + expectedLower: []byte{0x00, 0x02}, + expectedUpper: []byte{0x01}, + }, + { + start: []byte{0x01}, + prefix: []byte{0x00}, + expectedLower: []byte{0x01}, + expectedUpper: []byte{0x01}, + }, + { + start: nil, + prefix: []byte{0x01}, + expectedLower: []byte{0x01}, + expectedUpper: []byte{0x02}, + }, + { + start: nil, + prefix: []byte{0xFF}, + expectedLower: []byte{0xFF}, + expectedUpper: nil, + }, + { + start: []byte{0x00}, + prefix: []byte{0xFF}, + expectedLower: []byte{0xFF}, + expectedUpper: nil, + }, + { + start: nil, + prefix: []byte{0x01, 0x02}, + expectedLower: []byte{0x01, 0x02}, + expectedUpper: []byte{0x01, 0x03}, + }, + { + start: []byte{0x01, 0x02}, + prefix: []byte{0x01, 0x02}, + expectedLower: []byte{0x01, 0x02}, + expectedUpper: []byte{0x01, 0x03}, + }, + { + start: []byte{0x01, 0x02, 0x05}, + prefix: []byte{0x01, 0x02}, + expectedLower: []byte{0x01, 0x02, 0x05}, + expectedUpper: []byte{0x01, 0x03}, + }, + { + start: nil, + prefix: []byte{0x01, 0x02, 0xFF}, + expectedLower: []byte{0x01, 0x02, 0xFF}, + expectedUpper: []byte{0x01, 0x03}, + }, + } + + for _, tt := range tests { + t.Run(string(tt.start)+" "+string(tt.prefix), func(t *testing.T) { + bounds := keyRange(tt.start, tt.prefix) + require.Equal(tt.expectedLower, bounds.LowerBound) + require.Equal(tt.expectedUpper, bounds.UpperBound) + }) + } +} diff --git a/database/pebble/iterator.go b/database/pebble/iterator.go new file mode 100644 index 000000000000..115c122e30f4 --- /dev/null +++ b/database/pebble/iterator.go @@ -0,0 +1,133 @@ +// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package pebble + +import ( + "errors" + "fmt" + "sync" + + "github.com/cockroachdb/pebble" + + "golang.org/x/exp/slices" + + "github.com/ava-labs/avalanchego/database" +) + +var ( + _ database.Iterator = (*iter)(nil) + + errCouldntGetValue = errors.New("couldnt get iterator value") +) + +type iter struct { + // [lock] ensures that only one goroutine can access [iter] at a time. + // Note that [Database.Close] calls [iter.Release] so we need [lock] to ensure + // that the user and [Database.Close] don't execute [iter.Release] concurrently. + // Invariant: [Database.lock] is never grabbed while holding [lock]. + lock sync.Mutex + + db *Database + iter *pebble.Iterator + + initialized bool + closed bool + err error + + hasNext bool + nextKey []byte + nextVal []byte +} + +// Must not be called with [db.lock] held. +func (it *iter) Next() bool { + it.lock.Lock() + defer it.lock.Unlock() + + switch { + case it.err != nil: + it.hasNext = false + return false + case it.closed: + it.hasNext = false + it.err = database.ErrClosed + return false + case !it.initialized: + it.hasNext = it.iter.First() + it.initialized = true + default: + it.hasNext = it.iter.Next() + } + + if !it.hasNext { + return false + } + + it.nextKey = it.iter.Key() + + var err error + it.nextVal, err = it.iter.ValueAndErr() + if err != nil { + it.hasNext = false + it.err = fmt.Errorf("%w: %w", errCouldntGetValue, err) + return false + } + + return true +} + +func (it *iter) Error() error { + it.lock.Lock() + defer it.lock.Unlock() + + if it.err != nil || it.closed { + return it.err + } + return updateError(it.iter.Error()) +} + +func (it *iter) Key() []byte { + it.lock.Lock() + defer it.lock.Unlock() + + if !it.hasNext { + return nil + } + return slices.Clone(it.nextKey) +} + +func (it *iter) Value() []byte { + it.lock.Lock() + defer it.lock.Unlock() + + if !it.hasNext { + return nil + } + return slices.Clone(it.nextVal) +} + +func (it *iter) Release() { + it.db.lock.Lock() + defer it.db.lock.Unlock() + + it.lock.Lock() + defer it.lock.Unlock() + + it.release() +} + +// Assumes [it.lock] and [it.db.lock] are held. +func (it *iter) release() { + if it.closed { + return + } + + // Remove the iterator from the list of open iterators. + it.db.openIterators.Remove(it) + + it.closed = true + if err := it.iter.Close(); err != nil { + it.err = updateError(err) + } +} diff --git a/database/test_database.go b/database/test_database.go index 69fb1d2b7948..2e68f53341b8 100644 --- a/database/test_database.go +++ b/database/test_database.go @@ -933,7 +933,15 @@ func TestCompactNoPanic(t *testing.T, db Database) { require.NoError(db.Put(key2, value2)) require.NoError(db.Put(key3, value3)) + // Test compacting with nil bounds require.NoError(db.Compact(nil, nil)) + + // Test compacting when start > end + require.NoError(db.Compact([]byte{2}, []byte{1})) + + // Test compacting when start > largest key + require.NoError(db.Compact([]byte{255}, nil)) + require.NoError(db.Close()) err := db.Compact(nil, nil) require.ErrorIs(err, ErrClosed) diff --git a/go.mod b/go.mod index 134f99cfdd19..34c4b0cb7475 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/ava-labs/coreth v0.12.6-rc.2 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 github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 github.com/ethereum/go-ethereum v1.12.0 github.com/golang-jwt/jwt/v4 v4.3.0 @@ -57,7 +58,7 @@ require ( go.uber.org/mock v0.2.0 go.uber.org/zap v1.24.0 golang.org/x/crypto v0.14.0 - golang.org/x/exp v0.0.0-20230206171751-46f607a40771 + golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df golang.org/x/net v0.17.0 golang.org/x/sync v0.3.0 golang.org/x/term v0.13.0 @@ -70,6 +71,7 @@ require ( ) require ( + github.com/BurntSushi/toml v1.2.1 // indirect github.com/VictoriaMetrics/fastcache v1.10.0 // indirect github.com/benbjohnson/clock v1.3.0 // indirect github.com/beorn7/perks v1.0.1 // indirect @@ -78,7 +80,6 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cockroachdb/errors v1.9.1 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect - github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 // indirect github.com/cockroachdb/redact v1.1.3 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -86,6 +87,7 @@ require ( github.com/dlclark/regexp2 v1.7.0 // indirect github.com/dop251/goja v0.0.0-20230605162241-28ee0ee714f3 // indirect github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 // indirect + github.com/frankban/quicktest v1.14.4 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect github.com/getsentry/sentry-go v0.18.0 // indirect @@ -123,7 +125,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/common v0.39.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect - github.com/rogpeppe/go-internal v1.9.0 // indirect + github.com/rogpeppe/go-internal v1.10.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sanity-io/litter v1.5.1 // indirect github.com/spf13/afero v1.8.2 // indirect diff --git a/go.sum b/go.sum index c4077434e565..f4d30e37b89f 100644 --- a/go.sum +++ b/go.sum @@ -38,7 +38,8 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= +github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= +github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno= github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo= @@ -186,7 +187,8 @@ github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= -github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= +github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= +github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= @@ -522,8 +524,9 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= @@ -697,8 +700,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20230206171751-46f607a40771 h1:xP7rWLUr1e1n2xkK5YB4LI0hPEy3LJC6Wk+D4pGlOJg= -golang.org/x/exp v0.0.0-20230206171751-46f607a40771/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= +golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= From f020a05c1f0f85b461c97e32db8670fcc91ca469 Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Wed, 25 Oct 2023 16:51:24 -0400 Subject: [PATCH 05/25] Add `TransferSubnetOwnershipTx` (#2178) Signed-off-by: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> --- vms/platformvm/block/codec.go | 1 + vms/platformvm/metrics/tx_metrics.go | 9 +- vms/platformvm/txs/builder/builder.go | 52 ++ vms/platformvm/txs/builder/mock_builder.go | 15 + vms/platformvm/txs/codec.go | 8 + .../txs/executor/atomic_tx_executor.go | 4 + .../txs/executor/proposal_tx_executor.go | 4 + .../txs/executor/staker_tx_verification.go | 48 ++ .../txs/executor/standard_tx_executor.go | 24 + .../txs/executor/tx_mempool_verifier.go | 4 + vms/platformvm/txs/mempool/issuer.go | 5 + vms/platformvm/txs/mempool/remover.go | 5 + .../txs/transfer_subnet_ownership_tx.go | 65 ++ .../txs/transfer_subnet_ownership_tx_test.go | 669 ++++++++++++++++++ vms/platformvm/txs/visitor.go | 1 + vms/platformvm/vm_test.go | 75 ++ wallet/chain/p/backend_visitor.go | 5 + wallet/chain/p/signer_visitor.go | 13 + 18 files changed, 1006 insertions(+), 1 deletion(-) create mode 100644 vms/platformvm/txs/transfer_subnet_ownership_tx.go create mode 100644 vms/platformvm/txs/transfer_subnet_ownership_tx_test.go diff --git a/vms/platformvm/block/codec.go b/vms/platformvm/block/codec.go index 42c94cc8f62a..efffedcb551b 100644 --- a/vms/platformvm/block/codec.go +++ b/vms/platformvm/block/codec.go @@ -36,6 +36,7 @@ func init() { RegisterApricotBlockTypes(c), txs.RegisterUnsignedTxsTypes(c), RegisterBanffBlockTypes(c), + txs.RegisterDUnsignedTxsTypes(c), ) } errs.Add( diff --git a/vms/platformvm/metrics/tx_metrics.go b/vms/platformvm/metrics/tx_metrics.go index 118f1156e677..17d6a090957b 100644 --- a/vms/platformvm/metrics/tx_metrics.go +++ b/vms/platformvm/metrics/tx_metrics.go @@ -27,7 +27,8 @@ type txMetrics struct { numRemoveSubnetValidatorTxs, numTransformSubnetTxs, numAddPermissionlessValidatorTxs, - numAddPermissionlessDelegatorTxs prometheus.Counter + numAddPermissionlessDelegatorTxs, + numTransferSubnetOwnershipTxs prometheus.Counter } func newTxMetrics( @@ -49,6 +50,7 @@ func newTxMetrics( numTransformSubnetTxs: newTxMetric(namespace, "transform_subnet", registerer, &errs), numAddPermissionlessValidatorTxs: newTxMetric(namespace, "add_permissionless_validator", registerer, &errs), numAddPermissionlessDelegatorTxs: newTxMetric(namespace, "add_permissionless_delegator", registerer, &errs), + numTransferSubnetOwnershipTxs: newTxMetric(namespace, "transfer_subnet_ownership", registerer, &errs), } return m, errs.Err } @@ -132,3 +134,8 @@ func (m *txMetrics) AddPermissionlessDelegatorTx(*txs.AddPermissionlessDelegator m.numAddPermissionlessDelegatorTxs.Inc() return nil } + +func (m *txMetrics) TransferSubnetOwnershipTx(*txs.TransferSubnetOwnershipTx) error { + m.numTransferSubnetOwnershipTxs.Inc() + return nil +} diff --git a/vms/platformvm/txs/builder/builder.go b/vms/platformvm/txs/builder/builder.go index 279202087619..3f13ec2ecad9 100644 --- a/vms/platformvm/txs/builder/builder.go +++ b/vms/platformvm/txs/builder/builder.go @@ -159,6 +159,19 @@ type ProposalTxBuilder interface { changeAddr ids.ShortID, ) (*txs.Tx, error) + // Creates a transaction that transfers ownership of [subnetID] + // threshold: [threshold] of [ownerAddrs] needed to manage this subnet + // ownerAddrs: control addresses for the new subnet + // keys: keys to use for modifying the subnet + // changeAddr: address to send change to, if there is any + NewTransferSubnetOwnershipTx( + subnetID ids.ID, + threshold uint32, + ownerAddrs []ids.ShortID, + keys []*secp256k1.PrivateKey, + changeAddr ids.ShortID, + ) (*txs.Tx, error) + // newAdvanceTimeTx creates a new tx that, if it is accepted and followed by a // Commit block, will set the chain's timestamp to [timestamp]. NewAdvanceTimeTx(timestamp time.Time) (*txs.Tx, error) @@ -609,3 +622,42 @@ func (b *builder) NewRewardValidatorTx(txID ids.ID) (*txs.Tx, error) { return tx, tx.SyntacticVerify(b.ctx) } + +func (b *builder) NewTransferSubnetOwnershipTx( + subnetID ids.ID, + threshold uint32, + ownerAddrs []ids.ShortID, + keys []*secp256k1.PrivateKey, + changeAddr ids.ShortID, +) (*txs.Tx, error) { + ins, outs, _, signers, err := b.Spend(b.state, keys, 0, b.cfg.TxFee, changeAddr) + if err != nil { + return nil, fmt.Errorf("couldn't generate tx inputs/outputs: %w", err) + } + + subnetAuth, subnetSigners, err := b.Authorize(b.state, subnetID, keys) + if err != nil { + return nil, fmt.Errorf("couldn't authorize tx's subnet restrictions: %w", err) + } + signers = append(signers, subnetSigners) + + utx := &txs.TransferSubnetOwnershipTx{ + BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{ + NetworkID: b.ctx.NetworkID, + BlockchainID: b.ctx.ChainID, + Ins: ins, + Outs: outs, + }}, + Subnet: subnetID, + SubnetAuth: subnetAuth, + Owner: &secp256k1fx.OutputOwners{ + Threshold: threshold, + Addrs: ownerAddrs, + }, + } + 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 20fd52e4abd4..79291afb7cd7 100644 --- a/vms/platformvm/txs/builder/mock_builder.go +++ b/vms/platformvm/txs/builder/mock_builder.go @@ -189,3 +189,18 @@ func (mr *MockBuilderMockRecorder) NewRewardValidatorTx(arg0 interface{}) *gomoc mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewRewardValidatorTx", reflect.TypeOf((*MockBuilder)(nil).NewRewardValidatorTx), arg0) } + +// NewTransferSubnetOwnershipTx mocks base method. +func (m *MockBuilder) NewTransferSubnetOwnershipTx(arg0 ids.ID, arg1 uint32, arg2 []ids.ShortID, arg3 []*secp256k1.PrivateKey, arg4 ids.ShortID) (*txs.Tx, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewTransferSubnetOwnershipTx", arg0, arg1, arg2, arg3, arg4) + ret0, _ := ret[0].(*txs.Tx) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// NewTransferSubnetOwnershipTx indicates an expected call of NewTransferSubnetOwnershipTx. +func (mr *MockBuilderMockRecorder) NewTransferSubnetOwnershipTx(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewTransferSubnetOwnershipTx", reflect.TypeOf((*MockBuilder)(nil).NewTransferSubnetOwnershipTx), arg0, arg1, arg2, arg3, arg4) +} diff --git a/vms/platformvm/txs/codec.go b/vms/platformvm/txs/codec.go index cf67ce40ee9e..1d4eac1f700e 100644 --- a/vms/platformvm/txs/codec.go +++ b/vms/platformvm/txs/codec.go @@ -41,6 +41,10 @@ func init() { c.SkipRegistrations(5) errs.Add(RegisterUnsignedTxsTypes(c)) + + c.SkipRegistrations(4) + + errs.Add(RegisterDUnsignedTxsTypes(c)) } errs.Add( Codec.RegisterCodec(Version, c), @@ -97,3 +101,7 @@ func RegisterUnsignedTxsTypes(targetCodec linearcodec.Codec) error { ) return errs.Err } + +func RegisterDUnsignedTxsTypes(targetCodec linearcodec.Codec) error { + return targetCodec.RegisterType(&TransferSubnetOwnershipTx{}) +} diff --git a/vms/platformvm/txs/executor/atomic_tx_executor.go b/vms/platformvm/txs/executor/atomic_tx_executor.go index 00cb03404009..09d374b3a395 100644 --- a/vms/platformvm/txs/executor/atomic_tx_executor.go +++ b/vms/platformvm/txs/executor/atomic_tx_executor.go @@ -64,6 +64,10 @@ func (*AtomicTxExecutor) TransformSubnetTx(*txs.TransformSubnetTx) error { return ErrWrongTxType } +func (*AtomicTxExecutor) TransferSubnetOwnershipTx(*txs.TransferSubnetOwnershipTx) error { + return ErrWrongTxType +} + func (*AtomicTxExecutor) AddPermissionlessValidatorTx(*txs.AddPermissionlessValidatorTx) error { return ErrWrongTxType } diff --git a/vms/platformvm/txs/executor/proposal_tx_executor.go b/vms/platformvm/txs/executor/proposal_tx_executor.go index 4cdf500397cc..dd66815b9c8f 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor.go @@ -97,6 +97,10 @@ func (*ProposalTxExecutor) AddPermissionlessDelegatorTx(*txs.AddPermissionlessDe return ErrWrongTxType } +func (*ProposalTxExecutor) TransferSubnetOwnershipTx(*txs.TransferSubnetOwnershipTx) 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/staker_tx_verification.go b/vms/platformvm/txs/executor/staker_tx_verification.go index dd77437e8bcc..9ec4880e4a44 100644 --- a/vms/platformvm/txs/executor/staker_tx_verification.go +++ b/vms/platformvm/txs/executor/staker_tx_verification.go @@ -37,6 +37,7 @@ var ( ErrDuplicateValidator = errors.New("duplicate validator") ErrDelegateToPermissionedValidator = errors.New("delegation to permissioned validator") ErrWrongStakedAssetID = errors.New("incorrect staked assetID") + ErrDUpgradeNotActive = errors.New("attempting to use a D-upgrade feature prior to activation") ) // verifySubnetValidatorPrimaryNetworkRequirements verifies the primary @@ -714,3 +715,50 @@ func verifyAddPermissionlessDelegatorTx( return nil } + +// Returns an error if the given tx is invalid. +// The transaction is valid if: +// * [sTx]'s creds authorize it to spend the stated inputs. +// * [sTx]'s creds authorize it to transfer ownership of [tx.Subnet]. +// * The flow checker passes. +func verifyTransferSubnetOwnershipTx( + backend *Backend, + chainState state.Chain, + sTx *txs.Tx, + tx *txs.TransferSubnetOwnershipTx, +) error { + if !backend.Config.IsDActivated(chainState.GetTimestamp()) { + return ErrDUpgradeNotActive + } + + // Verify the tx is well-formed + if err := sTx.SyntacticVerify(backend.Ctx); err != nil { + return err + } + + if !backend.Bootstrapped.Get() { + // Not bootstrapped yet -- don't need to do full verification. + return nil + } + + baseTxCreds, err := verifySubnetAuthorization(backend, chainState, sTx, tx.Subnet, tx.SubnetAuth) + if err != nil { + return err + } + + // Verify the flowcheck + if err := backend.FlowChecker.VerifySpend( + tx, + chainState, + tx.Ins, + tx.Outs, + baseTxCreds, + map[ids.ID]uint64{ + backend.Ctx.AVAXAssetID: backend.Config.TxFee, + }, + ); err != nil { + return fmt.Errorf("%w: %w", ErrFlowCheckFailed, err) + } + + return nil +} diff --git a/vms/platformvm/txs/executor/standard_tx_executor.go b/vms/platformvm/txs/executor/standard_tx_executor.go index d9b1997bfb3f..92a4af6cc09e 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor.go +++ b/vms/platformvm/txs/executor/standard_tx_executor.go @@ -490,3 +490,27 @@ func (e *StandardTxExecutor) AddPermissionlessDelegatorTx(tx *txs.AddPermissionl return nil } + +// Verifies a [*txs.TransferSubnetOwnershipTx] and, if it passes, executes it on +// [e.State]. For verification rules, see [verifyTransferSubnetOwnershipTx]. +// This transaction will result in the ownership of [tx.Subnet] being transferred +// to [tx.Owner]. +func (e *StandardTxExecutor) TransferSubnetOwnershipTx(tx *txs.TransferSubnetOwnershipTx) error { + err := verifyTransferSubnetOwnershipTx( + e.Backend, + e.State, + e.Tx, + tx, + ) + if err != nil { + return err + } + + e.State.SetSubnetOwner(tx.Subnet, tx.Owner) + + txID := e.Tx.ID() + avax.Consume(e.State, tx.Ins) + avax.Produce(e.State, txID, 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 206ef6c04424..aa8d1dfaeb86 100644 --- a/vms/platformvm/txs/executor/tx_mempool_verifier.go +++ b/vms/platformvm/txs/executor/tx_mempool_verifier.go @@ -74,6 +74,10 @@ func (v *MempoolTxVerifier) AddPermissionlessDelegatorTx(tx *txs.AddPermissionle return v.standardTx(tx) } +func (v *MempoolTxVerifier) TransferSubnetOwnershipTx(tx *txs.TransferSubnetOwnershipTx) 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 aa5e5c707a6c..e24afb5282da 100644 --- a/vms/platformvm/txs/mempool/issuer.go +++ b/vms/platformvm/txs/mempool/issuer.go @@ -74,6 +74,11 @@ func (i *issuer) TransformSubnetTx(*txs.TransformSubnetTx) error { return nil } +func (i *issuer) TransferSubnetOwnershipTx(*txs.TransferSubnetOwnershipTx) 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 fcdeca380679..e418cf46c342 100644 --- a/vms/platformvm/txs/mempool/remover.go +++ b/vms/platformvm/txs/mempool/remover.go @@ -57,6 +57,11 @@ func (r *remover) TransformSubnetTx(*txs.TransformSubnetTx) error { return nil } +func (r *remover) TransferSubnetOwnershipTx(*txs.TransferSubnetOwnershipTx) 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/transfer_subnet_ownership_tx.go b/vms/platformvm/txs/transfer_subnet_ownership_tx.go new file mode 100644 index 000000000000..78dbf28b48b4 --- /dev/null +++ b/vms/platformvm/txs/transfer_subnet_ownership_tx.go @@ -0,0 +1,65 @@ +// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package txs + +import ( + "errors" + + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/utils/constants" + "github.com/ava-labs/avalanchego/vms/components/verify" + "github.com/ava-labs/avalanchego/vms/platformvm/fx" +) + +var ( + _ UnsignedTx = (*TransferSubnetOwnershipTx)(nil) + + ErrTransferPermissionlessSubnet = errors.New("cannot transfer ownership of a permissionless subnet") +) + +type TransferSubnetOwnershipTx struct { + // Metadata, inputs and outputs + BaseTx `serialize:"true"` + // ID of the subnet this tx is modifying + Subnet ids.ID `serialize:"true" json:"subnetID"` + // Proves that the issuer has the right to remove the node from the subnet. + SubnetAuth verify.Verifiable `serialize:"true" json:"subnetAuthorization"` + // Who is now authorized to manage this subnet + Owner fx.Owner `serialize:"true" json:"newOwner"` +} + +// InitCtx sets the FxID fields in the inputs and outputs of this +// [TransferSubnetOwnershipTx]. Also sets the [ctx] to the given [vm.ctx] so +// that the addresses can be json marshalled into human readable format +func (tx *TransferSubnetOwnershipTx) InitCtx(ctx *snow.Context) { + tx.BaseTx.InitCtx(ctx) + tx.Owner.InitCtx(ctx) +} + +func (tx *TransferSubnetOwnershipTx) SyntacticVerify(ctx *snow.Context) error { + switch { + case tx == nil: + return ErrNilTx + case tx.SyntacticallyVerified: + // already passed syntactic verification + return nil + case tx.Subnet == constants.PrimaryNetworkID: + return ErrTransferPermissionlessSubnet + } + + if err := tx.BaseTx.SyntacticVerify(ctx); err != nil { + return err + } + if err := verify.All(tx.SubnetAuth, tx.Owner); err != nil { + return err + } + + tx.SyntacticallyVerified = true + return nil +} + +func (tx *TransferSubnetOwnershipTx) Visit(visitor Visitor) error { + return visitor.TransferSubnetOwnershipTx(tx) +} diff --git a/vms/platformvm/txs/transfer_subnet_ownership_tx_test.go b/vms/platformvm/txs/transfer_subnet_ownership_tx_test.go new file mode 100644 index 000000000000..7e6f5835a283 --- /dev/null +++ b/vms/platformvm/txs/transfer_subnet_ownership_tx_test.go @@ -0,0 +1,669 @@ +// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package txs + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/require" + + "go.uber.org/mock/gomock" + + "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/components/verify" + "github.com/ava-labs/avalanchego/vms/platformvm/fx" + "github.com/ava-labs/avalanchego/vms/platformvm/stakeable" + "github.com/ava-labs/avalanchego/vms/secp256k1fx" + "github.com/ava-labs/avalanchego/vms/types" +) + +func TestTransferSubnetOwnershipTxSerialization(t *testing.T) { + require := require.New(t) + + 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, + } + subnetID := ids.ID{ + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + } + + simpleTransferSubnetOwnershipTx := &TransferSubnetOwnershipTx{ + BaseTx: 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{}, + }, + }, + Subnet: subnetID, + SubnetAuth: &secp256k1fx.Input{ + SigIndices: []uint32{3}, + }, + Owner: &secp256k1fx.OutputOwners{ + Locktime: 0, + Threshold: 1, + Addrs: []ids.ShortID{ + addr, + }, + }, + } + require.NoError(simpleTransferSubnetOwnershipTx.SyntacticVerify(&snow.Context{ + NetworkID: 1, + ChainID: constants.PlatformChainID, + AVAXAssetID: avaxAssetID, + })) + + expectedUnsignedSimpleTransferSubnetOwnershipTxBytes := []byte{ + // Codec version + 0x00, 0x00, + // RemoveSubnetValidatorTx Type ID + 0x00, 0x00, 0x00, 0x21, + // 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, + // subnetID to modify + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + // secp256k1fx authorization type ID + 0x00, 0x00, 0x00, 0x0a, + // number of signatures needed in authorization + 0x00, 0x00, 0x00, 0x01, + // index of signer + 0x00, 0x00, 0x00, 0x03, + // secp256k1fx output owners type ID + 0x00, 0x00, 0x00, 0x0b, + // locktime + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // threshold + 0x00, 0x00, 0x00, 0x01, + // number of addrs + 0x00, 0x00, 0x00, 0x01, + // Addrs[0] + 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, + 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, + 0x44, 0x55, 0x66, 0x77, + } + var unsignedSimpleTransferSubnetOwnershipTx UnsignedTx = simpleTransferSubnetOwnershipTx + unsignedSimpleTransferSubnetOwnershipTxBytes, err := Codec.Marshal(Version, &unsignedSimpleTransferSubnetOwnershipTx) + require.NoError(err) + require.Equal(expectedUnsignedSimpleTransferSubnetOwnershipTxBytes, unsignedSimpleTransferSubnetOwnershipTxBytes) + + complexTransferSubnetOwnershipTx := &TransferSubnetOwnershipTx{ + BaseTx: 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!"), + }, + }, + Subnet: subnetID, + SubnetAuth: &secp256k1fx.Input{ + SigIndices: []uint32{}, + }, + Owner: &secp256k1fx.OutputOwners{ + Locktime: 876543210, + Threshold: 1, + Addrs: []ids.ShortID{ + addr, + }, + }, + } + avax.SortTransferableOutputs(complexTransferSubnetOwnershipTx.Outs, Codec) + utils.Sort(complexTransferSubnetOwnershipTx.Ins) + require.NoError(simpleTransferSubnetOwnershipTx.SyntacticVerify(&snow.Context{ + NetworkID: 1, + ChainID: constants.PlatformChainID, + AVAXAssetID: avaxAssetID, + })) + + expectedUnsignedComplexTransferSubnetOwnershipTxBytes := []byte{ + // Codec version + 0x00, 0x00, + // TransferSubnetOwnershipTx Type ID + 0x00, 0x00, 0x00, 0x21, + // 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, + // subnetID to modify + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, + // secp256k1fx authorization type ID + 0x00, 0x00, 0x00, 0x0a, + // number of signatures needed in authorization + 0x00, 0x00, 0x00, 0x00, + // secp256k1fx output owners type ID + 0x00, 0x00, 0x00, 0x0b, + // locktime + 0x00, 0x00, 0x00, 0x00, 0x34, 0x3e, 0xfc, 0xea, + // threshold + 0x00, 0x00, 0x00, 0x01, + // number of addrs + 0x00, 0x00, 0x00, 0x01, + // Addrs[0] + 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, + 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, + 0x44, 0x55, 0x66, 0x77, + } + var unsignedComplexTransferSubnetOwnershipTx UnsignedTx = complexTransferSubnetOwnershipTx + unsignedComplexTransferSubnetOwnershipTxBytes, err := Codec.Marshal(Version, &unsignedComplexTransferSubnetOwnershipTx) + require.NoError(err) + require.Equal(expectedUnsignedComplexTransferSubnetOwnershipTxBytes, unsignedComplexTransferSubnetOwnershipTxBytes) + + aliaser := ids.NewAliaser() + require.NoError(aliaser.Alias(constants.PlatformChainID, "P")) + + unsignedComplexTransferSubnetOwnershipTx.InitCtx(&snow.Context{ + NetworkID: 1, + ChainID: constants.PlatformChainID, + AVAXAssetID: avaxAssetID, + BCLookup: aliaser, + }) + + unsignedComplexTransferSubnetOwnershipTxJSONBytes, err := json.MarshalIndent(unsignedComplexTransferSubnetOwnershipTx, "", "\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", + "subnetID": "SkB92YpWm4UpburLz9tEKZw2i67H3FF6YkjaU4BkFUDTG9Xm", + "subnetAuthorization": { + "signatureIndices": [] + }, + "newOwner": { + "addresses": [ + "P-avax1g32kvaugnx4tk3z4vemc3xd2hdz92enh972wxr" + ], + "locktime": 876543210, + "threshold": 1 + } +}`, string(unsignedComplexTransferSubnetOwnershipTxJSONBytes)) +} + +func TestTransferSubnetOwnershipTxSyntacticVerify(t *testing.T) { + type test struct { + name string + txFunc func(*gomock.Controller) *TransferSubnetOwnershipTx + expectedErr error + } + + var ( + networkID = uint32(1337) + chainID = ids.GenerateTestID() + ) + + ctx := &snow.Context{ + ChainID: chainID, + NetworkID: networkID, + } + + // A BaseTx that already passed syntactic verification. + verifiedBaseTx := BaseTx{ + SyntacticallyVerified: true, + } + // Sanity check. + require.NoError(t, verifiedBaseTx.SyntacticVerify(ctx)) + + // A BaseTx that passes syntactic verification. + validBaseTx := BaseTx{ + BaseTx: avax.BaseTx{ + NetworkID: networkID, + BlockchainID: chainID, + }, + } + // Sanity check. + require.NoError(t, validBaseTx.SyntacticVerify(ctx)) + // Make sure we're not caching the verification result. + require.False(t, validBaseTx.SyntacticallyVerified) + + // A BaseTx that fails syntactic verification. + invalidBaseTx := BaseTx{} + + tests := []test{ + { + name: "nil tx", + txFunc: func(*gomock.Controller) *TransferSubnetOwnershipTx { + return nil + }, + expectedErr: ErrNilTx, + }, + { + name: "already verified", + txFunc: func(*gomock.Controller) *TransferSubnetOwnershipTx { + return &TransferSubnetOwnershipTx{BaseTx: verifiedBaseTx} + }, + expectedErr: nil, + }, + { + name: "invalid BaseTx", + txFunc: func(*gomock.Controller) *TransferSubnetOwnershipTx { + return &TransferSubnetOwnershipTx{ + // Set subnetID so we don't error on that check. + Subnet: ids.GenerateTestID(), + BaseTx: invalidBaseTx, + } + }, + expectedErr: avax.ErrWrongNetworkID, + }, + { + name: "invalid subnetID", + txFunc: func(*gomock.Controller) *TransferSubnetOwnershipTx { + return &TransferSubnetOwnershipTx{ + BaseTx: validBaseTx, + Subnet: constants.PrimaryNetworkID, + } + }, + expectedErr: ErrTransferPermissionlessSubnet, + }, + { + name: "invalid subnetAuth", + txFunc: func(ctrl *gomock.Controller) *TransferSubnetOwnershipTx { + // This SubnetAuth fails verification. + invalidSubnetAuth := verify.NewMockVerifiable(ctrl) + invalidSubnetAuth.EXPECT().Verify().Return(errInvalidSubnetAuth) + return &TransferSubnetOwnershipTx{ + // Set subnetID so we don't error on that check. + Subnet: ids.GenerateTestID(), + BaseTx: validBaseTx, + SubnetAuth: invalidSubnetAuth, + } + }, + expectedErr: errInvalidSubnetAuth, + }, + { + name: "passes verification", + txFunc: func(ctrl *gomock.Controller) *TransferSubnetOwnershipTx { + // This SubnetAuth passes verification. + validSubnetAuth := verify.NewMockVerifiable(ctrl) + validSubnetAuth.EXPECT().Verify().Return(nil) + mockOwner := fx.NewMockOwner(ctrl) + mockOwner.EXPECT().Verify().Return(nil) + return &TransferSubnetOwnershipTx{ + // Set subnetID so we don't error on that check. + Subnet: ids.GenerateTestID(), + BaseTx: validBaseTx, + SubnetAuth: validSubnetAuth, + Owner: mockOwner, + } + }, + expectedErr: nil, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require := require.New(t) + ctrl := gomock.NewController(t) + + tx := tt.txFunc(ctrl) + err := tx.SyntacticVerify(ctx) + require.ErrorIs(err, tt.expectedErr) + if tt.expectedErr != nil { + return + } + require.True(tx.SyntacticallyVerified) + }) + } +} diff --git a/vms/platformvm/txs/visitor.go b/vms/platformvm/txs/visitor.go index 18455d814358..5476d73c7e86 100644 --- a/vms/platformvm/txs/visitor.go +++ b/vms/platformvm/txs/visitor.go @@ -18,4 +18,5 @@ type Visitor interface { TransformSubnetTx(*TransformSubnetTx) error AddPermissionlessValidatorTx(*AddPermissionlessValidatorTx) error AddPermissionlessDelegatorTx(*AddPermissionlessDelegatorTx) error + TransferSubnetOwnershipTx(*TransferSubnetOwnershipTx) error } diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 98c24e66d2e3..2db4146d05df 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -2118,3 +2118,78 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { _, err = vm.state.GetPendingValidator(createSubnetTx.ID(), ids.NodeID(id)) require.ErrorIs(err, database.ErrNotFound) } + +func TestTransferSubnetOwnershipTx(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() + }() + + // Create a subnet + createSubnetTx, err := vm.txBuilder.NewCreateSubnetTx( + 1, + []ids.ShortID{keys[0].PublicKey().Address()}, + []*secp256k1.PrivateKey{keys[0]}, + keys[0].Address(), + ) + require.NoError(err) + subnetID := createSubnetTx.ID() + + require.NoError(vm.Builder.AddUnverifiedTx(createSubnetTx)) + createSubnetBlock, err := vm.Builder.BuildBlock(context.Background()) + require.NoError(err) + + createSubnetRawBlock := createSubnetBlock.(*blockexecutor.Block).Block + require.IsType(&block.BanffStandardBlock{}, createSubnetRawBlock) + require.Contains(createSubnetRawBlock.Txs(), createSubnetTx) + + require.NoError(createSubnetBlock.Verify(context.Background())) + require.NoError(createSubnetBlock.Accept(context.Background())) + require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) + + subnetOwner, err := vm.state.GetSubnetOwner(subnetID) + require.NoError(err) + expectedOwner := &secp256k1fx.OutputOwners{ + Locktime: 0, + Threshold: 1, + Addrs: []ids.ShortID{ + keys[0].PublicKey().Address(), + }, + } + require.Equal(expectedOwner, subnetOwner) + + transferSubnetOwnershipTx, err := vm.txBuilder.NewTransferSubnetOwnershipTx( + subnetID, + 1, + []ids.ShortID{keys[1].PublicKey().Address()}, + []*secp256k1.PrivateKey{keys[0]}, + ids.ShortEmpty, // change addr + ) + require.NoError(err) + + require.NoError(vm.Builder.AddUnverifiedTx(transferSubnetOwnershipTx)) + transferSubnetOwnershipBlock, err := vm.Builder.BuildBlock(context.Background()) + require.NoError(err) + + transferSubnetOwnershipRawBlock := transferSubnetOwnershipBlock.(*blockexecutor.Block).Block + require.IsType(&block.BanffStandardBlock{}, transferSubnetOwnershipRawBlock) + require.Contains(transferSubnetOwnershipRawBlock.Txs(), transferSubnetOwnershipTx) + + require.NoError(transferSubnetOwnershipBlock.Verify(context.Background())) + require.NoError(transferSubnetOwnershipBlock.Accept(context.Background())) + require.NoError(vm.SetPreference(context.Background(), vm.manager.LastAccepted())) + + subnetOwner, err = vm.state.GetSubnetOwner(subnetID) + require.NoError(err) + expectedOwner = &secp256k1fx.OutputOwners{ + Locktime: 0, + Threshold: 1, + Addrs: []ids.ShortID{ + keys[1].PublicKey().Address(), + }, + } + require.Equal(expectedOwner, subnetOwner) +} diff --git a/wallet/chain/p/backend_visitor.go b/wallet/chain/p/backend_visitor.go index 9830d87ade05..da2fc591ecd5 100644 --- a/wallet/chain/p/backend_visitor.go +++ b/wallet/chain/p/backend_visitor.go @@ -53,6 +53,11 @@ func (b *backendVisitor) RemoveSubnetValidatorTx(tx *txs.RemoveSubnetValidatorTx return b.baseTx(&tx.BaseTx) } +func (b *backendVisitor) TransferSubnetOwnershipTx(tx *txs.TransferSubnetOwnershipTx) error { + // TODO: Correctly track subnet owners in [getSubnetSigners] + return b.baseTx(&tx.BaseTx) +} + 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 52269ee69081..6df1687400ac 100644 --- a/wallet/chain/p/signer_visitor.go +++ b/wallet/chain/p/signer_visitor.go @@ -135,6 +135,19 @@ func (s *signerVisitor) RemoveSubnetValidatorTx(tx *txs.RemoveSubnetValidatorTx) return sign(s.tx, true, txSigners) } +func (s *signerVisitor) TransferSubnetOwnershipTx(tx *txs.TransferSubnetOwnershipTx) error { + txSigners, err := s.getSigners(constants.PlatformChainID, tx.Ins) + if err != nil { + return err + } + subnetAuthSigners, err := s.getSubnetSigners(tx.Subnet, tx.SubnetAuth) + if err != nil { + return err + } + txSigners = append(txSigners, subnetAuthSigners) + return sign(s.tx, true, txSigners) +} + func (s *signerVisitor) TransformSubnetTx(tx *txs.TransformSubnetTx) error { txSigners, err := s.getSigners(constants.PlatformChainID, tx.Ins) if err != nil { From 1f779afc480622dca4124f228a37f87e32d0bf6a Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Wed, 25 Oct 2023 17:13:25 -0400 Subject: [PATCH 06/25] Revert networking AllowConnection change (#2219) --- network/network.go | 6 ++- network/network_test.go | 85 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/network/network.go b/network/network.go index b3a22681f8f7..a0fd6cced124 100644 --- a/network/network.go +++ b/network/network.go @@ -470,7 +470,11 @@ func (n *network) Connected(nodeID ids.NodeID) { // of peers, then it should only connect if this node is a validator, or the // peer is a validator/beacon. func (n *network) AllowConnection(nodeID ids.NodeID) bool { - return !n.config.RequireValidatorToConnect || n.WantsConnection(nodeID) + if !n.config.RequireValidatorToConnect { + return true + } + _, isValidator := n.config.Validators.GetValidator(constants.PrimaryNetworkID, n.config.MyNodeID) + return isValidator || n.WantsConnection(nodeID) } func (n *network) Track(peerID ids.NodeID, claimedIPPorts []*ips.ClaimedIPPort) ([]*p2p.PeerAck, error) { diff --git a/network/network_test.go b/network/network_test.go index 0b2ca3458658..65d4809101fb 100644 --- a/network/network_test.go +++ b/network/network_test.go @@ -683,3 +683,88 @@ func TestDialContext(t *testing.T) { network.StartClose() wg.Wait() } + +func TestAllowConnectionAsAValidator(t *testing.T) { + require := require.New(t) + + dialer, listeners, nodeIDs, configs := newTestNetwork(t, 2) + + networks := make([]Network, len(configs)) + for i, config := range configs { + msgCreator := newMessageCreator(t) + registry := prometheus.NewRegistry() + + g, err := peer.NewGossipTracker(registry, "foobar") + require.NoError(err) + + log := logging.NoLog{} + gossipTrackerCallback := peer.GossipTrackerCallback{ + Log: log, + GossipTracker: g, + } + + beacons := validators.NewManager() + require.NoError(beacons.AddStaker(constants.PrimaryNetworkID, nodeIDs[0], nil, ids.GenerateTestID(), 1)) + + vdrs := validators.NewManager() + vdrs.RegisterCallbackListener(constants.PrimaryNetworkID, &gossipTrackerCallback) + require.NoError(vdrs.AddStaker(constants.PrimaryNetworkID, nodeIDs[0], nil, ids.GenerateTestID(), 1)) + + config := config + + config.GossipTracker = g + config.Beacons = beacons + config.Validators = vdrs + config.RequireValidatorToConnect = true + + net, err := NewNetwork( + config, + msgCreator, + registry, + log, + listeners[i], + dialer, + &testHandler{ + InboundHandler: nil, + ConnectedF: nil, + DisconnectedF: nil, + }, + ) + require.NoError(err) + networks[i] = net + } + + wg := sync.WaitGroup{} + wg.Add(len(networks)) + for i, net := range networks { + if i != 0 { + config := configs[0] + net.ManuallyTrack(config.MyNodeID, config.MyIPPort.IPPort()) + } + + go func(net Network) { + defer wg.Done() + + require.NoError(net.Dispatch()) + }(net) + } + + network := networks[1].(*network) + require.Eventually( + func() bool { + network.peersLock.RLock() + defer network.peersLock.RUnlock() + + nodeID := nodeIDs[0] + _, contains := network.connectedPeers.GetByID(nodeID) + return contains + }, + 10*time.Second, + 50*time.Millisecond, + ) + + for _, net := range networks { + net.StartClose() + } + wg.Wait() +} From 787f0b6b5a5859cba74ad285e1a83c892b67f0dd Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Wed, 25 Oct 2023 17:35:17 -0400 Subject: [PATCH 07/25] Fix unexpected unlock (#2221) --- snow/networking/handler/handler.go | 2 -- snow/networking/handler/handler_test.go | 38 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/snow/networking/handler/handler.go b/snow/networking/handler/handler.go index a9d94e449288..1a9a1d89b6ae 100644 --- a/snow/networking/handler/handler.go +++ b/snow/networking/handler/handler.go @@ -222,8 +222,6 @@ func (h *handler) selectStartingGear(ctx context.Context) (common.Engine, error) func (h *handler) Start(ctx context.Context, recoverPanic bool) { gear, err := h.selectStartingGear(ctx) if err != nil { - h.ctx.Lock.Unlock() - h.ctx.Log.Error("chain failed to select starting gear", zap.Error(err), ) diff --git a/snow/networking/handler/handler_test.go b/snow/networking/handler/handler_test.go index bcc465a94335..c28da4bc8b71 100644 --- a/snow/networking/handler/handler_test.go +++ b/snow/networking/handler/handler_test.go @@ -633,3 +633,41 @@ func TestDynamicEngineTypeDispatch(t *testing.T) { }) } } + +func TestHandlerStartError(t *testing.T) { + require := require.New(t) + + ctx := snow.DefaultConsensusContextTest() + resourceTracker, err := tracker.NewResourceTracker( + prometheus.NewRegistry(), + resource.NoUsage, + meter.ContinuousFactory{}, + time.Second, + ) + require.NoError(err) + + handler, err := New( + ctx, + validators.NewManager(), + nil, + time.Second, + testThreadPoolSize, + resourceTracker, + nil, + subnets.New(ctx.NodeID, subnets.Config{}), + commontracker.NewPeers(), + ) + require.NoError(err) + + // Starting a handler with an unprovided engine should immediately cause the + // handler to shutdown. + handler.SetEngineManager(&EngineManager{}) + ctx.State.Set(snow.EngineState{ + Type: p2p.EngineType_ENGINE_TYPE_SNOWMAN, + State: snow.Initializing, + }) + handler.Start(context.Background(), false) + + _, err = handler.AwaitStopped(context.Background()) + require.NoError(err) +} From 8463690a6fe6327e3a8d323d23170120ef4c3365 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 26 Oct 2023 00:12:05 -0400 Subject: [PATCH 08/25] Improve logging for block verification failure (#2224) --- snow/engine/snowman/transitive.go | 4 +++- vms/proposervm/block.go | 6 +++++- vms/proposervm/pre_fork_block.go | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/snow/engine/snowman/transitive.go b/snow/engine/snowman/transitive.go index 629ad0dc2be1..803c03237c96 100644 --- a/snow/engine/snowman/transitive.go +++ b/snow/engine/snowman/transitive.go @@ -965,9 +965,12 @@ func (t *Transitive) addToNonVerifieds(blk snowman.Block) { // addUnverifiedBlockToConsensus returns whether the block was added and an // error if one occurred while adding it to consensus. func (t *Transitive) addUnverifiedBlockToConsensus(ctx context.Context, blk snowman.Block) (bool, error) { + blkID := blk.ID() + // make sure this block is valid if err := blk.Verify(ctx); err != nil { t.Ctx.Log.Debug("block verification failed", + zap.Stringer("blkID", blkID), zap.Error(err), ) @@ -976,7 +979,6 @@ func (t *Transitive) addUnverifiedBlockToConsensus(ctx context.Context, blk snow return false, nil } - blkID := blk.ID() t.nonVerifieds.Remove(blkID) t.nonVerifiedCache.Evict(blkID) t.metrics.numNonVerifieds.Set(float64(t.nonVerifieds.Len())) diff --git a/vms/proposervm/block.go b/vms/proposervm/block.go index 1355eb46dd7b..f07362708611 100644 --- a/vms/proposervm/block.go +++ b/vms/proposervm/block.go @@ -135,7 +135,11 @@ func (p *postForkCommonComponents) Verify( return err } if childPChainHeight > currentPChainHeight { - return errPChainHeightNotReached + return fmt.Errorf("%w: %d > %d", + errPChainHeightNotReached, + childPChainHeight, + currentPChainHeight, + ) } childHeight := child.Height() diff --git a/vms/proposervm/pre_fork_block.go b/vms/proposervm/pre_fork_block.go index 0b11ef8e4716..ed665e473910 100644 --- a/vms/proposervm/pre_fork_block.go +++ b/vms/proposervm/pre_fork_block.go @@ -5,6 +5,7 @@ package proposervm import ( "context" + "fmt" "time" "go.uber.org/zap" @@ -128,7 +129,11 @@ func (b *preForkBlock) verifyPostForkChild(ctx context.Context, child *postForkB return err } if childPChainHeight > currentPChainHeight { - return errPChainHeightNotReached + return fmt.Errorf("%w: %d > %d", + errPChainHeightNotReached, + childPChainHeight, + currentPChainHeight, + ) } if childPChainHeight < b.vm.minimumPChainHeight { return errPChainHeightTooLow From 638000c42e5361e656ffbc27024026f6d8f67810 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Thu, 26 Oct 2023 02:08:05 -0400 Subject: [PATCH 09/25] Update versions for v1.10.14 (#2225) --- RELEASES.md | 51 ++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 4 +-- version/compatibility.json | 3 ++- version/constants.go | 2 +- 5 files changed, 57 insertions(+), 5 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index c094b187a57d..31d9e3605dce 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,5 +1,56 @@ # Release Notes +## [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. + +The plugin version is unchanged at `29` and compatible with version `v1.10.13`. + +### Configs + +- Deprecated `--api-ipcs-enabled` +- Deprecated `--ipcs-chain-ids` +- Deprecated `--ipcs-path` +- Deprecated `--api-keystore-enabled` + +### Fixes + +- Fixed shutdown of timeout manager +- Fixed racy access of the shutdown time + +### What's Changed + +- Remove build check from unit tests by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2189 +- Update cgo usage by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2184 +- Deprecate IPC configs by @danlaine in https://github.com/ava-labs/avalanchego/pull/2168 +- Update P2P proto docs by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2181 +- Merkle db Make Paths only refer to lists of nodes by @dboehm-avalabs in https://github.com/ava-labs/avalanchego/pull/2143 +- Deprecate keystore config by @danlaine in https://github.com/ava-labs/avalanchego/pull/2195 +- Add tests for BanffBlock serialization by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2194 +- Move Shutdown lock from Handler into Engines by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2179 +- Move HealthCheck lock from Handler into Engines by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2173 +- Implement Heap Map by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2137 +- Move selectStartGear lock from Handler into Engines by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2182 +- Add Heap Set by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2136 +- Shutdown TimeoutManager during node Shutdown by @abi87 in https://github.com/ava-labs/avalanchego/pull/1707 +- Redesign validator set management to enable tracking all subnets by @ceyonur in https://github.com/ava-labs/avalanchego/pull/1857 +- Update local network readme by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2203 +- Use custom codec for validator metadata by @abi87 in https://github.com/ava-labs/avalanchego/pull/1510 +- Add RSA max key length test by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2205 +- Remove duplicate networking check by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2204 +- Update TestDialContext to use ManuallyTrack by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2209 +- Remove contains from validator manager interface by @ceyonur in https://github.com/ava-labs/avalanchego/pull/2198 +- Move the overridden manager into the node by @ceyonur in https://github.com/ava-labs/avalanchego/pull/2199 +- Remove `aggregate` struct by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2213 +- Add log for ungraceful shutdown on startup by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2215 +- Add pebble database implementation by @danlaine in https://github.com/ava-labs/avalanchego/pull/1999 +- Add `TransferSubnetOwnershipTx` by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2178 +- Revert networking AllowConnection change by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2219 +- Fix unexpected unlock by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2221 +- Improve logging for block verification failure by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2224 + +**Full Changelog**: https://github.com/ava-labs/avalanchego/compare/v1.10.13...v1.10.14 + ## [v1.10.13](https://github.com/ava-labs/avalanchego/releases/tag/v1.10.13) 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 34c4b0cb7475..f351efbef090 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.6-rc.2 + github.com/ava-labs/coreth v0.12.7-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 f4d30e37b89f..d301d4b6be81 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.6-rc.2 h1:5P9/i3h6g2uUYf6BVhG8YrV6iqhov6vRxph6cvuKpvU= -github.com/ava-labs/coreth v0.12.6-rc.2/go.mod h1:sNbwitXv4AhLvWpSqy6V8yzkhGFeWBQFD31/xiRDJ5M= +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/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/version/compatibility.json b/version/compatibility.json index c257b8a573df..0d8382e21678 100644 --- a/version/compatibility.json +++ b/version/compatibility.json @@ -1,6 +1,7 @@ { "29": [ - "v1.10.13" + "v1.10.13", + "v1.10.14" ], "28": [ "v1.10.9", diff --git a/version/constants.go b/version/constants.go index 146a4f1c8981..5cccb035d810 100644 --- a/version/constants.go +++ b/version/constants.go @@ -21,7 +21,7 @@ var ( Current = &Semantic{ Major: 1, Minor: 10, - Patch: 13, + Patch: 14, } CurrentApp = &Application{ Major: Current.Major, 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 10/25] 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 11/25] `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 12/25] 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 13/25] 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 14/25] 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 15/25] `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 16/25] 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 17/25] 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 18/25] 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 19/25] 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 20/25] 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 21/25] 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 22/25] 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 23/25] 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 24/25] 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 25/25] 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, ) }