diff --git a/.github/workflows/run-tests-publish-image-basic.yml b/.github/workflows/run-tests-publish-image-basic.yml index f1bbb46412ed..98ea15f3af6d 100644 --- a/.github/workflows/run-tests-publish-image-basic.yml +++ b/.github/workflows/run-tests-publish-image-basic.yml @@ -1,28 +1,15 @@ -name: Basic Lint + e2e Tests + Publish Docker Image +name: e2e Tests + Publish Docker Image on: push: tags-ignore: - - '*' # Ignores all tags + - "*" # Ignores all tags branches-ignore: - master - dev jobs: - run_lint: - name: lint - runs-on: ubuntu-18.04 - steps: - - uses: actions/checkout@v2 - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - version: v1.43.0 - working-directory: . - args: --timeout 10m - run_e2e_tests_plus_publish_image: - needs: run_lint runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/run-tests-publish-image-full.yml b/.github/workflows/run-tests-publish-image-full.yml index 1b441d99c5e3..442763a0da36 100644 --- a/.github/workflows/run-tests-publish-image-full.yml +++ b/.github/workflows/run-tests-publish-image-full.yml @@ -1,28 +1,15 @@ -name: Full Lint + e2e Tests + Publish Docker Image +name: e2e Tests + Publish Docker Image on: push: tags: - - '*' # Push events to every tag + - "*" # Push events to every tag branches: - - master - - dev + - master + - dev jobs: - run_lint: - name: lint - runs-on: ubuntu-18.04 - steps: - - uses: actions/checkout@v2 - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - version: v1.43.0 - working-directory: . - args: --timeout 10m - run_e2e_tests_plus_publish_image: - needs: run_lint runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/run_e2e_tests.sh b/.github/workflows/run_e2e_tests.sh index c57fe254e708..b241bd56a555 100755 --- a/.github/workflows/run_e2e_tests.sh +++ b/.github/workflows/run_e2e_tests.sh @@ -10,7 +10,7 @@ avalanchego_byzantine_repo="avaplatform/avalanche-byzantine" # Define avalanche-testing and avalanche-byzantine versions to use avalanche_testing_image="avaplatform/avalanche-testing:master" -avalanchego_byzantine_image="avaplatform/avalanche-byzantine:master" +avalanchego_byzantine_image="avaplatform/avalanche-byzantine:update-avalanchego-v1.7.0" # Fetch the images # If Docker Credentials are not available fail diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml new file mode 100644 index 000000000000..3ecad9df3d2f --- /dev/null +++ b/.github/workflows/static-analysis.yaml @@ -0,0 +1,21 @@ +name: Full Lint +on: + push: + tags-ignore: + - "*" # Ignores all tags + branches-ignore: + - master + - dev + +jobs: + run_lint: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.43.0 + working-directory: . + args: --timeout 10m --config .golangci.yml diff --git a/.golangci.yml b/.golangci.yml index fe05ec8ff66a..0989b3e512db 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,7 +19,7 @@ linters: - gofmt - gofumpt - goimports - - revive + - revive - gosec - gosimple - govet @@ -35,12 +35,21 @@ linters: - varcheck - unconvert - whitespace + - staticcheck # - lll # - gomnd # - goprintffuncname # - interfacer - # - staticcheck # - structcheck # - typecheck # - goerr113 # - noctx + +linters-settings: + staticcheck: + go: "1.17" + # https://staticcheck.io/docs/options#checks + checks: + - "all" + - "-SA6002" # argument should be pointer-like to avoid allocation, for sync.Pool + - "-SA1019" # deprecated packages e.g., golang.org/x/crypto/ripemd160 diff --git a/Dockerfile.protoc b/Dockerfile.protoc index 9873cd4448f4..7cc7a36da09f 100644 --- a/Dockerfile.protoc +++ b/Dockerfile.protoc @@ -1,6 +1,6 @@ FROM ubuntu:20.04 -RUN apt-get update && apt -y install bash curl unzip +RUN apt-get update && apt -y install bash curl unzip git WORKDIR /opt RUN \ curl -L https://golang.org/dl/go1.16.6.linux-amd64.tar.gz > golang.tar.gz && \ diff --git a/LICENSE.header b/LICENSE.header new file mode 100644 index 000000000000..d919afd2e035 --- /dev/null +++ b/LICENSE.header @@ -0,0 +1,2 @@ +Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +See the file LICENSE for licensing terms. \ No newline at end of file diff --git a/RELEASES.md b/RELEASES.md index cc0b11ab7d56..d48d5096c3af 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,5 +1,36 @@ # Release Notes +## [v1.7.0](https://github.com/ava-labs/avalanchego/releases/tag/v1.7.0) + +This upgrade adds support for issuing multiple atomic transactions into a single block and directly transferring assets between the P-chain and the C-chain. + +The changes in the upgrade go into effect at 10 AM EST, November 24th 2021 on the Fuji testnet. After Fuji is updated and verified, a mainnet compatible release will be published. + +**All Fuji nodes should upgrade before 10 AM EST, November 24th 2021.** + +## Networking + +- Added peer uptime reports as metrics. +- Removed IP rate limiting over local networks. + +## PlatformVM + +- Enabled `AtomicTx`s to be issued into `StandardBlock`s and deprecated `AtomicBlock`s. +- Added the ability to export/import AVAX to/from the C-chain. + +## Coreth + +- Enabled multiple `AtomicTx`s to be issued per block. +- Added the ability to export/import AVAX to/from the P-chain. + +## RPCChainVM + +- Added support for metrics to be reported by plugin VMs. + +## Configs + +- Removed `--snow-epoch-first-transition` and `snow-epoch-duration` as command line arguments. + ## [v1.6.5](https://github.com/ava-labs/avalanchego/releases/tag/v1.6.5) This version is backwards compatible to [v1.6.0](https://github.com/ava-labs/avalanchego/releases/tag/v1.6.0). It is optional, but encouraged. diff --git a/api/admin/client.go b/api/admin/client.go index cda5a70f537e..976e365dd7e7 100644 --- a/api/admin/client.go +++ b/api/admin/client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package admin diff --git a/api/admin/client_test.go b/api/admin/client_test.go index 21204d7a46d6..fc67150e982b 100644 --- a/api/admin/client_test.go +++ b/api/admin/client_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package admin diff --git a/api/admin/service.go b/api/admin/service.go index 5b0c216a0ee4..0ee95c4c69fb 100644 --- a/api/admin/service.go +++ b/api/admin/service.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package admin diff --git a/api/auth/auth.go b/api/auth/auth.go index 87e61fb9d4b9..45eccf513008 100644 --- a/api/auth/auth.go +++ b/api/auth/auth.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package auth diff --git a/api/auth/auth_test.go b/api/auth/auth_test.go index 078c14f793c2..f6c24f9a135d 100644 --- a/api/auth/auth_test.go +++ b/api/auth/auth_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package auth diff --git a/api/auth/claims.go b/api/auth/claims.go index 6de5abeb631a..c093764fffc1 100644 --- a/api/auth/claims.go +++ b/api/auth/claims.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package auth diff --git a/api/auth/response.go b/api/auth/response.go index 770d2a150e2f..ba33d5df05e4 100644 --- a/api/auth/response.go +++ b/api/auth/response.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package auth diff --git a/api/auth/service.go b/api/auth/service.go index 27b0567d05c5..ee1b681f6323 100644 --- a/api/auth/service.go +++ b/api/auth/service.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package auth diff --git a/api/common_args_responses.go b/api/common_args_responses.go index 19005e138b7e..2721000bc82e 100644 --- a/api/common_args_responses.go +++ b/api/common_args_responses.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package api diff --git a/api/health/client.go b/api/health/client.go index a7b19a267e65..3a0e8bb9752e 100644 --- a/api/health/client.go +++ b/api/health/client.go @@ -1,4 +1,4 @@ -// (c) 2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package health diff --git a/api/health/service.go b/api/health/service.go index 5387397f8ff8..64e7b3d1947d 100644 --- a/api/health/service.go +++ b/api/health/service.go @@ -1,4 +1,4 @@ -// (c) 2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package health diff --git a/api/info/client.go b/api/info/client.go index e9cba9399723..b86ec6b2205e 100644 --- a/api/info/client.go +++ b/api/info/client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package info diff --git a/api/info/service.go b/api/info/service.go index 9bd1d2ce2a4c..1330a4dbc3a6 100644 --- a/api/info/service.go +++ b/api/info/service.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package info @@ -6,7 +6,6 @@ package info import ( "errors" "fmt" - "math" "net/http" "github.com/gorilla/rpc/v2" @@ -23,7 +22,10 @@ import ( "github.com/ava-labs/avalanchego/vms" ) -var errNoChainProvided = errors.New("argument 'chain' not given") +var ( + errNoChainProvided = errors.New("argument 'chain' not given") + errNotValidator = errors.New("this is not a validator node") +) // Info is the API service for unprivileged info on a node type Info struct { @@ -44,7 +46,6 @@ type Parameters struct { CreateAssetTxFee uint64 CreateSubnetTxFee uint64 CreateBlockchainTxFee uint64 - UptimeRequirement float64 } // NewService returns a new admin API service @@ -248,49 +249,12 @@ type UptimeResponse struct { func (service *Info) Uptime(_ *http.Request, _ *struct{}, reply *UptimeResponse) error { service.log.Debug("Info: Uptime called") - - myStake, _ := service.validators.GetWeight(service.NodeID) - var ( - totalWeight = float64(service.validators.Weight()) - totalWeightedPercent = 100 * float64(myStake) - rewardingStake = float64(myStake) - ) - for _, peerInfo := range service.networking.Peers(nil) { - peerID, err := ids.ShortFromPrefixedString(peerInfo.ID, constants.NodeIDPrefix) - if err != nil { - return err - } - - weight, ok := service.validators.GetWeight(peerID) - if !ok { - // this is not a validator skip it. - continue - } - - peerVersion, err := service.versionParser.Parse(peerInfo.Version) - if err != nil { - return err - } - - weightFloat := float64(weight) - - if peerVersion.Before(version.MinUptimeVersion) { - // If the peer is running an earlier version, then ignore their - // stake - totalWeight -= weightFloat - continue - } - - percent := float64(peerInfo.ObservedUptime) - totalWeightedPercent += percent * weightFloat - - // if this peer thinks we're above requirement add the weight - if percent/100 >= service.UptimeRequirement { - rewardingStake += weightFloat - } + result, isValidator := service.networking.NodeUptime() + if !isValidator { + return errNotValidator } - reply.WeightedAveragePercentage = json.Float64(math.Abs(totalWeightedPercent / totalWeight)) - reply.RewardingStakePercentage = json.Float64(math.Abs(100 * rewardingStake / totalWeight)) + reply.WeightedAveragePercentage = json.Float64(result.WeightedAveragePercentage) + reply.RewardingStakePercentage = json.Float64(result.RewardingStakePercentage) return nil } diff --git a/api/ipcs/client.go b/api/ipcs/client.go index 891dee6e5422..65084dd4c3a5 100644 --- a/api/ipcs/client.go +++ b/api/ipcs/client.go @@ -1,4 +1,4 @@ -// (c) 2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ipcs diff --git a/api/ipcs/service.go b/api/ipcs/service.go index 42ac5044929b..2586a73890d6 100644 --- a/api/ipcs/service.go +++ b/api/ipcs/service.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ipcs diff --git a/api/keystore/blockchain_keystore.go b/api/keystore/blockchain_keystore.go index 310d1344c455..59d5336833a7 100644 --- a/api/keystore/blockchain_keystore.go +++ b/api/keystore/blockchain_keystore.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package keystore diff --git a/api/keystore/client.go b/api/keystore/client.go index b0c7f85d8fb2..167b05e886a8 100644 --- a/api/keystore/client.go +++ b/api/keystore/client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package keystore diff --git a/api/keystore/codec.go b/api/keystore/codec.go index 92e599ed2cb6..b515cc875e3f 100644 --- a/api/keystore/codec.go +++ b/api/keystore/codec.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package keystore diff --git a/api/keystore/gkeystore/keystore_client.go b/api/keystore/gkeystore/keystore_client.go index 806049b6aa29..68ceefe77d99 100644 --- a/api/keystore/gkeystore/keystore_client.go +++ b/api/keystore/gkeystore/keystore_client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package gkeystore diff --git a/api/keystore/gkeystore/keystore_server.go b/api/keystore/gkeystore/keystore_server.go index faf83de737d2..341e64e84429 100644 --- a/api/keystore/gkeystore/keystore_server.go +++ b/api/keystore/gkeystore/keystore_server.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package gkeystore diff --git a/api/keystore/keystore.go b/api/keystore/keystore.go index 91757302d3db..23b429b415d2 100644 --- a/api/keystore/keystore.go +++ b/api/keystore/keystore.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package keystore diff --git a/api/keystore/service.go b/api/keystore/service.go index f0b7fcb79130..a190212ddc5a 100644 --- a/api/keystore/service.go +++ b/api/keystore/service.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package keystore diff --git a/api/keystore/service_test.go b/api/keystore/service_test.go index 325d5ab86c37..282ec8ce5432 100644 --- a/api/keystore/service_test.go +++ b/api/keystore/service_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package keystore diff --git a/api/metrics/gatherer_test.go b/api/metrics/gatherer_test.go new file mode 100644 index 000000000000..fd1440bbcb1b --- /dev/null +++ b/api/metrics/gatherer_test.go @@ -0,0 +1,23 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package metrics + +import ( + dto "github.com/prometheus/client_model/go" +) + +var ( + hello = "hello" + world = "world" + helloWorld = "hello_world" +) + +type testGatherer struct { + mfs []*dto.MetricFamily + err error +} + +func (g *testGatherer) Gather() ([]*dto.MetricFamily, error) { + return g.mfs, g.err +} diff --git a/api/metrics/multi_gatherer.go b/api/metrics/multi_gatherer.go new file mode 100644 index 000000000000..5997f7965f4b --- /dev/null +++ b/api/metrics/multi_gatherer.go @@ -0,0 +1,93 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package metrics + +import ( + "errors" + "fmt" + "sort" + "sync" + + "github.com/prometheus/client_golang/prometheus" + + dto "github.com/prometheus/client_model/go" +) + +var ( + errDuplicatedPrefix = errors.New("duplicated prefix") + + _ MultiGatherer = &multiGatherer{} +) + +// MultiGatherer extends the Gatherer interface by allowing additional gatherers +// to be registered. +type MultiGatherer interface { + prometheus.Gatherer + + // Register adds the outputs of [gatherer] to the results of future calls to + // Gather with the provided [namespace] added to the metrics. + Register(namespace string, gatherer prometheus.Gatherer) error +} + +type multiGatherer struct { + lock sync.RWMutex + gatherers map[string]prometheus.Gatherer +} + +func NewMultiGatherer() MultiGatherer { + return &multiGatherer{ + gatherers: make(map[string]prometheus.Gatherer), + } +} + +func (g *multiGatherer) Gather() ([]*dto.MetricFamily, error) { + g.lock.RLock() + defer g.lock.RUnlock() + + var results []*dto.MetricFamily + for namespace, gatherer := range g.gatherers { + metrics, err := gatherer.Gather() + if err != nil { + return nil, err + } + for _, metric := range metrics { + var name string + if metric.Name != nil { + if len(namespace) > 0 { + name = fmt.Sprintf("%s_%s", namespace, *metric.Name) + } else { + name = *metric.Name + } + } else { + name = namespace + } + metric.Name = &name + results = append(results, metric) + } + } + // Because we overwrite every metric's name, we are guaranteed that there + // are no metrics with nil names. + sortMetrics(results) + return results, nil +} + +func (g *multiGatherer) Register(namespace string, gatherer prometheus.Gatherer) error { + g.lock.Lock() + defer g.lock.Unlock() + + if _, exists := g.gatherers[namespace]; exists { + return errDuplicatedPrefix + } + + g.gatherers[namespace] = gatherer + return nil +} + +type sortMetricsData []*dto.MetricFamily + +func (m sortMetricsData) Less(i, j int) bool { return *m[i].Name < *m[j].Name } +func (m sortMetricsData) Len() int { return len(m) } +func (m sortMetricsData) Swap(i, j int) { m[j], m[i] = m[i], m[j] } + +func sortMetrics(m []*dto.MetricFamily) { sort.Sort(sortMetricsData(m)) } diff --git a/api/metrics/multi_gatherer_test.go b/api/metrics/multi_gatherer_test.go new file mode 100644 index 000000000000..e7a0a4c824a5 --- /dev/null +++ b/api/metrics/multi_gatherer_test.go @@ -0,0 +1,143 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package metrics + +import ( + "errors" + "testing" + + "github.com/stretchr/testify/assert" + + dto "github.com/prometheus/client_model/go" +) + +func TestMultiGathererEmptyGather(t *testing.T) { + assert := assert.New(t) + + g := NewMultiGatherer() + + mfs, err := g.Gather() + assert.NoError(err) + assert.Empty(mfs) +} + +func TestMultiGathererDuplicatedPrefix(t *testing.T) { + assert := assert.New(t) + + g := NewMultiGatherer() + og := NewOptionalGatherer() + + err := g.Register("", og) + assert.NoError(err) + + err = g.Register("", og) + assert.Equal(errDuplicatedPrefix, err) + + err = g.Register("lol", og) + assert.NoError(err) +} + +func TestMultiGathererAddedError(t *testing.T) { + assert := assert.New(t) + + g := NewMultiGatherer() + + expected := errors.New(":(") + tg := &testGatherer{ + err: expected, + } + + err := g.Register("", tg) + assert.NoError(err) + + mfs, err := g.Gather() + assert.Equal(expected, err) + assert.Empty(mfs) +} + +func TestMultiGathererNoAddedPrefix(t *testing.T) { + assert := assert.New(t) + + g := NewMultiGatherer() + + tg := &testGatherer{ + mfs: []*dto.MetricFamily{{ + Name: &hello, + }}, + } + + err := g.Register("", tg) + assert.NoError(err) + + mfs, err := g.Gather() + assert.NoError(err) + assert.Len(mfs, 1) + assert.Equal(&hello, mfs[0].Name) +} + +func TestMultiGathererAddedPrefix(t *testing.T) { + assert := assert.New(t) + + g := NewMultiGatherer() + + tg := &testGatherer{ + mfs: []*dto.MetricFamily{{ + Name: &world, + }}, + } + + err := g.Register(hello, tg) + assert.NoError(err) + + mfs, err := g.Gather() + assert.NoError(err) + assert.Len(mfs, 1) + assert.Equal(&helloWorld, mfs[0].Name) +} + +func TestMultiGathererJustPrefix(t *testing.T) { + assert := assert.New(t) + + g := NewMultiGatherer() + + tg := &testGatherer{ + mfs: []*dto.MetricFamily{{}}, + } + + err := g.Register(hello, tg) + assert.NoError(err) + + mfs, err := g.Gather() + assert.NoError(err) + assert.Len(mfs, 1) + assert.Equal(&hello, mfs[0].Name) +} + +func TestMultiGathererSorted(t *testing.T) { + assert := assert.New(t) + + g := NewMultiGatherer() + + name0 := "a" + name1 := "z" + tg := &testGatherer{ + mfs: []*dto.MetricFamily{ + { + Name: &name1, + }, + { + Name: &name0, + }, + }, + } + + err := g.Register("", tg) + assert.NoError(err) + + mfs, err := g.Gather() + assert.NoError(err) + assert.Len(mfs, 2) + assert.Equal(&name0, mfs[0].Name) + assert.Equal(&name1, mfs[1].Name) +} diff --git a/api/metrics/optional_gatherer.go b/api/metrics/optional_gatherer.go new file mode 100644 index 000000000000..76c3694c3c52 --- /dev/null +++ b/api/metrics/optional_gatherer.go @@ -0,0 +1,61 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package metrics + +import ( + "errors" + "sync" + + "github.com/prometheus/client_golang/prometheus" + + dto "github.com/prometheus/client_model/go" +) + +var ( + errDuplicatedRegister = errors.New("duplicated register") + + _ OptionalGatherer = &optionalGatherer{} +) + +// OptionalGatherer extends the Gatherer interface by allowing the optional +// registration of a single gatherer. If no gatherer is registered, Gather will +// return no metrics and no error. If a gatherer is registered, Gather will +// return the results of calling Gather on the provided gatherer. +type OptionalGatherer interface { + prometheus.Gatherer + + // Register the provided gatherer. If a gatherer was previously registered, + // an error will be returned. + Register(gatherer prometheus.Gatherer) error +} + +type optionalGatherer struct { + lock sync.RWMutex + gatherer prometheus.Gatherer +} + +func NewOptionalGatherer() OptionalGatherer { + return &optionalGatherer{} +} + +func (g *optionalGatherer) Gather() ([]*dto.MetricFamily, error) { + g.lock.RLock() + defer g.lock.RUnlock() + + if g.gatherer == nil { + return nil, nil + } + return g.gatherer.Gather() +} + +func (g *optionalGatherer) Register(gatherer prometheus.Gatherer) error { + g.lock.Lock() + defer g.lock.Unlock() + + if g.gatherer != nil { + return errDuplicatedRegister + } + g.gatherer = gatherer + return nil +} diff --git a/api/metrics/optional_gatherer_test.go b/api/metrics/optional_gatherer_test.go new file mode 100644 index 000000000000..f187e06bf3de --- /dev/null +++ b/api/metrics/optional_gatherer_test.go @@ -0,0 +1,74 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package metrics + +import ( + "errors" + "testing" + + "github.com/stretchr/testify/assert" + + dto "github.com/prometheus/client_model/go" +) + +func TestOptionalGathererEmptyGather(t *testing.T) { + assert := assert.New(t) + + g := NewOptionalGatherer() + + mfs, err := g.Gather() + assert.NoError(err) + assert.Empty(mfs) +} + +func TestOptionalGathererDuplicated(t *testing.T) { + assert := assert.New(t) + + g := NewOptionalGatherer() + og := NewOptionalGatherer() + + err := g.Register(og) + assert.NoError(err) + + err = g.Register(og) + assert.Equal(errDuplicatedRegister, err) +} + +func TestOptionalGathererAddedError(t *testing.T) { + assert := assert.New(t) + + g := NewOptionalGatherer() + + expected := errors.New(":(") + tg := &testGatherer{ + err: expected, + } + + err := g.Register(tg) + assert.NoError(err) + + mfs, err := g.Gather() + assert.Equal(expected, err) + assert.Empty(mfs) +} + +func TestMultiGathererAdded(t *testing.T) { + assert := assert.New(t) + + g := NewOptionalGatherer() + + tg := &testGatherer{ + mfs: []*dto.MetricFamily{{ + Name: &hello, + }}, + } + + err := g.Register(tg) + assert.NoError(err) + + mfs, err := g.Gather() + assert.NoError(err) + assert.Len(mfs, 1) + assert.Equal(&hello, mfs[0].Name) +} diff --git a/api/metrics/service.go b/api/metrics/service.go deleted file mode 100644 index 20687f22098c..000000000000 --- a/api/metrics/service.go +++ /dev/null @@ -1,24 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package metrics - -import ( - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" - - "github.com/ava-labs/avalanchego/snow/engine/common" -) - -// NewService returns a new prometheus service -func NewService() (*prometheus.Registry, *common.HTTPHandler) { - registerer := prometheus.NewRegistry() - handler := promhttp.InstrumentMetricHandler( - registerer, - promhttp.HandlerFor( - registerer, - promhttp.HandlerOpts{}, - ), - ) - return registerer, &common.HTTPHandler{LockOptions: common.NoLock, Handler: handler} -} diff --git a/api/server/middleware_handler.go b/api/server/middleware_handler.go index 5d1ece740d5c..fa744e389184 100644 --- a/api/server/middleware_handler.go +++ b/api/server/middleware_handler.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package server diff --git a/api/server/router.go b/api/server/router.go index 5bab97347f0c..c54c881cd46c 100644 --- a/api/server/router.go +++ b/api/server/router.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package server diff --git a/api/server/router_test.go b/api/server/router_test.go index a62703e837a2..48400728bbe3 100644 --- a/api/server/router_test.go +++ b/api/server/router_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package server diff --git a/api/server/server.go b/api/server/server.go index 8d2d276e1ca9..7b1e7dfd1135 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package server @@ -143,11 +143,11 @@ func (s *Server) DispatchTLS(certFile, keyFile string) error { // creating a new chain and holds the P-Chain's lock when this function is held, // and at the same time the server's lock is held due to an API call and is trying // to grab the P-Chain's lock. -func (s *Server) RegisterChain(chainName string, ctx *snow.Context, engine common.Engine) { +func (s *Server) RegisterChain(chainName string, ctx *snow.ConsensusContext, engine common.Engine) { go s.registerChain(chainName, ctx, engine) } -func (s *Server) registerChain(chainName string, ctx *snow.Context, engine common.Engine) { +func (s *Server) registerChain(chainName string, ctx *snow.ConsensusContext, engine common.Engine) { var ( handlers map[string]*common.HTTPHandler err error @@ -187,7 +187,7 @@ func (s *Server) registerChain(chainName string, ctx *snow.Context, engine commo } // AddChainRoute registers a route to a chain's handler -func (s *Server) AddChainRoute(handler *common.HTTPHandler, ctx *snow.Context, base, endpoint string, loggingWriter io.Writer) error { +func (s *Server) AddChainRoute(handler *common.HTTPHandler, ctx *snow.ConsensusContext, base, endpoint string, loggingWriter io.Writer) error { url := fmt.Sprintf("%s/%s", baseURL, base) s.log.Info("adding route %s%s", url, endpoint) // Apply logging middleware @@ -240,7 +240,7 @@ func lockMiddleware(handler http.Handler, lockOption common.LockOption, lock *sy // Reject middleware wraps a handler. If the chain that the context describes is // not done bootstrapping, writes back an error. -func rejectMiddleware(handler http.Handler, ctx *snow.Context) http.Handler { +func rejectMiddleware(handler http.Handler, ctx *snow.ConsensusContext) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // If chain isn't done bootstrapping, ignore API calls if !ctx.IsBootstrapped() { w.WriteHeader(http.StatusServiceUnavailable) diff --git a/api/server/server_test.go b/api/server/server_test.go index 7cb9dc17db25..dd02ab067d26 100644 --- a/api/server/server_test.go +++ b/api/server/server_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package server diff --git a/api/server/wrapper.go b/api/server/wrapper.go index bef6b91f07e1..f484031890cf 100644 --- a/api/server/wrapper.go +++ b/api/server/wrapper.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package server diff --git a/app/app.go b/app/app.go index 246bc605883d..ecddcfb4d09d 100644 --- a/app/app.go +++ b/app/app.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package app diff --git a/app/plugin/plugin.go b/app/plugin/plugin.go index 32bd39f3f702..37a7e65ed954 100644 --- a/app/plugin/plugin.go +++ b/app/plugin/plugin.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package plugin diff --git a/app/plugin/plugin_client.go b/app/plugin/plugin_client.go index 21a353f26ce7..894f03153f8f 100644 --- a/app/plugin/plugin_client.go +++ b/app/plugin/plugin_client.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package plugin diff --git a/app/plugin/plugin_server.go b/app/plugin/plugin_server.go index 7bd7f6548344..526edbdfbaf1 100644 --- a/app/plugin/plugin_server.go +++ b/app/plugin/plugin_server.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package plugin diff --git a/app/plugin/process.go b/app/plugin/process.go index cb8a555c42e0..59a52d77e1bb 100644 --- a/app/plugin/process.go +++ b/app/plugin/process.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package plugin diff --git a/app/process/process.go b/app/process/process.go index 285de87341b1..7c4e766681fc 100644 --- a/app/process/process.go +++ b/app/process/process.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package process diff --git a/app/runner/config.go b/app/runner/config.go index cbab6276cf9a..b7e8caebfeaa 100644 --- a/app/runner/config.go +++ b/app/runner/config.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package runner diff --git a/app/runner/runner.go b/app/runner/runner.go index e2521fe403ca..f0ebd3ff6263 100644 --- a/app/runner/runner.go +++ b/app/runner/runner.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package runner diff --git a/cache/cache.go b/cache/cache.go index 1703ac0c892f..017fc697b28a 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package cache diff --git a/cache/lru_cache.go b/cache/lru_cache.go index 065079e33a20..ccee21cb3354 100644 --- a/cache/lru_cache.go +++ b/cache/lru_cache.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package cache diff --git a/cache/lru_cache_benchmark_test.go b/cache/lru_cache_benchmark_test.go index ab95c996912e..aabddda70df0 100644 --- a/cache/lru_cache_benchmark_test.go +++ b/cache/lru_cache_benchmark_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package cache diff --git a/cache/lru_cache_test.go b/cache/lru_cache_test.go index 87fc8a37f5a4..6de5b028210b 100644 --- a/cache/lru_cache_test.go +++ b/cache/lru_cache_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package cache diff --git a/cache/metercacher/cache.go b/cache/metercacher/cache.go index 96796de2a5fc..b372455cd9a7 100644 --- a/cache/metercacher/cache.go +++ b/cache/metercacher/cache.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package metercacher diff --git a/cache/metercacher/cache_test.go b/cache/metercacher/cache_test.go index 4f018ed3ca2f..cd081e6c21d6 100644 --- a/cache/metercacher/cache_test.go +++ b/cache/metercacher/cache_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package metercacher diff --git a/cache/metercacher/metrics.go b/cache/metercacher/metrics.go index e9e9f34d4520..177fd8c237a5 100644 --- a/cache/metercacher/metrics.go +++ b/cache/metercacher/metrics.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package metercacher diff --git a/cache/test_cacher.go b/cache/test_cacher.go index a2672f6ac230..5e13c6d7710b 100644 --- a/cache/test_cacher.go +++ b/cache/test_cacher.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package cache diff --git a/cache/unique_cache.go b/cache/unique_cache.go index 8e08e7936492..3f5918ec8538 100644 --- a/cache/unique_cache.go +++ b/cache/unique_cache.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package cache diff --git a/cache/unique_cache_test.go b/cache/unique_cache_test.go index 2d8416a5aabd..950dbff69d1e 100644 --- a/cache/unique_cache_test.go +++ b/cache/unique_cache_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package cache diff --git a/chains/atomic/gsharedmemory/filtered_batch.go b/chains/atomic/gsharedmemory/filtered_batch.go index a123cd7ff22d..9b079aab0259 100644 --- a/chains/atomic/gsharedmemory/filtered_batch.go +++ b/chains/atomic/gsharedmemory/filtered_batch.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package gsharedmemory diff --git a/chains/atomic/gsharedmemory/shared_memory_client.go b/chains/atomic/gsharedmemory/shared_memory_client.go index fade6085f6b7..205739f7ddbb 100644 --- a/chains/atomic/gsharedmemory/shared_memory_client.go +++ b/chains/atomic/gsharedmemory/shared_memory_client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package gsharedmemory diff --git a/chains/atomic/gsharedmemory/shared_memory_server.go b/chains/atomic/gsharedmemory/shared_memory_server.go index 9e99ba25ce9c..1e4b65fc5158 100644 --- a/chains/atomic/gsharedmemory/shared_memory_server.go +++ b/chains/atomic/gsharedmemory/shared_memory_server.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package gsharedmemory diff --git a/chains/atomic/gsharedmemory/shared_memory_test.go b/chains/atomic/gsharedmemory/shared_memory_test.go index 05cebdc8632b..bb796adf943c 100644 --- a/chains/atomic/gsharedmemory/shared_memory_test.go +++ b/chains/atomic/gsharedmemory/shared_memory_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package gsharedmemory diff --git a/chains/atomic/memory.go b/chains/atomic/memory.go index 689b94e496d6..d49101f4f486 100644 --- a/chains/atomic/memory.go +++ b/chains/atomic/memory.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package atomic diff --git a/chains/atomic/memory_test.go b/chains/atomic/memory_test.go index 1c7bd809a4da..5a7e170d93a7 100644 --- a/chains/atomic/memory_test.go +++ b/chains/atomic/memory_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package atomic diff --git a/chains/atomic/prefixes.go b/chains/atomic/prefixes.go index d0bb99071349..7b2d6fd1f26d 100644 --- a/chains/atomic/prefixes.go +++ b/chains/atomic/prefixes.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package atomic diff --git a/chains/atomic/shared_memory.go b/chains/atomic/shared_memory.go index 4fc7bdf975dd..12ab7f24a441 100644 --- a/chains/atomic/shared_memory.go +++ b/chains/atomic/shared_memory.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package atomic diff --git a/chains/atomic/shared_memory_test.go b/chains/atomic/shared_memory_test.go index ffa9439b16fa..e60c3313f9ed 100644 --- a/chains/atomic/shared_memory_test.go +++ b/chains/atomic/shared_memory_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package atomic diff --git a/chains/atomic/state.go b/chains/atomic/state.go index 6c53b678ba35..046432918232 100644 --- a/chains/atomic/state.go +++ b/chains/atomic/state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package atomic diff --git a/chains/atomic/test_shared_memory.go b/chains/atomic/test_shared_memory.go index 914d5bbfe830..1af8a5cd0a0a 100644 --- a/chains/atomic/test_shared_memory.go +++ b/chains/atomic/test_shared_memory.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package atomic diff --git a/chains/atomic/writer.go b/chains/atomic/writer.go index 8fc3f7c40d44..1af7b2a0525b 100644 --- a/chains/atomic/writer.go +++ b/chains/atomic/writer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package atomic diff --git a/chains/manager.go b/chains/manager.go index 82751b2789a0..32f8364276b2 100644 --- a/chains/manager.go +++ b/chains/manager.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package chains @@ -11,8 +11,11 @@ import ( "sync" "time" + "github.com/prometheus/client_golang/prometheus" + "github.com/ava-labs/avalanchego/api/health" "github.com/ava-labs/avalanchego/api/keystore" + "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/prefixdb" @@ -48,9 +51,7 @@ import ( smbootstrap "github.com/ava-labs/avalanchego/snow/engine/snowman/bootstrap" ) -const ( - defaultChannelSize = 1 -) +const defaultChannelSize = 1 var ( errUnknownChainID = errors.New("unknown chain ID") @@ -111,7 +112,7 @@ type chain struct { Name string Engine common.Engine Handler *router.Handler - Ctx *snow.Context + Ctx *snow.ConsensusContext Beacons validators.Set } @@ -132,12 +133,10 @@ type ManagerConfig struct { DecisionEvents *triggers.EventDispatcher ConsensusEvents *triggers.EventDispatcher DBManager dbManager.Manager - MsgCreator message.Creator // message creator, shared with network - Router router.Router // Routes incoming messages to the appropriate chain - Net network.Network // Sends consensus messages to other validators - ConsensusParams avcon.Parameters // The consensus parameters (alpha, beta, etc.) for new chains - EpochFirstTransition time.Time - EpochDuration time.Duration + MsgCreator message.Creator // message creator, shared with network + Router router.Router // Routes incoming messages to the appropriate chain + Net network.Network // Sends consensus messages to other validators + ConsensusParams avcon.Parameters // The consensus parameters (alpha, beta, etc.) for new chains Validators validators.Manager // Validators validating on this chain NodeID ids.ShortID // The ID of this node NetworkID uint32 // ID of the network this node is connected to @@ -157,6 +156,7 @@ type ManagerConfig struct { // ShutdownNodeFunc allows the chain manager to issue a request to shutdown the node ShutdownNodeFunc func(exitCode int) MeterVMEnabled bool // Should each VM be wrapped with a MeterVM + Metrics metrics.MultiGatherer AppGossipValidatorSize int AppGossipNonValidatorSize int @@ -312,27 +312,42 @@ func (m *manager) buildChain(chainParams ChainParameters, sb Subnet) (*chain, er return nil, fmt.Errorf("error while creating chain's log %w", err) } - ctx := &snow.Context{ - NetworkID: m.NetworkID, - SubnetID: chainParams.SubnetID, - ChainID: chainParams.ID, - NodeID: m.NodeID, - XChainID: m.XChainID, - AVAXAssetID: m.AVAXAssetID, - Log: chainLog, - DecisionDispatcher: m.DecisionEvents, - ConsensusDispatcher: m.ConsensusEvents, - Keystore: m.Keystore.NewBlockchainKeyStore(chainParams.ID), - SharedMemory: m.AtomicMemory.NewSharedMemory(chainParams.ID), - BCLookup: m, - SNLookup: m, - Namespace: fmt.Sprintf("%s_%s_vm", constants.PlatformName, primaryAlias), - Metrics: m.ConsensusParams.Metrics, - EpochFirstTransition: m.EpochFirstTransition, - EpochDuration: m.EpochDuration, - ValidatorState: m.validatorState, - StakingCertLeaf: m.StakingCert.Leaf, - StakingLeafSigner: m.StakingCert.PrivateKey.(crypto.Signer), + consensusMetrics := prometheus.NewRegistry() + chainNamespace := fmt.Sprintf("%s_%s", constants.PlatformName, primaryAlias) + if err := m.Metrics.Register(chainNamespace, consensusMetrics); err != nil { + return nil, fmt.Errorf("error while registering chain's metrics %w", err) + } + + vmMetrics := metrics.NewOptionalGatherer() + vmNamespace := fmt.Sprintf("%s_vm", chainNamespace) + if err := m.Metrics.Register(vmNamespace, vmMetrics); err != nil { + return nil, fmt.Errorf("error while registering vm's metrics %w", err) + } + + ctx := &snow.ConsensusContext{ + Context: &snow.Context{ + NetworkID: m.NetworkID, + SubnetID: chainParams.SubnetID, + ChainID: chainParams.ID, + NodeID: m.NodeID, + + XChainID: m.XChainID, + AVAXAssetID: m.AVAXAssetID, + + Log: chainLog, + Keystore: m.Keystore.NewBlockchainKeyStore(chainParams.ID), + SharedMemory: m.AtomicMemory.NewSharedMemory(chainParams.ID), + BCLookup: m, + SNLookup: m, + Metrics: vmMetrics, + + ValidatorState: m.validatorState, + StakingCertLeaf: m.StakingCert.Leaf, + StakingLeafSigner: m.StakingCert.PrivateKey.(crypto.Signer), + }, + DecisionDispatcher: m.DecisionEvents, + ConsensusDispatcher: m.ConsensusEvents, + Registerer: consensusMetrics, } if sbConfigs, ok := m.SubnetConfigs[chainParams.SubnetID]; ok { @@ -348,7 +363,7 @@ func (m *manager) buildChain(chainParams ChainParameters, sb Subnet) (*chain, er } // Create the chain - vm, err := vmFactory.New(ctx) + vm, err := vmFactory.New(ctx.Context) if err != nil { return nil, fmt.Errorf("error while creating vm: %w", err) } @@ -367,7 +382,7 @@ func (m *manager) buildChain(chainParams ChainParameters, sb Subnet) (*chain, er return nil, fmt.Errorf("error while getting fxFactory: %w", err) } - fx, err := fxFactory.New(ctx) + fx, err := fxFactory.New(ctx.Context) if err != nil { return nil, fmt.Errorf("error while creating fx: %w", err) } @@ -382,10 +397,7 @@ func (m *manager) buildChain(chainParams ChainParameters, sb Subnet) (*chain, er consensusParams := m.ConsensusParams if sbConfigs, ok := m.SubnetConfigs[chainParams.SubnetID]; ok && chainParams.SubnetID != constants.PrimaryNetworkID { consensusParams = sbConfigs.ConsensusParameters - // TODO: move metrics to another place so this can be tidier - consensusParams.Metrics = m.ConsensusParams.Metrics } - consensusParams.Namespace = fmt.Sprintf("%s_%s", constants.PlatformName, primaryAlias) // The validators of this blockchain var vdrs validators.Set // Validators validating this blockchain @@ -443,7 +455,7 @@ func (m *manager) buildChain(chainParams ChainParameters, sb Subnet) (*chain, er } // Register the chain with the timeout manager - if err := m.TimeoutManager.RegisterChain(ctx, consensusParams.Namespace); err != nil { + if err := m.TimeoutManager.RegisterChain(ctx); err != nil { return nil, err } @@ -464,7 +476,7 @@ func (m *manager) unblockChains() { // Create a DAG-based blockchain that uses Avalanche func (m *manager) createAvalancheChain( - ctx *snow.Context, + ctx *snow.ConsensusContext, genesisData []byte, vdrs, beacons validators.Set, @@ -477,7 +489,7 @@ func (m *manager) createAvalancheChain( ctx.Lock.Lock() defer ctx.Lock.Unlock() - meterDBManager, err := m.DBManager.NewMeterDBManager(consensusParams.Namespace+"_db", ctx.Metrics) + meterDBManager, err := m.DBManager.NewMeterDBManager("db", ctx.Registerer) if err != nil { return nil, err } @@ -489,11 +501,11 @@ func (m *manager) createAvalancheChain( vertexBootstrappingDB := prefixdb.New([]byte("vertex_bs"), db.Database) txBootstrappingDB := prefixdb.New([]byte("tx_bs"), db.Database) - vtxBlocker, err := queue.NewWithMissing(vertexBootstrappingDB, consensusParams.Namespace+"_vtx", ctx.Metrics) + vtxBlocker, err := queue.NewWithMissing(vertexBootstrappingDB, "vtx", ctx.Registerer) if err != nil { return nil, err } - txBlocker, err := queue.New(txBootstrappingDB, consensusParams.Namespace+"_tx", ctx.Metrics) + txBlocker, err := queue.New(txBootstrappingDB, "tx", ctx.Registerer) if err != nil { return nil, err } @@ -510,8 +522,6 @@ func (m *manager) createAvalancheChain( m.Net, m.ManagerConfig.Router, m.TimeoutManager, - consensusParams.Namespace, - consensusParams.Metrics, m.AppGossipValidatorSize, m.AppGossipNonValidatorSize, m.GossipAcceptedFrontierSize, @@ -528,7 +538,7 @@ func (m *manager) createAvalancheChain( vm = metervm.NewVertexVM(vm) } if err := vm.Initialize( - ctx, + ctx.Context, vmDBManager, genesisData, chainConfig.Upgrade, @@ -543,7 +553,7 @@ func (m *manager) createAvalancheChain( // Handles serialization/deserialization of vertices and also the // persistence of vertices vtxManager := &state.Serializer{} - vtxManager.Initialize(ctx, vm, vertexDB) + vtxManager.Initialize(ctx.Context, vm, vertexDB) sampleK := consensusParams.K if uint64(sampleK) > bootstrapWeight { @@ -610,8 +620,6 @@ func (m *manager) createAvalancheChain( engine, vdrs, msgChan, - fmt.Sprintf("%s_handler", consensusParams.Namespace), - consensusParams.Metrics, ) return &chain{ @@ -624,7 +632,7 @@ func (m *manager) createAvalancheChain( // Create a linear chain using the Snowman consensus engine func (m *manager) createSnowmanChain( - ctx *snow.Context, + ctx *snow.ConsensusContext, genesisData []byte, vdrs, beacons validators.Set, @@ -637,7 +645,7 @@ func (m *manager) createSnowmanChain( ctx.Lock.Lock() defer ctx.Lock.Unlock() - meterDBManager, err := m.DBManager.NewMeterDBManager(consensusParams.Namespace+"_db", ctx.Metrics) + meterDBManager, err := m.DBManager.NewMeterDBManager("db", ctx.Registerer) if err != nil { return nil, err } @@ -647,7 +655,7 @@ func (m *manager) createSnowmanChain( db := prefixDBManager.Current() bootstrappingDB := prefixdb.New([]byte("bs"), db.Database) - blocked, err := queue.NewWithMissing(bootstrappingDB, consensusParams.Namespace+"_block", ctx.Metrics) + blocked, err := queue.NewWithMissing(bootstrappingDB, "block", ctx.Registerer) if err != nil { return nil, err } @@ -664,8 +672,6 @@ func (m *manager) createSnowmanChain( m.Net, m.ManagerConfig.Router, m.TimeoutManager, - consensusParams.Namespace, - consensusParams.Metrics, m.AppGossipValidatorSize, m.AppGossipNonValidatorSize, m.GossipAcceptedFrontierSize, @@ -707,7 +713,7 @@ func (m *manager) createSnowmanChain( vm = metervm.NewBlockVM(vm) } if err := vm.Initialize( - ctx, + ctx.Context, vmDBManager, genesisData, chainConfig.Upgrade, @@ -767,8 +773,6 @@ func (m *manager) createSnowmanChain( engine, vdrs, msgChan, - fmt.Sprintf("%s_handler", consensusParams.Namespace), - consensusParams.Metrics, ) if err != nil { return nil, fmt.Errorf("couldn't initialize message handler: %s", err) @@ -830,7 +834,7 @@ func (m *manager) LookupVM(alias string) (ids.ID, error) { return m.VMManager.Lo // Notify registrants [those who want to know about the creation of chains] // that the specified chain has been created -func (m *manager) notifyRegistrants(name string, ctx *snow.Context, engine common.Engine) { +func (m *manager) notifyRegistrants(name string, ctx *snow.ConsensusContext, engine common.Engine) { for _, registrant := range m.registrants { registrant.RegisterChain(name, ctx, engine) } diff --git a/chains/mock_manager.go b/chains/mock_manager.go index 43aee9cfb4fa..bd2025687008 100644 --- a/chains/mock_manager.go +++ b/chains/mock_manager.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package chains diff --git a/chains/registrant.go b/chains/registrant.go index 9ccfc3fbded5..d97dc508e760 100644 --- a/chains/registrant.go +++ b/chains/registrant.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package chains @@ -13,5 +13,5 @@ type Registrant interface { // Called when the chain described by [ctx] and [engine] is created // This function is called before the chain starts processing messages // [engine] should be an avalanche.Engine or snowman.Engine - RegisterChain(name string, ctx *snow.Context, engine common.Engine) + RegisterChain(name string, ctx *snow.ConsensusContext, engine common.Engine) } diff --git a/chains/subnet.go b/chains/subnet.go index 0b1a3cfa94fa..fbe517ebf708 100644 --- a/chains/subnet.go +++ b/chains/subnet.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package chains diff --git a/chains/subnet_test.go b/chains/subnet_test.go index a740bfaace6e..3440cde4c9ad 100644 --- a/chains/subnet_test.go +++ b/chains/subnet_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package chains diff --git a/codec/codec.go b/codec/codec.go index de01f5bfd389..f79aa93f0d5e 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package codec diff --git a/codec/general_codec.go b/codec/general_codec.go index 1ec86abdbe53..2cffd5f632ab 100644 --- a/codec/general_codec.go +++ b/codec/general_codec.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package codec diff --git a/codec/hierarchycodec/codec.go b/codec/hierarchycodec/codec.go index f160d46ba8a3..37ee16758110 100644 --- a/codec/hierarchycodec/codec.go +++ b/codec/hierarchycodec/codec.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package hierarchycodec diff --git a/codec/hierarchycodec/codec_test.go b/codec/hierarchycodec/codec_test.go index 5c9cbd6bb57c..40a2f531c785 100644 --- a/codec/hierarchycodec/codec_test.go +++ b/codec/hierarchycodec/codec_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package hierarchycodec diff --git a/codec/linearcodec/codec.go b/codec/linearcodec/codec.go index a6111ab35cbf..070e3d41df1f 100644 --- a/codec/linearcodec/codec.go +++ b/codec/linearcodec/codec.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package linearcodec diff --git a/codec/linearcodec/codec_test.go b/codec/linearcodec/codec_test.go index d9dde2d5bb55..1045319d20fe 100644 --- a/codec/linearcodec/codec_test.go +++ b/codec/linearcodec/codec_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package linearcodec diff --git a/codec/manager.go b/codec/manager.go index 673aa6577e9a..198f71d8da6f 100644 --- a/codec/manager.go +++ b/codec/manager.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package codec diff --git a/codec/reflectcodec/struct_fielder.go b/codec/reflectcodec/struct_fielder.go index 50abd61bff3a..bd2ec04d836e 100644 --- a/codec/reflectcodec/struct_fielder.go +++ b/codec/reflectcodec/struct_fielder.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package reflectcodec diff --git a/codec/reflectcodec/type_codec.go b/codec/reflectcodec/type_codec.go index 697d9a74c125..c99e9dd5d1ea 100644 --- a/codec/reflectcodec/type_codec.go +++ b/codec/reflectcodec/type_codec.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package reflectcodec diff --git a/codec/registry.go b/codec/registry.go index c3999687d9eb..aea9186b5dd6 100644 --- a/codec/registry.go +++ b/codec/registry.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package codec diff --git a/codec/test_codec.go b/codec/test_codec.go index 02d9fd4a9602..8acb350679a7 100644 --- a/codec/test_codec.go +++ b/codec/test_codec.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package codec diff --git a/config/config.go b/config/config.go index 0e5a0d1389c9..35661004e8e2 100644 --- a/config/config.go +++ b/config/config.go @@ -1,4 +1,4 @@ -// (c) 2021 Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package config @@ -337,6 +337,7 @@ func getNetworkConfig(v *viper.Viper, halflife time.Duration) (network.Config, e CompressionEnabled: v.GetBool(NetworkCompressionEnabledKey), PingFrequency: v.GetDuration(NetworkPingFrequencyKey), AllowPrivateIPs: v.GetBool(NetworkAllowPrivateIPsKey), + UptimeMetricFreq: v.GetDuration(UptimeMetricFreqKey), RequireValidatorToConnect: v.GetBool(NetworkRequireValidatorToConnectKey), } @@ -589,20 +590,6 @@ func getTxFeeConfig(v *viper.Viper, networkID uint32) genesis.TxFeeConfig { return genesis.GetTxFeeConfig(networkID) } -func getEpochConfig(v *viper.Viper, networkID uint32) (genesis.EpochConfig, error) { - if networkID != constants.MainnetID && networkID != constants.FujiID { - config := genesis.EpochConfig{ - EpochFirstTransition: time.Unix(v.GetInt64(SnowEpochFirstTransitionKey), 0), - EpochDuration: v.GetDuration(SnowEpochDurationKey), - } - if config.EpochDuration <= 0 { - return genesis.EpochConfig{}, fmt.Errorf("%s must be > 0", SnowEpochDurationKey) - } - return config, nil - } - return genesis.GetEpochConfig(networkID), nil -} - func getWhitelistedSubnets(v *viper.Viper) (ids.Set, error) { whitelistedSubnetIDs := ids.Set{} for _, subnet := range strings.Split(v.GetString(WhitelistedSubnetsKey), ",") { @@ -837,6 +824,10 @@ func GetNodeConfig(v *viper.Viper, buildDir string) (node.Config, error) { return node.Config{}, err } + if nodeConfig.NetworkID == constants.MainnetID { + return node.Config{}, errors.New("mainnet is not supported") + } + // Database nodeConfig.DatabaseConfig, err = getDatabaseConfig(v, nodeConfig.NetworkID) if err != nil { @@ -915,12 +906,6 @@ func GetNodeConfig(v *viper.Viper, buildDir string) (node.Config, error) { // Tx Fee nodeConfig.TxFeeConfig = getTxFeeConfig(v, nodeConfig.NetworkID) - // Epoch - nodeConfig.EpochConfig, err = getEpochConfig(v, nodeConfig.NetworkID) - if err != nil { - return node.Config{}, fmt.Errorf("couldn't load epoch config: %w", err) - } - // Genesis Data nodeConfig.GenesisBytes, nodeConfig.AvaxAssetID, err = genesis.Genesis( nodeConfig.NetworkID, diff --git a/config/config_test.go b/config/config_test.go index 3a9fb211b977..5007e2093da3 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package config diff --git a/config/flags.go b/config/flags.go index d27d332784f0..8db8804dc573 100644 --- a/config/flags.go +++ b/config/flags.go @@ -1,4 +1,4 @@ -// (c) 2021 Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package config @@ -254,11 +254,10 @@ func addNodeFlags(fs *flag.FlagSet) { fs.Int(SnowOptimalProcessingKey, 50, "Optimal number of processing vertices in consensus") fs.Int(SnowMaxProcessingKey, 1024, "Maximum number of processing items to be considered healthy") fs.Duration(SnowMaxTimeProcessingKey, 2*time.Minute, "Maximum amount of time an item should be processing and still be healthy") - fs.Int64(SnowEpochFirstTransitionKey, genesis.LocalParams.EpochFirstTransition.Unix(), "Unix timestamp of the first epoch transaction, in seconds. Defaults to 12/10/2020 @ 7:00pm (UTC)") - fs.Duration(SnowEpochDurationKey, genesis.LocalParams.EpochDuration, "Duration of each epoch") // Metrics fs.Bool(MeterVMsEnabledKey, true, "Enable Meter VMs to track VM performance with more granularity") + fs.Duration(UptimeMetricFreqKey, 30*time.Second, "Frequency of renewing this node's average uptime metric") // IPC fs.String(IpcsChainIDsKey, "", "Comma separated list of chain ids to add to the IPC engine. Example: 11111111111111111111111111111111LpoYY,4R5p2RXDGLqaifZE4hHWH9owe34pfoBULn1DrQTWivjg8o4aH") diff --git a/config/keys.go b/config/keys.go index 18a81565b31d..0170e5c45313 100644 --- a/config/keys.go +++ b/config/keys.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package config @@ -94,8 +94,6 @@ const ( SnowOptimalProcessingKey = "snow-optimal-processing" SnowMaxProcessingKey = "snow-max-processing" SnowMaxTimeProcessingKey = "snow-max-time-processing" - SnowEpochFirstTransitionKey = "snow-epoch-first-transition" - SnowEpochDurationKey = "snow-epoch-duration" WhitelistedSubnetsKey = "whitelisted-subnets" AdminAPIEnabledKey = "api-admin-enabled" InfoAPIEnabledKey = "api-info-enabled" @@ -142,5 +140,6 @@ const ( OutboundThrottlerAtLargeAllocSizeKey = "throttler-outbound-at-large-alloc-size" OutboundThrottlerVdrAllocSizeKey = "throttler-outbound-validator-alloc-size" OutboundThrottlerNodeMaxAtLargeBytesKey = "throttler-outbound-node-max-at-large-bytes" + UptimeMetricFreqKey = "uptime-metric-freq" VMAliasesFileKey = "vm-aliases-file" ) diff --git a/config/pflags.go b/config/pflags.go index acffbe3de701..85ef0f076d9a 100644 --- a/config/pflags.go +++ b/config/pflags.go @@ -1,4 +1,4 @@ -// (c) 2021 Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package config diff --git a/config/viper.go b/config/viper.go index 7989115b2a9b..cf22d62b73a2 100644 --- a/config/viper.go +++ b/config/viper.go @@ -1,4 +1,4 @@ -// (c) 2021 Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package config diff --git a/database/batch.go b/database/batch.go index 2ec2192761b0..ab9977be6712 100644 --- a/database/batch.go +++ b/database/batch.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. // For ease of implementation, our database's interface matches Ethereum's diff --git a/database/benchmark_database.go b/database/benchmark_database.go index ed944efd180c..aadbd6448754 100644 --- a/database/benchmark_database.go +++ b/database/benchmark_database.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package database diff --git a/database/common.go b/database/common.go index e88860b1d62d..0c66d636ac0a 100644 --- a/database/common.go +++ b/database/common.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package database diff --git a/database/database.go b/database/database.go index 4e2dc1bac793..49148ec52f4c 100644 --- a/database/database.go +++ b/database/database.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. // For ease of implementation, our database's interface matches Ethereum's diff --git a/database/encdb/db.go b/database/encdb/db.go index 31c6c86b3e5d..fb2e95ff678b 100644 --- a/database/encdb/db.go +++ b/database/encdb/db.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package encdb diff --git a/database/encdb/db_test.go b/database/encdb/db_test.go index b7c3bae57efb..2ca8b3b8db10 100644 --- a/database/encdb/db_test.go +++ b/database/encdb/db_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package encdb diff --git a/database/errors.go b/database/errors.go index fcf26d2a45fb..8a7a2c9a380d 100644 --- a/database/errors.go +++ b/database/errors.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package database diff --git a/database/helpers.go b/database/helpers.go index b86509ab846e..c40923422c44 100644 --- a/database/helpers.go +++ b/database/helpers.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package database @@ -141,3 +141,20 @@ func Size(db Iteratee) (int, error) { } return size, iterator.Error() } + +func Clear(readerDB Iteratee, writerDB KeyValueWriter) error { + return ClearPrefix(readerDB, writerDB, nil) +} + +func ClearPrefix(readerDB Iteratee, writerDB KeyValueWriter, prefix []byte) error { + iterator := readerDB.NewIteratorWithPrefix(prefix) + defer iterator.Release() + + for iterator.Next() { + key := iterator.Key() + if err := writerDB.Delete(key); err != nil { + return err + } + } + return iterator.Error() +} diff --git a/database/iterator.go b/database/iterator.go index fd5ad83f2bdc..3457f52e7a93 100644 --- a/database/iterator.go +++ b/database/iterator.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. // For ease of implementation, our database's interface matches Ethereum's diff --git a/database/leveldb/db.go b/database/leveldb/db.go index 5c087838fea2..ff16c9753945 100644 --- a/database/leveldb/db.go +++ b/database/leveldb/db.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package leveldb diff --git a/database/leveldb/db_test.go b/database/leveldb/db_test.go index f8e2f8f768f4..8211059089ae 100644 --- a/database/leveldb/db_test.go +++ b/database/leveldb/db_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package leveldb diff --git a/database/linkeddb/codec.go b/database/linkeddb/codec.go index 5127d28e72a8..e1f97ca363d2 100644 --- a/database/linkeddb/codec.go +++ b/database/linkeddb/codec.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package linkeddb diff --git a/database/linkeddb/linkeddb.go b/database/linkeddb/linkeddb.go index b80fe14f8b70..571a9e4f056d 100644 --- a/database/linkeddb/linkeddb.go +++ b/database/linkeddb/linkeddb.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package linkeddb diff --git a/database/linkeddb/linkeddb_test.go b/database/linkeddb/linkeddb_test.go index 0ffb15cf7fe7..1b693afa5afa 100644 --- a/database/linkeddb/linkeddb_test.go +++ b/database/linkeddb/linkeddb_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package linkeddb diff --git a/database/manager/manager.go b/database/manager/manager.go index 054326c96a67..be1fbefdb6d3 100644 --- a/database/manager/manager.go +++ b/database/manager/manager.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package manager diff --git a/database/manager/manager_linux_test.go b/database/manager/manager_linux_test.go index 38abc3e54fcd..daf2ee11fe7c 100644 --- a/database/manager/manager_linux_test.go +++ b/database/manager/manager_linux_test.go @@ -2,19 +2,19 @@ // +build linux,amd64,rocksdballowed // ^ Only build this file if this computer runs Linux AND is AMD64 AND rocksdb is allowed -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package manager import ( + "path/filepath" "testing" "github.com/ava-labs/avalanchego/database/rocksdb" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/version" "github.com/stretchr/testify/assert" - "path/filepath" ) func TestNewSingleRocksDB(t *testing.T) { diff --git a/database/manager/manager_test.go b/database/manager/manager_test.go index baf8b579bdba..088f225f8d96 100644 --- a/database/manager/manager_test.go +++ b/database/manager/manager_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package manager diff --git a/database/manager/versioned_database.go b/database/manager/versioned_database.go index 53d3835f86fb..716be7f4c94b 100644 --- a/database/manager/versioned_database.go +++ b/database/manager/versioned_database.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package manager diff --git a/database/memdb/db.go b/database/memdb/db.go index 64e01a659517..a4ef00e6f3eb 100644 --- a/database/memdb/db.go +++ b/database/memdb/db.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package memdb diff --git a/database/memdb/db_test.go b/database/memdb/db_test.go index 1575d04cd6ce..d4cf5ce1c8a5 100644 --- a/database/memdb/db_test.go +++ b/database/memdb/db_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package memdb diff --git a/database/meterdb/db.go b/database/meterdb/db.go index 0998acfe427a..752d22fe0cef 100644 --- a/database/meterdb/db.go +++ b/database/meterdb/db.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package meterdb diff --git a/database/meterdb/db_test.go b/database/meterdb/db_test.go index 79ddba569482..4d518f600737 100644 --- a/database/meterdb/db_test.go +++ b/database/meterdb/db_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package meterdb diff --git a/database/meterdb/metrics.go b/database/meterdb/metrics.go index 3c95b248cf18..f16cd7faf8ed 100644 --- a/database/meterdb/metrics.go +++ b/database/meterdb/metrics.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package meterdb diff --git a/database/mockdb/db.go b/database/mockdb/db.go index 0621b997c4a2..0b84d4db5028 100644 --- a/database/mockdb/db.go +++ b/database/mockdb/db.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package mockdb diff --git a/database/mockdb/db_test.go b/database/mockdb/db_test.go index 4f1065a5d591..92a3a7b931ed 100644 --- a/database/mockdb/db_test.go +++ b/database/mockdb/db_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package mockdb diff --git a/database/nodb/db.go b/database/nodb/db.go index 498a065c13f9..2c7a73c4fb53 100644 --- a/database/nodb/db.go +++ b/database/nodb/db.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nodb diff --git a/database/prefixdb/db.go b/database/prefixdb/db.go index 3c4b76f68562..c2e4f1343f2c 100644 --- a/database/prefixdb/db.go +++ b/database/prefixdb/db.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package prefixdb diff --git a/database/prefixdb/db_test.go b/database/prefixdb/db_test.go index 8d818b3af530..3bcf2c9d1521 100644 --- a/database/prefixdb/db_test.go +++ b/database/prefixdb/db_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package prefixdb diff --git a/database/rocksdb/db.go b/database/rocksdb/db.go index 3d7e9cda2038..746533b6f878 100644 --- a/database/rocksdb/db.go +++ b/database/rocksdb/db.go @@ -2,7 +2,7 @@ // +build linux,amd64,rocksdballowed // ^ Only build this file if this computer linux AND it's AMD64 AND rocksdb is allowed -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package rocksdb diff --git a/database/rocksdb/db_not_supported.go b/database/rocksdb/db_not_supported.go index cb7ee436411d..10b636e78bd3 100644 --- a/database/rocksdb/db_not_supported.go +++ b/database/rocksdb/db_not_supported.go @@ -2,7 +2,7 @@ // +build !linux !amd64 !rocksdballowed // ^ Only build this file if this computer is not Linux OR it's not AMD64 OR rocksdb is not allowed -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package rocksdb diff --git a/database/rocksdb/db_test.go b/database/rocksdb/db_test.go index d326f110846f..8a8b2817b9fc 100644 --- a/database/rocksdb/db_test.go +++ b/database/rocksdb/db_test.go @@ -1,7 +1,7 @@ //go:build linux && amd64 && rocksdballowed // +build linux,amd64,rocksdballowed -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package rocksdb diff --git a/database/rocksdb/name.go b/database/rocksdb/name.go index 20c4cd31ac55..97d68947a8ed 100644 --- a/database/rocksdb/name.go +++ b/database/rocksdb/name.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package rocksdb diff --git a/database/rpcdb/db_client.go b/database/rpcdb/db_client.go index 4d115da1ee7d..46eaf105def2 100644 --- a/database/rpcdb/db_client.go +++ b/database/rpcdb/db_client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package rpcdb diff --git a/database/rpcdb/db_server.go b/database/rpcdb/db_server.go index c844847a3cb0..6aa465f425b6 100644 --- a/database/rpcdb/db_server.go +++ b/database/rpcdb/db_server.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package rpcdb diff --git a/database/rpcdb/db_test.go b/database/rpcdb/db_test.go index 4fdb615b1fe7..ddede7bf4750 100644 --- a/database/rpcdb/db_test.go +++ b/database/rpcdb/db_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package rpcdb diff --git a/database/rpcdb/errors.go b/database/rpcdb/errors.go index 50d31a20837f..d53453c324ba 100644 --- a/database/rpcdb/errors.go +++ b/database/rpcdb/errors.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package rpcdb diff --git a/database/test_database.go b/database/test_database.go index dfd863095b8a..0fffb3f86526 100644 --- a/database/test_database.go +++ b/database/test_database.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package database @@ -39,6 +39,8 @@ var Tests = []func(t *testing.T, db Database){ TestCompactNoPanic, TestMemorySafetyDatabase, TestMemorySafetyBatch, + TestClear, + TestClearPrefix, } // TestSimpleKeyValue tests to make sure that simple Put + Get + Delete + Has @@ -1099,3 +1101,85 @@ func TestCompactNoPanic(t *testing.T, db Database) { t.Fatalf("Expected error %s on db.Close but got %s", ErrClosed, err) } } + +// TestClear tests to make sure the deletion helper works as expected. +func TestClear(t *testing.T, db Database) { + assert := assert.New(t) + + key1 := []byte("hello1") + value1 := []byte("world1") + + key2 := []byte("z") + value2 := []byte("world2") + + key3 := []byte("hello3") + value3 := []byte("world3") + + err := db.Put(key1, value1) + assert.NoError(err) + + err = db.Put(key2, value2) + assert.NoError(err) + + err = db.Put(key3, value3) + assert.NoError(err) + + err = Clear(db, db) + assert.NoError(err) + + has, err := db.Has(key1) + assert.NoError(err) + assert.False(has) + + has, err = db.Has(key2) + assert.NoError(err) + assert.False(has) + + has, err = db.Has(key3) + assert.NoError(err) + assert.False(has) + + err = db.Close() + assert.NoError(err) +} + +// TestClearPrefix tests to make sure prefix deletion works as expected. +func TestClearPrefix(t *testing.T, db Database) { + assert := assert.New(t) + + key1 := []byte("hello1") + value1 := []byte("world1") + + key2 := []byte("z") + value2 := []byte("world2") + + key3 := []byte("hello3") + value3 := []byte("world3") + + err := db.Put(key1, value1) + assert.NoError(err) + + err = db.Put(key2, value2) + assert.NoError(err) + + err = db.Put(key3, value3) + assert.NoError(err) + + err = ClearPrefix(db, db, []byte("hello")) + assert.NoError(err) + + has, err := db.Has(key1) + assert.NoError(err) + assert.False(has) + + has, err = db.Has(key2) + assert.NoError(err) + assert.True(has) + + has, err = db.Has(key3) + assert.NoError(err) + assert.False(has) + + err = db.Close() + assert.NoError(err) +} diff --git a/database/versiondb/db.go b/database/versiondb/db.go index 20b27b8c7967..52ff551ce63e 100644 --- a/database/versiondb/db.go +++ b/database/versiondb/db.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package versiondb diff --git a/database/versiondb/db_test.go b/database/versiondb/db_test.go index b015c08edbbb..c4ef4925f413 100644 --- a/database/versiondb/db_test.go +++ b/database/versiondb/db_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package versiondb diff --git a/genesis/aliases.go b/genesis/aliases.go index bd5c13894ef6..4c6998ba84ab 100644 --- a/genesis/aliases.go +++ b/genesis/aliases.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package genesis diff --git a/genesis/beacons.go b/genesis/beacons.go index 17b76e257dcf..0d642041c1ba 100644 --- a/genesis/beacons.go +++ b/genesis/beacons.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package genesis diff --git a/genesis/config.go b/genesis/config.go index d9b29df94cbe..7f7e0824846f 100644 --- a/genesis/config.go +++ b/genesis/config.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package genesis diff --git a/genesis/genesis.go b/genesis/genesis.go index 9e5d6a1a7aae..b061f7219780 100644 --- a/genesis/genesis.go +++ b/genesis/genesis.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package genesis diff --git a/genesis/genesis_fuji.go b/genesis/genesis_fuji.go index 292532664098..0eb2cb300585 100644 --- a/genesis/genesis_fuji.go +++ b/genesis/genesis_fuji.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package genesis @@ -214,9 +214,5 @@ var ( MaxStakeDuration: 365 * 24 * time.Hour, StakeMintingPeriod: 365 * 24 * time.Hour, }, - EpochConfig: EpochConfig{ - EpochFirstTransition: time.Unix(1607626800, 0), - EpochDuration: 6 * time.Hour, - }, } ) diff --git a/genesis/genesis_local.go b/genesis/genesis_local.go index 3cc7130e38d4..afa698cdef05 100644 --- a/genesis/genesis_local.go +++ b/genesis/genesis_local.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package genesis @@ -109,9 +109,5 @@ var ( MaxStakeDuration: 365 * 24 * time.Hour, StakeMintingPeriod: 365 * 24 * time.Hour, }, - EpochConfig: EpochConfig{ - EpochFirstTransition: time.Unix(1607626800, 0), - EpochDuration: 6 * time.Hour, - }, } ) diff --git a/genesis/genesis_mainnet.go b/genesis/genesis_mainnet.go index f8136e227dd6..933bdc68b67b 100644 --- a/genesis/genesis_mainnet.go +++ b/genesis/genesis_mainnet.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package genesis @@ -175787,9 +175787,5 @@ var ( MaxStakeDuration: 365 * 24 * time.Hour, StakeMintingPeriod: 365 * 24 * time.Hour, }, - EpochConfig: EpochConfig{ - EpochFirstTransition: time.Unix(1607626800, 0), - EpochDuration: 6 * time.Hour, - }, } ) diff --git a/genesis/genesis_test.go b/genesis/genesis_test.go index 5c334ac6066d..55235031ef59 100644 --- a/genesis/genesis_test.go +++ b/genesis/genesis_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package genesis diff --git a/genesis/params.go b/genesis/params.go index 5beb554cc16a..3fbf1a270f82 100644 --- a/genesis/params.go +++ b/genesis/params.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package genesis @@ -43,31 +43,9 @@ type TxFeeConfig struct { CreateBlockchainTxFee uint64 `json:"createBlockchainTxFee"` } -type EpochConfig struct { - // EpochFirstTransition is the time that the transition from epoch 0 to 1 - // should occur. - EpochFirstTransition time.Time `json:"epochFirstTransition"` - // EpochDuration is the amount of time that an epoch runs for. - EpochDuration time.Duration `json:"epochDuration"` -} - type Params struct { StakingConfig TxFeeConfig - EpochConfig -} - -func GetEpochConfig(networkID uint32) EpochConfig { - switch networkID { - case constants.MainnetID: - return MainnetParams.EpochConfig - case constants.FujiID: - return FujiParams.EpochConfig - case constants.LocalID: - return LocalParams.EpochConfig - default: - return LocalParams.EpochConfig - } } func GetTxFeeConfig(networkID uint32) TxFeeConfig { diff --git a/genesis/unparsed_config.go b/genesis/unparsed_config.go index 6aad2540b379..4727a8f1d5f7 100644 --- a/genesis/unparsed_config.go +++ b/genesis/unparsed_config.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package genesis diff --git a/go.mod b/go.mod index 0b34870e5dde..827136351b90 100644 --- a/go.mod +++ b/go.mod @@ -37,6 +37,7 @@ require ( github.com/mr-tron/base58 v1.2.0 github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d github.com/prometheus/client_golang v1.7.1 + github.com/prometheus/client_model v0.2.0 github.com/rs/cors v1.7.0 github.com/spaolacci/murmur3 v1.1.0 github.com/spf13/cast v1.3.1 // indirect diff --git a/health/check.go b/health/check.go index ea6d397b85aa..82d9bb336147 100644 --- a/health/check.go +++ b/health/check.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package health diff --git a/health/checkable.go b/health/checkable.go index 2f0f7d271922..8db85c57e758 100644 --- a/health/checkable.go +++ b/health/checkable.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package health diff --git a/health/metrics.go b/health/metrics.go index e23febeb7bae..e254374ff26c 100644 --- a/health/metrics.go +++ b/health/metrics.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package health diff --git a/health/service.go b/health/service.go index 4b77fcfafb8c..c228d2ad617b 100644 --- a/health/service.go +++ b/health/service.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package health diff --git a/ids/aliases.go b/ids/aliases.go index eddc1dac5acf..929d93c07e31 100644 --- a/ids/aliases.go +++ b/ids/aliases.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/aliases_test.go b/ids/aliases_test.go index 5a9344687ea0..2d5311777e01 100644 --- a/ids/aliases_test.go +++ b/ids/aliases_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/bag.go b/ids/bag.go index 52ad78014da7..8c875087e599 100644 --- a/ids/bag.go +++ b/ids/bag.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/bag_benchmark_test.go b/ids/bag_benchmark_test.go index 776721d29056..f1a1f50041b0 100644 --- a/ids/bag_benchmark_test.go +++ b/ids/bag_benchmark_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/bag_test.go b/ids/bag_test.go index c8500cc91b1f..8cccd03eec89 100644 --- a/ids/bag_test.go +++ b/ids/bag_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/bit_set.go b/ids/bit_set.go index f686e5184759..5abc9e3bb92f 100644 --- a/ids/bit_set.go +++ b/ids/bit_set.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/bit_set_test.go b/ids/bit_set_test.go index 895c3fcf068c..81b1b75523a1 100644 --- a/ids/bit_set_test.go +++ b/ids/bit_set_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/bits.go b/ids/bits.go index a40879fc0b84..4ce351eeb64e 100644 --- a/ids/bits.go +++ b/ids/bits.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/bits_test.go b/ids/bits_test.go index 588f427ca5a4..76554ced834d 100644 --- a/ids/bits_test.go +++ b/ids/bits_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/galiasreader/alias_reader_client.go b/ids/galiasreader/alias_reader_client.go index 96367ed5ab18..0f7b525f1caa 100644 --- a/ids/galiasreader/alias_reader_client.go +++ b/ids/galiasreader/alias_reader_client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package galiasreader diff --git a/ids/galiasreader/alias_reader_server.go b/ids/galiasreader/alias_reader_server.go index d6535fa4fb77..f5c8aaee9342 100644 --- a/ids/galiasreader/alias_reader_server.go +++ b/ids/galiasreader/alias_reader_server.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package galiasreader diff --git a/ids/galiasreader/alias_reader_test.go b/ids/galiasreader/alias_reader_test.go index d31e532db429..73c3b5a85af3 100644 --- a/ids/galiasreader/alias_reader_test.go +++ b/ids/galiasreader/alias_reader_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package galiasreader diff --git a/ids/id.go b/ids/id.go index 51d6cd922a56..cd4d28ed59a0 100644 --- a/ids/id.go +++ b/ids/id.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/id_test.go b/ids/id_test.go index 67eaa1897a38..fda1c1af599f 100644 --- a/ids/id_test.go +++ b/ids/id_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/queue.go b/ids/queue.go index 2e371c8987d1..53286660a5d6 100644 --- a/ids/queue.go +++ b/ids/queue.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/queue_test.go b/ids/queue_test.go index 01f3b76c9c05..90d804bdbd33 100644 --- a/ids/queue_test.go +++ b/ids/queue_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/set.go b/ids/set.go index ab75577717eb..134be2769ccb 100644 --- a/ids/set.go +++ b/ids/set.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/set_benchmark_test.go b/ids/set_benchmark_test.go index 18bf8a379b38..bc8d3099f8d1 100644 --- a/ids/set_benchmark_test.go +++ b/ids/set_benchmark_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/set_test.go b/ids/set_test.go index 35eeddf95cd0..da20772f77d4 100644 --- a/ids/set_test.go +++ b/ids/set_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/short.go b/ids/short.go index d54c24080c79..4a9e9254bed2 100644 --- a/ids/short.go +++ b/ids/short.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/short_bag.go b/ids/short_bag.go index aebee978c5e2..404b1bce9b03 100644 --- a/ids/short_bag.go +++ b/ids/short_bag.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/short_set.go b/ids/short_set.go index 7a1520bad8f1..fc44fdce8de3 100644 --- a/ids/short_set.go +++ b/ids/short_set.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/short_set_test.go b/ids/short_set_test.go index 31d2a009dc25..ad9115082070 100644 --- a/ids/short_set_test.go +++ b/ids/short_set_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/short_test.go b/ids/short_test.go index 957b093dacc0..1a85114fa130 100644 --- a/ids/short_test.go +++ b/ids/short_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/slice.go b/ids/slice.go index d38a66f7f738..812713d75047 100644 --- a/ids/slice.go +++ b/ids/slice.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/test_aliases.go b/ids/test_aliases.go index 4cb48463434a..728f9391f65d 100644 --- a/ids/test_aliases.go +++ b/ids/test_aliases.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/test_generator.go b/ids/test_generator.go index 3d5eda530397..cb6113595bc0 100644 --- a/ids/test_generator.go +++ b/ids/test_generator.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/unique_bag.go b/ids/unique_bag.go index 072eb625a8f7..a4383d984bfd 100644 --- a/ids/unique_bag.go +++ b/ids/unique_bag.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/ids/unique_bag_test.go b/ids/unique_bag_test.go index d8ba82544b76..d4b3ecf12fb2 100644 --- a/ids/unique_bag_test.go +++ b/ids/unique_bag_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ids diff --git a/indexer/client.go b/indexer/client.go index 2f0a51583468..4f125e0d10b0 100644 --- a/indexer/client.go +++ b/indexer/client.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package indexer diff --git a/indexer/client_test.go b/indexer/client_test.go index 4db92c1045aa..4b5cb2963104 100644 --- a/indexer/client_test.go +++ b/indexer/client_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package indexer diff --git a/indexer/container.go b/indexer/container.go index 7816257b5341..055089981684 100644 --- a/indexer/container.go +++ b/indexer/container.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package indexer diff --git a/indexer/index.go b/indexer/index.go index a3ba2756a73f..20fd0710f5c6 100644 --- a/indexer/index.go +++ b/indexer/index.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package indexer @@ -44,7 +44,7 @@ var ( // Index assumes that Accept is called before the container is committed to the // database of the VM that the container exists in. type Index interface { - Accept(ctx *snow.Context, containerID ids.ID, container []byte) error + Accept(ctx *snow.ConsensusContext, containerID ids.ID, container []byte) error GetContainerByIndex(index uint64) (Container, error) GetContainerRange(startIndex uint64, numToFetch uint64) ([]Container, error) GetLastAccepted() (Container, error) @@ -123,7 +123,7 @@ func (i *index) Close() error { // Index that the given transaction is accepted // Returned error should be treated as fatal; the VM should not commit [containerID] // or any new containers as accepted. -func (i *index) Accept(ctx *snow.Context, containerID ids.ID, containerBytes []byte) error { +func (i *index) Accept(ctx *snow.ConsensusContext, containerID ids.ID, containerBytes []byte) error { i.lock.Lock() defer i.lock.Unlock() diff --git a/indexer/index_test.go b/indexer/index_test.go index 446ad0ee60da..16841d0e69cf 100644 --- a/indexer/index_test.go +++ b/indexer/index_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package indexer @@ -27,7 +27,7 @@ func TestIndex(t *testing.T) { assert.NoError(err) baseDB := memdb.New() db := versiondb.New(baseDB) - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() indexIntf, err := newIndex(db, logging.NoLog{}, codec, mockable.Clock{}) assert.NoError(err) @@ -117,7 +117,7 @@ func TestIndexGetContainerByRangeMaxPageSize(t *testing.T) { err := codec.RegisterCodec(codecVersion, linearcodec.NewDefault()) assert.NoError(err) db := memdb.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() indexIntf, err := newIndex(db, logging.NoLog{}, codec, mockable.Clock{}) assert.NoError(err) idx := indexIntf.(*index) @@ -159,7 +159,7 @@ func TestDontIndexSameContainerTwice(t *testing.T) { err := codec.RegisterCodec(codecVersion, linearcodec.NewDefault()) assert.NoError(err) db := memdb.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() idx, err := newIndex(db, logging.NoLog{}, codec, mockable.Clock{}) assert.NoError(err) diff --git a/indexer/indexer.go b/indexer/indexer.go index fe9b6a116b37..bd9d713b3503 100644 --- a/indexer/indexer.go +++ b/indexer/indexer.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package indexer @@ -145,7 +145,7 @@ type indexer struct { } // Assumes [engine]'s context lock is not held -func (i *indexer) RegisterChain(name string, ctx *snow.Context, engine common.Engine) { +func (i *indexer) RegisterChain(name string, ctx *snow.ConsensusContext, engine common.Engine) { i.lock.Lock() defer i.lock.Unlock() diff --git a/indexer/indexer_test.go b/indexer/indexer_test.go index 4c209ea62af4..38f021292c6d 100644 --- a/indexer/indexer_test.go +++ b/indexer/indexer_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package indexer @@ -9,6 +9,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/ava-labs/avalanchego/database/memdb" "github.com/ava-labs/avalanchego/database/versiondb" "github.com/ava-labs/avalanchego/ids" @@ -18,14 +20,14 @@ import ( "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/snow/consensus/snowstorm" "github.com/ava-labs/avalanchego/snow/engine/avalanche/mocks" - avvtxmocks "github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex/mocks" "github.com/ava-labs/avalanchego/snow/engine/common" - smblockmocks "github.com/ava-labs/avalanchego/snow/engine/snowman/block/mocks" - smengmocks "github.com/ava-labs/avalanchego/snow/engine/snowman/mocks" "github.com/ava-labs/avalanchego/snow/triggers" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/logging" - "github.com/stretchr/testify/assert" + + avvtxmocks "github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex/mocks" + smblockmocks "github.com/ava-labs/avalanchego/snow/engine/snowman/block/mocks" + smengmocks "github.com/ava-labs/avalanchego/snow/engine/snowman/mocks" ) type apiServerMock struct { @@ -149,7 +151,7 @@ func TestIndexer(t *testing.T) { idxr.clock.Set(now) // Assert state is right - chain1Ctx := snow.DefaultContextTest() + chain1Ctx := snow.DefaultConsensusContextTest() chain1Ctx.ChainID = ids.GenerateTestID() isIncomplete, err := idxr.isIncomplete(chain1Ctx.ChainID) assert.NoError(err) @@ -266,7 +268,7 @@ func TestIndexer(t *testing.T) { assert.Equal(blkID, container.ID) // Register a DAG chain - chain2Ctx := snow.DefaultContextTest() + chain2Ctx := snow.DefaultConsensusContextTest() chain2Ctx.ChainID = ids.GenerateTestID() isIncomplete, err = idxr.isIncomplete(chain2Ctx.ChainID) assert.NoError(err) @@ -449,7 +451,7 @@ func TestIncompleteIndex(t *testing.T) { assert.False(idxr.indexingEnabled) // Register a chain - chain1Ctx := snow.DefaultContextTest() + chain1Ctx := snow.DefaultConsensusContextTest() chain1Ctx.ChainID = ids.GenerateTestID() isIncomplete, err := idxr.isIncomplete(chain1Ctx.ChainID) assert.NoError(err) @@ -503,7 +505,7 @@ func TestIncompleteIndex(t *testing.T) { config.DB = versiondb.New(baseDB) idxrIntf, err = NewIndexer(config) assert.NoError(err) - idxr, ok = idxrIntf.(*indexer) + _, ok = idxrIntf.(*indexer) assert.True(ok) } @@ -534,7 +536,7 @@ func TestIgnoreNonDefaultChains(t *testing.T) { assert.True(ok) // Assert state is right - chain1Ctx := snow.DefaultContextTest() + chain1Ctx := snow.DefaultConsensusContextTest() chain1Ctx.ChainID = ids.GenerateTestID() chain1Ctx.SubnetID = ids.GenerateTestID() diff --git a/indexer/service.go b/indexer/service.go index 2860a4dca264..67bedb85b5f0 100644 --- a/indexer/service.go +++ b/indexer/service.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package indexer diff --git a/ipcs/chainipc.go b/ipcs/chainipc.go index 9d16dc4929a7..5528a254048b 100644 --- a/ipcs/chainipc.go +++ b/ipcs/chainipc.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ipcs diff --git a/ipcs/eventsocket.go b/ipcs/eventsocket.go index 66dc62fe7398..656c54a05e8b 100644 --- a/ipcs/eventsocket.go +++ b/ipcs/eventsocket.go @@ -1,4 +1,4 @@ -// (c) 2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ipcs diff --git a/ipcs/socket/socket.go b/ipcs/socket/socket.go index 67bc213870b9..758e64c36b32 100644 --- a/ipcs/socket/socket.go +++ b/ipcs/socket/socket.go @@ -1,4 +1,4 @@ -// (c) 2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package socket diff --git a/ipcs/socket/socket_test.go b/ipcs/socket/socket_test.go index 78264a8ac94b..d947ee213882 100644 --- a/ipcs/socket/socket_test.go +++ b/ipcs/socket/socket_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package socket diff --git a/ipcs/socket/socket_unix.go b/ipcs/socket/socket_unix.go index ffe14f2d77ec..f9cb8986c32a 100644 --- a/ipcs/socket/socket_unix.go +++ b/ipcs/socket/socket_unix.go @@ -1,7 +1,7 @@ //go:build !windows && !plan9 && !js // +build !windows,!plan9,!js -// (c) 2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package socket diff --git a/ipcs/socket/socket_windows.go b/ipcs/socket/socket_windows.go index ed4973b3d389..ca37edbcec17 100644 --- a/ipcs/socket/socket_windows.go +++ b/ipcs/socket/socket_windows.go @@ -1,7 +1,7 @@ //go:build windows // +build windows -// (c) 2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package socket diff --git a/main/main.go b/main/main.go index c519327a5e8b..235fb30637d1 100644 --- a/main/main.go +++ b/main/main.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package main diff --git a/message/builder_test.go b/message/builder_test.go index 826b117d1dd3..6a9b6b4beac0 100644 --- a/message/builder_test.go +++ b/message/builder_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package message diff --git a/message/codec.go b/message/codec.go index 52ac8a23d7ea..20768ae046a9 100644 --- a/message/codec.go +++ b/message/codec.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package message diff --git a/message/codec_test.go b/message/codec_test.go index ed097dd781e6..c901bf6caf10 100644 --- a/message/codec_test.go +++ b/message/codec_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package message diff --git a/message/creator.go b/message/creator.go index 4c60d535ff96..9c567cfcbf9b 100644 --- a/message/creator.go +++ b/message/creator.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package message diff --git a/message/fields.go b/message/fields.go index b66d56624bb2..f4bf98082a3b 100644 --- a/message/fields.go +++ b/message/fields.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package message diff --git a/message/inbound_msg_builder.go b/message/inbound_msg_builder.go index 5d96fef2465c..ebc47ec45c50 100644 --- a/message/inbound_msg_builder.go +++ b/message/inbound_msg_builder.go @@ -1,3 +1,6 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + package message import ( diff --git a/message/internal_msg_builder.go b/message/internal_msg_builder.go index 18b3d7a0a44a..c0f428f7a383 100644 --- a/message/internal_msg_builder.go +++ b/message/internal_msg_builder.go @@ -1,3 +1,6 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + package message import ( diff --git a/message/messages.go b/message/messages.go index 7f09c58d661e..bba9fc0ccdff 100644 --- a/message/messages.go +++ b/message/messages.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package message diff --git a/message/ops.go b/message/ops.go index 34d756f6ab52..64b032c1b8d8 100644 --- a/message/ops.go +++ b/message/ops.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package message diff --git a/message/outbound_msg_builder.go b/message/outbound_msg_builder.go index 39c304fb883c..75ff0616f5ca 100644 --- a/message/outbound_msg_builder.go +++ b/message/outbound_msg_builder.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package message diff --git a/nat/nat.go b/nat/nat.go index 70d781a3d89d..7cd50bcff8fc 100644 --- a/nat/nat.go +++ b/nat/nat.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nat diff --git a/nat/no_router.go b/nat/no_router.go index 0fcb05ce0317..2e93039a0c1f 100644 --- a/nat/no_router.go +++ b/nat/no_router.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nat diff --git a/nat/pmp.go b/nat/pmp.go index 1488b29e1e5b..cf0790c1eeaa 100644 --- a/nat/pmp.go +++ b/nat/pmp.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nat diff --git a/nat/upnp.go b/nat/upnp.go index d8ed56762f86..ca824b3012d7 100644 --- a/nat/upnp.go +++ b/nat/upnp.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nat diff --git a/network/dialer/dialer.go b/network/dialer/dialer.go index f700861bb50b..a84bc1aad8c0 100644 --- a/network/dialer/dialer.go +++ b/network/dialer/dialer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package dialer diff --git a/network/dialer/dialer_test.go b/network/dialer/dialer_test.go index 6211192ac45f..bb0afaa087a4 100644 --- a/network/dialer/dialer_test.go +++ b/network/dialer/dialer_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package dialer diff --git a/network/health.go b/network/health.go index 728e08b26518..9037bad5da39 100644 --- a/network/health.go +++ b/network/health.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package network diff --git a/network/metrics.go b/network/metrics.go index 325a2f8caaf7..2d856c60abfb 100644 --- a/network/metrics.go +++ b/network/metrics.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package network @@ -77,16 +77,18 @@ func newMessageMetrics(op message.Op, namespace string, metrics prometheus.Regis } type metrics struct { - numPeers prometheus.Gauge - timeSinceLastMsgSent prometheus.Gauge - timeSinceLastMsgReceived prometheus.Gauge - sendQueuePortionFull prometheus.Gauge - sendFailRate prometheus.Gauge - failedToParse prometheus.Counter - connected prometheus.Counter - disconnected prometheus.Counter - inboundConnRateLimited prometheus.Counter - inboundConnAllowed prometheus.Counter + numPeers prometheus.Gauge + timeSinceLastMsgSent prometheus.Gauge + timeSinceLastMsgReceived prometheus.Gauge + sendQueuePortionFull prometheus.Gauge + sendFailRate prometheus.Gauge + failedToParse prometheus.Counter + connected prometheus.Counter + disconnected prometheus.Counter + inboundConnRateLimited prometheus.Counter + inboundConnAllowed prometheus.Counter + nodeUptimeWeightedAverage prometheus.Gauge + nodeUptimeRewardingStake prometheus.Gauge messageMetrics map[message.Op]*messageMetrics } @@ -140,7 +142,17 @@ func (m *metrics) initialize(namespace string, registerer prometheus.Registerer) m.inboundConnRateLimited = prometheus.NewCounter(prometheus.CounterOpts{ Namespace: namespace, Name: "inbound_conn_throttler_rate_limited", - Help: "Times this node rejected an inbound connection due to rate-limiting.", + Help: "Times this node rejected an inbound connection due to rate-limiting", + }) + m.nodeUptimeWeightedAverage = prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "node_uptime_weighted_average", + Help: "This node's uptime average weighted by observing peer stakes", + }) + m.nodeUptimeRewardingStake = prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "node_uptime_rewarding_stake", + Help: "The percentage of total stake which thinks this node is eligible for rewards", }) errs := wrappers.Errs{} @@ -155,6 +167,8 @@ func (m *metrics) initialize(namespace string, registerer prometheus.Registerer) registerer.Register(m.disconnected), registerer.Register(m.inboundConnAllowed), registerer.Register(m.inboundConnRateLimited), + registerer.Register(m.nodeUptimeWeightedAverage), + registerer.Register(m.nodeUptimeRewardingStake), ) m.messageMetrics = make(map[message.Op]*messageMetrics, len(message.ExternalOps)) diff --git a/network/network.go b/network/network.go index 2b70ec775af5..34f8d243f04c 100644 --- a/network/network.go +++ b/network/network.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package network @@ -17,6 +17,7 @@ import ( "time" cryptorand "crypto/rand" + gomath "math" "github.com/prometheus/client_golang/prometheus" @@ -89,10 +90,17 @@ type Network interface { // Return the IP of the node IP() utils.IPDesc + NodeUptime() (UptimeResult, bool) + // Has a health check health.Checkable } +type UptimeResult struct { + WeightedAveragePercentage float64 + RewardingStakePercentage float64 +} + type network struct { config *Config // The metrics that this network tracks @@ -128,7 +136,7 @@ type network struct { peers peersData // disconnectedIPs, connectedIPs, peerAliasIPs, and myIPs - // are maps with ip.String() keys that are used to determine if + // are maps with utils.IPDesc.String() keys that are used to determine if // we should attempt to dial an IP. [stateLock] should be held // whenever accessing one of these maps. disconnectedIPs map[string]struct{} // set of IPs we are attempting to connect to @@ -137,7 +145,7 @@ type network struct { // TODO: bound the size of [myIPs] to avoid DoS. LRU caching would be ideal myIPs map[string]struct{} // set of IPs that resulted in my ID. - // retryDelay is a map with ip.String() keys that is used to track + // retryDelay is a map with utils.IPDesc.String() keys that is used to track // the backoff delay we should wait before attempting to dial an IP address // again. retryDelay map[string]time.Duration @@ -241,8 +249,10 @@ type Config struct { WhitelistedSubnets ids.Set `json:"whitelistedSubnets"` Beacons validators.Set `json:"beacons"` // Current validators in the Avalanche network - Validators validators.Manager `json:"validators"` - UptimeCalculator uptime.Calculator `json:"-"` + Validators validators.Manager `json:"validators"` + UptimeCalculator uptime.Calculator `json:"-"` + UptimeMetricFreq time.Duration `json:"uptimeMetricFreq"` + UptimeRequirement float64 `json:"uptimeRequirement"` // Require that all connections must have at least one validator between the // 2 peers. This can be useful to enable if the node wants to connect to the @@ -362,7 +372,7 @@ func (n *network) Gossip( // Accept is called after every consensus decision // Assumes [n.stateLock] is not held. -func (n *network) Accept(ctx *snow.Context, containerID ids.ID, container []byte) error { +func (n *network) Accept(ctx *snow.ConsensusContext, containerID ids.ID, container []byte) error { if !ctx.IsBootstrapped() { // don't gossip during bootstrapping return nil @@ -372,7 +382,7 @@ func (n *network) Accept(ctx *snow.Context, containerID ids.ID, container []byte msg, err := n.mc.Put(ctx.ChainID, constants.GossipMsgRequestID, containerID, container) if err != nil { n.log.Debug("failed to build Put message for gossip (%s, %s): %s", ctx.ChainID, containerID, err) - n.log.Verbo("container:\n%s", formatting.DumpBytes{Bytes: container}) + n.log.Verbo("container:\n%s", formatting.DumpBytes(container)) n.sendFailRateCalculator.Observe(1, now) return fmt.Errorf("attempted to pack too large of a Put message.\nContainer length: %d", len(container)) } @@ -470,10 +480,11 @@ func (n *network) send(msg message.OutboundMessage, connectedOnly bool, peers [] // shouldUpgradeIncoming returns whether we should upgrade an incoming // connection from a peer at the IP whose string repr. is [ipStr]. // Assumes stateLock is not held. -func (n *network) shouldUpgradeIncoming(ipStr string) bool { +func (n *network) shouldUpgradeIncoming(ip utils.IPDesc) bool { n.stateLock.RLock() defer n.stateLock.RUnlock() + ipStr := ip.String() if _, ok := n.connectedIPs[ipStr]; ok { n.log.Debug("not upgrading connection to %s because it's connected", ipStr) return false @@ -486,7 +497,7 @@ func (n *network) shouldUpgradeIncoming(ipStr string) bool { n.log.Debug("not upgrading connection to %s because it's an alias", ipStr) return false } - if !n.inboundConnUpgradeThrottler.ShouldUpgrade(ipStr) { + if !n.inboundConnUpgradeThrottler.ShouldUpgrade(ip) { n.log.Debug("not upgrading connection to %s due to rate-limiting", ipStr) n.metrics.inboundConnRateLimited.Inc() return false @@ -514,7 +525,8 @@ func (n *network) shouldHoldConnection(peerID ids.ShortID) bool { // to this node. // Assumes [n.stateLock] is not held. func (n *network) Dispatch() error { - go n.gossipPeerList() // Periodically gossip peers + go n.gossipPeerList() // Periodically gossip peers + go n.updateUptimeMetrics() // Periodically update uptime metrics go n.inboundConnUpgradeThrottler.Dispatch() defer n.inboundConnUpgradeThrottler.Stop() go func() { @@ -565,8 +577,7 @@ func (n *network) Dispatch() error { if err != nil { return fmt.Errorf("unable to convert remote address %s to IPDesc: %w", remoteAddr, err) } - ipStr := ip.IP.String() - upgrade := n.shouldUpgradeIncoming(ipStr) + upgrade := n.shouldUpgradeIncoming(ip) if !upgrade { _ = conn.Close() continue @@ -688,6 +699,60 @@ func (n *network) IP() utils.IPDesc { return n.currentIP.IP() } +func (n *network) NodeUptime() (UptimeResult, bool) { + n.stateLock.RLock() + defer n.stateLock.RUnlock() + primaryValidators, ok := n.config.Validators.GetValidators(constants.PrimaryNetworkID) + if !ok { + return UptimeResult{}, false + } + + myStake, isValidator := primaryValidators.GetWeight(n.config.MyNodeID) + if !isValidator { + return UptimeResult{}, false + } + + var ( + totalWeight = float64(primaryValidators.Weight()) + totalWeightedPercent = 100 * float64(myStake) + rewardingStake = float64(myStake) + ) + for _, peer := range n.peers.peersList { + weight, ok := primaryValidators.GetWeight(peer.nodeID) + if !ok { + // this is not a validator skip it. + continue + } + + if !peer.finishedHandshake.GetValue() { + continue + } + + weightFloat := float64(weight) + + peerVersion := peer.versionStruct.GetValue().(version.Application) + if peerVersion.Before(version.MinUptimeVersion) { + // If the peer is running an earlier version, then ignore their + // stake + totalWeight -= weightFloat + continue + } + + percent := float64(peer.observedUptime) + totalWeightedPercent += percent * weightFloat + + // if this peer thinks we're above requirement add the weight + if percent/100 >= n.config.UptimeRequirement { + rewardingStake += weightFloat + } + } + + return UptimeResult{ + WeightedAveragePercentage: gomath.Abs(totalWeightedPercent / totalWeight), + RewardingStakePercentage: gomath.Abs(100 * rewardingStake / totalWeight), + }, true +} + // assumes the stateLock is held. // Try to connect to [nodeID] at [ip]. func (n *network) track(ip utils.IPDesc, nodeID ids.ShortID) { @@ -756,6 +821,21 @@ func (n *network) gossipPeerList() { } } +// Assumes [n.stateLock] is not held. Only returns after the network is closed. +func (n *network) updateUptimeMetrics() { + t := time.NewTicker(n.config.UptimeMetricFreq) + defer t.Stop() + + for range t.C { + if n.closed.GetValue() { + return + } + result, _ := n.NodeUptime() + n.metrics.nodeUptimeWeightedAverage.Set(result.WeightedAveragePercentage) + n.metrics.nodeUptimeRewardingStake.Set(result.RewardingStakePercentage) + } +} + // Returns when: // * We connected to [ip] // * The network is closed diff --git a/network/network_test.go b/network/network_test.go index 34cdb8e916ec..d10da07744a2 100644 --- a/network/network_test.go +++ b/network/network_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package network @@ -3203,5 +3203,6 @@ func newDefaultConfig() Config { MaxClockDifference: time.Minute, AllowPrivateIPs: true, PingFrequency: constants.DefaultPingFrequency, + UptimeMetricFreq: 30 * time.Second, } } diff --git a/network/peer.go b/network/peer.go index 125f3489d838..32d7807da1f8 100644 --- a/network/peer.go +++ b/network/peer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package network @@ -291,12 +291,12 @@ func (p *peer) ReadMessages() { return } - p.net.log.Verbo("parsing message from %s%s at %s:\n%s", constants.NodeIDPrefix, p.nodeID, p.getIP(), formatting.DumpBytes{Bytes: msgBytes}) + p.net.log.Verbo("parsing message from %s%s at %s:\n%s", constants.NodeIDPrefix, p.nodeID, p.getIP(), formatting.DumpBytes(msgBytes)) // Parse the message msg, err := p.net.mc.Parse(msgBytes, p.nodeID, onFinishedHandling) if err != nil { - p.net.log.Verbo("failed to parse message from %s%s at %s:\n%s\n%s", constants.NodeIDPrefix, p.nodeID, p.getIP(), formatting.DumpBytes{Bytes: msgBytes}, err) + p.net.log.Verbo("failed to parse message from %s%s at %s:\n%s\n%s", constants.NodeIDPrefix, p.nodeID, p.getIP(), formatting.DumpBytes(msgBytes), err) // Couldn't parse the message. Read the next one. onFinishedHandling() p.net.metrics.failedToParse.Inc() @@ -336,7 +336,7 @@ func (p *peer) WriteMessages() { msgLen := uint32(len(msg.Bytes())) p.net.outboundMsgThrottler.Release(uint64(msgLen), p.nodeID) - p.net.log.Verbo("sending message to %s%s at %s:\n%s", constants.NodeIDPrefix, p.nodeID, p.getIP(), formatting.DumpBytes{Bytes: msg.Bytes()}) + p.net.log.Verbo("sending message to %s%s at %s:\n%s", constants.NodeIDPrefix, p.nodeID, p.getIP(), formatting.DumpBytes(msg.Bytes())) msgb := [wrappers.IntLen]byte{} binary.BigEndian.PutUint32(msgb[:], msgLen) for _, byteSlice := range [2][]byte{msgb[:], msg.Bytes()} { @@ -351,8 +351,8 @@ func (p *peer) WriteMessages() { msg.DecRef() return } - p.tickerOnce.Do(p.StartTicker) } + p.tickerOnce.Do(p.StartTicker) // Make sure the peer got the entire message if err := writer.Flush(); err != nil { p.net.log.Verbo("couldn't flush writer to %s%s at %s: %s", constants.NodeIDPrefix, p.nodeID, p.getIP(), err) @@ -855,7 +855,10 @@ func (p *peer) pongHandle(msg message.InboundMessage, isUptime bool) { p.net.log.Debug("disconnecting from peer %s%s at %s version (%s) not compatible: %s", constants.NodeIDPrefix, p.nodeID, p.getIP(), peerVersion, err) p.discardIP() } - if isUptime { + if isUptime && + // if the peer or this node is not a validator, we don't need their uptime. + p.net.config.Validators.Contains(constants.PrimaryNetworkID, p.nodeID) && + p.net.config.Validators.Contains(constants.PrimaryNetworkID, p.net.config.MyNodeID) { uptime := msg.Get(message.Uptime).(uint8) if uptime <= 100 { p.observedUptime = uptime // [0, 100] percentage diff --git a/network/peer_info.go b/network/peer_info.go index a6ebfdff3283..5f62eb8e4629 100644 --- a/network/peer_info.go +++ b/network/peer_info.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package network diff --git a/network/peer_test.go b/network/peer_test.go index 8dcf6f66330a..66a2403972df 100644 --- a/network/peer_test.go +++ b/network/peer_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package network diff --git a/network/peers_data.go b/network/peers_data.go index 30d235976dfe..c11c0604b8cb 100644 --- a/network/peers_data.go +++ b/network/peers_data.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package network diff --git a/network/peers_data_test.go b/network/peers_data_test.go index 3bf9b47c90ea..dec5495ca202 100644 --- a/network/peers_data_test.go +++ b/network/peers_data_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package network diff --git a/network/throttling/bandwidth_throttler.go b/network/throttling/bandwidth_throttler.go index 08acdb840439..a84b463de023 100644 --- a/network/throttling/bandwidth_throttler.go +++ b/network/throttling/bandwidth_throttler.go @@ -1,3 +1,6 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + package throttling import ( diff --git a/network/throttling/bandwidth_throttler_test.go b/network/throttling/bandwidth_throttler_test.go index 7c72240dcd91..7a2a51f15629 100644 --- a/network/throttling/bandwidth_throttler_test.go +++ b/network/throttling/bandwidth_throttler_test.go @@ -1,3 +1,6 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + package throttling import ( diff --git a/network/throttling/common.go b/network/throttling/common.go index da1082594365..11c9b83b8734 100644 --- a/network/throttling/common.go +++ b/network/throttling/common.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling diff --git a/network/throttling/dial_throttler.go b/network/throttling/dial_throttler.go index 669655e20b7f..442391829f1e 100644 --- a/network/throttling/dial_throttler.go +++ b/network/throttling/dial_throttler.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling diff --git a/network/throttling/dial_throttler_test.go b/network/throttling/dial_throttler_test.go index a4ab04739417..e3d4ce2fffe5 100644 --- a/network/throttling/dial_throttler_test.go +++ b/network/throttling/dial_throttler_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling diff --git a/network/throttling/inbound_conn_throttler.go b/network/throttling/inbound_conn_throttler.go index 709d3adca420..47550b919e37 100644 --- a/network/throttling/inbound_conn_throttler.go +++ b/network/throttling/inbound_conn_throttler.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling diff --git a/network/throttling/inbound_conn_throttler_test.go b/network/throttling/inbound_conn_throttler_test.go index b533c3a94c05..9febb66d89aa 100644 --- a/network/throttling/inbound_conn_throttler_test.go +++ b/network/throttling/inbound_conn_throttler_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling diff --git a/network/throttling/inbound_conn_upgrade_throttler.go b/network/throttling/inbound_conn_upgrade_throttler.go index 582d739eee26..99dcf79f5cc9 100644 --- a/network/throttling/inbound_conn_upgrade_throttler.go +++ b/network/throttling/inbound_conn_upgrade_throttler.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling @@ -7,6 +7,7 @@ import ( "sync" "time" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" ) @@ -32,8 +33,9 @@ type InboundConnUpgradeThrottler interface { Stop() // Returns whether we should upgrade an inbound connection from [ipStr]. // Must only be called after [Dispatch] has been called. + // If [ip] is a local IP, this method always returns true. // Must not be called after [Stop] has been called. - ShouldUpgrade(ipStr string) bool + ShouldUpgrade(ip utils.IPDesc) bool } type InboundConnUpgradeThrottlerConfig struct { @@ -67,9 +69,9 @@ func NewInboundConnUpgradeThrottler(log logging.Logger, config InboundConnUpgrad // noInboundConnUpgradeThrottler upgrades all inbound connections type noInboundConnUpgradeThrottler struct{} -func (*noInboundConnUpgradeThrottler) Dispatch() {} -func (*noInboundConnUpgradeThrottler) Stop() {} -func (*noInboundConnUpgradeThrottler) ShouldUpgrade(string) bool { return true } +func (*noInboundConnUpgradeThrottler) Dispatch() {} +func (*noInboundConnUpgradeThrottler) Stop() {} +func (*noInboundConnUpgradeThrottler) ShouldUpgrade(utils.IPDesc) bool { return true } type ipAndTime struct { ip string @@ -96,7 +98,14 @@ type inboundConnUpgradeThrottler struct { } // Returns whether we should upgrade an inbound connection from [ipStr]. -func (n *inboundConnUpgradeThrottler) ShouldUpgrade(ipStr string) bool { +func (n *inboundConnUpgradeThrottler) ShouldUpgrade(ip utils.IPDesc) bool { + if ip.IsPrivate() { + // Don't rate-limit private (local) IPs + return true + } + // Only use IP (not port). This mitigates DoS + // attacks from many nodes on one host. + ipStr := ip.IP.String() n.lock.Lock() defer n.lock.Unlock() diff --git a/network/throttling/inbound_conn_upgrade_throttler_test.go b/network/throttling/inbound_conn_upgrade_throttler_test.go index 955b4060073b..ba2544c365a7 100644 --- a/network/throttling/inbound_conn_upgrade_throttler_test.go +++ b/network/throttling/inbound_conn_upgrade_throttler_test.go @@ -1,21 +1,24 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling import ( + "net" "testing" "time" + "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/logging" "github.com/stretchr/testify/assert" ) -const ( - host1 = "127.0.0.1" - host2 = "127.0.0.2" - host3 = "127.0.0.3" - host4 = "127.0.0.4" +var ( + host1 = utils.IPDesc{IP: net.IPv4(1, 2, 3, 4), Port: 9651} + host2 = utils.IPDesc{IP: net.IPv4(1, 2, 3, 5), Port: 9653} + host3 = utils.IPDesc{IP: net.IPv4(1, 2, 3, 6), Port: 9655} + host4 = utils.IPDesc{IP: net.IPv4(1, 2, 3, 7), Port: 9657} + localhost = utils.IPDesc{IP: net.IPv4(127, 0, 0, 1), Port: 9657} ) func TestNoInboundConnUpgradeThrottler(t *testing.T) { @@ -76,6 +79,13 @@ func TestInboundConnUpgradeThrottler(t *testing.T) { assert.False(throttlerIntf.ShouldUpgrade(host2)) assert.False(throttlerIntf.ShouldUpgrade(host3)) + // Local host should never be rate-limited + assert.True(throttlerIntf.ShouldUpgrade(localhost)) + assert.True(throttlerIntf.ShouldUpgrade(localhost)) + assert.True(throttlerIntf.ShouldUpgrade(localhost)) + assert.True(throttlerIntf.ShouldUpgrade(localhost)) + assert.True(throttlerIntf.ShouldUpgrade(localhost)) + // Make sure [throttler.done] isn't closed throttler := throttlerIntf.(*inboundConnUpgradeThrottler) select { diff --git a/network/throttling/inbound_msg_buffer_throttler.go b/network/throttling/inbound_msg_buffer_throttler.go index 1dad6340b3e0..320e270ba6d7 100644 --- a/network/throttling/inbound_msg_buffer_throttler.go +++ b/network/throttling/inbound_msg_buffer_throttler.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling diff --git a/network/throttling/inbound_msg_buffer_throttler_test.go b/network/throttling/inbound_msg_buffer_throttler_test.go index 23d3045c267e..3d06f3bdee9c 100644 --- a/network/throttling/inbound_msg_buffer_throttler_test.go +++ b/network/throttling/inbound_msg_buffer_throttler_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling diff --git a/network/throttling/inbound_msg_byte_throttler.go b/network/throttling/inbound_msg_byte_throttler.go index bd0de1a38f71..4490b3709d10 100644 --- a/network/throttling/inbound_msg_byte_throttler.go +++ b/network/throttling/inbound_msg_byte_throttler.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling diff --git a/network/throttling/inbound_msg_byte_throttler_test.go b/network/throttling/inbound_msg_byte_throttler_test.go index 452dd5361a04..35413d895987 100644 --- a/network/throttling/inbound_msg_byte_throttler_test.go +++ b/network/throttling/inbound_msg_byte_throttler_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling diff --git a/network/throttling/inbound_msg_throttler.go b/network/throttling/inbound_msg_throttler.go index 251e647cb02b..e7b3e265fb2c 100644 --- a/network/throttling/inbound_msg_throttler.go +++ b/network/throttling/inbound_msg_throttler.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling diff --git a/network/throttling/no_inbound_msg_throttler.go b/network/throttling/no_inbound_msg_throttler.go index 56363126162d..345908e6af40 100644 --- a/network/throttling/no_inbound_msg_throttler.go +++ b/network/throttling/no_inbound_msg_throttler.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling diff --git a/network/throttling/outbound_msg_throttler.go b/network/throttling/outbound_msg_throttler.go index e33a64a58058..15a41087535d 100644 --- a/network/throttling/outbound_msg_throttler.go +++ b/network/throttling/outbound_msg_throttler.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling diff --git a/network/throttling/outbound_msg_throttler_test.go b/network/throttling/outbound_msg_throttler_test.go index c19815b5d3d8..137c3e676620 100644 --- a/network/throttling/outbound_msg_throttler_test.go +++ b/network/throttling/outbound_msg_throttler_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package throttling diff --git a/network/tls_config.go b/network/tls_config.go index ac6b041fcf00..c8483d1303cc 100644 --- a/network/tls_config.go +++ b/network/tls_config.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package network diff --git a/network/upgrader.go b/network/upgrader.go index 83dfb36b621e..adae67abc3b3 100644 --- a/network/upgrader.go +++ b/network/upgrader.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package network diff --git a/node/config.go b/node/config.go index 51db2ea313b9..91de1a4aea66 100644 --- a/node/config.go +++ b/node/config.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package node @@ -126,7 +126,6 @@ type Config struct { IPConfig `json:"ipConfig"` StakingConfig `json:"stakingConfig"` genesis.TxFeeConfig `json:"txFeeConfig"` - genesis.EpochConfig `json:"epochConfig"` BootstrapConfig `json:"bootstrapConfig"` DatabaseConfig `json:"databaseConfig"` diff --git a/node/node.go b/node/node.go index 764d5eefd6e4..c55cade1ec69 100644 --- a/node/node.go +++ b/node/node.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package node @@ -15,7 +15,9 @@ import ( "sync" "github.com/hashicorp/go-plugin" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/ava-labs/avalanchego/api/admin" "github.com/ava-labs/avalanchego/api/auth" @@ -155,6 +157,7 @@ type Node struct { // Metrics Registerer MetricsRegisterer *prometheus.Registry + MetricsGatherer metrics.MultiGatherer } /* @@ -254,6 +257,7 @@ func (n *Node) initNetworking() error { n.Config.NetworkConfig.TLSKey = tlsKey n.Config.NetworkConfig.WhitelistedSubnets = n.Config.WhitelistedSubnets n.Config.NetworkConfig.UptimeCalculator = n.uptimeCalculator + n.Config.NetworkConfig.UptimeRequirement = n.Config.UptimeRequirement n.Net, err = network.NewNetwork( &n.Config.NetworkConfig, @@ -579,14 +583,12 @@ func (n *Node) initChainManager(avaxAssetID ids.ID) error { cChainID, ) - requestsNamespace := fmt.Sprintf("%s_requests", constants.PlatformName) - // Manages network timeouts timeoutManager := &timeout.Manager{} if err := timeoutManager.Initialize( &n.Config.AdaptiveTimeoutConfig, n.benchlistManager, - requestsNamespace, + "requests", n.MetricsRegisterer, ); err != nil { return err @@ -604,7 +606,7 @@ func (n *Node) initChainManager(avaxAssetID ids.ID) error { criticalChains, n.Shutdown, n.Config.RouterHealthConfig, - requestsNamespace, + "requests", n.MetricsRegisterer, ) if err != nil { @@ -631,8 +633,6 @@ func (n *Node) initChainManager(avaxAssetID ids.ID) error { Router: n.Config.ConsensusRouter, Net: n.Net, ConsensusParams: n.Config.ConsensusParams, - EpochFirstTransition: n.Config.EpochFirstTransition, - EpochDuration: n.Config.EpochDuration, Validators: n.vdrs, NodeID: n.ID, NetworkID: n.Config.NetworkID, @@ -649,6 +649,7 @@ func (n *Node) initChainManager(avaxAssetID ids.ID) error { RetryBootstrapWarnFrequency: n.Config.RetryBootstrapWarnFrequency, ShutdownNodeFunc: n.Shutdown, MeterVMEnabled: n.Config.MeterVMEnabled, + Metrics: n.MetricsGatherer, SubnetConfigs: n.Config.SubnetConfigs, ChainConfigs: n.Config.ChainConfigs, AppGossipValidatorSize: int(n.Config.NetworkConfig.AppGossipValidatorSize), @@ -693,6 +694,7 @@ func (n *Node) initChainManager(avaxAssetID ids.ID) error { StakeMintingPeriod: n.Config.StakeMintingPeriod, ApricotPhase3Time: version.GetApricotPhase3Time(n.Config.NetworkID), ApricotPhase4Time: version.GetApricotPhase4Time(n.Config.NetworkID), + ApricotPhase5Time: version.GetApricotPhase5Time(n.Config.NetworkID), }), n.vmManager.RegisterFactory(avm.ID, &avm.Factory{ TxFee: n.Config.TxFee, @@ -786,29 +788,39 @@ func (n *Node) initKeystoreAPI() error { // initMetricsAPI initializes the Metrics API // Assumes n.APIServer is already set func (n *Node) initMetricsAPI() error { - registry, handler := metrics.NewService() - // It is assumed by components of the system that the Metrics interface is - // non-nil. So, it is set regardless of if the metrics API is available or not. - n.MetricsRegisterer = registry - - // TODO: remove metrics field from consensus params. - n.Config.ConsensusParams.Metrics = n.MetricsRegisterer + n.MetricsRegisterer = prometheus.NewRegistry() + n.MetricsGatherer = metrics.NewMultiGatherer() if !n.Config.MetricsAPIEnabled { n.Log.Info("skipping metrics API initialization because it has been disabled") return nil } + if err := n.MetricsGatherer.Register(constants.PlatformName, n.MetricsRegisterer); err != nil { + return err + } + n.Log.Info("initializing metrics API") - dbNamespace := fmt.Sprintf("%s_db", constants.PlatformName) - meterDBManager, err := n.DBManager.NewMeterDBManager(dbNamespace, registry) + meterDBManager, err := n.DBManager.NewMeterDBManager("db", n.MetricsRegisterer) if err != nil { return err } n.DBManager = meterDBManager - return n.APIServer.AddRoute(handler, &sync.RWMutex{}, "metrics", "", n.HTTPLog) + return n.APIServer.AddRoute( + &common.HTTPHandler{ + LockOptions: common.NoLock, + Handler: promhttp.HandlerFor( + n.MetricsGatherer, + promhttp.HandlerOpts{}, + ), + }, + &sync.RWMutex{}, + "metrics", + "", + n.HTTPLog, + ) } // initAdminAPI initializes the Admin API service @@ -881,7 +893,6 @@ func (n *Node) initInfoAPI() error { CreateAssetTxFee: n.Config.CreateAssetTxFee, CreateSubnetTxFee: n.Config.CreateSubnetTxFee, CreateBlockchainTxFee: n.Config.CreateBlockchainTxFee, - UptimeRequirement: n.Config.UptimeRequirement, }, n.Log, n.chainManager, @@ -909,7 +920,7 @@ func (n *Node) initHealthAPI() error { healthService, err := health.NewService( n.Config.HealthCheckFreq, n.Log, - fmt.Sprintf("%s_health", constants.PlatformName), + "health", n.MetricsRegisterer, ) if err != nil { @@ -1083,7 +1094,7 @@ func (n *Node) Initialize( // It must be initiated before networking (initNetworking), chain manager (initChainManager) // and the engine (initChains) but after the metrics (initMetricsAPI) // message.Creator currently record metrics under network namespace - n.networkNamespace = fmt.Sprintf("%s_network", constants.PlatformName) + n.networkNamespace = "network" if n.msgCreator, err = message.NewCreator(n.MetricsRegisterer, n.Config.NetworkConfig.CompressionEnabled, n.networkNamespace); err != nil { diff --git a/pubsub/connection.go b/pubsub/connection.go index 23c7c2d1c545..9682ef472679 100644 --- a/pubsub/connection.go +++ b/pubsub/connection.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package pubsub diff --git a/pubsub/connections.go b/pubsub/connections.go index 9fc332576cd7..831d14ba538d 100644 --- a/pubsub/connections.go +++ b/pubsub/connections.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package pubsub diff --git a/pubsub/filter_param.go b/pubsub/filter_param.go index 6cbbfeb5a405..b4d1096facd8 100644 --- a/pubsub/filter_param.go +++ b/pubsub/filter_param.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package pubsub diff --git a/pubsub/filter_test.go b/pubsub/filter_test.go index 04c77c0e1c89..2760fc16f80d 100644 --- a/pubsub/filter_test.go +++ b/pubsub/filter_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package pubsub diff --git a/pubsub/filterer.go b/pubsub/filterer.go index 752387666a92..adb59ca28b85 100644 --- a/pubsub/filterer.go +++ b/pubsub/filterer.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package pubsub diff --git a/pubsub/messages.go b/pubsub/messages.go index 9f5074c8b488..5c1f3b311687 100644 --- a/pubsub/messages.go +++ b/pubsub/messages.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package pubsub diff --git a/pubsub/server.go b/pubsub/server.go index 61357bbe7baa..58058d074b2e 100644 --- a/pubsub/server.go +++ b/pubsub/server.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package pubsub diff --git a/scripts/lint.sh b/scripts/lint.sh index 9f5b958e4625..4672312aa003 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -1,7 +1,75 @@ #!/usr/bin/env bash set -o errexit -set -o nounset set -o pipefail +set -e -golangci-lint run --max-same-issues=0 --timeout=2m +if ! [[ "$0" =~ scripts/lint.sh ]]; then + echo "must be run from repository root" + exit 255 +fi + +if [ "$#" -eq 0 ]; then + # by default, check all source code + # to test only "snow" package + # ./scripts/lint.sh ./snow/... + TARGET="./..." +else + TARGET="${1}" +fi + +# by default, "./scripts/lint.sh" runs all lint tests +# to run only "license_header" test +# TESTS='license_header' ./scripts/lint.sh +TESTS=${TESTS:-"golangci_lint license_header"} + +function test_golangci_lint { + golangci-lint run --max-same-issues=0 --timeout=2m +} + +# find_go_files [package] +# all go files except generated ones +function find_go_files { + local target="${1}" + go fmt -n "${target}" | grep -Eo "([^ ]*)$" | grep -vE "(\\.pb\\.go|\\.pb\\.gw.go)" +} + +# automatically checks license headers +# to modify the file headers (if missing), remove "--check" flag +# TESTS='license_header' ADDLICENSE_FLAGS="-v" ./scripts/lint.sh +_addlicense_flags=${ADDLICENSE_FLAGS:-"--check -v"} +function test_license_header { + go install -v github.com/google/addlicense@latest + local target="${1}" + local files=() + while IFS= read -r line; do files+=("$line"); done < <(find_go_files "${target}") + + # ignore 3rd party code + addlicense \ + -f ./LICENSE.header \ + ${_addlicense_flags} \ + --ignore 'utils/ip_test.go' \ + --ignore 'utils/logging/highlight.go' \ + --ignore 'utils/ulimit/ulimit_non_unix.go.go' \ + --ignore 'utils/ulimit/ulimit_unix.go' \ + "${files[@]}" +} + +function run { + local test="${1}" + shift 1 + echo "START: '${test}' at $(date)" + if "test_${test}" "$@" ; then + echo "SUCCESS: '${test}' completed at $(date)" + else + echo "FAIL: '${test}' failed at $(date)" + exit 255 + fi +} + +echo "Running '$TESTS' at: $(date)" +for test in $TESTS; do + run "${test}" "${TARGET}" +done + +echo "ALL SUCCESS!" diff --git a/scripts/protobuf_codegen.sh b/scripts/protobuf_codegen.sh index 0bb93d83588d..ccc81599b0ad 100755 --- a/scripts/protobuf_codegen.sh +++ b/scripts/protobuf_codegen.sh @@ -1,18 +1,29 @@ #!/bin/bash -TARGET=$PWD +if ! [[ "$0" =~ scripts/protobuf_codegen.sh ]]; then + echo "must be run from repository root" + exit 255 +fi +TARGET=$PWD if [ -n "$1" ]; then TARGET="$1" fi echo "Re-genrating protobuf for target directory: $TARGET" -for PROTO_BUFFER_FILE in $(find $TARGET -type f | grep proto$) +# go module does not download the actual "io/prometheus/client/metrics.proto" file +# manually download using git +PROMETHEUS_PATH=/tmp/client_model +rm -rf ${PROMETHEUS_PATH} +git clone --quiet -b v0.2.0 https://github.com/prometheus/client_model.git ${PROMETHEUS_PATH} + +for PROTO_BUFFER_FILE in $(find $TARGET -type f ! -path '*/.git/*' | grep proto$) do echo "Re-generating protobuf: $PROTO_BUFFER_FILE" PROTO_FILE_DIR=$(dirname $PROTO_BUFFER_FILE) protoc \ + --proto_path="$PROMETHEUS_PATH" \ -I="$PROTO_FILE_DIR" \ --go_out="$PROTO_FILE_DIR" \ --go-grpc_out="$PROTO_FILE_DIR" \ @@ -25,3 +36,5 @@ do echo "protobuf codegen succeed for $PROTO_BUFFER_FILE" fi done + +rm -rf ${PROMETHEUS_PATH} diff --git a/scripts/versions.sh b/scripts/versions.sh index d1c9b1aefbe4..5b664044fe4f 100644 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -7,4 +7,4 @@ # Set up the versions to be used # Don't export them as their used in the context of other calls -coreth_version=${CORETH_VERSION:-'v0.7.4-rc.1'} +coreth_version=${CORETH_VERSION:-'v0.8.0-rc.2'} diff --git a/snow/choices/decidable.go b/snow/choices/decidable.go index 8beacba055a1..10ad6dcf6a25 100644 --- a/snow/choices/decidable.go +++ b/snow/choices/decidable.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package choices diff --git a/snow/choices/status.go b/snow/choices/status.go index 104797ef056a..e9a972d36419 100644 --- a/snow/choices/status.go +++ b/snow/choices/status.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package choices diff --git a/snow/choices/status_test.go b/snow/choices/status_test.go index da5c4dae3d0a..97369901ca92 100644 --- a/snow/choices/status_test.go +++ b/snow/choices/status_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package choices diff --git a/snow/choices/test_decidable.go b/snow/choices/test_decidable.go index c81286133764..36a34fd9dcf1 100644 --- a/snow/choices/test_decidable.go +++ b/snow/choices/test_decidable.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package choices diff --git a/snow/consensus/avalanche/consensus.go b/snow/consensus/avalanche/consensus.go index bdbde9b978c4..4693400676bc 100644 --- a/snow/consensus/avalanche/consensus.go +++ b/snow/consensus/avalanche/consensus.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche @@ -23,7 +23,7 @@ type Consensus interface { // called, the status maps should be immediately updated accordingly. // Assumes each element in the accepted frontier will return accepted from // the join status map. - Initialize(*snow.Context, Parameters, []Vertex) error + Initialize(*snow.ConsensusContext, Parameters, []Vertex) error // Returns the parameters that describe this avalanche instance Parameters() Parameters diff --git a/snow/consensus/avalanche/consensus_test.go b/snow/consensus/avalanche/consensus_test.go index 87587363d5e4..0dff4b156887 100644 --- a/snow/consensus/avalanche/consensus_test.go +++ b/snow/consensus/avalanche/consensus_test.go @@ -1,11 +1,10 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche import ( "errors" - "fmt" "math" "path" "reflect" @@ -20,7 +19,6 @@ import ( "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/snowball" "github.com/ava-labs/avalanchego/snow/consensus/snowstorm" - "github.com/ava-labs/avalanchego/utils/constants" ) type testFunc func(*testing.T, Factory) @@ -63,14 +61,12 @@ func getTestName(i interface{}) string { } func MetricsTest(t *testing.T, factory Factory) { - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() { avl := factory.New() params := Parameters{ Parameters: snowball.Parameters{ - Namespace: fmt.Sprintf("%s_%s", constants.PlatformName, ctx.ChainID), - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -81,9 +77,8 @@ func MetricsTest(t *testing.T, factory Factory) { Parents: 2, BatchSize: 1, } - err := params.Metrics.Register(prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: params.Namespace, - Name: "vtx_processing", + err := ctx.Registerer.Register(prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "vtx_processing", })) if err != nil { t.Fatal(err) @@ -96,8 +91,6 @@ func MetricsTest(t *testing.T, factory Factory) { avl := factory.New() params := Parameters{ Parameters: snowball.Parameters{ - Namespace: fmt.Sprintf("%s_%s", constants.PlatformName, ctx.ChainID), - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -108,9 +101,8 @@ func MetricsTest(t *testing.T, factory Factory) { Parents: 2, BatchSize: 1, } - err := params.Metrics.Register(prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: params.Namespace, - Name: "vtx_accepted", + err := ctx.Registerer.Register(prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "vtx_accepted", })) if err != nil { t.Fatal(err) @@ -123,8 +115,6 @@ func MetricsTest(t *testing.T, factory Factory) { avl := factory.New() params := Parameters{ Parameters: snowball.Parameters{ - Namespace: fmt.Sprintf("%s_%s", constants.PlatformName, ctx.ChainID), - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -135,9 +125,8 @@ func MetricsTest(t *testing.T, factory Factory) { Parents: 2, BatchSize: 1, } - err := params.Metrics.Register(prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: params.Namespace, - Name: "vtx_rejected", + err := ctx.Registerer.Register(prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "vtx_rejected", })) if err != nil { t.Fatal(err) @@ -151,11 +140,9 @@ func MetricsTest(t *testing.T, factory Factory) { func ParamsTest(t *testing.T, factory Factory) { avl := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := Parameters{ Parameters: snowball.Parameters{ - Namespace: fmt.Sprintf("%s_%s", constants.PlatformName, ctx.ChainID), - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -193,7 +180,6 @@ func NumProcessingTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -218,7 +204,7 @@ func NumProcessingTest(t *testing.T, factory Factory) { } utxos := []ids.ID{ids.GenerateTestID()} - if err := avl.Initialize(snow.DefaultContextTest(), params, vts); err != nil { + if err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts); err != nil { t.Fatal(err) } @@ -306,7 +292,6 @@ func AddTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -319,98 +304,128 @@ func AddTest(t *testing.T, factory Factory) { Parents: 2, BatchSize: 1, } - vts := []Vertex{ - &TestVertex{TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Accepted, - }}, - &TestVertex{TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Accepted, - }}, + + seedVertices := []Vertex{ + &TestVertex{ + TestDecidable: choices.TestDecidable{ + IDV: ids.GenerateTestID(), + StatusV: choices.Accepted, + }, + }, + &TestVertex{ + TestDecidable: choices.TestDecidable{ + IDV: ids.GenerateTestID(), + StatusV: choices.Accepted, + }, + }, } - utxos := []ids.ID{ids.GenerateTestID()} - if err := avl.Initialize(snow.DefaultContextTest(), params, vts); err != nil { + ctx := snow.DefaultConsensusContextTest() + // track consensus events to ensure idempotency in case of redundant vertex adds + consensusEvents := snow.NewEventDispatcherTracker() + ctx.ConsensusDispatcher = consensusEvents + + if err := avl.Initialize(ctx, params, seedVertices); err != nil { t.Fatal(err) } if !avl.Finalized() { - t.Fatalf("An empty avalanche instance is not finalized") - } else if !ids.UnsortedEquals([]ids.ID{vts[0].ID(), vts[1].ID()}, avl.Preferences().List()) { - t.Fatalf("Initial frontier failed to be set") + t.Fatal("An empty avalanche instance is not finalized") + } + if !ids.UnsortedEquals([]ids.ID{seedVertices[0].ID(), seedVertices[1].ID()}, avl.Preferences().List()) { + t.Fatal("Initial frontier failed to be set") } - tx0 := &snowstorm.TestTx{TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }} - tx0.InputIDsV = append(tx0.InputIDsV, utxos[0]) - + utxos := []ids.ID{ids.GenerateTestID()} vtx0 := &TestVertex{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, }, - ParentsV: vts, + ParentsV: seedVertices, HeightV: 1, - TxsV: []snowstorm.Tx{tx0}, - } - - err := avl.Add(vtx0) - switch { - case err != nil: - t.Fatal(err) - case avl.Finalized(): - t.Fatalf("A non-empty avalanche instance is finalized") - case !ids.UnsortedEquals([]ids.ID{vtx0.IDV}, avl.Preferences().List()): - t.Fatalf("Initial frontier failed to be set") + TxsV: []snowstorm.Tx{ + &snowstorm.TestTx{ + TestDecidable: choices.TestDecidable{ + IDV: ids.GenerateTestID(), + StatusV: choices.Processing, + }, + InputIDsV: utxos, + }, + }, } - - tx1 := &snowstorm.TestTx{TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }} - tx1.InputIDsV = append(tx1.InputIDsV, utxos[0]) - vtx1 := &TestVertex{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), StatusV: choices.Processing, }, - ParentsV: vts, + ParentsV: seedVertices, HeightV: 1, - TxsV: []snowstorm.Tx{tx1}, - } - - err = avl.Add(vtx1) - switch { - case err != nil: - t.Fatal(err) - case avl.Finalized(): - t.Fatalf("A non-empty avalanche instance is finalized") - case !ids.UnsortedEquals([]ids.ID{vtx0.IDV}, avl.Preferences().List()): - t.Fatalf("Initial frontier failed to be set") - } - - err = avl.Add(vtx1) - switch { - case err != nil: - t.Fatal(err) - case avl.Finalized(): - t.Fatalf("A non-empty avalanche instance is finalized") - case !ids.UnsortedEquals([]ids.ID{vtx0.IDV}, avl.Preferences().List()): - t.Fatalf("Initial frontier failed to be set") + TxsV: []snowstorm.Tx{ + &snowstorm.TestTx{ + TestDecidable: choices.TestDecidable{ + IDV: ids.GenerateTestID(), + StatusV: choices.Processing, + }, + InputIDsV: utxos, + }, + }, } - err = avl.Add(vts[0]) - switch { - case err != nil: - t.Fatal(err) - case avl.Finalized(): - t.Fatalf("A non-empty avalanche instance is finalized") - case !ids.UnsortedEquals([]ids.ID{vtx0.IDV}, avl.Preferences().List()): - t.Fatalf("Initial frontier failed to be set") + tt := []struct { + toAdd Vertex + err error + finalized bool + preferenceSet []ids.ID + issued int + accepted int + }{ + { + toAdd: vtx0, + err: nil, + finalized: false, + preferenceSet: []ids.ID{vtx0.IDV}, + issued: 1, // on "add", it should be issued + accepted: 0, + }, + { + toAdd: vtx1, + err: nil, + finalized: false, + preferenceSet: []ids.ID{vtx0.IDV}, + issued: 1, // on "add", it should be issued + accepted: 0, + }, + { + toAdd: seedVertices[0], + err: nil, + finalized: false, + preferenceSet: []ids.ID{vtx0.IDV}, + issued: 0, // initialized vertex should not belong to in-processing nodes + accepted: 0, + }, + } + for i, tv := range tt { + for _, j := range []int{1, 2} { // duplicate vertex add should be skipped + err := avl.Add(tv.toAdd) + if err != tv.err { + t.Fatalf("#%d-%d: expected error %v, got %v", i, j, tv.err, err) + } + finalized := avl.Finalized() + if finalized != tv.finalized { + t.Fatalf("#%d-%d: expected finalized %v, got %v", i, j, finalized, tv.finalized) + } + preferenceSet := avl.Preferences().List() + if !ids.UnsortedEquals(tv.preferenceSet, preferenceSet) { + t.Fatalf("#%d-%d: expected preferenceSet %v, got %v", i, j, preferenceSet, tv.preferenceSet) + } + if issued, _ := consensusEvents.IsIssued(tv.toAdd.ID()); issued != tv.issued { + t.Fatalf("#%d-%d: expected issued %d, got %d", i, j, tv.issued, issued) + } + if accepted, _ := consensusEvents.IsAccepted(tv.toAdd.ID()); accepted != tv.accepted { + t.Fatalf("#%d-%d: expected accepted %d, got %d", i, j, tv.accepted, accepted) + } + } } } @@ -419,7 +434,6 @@ func VertexIssuedTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -444,7 +458,7 @@ func VertexIssuedTest(t *testing.T, factory Factory) { } utxos := []ids.ID{ids.GenerateTestID()} - if err := avl.Initialize(snow.DefaultContextTest(), params, vts); err != nil { + if err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts); err != nil { t.Fatal(err) } @@ -482,7 +496,6 @@ func TxIssuedTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -515,7 +528,7 @@ func TxIssuedTest(t *testing.T, factory Factory) { }} tx1.InputIDsV = append(tx1.InputIDsV, utxos[0]) - if err := avl.Initialize(snow.DefaultContextTest(), params, vts); err != nil { + if err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts); err != nil { t.Fatal(err) } @@ -546,7 +559,6 @@ func VirtuousTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 10, @@ -571,7 +583,7 @@ func VirtuousTest(t *testing.T, factory Factory) { } utxos := []ids.ID{ids.GenerateTestID(), ids.GenerateTestID()} - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } @@ -700,7 +712,6 @@ func VirtuousSkippedUpdateTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 10, @@ -728,7 +739,7 @@ func VirtuousSkippedUpdateTest(t *testing.T, factory Factory) { ids.GenerateTestID(), } - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } @@ -796,12 +807,13 @@ func VirtuousSkippedUpdateTest(t *testing.T, factory Factory) { } } +// Creates two conflicting transactions in different vertices +// and make sure only one is accepted func VotingTest(t *testing.T, factory Factory) { avl := factory.New() params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -826,17 +838,28 @@ func VotingTest(t *testing.T, factory Factory) { } utxos := []ids.ID{ids.GenerateTestID()} - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } - tx0 := &snowstorm.TestTx{TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }} - tx0.InputIDsV = append(tx0.InputIDsV, utxos[0]) + // create two different transactions with the same input UTXO (double-spend) + tx0 := &snowstorm.TestTx{ + TestDecidable: choices.TestDecidable{ + IDV: ids.GenerateTestID(), + StatusV: choices.Processing, + }, + InputIDsV: []ids.ID{utxos[0]}, + } + tx1 := &snowstorm.TestTx{ + TestDecidable: choices.TestDecidable{ + IDV: ids.GenerateTestID(), + StatusV: choices.Processing, + }, + InputIDsV: []ids.ID{utxos[0]}, + } + // put them in different vertices vtx0 := &TestVertex{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), @@ -846,13 +869,6 @@ func VotingTest(t *testing.T, factory Factory) { HeightV: 1, TxsV: []snowstorm.Tx{tx0}, } - - tx1 := &snowstorm.TestTx{TestDecidable: choices.TestDecidable{ - IDV: ids.GenerateTestID(), - StatusV: choices.Processing, - }} - tx1.InputIDsV = append(tx1.InputIDsV, utxos[0]) - vtx1 := &TestVertex{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), @@ -863,16 +879,20 @@ func VotingTest(t *testing.T, factory Factory) { TxsV: []snowstorm.Tx{tx1}, } + // issue two vertices with conflicting transaction to the consensus instance if err := avl.Add(vtx0); err != nil { t.Fatal(err) - } else if err := avl.Add(vtx1); err != nil { + } + if err := avl.Add(vtx1); err != nil { t.Fatal(err) } + // create poll results, all vote for vtx1, not for vtx0 sm := ids.UniqueBag{} sm.Add(0, vtx1.IDV) sm.Add(1, vtx1.IDV) + // "BetaRogue" is 2, thus consensus should not be finalized yet err = avl.RecordPoll(sm) switch { case err != nil: @@ -881,8 +901,14 @@ func VotingTest(t *testing.T, factory Factory) { t.Fatalf("An avalanche instance finalized too early") case !ids.UnsortedEquals([]ids.ID{vtx1.IDV}, avl.Preferences().List()): t.Fatalf("Initial frontier failed to be set") + case tx0.Status() != choices.Processing: + t.Fatalf("Tx should have been Processing") + case tx1.Status() != choices.Processing: + t.Fatalf("Tx should have been Processing") } + // second poll should reach consensus, + // and the other vertex of conflict transaction should be rejected err = avl.RecordPoll(sm) switch { case err != nil: @@ -903,7 +929,6 @@ func IgnoreInvalidVotingTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 3, Alpha: 2, BetaVirtuous: 1, @@ -929,7 +954,7 @@ func IgnoreInvalidVotingTest(t *testing.T, factory Factory) { } utxos := []ids.ID{ids.GenerateTestID()} - if err := avl.Initialize(snow.DefaultContextTest(), params, vts); err != nil { + if err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts); err != nil { t.Fatal(err) } @@ -991,7 +1016,6 @@ func TransitiveVotingTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -1016,7 +1040,7 @@ func TransitiveVotingTest(t *testing.T, factory Factory) { } utxos := []ids.ID{ids.GenerateTestID(), ids.GenerateTestID()} - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } @@ -1111,7 +1135,6 @@ func SplitVotingTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -1136,7 +1159,7 @@ func SplitVotingTest(t *testing.T, factory Factory) { } utxos := []ids.ID{ids.GenerateTestID()} - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } @@ -1195,7 +1218,6 @@ func TransitiveRejectionTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -1220,7 +1242,7 @@ func TransitiveRejectionTest(t *testing.T, factory Factory) { } utxos := []ids.ID{ids.GenerateTestID(), ids.GenerateTestID()} - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } @@ -1333,7 +1355,6 @@ func IsVirtuousTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -1358,7 +1379,7 @@ func IsVirtuousTest(t *testing.T, factory Factory) { } utxos := []ids.ID{ids.GenerateTestID(), ids.GenerateTestID()} - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } @@ -1437,7 +1458,6 @@ func QuiesceTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1462,7 +1482,7 @@ func QuiesceTest(t *testing.T, factory Factory) { } utxos := []ids.ID{ids.GenerateTestID(), ids.GenerateTestID()} - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } @@ -1543,7 +1563,6 @@ func OrphansTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: math.MaxInt32, @@ -1568,7 +1587,7 @@ func OrphansTest(t *testing.T, factory Factory) { } utxos := []ids.ID{ids.GenerateTestID(), ids.GenerateTestID()} - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } @@ -1651,7 +1670,6 @@ func ErrorOnVacuousAcceptTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: math.MaxInt32, @@ -1669,7 +1687,7 @@ func ErrorOnVacuousAcceptTest(t *testing.T, factory Factory) { StatusV: choices.Accepted, }}} - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } @@ -1700,7 +1718,6 @@ func ErrorOnTxAcceptTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1719,7 +1736,7 @@ func ErrorOnTxAcceptTest(t *testing.T, factory Factory) { }}} utxos := []ids.ID{ids.GenerateTestID()} - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } @@ -1757,7 +1774,6 @@ func ErrorOnVtxAcceptTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1776,7 +1792,7 @@ func ErrorOnVtxAcceptTest(t *testing.T, factory Factory) { }}} utxos := []ids.ID{ids.GenerateTestID()} - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } @@ -1814,7 +1830,6 @@ func ErrorOnVtxRejectTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1833,7 +1848,7 @@ func ErrorOnVtxRejectTest(t *testing.T, factory Factory) { }}} utxos := []ids.ID{ids.GenerateTestID()} - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } @@ -1889,7 +1904,6 @@ func ErrorOnParentVtxRejectTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1908,7 +1922,7 @@ func ErrorOnParentVtxRejectTest(t *testing.T, factory Factory) { }}} utxos := []ids.ID{ids.GenerateTestID()} - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } @@ -1976,7 +1990,6 @@ func ErrorOnTransitiveVtxRejectTest(t *testing.T, factory Factory) { params := Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1995,7 +2008,7 @@ func ErrorOnTransitiveVtxRejectTest(t *testing.T, factory Factory) { }}} utxos := []ids.ID{ids.GenerateTestID()} - err := avl.Initialize(snow.DefaultContextTest(), params, vts) + err := avl.Initialize(snow.DefaultConsensusContextTest(), params, vts) if err != nil { t.Fatal(err) } diff --git a/snow/consensus/avalanche/factory.go b/snow/consensus/avalanche/factory.go index 5f0d2d1706ba..ce8072b458ae 100644 --- a/snow/consensus/avalanche/factory.go +++ b/snow/consensus/avalanche/factory.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche diff --git a/snow/consensus/avalanche/parameters.go b/snow/consensus/avalanche/parameters.go index c1c4cbf04642..ab53cd08f08d 100644 --- a/snow/consensus/avalanche/parameters.go +++ b/snow/consensus/avalanche/parameters.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche diff --git a/snow/consensus/avalanche/parameters_test.go b/snow/consensus/avalanche/parameters_test.go index ba61a1ee2dfe..0f66abd33bf1 100644 --- a/snow/consensus/avalanche/parameters_test.go +++ b/snow/consensus/avalanche/parameters_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche diff --git a/snow/consensus/avalanche/poll/early_term_no_traversal.go b/snow/consensus/avalanche/poll/early_term_no_traversal.go index d58724f21657..fbccd7986701 100644 --- a/snow/consensus/avalanche/poll/early_term_no_traversal.go +++ b/snow/consensus/avalanche/poll/early_term_no_traversal.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package poll diff --git a/snow/consensus/avalanche/poll/early_term_no_traversal_test.go b/snow/consensus/avalanche/poll/early_term_no_traversal_test.go index 4326eae86d75..0fcfe1d64ab5 100644 --- a/snow/consensus/avalanche/poll/early_term_no_traversal_test.go +++ b/snow/consensus/avalanche/poll/early_term_no_traversal_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package poll diff --git a/snow/consensus/avalanche/poll/interfaces.go b/snow/consensus/avalanche/poll/interfaces.go index 6c57c25f800e..6b185138ffec 100644 --- a/snow/consensus/avalanche/poll/interfaces.go +++ b/snow/consensus/avalanche/poll/interfaces.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package poll diff --git a/snow/consensus/avalanche/poll/no_early_term.go b/snow/consensus/avalanche/poll/no_early_term.go index fad11773fbec..64330774a9a1 100644 --- a/snow/consensus/avalanche/poll/no_early_term.go +++ b/snow/consensus/avalanche/poll/no_early_term.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package poll diff --git a/snow/consensus/avalanche/poll/no_early_term_test.go b/snow/consensus/avalanche/poll/no_early_term_test.go index 4a9eadc12c36..5e491c8f113d 100644 --- a/snow/consensus/avalanche/poll/no_early_term_test.go +++ b/snow/consensus/avalanche/poll/no_early_term_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package poll diff --git a/snow/consensus/avalanche/poll/set.go b/snow/consensus/avalanche/poll/set.go index c2f43aacb8dd..8d2b3253b100 100644 --- a/snow/consensus/avalanche/poll/set.go +++ b/snow/consensus/avalanche/poll/set.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package poll diff --git a/snow/consensus/avalanche/poll/set_test.go b/snow/consensus/avalanche/poll/set_test.go index 341cedfd6325..2b86d1e86490 100644 --- a/snow/consensus/avalanche/poll/set_test.go +++ b/snow/consensus/avalanche/poll/set_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package poll diff --git a/snow/consensus/avalanche/test_vertex.go b/snow/consensus/avalanche/test_vertex.go index 49150e64f2ca..352dc0fb6ebe 100644 --- a/snow/consensus/avalanche/test_vertex.go +++ b/snow/consensus/avalanche/test_vertex.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche @@ -18,8 +18,6 @@ type TestVertex struct { ParentsErrV error HeightV uint64 HeightErrV error - EpochV uint32 - EpochErrV error TxsV []snowstorm.Tx TxsErrV error BytesV []byte @@ -31,9 +29,6 @@ func (v *TestVertex) Parents() ([]Vertex, error) { return v.ParentsV, v.ParentsE // Height implements the Vertex interface func (v *TestVertex) Height() (uint64, error) { return v.HeightV, v.HeightErrV } -// Epoch implements the Vertex interface -func (v *TestVertex) Epoch() (uint32, error) { return v.EpochV, v.EpochErrV } - // Txs implements the Vertex interface func (v *TestVertex) Txs() ([]snowstorm.Tx, error) { return v.TxsV, v.TxsErrV } diff --git a/snow/consensus/avalanche/topological.go b/snow/consensus/avalanche/topological.go index 5af725f03159..61dcf4b49291 100644 --- a/snow/consensus/avalanche/topological.go +++ b/snow/consensus/avalanche/topological.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche @@ -45,7 +45,7 @@ type Topological struct { pollNumber uint64 // Context used for logging - ctx *snow.Context + ctx *snow.ConsensusContext // Threshold for confidence increases params Parameters @@ -89,7 +89,7 @@ type kahnNode struct { // Initialize implements the Avalanche interface func (ta *Topological) Initialize( - ctx *snow.Context, + ctx *snow.ConsensusContext, params Parameters, frontier []Vertex, ) error { @@ -103,7 +103,7 @@ func (ta *Topological) Initialize( ta.votes = ids.UniqueBag{} ta.kahnNodes = make(map[ids.ID]kahnNode) - if err := ta.Latency.Initialize("vtx", "vertex/vertices", ctx.Log, params.Namespace, params.Metrics); err != nil { + if err := ta.Latency.Initialize("vtx", "vertex/vertices", ctx.Log, "", ctx.Registerer); err != nil { return err } diff --git a/snow/consensus/avalanche/topological_test.go b/snow/consensus/avalanche/topological_test.go index a97fb18b491a..f8461d2655e1 100644 --- a/snow/consensus/avalanche/topological_test.go +++ b/snow/consensus/avalanche/topological_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche diff --git a/snow/consensus/avalanche/vertex.go b/snow/consensus/avalanche/vertex.go index f711149a7aad..66d98403b59e 100644 --- a/snow/consensus/avalanche/vertex.go +++ b/snow/consensus/avalanche/vertex.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche @@ -19,9 +19,6 @@ type Vertex interface { // greater than the maximum height of the parents. Height() (uint64, error) - // Returns the epoch this vertex was issued in. - Epoch() (uint32, error) - // Returns a series of state transitions to be performed on acceptance Txs() ([]snowstorm.Tx, error) diff --git a/snow/consensus/metrics/latency.go b/snow/consensus/metrics/latency.go index e0193c576fc7..b87ba982b446 100644 --- a/snow/consensus/metrics/latency.go +++ b/snow/consensus/metrics/latency.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package metrics diff --git a/snow/consensus/metrics/polls.go b/snow/consensus/metrics/polls.go index 5ba87bc421a1..69551f5daae3 100644 --- a/snow/consensus/metrics/polls.go +++ b/snow/consensus/metrics/polls.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package metrics diff --git a/snow/consensus/snowball/binary_slush.go b/snow/consensus/snowball/binary_slush.go index 84e4cd3c3dc7..281c74ce11ce 100644 --- a/snow/consensus/snowball/binary_slush.go +++ b/snow/consensus/snowball/binary_slush.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/binary_snowball.go b/snow/consensus/snowball/binary_snowball.go index f41046c78134..c2e9a77c63d7 100644 --- a/snow/consensus/snowball/binary_snowball.go +++ b/snow/consensus/snowball/binary_snowball.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/binary_snowball_test.go b/snow/consensus/snowball/binary_snowball_test.go index 2962164a9943..c58fee112274 100644 --- a/snow/consensus/snowball/binary_snowball_test.go +++ b/snow/consensus/snowball/binary_snowball_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/binary_snowflake.go b/snow/consensus/snowball/binary_snowflake.go index 18600126bfd6..58cf532bcf09 100644 --- a/snow/consensus/snowball/binary_snowflake.go +++ b/snow/consensus/snowball/binary_snowflake.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/binary_snowflake_test.go b/snow/consensus/snowball/binary_snowflake_test.go index 1078687e15ab..d55d33035d49 100644 --- a/snow/consensus/snowball/binary_snowflake_test.go +++ b/snow/consensus/snowball/binary_snowflake_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/consensus.go b/snow/consensus/snowball/consensus.go index 9d1d7c56a846..868fe6822a9e 100644 --- a/snow/consensus/snowball/consensus.go +++ b/snow/consensus/snowball/consensus.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/consensus_performance_test.go b/snow/consensus/snowball/consensus_performance_test.go index d9475bc8531d..5edf0025cc5f 100644 --- a/snow/consensus/snowball/consensus_performance_test.go +++ b/snow/consensus/snowball/consensus_performance_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball @@ -7,15 +7,13 @@ import ( "testing" "github.com/ava-labs/avalanchego/utils/sampler" - "github.com/prometheus/client_golang/prometheus" ) func TestSnowballOptimized(t *testing.T) { numColors := 10 numNodes := 100 params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 20, Alpha: 15, BetaVirtuous: 20, BetaRogue: 30, + K: 20, Alpha: 15, BetaVirtuous: 20, BetaRogue: 30, } seed := int64(0) diff --git a/snow/consensus/snowball/consensus_reversibility_test.go b/snow/consensus/snowball/consensus_reversibility_test.go index e11842241f52..c48f0db2a21e 100644 --- a/snow/consensus/snowball/consensus_reversibility_test.go +++ b/snow/consensus/snowball/consensus_reversibility_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball @@ -7,7 +7,6 @@ import ( "testing" "github.com/ava-labs/avalanchego/utils/sampler" - "github.com/prometheus/client_golang/prometheus" ) func TestSnowballGovernance(t *testing.T) { @@ -16,8 +15,7 @@ func TestSnowballGovernance(t *testing.T) { numByzantine := 10 numRed := 55 params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 20, Alpha: 15, BetaVirtuous: 20, BetaRogue: 30, + K: 20, Alpha: 15, BetaVirtuous: 20, BetaRogue: 30, } seed := int64(0) diff --git a/snow/consensus/snowball/consensus_test.go b/snow/consensus/snowball/consensus_test.go index 5960cbd2801f..67f4c0289b8a 100644 --- a/snow/consensus/snowball/consensus_test.go +++ b/snow/consensus/snowball/consensus_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball @@ -6,8 +6,6 @@ package snowball import ( "testing" - "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/ids" ) @@ -55,8 +53,7 @@ func ParamsTest(t *testing.T, factory Factory) { sb := factory.New() params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 2, Alpha: 2, BetaVirtuous: 1, BetaRogue: 2, ConcurrentRepolls: 1, + K: 2, Alpha: 2, BetaVirtuous: 1, BetaRogue: 2, ConcurrentRepolls: 1, } sb.Initialize(params, Red) diff --git a/snow/consensus/snowball/factory.go b/snow/consensus/snowball/factory.go index b86f8a4ce2c5..d5656d46912c 100644 --- a/snow/consensus/snowball/factory.go +++ b/snow/consensus/snowball/factory.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/flat.go b/snow/consensus/snowball/flat.go index 11154293fbf3..51ad40e9f6f7 100644 --- a/snow/consensus/snowball/flat.go +++ b/snow/consensus/snowball/flat.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/flat_test.go b/snow/consensus/snowball/flat_test.go index cafc53335a38..c36fde6ff3b8 100644 --- a/snow/consensus/snowball/flat_test.go +++ b/snow/consensus/snowball/flat_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball @@ -6,8 +6,6 @@ package snowball import ( "testing" - "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/ids" ) @@ -15,8 +13,7 @@ func TestFlatParams(t *testing.T) { ParamsTest(t, FlatFactory{}) } func TestFlat(t *testing.T) { params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 2, Alpha: 2, BetaVirtuous: 1, BetaRogue: 2, + K: 2, Alpha: 2, BetaVirtuous: 1, BetaRogue: 2, } f := Flat{} f.Initialize(params, Red) diff --git a/snow/consensus/snowball/network_test.go b/snow/consensus/snowball/network_test.go index 865b638fd983..cb144d0e8bd8 100644 --- a/snow/consensus/snowball/network_test.go +++ b/snow/consensus/snowball/network_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/nnary_slush.go b/snow/consensus/snowball/nnary_slush.go index 8807be8b6f47..5f70fc8ced40 100644 --- a/snow/consensus/snowball/nnary_slush.go +++ b/snow/consensus/snowball/nnary_slush.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/nnary_snowball.go b/snow/consensus/snowball/nnary_snowball.go index 5d3ac3aaea5f..31508e30f754 100644 --- a/snow/consensus/snowball/nnary_snowball.go +++ b/snow/consensus/snowball/nnary_snowball.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/nnary_snowball_test.go b/snow/consensus/snowball/nnary_snowball_test.go index 023dec525206..025241e72977 100644 --- a/snow/consensus/snowball/nnary_snowball_test.go +++ b/snow/consensus/snowball/nnary_snowball_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/nnary_snowflake.go b/snow/consensus/snowball/nnary_snowflake.go index fd0106d05e75..9805b332a79a 100644 --- a/snow/consensus/snowball/nnary_snowflake.go +++ b/snow/consensus/snowball/nnary_snowflake.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/nnary_snowflake_test.go b/snow/consensus/snowball/nnary_snowflake_test.go index 9ab763c86d3b..8ec2210195f3 100644 --- a/snow/consensus/snowball/nnary_snowflake_test.go +++ b/snow/consensus/snowball/nnary_snowflake_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/parameters.go b/snow/consensus/snowball/parameters.go index 8c7dad1f2a48..15e621cca6fb 100644 --- a/snow/consensus/snowball/parameters.go +++ b/snow/consensus/snowball/parameters.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball @@ -6,8 +6,6 @@ package snowball import ( "fmt" "time" - - "github.com/prometheus/client_golang/prometheus" ) const ( @@ -30,15 +28,12 @@ const ( // Parameters required for snowball consensus type Parameters struct { - Namespace string `json:"-"` - // TODO: move metrics to a more suitable place - Metrics prometheus.Registerer `json:"-"` - K int `json:"k"` - Alpha int `json:"alpha"` - BetaVirtuous int `json:"betaVirtuous"` - BetaRogue int `json:"betaRogue"` - ConcurrentRepolls int `json:"concurrentRepolls"` - OptimalProcessing int `json:"optimalProcessing"` + K int `json:"k"` + Alpha int `json:"alpha"` + BetaVirtuous int `json:"betaVirtuous"` + BetaRogue int `json:"betaRogue"` + ConcurrentRepolls int `json:"concurrentRepolls"` + OptimalProcessing int `json:"optimalProcessing"` // Reports unhealthy if more than this number of items are outstanding. MaxOutstandingItems int `json:"maxOutstandingItems"` diff --git a/snow/consensus/snowball/parameters_test.go b/snow/consensus/snowball/parameters_test.go index bec3dfd6bee0..4e2d6242b656 100644 --- a/snow/consensus/snowball/parameters_test.go +++ b/snow/consensus/snowball/parameters_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/tree.go b/snow/consensus/snowball/tree.go index 6db596073c8e..6a44aaf9838c 100644 --- a/snow/consensus/snowball/tree.go +++ b/snow/consensus/snowball/tree.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/tree_test.go b/snow/consensus/snowball/tree_test.go index 24447529d998..8aacf6fdbea8 100644 --- a/snow/consensus/snowball/tree_test.go +++ b/snow/consensus/snowball/tree_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball @@ -7,8 +7,6 @@ import ( "strings" "testing" - "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/sampler" ) @@ -21,8 +19,7 @@ func TestTreeParams(t *testing.T) { ParamsTest(t, TreeFactory{}) } func TestSnowballSingleton(t *testing.T) { params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 2, BetaRogue: 5, + K: 1, Alpha: 1, BetaVirtuous: 2, BetaRogue: 5, } tree := Tree{} tree.Initialize(params, Red) @@ -75,8 +72,7 @@ func TestSnowballSingleton(t *testing.T) { func TestSnowballRecordUnsuccessfulPoll(t *testing.T) { params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 3, BetaRogue: 5, + K: 1, Alpha: 1, BetaVirtuous: 3, BetaRogue: 5, } tree := Tree{} tree.Initialize(params, Red) @@ -114,8 +110,7 @@ func TestSnowballRecordUnsuccessfulPoll(t *testing.T) { func TestSnowballBinary(t *testing.T) { params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, + K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, } tree := Tree{} tree.Initialize(params, Red) @@ -174,8 +169,7 @@ func TestSnowballLastBinary(t *testing.T) { } params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 2, BetaRogue: 2, + K: 1, Alpha: 1, BetaVirtuous: 2, BetaRogue: 2, } tree := Tree{} tree.Initialize(params, zero) @@ -220,8 +214,7 @@ func TestSnowballAddPreviouslyRejected(t *testing.T) { four := ids.ID{0b00000100} params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, + K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, } tree := Tree{} tree.Initialize(params, zero) @@ -286,8 +279,7 @@ func TestSnowballNewUnary(t *testing.T) { one := ids.ID{0b00000001} params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 2, BetaRogue: 3, + K: 1, Alpha: 1, BetaVirtuous: 2, BetaRogue: 3, } tree := Tree{} tree.Initialize(params, zero) @@ -345,8 +337,7 @@ func TestSnowballTransitiveReset(t *testing.T) { eight := ids.ID{0b00001000} params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 2, BetaRogue: 2, + K: 1, Alpha: 1, BetaVirtuous: 2, BetaRogue: 2, } tree := Tree{} tree.Initialize(params, zero) @@ -446,8 +437,7 @@ func TestSnowballTransitiveReset(t *testing.T) { func TestSnowballTrinary(t *testing.T) { params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, + K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, } tree := Tree{} tree.Initialize(params, Green) @@ -521,8 +511,7 @@ func TestSnowballCloseTrinary(t *testing.T) { magenta := ids.ID{0x03} params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, + K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, } tree := Tree{} tree.Initialize(params, yellow) @@ -581,8 +570,7 @@ func TestSnowballAddRejected(t *testing.T) { c0010 := ids.ID{0x04} // 0010 params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, + K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, } tree := Tree{} tree.Initialize(params, c0000) @@ -637,8 +625,7 @@ func TestSnowballResetChild(t *testing.T) { c1000 := ids.ID{0x01} // 1000 params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, + K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, } tree := Tree{} tree.Initialize(params, c0000) @@ -711,8 +698,7 @@ func TestSnowballResetSibling(t *testing.T) { c1000 := ids.ID{0x01} // 1000 params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, + K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, } tree := Tree{} tree.Initialize(params, c0000) @@ -783,8 +769,7 @@ func TestSnowballResetSibling(t *testing.T) { func TestSnowball5Colors(t *testing.T) { numColors := 5 params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 5, Alpha: 5, BetaVirtuous: 20, BetaRogue: 30, + K: 5, Alpha: 5, BetaVirtuous: 20, BetaRogue: 30, } colors := []ids.ID{} @@ -823,8 +808,7 @@ func TestSnowballFineGrained(t *testing.T) { c0010 := ids.ID{0x04} params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, + K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, } tree := Tree{} tree.Initialize(params, c0000) @@ -939,8 +923,7 @@ func TestSnowballFineGrained(t *testing.T) { func TestSnowballDoubleAdd(t *testing.T) { params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 3, BetaRogue: 5, + K: 1, Alpha: 1, BetaVirtuous: 3, BetaRogue: 5, } tree := Tree{} tree.Initialize(params, Red) @@ -962,8 +945,7 @@ func TestSnowballConsistent(t *testing.T) { numColors := 50 numNodes := 100 params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 20, Alpha: 15, BetaVirtuous: 20, BetaRogue: 30, + K: 20, Alpha: 15, BetaVirtuous: 20, BetaRogue: 30, } seed := int64(0) @@ -992,8 +974,7 @@ func TestSnowballFilterBinaryChildren(t *testing.T) { c0010 := ids.ID{0b00000100} params := Parameters{ - Metrics: prometheus.NewRegistry(), - K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, + K: 1, Alpha: 1, BetaVirtuous: 1, BetaRogue: 2, } tree := Tree{} tree.Initialize(params, c0000) diff --git a/snow/consensus/snowball/unary_snowball.go b/snow/consensus/snowball/unary_snowball.go index 44eea46f3e3f..3e7fbb2dec67 100644 --- a/snow/consensus/snowball/unary_snowball.go +++ b/snow/consensus/snowball/unary_snowball.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/unary_snowball_test.go b/snow/consensus/snowball/unary_snowball_test.go index 4ddc6c6808ec..42775d500ac7 100644 --- a/snow/consensus/snowball/unary_snowball_test.go +++ b/snow/consensus/snowball/unary_snowball_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/unary_snowflake.go b/snow/consensus/snowball/unary_snowflake.go index 217233168b18..c967d1dd2896 100644 --- a/snow/consensus/snowball/unary_snowflake.go +++ b/snow/consensus/snowball/unary_snowflake.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowball/unary_snowflake_test.go b/snow/consensus/snowball/unary_snowflake_test.go index 55d29e2f2810..d3139bf608cc 100644 --- a/snow/consensus/snowball/unary_snowflake_test.go +++ b/snow/consensus/snowball/unary_snowflake_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowball diff --git a/snow/consensus/snowman/block.go b/snow/consensus/snowman/block.go index 51865993ba42..56d93c0efdfa 100644 --- a/snow/consensus/snowman/block.go +++ b/snow/consensus/snowman/block.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/consensus/snowman/consensus.go b/snow/consensus/snowman/consensus.go index 4f3a19cd9696..55e0d0734b63 100644 --- a/snow/consensus/snowman/consensus.go +++ b/snow/consensus/snowman/consensus.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman @@ -14,7 +14,7 @@ import ( type Consensus interface { // Takes in the context, snowball parameters, and the last accepted block. Initialize( - ctx *snow.Context, + ctx *snow.ConsensusContext, params snowball.Parameters, lastAcceptedID ids.ID, lastAcceptedHeight uint64, diff --git a/snow/consensus/snowman/consensus_test.go b/snow/consensus/snowman/consensus_test.go index 72d52a0bf05f..3a768ef24be7 100644 --- a/snow/consensus/snowman/consensus_test.go +++ b/snow/consensus/snowman/consensus_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman @@ -77,9 +77,8 @@ func getTestName(i interface{}) string { func InitializeTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 3, @@ -107,9 +106,8 @@ func InitializeTest(t *testing.T, factory Factory) { func NumProcessingTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -159,9 +157,8 @@ func NumProcessingTest(t *testing.T, factory Factory) { func AddToTailTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 3, @@ -197,9 +194,8 @@ func AddToTailTest(t *testing.T, factory Factory) { func AddToNonTailTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 3, @@ -249,9 +245,8 @@ func AddToNonTailTest(t *testing.T, factory Factory) { func AddToUnknownTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 3, @@ -292,9 +287,8 @@ func AddToUnknownTest(t *testing.T, factory Factory) { func StatusOrProcessingPreviouslyAcceptedTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 3, @@ -322,9 +316,8 @@ func StatusOrProcessingPreviouslyAcceptedTest(t *testing.T, factory Factory) { func StatusOrProcessingPreviouslyRejectedTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 3, @@ -360,9 +353,8 @@ func StatusOrProcessingPreviouslyRejectedTest(t *testing.T, factory Factory) { func StatusOrProcessingUnissuedTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 3, @@ -399,9 +391,8 @@ func StatusOrProcessingUnissuedTest(t *testing.T, factory Factory) { func StatusOrProcessingIssuedTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 3, @@ -440,9 +431,8 @@ func StatusOrProcessingIssuedTest(t *testing.T, factory Factory) { func RecordPollAcceptSingleBlockTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 2, @@ -492,9 +482,8 @@ func RecordPollAcceptSingleBlockTest(t *testing.T, factory Factory) { func RecordPollAcceptAndRejectTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -558,9 +547,8 @@ func RecordPollAcceptAndRejectTest(t *testing.T, factory Factory) { func RecordPollWhenFinalizedTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -588,9 +576,8 @@ func RecordPollWhenFinalizedTest(t *testing.T, factory Factory) { func RecordPollRejectTransitivelyTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -668,9 +655,8 @@ func RecordPollRejectTransitivelyTest(t *testing.T, factory Factory) { func RecordPollTransitivelyResetConfidenceTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 2, @@ -783,9 +769,8 @@ func RecordPollTransitivelyResetConfidenceTest(t *testing.T, factory Factory) { func RecordPollInvalidVoteTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 2, @@ -834,9 +819,8 @@ func RecordPollInvalidVoteTest(t *testing.T, factory Factory) { func RecordPollTransitiveVotingTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 3, Alpha: 3, BetaVirtuous: 1, @@ -976,9 +960,8 @@ func RecordPollTransitiveVotingTest(t *testing.T, factory Factory) { func RecordPollDivergedVotingTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1059,9 +1042,8 @@ func RecordPollDivergedVotingTest(t *testing.T, factory Factory) { func RecordPollChangePreferredChainTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 10, @@ -1193,9 +1175,8 @@ func RecordPollChangePreferredChainTest(t *testing.T, factory Factory) { func MetricsProcessingErrorTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1208,11 +1189,10 @@ func MetricsProcessingErrorTest(t *testing.T, factory Factory) { numProcessing := prometheus.NewGauge( prometheus.GaugeOpts{ - Namespace: params.Namespace, - Name: "blks_processing", + Name: "blks_processing", }) - if err := params.Metrics.Register(numProcessing); err != nil { + if err := ctx.Registerer.Register(numProcessing); err != nil { t.Fatal(err) } @@ -1224,9 +1204,8 @@ func MetricsProcessingErrorTest(t *testing.T, factory Factory) { func MetricsAcceptedErrorTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1239,11 +1218,10 @@ func MetricsAcceptedErrorTest(t *testing.T, factory Factory) { numAccepted := prometheus.NewGauge( prometheus.GaugeOpts{ - Namespace: params.Namespace, - Name: "blks_accepted_count", + Name: "blks_accepted_count", }) - if err := params.Metrics.Register(numAccepted); err != nil { + if err := ctx.Registerer.Register(numAccepted); err != nil { t.Fatal(err) } @@ -1255,9 +1233,8 @@ func MetricsAcceptedErrorTest(t *testing.T, factory Factory) { func MetricsRejectedErrorTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1270,11 +1247,10 @@ func MetricsRejectedErrorTest(t *testing.T, factory Factory) { numRejected := prometheus.NewGauge( prometheus.GaugeOpts{ - Namespace: params.Namespace, - Name: "blks_rejected_count", + Name: "blks_rejected_count", }) - if err := params.Metrics.Register(numRejected); err != nil { + if err := ctx.Registerer.Register(numRejected); err != nil { t.Fatal(err) } @@ -1286,9 +1262,8 @@ func MetricsRejectedErrorTest(t *testing.T, factory Factory) { func ErrorOnInitialRejectionTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1325,9 +1300,8 @@ func ErrorOnInitialRejectionTest(t *testing.T, factory Factory) { func ErrorOnAcceptTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1365,9 +1339,8 @@ func ErrorOnAcceptTest(t *testing.T, factory Factory) { func ErrorOnRejectSiblingTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1414,9 +1387,8 @@ func ErrorOnRejectSiblingTest(t *testing.T, factory Factory) { func ErrorOnTransitiveRejectionTest(t *testing.T, factory Factory) { sm := factory.New() - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1473,7 +1445,6 @@ func RandomizedConsistencyTest(t *testing.T, factory Factory) { numColors := 50 numNodes := 100 params := snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 20, Alpha: 15, BetaVirtuous: 20, diff --git a/snow/consensus/snowman/factory.go b/snow/consensus/snowman/factory.go index dd45e2a726b5..8b9fa64a43ba 100644 --- a/snow/consensus/snowman/factory.go +++ b/snow/consensus/snowman/factory.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/consensus/snowman/network_test.go b/snow/consensus/snowman/network_test.go index 1fbc12641c74..4e8cb6c14054 100644 --- a/snow/consensus/snowman/network_test.go +++ b/snow/consensus/snowman/network_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman @@ -6,8 +6,6 @@ package snowman import ( "math/rand" - "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" @@ -60,8 +58,7 @@ func (n *Network) Initialize(params snowball.Parameters, numColors int) { } func (n *Network) AddNode(sm Consensus) error { - n.params.Metrics = prometheus.NewRegistry() - if err := sm.Initialize(snow.DefaultContextTest(), n.params, Genesis.ID(), Genesis.Height()); err != nil { + if err := sm.Initialize(snow.DefaultConsensusContextTest(), n.params, Genesis.ID(), Genesis.Height()); err != nil { return err } diff --git a/snow/consensus/snowman/oracle_block.go b/snow/consensus/snowman/oracle_block.go index 1c50ef1c41c2..1d1bac1f5b18 100644 --- a/snow/consensus/snowman/oracle_block.go +++ b/snow/consensus/snowman/oracle_block.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/consensus/snowman/poll/early_term_no_traversal.go b/snow/consensus/snowman/poll/early_term_no_traversal.go index 5f6d8d70a7fe..c4376e3aabd4 100644 --- a/snow/consensus/snowman/poll/early_term_no_traversal.go +++ b/snow/consensus/snowman/poll/early_term_no_traversal.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package poll diff --git a/snow/consensus/snowman/poll/early_term_no_traversal_test.go b/snow/consensus/snowman/poll/early_term_no_traversal_test.go index 791cd2ef587b..b3f7512bdfdd 100644 --- a/snow/consensus/snowman/poll/early_term_no_traversal_test.go +++ b/snow/consensus/snowman/poll/early_term_no_traversal_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package poll diff --git a/snow/consensus/snowman/poll/interfaces.go b/snow/consensus/snowman/poll/interfaces.go index 3784a87f9269..e20821af5e59 100644 --- a/snow/consensus/snowman/poll/interfaces.go +++ b/snow/consensus/snowman/poll/interfaces.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package poll diff --git a/snow/consensus/snowman/poll/no_early_term.go b/snow/consensus/snowman/poll/no_early_term.go index 6aa6a2de31ef..b4416a8cfcca 100644 --- a/snow/consensus/snowman/poll/no_early_term.go +++ b/snow/consensus/snowman/poll/no_early_term.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package poll diff --git a/snow/consensus/snowman/poll/no_early_term_test.go b/snow/consensus/snowman/poll/no_early_term_test.go index 8019d08d3127..8ae910239e2e 100644 --- a/snow/consensus/snowman/poll/no_early_term_test.go +++ b/snow/consensus/snowman/poll/no_early_term_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package poll diff --git a/snow/consensus/snowman/poll/set.go b/snow/consensus/snowman/poll/set.go index 26ee82660a60..6512672353c1 100644 --- a/snow/consensus/snowman/poll/set.go +++ b/snow/consensus/snowman/poll/set.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package poll diff --git a/snow/consensus/snowman/poll/set_test.go b/snow/consensus/snowman/poll/set_test.go index e29b01eead66..9a4e772e755a 100644 --- a/snow/consensus/snowman/poll/set_test.go +++ b/snow/consensus/snowman/poll/set_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package poll diff --git a/snow/consensus/snowman/snowman_block.go b/snow/consensus/snowman/snowman_block.go index 3cbcaa251ca5..3187d0a0c0ff 100644 --- a/snow/consensus/snowman/snowman_block.go +++ b/snow/consensus/snowman/snowman_block.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/consensus/snowman/test_block.go b/snow/consensus/snowman/test_block.go index 22335b41d1d2..74db74de1554 100644 --- a/snow/consensus/snowman/test_block.go +++ b/snow/consensus/snowman/test_block.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/consensus/snowman/topological.go b/snow/consensus/snowman/topological.go index 9e496d73bf91..df93fbdca8d8 100644 --- a/snow/consensus/snowman/topological.go +++ b/snow/consensus/snowman/topological.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman @@ -31,7 +31,7 @@ type Topological struct { pollNumber uint64 // ctx is the context this snowman instance is executing in - ctx *snow.Context + ctx *snow.ConsensusContext // params are the parameters that should be used to initialize snowball // instances @@ -83,14 +83,14 @@ type votes struct { } // Initialize implements the Snowman interface -func (ts *Topological) Initialize(ctx *snow.Context, params snowball.Parameters, rootID ids.ID, rootHeight uint64) error { +func (ts *Topological) Initialize(ctx *snow.ConsensusContext, params snowball.Parameters, rootID ids.ID, rootHeight uint64) error { if err := params.Verify(); err != nil { return err } - if err := ts.Latency.Initialize("blks", "block(s)", ctx.Log, params.Namespace, params.Metrics); err != nil { + if err := ts.Latency.Initialize("blks", "block(s)", ctx.Log, "", ctx.Registerer); err != nil { return err } - if err := ts.Polls.Initialize(params.Namespace, params.Metrics); err != nil { + if err := ts.Polls.Initialize("", ctx.Registerer); err != nil { return err } ts.leaves = ids.Set{} diff --git a/snow/consensus/snowman/topological_test.go b/snow/consensus/snowman/topological_test.go index dd182782c57c..95f82cb4a5f0 100644 --- a/snow/consensus/snowman/topological_test.go +++ b/snow/consensus/snowman/topological_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/consensus/snowstorm/benchmark_test.go b/snow/consensus/snowstorm/benchmark_test.go index a7f7b74c986b..c5a4a8c36f46 100644 --- a/snow/consensus/snowstorm/benchmark_test.go +++ b/snow/consensus/snowstorm/benchmark_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowstorm @@ -6,8 +6,6 @@ package snowstorm import ( "testing" - "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/utils/sampler" sbcon "github.com/ava-labs/avalanchego/snow/consensus/snowball" @@ -60,7 +58,6 @@ func BenchmarkVirtuousDirected(b *testing.B) { /*maxInputConflicts=*/ 1, /*numNodes=*/ 50, /*params=*/ sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 20, Alpha: 11, BetaVirtuous: 20, @@ -84,7 +81,7 @@ func BenchmarkVirtuousInput(b *testing.B) { /*maxInputConflicts=*/ 1, /*numNodes=*/ 50, /*params=*/ sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), + K: 20, Alpha: 11, BetaVirtuous: 20, @@ -114,7 +111,6 @@ func BenchmarkRogueDirected(b *testing.B) { /*maxInputConflicts=*/ 3, /*numNodes=*/ 50, /*params=*/ sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 20, Alpha: 11, BetaVirtuous: 20, @@ -138,7 +134,6 @@ func BenchmarkRogueInput(b *testing.B) { /*maxInputConflicts=*/ 3, /*numNodes=*/ 50, /*params=*/ sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 20, Alpha: 11, BetaVirtuous: 20, @@ -168,7 +163,6 @@ func BenchmarkMultiDirected(b *testing.B) { /*maxInputConflicts=*/ 1, /*numNodes=*/ 50, /*params=*/ sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 20, Alpha: 11, BetaVirtuous: 20, @@ -192,7 +186,6 @@ func BenchmarkMultiInput(b *testing.B) { /*maxInputConflicts=*/ 1, /*numNodes=*/ 50, /*params=*/ sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 20, Alpha: 11, BetaVirtuous: 20, @@ -222,7 +215,6 @@ func BenchmarkMultiRogueDirected(b *testing.B) { /*maxInputConflicts=*/ 3, /*numNodes=*/ 50, /*params=*/ sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 20, Alpha: 11, BetaVirtuous: 20, @@ -246,7 +238,6 @@ func BenchmarkMultiRogueInput(b *testing.B) { /*maxInputConflicts=*/ 3, /*numNodes=*/ 50, /*params=*/ sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 20, Alpha: 11, BetaVirtuous: 20, diff --git a/snow/consensus/snowstorm/common.go b/snow/consensus/snowstorm/common.go index 919561b42312..850279c460a2 100644 --- a/snow/consensus/snowstorm/common.go +++ b/snow/consensus/snowstorm/common.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowstorm @@ -26,7 +26,7 @@ type common struct { metrics.Polls // context that this consensus instance is executing in - ctx *snow.Context + ctx *snow.ConsensusContext // params describes how this instance was parameterized params sbcon.Parameters @@ -54,14 +54,14 @@ type common struct { } // Initialize implements the ConflictGraph interface -func (c *common) Initialize(ctx *snow.Context, params sbcon.Parameters) error { +func (c *common) Initialize(ctx *snow.ConsensusContext, params sbcon.Parameters) error { c.ctx = ctx c.params = params - if err := c.Latency.Initialize("txs", "transaction(s)", ctx.Log, params.Namespace, params.Metrics); err != nil { + if err := c.Latency.Initialize("txs", "transaction(s)", ctx.Log, "", ctx.Registerer); err != nil { return fmt.Errorf("failed to initialize latency metrics: %w", err) } - if err := c.Polls.Initialize(params.Namespace, params.Metrics); err != nil { + if err := c.Polls.Initialize("", ctx.Registerer); err != nil { return fmt.Errorf("failed to initialize poll metrics: %w", err) } return params.Verify() diff --git a/snow/consensus/snowstorm/consensus.go b/snow/consensus/snowstorm/consensus.go index 964bfd54f0a3..78d6b971c74c 100644 --- a/snow/consensus/snowstorm/consensus.go +++ b/snow/consensus/snowstorm/consensus.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowstorm @@ -19,7 +19,7 @@ type Consensus interface { fmt.Stringer // Takes in the context, alpha, betaVirtuous, and betaRogue - Initialize(*snow.Context, sbcon.Parameters) error + Initialize(*snow.ConsensusContext, sbcon.Parameters) error // Returns the parameters that describe this snowstorm instance Parameters() sbcon.Parameters diff --git a/snow/consensus/snowstorm/consensus_test.go b/snow/consensus/snowstorm/consensus_test.go index e771986303f2..be197a89bc42 100644 --- a/snow/consensus/snowstorm/consensus_test.go +++ b/snow/consensus/snowstorm/consensus_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowstorm @@ -115,62 +115,62 @@ func getTestName(i interface{}) string { func MetricsTest(t *testing.T, factory Factory) { { + ctx := snow.DefaultConsensusContextTest() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, BetaRogue: 2, ConcurrentRepolls: 1, } - err := params.Metrics.Register(prometheus.NewCounter(prometheus.CounterOpts{ + err := ctx.Registerer.Register(prometheus.NewCounter(prometheus.CounterOpts{ Name: "tx_processing", })) if err != nil { t.Fatal(err) } graph := factory.New() - if err := graph.Initialize(snow.DefaultContextTest(), params); err == nil { + if err := graph.Initialize(ctx, params); err == nil { t.Fatalf("should have errored due to a duplicated metric") } } { + ctx := snow.DefaultConsensusContextTest() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, BetaRogue: 2, ConcurrentRepolls: 1, } - err := params.Metrics.Register(prometheus.NewCounter(prometheus.CounterOpts{ + err := ctx.Registerer.Register(prometheus.NewCounter(prometheus.CounterOpts{ Name: "tx_accepted", })) if err != nil { t.Fatal(err) } graph := factory.New() - if err := graph.Initialize(snow.DefaultContextTest(), params); err == nil { + if err := graph.Initialize(ctx, params); err == nil { t.Fatalf("should have errored due to a duplicated metric") } } { + ctx := snow.DefaultConsensusContextTest() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, BetaRogue: 2, ConcurrentRepolls: 1, } - err := params.Metrics.Register(prometheus.NewCounter(prometheus.CounterOpts{ + err := ctx.Registerer.Register(prometheus.NewCounter(prometheus.CounterOpts{ Name: "tx_rejected", })) if err != nil { t.Fatal(err) } graph := factory.New() - if err := graph.Initialize(snow.DefaultContextTest(), params); err == nil { + if err := graph.Initialize(ctx, params); err == nil { t.Fatalf("should have errored due to a duplicated metric") } } @@ -180,7 +180,6 @@ func ParamsTest(t *testing.T, factory Factory) { graph := factory.New() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -190,7 +189,7 @@ func ParamsTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -210,7 +209,6 @@ func IssuedTest(t *testing.T, factory Factory) { graph := factory.New() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -220,7 +218,7 @@ func IssuedTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -244,7 +242,6 @@ func LeftoverInputTest(t *testing.T, factory Factory) { graph := factory.New() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -254,7 +251,7 @@ func LeftoverInputTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -301,7 +298,6 @@ func LowerConfidenceTest(t *testing.T, factory Factory) { graph := factory.New() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -311,7 +307,7 @@ func LowerConfidenceTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -360,7 +356,6 @@ func MiddleConfidenceTest(t *testing.T, factory Factory) { graph := factory.New() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -370,7 +365,7 @@ func MiddleConfidenceTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -424,7 +419,6 @@ func IndependentTest(t *testing.T, factory Factory) { graph := factory.New() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 2, @@ -434,7 +428,7 @@ func IndependentTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -489,7 +483,6 @@ func VirtuousTest(t *testing.T, factory Factory) { graph := factory.New() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -499,7 +492,7 @@ func VirtuousTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -535,7 +528,6 @@ func IsVirtuousTest(t *testing.T, factory Factory) { graph := factory.New() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -545,7 +537,7 @@ func IsVirtuousTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - if err := graph.Initialize(snow.DefaultContextTest(), params); err != nil { + if err := graph.Initialize(snow.DefaultConsensusContextTest(), params); err != nil { t.Fatal(err) } @@ -591,7 +583,6 @@ func QuiesceTest(t *testing.T, factory Factory) { graph := factory.New() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -601,7 +592,7 @@ func QuiesceTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -632,7 +623,6 @@ func AcceptingDependencyTest(t *testing.T, factory Factory) { purple.InputIDsV = append(purple.InputIDsV, ids.Empty.Prefix(8)) params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -642,7 +632,7 @@ func AcceptingDependencyTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - if err := graph.Initialize(snow.DefaultContextTest(), params); err != nil { + if err := graph.Initialize(snow.DefaultConsensusContextTest(), params); err != nil { t.Fatal(err) } @@ -774,7 +764,6 @@ func AcceptingSlowDependencyTest(t *testing.T, factory Factory) { } params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -784,7 +773,7 @@ func AcceptingSlowDependencyTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -921,7 +910,6 @@ func RejectingDependencyTest(t *testing.T, factory Factory) { purple.InputIDsV = append(purple.InputIDsV, ids.Empty.Prefix(8)) params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -931,7 +919,7 @@ func RejectingDependencyTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -1023,7 +1011,6 @@ func VacuouslyAcceptedTest(t *testing.T, factory Factory) { }} params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1033,7 +1020,7 @@ func VacuouslyAcceptedTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -1051,7 +1038,6 @@ func ConflictsTest(t *testing.T, factory Factory) { graph := factory.New() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1061,7 +1047,7 @@ func ConflictsTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -1103,7 +1089,6 @@ func VirtuousDependsOnRogueTest(t *testing.T, factory Factory) { graph := factory.New() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1113,7 +1098,7 @@ func VirtuousDependsOnRogueTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -1178,7 +1163,6 @@ func ErrorOnVacuouslyAcceptedTest(t *testing.T, factory Factory) { }} params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1188,7 +1172,7 @@ func ErrorOnVacuouslyAcceptedTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -1209,7 +1193,6 @@ func ErrorOnAcceptedTest(t *testing.T, factory Factory) { purple.InputIDsV = append(purple.InputIDsV, ids.Empty.Prefix(4)) params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1219,7 +1202,7 @@ func ErrorOnAcceptedTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -1254,7 +1237,6 @@ func ErrorOnRejectingLowerConfidenceConflictTest(t *testing.T, factory Factory) pink.InputIDsV = append(pink.InputIDsV, X) params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1264,7 +1246,7 @@ func ErrorOnRejectingLowerConfidenceConflictTest(t *testing.T, factory Factory) MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -1301,7 +1283,6 @@ func ErrorOnRejectingHigherConfidenceConflictTest(t *testing.T, factory Factory) pink.InputIDsV = append(pink.InputIDsV, X) params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1311,7 +1292,7 @@ func ErrorOnRejectingHigherConfidenceConflictTest(t *testing.T, factory Factory) MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } @@ -1333,7 +1314,6 @@ func UTXOCleanupTest(t *testing.T, factory Factory) { graph := factory.New() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, @@ -1343,7 +1323,7 @@ func UTXOCleanupTest(t *testing.T, factory Factory) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) assert.NoError(t, err) err = graph.Add(Red) @@ -1381,7 +1361,6 @@ func StringTest(t *testing.T, factory Factory, prefix string) { graph := factory.New() params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 2, Alpha: 2, BetaVirtuous: 1, @@ -1391,7 +1370,7 @@ func StringTest(t *testing.T, factory Factory, prefix string) { MaxOutstandingItems: 1, MaxItemProcessingTime: 1, } - err := graph.Initialize(snow.DefaultContextTest(), params) + err := graph.Initialize(snow.DefaultConsensusContextTest(), params) if err != nil { t.Fatal(err) } diff --git a/snow/consensus/snowstorm/directed.go b/snow/consensus/snowstorm/directed.go index 848375979d5a..9fe0e2d50241 100644 --- a/snow/consensus/snowstorm/directed.go +++ b/snow/consensus/snowstorm/directed.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowstorm @@ -52,7 +52,7 @@ type directedTx struct { // Initialize implements the Consensus interface func (dg *Directed) Initialize( - ctx *snow.Context, + ctx *snow.ConsensusContext, params sbcon.Parameters, ) error { dg.txs = make(map[ids.ID]*directedTx) diff --git a/snow/consensus/snowstorm/directed_test.go b/snow/consensus/snowstorm/directed_test.go index 4b7a4e6c2c32..ad22e06f6417 100644 --- a/snow/consensus/snowstorm/directed_test.go +++ b/snow/consensus/snowstorm/directed_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowstorm diff --git a/snow/consensus/snowstorm/equality_test.go b/snow/consensus/snowstorm/equality_test.go index d93038c557ad..4409deb8b3a3 100644 --- a/snow/consensus/snowstorm/equality_test.go +++ b/snow/consensus/snowstorm/equality_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowstorm @@ -6,8 +6,6 @@ package snowstorm import ( "testing" - "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/utils/sampler" sbcon "github.com/ava-labs/avalanchego/snow/consensus/snowball" @@ -21,7 +19,6 @@ func TestConflictGraphEquality(t *testing.T) { maxInputConflicts := 2 numNodes := 100 params := sbcon.Parameters{ - Metrics: prometheus.NewRegistry(), K: 20, Alpha: 11, BetaVirtuous: 20, diff --git a/snow/consensus/snowstorm/factory.go b/snow/consensus/snowstorm/factory.go index 839ca5cd5a61..71f8c122f139 100644 --- a/snow/consensus/snowstorm/factory.go +++ b/snow/consensus/snowstorm/factory.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowstorm diff --git a/snow/consensus/snowstorm/input.go b/snow/consensus/snowstorm/input.go index 76e17c3677b8..c4864e42b5bc 100644 --- a/snow/consensus/snowstorm/input.go +++ b/snow/consensus/snowstorm/input.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowstorm @@ -70,7 +70,7 @@ type inputUTXO struct { } // Initialize implements the ConflictGraph interface -func (ig *Input) Initialize(ctx *snow.Context, params sbcon.Parameters) error { +func (ig *Input) Initialize(ctx *snow.ConsensusContext, params sbcon.Parameters) error { ig.txs = make(map[ids.ID]*inputTx) ig.utxos = make(map[ids.ID]inputUTXO) diff --git a/snow/consensus/snowstorm/input_test.go b/snow/consensus/snowstorm/input_test.go index daa7239c2008..49e478ae1851 100644 --- a/snow/consensus/snowstorm/input_test.go +++ b/snow/consensus/snowstorm/input_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowstorm diff --git a/snow/consensus/snowstorm/network_test.go b/snow/consensus/snowstorm/network_test.go index e3a01bd71ecf..3ae1d440448c 100644 --- a/snow/consensus/snowstorm/network_test.go +++ b/snow/consensus/snowstorm/network_test.go @@ -1,11 +1,9 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowstorm import ( - "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/choices" @@ -94,8 +92,7 @@ func (n *Network) Initialize( } func (n *Network) AddNode(cg Consensus) error { - n.params.Metrics = prometheus.NewRegistry() - if err := cg.Initialize(snow.DefaultContextTest(), n.params); err != nil { + if err := cg.Initialize(snow.DefaultConsensusContextTest(), n.params); err != nil { return err } diff --git a/snow/consensus/snowstorm/snowball.go b/snow/consensus/snowstorm/snowball.go index 1a4eb47bddf8..6db6651412a2 100644 --- a/snow/consensus/snowstorm/snowball.go +++ b/snow/consensus/snowstorm/snowball.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowstorm diff --git a/snow/consensus/snowstorm/test_tx.go b/snow/consensus/snowstorm/test_tx.go index b16ec4715696..54f94b43453e 100644 --- a/snow/consensus/snowstorm/test_tx.go +++ b/snow/consensus/snowstorm/test_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowstorm diff --git a/snow/consensus/snowstorm/tx.go b/snow/consensus/snowstorm/tx.go index bb5a91af855f..9f22180c423c 100644 --- a/snow/consensus/snowstorm/tx.go +++ b/snow/consensus/snowstorm/tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowstorm diff --git a/snow/context.go b/snow/context.go index 1f140940a49b..981491c869cd 100644 --- a/snow/context.go +++ b/snow/context.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snow @@ -7,26 +7,25 @@ import ( "crypto" "crypto/x509" "sync" - "time" "github.com/prometheus/client_golang/prometheus" "github.com/ava-labs/avalanchego/api/keystore" + "github.com/ava-labs/avalanchego/api/metrics" "github.com/ava-labs/avalanchego/chains/atomic" "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/logging" - "github.com/ava-labs/avalanchego/utils/timer/mockable" ) type EventDispatcher interface { - Issue(ctx *Context, containerID ids.ID, container []byte) error + Issue(ctx *ConsensusContext, containerID ids.ID, container []byte) error // If the returned error is non-nil, the chain associated with [ctx] should shut // down and not commit [container] or any other container to its database as accepted. // Accept must be called before [containerID] is committed to the VM as accepted. - Accept(ctx *Context, containerID ids.ID, container []byte) error - Reject(ctx *Context, containerID ids.ID, container []byte) error + Accept(ctx *ConsensusContext, containerID ids.ID, container []byte) error + Reject(ctx *ConsensusContext, containerID ids.ID, container []byte) error } type SubnetLookup interface { @@ -53,21 +52,27 @@ type Context struct { XChainID ids.ID AVAXAssetID ids.ID - Log logging.Logger + Log logging.Logger + Lock sync.RWMutex + Keystore keystore.BlockchainKeystore + SharedMemory atomic.SharedMemory + BCLookup ids.AliaserReader + SNLookup SubnetLookup + Metrics metrics.OptionalGatherer + + // snowman++ attributes + ValidatorState validators.State // interface for P-Chain validators + StakingLeafSigner crypto.Signer // block signer + StakingCertLeaf *x509.Certificate // block certificate +} + +type ConsensusContext struct { + *Context + + Registerer prometheus.Registerer + DecisionDispatcher EventDispatcher ConsensusDispatcher EventDispatcher - Lock sync.RWMutex - Keystore keystore.BlockchainKeystore - SharedMemory atomic.SharedMemory - BCLookup ids.AliaserReader - SNLookup SubnetLookup - Namespace string - Metrics prometheus.Registerer - - // Epoch management - EpochFirstTransition time.Time - EpochDuration time.Duration - Clock mockable.Clock // Non-zero iff this chain bootstrapped. bootstrapped utils.AtomicBool @@ -77,73 +82,126 @@ type Context struct { // Indicates this chain is available to only validators. validatorOnly utils.AtomicBool - - // snowman++ attributes - ValidatorState validators.State // interface for P-Chain validators - StakingLeafSigner crypto.Signer // block signer - StakingCertLeaf *x509.Certificate // block certificate } // IsBootstrapped returns true iff this chain is done bootstrapping -func (ctx *Context) IsBootstrapped() bool { +func (ctx *ConsensusContext) IsBootstrapped() bool { return ctx.bootstrapped.GetValue() } // Bootstrapped marks this chain as done bootstrapping -func (ctx *Context) Bootstrapped() { +func (ctx *ConsensusContext) Bootstrapped() { ctx.bootstrapped.SetValue(true) } // IsExecuting returns true iff this chain is still executing transactions. -func (ctx *Context) IsExecuting() bool { +func (ctx *ConsensusContext) IsExecuting() bool { return ctx.executing.GetValue() } // Executing marks this chain as executing or not. // Set to "true" if there's an ongoing transaction. -func (ctx *Context) Executing(b bool) { +func (ctx *ConsensusContext) Executing(b bool) { ctx.executing.SetValue(b) } // IsValidatorOnly returns true iff this chain is available only to validators -func (ctx *Context) IsValidatorOnly() bool { +func (ctx *ConsensusContext) IsValidatorOnly() bool { return ctx.validatorOnly.GetValue() } // SetValidatorOnly marks this chain as available only to validators -func (ctx *Context) SetValidatorOnly() { +func (ctx *ConsensusContext) SetValidatorOnly() { ctx.validatorOnly.SetValue(true) } -// Epoch this context thinks it's in based on the wall clock time. -func (ctx *Context) Epoch() uint32 { - now := ctx.Clock.Time() - timeSinceFirstEpochTransition := now.Sub(ctx.EpochFirstTransition) - epochsSinceFirstTransition := timeSinceFirstEpochTransition / ctx.EpochDuration - currentEpoch := epochsSinceFirstTransition + 1 - if currentEpoch < 0 { - return 0 +func DefaultContextTest() *Context { + return &Context{ + NetworkID: 0, + SubnetID: ids.Empty, + ChainID: ids.Empty, + NodeID: ids.ShortEmpty, + Log: logging.NoLog{}, + BCLookup: ids.NewAliaser(), + Metrics: metrics.NewOptionalGatherer(), } - return uint32(currentEpoch) } -func DefaultContextTest() *Context { - return &Context{ - NetworkID: 0, - SubnetID: ids.Empty, - ChainID: ids.Empty, - NodeID: ids.ShortEmpty, - Log: logging.NoLog{}, - DecisionDispatcher: emptyEventDispatcher{}, - ConsensusDispatcher: emptyEventDispatcher{}, - BCLookup: ids.NewAliaser(), - Namespace: "", - Metrics: prometheus.NewRegistry(), +func DefaultConsensusContextTest() *ConsensusContext { + return &ConsensusContext{ + Context: DefaultContextTest(), + Registerer: prometheus.NewRegistry(), + DecisionDispatcher: noOpEventDispatcher{}, + ConsensusDispatcher: noOpEventDispatcher{}, } } -type emptyEventDispatcher struct{} +type noOpEventDispatcher struct{} -func (emptyEventDispatcher) Issue(*Context, ids.ID, []byte) error { return nil } -func (emptyEventDispatcher) Accept(*Context, ids.ID, []byte) error { return nil } -func (emptyEventDispatcher) Reject(*Context, ids.ID, []byte) error { return nil } +func (noOpEventDispatcher) Issue(*ConsensusContext, ids.ID, []byte) error { return nil } +func (noOpEventDispatcher) Accept(*ConsensusContext, ids.ID, []byte) error { return nil } +func (noOpEventDispatcher) Reject(*ConsensusContext, ids.ID, []byte) error { return nil } + +var _ EventDispatcher = &EventDispatcherTracker{} + +func NewEventDispatcherTracker() *EventDispatcherTracker { + return &EventDispatcherTracker{ + issued: make(map[ids.ID]int), + accepted: make(map[ids.ID]int), + rejected: make(map[ids.ID]int), + } +} + +// EventDispatcherTracker tracks the dispatched events by its ID and counts. +// Useful for testing. +type EventDispatcherTracker struct { + mu sync.RWMutex + // maps "issued" ID to its count + issued map[ids.ID]int + // maps "accepted" ID to its count + accepted map[ids.ID]int + // maps "rejected" ID to its count + rejected map[ids.ID]int +} + +func (evd *EventDispatcherTracker) IsIssued(containerID ids.ID) (int, bool) { + evd.mu.RLock() + cnt, ok := evd.issued[containerID] + evd.mu.RUnlock() + return cnt, ok +} + +func (evd *EventDispatcherTracker) Issue(ctx *ConsensusContext, containerID ids.ID, container []byte) error { + evd.mu.Lock() + evd.issued[containerID]++ + evd.mu.Unlock() + return nil +} + +func (evd *EventDispatcherTracker) Accept(ctx *ConsensusContext, containerID ids.ID, container []byte) error { + evd.mu.Lock() + evd.accepted[containerID]++ + evd.mu.Unlock() + return nil +} + +func (evd *EventDispatcherTracker) IsAccepted(containerID ids.ID) (int, bool) { + evd.mu.RLock() + cnt, ok := evd.accepted[containerID] + evd.mu.RUnlock() + return cnt, ok +} + +func (evd *EventDispatcherTracker) Reject(ctx *ConsensusContext, containerID ids.ID, container []byte) error { + evd.mu.Lock() + evd.rejected[containerID]++ + evd.mu.Unlock() + return nil +} + +func (evd *EventDispatcherTracker) IsRejected(containerID ids.ID) (int, bool) { + evd.mu.RLock() + cnt, ok := evd.rejected[containerID] + evd.mu.RUnlock() + return cnt, ok +} diff --git a/snow/engine/avalanche/bootstrap/bootstrapper.go b/snow/engine/avalanche/bootstrap/bootstrapper.go index 94da1730f480..b8dcf9e614de 100644 --- a/snow/engine/avalanche/bootstrap/bootstrapper.go +++ b/snow/engine/avalanche/bootstrap/bootstrapper.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package bootstrap @@ -304,7 +304,7 @@ func (b *Bootstrapper) MultiPut(vdr ids.ShortID, requestID uint32, vtxs [][]byte return nil } b.Ctx.Log.Debug("failed to parse requested vertex %s: %s", requestedVtxID, err) - b.Ctx.Log.Verbo("vertex: %s", formatting.DumpBytes{Bytes: vtxs[0]}) + b.Ctx.Log.Verbo("vertex: %s", formatting.DumpBytes(vtxs[0])) return b.fetch(requestedVtxID) } @@ -340,7 +340,7 @@ func (b *Bootstrapper) MultiPut(vdr ids.ShortID, requestID uint32, vtxs [][]byte vtx, err := b.Manager.ParseVtx(vtxBytes) // Persists the vtx if err != nil { b.Ctx.Log.Debug("failed to parse vertex: %s", err) - b.Ctx.Log.Verbo("vertex: %s", formatting.DumpBytes{Bytes: vtxBytes}) + b.Ctx.Log.Verbo("vertex: %s", formatting.DumpBytes(vtxBytes)) break } vtxID := vtx.ID() diff --git a/snow/engine/avalanche/bootstrap/bootstrapper_test.go b/snow/engine/avalanche/bootstrap/bootstrapper_test.go index 324396dd5318..b8aec55a4e78 100644 --- a/snow/engine/avalanche/bootstrap/bootstrapper_test.go +++ b/snow/engine/avalanche/bootstrap/bootstrapper_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package bootstrap @@ -22,7 +22,6 @@ import ( "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/engine/common/queue" "github.com/ava-labs/avalanchego/snow/validators" - "github.com/ava-labs/avalanchego/utils/constants" ) var ( @@ -31,7 +30,7 @@ var ( ) func newConfig(t *testing.T) (Config, ids.ShortID, *common.SenderTest, *vertex.TestManager, *vertex.TestVM) { - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() peers := validators.NewSet() db := memdb.New() @@ -58,11 +57,11 @@ func newConfig(t *testing.T) (Config, ids.ShortID, *common.SenderTest, *vertex.T t.Fatal(err) } - vtxBlocker, err := queue.NewWithMissing(prefixdb.New([]byte("vtx"), db), ctx.Namespace+"_vtx", ctx.Metrics) + vtxBlocker, err := queue.NewWithMissing(prefixdb.New([]byte("vtx"), db), "vtx", ctx.Registerer) if err != nil { t.Fatal(err) } - txBlocker, err := queue.New(prefixdb.New([]byte("tx"), db), ctx.Namespace+"_tx", ctx.Metrics) + txBlocker, err := queue.New(prefixdb.New([]byte("tx"), db), "tx", ctx.Registerer) if err != nil { t.Fatal(err) } @@ -131,7 +130,7 @@ func TestBootstrapperSingleFrontier(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s_bs", constants.PlatformName, config.Ctx.ChainID), + fmt.Sprintf("chain_%s_bs", config.Ctx.ChainID), prometheus.NewRegistry(), ) if err != nil { @@ -232,7 +231,7 @@ func TestBootstrapperByzantineResponses(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s_bs", constants.PlatformName, config.Ctx.ChainID), + fmt.Sprintf("chain_%s_bs", config.Ctx.ChainID), prometheus.NewRegistry(), ) if err != nil { @@ -408,7 +407,7 @@ func TestBootstrapperTxDependencies(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s_bs", constants.PlatformName, config.Ctx.ChainID), + fmt.Sprintf("chain_%s_bs", config.Ctx.ChainID), prometheus.NewRegistry(), ) if err != nil { @@ -551,7 +550,7 @@ func TestBootstrapperMissingTxDependency(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s_bs", constants.PlatformName, config.Ctx.ChainID), + fmt.Sprintf("chain_%s_bs", config.Ctx.ChainID), prometheus.NewRegistry(), ) if err != nil { @@ -638,7 +637,7 @@ func TestBootstrapperAcceptedFrontier(t *testing.T) { err := bs.Initialize( config, nil, - fmt.Sprintf("%s_%s_bs", constants.PlatformName, config.Ctx.ChainID), + fmt.Sprintf("chain_%s_bs", config.Ctx.ChainID), prometheus.NewRegistry(), ) if err != nil { @@ -693,7 +692,7 @@ func TestBootstrapperFilterAccepted(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s_bs", constants.PlatformName, config.Ctx.ChainID), + fmt.Sprintf("chain_%s_bs", config.Ctx.ChainID), prometheus.NewRegistry(), ) if err != nil { @@ -776,7 +775,7 @@ func TestBootstrapperIncompleteMultiPut(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s_bs", constants.PlatformName, config.Ctx.ChainID), + fmt.Sprintf("chain_%s_bs", config.Ctx.ChainID), prometheus.NewRegistry(), ) if err != nil { @@ -895,7 +894,7 @@ func TestBootstrapperFinalized(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s_bs", constants.PlatformName, config.Ctx.ChainID), + fmt.Sprintf("chain_%s_bs", config.Ctx.ChainID), prometheus.NewRegistry(), ) if err != nil { @@ -1025,7 +1024,7 @@ func TestBootstrapperAcceptsMultiPutParents(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s_bs", constants.PlatformName, config.Ctx.ChainID), + fmt.Sprintf("chain_%s_bs", config.Ctx.ChainID), prometheus.NewRegistry(), ) if err != nil { @@ -1191,7 +1190,7 @@ func TestRestartBootstrapping(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s_bs", constants.PlatformName, config.Ctx.ChainID), + fmt.Sprintf("chain_%s_bs", config.Ctx.ChainID), prometheus.NewRegistry(), ) if err != nil { diff --git a/snow/engine/avalanche/bootstrap/metrics.go b/snow/engine/avalanche/bootstrap/metrics.go index df5781653417..8399040fd7fe 100644 --- a/snow/engine/avalanche/bootstrap/metrics.go +++ b/snow/engine/avalanche/bootstrap/metrics.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package bootstrap diff --git a/snow/engine/avalanche/bootstrap/tx_job.go b/snow/engine/avalanche/bootstrap/tx_job.go index b11fef12635b..9825d0bf4f73 100644 --- a/snow/engine/avalanche/bootstrap/tx_job.go +++ b/snow/engine/avalanche/bootstrap/tx_job.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package bootstrap diff --git a/snow/engine/avalanche/bootstrap/vertex_job.go b/snow/engine/avalanche/bootstrap/vertex_job.go index 0c91f6b553f3..0672d74833f8 100644 --- a/snow/engine/avalanche/bootstrap/vertex_job.go +++ b/snow/engine/avalanche/bootstrap/vertex_job.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package bootstrap diff --git a/snow/engine/avalanche/config.go b/snow/engine/avalanche/config.go index fe8e4205c6bc..38e169d67730 100644 --- a/snow/engine/avalanche/config.go +++ b/snow/engine/avalanche/config.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche diff --git a/snow/engine/avalanche/config_test.go b/snow/engine/avalanche/config_test.go index 3373826d6d2b..bc7972d1e700 100644 --- a/snow/engine/avalanche/config_test.go +++ b/snow/engine/avalanche/config_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche @@ -28,7 +28,6 @@ func DefaultConfig() Config { }, Params: avalanche.Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 1, diff --git a/snow/engine/avalanche/convincer.go b/snow/engine/avalanche/convincer.go index 50b210a798db..1e8adfe3e78b 100644 --- a/snow/engine/avalanche/convincer.go +++ b/snow/engine/avalanche/convincer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche diff --git a/snow/engine/avalanche/engine.go b/snow/engine/avalanche/engine.go index da5583816120..8dafa6daad55 100644 --- a/snow/engine/avalanche/engine.go +++ b/snow/engine/avalanche/engine.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche diff --git a/snow/engine/avalanche/issuer.go b/snow/engine/avalanche/issuer.go index 5b5bf02b5e03..ce681b6e7329 100644 --- a/snow/engine/avalanche/issuer.go +++ b/snow/engine/avalanche/issuer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche diff --git a/snow/engine/avalanche/metrics.go b/snow/engine/avalanche/metrics.go index 6d0b86d63db5..dd81e3eefa25 100644 --- a/snow/engine/avalanche/metrics.go +++ b/snow/engine/avalanche/metrics.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche diff --git a/snow/engine/avalanche/mocks/engine.go b/snow/engine/avalanche/mocks/engine.go index 458645cc45db..403c95e700e1 100644 --- a/snow/engine/avalanche/mocks/engine.go +++ b/snow/engine/avalanche/mocks/engine.go @@ -135,15 +135,15 @@ func (_m *Engine) Connected(validatorID ids.ShortID) error { } // Context provides a mock function with given fields: -func (_m *Engine) Context() *snow.Context { +func (_m *Engine) Context() *snow.ConsensusContext { ret := _m.Called() - var r0 *snow.Context - if rf, ok := ret.Get(0).(func() *snow.Context); ok { + var r0 *snow.ConsensusContext + if rf, ok := ret.Get(0).(func() *snow.ConsensusContext); ok { r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*snow.Context) + r0 = ret.Get(0).(*snow.ConsensusContext) } } diff --git a/snow/engine/avalanche/state/prefixed_state.go b/snow/engine/avalanche/state/prefixed_state.go index 304df1cb740f..bd962bb04af4 100644 --- a/snow/engine/avalanche/state/prefixed_state.go +++ b/snow/engine/avalanche/state/prefixed_state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state diff --git a/snow/engine/avalanche/state/serializer.go b/snow/engine/avalanche/state/serializer.go index 35dfdfe64f0c..80b317ba9ef8 100644 --- a/snow/engine/avalanche/state/serializer.go +++ b/snow/engine/avalanche/state/serializer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. // Package state manages the meta-data required by consensus for an avalanche @@ -66,10 +66,8 @@ func (s *Serializer) ParseVtx(b []byte) (avalanche.Vertex, error) { // BuildVtx implements the avalanche.State interface func (s *Serializer) BuildVtx( - epoch uint32, parentIDs []ids.ID, txs []snowstorm.Tx, - restrictions []ids.ID, ) (avalanche.Vertex, error) { height := uint64(0) for _, parentID := range parentIDs { @@ -93,10 +91,8 @@ func (s *Serializer) BuildVtx( vtx, err := vertex.Build( s.ctx.ChainID, height, - epoch, parentIDs, txBytes, - restrictions, ) if err != nil { return nil, err diff --git a/snow/engine/avalanche/state/state.go b/snow/engine/avalanche/state/state.go index 363e351dc184..1741f3296fe5 100644 --- a/snow/engine/avalanche/state/state.go +++ b/snow/engine/avalanche/state/state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state @@ -35,7 +35,7 @@ func (s *state) Vertex(id ids.ID) vertex.StatelessVertex { } s.serializer.ctx.Log.Error("Parsing failed on saved vertex.\nPrefixed key = %s\nBytes = %s", id, - formatting.DumpBytes{Bytes: b}) + formatting.DumpBytes(b)) } s.dbCache.Put(id, nil) // Cache the miss @@ -104,7 +104,7 @@ func (s *state) Edge(id ids.ID) []ids.ID { } s.serializer.ctx.Log.Error("Parsing failed on saved ids.\nPrefixed key = %s\nBytes = %s", id, - formatting.DumpBytes{Bytes: b}) + formatting.DumpBytes(b)) } s.dbCache.Put(id, nil) // Cache the miss diff --git a/snow/engine/avalanche/state/unique_vertex.go b/snow/engine/avalanche/state/unique_vertex.go index 483399b78c3b..31865b61fdaf 100644 --- a/snow/engine/avalanche/state/unique_vertex.go +++ b/snow/engine/avalanche/state/unique_vertex.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state diff --git a/snow/engine/avalanche/state/unique_vertex_test.go b/snow/engine/avalanche/state/unique_vertex_test.go index 0acc3a4ed4f8..3254960f2a41 100644 --- a/snow/engine/avalanche/state/unique_vertex_test.go +++ b/snow/engine/avalanche/state/unique_vertex_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state @@ -79,10 +79,8 @@ func TestUniqueVertexCacheHit(t *testing.T) { vtx, err := vertex.Build( chainID, height, - 0, parentIDs, [][]byte{{0}}, - nil, ) if err != nil { t.Fatal(err) @@ -159,10 +157,8 @@ func TestUniqueVertexCacheMiss(t *testing.T) { innerVertex, err := vertex.Build( chainID, height, - 0, parentIDs, [][]byte{txBytes}, - nil, ) if err != nil { t.Fatal(err) @@ -272,10 +268,8 @@ func TestParseVertexWithInvalidTxs(t *testing.T) { statelessVertex, err := vertex.Build( ctx.ChainID, 0, - 0, nil, [][]byte{{1}}, - nil, ) if err != nil { t.Fatal(err) @@ -309,10 +303,8 @@ func TestParseVertexWithInvalidTxs(t *testing.T) { childStatelessVertex, err := vertex.Build( ctx.ChainID, 1, - 0, []ids.ID{vtxID}, [][]byte{{2}}, - nil, ) if err != nil { t.Fatal(err) diff --git a/snow/engine/avalanche/transitive.go b/snow/engine/avalanche/transitive.go index 261aaabac2cb..577c74cfeaab 100644 --- a/snow/engine/avalanche/transitive.go +++ b/snow/engine/avalanche/transitive.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche @@ -70,20 +70,20 @@ func (t *Transitive) Initialize(config Config) error { factory := poll.NewEarlyTermNoTraversalFactory(config.Params.Alpha) t.polls = poll.NewSet(factory, config.Ctx.Log, - config.Params.Namespace, - config.Params.Metrics, + "", + config.Ctx.Registerer, ) t.uniformSampler = sampler.NewUniform() - if err := t.metrics.Initialize(config.Params.Namespace, config.Params.Metrics); err != nil { + if err := t.metrics.Initialize("", config.Ctx.Registerer); err != nil { return err } return t.Bootstrapper.Initialize( config.Config, t.finishBootstrapping, - fmt.Sprintf("%s_bs", config.Params.Namespace), - config.Params.Metrics, + "bs", + config.Ctx.Registerer, ) } @@ -211,7 +211,7 @@ func (t *Transitive) Put(vdr ids.ShortID, requestID uint32, vtxID ids.ID, vtxByt vtx, err := t.Manager.ParseVtx(vtxBytes) if err != nil { t.Ctx.Log.Debug("failed to parse vertex %s due to: %s", vtxID, err) - t.Ctx.Log.Verbo("vertex:\n%s", formatting.DumpBytes{Bytes: vtxBytes}) + t.Ctx.Log.Verbo("vertex:\n%s", formatting.DumpBytes(vtxBytes)) return t.GetFailed(vdr, requestID) } if _, err := t.issueFrom(vdr, vtx); err != nil { @@ -296,7 +296,7 @@ func (t *Transitive) PushQuery(vdr ids.ShortID, requestID uint32, vtxID ids.ID, vtx, err := t.Manager.ParseVtx(vtxBytes) if err != nil { t.Ctx.Log.Debug("failed to parse vertex %s due to: %s", vtxID, err) - t.Ctx.Log.Verbo("vertex:\n%s", formatting.DumpBytes{Bytes: vtxBytes}) + t.Ctx.Log.Verbo("vertex:\n%s", formatting.DumpBytes(vtxBytes)) return nil } @@ -657,7 +657,7 @@ func (t *Transitive) issueBatch(txs []snowstorm.Tx) error { parentIDs[i] = virtuousIDs[int(index)] } - vtx, err := t.Manager.BuildVtx(0, parentIDs, txs, nil) + vtx, err := t.Manager.BuildVtx(parentIDs, txs) if err != nil { t.Ctx.Log.Warn("error building new vertex with %d parents and %d transactions", len(parentIDs), len(txs)) diff --git a/snow/engine/avalanche/transitive_test.go b/snow/engine/avalanche/transitive_test.go index 1f95f47929b4..5682896c5bc8 100644 --- a/snow/engine/avalanche/transitive_test.go +++ b/snow/engine/avalanche/transitive_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche @@ -8,10 +8,10 @@ import ( "errors" "testing" - "github.com/stretchr/testify/assert" - "github.com/prometheus/client_golang/prometheus" + "github.com/stretchr/testify/assert" + "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/choices" "github.com/ava-labs/avalanchego/snow/consensus/avalanche" @@ -413,7 +413,6 @@ func TestEngineMultipleQuery(t *testing.T) { config.Params = avalanche.Parameters{ Parameters: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 3, Alpha: 2, BetaVirtuous: 1, @@ -903,7 +902,7 @@ func TestEngineRejectDoubleSpendTx(t *testing.T) { t.Fatalf("Unknown vertex") panic("Should have errored") } - manager.BuildVtxF = func(_ uint32, _ []ids.ID, txs []snowstorm.Tx, _ []ids.ID) (avalanche.Vertex, error) { + manager.BuildVtxF = func(_ []ids.ID, txs []snowstorm.Tx) (avalanche.Vertex, error) { return &avalanche.TestVertex{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), @@ -1022,7 +1021,7 @@ func TestEngineRejectDoubleSpendIssuedTx(t *testing.T) { vm.CantBootstrapping = true vm.CantBootstrapped = true - manager.BuildVtxF = func(_ uint32, _ []ids.ID, txs []snowstorm.Tx, _ []ids.ID) (avalanche.Vertex, error) { + manager.BuildVtxF = func(_ []ids.ID, txs []snowstorm.Tx) (avalanche.Vertex, error) { return &avalanche.TestVertex{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), @@ -1237,7 +1236,7 @@ func TestEngineReissue(t *testing.T) { vm.CantBootstrapped = true lastVtx := new(avalanche.TestVertex) - manager.BuildVtxF = func(_ uint32, _ []ids.ID, txs []snowstorm.Tx, _ []ids.ID) (avalanche.Vertex, error) { + manager.BuildVtxF = func(_ []ids.ID, txs []snowstorm.Tx) (avalanche.Vertex, error) { lastVtx = &avalanche.TestVertex{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), @@ -1393,7 +1392,7 @@ func TestEngineLargeIssue(t *testing.T) { vm.CantBootstrapped = true lastVtx := new(avalanche.TestVertex) - manager.BuildVtxF = func(_ uint32, _ []ids.ID, txs []snowstorm.Tx, _ []ids.ID) (avalanche.Vertex, error) { + manager.BuildVtxF = func(_ []ids.ID, txs []snowstorm.Tx) (avalanche.Vertex, error) { lastVtx = &avalanche.TestVertex{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), @@ -2763,11 +2762,10 @@ func TestEngineReBootstrapFails(t *testing.T) { t.Fatal(err) } + config.Ctx.Registerer = prometheus.NewRegistry() + // re-register the Transitive te2 := &Transitive{} - config.Params.Namespace = "AcceptedFrontier" - config.Params.Metrics = prometheus.NewRegistry() - if err := te2.Initialize(config); err != nil { t.Fatal(err) } @@ -3208,7 +3206,7 @@ func TestEnginePartiallyValidVertex(t *testing.T) { } expectedVtxID := ids.GenerateTestID() - manager.BuildVtxF = func(_ uint32, _ []ids.ID, txs []snowstorm.Tx, _ []ids.ID) (avalanche.Vertex, error) { + manager.BuildVtxF = func(_ []ids.ID, txs []snowstorm.Tx) (avalanche.Vertex, error) { return &avalanche.TestVertex{ TestDecidable: choices.TestDecidable{ IDV: expectedVtxID, @@ -3771,7 +3769,7 @@ func TestEngineDuplicatedIssuance(t *testing.T) { vm.CantBootstrapped = true lastVtx := new(avalanche.TestVertex) - manager.BuildVtxF = func(_ uint32, _ []ids.ID, txs []snowstorm.Tx, _ []ids.ID) (avalanche.Vertex, error) { + manager.BuildVtxF = func(_ []ids.ID, txs []snowstorm.Tx) (avalanche.Vertex, error) { lastVtx = &avalanche.TestVertex{ TestDecidable: choices.TestDecidable{ IDV: ids.GenerateTestID(), @@ -3796,7 +3794,7 @@ func TestEngineDuplicatedIssuance(t *testing.T) { t.Fatalf("Should have issued txs differently") } - manager.BuildVtxF = func(uint32, []ids.ID, []snowstorm.Tx, []ids.ID) (avalanche.Vertex, error) { + manager.BuildVtxF = func([]ids.ID, []snowstorm.Tx) (avalanche.Vertex, error) { t.Fatalf("shouldn't have attempted to issue a duplicated tx") return nil, nil } @@ -4171,7 +4169,7 @@ func TestEngineIssue(t *testing.T) { vm.CantBootstrapped = true numBuilt := 0 - manager.BuildVtxF = func(_ uint32, _ []ids.ID, txs []snowstorm.Tx, _ []ids.ID) (avalanche.Vertex, error) { + manager.BuildVtxF = func(_ []ids.ID, txs []snowstorm.Tx) (avalanche.Vertex, error) { numBuilt++ vtx := &avalanche.TestVertex{ TestDecidable: choices.TestDecidable{ diff --git a/snow/engine/avalanche/vertex/builder.go b/snow/engine/avalanche/vertex/builder.go index 77e52bbada25..8ce8895b9a7c 100644 --- a/snow/engine/avalanche/vertex/builder.go +++ b/snow/engine/avalanche/vertex/builder.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex @@ -14,10 +14,8 @@ import ( type Builder interface { // Build a new vertex from the contents of a vertex BuildVtx( - epoch uint32, parentIDs []ids.ID, txs []snowstorm.Tx, - restrictions []ids.ID, ) (avalanche.Vertex, error) } @@ -25,23 +23,19 @@ type Builder interface { func Build( chainID ids.ID, height uint64, - epoch uint32, parentIDs []ids.ID, txs [][]byte, - restrictions []ids.ID, ) (StatelessVertex, error) { ids.SortIDs(parentIDs) SortHashOf(txs) - ids.SortIDs(restrictions) innerVtx := innerStatelessVertex{ - Version: noEpochTransitionsCodecVersion, - ChainID: chainID, - Height: height, - Epoch: epoch, - ParentIDs: parentIDs, - Txs: txs, - Restrictions: restrictions, + Version: codecVersion, + ChainID: chainID, + Height: height, + Epoch: 0, + ParentIDs: parentIDs, + Txs: txs, } if err := innerVtx.Verify(); err != nil { return nil, err diff --git a/snow/engine/avalanche/vertex/builder_test.go b/snow/engine/avalanche/vertex/builder_test.go index 180d4b02c3bd..1381e23caa70 100644 --- a/snow/engine/avalanche/vertex/builder_test.go +++ b/snow/engine/avalanche/vertex/builder_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex @@ -14,17 +14,13 @@ import ( func TestBuildInvalid(t *testing.T) { chainID := ids.ID{1} height := uint64(2) - epoch := uint32(0) parentIDs := []ids.ID{{4}, {5}} - txs := [][]byte{{7}, {6}} - restrictions := []ids.ID{{8}, {9}} + txs := [][]byte{{6}, {6}} _, err := Build( chainID, height, - epoch, parentIDs, txs, - restrictions, ) assert.Error(t, err, "build should have errored because restrictions were provided in epoch 0") } @@ -32,23 +28,17 @@ func TestBuildInvalid(t *testing.T) { func TestBuildValid(t *testing.T) { chainID := ids.ID{1} height := uint64(2) - epoch := uint32(0) parentIDs := []ids.ID{{4}, {5}} txs := [][]byte{{7}, {6}} - restrictions := []ids.ID{} vtx, err := Build( chainID, height, - epoch, parentIDs, txs, - restrictions, ) assert.NoError(t, err) assert.Equal(t, chainID, vtx.ChainID()) assert.Equal(t, height, vtx.Height()) - assert.Equal(t, epoch, vtx.Epoch()) assert.Equal(t, parentIDs, vtx.ParentIDs()) assert.Equal(t, txs, vtx.Txs()) - assert.Equal(t, restrictions, vtx.Restrictions()) } diff --git a/snow/engine/avalanche/vertex/codec.go b/snow/engine/avalanche/vertex/codec.go index dbb4242c43eb..137d11b784d9 100644 --- a/snow/engine/avalanche/vertex/codec.go +++ b/snow/engine/avalanche/vertex/codec.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex @@ -6,36 +6,25 @@ package vertex 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/units" - "github.com/ava-labs/avalanchego/utils/wrappers" ) const ( // maxSize is the maximum allowed vertex size. It is necessary to deter DoS maxSize = units.MiB - // noEpochTransitionsCodecVersion is the codec version that was used when - // there were no epoch transitions - noEpochTransitionsCodecVersion = uint16(0) - - // apricotCodecVersion is the codec version that was used when we added - // epoch transitions - apricotCodecVersion = uint16(1) + // codecVersion is the only supported codec version + codecVersion uint16 = 0 ) var c codec.Manager func init() { - codecV0 := linearcodec.New("serializeV0", maxSize) - codecV1 := linearcodec.New("serializeV1", maxSize) + lc := linearcodec.New(reflectcodec.DefaultTagName, maxSize) c = codec.NewManager(maxSize) - errs := wrappers.Errs{} - errs.Add( - c.RegisterCodec(noEpochTransitionsCodecVersion, codecV0), - c.RegisterCodec(apricotCodecVersion, codecV1), - ) - if errs.Errored() { - panic(errs.Err) + if err := c.RegisterCodec(codecVersion, lc); err != nil { + panic(err) } } diff --git a/snow/engine/avalanche/vertex/heap.go b/snow/engine/avalanche/vertex/heap.go index 156d656a1091..c5a34d819fb2 100644 --- a/snow/engine/avalanche/vertex/heap.go +++ b/snow/engine/avalanche/vertex/heap.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex diff --git a/snow/engine/avalanche/vertex/heap_test.go b/snow/engine/avalanche/vertex/heap_test.go index caa5fb6f3c9a..52399a9fc4bb 100644 --- a/snow/engine/avalanche/vertex/heap_test.go +++ b/snow/engine/avalanche/vertex/heap_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex diff --git a/snow/engine/avalanche/vertex/manager.go b/snow/engine/avalanche/vertex/manager.go index e4c795a2769a..c39c22ebde8a 100644 --- a/snow/engine/avalanche/vertex/manager.go +++ b/snow/engine/avalanche/vertex/manager.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex diff --git a/snow/engine/avalanche/vertex/parser.go b/snow/engine/avalanche/vertex/parser.go index e37f7575c480..216cf4e7a3c4 100644 --- a/snow/engine/avalanche/vertex/parser.go +++ b/snow/engine/avalanche/vertex/parser.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex diff --git a/snow/engine/avalanche/vertex/parser_test.go b/snow/engine/avalanche/vertex/parser_test.go index 41f3e89e31ef..f7f959588c18 100644 --- a/snow/engine/avalanche/vertex/parser_test.go +++ b/snow/engine/avalanche/vertex/parser_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex @@ -19,17 +19,13 @@ func TestParseInvalid(t *testing.T) { func TestParseValid(t *testing.T) { chainID := ids.ID{1} height := uint64(2) - epoch := uint32(0) parentIDs := []ids.ID{{4}, {5}} txs := [][]byte{{6}, {7}} - restrictions := []ids.ID(nil) vtx, err := Build( chainID, height, - epoch, parentIDs, txs, - restrictions, ) assert.NoError(t, err) diff --git a/snow/engine/avalanche/vertex/sorting.go b/snow/engine/avalanche/vertex/sorting.go index 10330a655e26..f8fe242fa23f 100644 --- a/snow/engine/avalanche/vertex/sorting.go +++ b/snow/engine/avalanche/vertex/sorting.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex diff --git a/snow/engine/avalanche/vertex/stateless_vertex.go b/snow/engine/avalanche/vertex/stateless_vertex.go index 96238a22b958..530b61bff7d4 100644 --- a/snow/engine/avalanche/vertex/stateless_vertex.go +++ b/snow/engine/avalanche/vertex/stateless_vertex.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex @@ -20,16 +20,13 @@ const ( ) var ( - errBadVersion = errors.New("invalid version") - errBadEpoch = errors.New("invalid epoch") - errFutureField = errors.New("field specified in a previous version") - errTooManyparentIDs = fmt.Errorf("vertex contains more than %d parentIDs", maxNumParents) - errNoOperations = errors.New("vertex contains no operations") - errTooManyTxs = fmt.Errorf("vertex contains more than %d transactions", maxTxsPerVtx) - errTooManyRestrictions = fmt.Errorf("vertex contains more than %d restrictions", maxTxsPerVtx) - errInvalidParents = errors.New("vertex contains non-sorted or duplicated parentIDs") - errInvalidRestrictions = errors.New("vertex contains non-sorted or duplicated restrictions") - errInvalidTxs = errors.New("vertex contains non-sorted or duplicated transactions") + errBadVersion = errors.New("invalid version") + errBadEpoch = errors.New("invalid epoch") + errTooManyparentIDs = fmt.Errorf("vertex contains more than %d parentIDs", maxNumParents) + errNoOperations = errors.New("vertex contains no operations") + errTooManyTxs = fmt.Errorf("vertex contains more than %d transactions", maxTxsPerVtx) + errInvalidParents = errors.New("vertex contains non-sorted or duplicated parentIDs") + errInvalidTxs = errors.New("vertex contains non-sorted or duplicated transactions") _ StatelessVertex = statelessVertex{} ) @@ -45,7 +42,6 @@ type StatelessVertex interface { Epoch() uint32 ParentIDs() []ids.ID Txs() [][]byte - Restrictions() []ids.ID } type statelessVertex struct { @@ -59,24 +55,22 @@ type statelessVertex struct { bytes []byte } -func (v statelessVertex) ID() ids.ID { return v.id } -func (v statelessVertex) Bytes() []byte { return v.bytes } -func (v statelessVertex) Version() uint16 { return v.innerStatelessVertex.Version } -func (v statelessVertex) ChainID() ids.ID { return v.innerStatelessVertex.ChainID } -func (v statelessVertex) Height() uint64 { return v.innerStatelessVertex.Height } -func (v statelessVertex) Epoch() uint32 { return v.innerStatelessVertex.Epoch } -func (v statelessVertex) ParentIDs() []ids.ID { return v.innerStatelessVertex.ParentIDs } -func (v statelessVertex) Txs() [][]byte { return v.innerStatelessVertex.Txs } -func (v statelessVertex) Restrictions() []ids.ID { return v.innerStatelessVertex.Restrictions } +func (v statelessVertex) ID() ids.ID { return v.id } +func (v statelessVertex) Bytes() []byte { return v.bytes } +func (v statelessVertex) Version() uint16 { return v.innerStatelessVertex.Version } +func (v statelessVertex) ChainID() ids.ID { return v.innerStatelessVertex.ChainID } +func (v statelessVertex) Height() uint64 { return v.innerStatelessVertex.Height } +func (v statelessVertex) Epoch() uint32 { return v.innerStatelessVertex.Epoch } +func (v statelessVertex) ParentIDs() []ids.ID { return v.innerStatelessVertex.ParentIDs } +func (v statelessVertex) Txs() [][]byte { return v.innerStatelessVertex.Txs } type innerStatelessVertex struct { - Version uint16 `json:"version"` - ChainID ids.ID `serializeV0:"true" serializeV1:"true" json:"chainID"` - Height uint64 `serializeV0:"true" serializeV1:"true" json:"height"` - Epoch uint32 `serializeV0:"true" serializeV1:"true" json:"epoch"` - ParentIDs []ids.ID `serializeV0:"true" serializeV1:"true" len:"128" json:"parentIDs"` - Txs [][]byte `serializeV0:"true" serializeV1:"true" len:"128" json:"txs"` - Restrictions []ids.ID `serializeV1:"true" len:"128" json:"restrictions"` + Version uint16 `json:"version"` + ChainID ids.ID `serialize:"true" json:"chainID"` + Height uint64 `serialize:"true" json:"height"` + Epoch uint32 `serialize:"true" json:"epoch"` + ParentIDs []ids.ID `serialize:"true" len:"128" json:"parentIDs"` + Txs [][]byte `serialize:"true" len:"128" json:"txs"` } func (v innerStatelessVertex) Verify() error { @@ -85,21 +79,14 @@ func (v innerStatelessVertex) Verify() error { return errBadVersion case v.Epoch != 0: return errBadEpoch - case len(v.Restrictions) != 0: - return errFutureField - // TODO: Remove the above checks once the apricot release is ready case len(v.ParentIDs) > maxNumParents: return errTooManyparentIDs - case len(v.Txs)+len(v.Restrictions) == 0: + case len(v.Txs) == 0: return errNoOperations case len(v.Txs) > maxTxsPerVtx: return errTooManyTxs - case len(v.Restrictions) > maxTxsPerVtx: - return errTooManyRestrictions case !ids.IsSortedAndUniqueIDs(v.ParentIDs): return errInvalidParents - case !ids.IsSortedAndUniqueIDs(v.Restrictions): - return errInvalidRestrictions case !IsSortedAndUniqueHashOf(v.Txs): return errInvalidTxs default: diff --git a/snow/engine/avalanche/vertex/stateless_vertex_test.go b/snow/engine/avalanche/vertex/stateless_vertex_test.go index 0480b2c65c5b..856a9d02dbc0 100644 --- a/snow/engine/avalanche/vertex/stateless_vertex_test.go +++ b/snow/engine/avalanche/vertex/stateless_vertex_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex @@ -36,156 +36,108 @@ func TestVertexVerify(t *testing.T) { { name: "valid vertex", vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{ - Version: 0, - ChainID: ids.ID{}, - Height: 0, - Epoch: 0, - ParentIDs: []ids.ID{}, - Txs: [][]byte{{}}, - Restrictions: []ids.ID{}, + Version: 0, + ChainID: ids.ID{}, + Height: 0, + Epoch: 0, + ParentIDs: []ids.ID{}, + Txs: [][]byte{{}}, }}, shouldErr: false, }, { name: "invalid vertex epoch", vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{ - Version: 0, - ChainID: ids.ID{}, - Height: 0, - Epoch: 1, - ParentIDs: []ids.ID{}, - Txs: [][]byte{{}}, - Restrictions: []ids.ID{}, + Version: 0, + ChainID: ids.ID{}, + Height: 0, + Epoch: 1, + ParentIDs: []ids.ID{}, + Txs: [][]byte{{}}, }}, shouldErr: true, }, { name: "too many vertex parents", vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{ - Version: 0, - ChainID: ids.ID{}, - Height: 0, - Epoch: 0, - ParentIDs: tooManyParents, - Txs: [][]byte{{}}, - Restrictions: []ids.ID{}, + Version: 0, + ChainID: ids.ID{}, + Height: 0, + Epoch: 0, + ParentIDs: tooManyParents, + Txs: [][]byte{{}}, }}, shouldErr: true, }, { name: "no vertex txs", vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{ - Version: 0, - ChainID: ids.ID{}, - Height: 0, - Epoch: 0, - ParentIDs: []ids.ID{}, - Txs: [][]byte{}, - Restrictions: []ids.ID{}, + Version: 0, + ChainID: ids.ID{}, + Height: 0, + Epoch: 0, + ParentIDs: []ids.ID{}, + Txs: [][]byte{}, }}, shouldErr: true, }, { name: "too many vertex txs", vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{ - Version: 0, - ChainID: ids.ID{}, - Height: 0, - Epoch: 0, - ParentIDs: []ids.ID{}, - Txs: tooManyTxs, - Restrictions: []ids.ID{}, - }}, - shouldErr: true, - }, - { - name: "too many vertex restrictions", - vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{ - Version: 0, - ChainID: ids.ID{}, - Height: 0, - Epoch: 0, - ParentIDs: []ids.ID{}, - Txs: [][]byte{{}}, - Restrictions: tooManyRestrictions, + Version: 0, + ChainID: ids.ID{}, + Height: 0, + Epoch: 0, + ParentIDs: []ids.ID{}, + Txs: tooManyTxs, }}, shouldErr: true, }, { name: "unsorted vertex parents", vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{ - Version: 0, - ChainID: ids.ID{}, - Height: 0, - Epoch: 0, - ParentIDs: []ids.ID{{1}, {0}}, - Txs: [][]byte{{}}, - Restrictions: []ids.ID{}, - }}, - shouldErr: true, - }, - { - name: "unsorted vertex restrictions", - vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{ - Version: 0, - ChainID: ids.ID{}, - Height: 0, - Epoch: 0, - ParentIDs: []ids.ID{}, - Txs: [][]byte{{}}, - Restrictions: []ids.ID{{1}, {0}}, + Version: 0, + ChainID: ids.ID{}, + Height: 0, + Epoch: 0, + ParentIDs: []ids.ID{{1}, {0}}, + Txs: [][]byte{{}}, }}, shouldErr: true, }, { name: "unsorted vertex txs", vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{ - Version: 0, - ChainID: ids.ID{}, - Height: 0, - Epoch: 0, - ParentIDs: []ids.ID{}, - Txs: [][]byte{{0}, {1}}, // note that txs are sorted by their hashes - Restrictions: []ids.ID{}, + Version: 0, + ChainID: ids.ID{}, + Height: 0, + Epoch: 0, + ParentIDs: []ids.ID{}, + Txs: [][]byte{{0}, {1}}, // note that txs are sorted by their hashes }}, shouldErr: true, }, { name: "duplicate vertex parents", vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{ - Version: 0, - ChainID: ids.ID{}, - Height: 0, - Epoch: 0, - ParentIDs: []ids.ID{{0}, {0}}, - Txs: [][]byte{{}}, - Restrictions: []ids.ID{}, - }}, - shouldErr: true, - }, - { - name: "duplicate vertex restrictions", - vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{ - Version: 0, - ChainID: ids.ID{}, - Height: 0, - Epoch: 0, - ParentIDs: []ids.ID{}, - Txs: [][]byte{{}}, - Restrictions: []ids.ID{{0}, {0}}, + Version: 0, + ChainID: ids.ID{}, + Height: 0, + Epoch: 0, + ParentIDs: []ids.ID{{0}, {0}}, + Txs: [][]byte{{}}, }}, shouldErr: true, }, { name: "duplicate vertex txs", vertex: statelessVertex{innerStatelessVertex: innerStatelessVertex{ - Version: 0, - ChainID: ids.ID{}, - Height: 0, - Epoch: 0, - ParentIDs: []ids.ID{}, - Txs: [][]byte{{0}, {0}}, // note that txs are sorted by their hashes - Restrictions: []ids.ID{}, + Version: 0, + ChainID: ids.ID{}, + Height: 0, + Epoch: 0, + ParentIDs: []ids.ID{}, + Txs: [][]byte{{0}, {0}}, // note that txs are sorted by their hashes }}, shouldErr: true, }, diff --git a/snow/engine/avalanche/vertex/storage.go b/snow/engine/avalanche/vertex/storage.go index 7463e5ab675f..9c587d99e26b 100644 --- a/snow/engine/avalanche/vertex/storage.go +++ b/snow/engine/avalanche/vertex/storage.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex diff --git a/snow/engine/avalanche/vertex/test_builder.go b/snow/engine/avalanche/vertex/test_builder.go index a28cff4f439b..6b2c69a1240f 100644 --- a/snow/engine/avalanche/vertex/test_builder.go +++ b/snow/engine/avalanche/vertex/test_builder.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex @@ -22,23 +22,19 @@ type TestBuilder struct { T *testing.T CantBuildVtx bool BuildVtxF func( - epoch uint32, parentIDs []ids.ID, txs []snowstorm.Tx, - restrictions []ids.ID, ) (avalanche.Vertex, error) } func (b *TestBuilder) Default(cant bool) { b.CantBuildVtx = cant } func (b *TestBuilder) BuildVtx( - epoch uint32, parentIDs []ids.ID, txs []snowstorm.Tx, - restrictions []ids.ID, ) (avalanche.Vertex, error) { if b.BuildVtxF != nil { - return b.BuildVtxF(epoch, parentIDs, txs, restrictions) + return b.BuildVtxF(parentIDs, txs) } if b.CantBuildVtx && b.T != nil { b.T.Fatal(errBuild) diff --git a/snow/engine/avalanche/vertex/test_manager.go b/snow/engine/avalanche/vertex/test_manager.go index 746156263950..7aac4ab5f2f6 100644 --- a/snow/engine/avalanche/vertex/test_manager.go +++ b/snow/engine/avalanche/vertex/test_manager.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex diff --git a/snow/engine/avalanche/vertex/test_parser.go b/snow/engine/avalanche/vertex/test_parser.go index 1e37edb44fc3..628b23c6c257 100644 --- a/snow/engine/avalanche/vertex/test_parser.go +++ b/snow/engine/avalanche/vertex/test_parser.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex diff --git a/snow/engine/avalanche/vertex/test_storage.go b/snow/engine/avalanche/vertex/test_storage.go index 68335f0c818a..694ef3d1b9d1 100644 --- a/snow/engine/avalanche/vertex/test_storage.go +++ b/snow/engine/avalanche/vertex/test_storage.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex diff --git a/snow/engine/avalanche/vertex/test_vm.go b/snow/engine/avalanche/vertex/test_vm.go index 9cd39a56eff4..502c66fc15b9 100644 --- a/snow/engine/avalanche/vertex/test_vm.go +++ b/snow/engine/avalanche/vertex/test_vm.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex diff --git a/snow/engine/avalanche/vertex/vm.go b/snow/engine/avalanche/vertex/vm.go index 4e125b445811..a3563b57b0ee 100644 --- a/snow/engine/avalanche/vertex/vm.go +++ b/snow/engine/avalanche/vertex/vm.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vertex diff --git a/snow/engine/avalanche/voter.go b/snow/engine/avalanche/voter.go index cd2d68b655f3..8f6fea2d6026 100644 --- a/snow/engine/avalanche/voter.go +++ b/snow/engine/avalanche/voter.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche diff --git a/snow/engine/avalanche/voter_test.go b/snow/engine/avalanche/voter_test.go index 9ce09499e289..ee3685762973 100644 --- a/snow/engine/avalanche/voter_test.go +++ b/snow/engine/avalanche/voter_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avalanche diff --git a/snow/engine/common/appsender/appsender_client.go b/snow/engine/common/appsender/appsender_client.go index 831f3ca208c8..1188ba5c928f 100644 --- a/snow/engine/common/appsender/appsender_client.go +++ b/snow/engine/common/appsender/appsender_client.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package appsender diff --git a/snow/engine/common/appsender/appsender_server.go b/snow/engine/common/appsender/appsender_server.go index 09226d2c4e35..5e5b6787c80e 100644 --- a/snow/engine/common/appsender/appsender_server.go +++ b/snow/engine/common/appsender/appsender_server.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package appsender diff --git a/snow/engine/common/bootstrapable.go b/snow/engine/common/bootstrapable.go index e4ac8a9e02c0..4d87fda75110 100644 --- a/snow/engine/common/bootstrapable.go +++ b/snow/engine/common/bootstrapable.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/bootstrapper.go b/snow/engine/common/bootstrapper.go index fe41c5ee63a0..d3dc8a6be42d 100644 --- a/snow/engine/common/bootstrapper.go +++ b/snow/engine/common/bootstrapper.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/config.go b/snow/engine/common/config.go index 3a37127f7aec..551d4c527dd1 100644 --- a/snow/engine/common/config.go +++ b/snow/engine/common/config.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common @@ -13,7 +13,7 @@ import ( // Config wraps the common configurations that are needed by a Snow consensus // engine type Config struct { - Ctx *snow.Context + Ctx *snow.ConsensusContext Validators validators.Set Beacons validators.Set @@ -44,7 +44,7 @@ type Config struct { } // Context implements the Engine interface -func (c *Config) Context() *snow.Context { return c.Ctx } +func (c *Config) Context() *snow.ConsensusContext { return c.Ctx } // IsBootstrapped returns true iff this chain is done bootstrapping func (c *Config) IsBootstrapped() bool { return c.Ctx.IsBootstrapped() } diff --git a/snow/engine/common/engine.go b/snow/engine/common/engine.go index d0e9879fb8d9..fb27c25fd54a 100644 --- a/snow/engine/common/engine.go +++ b/snow/engine/common/engine.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common @@ -16,7 +16,7 @@ type Engine interface { Handler // Return the context of the chain this engine is working on - Context() *snow.Context + Context() *snow.ConsensusContext // Returns true iff the chain is done bootstrapping IsBootstrapped() bool diff --git a/snow/engine/common/fetcher.go b/snow/engine/common/fetcher.go index b275ab9c1b88..d5f905e920af 100644 --- a/snow/engine/common/fetcher.go +++ b/snow/engine/common/fetcher.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/fx.go b/snow/engine/common/fx.go index 54daf4eb91d9..0c1ddd76bcbb 100644 --- a/snow/engine/common/fx.go +++ b/snow/engine/common/fx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/halter.go b/snow/engine/common/halter.go index 5ead521173e9..33c415ac2281 100644 --- a/snow/engine/common/halter.go +++ b/snow/engine/common/halter.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/http_handler.go b/snow/engine/common/http_handler.go index de6747adf5e0..ae404615c97c 100644 --- a/snow/engine/common/http_handler.go +++ b/snow/engine/common/http_handler.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/message.go b/snow/engine/common/message.go index 19f4205c4f2c..48122a78e72e 100644 --- a/snow/engine/common/message.go +++ b/snow/engine/common/message.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/queue/job.go b/snow/engine/common/queue/job.go index 85c1310b9761..7243fdba1298 100644 --- a/snow/engine/common/queue/job.go +++ b/snow/engine/common/queue/job.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package queue diff --git a/snow/engine/common/queue/jobs.go b/snow/engine/common/queue/jobs.go index fb2b767164c4..119d3e137281 100644 --- a/snow/engine/common/queue/jobs.go +++ b/snow/engine/common/queue/jobs.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package queue @@ -88,7 +88,7 @@ func (j *Jobs) Push(job Job) (bool, error) { return true, nil } -func (j *Jobs) ExecuteAll(ctx *snow.Context, halter common.Haltable, restarted bool, events ...snow.EventDispatcher) (int, error) { +func (j *Jobs) ExecuteAll(ctx *snow.ConsensusContext, halter common.Haltable, restarted bool, events ...snow.EventDispatcher) (int, error) { ctx.Executing(true) defer ctx.Executing(false) diff --git a/snow/engine/common/queue/jobs_test.go b/snow/engine/common/queue/jobs_test.go index 069ba0614bf8..31808f6eed4d 100644 --- a/snow/engine/common/queue/jobs_test.go +++ b/snow/engine/common/queue/jobs_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package queue @@ -96,7 +96,7 @@ func TestPushAndExecute(t *testing.T) { return job, nil } - count, err := jobs.ExecuteAll(snow.DefaultContextTest(), &common.Halter{}, false) + count, err := jobs.ExecuteAll(snow.DefaultConsensusContextTest(), &common.Halter{}, false) assert.NoError(err) assert.Equal(1, count) @@ -189,7 +189,7 @@ func TestRemoveDependency(t *testing.T) { } } - count, err := jobs.ExecuteAll(snow.DefaultContextTest(), &common.Halter{}, false) + count, err := jobs.ExecuteAll(snow.DefaultConsensusContextTest(), &common.Halter{}, false) assert.NoError(err) assert.Equal(2, count) assert.True(executed0) @@ -415,7 +415,7 @@ func TestHandleJobWithMissingDependencyOnRunnableStack(t *testing.T) { } } - _, err = jobs.ExecuteAll(snow.DefaultContextTest(), &common.Halter{}, false) + _, err = jobs.ExecuteAll(snow.DefaultConsensusContextTest(), &common.Halter{}, false) // Assert that the database closed error on job1 causes ExecuteAll // to fail in the middle of execution. assert.Error(err) @@ -448,7 +448,7 @@ func TestHandleJobWithMissingDependencyOnRunnableStack(t *testing.T) { assert.NoError(err) assert.True(hasNext) - count, err := jobs.ExecuteAll(snow.DefaultContextTest(), &common.Halter{}, false) + count, err := jobs.ExecuteAll(snow.DefaultConsensusContextTest(), &common.Halter{}, false) assert.NoError(err) assert.Equal(2, count) assert.True(executed1) diff --git a/snow/engine/common/queue/parser.go b/snow/engine/common/queue/parser.go index e93fd239388c..434c62e89386 100644 --- a/snow/engine/common/queue/parser.go +++ b/snow/engine/common/queue/parser.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package queue diff --git a/snow/engine/common/queue/state.go b/snow/engine/common/queue/state.go index c82deba09ace..49c9690418c7 100644 --- a/snow/engine/common/queue/state.go +++ b/snow/engine/common/queue/state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package queue diff --git a/snow/engine/common/queue/test_job.go b/snow/engine/common/queue/test_job.go index 6c78c8e848ea..8325711ea274 100644 --- a/snow/engine/common/queue/test_job.go +++ b/snow/engine/common/queue/test_job.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package queue diff --git a/snow/engine/common/queue/test_parser.go b/snow/engine/common/queue/test_parser.go index e92509bd4b60..21ac2e24e20c 100644 --- a/snow/engine/common/queue/test_parser.go +++ b/snow/engine/common/queue/test_parser.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package queue diff --git a/snow/engine/common/requests.go b/snow/engine/common/requests.go index 4590794c9002..3429b5b49f01 100644 --- a/snow/engine/common/requests.go +++ b/snow/engine/common/requests.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/requests_test.go b/snow/engine/common/requests_test.go index 912e4df4785d..56a33af64e52 100644 --- a/snow/engine/common/requests_test.go +++ b/snow/engine/common/requests_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/sender.go b/snow/engine/common/sender.go index 80853d346414..91f4bdb1c12b 100644 --- a/snow/engine/common/sender.go +++ b/snow/engine/common/sender.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/subnet.go b/snow/engine/common/subnet.go index e55ed8e04572..b04bd745a44d 100644 --- a/snow/engine/common/subnet.go +++ b/snow/engine/common/subnet.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/test_bootstrapable.go b/snow/engine/common/test_bootstrapable.go index c39a18260c0b..aa7c3cb1be68 100644 --- a/snow/engine/common/test_bootstrapable.go +++ b/snow/engine/common/test_bootstrapable.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/test_config.go b/snow/engine/common/test_config.go index c324f8874c96..edd47f3645ee 100644 --- a/snow/engine/common/test_config.go +++ b/snow/engine/common/test_config.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common @@ -18,7 +18,7 @@ func DefaultConfigTest() Config { } return Config{ - Ctx: snow.DefaultContextTest(), + Ctx: snow.DefaultConsensusContextTest(), Validators: validators.NewSet(), Beacons: validators.NewSet(), Sender: &SenderTest{}, diff --git a/snow/engine/common/test_engine.go b/snow/engine/common/test_engine.go index f5627999f55c..4b4377aa8248 100644 --- a/snow/engine/common/test_engine.go +++ b/snow/engine/common/test_engine.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common @@ -83,7 +83,7 @@ type EngineTest struct { CantGetVM bool IsBootstrappedF func() bool - ContextF func() *snow.Context + ContextF func() *snow.ConsensusContext HaltF func() TimeoutF, GossipF, ShutdownF func() error NotifyF func(Message) error @@ -134,7 +134,7 @@ func (e *EngineTest) Default(cant bool) { e.CantGetVM = cant } -func (e *EngineTest) Context() *snow.Context { +func (e *EngineTest) Context() *snow.ConsensusContext { if e.ContextF != nil { return e.ContextF() } diff --git a/snow/engine/common/test_sender.go b/snow/engine/common/test_sender.go index ba0f1560b3a3..b3759c41a42c 100644 --- a/snow/engine/common/test_sender.go +++ b/snow/engine/common/test_sender.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/test_subnet.go b/snow/engine/common/test_subnet.go index a9f5bef26ece..852bd0e338fc 100644 --- a/snow/engine/common/test_subnet.go +++ b/snow/engine/common/test_subnet.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/test_timer.go b/snow/engine/common/test_timer.go index 68f7be7e126f..5572ed7107ce 100644 --- a/snow/engine/common/test_timer.go +++ b/snow/engine/common/test_timer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/test_vm.go b/snow/engine/common/test_vm.go index d04688085612..edc3a7c149f3 100644 --- a/snow/engine/common/test_vm.go +++ b/snow/engine/common/test_vm.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/timer.go b/snow/engine/common/timer.go index 14ed2a549277..930ceab7a2a9 100644 --- a/snow/engine/common/timer.go +++ b/snow/engine/common/timer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/common/vm.go b/snow/engine/common/vm.go index 8eeb9bf0a9d3..b60190e838fc 100644 --- a/snow/engine/common/vm.go +++ b/snow/engine/common/vm.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package common diff --git a/snow/engine/snowman/ancestor_tree.go b/snow/engine/snowman/ancestor_tree.go index ee8348e564a7..439291901ce1 100644 --- a/snow/engine/snowman/ancestor_tree.go +++ b/snow/engine/snowman/ancestor_tree.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/engine/snowman/ancestor_tree_test.go b/snow/engine/snowman/ancestor_tree_test.go index 365a8d7b58e1..b55d3e999306 100644 --- a/snow/engine/snowman/ancestor_tree_test.go +++ b/snow/engine/snowman/ancestor_tree_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/engine/snowman/block/batched_vm.go b/snow/engine/snowman/block/batched_vm.go index ac7ed49c3e7b..efb63b91aded 100644 --- a/snow/engine/snowman/block/batched_vm.go +++ b/snow/engine/snowman/block/batched_vm.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/snow/engine/snowman/block/test_batched_vm.go b/snow/engine/snowman/block/test_batched_vm.go index a370a1cacad2..6bf098a3fdf9 100644 --- a/snow/engine/snowman/block/test_batched_vm.go +++ b/snow/engine/snowman/block/test_batched_vm.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/snow/engine/snowman/block/test_vm.go b/snow/engine/snowman/block/test_vm.go index 42a3f3c1001a..5c96828eac5f 100644 --- a/snow/engine/snowman/block/test_vm.go +++ b/snow/engine/snowman/block/test_vm.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/snow/engine/snowman/block/vm.go b/snow/engine/snowman/block/vm.go index 4b7a996a2691..bfbb2a9e43ec 100644 --- a/snow/engine/snowman/block/vm.go +++ b/snow/engine/snowman/block/vm.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/snow/engine/snowman/bootstrap/block_job.go b/snow/engine/snowman/bootstrap/block_job.go index 989409ecfa3f..33c78a6fadac 100644 --- a/snow/engine/snowman/bootstrap/block_job.go +++ b/snow/engine/snowman/bootstrap/block_job.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package bootstrap diff --git a/snow/engine/snowman/bootstrap/bootstrapper.go b/snow/engine/snowman/bootstrap/bootstrapper.go index 083588bb354e..d31c17519688 100644 --- a/snow/engine/snowman/bootstrap/bootstrapper.go +++ b/snow/engine/snowman/bootstrap/bootstrapper.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package bootstrap diff --git a/snow/engine/snowman/bootstrap/bootstrapper_test.go b/snow/engine/snowman/bootstrap/bootstrapper_test.go index 7bc9e1a8fd93..434d26b759d4 100644 --- a/snow/engine/snowman/bootstrap/bootstrapper_test.go +++ b/snow/engine/snowman/bootstrap/bootstrapper_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package bootstrap @@ -6,7 +6,6 @@ package bootstrap import ( "bytes" "errors" - "fmt" "testing" "github.com/prometheus/client_golang/prometheus" @@ -21,13 +20,12 @@ import ( "github.com/ava-labs/avalanchego/snow/engine/common/queue" "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/validators" - "github.com/ava-labs/avalanchego/utils/constants" ) var errUnknownBlock = errors.New("unknown block") func newConfig(t *testing.T) (Config, ids.ShortID, *common.SenderTest, *block.TestVM) { - ctx := snow.DefaultContextTest() + ctx := snow.DefaultConsensusContextTest() peers := validators.NewSet() db := memdb.New() @@ -115,7 +113,7 @@ func TestBootstrapperSingleFrontier(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s", constants.PlatformName, config.Ctx.ChainID), + "chain_"+config.Ctx.ChainID.String(), prometheus.NewRegistry(), ) if err != nil { @@ -214,7 +212,7 @@ func TestBootstrapperUnknownByzantineResponse(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s", constants.PlatformName, config.Ctx.ChainID), + "chain_"+config.Ctx.ChainID.String(), prometheus.NewRegistry(), ) if err != nil { @@ -371,7 +369,7 @@ func TestBootstrapperPartialFetch(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s", constants.PlatformName, config.Ctx.ChainID), + "chain_"+config.Ctx.ChainID.String(), prometheus.NewRegistry(), ) if err != nil { @@ -531,7 +529,7 @@ func TestBootstrapperMultiPut(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s", constants.PlatformName, config.Ctx.ChainID), + "chain_"+config.Ctx.ChainID.String(), prometheus.NewRegistry(), ) if err != nil { @@ -644,7 +642,7 @@ func TestBootstrapperAcceptedFrontier(t *testing.T) { err := bs.Initialize( config, nil, - fmt.Sprintf("%s_%s", constants.PlatformName, config.Ctx.ChainID), + "chain_"+config.Ctx.ChainID.String(), prometheus.NewRegistry(), ) if err != nil { @@ -691,7 +689,7 @@ func TestBootstrapperFilterAccepted(t *testing.T) { err := bs.Initialize( config, nil, - fmt.Sprintf("%s_%s", constants.PlatformName, config.Ctx.ChainID), + "chain_"+config.Ctx.ChainID.String(), prometheus.NewRegistry(), ) if err != nil { @@ -780,7 +778,7 @@ func TestBootstrapperFinalized(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s", constants.PlatformName, config.Ctx.ChainID), + "chain_"+config.Ctx.ChainID.String(), prometheus.NewRegistry(), ) if err != nil { @@ -987,7 +985,7 @@ func TestRestartBootstrapping(t *testing.T) { err := bs.Initialize( config, func() error { *finished = true; return nil }, - fmt.Sprintf("%s_%s", constants.PlatformName, config.Ctx.ChainID), + "chain_"+config.Ctx.ChainID.String(), prometheus.NewRegistry(), ) if err != nil { diff --git a/snow/engine/snowman/bootstrap/metrics.go b/snow/engine/snowman/bootstrap/metrics.go index e4f97bd16434..18583df67951 100644 --- a/snow/engine/snowman/bootstrap/metrics.go +++ b/snow/engine/snowman/bootstrap/metrics.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package bootstrap diff --git a/snow/engine/snowman/config.go b/snow/engine/snowman/config.go index 6b361646f5cd..fa389dae6ebd 100644 --- a/snow/engine/snowman/config.go +++ b/snow/engine/snowman/config.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/engine/snowman/config_test.go b/snow/engine/snowman/config_test.go index 8f7ad57aac02..516565800af5 100644 --- a/snow/engine/snowman/config_test.go +++ b/snow/engine/snowman/config_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman @@ -24,7 +24,7 @@ func DefaultConfig() Config { VM: &block.TestVM{}, }, Params: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), + K: 1, Alpha: 1, BetaVirtuous: 1, diff --git a/snow/engine/snowman/convincer.go b/snow/engine/snowman/convincer.go index 1481849abd56..d247d7a23651 100644 --- a/snow/engine/snowman/convincer.go +++ b/snow/engine/snowman/convincer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/engine/snowman/engine.go b/snow/engine/snowman/engine.go index e35e26630c65..50a0e7b33708 100644 --- a/snow/engine/snowman/engine.go +++ b/snow/engine/snowman/engine.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/engine/snowman/issuer.go b/snow/engine/snowman/issuer.go index cdfed0b0a941..e9835ddee689 100644 --- a/snow/engine/snowman/issuer.go +++ b/snow/engine/snowman/issuer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/engine/snowman/memory_block.go b/snow/engine/snowman/memory_block.go index 74e83a55e316..a71842b57d83 100644 --- a/snow/engine/snowman/memory_block.go +++ b/snow/engine/snowman/memory_block.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/engine/snowman/metrics.go b/snow/engine/snowman/metrics.go index c3fbcb7cf7f6..e07b0480b238 100644 --- a/snow/engine/snowman/metrics.go +++ b/snow/engine/snowman/metrics.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/engine/snowman/mocks/engine.go b/snow/engine/snowman/mocks/engine.go index 139e792573eb..8ceaf50e174b 100644 --- a/snow/engine/snowman/mocks/engine.go +++ b/snow/engine/snowman/mocks/engine.go @@ -135,15 +135,15 @@ func (_m *Engine) Connected(validatorID ids.ShortID) error { } // Context provides a mock function with given fields: -func (_m *Engine) Context() *snow.Context { +func (_m *Engine) Context() *snow.ConsensusContext { ret := _m.Called() - var r0 *snow.Context - if rf, ok := ret.Get(0).(func() *snow.Context); ok { + var r0 *snow.ConsensusContext + if rf, ok := ret.Get(0).(func() *snow.ConsensusContext); ok { r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*snow.Context) + r0 = ret.Get(0).(*snow.ConsensusContext) } } diff --git a/snow/engine/snowman/transitive.go b/snow/engine/snowman/transitive.go index 55a55da34a79..4b5c7cfea981 100644 --- a/snow/engine/snowman/transitive.go +++ b/snow/engine/snowman/transitive.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman @@ -69,19 +69,19 @@ func (t *Transitive) Initialize(config Config) error { factory := poll.NewEarlyTermNoTraversalFactory(config.Params.Alpha) t.polls = poll.NewSet(factory, config.Ctx.Log, - config.Params.Namespace, - config.Params.Metrics, + "", + config.Ctx.Registerer, ) - if err := t.metrics.Initialize(config.Params.Namespace, config.Params.Metrics); err != nil { + if err := t.metrics.Initialize("", config.Ctx.Registerer); err != nil { return err } return t.Bootstrapper.Initialize( config.Config, t.finishBootstrapping, - fmt.Sprintf("%s_bs", config.Params.Namespace), - config.Params.Metrics, + "bs", + config.Ctx.Registerer, ) } @@ -207,7 +207,7 @@ func (t *Transitive) Put(vdr ids.ShortID, requestID uint32, blkID ids.ID, blkByt blk, err := t.VM.ParseBlock(blkBytes) if err != nil { t.Ctx.Log.Debug("failed to parse block %s: %s", blkID, err) - t.Ctx.Log.Verbo("block:\n%s", formatting.DumpBytes{Bytes: blkBytes}) + t.Ctx.Log.Verbo("block:\n%s", formatting.DumpBytes(blkBytes)) // because GetFailed doesn't utilize the assumption that we actually // sent a Get message, we can safely call GetFailed here to potentially // abandon the request. @@ -293,7 +293,7 @@ func (t *Transitive) PushQuery(vdr ids.ShortID, requestID uint32, blkID ids.ID, // If parsing fails, we just drop the request, as we didn't ask for it if err != nil { t.Ctx.Log.Debug("failed to parse block %s: %s", blkID, err) - t.Ctx.Log.Verbo("block:\n%s", formatting.DumpBytes{Bytes: blkBytes}) + t.Ctx.Log.Verbo("block:\n%s", formatting.DumpBytes(blkBytes)) return nil } diff --git a/snow/engine/snowman/transitive_test.go b/snow/engine/snowman/transitive_test.go index 6148bed93c4a..3bbee800a77d 100644 --- a/snow/engine/snowman/transitive_test.go +++ b/snow/engine/snowman/transitive_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman @@ -17,7 +17,6 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/wrappers" - "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" ) @@ -385,7 +384,7 @@ func TestEngineMultipleQuery(t *testing.T) { config := DefaultConfig() config.Params = snowball.Parameters{ - Metrics: prometheus.NewRegistry(), + K: 3, Alpha: 2, BetaVirtuous: 1, @@ -873,7 +872,7 @@ func TestVoteCanceling(t *testing.T) { config := DefaultConfig() config.Params = snowball.Parameters{ - Metrics: prometheus.NewRegistry(), + K: 3, Alpha: 2, BetaVirtuous: 1, @@ -1826,7 +1825,7 @@ func TestEngineDoubleChit(t *testing.T) { config := DefaultConfig() config.Params = snowball.Parameters{ - Metrics: prometheus.NewRegistry(), + K: 2, Alpha: 2, BetaVirtuous: 1, diff --git a/snow/engine/snowman/voter.go b/snow/engine/snowman/voter.go index babb1b67764c..b1b4fc891ebe 100644 --- a/snow/engine/snowman/voter.go +++ b/snow/engine/snowman/voter.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package snowman diff --git a/snow/events/blockable.go b/snow/events/blockable.go index 3c0bc28ce24f..cdccce8dc3cb 100644 --- a/snow/events/blockable.go +++ b/snow/events/blockable.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package events diff --git a/snow/events/blockable_test.go b/snow/events/blockable_test.go index dbc975dd5f85..d66d876f73e1 100644 --- a/snow/events/blockable_test.go +++ b/snow/events/blockable_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package events diff --git a/snow/events/blocker.go b/snow/events/blocker.go index 3908b306f74e..488b08fcd7e6 100644 --- a/snow/events/blocker.go +++ b/snow/events/blocker.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package events diff --git a/snow/events/blocker_test.go b/snow/events/blocker_test.go index 9cc9c03ce0ef..29e27f6c1d40 100644 --- a/snow/events/blocker_test.go +++ b/snow/events/blocker_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package events diff --git a/snow/networking/benchlist/benchable.go b/snow/networking/benchlist/benchable.go index 02b43bc4548c..c16c2f922e4e 100644 --- a/snow/networking/benchlist/benchable.go +++ b/snow/networking/benchlist/benchable.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package benchlist diff --git a/snow/networking/benchlist/benchlist.go b/snow/networking/benchlist/benchlist.go index 28561f1c7e3c..08a9f8625ec4 100644 --- a/snow/networking/benchlist/benchlist.go +++ b/snow/networking/benchlist/benchlist.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package benchlist @@ -137,7 +137,6 @@ func NewBenchlist( minimumFailingDuration, duration time.Duration, maxPortion float64, - namespace string, registerer prometheus.Registerer, ) (Benchlist, error) { if maxPortion < 0 || maxPortion >= 1 { @@ -157,7 +156,7 @@ func NewBenchlist( } benchlist.timer = timer.NewTimer(benchlist.update) go benchlist.timer.Dispatch() - return benchlist, benchlist.metrics.Initialize(registerer, namespace) + return benchlist, benchlist.metrics.Initialize(registerer) } // Update removes benched validators whose time on the bench is over diff --git a/snow/networking/benchlist/benchlist_test.go b/snow/networking/benchlist/benchlist_test.go index c3cfa898e5d6..589a659c6a76 100644 --- a/snow/networking/benchlist/benchlist_test.go +++ b/snow/networking/benchlist/benchlist_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package benchlist @@ -55,7 +55,6 @@ func TestBenchlistAdd(t *testing.T) { minimumFailingDuration, duration, maxPortion, - "", prometheus.NewRegistry(), ) if err != nil { @@ -199,7 +198,6 @@ func TestBenchlistMaxStake(t *testing.T) { minimumFailingDuration, duration, maxPortion, - "", prometheus.NewRegistry(), ) if err != nil { @@ -340,7 +338,6 @@ func TestBenchlistRemove(t *testing.T) { minimumFailingDuration, duration, maxPortion, - "", prometheus.NewRegistry(), ) if err != nil { diff --git a/snow/networking/benchlist/manager.go b/snow/networking/benchlist/manager.go index 5ab93f44780c..29f8360f0373 100644 --- a/snow/networking/benchlist/manager.go +++ b/snow/networking/benchlist/manager.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package benchlist @@ -28,7 +28,7 @@ type Manager interface { // [chainID] timed out RegisterFailure(chainID ids.ID, validatorID ids.ShortID) // RegisterChain registers a new chain with metrics under [namespace] - RegisterChain(ctx *snow.Context, namespace string) error + RegisterChain(ctx *snow.ConsensusContext) error // IsBenched returns true if messages to [validatorID] regarding chain [chainID] // should not be sent over the network and should immediately fail. // Returns false if such messages should be sent, or if the chain is unknown. @@ -104,7 +104,7 @@ func (m *manager) GetBenched(validatorID ids.ShortID) []ids.ID { return benched } -func (m *manager) RegisterChain(ctx *snow.Context, namespace string) error { +func (m *manager) RegisterChain(ctx *snow.ConsensusContext) error { m.lock.Lock() defer m.lock.Unlock() @@ -135,8 +135,7 @@ func (m *manager) RegisterChain(ctx *snow.Context, namespace string) error { m.config.MinimumFailingDuration, m.config.Duration, m.config.MaxPortion, - namespace, - ctx.Metrics, + ctx.Registerer, ) if err != nil { return err @@ -175,8 +174,8 @@ type noBenchlist struct{} // NewNoBenchlist returns an empty benchlist that will never stop any queries func NewNoBenchlist() Manager { return &noBenchlist{} } -func (noBenchlist) RegisterChain(*snow.Context, string) error { return nil } -func (noBenchlist) RegisterResponse(ids.ID, ids.ShortID) {} -func (noBenchlist) RegisterFailure(ids.ID, ids.ShortID) {} -func (noBenchlist) IsBenched(ids.ShortID, ids.ID) bool { return false } -func (noBenchlist) GetBenched(ids.ShortID) []ids.ID { return []ids.ID{} } +func (noBenchlist) RegisterChain(*snow.ConsensusContext) error { return nil } +func (noBenchlist) RegisterResponse(ids.ID, ids.ShortID) {} +func (noBenchlist) RegisterFailure(ids.ID, ids.ShortID) {} +func (noBenchlist) IsBenched(ids.ShortID, ids.ID) bool { return false } +func (noBenchlist) GetBenched(ids.ShortID) []ids.ID { return []ids.ID{} } diff --git a/snow/networking/benchlist/metrics.go b/snow/networking/benchlist/metrics.go index 96efdd125d28..06b9d9b5efdb 100644 --- a/snow/networking/benchlist/metrics.go +++ b/snow/networking/benchlist/metrics.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package benchlist @@ -14,11 +14,9 @@ type metrics struct { } // Initialize implements the Engine interface -func (m *metrics) Initialize(registerer prometheus.Registerer, namespace string) error { - benchNamespace := fmt.Sprintf("%s_benchlist", namespace) - +func (m *metrics) Initialize(registerer prometheus.Registerer) error { m.numBenched = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: benchNamespace, + Namespace: "benchlist", Name: "benched_num", Help: "Number of currently benched validators", }) @@ -27,7 +25,7 @@ func (m *metrics) Initialize(registerer prometheus.Registerer, namespace string) } m.weightBenched = prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: benchNamespace, + Namespace: "benchlist", Name: "benched_weight", Help: "Weight of currently benched validators", }) diff --git a/snow/networking/benchlist/test_benchable.go b/snow/networking/benchlist/test_benchable.go index 3be7d2ef7393..786991a3e273 100644 --- a/snow/networking/benchlist/test_benchable.go +++ b/snow/networking/benchlist/test_benchable.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package benchlist diff --git a/snow/networking/router/chain_router.go b/snow/networking/router/chain_router.go index 1743cd714c3f..67913be77db3 100644 --- a/snow/networking/router/chain_router.go +++ b/snow/networking/router/chain_router.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package router diff --git a/snow/networking/router/chain_router_metrics.go b/snow/networking/router/chain_router_metrics.go index 48c3fa73c228..f98085ef2dba 100644 --- a/snow/networking/router/chain_router_metrics.go +++ b/snow/networking/router/chain_router_metrics.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package router diff --git a/snow/networking/router/chain_router_test.go b/snow/networking/router/chain_router_test.go index d6e6a68542a6..81d82b3d6afb 100644 --- a/snow/networking/router/chain_router_test.go +++ b/snow/networking/router/chain_router_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package router @@ -58,7 +58,7 @@ func TestShutdown(t *testing.T) { shutdownCalled := make(chan struct{}, 1) - engine.ContextF = snow.DefaultContextTest + engine.ContextF = snow.DefaultConsensusContextTest engine.ShutdownF = func() error { shutdownCalled <- struct{}{}; return nil } handler := &Handler{} @@ -67,8 +67,6 @@ func TestShutdown(t *testing.T) { &engine, vdrs, nil, - "", - prometheus.NewRegistry(), ) assert.NoError(t, err) @@ -151,7 +149,7 @@ func TestShutdownTimesOut(t *testing.T) { closed := new(int) - engine.ContextF = snow.DefaultContextTest + engine.ContextF = snow.DefaultConsensusContextTest engine.ShutdownF = func() error { *closed++; return nil } handler := &Handler{} @@ -160,8 +158,6 @@ func TestShutdownTimesOut(t *testing.T) { &engine, vdrs, nil, - "", - metrics, ) assert.NoError(t, err) @@ -258,7 +254,7 @@ func TestRouterTimeout(t *testing.T) { return nil } - engine.ContextF = snow.DefaultContextTest + engine.ContextF = snow.DefaultConsensusContextTest handler := &Handler{} vdrs := validators.NewSet() @@ -269,8 +265,6 @@ func TestRouterTimeout(t *testing.T) { &engine, vdrs, nil, - "", - prometheus.NewRegistry(), ) assert.NoError(t, err) @@ -334,7 +328,7 @@ func TestRouterClearTimeouts(t *testing.T) { engine := common.EngineTest{T: t} engine.Default(false) - engine.ContextF = snow.DefaultContextTest + engine.ContextF = snow.DefaultConsensusContextTest vdrs := validators.NewSet() err = vdrs.AddWeight(ids.GenerateTestShortID(), 1) @@ -345,8 +339,6 @@ func TestRouterClearTimeouts(t *testing.T) { &engine, vdrs, nil, - "", - metrics, ) assert.NoError(t, err) @@ -438,8 +430,8 @@ func TestValidatorOnlyMessageDrops(t *testing.T) { return nil } - engine.ContextF = func() *snow.Context { - ctx := snow.DefaultContextTest() + engine.ContextF = func() *snow.ConsensusContext { + ctx := snow.DefaultConsensusContextTest() ctx.SetValidatorOnly() return ctx } @@ -454,8 +446,6 @@ func TestValidatorOnlyMessageDrops(t *testing.T) { &engine, vdrs, nil, - "", - metrics, ) assert.NoError(t, err) diff --git a/snow/networking/router/handler.go b/snow/networking/router/handler.go index eb0e50ccfc13..30f7d9ca4f3f 100644 --- a/snow/networking/router/handler.go +++ b/snow/networking/router/handler.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package router @@ -8,8 +8,6 @@ import ( "fmt" "sync" - "github.com/prometheus/client_golang/prometheus" - "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/message" "github.com/ava-labs/avalanchego/snow" @@ -27,7 +25,7 @@ var errDuplicatedContainerID = errors.New("inbound message contains duplicated c // Handler passes incoming messages from the network to the consensus engine. // (Actually, it receives the incoming messages from a ChainRouter, but same difference.) type Handler struct { - ctx *snow.Context + ctx *snow.ConsensusContext // Useful for faking time in tests clock mockable.Clock mc message.Creator @@ -59,11 +57,9 @@ func (h *Handler) Initialize( engine common.Engine, validators validators.Set, msgFromVMChan <-chan common.Message, - metricsNamespace string, - metricsRegisterer prometheus.Registerer, ) error { h.ctx = engine.Context() - if err := h.metrics.Initialize(metricsNamespace, metricsRegisterer); err != nil { + if err := h.metrics.Initialize("handler", h.ctx.Registerer); err != nil { return fmt.Errorf("initializing handler metrics errored with: %s", err) } h.mc = mc @@ -75,12 +71,12 @@ func (h *Handler) Initialize( h.unprocessedMsgsCond = sync.NewCond(&lock) h.cpuTracker = tracker.NewCPUTracker(uptime.IntervalFactory{}, defaultCPUInterval) var err error - h.unprocessedMsgs, err = newUnprocessedMsgs(h.ctx.Log, h.validators, h.cpuTracker, metricsNamespace, metricsRegisterer) + h.unprocessedMsgs, err = newUnprocessedMsgs(h.ctx.Log, h.validators, h.cpuTracker, "handler", h.ctx.Registerer) return err } // Context of this Handler -func (h *Handler) Context() *snow.Context { return h.engine.Context() } +func (h *Handler) Context() *snow.ConsensusContext { return h.engine.Context() } // Engine returns the engine this handler dispatches to func (h *Handler) Engine() common.Engine { return h.engine } diff --git a/snow/networking/router/handler_metrics.go b/snow/networking/router/handler_metrics.go index 8947140f7014..fc883f05473b 100644 --- a/snow/networking/router/handler_metrics.go +++ b/snow/networking/router/handler_metrics.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package router diff --git a/snow/networking/router/handler_test.go b/snow/networking/router/handler_test.go index 2d3cff53ef8b..6dae455aba4b 100644 --- a/snow/networking/router/handler_test.go +++ b/snow/networking/router/handler_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package router @@ -21,7 +21,7 @@ import ( func TestHandlerDropsTimedOutMessages(t *testing.T) { engine := common.EngineTest{T: t} engine.Default(true) - engine.ContextF = snow.DefaultContextTest + engine.ContextF = snow.DefaultConsensusContextTest called := make(chan struct{}) engine.GetAcceptedFrontierF = func(nodeID ids.ShortID, requestID uint32) error { @@ -47,8 +47,6 @@ func TestHandlerDropsTimedOutMessages(t *testing.T) { &engine, vdrs, nil, - "", - metrics, ) assert.NoError(t, err) @@ -88,7 +86,7 @@ func TestHandlerClosesOnError(t *testing.T) { closed := make(chan struct{}, 1) - engine.ContextF = snow.DefaultContextTest + engine.ContextF = snow.DefaultConsensusContextTest engine.GetAcceptedFrontierF = func(nodeID ids.ShortID, requestID uint32) error { return errors.New("Engine error should cause handler to close") } @@ -105,8 +103,6 @@ func TestHandlerClosesOnError(t *testing.T) { &engine, vdrs, nil, - "", - metrics, ) assert.NoError(t, err) @@ -139,7 +135,7 @@ func TestHandlerDropsGossipDuringBootstrapping(t *testing.T) { closed := make(chan struct{}, 1) - engine.ContextF = snow.DefaultContextTest + engine.ContextF = snow.DefaultConsensusContextTest engine.GetFailedF = func(nodeID ids.ShortID, requestID uint32) error { closed <- struct{}{} return nil @@ -157,8 +153,6 @@ func TestHandlerDropsGossipDuringBootstrapping(t *testing.T) { &engine, vdrs, nil, - "", - metrics, ) assert.NoError(t, err) @@ -186,7 +180,7 @@ func TestHandlerDropsGossipDuringBootstrapping(t *testing.T) { func TestHandlerDispatchInternal(t *testing.T) { engine := common.EngineTest{T: t} engine.Default(false) - engine.ContextF = snow.DefaultContextTest + engine.ContextF = snow.DefaultConsensusContextTest calledNotify := make(chan struct{}, 1) engine.NotifyF = func(common.Message) error { calledNotify <- struct{}{} @@ -206,8 +200,6 @@ func TestHandlerDispatchInternal(t *testing.T) { &engine, vdrs, msgFromVMChan, - "", - prometheus.NewRegistry(), ) assert.NoError(t, err) diff --git a/snow/networking/router/health.go b/snow/networking/router/health.go index 778f00d8da19..11a66b08a7c3 100644 --- a/snow/networking/router/health.go +++ b/snow/networking/router/health.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package router diff --git a/snow/networking/router/router.go b/snow/networking/router/router.go index 3c2f2c4b6064..6bc3cf88abf5 100644 --- a/snow/networking/router/router.go +++ b/snow/networking/router/router.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package router diff --git a/snow/networking/router/timer.go b/snow/networking/router/timer.go index 5cd7c488f5d3..84407b2e1915 100644 --- a/snow/networking/router/timer.go +++ b/snow/networking/router/timer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package router diff --git a/snow/networking/router/unprocessed_msgs.go b/snow/networking/router/unprocessed_msgs.go index 339839084bbb..24a36a10dc1f 100644 --- a/snow/networking/router/unprocessed_msgs.go +++ b/snow/networking/router/unprocessed_msgs.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package router diff --git a/snow/networking/router/unprocessed_msgs_test.go b/snow/networking/router/unprocessed_msgs_test.go index a958e507f2eb..5dff16da09e3 100644 --- a/snow/networking/router/unprocessed_msgs_test.go +++ b/snow/networking/router/unprocessed_msgs_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package router diff --git a/snow/networking/sender/external_sender.go b/snow/networking/sender/external_sender.go index 9007c946b110..d58cd5115dbe 100644 --- a/snow/networking/sender/external_sender.go +++ b/snow/networking/sender/external_sender.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sender diff --git a/snow/networking/sender/sender.go b/snow/networking/sender/sender.go index 173aae25246e..d1c13b83b814 100644 --- a/snow/networking/sender/sender.go +++ b/snow/networking/sender/sender.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sender @@ -22,7 +22,7 @@ import ( // Sender registers outbound requests with [router] so that [router] // fires a timeout if we don't get a response to the request. type Sender struct { - ctx *snow.Context + ctx *snow.ConsensusContext msgCreator message.Creator sender ExternalSender // Actually does the sending over the network router router.Router @@ -39,13 +39,11 @@ type Sender struct { // Initialize this sender func (s *Sender) Initialize( - ctx *snow.Context, + ctx *snow.ConsensusContext, msgCreator message.Creator, sender ExternalSender, router router.Router, timeouts *timeout.Manager, - metricsNamespace string, - metricsRegisterer prometheus.Registerer, appGossipValidatorSize int, appGossipNonValidatorSize int, gossipAcceptedFrontierSize int, @@ -65,12 +63,11 @@ func (s *Sender) Initialize( for _, op := range message.ConsensusRequestOps { counter := prometheus.NewCounter( prometheus.CounterOpts{ - Namespace: metricsNamespace, - Name: fmt.Sprintf("%s_failed_benched", op), - Help: fmt.Sprintf("# of times a %s request was not sent because the node was benched", op), + Name: fmt.Sprintf("%s_failed_benched", op), + Help: fmt.Sprintf("# of times a %s request was not sent because the node was benched", op), }, ) - if err := metricsRegisterer.Register(counter); err != nil { + if err := ctx.Registerer.Register(counter); err != nil { return fmt.Errorf("couldn't register metric for %s: %w", op, err) } s.failedDueToBench[op] = counter @@ -79,7 +76,7 @@ func (s *Sender) Initialize( } // Context of this sender -func (s *Sender) Context() *snow.Context { return s.ctx } +func (s *Sender) Context() *snow.ConsensusContext { return s.ctx } func (s *Sender) SendGetAcceptedFrontier(nodeIDs ids.ShortSet, requestID uint32) { // Note that this timeout duration won't exactly match the one that gets @@ -424,7 +421,7 @@ func (s *Sender) SendPut(nodeID ids.ShortID, requestID uint32, containerID ids.I requestID, containerID, ) - s.ctx.Log.Verbo("container: %s", formatting.DumpBytes{Bytes: container}) + s.ctx.Log.Verbo("container: %s", formatting.DumpBytes(container)) } } @@ -503,7 +500,7 @@ func (s *Sender) SendPushQuery(nodeIDs ids.ShortSet, requestID uint32, container requestID, containerID, ) - s.ctx.Log.Verbo("container: %s", formatting.DumpBytes{Bytes: container}) + s.ctx.Log.Verbo("container: %s", formatting.DumpBytes(container)) // Register failures for nodes we didn't send a request to. s.timeouts.RegisterRequestToUnreachableValidator() @@ -633,7 +630,7 @@ func (s *Sender) SendAppRequest(nodeIDs ids.ShortSet, requestID uint32, appReque s.ctx.Log.Verbo( "Sending AppRequest. RequestID: %d. Message: %s", requestID, - formatting.DumpBytes{Bytes: appRequestBytes}, + formatting.DumpBytes(appRequestBytes), ) // Tell the router to expect a response message or a message notifying @@ -696,7 +693,7 @@ func (s *Sender) SendAppRequest(nodeIDs ids.ShortSet, requestID uint32, appReque s.ctx.ChainID, requestID, ) - s.ctx.Log.Verbo("failed message: %s", formatting.DumpBytes{Bytes: appRequestBytes}) + s.ctx.Log.Verbo("failed message: %s", formatting.DumpBytes(appRequestBytes)) // Register failures for nodes we didn't send a request to. s.timeouts.RegisterRequestToUnreachableValidator() @@ -725,7 +722,7 @@ func (s *Sender) SendAppResponse(nodeID ids.ShortID, requestID uint32, appRespon requestID, err, ) - s.ctx.Log.Verbo("message: %s", formatting.DumpBytes{Bytes: appResponseBytes}) + s.ctx.Log.Verbo("message: %s", formatting.DumpBytes(appResponseBytes)) return nil } @@ -739,7 +736,7 @@ func (s *Sender) SendAppResponse(nodeID ids.ShortID, requestID uint32, appRespon s.ctx.ChainID, requestID, ) - s.ctx.Log.Verbo("container: %s", formatting.DumpBytes{Bytes: appResponseBytes}) + s.ctx.Log.Verbo("container: %s", formatting.DumpBytes(appResponseBytes)) } return nil @@ -754,13 +751,13 @@ func (s *Sender) SendAppGossipSpecific(nodeIDs ids.ShortSet, appGossipBytes []by s.ctx.ChainID, err, ) - s.ctx.Log.Verbo("message: %s", formatting.DumpBytes{Bytes: appGossipBytes}) + s.ctx.Log.Verbo("message: %s", formatting.DumpBytes(appGossipBytes)) } // Send the message over the network. if sentTo := s.sender.Send(outMsg, nodeIDs, s.ctx.SubnetID, s.ctx.IsValidatorOnly()); sentTo.Len() == 0 { s.ctx.Log.Debug("failed to gossip SpecificGossip(%s)", s.ctx.ChainID) - s.ctx.Log.Verbo("failed message: %s", formatting.DumpBytes{Bytes: appGossipBytes}) + s.ctx.Log.Verbo("failed message: %s", formatting.DumpBytes(appGossipBytes)) } return nil } @@ -771,13 +768,13 @@ func (s *Sender) SendAppGossip(appGossipBytes []byte) error { outMsg, err := s.msgCreator.AppGossip(s.ctx.ChainID, appGossipBytes) if err != nil { s.ctx.Log.Error("failed to build AppGossip(%s): %s", s.ctx.ChainID, err) - s.ctx.Log.Verbo("message: %s", formatting.DumpBytes{Bytes: appGossipBytes}) + s.ctx.Log.Verbo("message: %s", formatting.DumpBytes(appGossipBytes)) } sentTo := s.sender.Gossip(outMsg, s.ctx.SubnetID, s.ctx.IsValidatorOnly(), s.appGossipValidatorSize, s.appGossipNonValidatorSize) if sentTo.Len() == 0 { s.ctx.Log.Debug("failed to gossip AppGossip(%s)", s.ctx.ChainID) - s.ctx.Log.Verbo("failed message: %s", formatting.DumpBytes{Bytes: appGossipBytes}) + s.ctx.Log.Verbo("failed message: %s", formatting.DumpBytes(appGossipBytes)) } return nil } diff --git a/snow/networking/sender/sender_test.go b/snow/networking/sender/sender_test.go index 3f7f444181e1..d842b6900908 100644 --- a/snow/networking/sender/sender_test.go +++ b/snow/networking/sender/sender_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sender @@ -27,7 +27,7 @@ import ( ) func TestSenderContext(t *testing.T) { - context := snow.DefaultContextTest() + context := snow.DefaultConsensusContextTest() metrics := prometheus.NewRegistry() msgCreator, err := message.NewCreator(metrics, true /*compressionEnabled*/, "dummyNamespace" /*parentNamespace*/) assert.NoError(t, err) @@ -40,8 +40,6 @@ func TestSenderContext(t *testing.T) { externalSender, &router.ChainRouter{}, &timeout.Manager{}, - "", - metrics, 2, 2, 2, @@ -82,18 +80,18 @@ func TestTimeout(t *testing.T) { err = chainRouter.Initialize(ids.ShortEmpty, logging.NoLog{}, mc, &tm, time.Hour, time.Second, ids.Set{}, nil, router.HealthConfig{}, "", prometheus.NewRegistry()) assert.NoError(t, err) - context := snow.DefaultContextTest() + context := snow.DefaultConsensusContextTest() externalSender := &ExternalSenderTest{TB: t} externalSender.Default(false) sender := Sender{} - err = sender.Initialize(context, mc, externalSender, &chainRouter, &tm, "", metrics, 2, 2, 2) + err = sender.Initialize(context, mc, externalSender, &chainRouter, &tm, 2, 2, 2) assert.NoError(t, err) engine := common.EngineTest{T: t} engine.Default(true) engine.CantConnected = false - engine.ContextF = snow.DefaultContextTest + engine.ContextF = snow.DefaultConsensusContextTest wg := sync.WaitGroup{} wg.Add(2) @@ -111,8 +109,6 @@ func TestTimeout(t *testing.T) { &engine, vdrs, nil, - "", - prometheus.NewRegistry(), ) assert.NoError(t, err) @@ -164,19 +160,19 @@ func TestReliableMessages(t *testing.T) { ids.Set{}, nil, router.HealthConfig{}, "", prometheus.NewRegistry()) assert.NoError(t, err) - context := snow.DefaultContextTest() + context := snow.DefaultConsensusContextTest() externalSender := &ExternalSenderTest{TB: t} externalSender.Default(false) sender := Sender{} - err = sender.Initialize(context, mc, externalSender, &chainRouter, &tm, "", metrics, 2, 2, 2) + err = sender.Initialize(context, mc, externalSender, &chainRouter, &tm, 2, 2, 2) assert.NoError(t, err) engine := common.EngineTest{T: t} engine.Default(true) engine.CantConnected = false - engine.ContextF = snow.DefaultContextTest + engine.ContextF = snow.DefaultConsensusContextTest engine.GossipF = func() error { return nil } queriesToSend := 1000 @@ -196,8 +192,6 @@ func TestReliableMessages(t *testing.T) { &engine, vdrs, nil, - "", - prometheus.NewRegistry(), ) assert.NoError(t, err) @@ -257,18 +251,18 @@ func TestReliableMessagesToMyself(t *testing.T) { err = chainRouter.Initialize(ids.ShortEmpty, logging.NoLog{}, mc, &tm, time.Hour, time.Second, ids.Set{}, nil, router.HealthConfig{}, "", prometheus.NewRegistry()) assert.NoError(t, err) - context := snow.DefaultContextTest() + context := snow.DefaultConsensusContextTest() sender := Sender{} externalSender := &ExternalSenderTest{TB: t} externalSender.Default(false) - err = sender.Initialize(context, mc, externalSender, &chainRouter, &tm, "", metrics, 2, 2, 2) + err = sender.Initialize(context, mc, externalSender, &chainRouter, &tm, 2, 2, 2) assert.NoError(t, err) engine := common.EngineTest{T: t} engine.Default(false) - engine.ContextF = snow.DefaultContextTest + engine.ContextF = snow.DefaultConsensusContextTest engine.GossipF = func() error { return nil } engine.CantPullQuery = false @@ -289,8 +283,6 @@ func TestReliableMessagesToMyself(t *testing.T) { &engine, vdrs, nil, - "", - prometheus.NewRegistry(), ) assert.NoError(t, err) diff --git a/snow/networking/sender/test_external_sender.go b/snow/networking/sender/test_external_sender.go index f75f358587b3..e031beff8c67 100644 --- a/snow/networking/sender/test_external_sender.go +++ b/snow/networking/sender/test_external_sender.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sender diff --git a/snow/networking/timeout/manager.go b/snow/networking/timeout/manager.go index 0a19129478d7..af88212b70e0 100644 --- a/snow/networking/timeout/manager.go +++ b/snow/networking/timeout/manager.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timeout @@ -48,11 +48,11 @@ func (m *Manager) IsBenched(validatorID ids.ShortID, chainID ids.ID) bool { return m.benchlistMgr.IsBenched(validatorID, chainID) } -func (m *Manager) RegisterChain(ctx *snow.Context, namespace string) error { - if err := m.metrics.RegisterChain(ctx, namespace); err != nil { +func (m *Manager) RegisterChain(ctx *snow.ConsensusContext) error { + if err := m.metrics.RegisterChain(ctx); err != nil { return fmt.Errorf("couldn't register timeout metrics for chain %s: %w", ctx.ChainID, err) } - if err := m.benchlistMgr.RegisterChain(ctx, namespace); err != nil { + if err := m.benchlistMgr.RegisterChain(ctx); err != nil { return fmt.Errorf("couldn't register chain %s with benchlist manager: %w", ctx.ChainID, err) } return nil diff --git a/snow/networking/timeout/manager_test.go b/snow/networking/timeout/manager_test.go index 792a2f6b946e..f502d4591772 100644 --- a/snow/networking/timeout/manager_test.go +++ b/snow/networking/timeout/manager_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timeout diff --git a/snow/networking/timeout/metrics.go b/snow/networking/timeout/metrics.go index ae9a62cb205e..07d280c27a4a 100644 --- a/snow/networking/timeout/metrics.go +++ b/snow/networking/timeout/metrics.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timeout @@ -27,7 +27,7 @@ type metrics struct { chainToMetrics map[ids.ID]*chainMetrics } -func (m *metrics) RegisterChain(ctx *snow.Context, namespace string) error { +func (m *metrics) RegisterChain(ctx *snow.ConsensusContext) error { m.lock.Lock() defer m.lock.Unlock() @@ -37,7 +37,7 @@ func (m *metrics) RegisterChain(ctx *snow.Context, namespace string) error { if _, exists := m.chainToMetrics[ctx.ChainID]; exists { return fmt.Errorf("chain %s has already been registered", ctx.ChainID) } - cm, err := newChainMetrics(ctx, namespace, false) + cm, err := newChainMetrics(ctx, false) if err != nil { return fmt.Errorf("couldn't create metrics for chain %s: %w", ctx.ChainID, err) } @@ -60,7 +60,7 @@ func (m *metrics) Observe(chainID ids.ID, op message.Op, latency time.Duration) // chainMetrics contains message response time metrics for a chain type chainMetrics struct { - ctx *snow.Context + ctx *snow.ConsensusContext messageLatencies map[message.Op]metric.Averager @@ -68,7 +68,7 @@ type chainMetrics struct { messageSummaries map[message.Op]*prometheus.SummaryVec } -func newChainMetrics(ctx *snow.Context, namespace string, summaryEnabled bool) (*chainMetrics, error) { +func newChainMetrics(ctx *snow.ConsensusContext, summaryEnabled bool) (*chainMetrics, error) { cm := &chainMetrics{ ctx: ctx, @@ -78,14 +78,13 @@ func newChainMetrics(ctx *snow.Context, namespace string, summaryEnabled bool) ( messageSummaries: make(map[message.Op]*prometheus.SummaryVec, len(message.ConsensusResponseOps)), } - queryLatencyNamespace := fmt.Sprintf("%s_lat", namespace) errs := wrappers.Errs{} for _, op := range message.ConsensusResponseOps { cm.messageLatencies[op] = metric.NewAveragerWithErrs( - queryLatencyNamespace, + "lat", op.String(), defaultRequestHelpMsg, - ctx.Metrics, + ctx.Registerer, &errs, ) @@ -96,7 +95,7 @@ func newChainMetrics(ctx *snow.Context, namespace string, summaryEnabled bool) ( summaryName := fmt.Sprintf("%s_peer", op) summary := prometheus.NewSummaryVec( prometheus.SummaryOpts{ - Namespace: queryLatencyNamespace, + Namespace: "lat", Name: summaryName, Help: defaultRequestHelpMsg, }, @@ -104,7 +103,7 @@ func newChainMetrics(ctx *snow.Context, namespace string, summaryEnabled bool) ( ) cm.messageSummaries[op] = summary - if err := ctx.Metrics.Register(summary); err != nil { + if err := ctx.Registerer.Register(summary); err != nil { errs.Add(fmt.Errorf("failed to register %s statistics: %w", summaryName, err)) } } diff --git a/snow/networking/tracker/cpu_tracker.go b/snow/networking/tracker/cpu_tracker.go index 2a8814361462..0d7bc3339ce0 100644 --- a/snow/networking/tracker/cpu_tracker.go +++ b/snow/networking/tracker/cpu_tracker.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package tracker diff --git a/snow/networking/tracker/cpu_tracker_test.go b/snow/networking/tracker/cpu_tracker_test.go index b3ac82bf332e..ca0e6f686f56 100644 --- a/snow/networking/tracker/cpu_tracker_test.go +++ b/snow/networking/tracker/cpu_tracker_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package tracker diff --git a/snow/triggers/dispatcher.go b/snow/triggers/dispatcher.go index 7ace1028fe29..c6a4df887bc6 100644 --- a/snow/triggers/dispatcher.go +++ b/snow/triggers/dispatcher.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package triggers @@ -41,7 +41,7 @@ func (ed *EventDispatcher) Initialize(log logging.Logger) { // Accept is called when a transaction or block is accepted. // If the returned error is non-nil, the chain associated with [ctx] should shut // down and not commit [container] or any other container to its database as accepted. -func (ed *EventDispatcher) Accept(ctx *snow.Context, containerID ids.ID, container []byte) error { +func (ed *EventDispatcher) Accept(ctx *snow.ConsensusContext, containerID ids.ID, container []byte) error { ed.lock.Lock() defer ed.lock.Unlock() @@ -77,7 +77,7 @@ func (ed *EventDispatcher) Accept(ctx *snow.Context, containerID ids.ID, contain } // Reject is called when a transaction or block is rejected -func (ed *EventDispatcher) Reject(ctx *snow.Context, containerID ids.ID, container []byte) error { +func (ed *EventDispatcher) Reject(ctx *snow.ConsensusContext, containerID ids.ID, container []byte) error { ed.lock.Lock() defer ed.lock.Unlock() @@ -110,7 +110,7 @@ func (ed *EventDispatcher) Reject(ctx *snow.Context, containerID ids.ID, contain } // Issue is called when a transaction or block is issued -func (ed *EventDispatcher) Issue(ctx *snow.Context, containerID ids.ID, container []byte) error { +func (ed *EventDispatcher) Issue(ctx *snow.ConsensusContext, containerID ids.ID, container []byte) error { ed.lock.Lock() defer ed.lock.Unlock() diff --git a/snow/triggers/events.go b/snow/triggers/events.go index 2ada1cf3f91b..23606fe43de4 100644 --- a/snow/triggers/events.go +++ b/snow/triggers/events.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package triggers @@ -10,15 +10,15 @@ import ( // Acceptor is implemented when a struct is monitoring if a message is accepted type Acceptor interface { - Accept(ctx *snow.Context, containerID ids.ID, container []byte) error + Accept(ctx *snow.ConsensusContext, containerID ids.ID, container []byte) error } // Rejector is implemented when a struct is monitoring if a message is rejected type Rejector interface { - Reject(ctx *snow.Context, containerID ids.ID, container []byte) error + Reject(ctx *snow.ConsensusContext, containerID ids.ID, container []byte) error } // Issuer is implemented when a struct is monitoring if a message is issued type Issuer interface { - Issue(ctx *snow.Context, containerID ids.ID, container []byte) error + Issue(ctx *snow.ConsensusContext, containerID ids.ID, container []byte) error } diff --git a/snow/uptime/locked_calculator.go b/snow/uptime/locked_calculator.go index 552cbb80e52c..d5d9a2a3ff8e 100644 --- a/snow/uptime/locked_calculator.go +++ b/snow/uptime/locked_calculator.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package uptime @@ -9,7 +9,7 @@ import ( "time" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/utils" ) var ( @@ -21,13 +21,14 @@ var ( type LockedCalculator interface { Calculator - SetCalculator(ctx *snow.Context, newC Calculator) + SetCalculator(isBootstrapped *utils.AtomicBool, lock sync.Locker, newC Calculator) } type lockedCalculator struct { - lock sync.RWMutex - ctx *snow.Context - c Calculator + lock sync.RWMutex + isBootstrapped *utils.AtomicBool + calculatorLock sync.Locker + c Calculator } func NewLockedCalculator() LockedCalculator { @@ -38,12 +39,12 @@ func (c *lockedCalculator) CalculateUptime(nodeID ids.ShortID) (time.Duration, t c.lock.RLock() defer c.lock.RUnlock() - if c.ctx == nil || !c.ctx.IsBootstrapped() { + if c.isBootstrapped == nil || !c.isBootstrapped.GetValue() { return 0, time.Time{}, errNotReady } - c.ctx.Lock.Lock() - defer c.ctx.Lock.Unlock() + c.calculatorLock.Lock() + defer c.calculatorLock.Unlock() return c.c.CalculateUptime(nodeID) } @@ -52,12 +53,12 @@ func (c *lockedCalculator) CalculateUptimePercent(nodeID ids.ShortID) (float64, c.lock.RLock() defer c.lock.RUnlock() - if c.ctx == nil || !c.ctx.IsBootstrapped() { + if c.isBootstrapped == nil || !c.isBootstrapped.GetValue() { return 0, errNotReady } - c.ctx.Lock.Lock() - defer c.ctx.Lock.Unlock() + c.calculatorLock.Lock() + defer c.calculatorLock.Unlock() return c.c.CalculateUptimePercent(nodeID) } @@ -66,20 +67,21 @@ func (c *lockedCalculator) CalculateUptimePercentFrom(nodeID ids.ShortID, startT c.lock.RLock() defer c.lock.RUnlock() - if c.ctx == nil || !c.ctx.IsBootstrapped() { + if c.isBootstrapped == nil || !c.isBootstrapped.GetValue() { return 0, errNotReady } - c.ctx.Lock.Lock() - defer c.ctx.Lock.Unlock() + c.calculatorLock.Lock() + defer c.calculatorLock.Unlock() return c.c.CalculateUptimePercentFrom(nodeID, startTime) } -func (c *lockedCalculator) SetCalculator(ctx *snow.Context, newC Calculator) { +func (c *lockedCalculator) SetCalculator(isBootstrapped *utils.AtomicBool, lock sync.Locker, newC Calculator) { c.lock.Lock() defer c.lock.Unlock() - c.ctx = ctx + c.isBootstrapped = isBootstrapped + c.calculatorLock = lock c.c = newC } diff --git a/snow/uptime/locked_calculator_test.go b/snow/uptime/locked_calculator_test.go index 75d1a92216b1..f03e1c0ad5ad 100644 --- a/snow/uptime/locked_calculator_test.go +++ b/snow/uptime/locked_calculator_test.go @@ -1,13 +1,17 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + package uptime import ( "errors" + "sync" "testing" "time" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/uptime/mocks" + "github.com/ava-labs/avalanchego/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -26,11 +30,11 @@ func TestLockedCalculator(t *testing.T) { _, err = lc.CalculateUptimePercentFrom(nodeID, time.Now()) assert.EqualValues(errNotReady, err) - ctx := &snow.Context{} + var isBootstrapped utils.AtomicBool mockCalc := &mocks.Calculator{} // Should still error because ctx is not bootstrapped - lc.SetCalculator(ctx, mockCalc) + lc.SetCalculator(&isBootstrapped, &sync.Mutex{}, mockCalc) _, _, err = lc.CalculateUptime(nodeID) assert.EqualValues(errNotReady, err) _, err = lc.CalculateUptimePercent(nodeID) @@ -38,7 +42,7 @@ func TestLockedCalculator(t *testing.T) { _, err = lc.CalculateUptimePercentFrom(nodeID, time.Now()) assert.EqualValues(errNotReady, err) - ctx.Bootstrapped() + isBootstrapped.SetValue(true) // Should return the value from the mocked inner calculator mockErr := errors.New("mock error") diff --git a/snow/uptime/manager.go b/snow/uptime/manager.go index 4021c195a5f5..605c3d4eb54a 100644 --- a/snow/uptime/manager.go +++ b/snow/uptime/manager.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package uptime diff --git a/snow/uptime/manager_test.go b/snow/uptime/manager_test.go index 7ab3e7a71bec..707baf878900 100644 --- a/snow/uptime/manager_test.go +++ b/snow/uptime/manager_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package uptime diff --git a/snow/uptime/state.go b/snow/uptime/state.go index f9148ce5abab..7ae1a2b3c537 100644 --- a/snow/uptime/state.go +++ b/snow/uptime/state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package uptime diff --git a/snow/uptime/test_state.go b/snow/uptime/test_state.go index 90d18e4a440b..1b4bc5c2e025 100644 --- a/snow/uptime/test_state.go +++ b/snow/uptime/test_state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package uptime diff --git a/snow/validators/connector.go b/snow/validators/connector.go index 9ea9b15a6761..4a98c6ec40ec 100644 --- a/snow/validators/connector.go +++ b/snow/validators/connector.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package validators diff --git a/snow/validators/manager.go b/snow/validators/manager.go index 8dfa2708af0a..5b226f080628 100644 --- a/snow/validators/manager.go +++ b/snow/validators/manager.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package validators diff --git a/snow/validators/set.go b/snow/validators/set.go index 02e7469b8c4b..3d77552e6588 100644 --- a/snow/validators/set.go +++ b/snow/validators/set.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package validators diff --git a/snow/validators/set_test.go b/snow/validators/set_test.go index 546aa6121558..bb09c09391ca 100644 --- a/snow/validators/set_test.go +++ b/snow/validators/set_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package validators diff --git a/snow/validators/state.go b/snow/validators/state.go index 072dd9429538..929e53826cd2 100644 --- a/snow/validators/state.go +++ b/snow/validators/state.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package validators diff --git a/snow/validators/test_state.go b/snow/validators/test_state.go index 720fc42e35bf..ed3cb0d00867 100644 --- a/snow/validators/test_state.go +++ b/snow/validators/test_state.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package validators diff --git a/snow/validators/validator.go b/snow/validators/validator.go index c8d3045a5e4a..e071dc99b467 100644 --- a/snow/validators/validator.go +++ b/snow/validators/validator.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package validators diff --git a/staking/tls.go b/staking/tls.go index 198756af3d70..69ca99c9c681 100644 --- a/staking/tls.go +++ b/staking/tls.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package staking diff --git a/staking/tls_test.go b/staking/tls_test.go index 8f4b9b571682..62dc7f8bca5e 100644 --- a/staking/tls_test.go +++ b/staking/tls_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package staking diff --git a/utils/atomic_bool.go b/utils/atomic_bool.go index 2a2169beed12..1bccdf1eb718 100644 --- a/utils/atomic_bool.go +++ b/utils/atomic_bool.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package utils diff --git a/utils/atomic_interface.go b/utils/atomic_interface.go index 1c0f130cd008..1ee1a74e4b64 100644 --- a/utils/atomic_interface.go +++ b/utils/atomic_interface.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package utils diff --git a/utils/atomic_interface_test.go b/utils/atomic_interface_test.go index c3374d29d580..57b67d5d31b5 100644 --- a/utils/atomic_interface_test.go +++ b/utils/atomic_interface_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package utils diff --git a/utils/bloom/bloom_filter.go b/utils/bloom/bloom_filter.go index c32f29fe6afd..7105c694e912 100644 --- a/utils/bloom/bloom_filter.go +++ b/utils/bloom/bloom_filter.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package bloom diff --git a/utils/bloom/bloom_filter_test.go b/utils/bloom/bloom_filter_test.go index 07711fa0a7fd..f3746677828a 100644 --- a/utils/bloom/bloom_filter_test.go +++ b/utils/bloom/bloom_filter_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package bloom diff --git a/utils/bloom/map_filter.go b/utils/bloom/map_filter.go index 2363a9141282..5188f45fb624 100644 --- a/utils/bloom/map_filter.go +++ b/utils/bloom/map_filter.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package bloom diff --git a/utils/bytes.go b/utils/bytes.go index fa64b01fbd9c..c74f71ef2f20 100644 --- a/utils/bytes.go +++ b/utils/bytes.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package utils diff --git a/utils/bytes_test.go b/utils/bytes_test.go index 10f40a7d3b9e..d6f4de7c30d5 100644 --- a/utils/bytes_test.go +++ b/utils/bytes_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package utils diff --git a/utils/compression/compressor.go b/utils/compression/compressor.go index da26cd25c927..31b22e4d5d1b 100644 --- a/utils/compression/compressor.go +++ b/utils/compression/compressor.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package compression diff --git a/utils/compression/gzip_compressor.go b/utils/compression/gzip_compressor.go index bfc469b4419c..f067871eea28 100644 --- a/utils/compression/gzip_compressor.go +++ b/utils/compression/gzip_compressor.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package compression diff --git a/utils/compression/gzip_compressor_test.go b/utils/compression/gzip_compressor_test.go index ea22ddedbb3b..fa0e4594cbc3 100644 --- a/utils/compression/gzip_compressor_test.go +++ b/utils/compression/gzip_compressor_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package compression diff --git a/utils/compression/no_compressor.go b/utils/compression/no_compressor.go index c07744aa883b..6fda91e6db6c 100644 --- a/utils/compression/no_compressor.go +++ b/utils/compression/no_compressor.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package compression diff --git a/utils/compression/no_compressor_test.go b/utils/compression/no_compressor_test.go index bdd863539ce1..8f4cbf71a570 100644 --- a/utils/compression/no_compressor_test.go +++ b/utils/compression/no_compressor_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package compression diff --git a/utils/constants/aliases.go b/utils/constants/aliases.go index 8fada9b571a0..77c0fe8b41e5 100644 --- a/utils/constants/aliases.go +++ b/utils/constants/aliases.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package constants diff --git a/utils/constants/api_prefixes.go b/utils/constants/api_prefixes.go index 579fe619d665..f5e2eefbe50e 100644 --- a/utils/constants/api_prefixes.go +++ b/utils/constants/api_prefixes.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package constants diff --git a/utils/constants/application.go b/utils/constants/application.go index 9a1958018819..494734b89c7c 100644 --- a/utils/constants/application.go +++ b/utils/constants/application.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package constants diff --git a/utils/constants/health.go b/utils/constants/health.go index fa054e584778..b4b39137f26d 100644 --- a/utils/constants/health.go +++ b/utils/constants/health.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package constants diff --git a/utils/constants/network_ids.go b/utils/constants/network_ids.go index afdd88315246..86e4fc8e7ea7 100644 --- a/utils/constants/network_ids.go +++ b/utils/constants/network_ids.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package constants diff --git a/utils/constants/network_ids_test.go b/utils/constants/network_ids_test.go index 36624b0064f7..a1c8fab2184b 100644 --- a/utils/constants/network_ids_test.go +++ b/utils/constants/network_ids_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package constants diff --git a/utils/constants/networking.go b/utils/constants/networking.go index d8c2171ac5a3..59ba240915fc 100644 --- a/utils/constants/networking.go +++ b/utils/constants/networking.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package constants diff --git a/utils/crypto/crypto.go b/utils/crypto/crypto.go index 76d7ac9ef470..21d89199e8ca 100644 --- a/utils/crypto/crypto.go +++ b/utils/crypto/crypto.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package crypto diff --git a/utils/crypto/crypto_benchmark_test.go b/utils/crypto/crypto_benchmark_test.go index d60ca825d68f..90accc7b0d8b 100644 --- a/utils/crypto/crypto_benchmark_test.go +++ b/utils/crypto/crypto_benchmark_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package crypto diff --git a/utils/crypto/ed25519.go b/utils/crypto/ed25519.go index c08856b3c96e..a8878558035e 100644 --- a/utils/crypto/ed25519.go +++ b/utils/crypto/ed25519.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package crypto diff --git a/utils/crypto/errors.go b/utils/crypto/errors.go index 2aad688ff780..f2fb39874730 100644 --- a/utils/crypto/errors.go +++ b/utils/crypto/errors.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package crypto diff --git a/utils/crypto/rsa.go b/utils/crypto/rsa.go index c36dbd9f82c5..34645df0bc8a 100644 --- a/utils/crypto/rsa.go +++ b/utils/crypto/rsa.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package crypto diff --git a/utils/crypto/rsapss.go b/utils/crypto/rsapss.go index a21864c9f0ab..fd5a44c875e2 100644 --- a/utils/crypto/rsapss.go +++ b/utils/crypto/rsapss.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package crypto diff --git a/utils/crypto/secp256k1r.go b/utils/crypto/secp256k1r.go index 9d80923cefd8..6e34d22be192 100644 --- a/utils/crypto/secp256k1r.go +++ b/utils/crypto/secp256k1r.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package crypto diff --git a/utils/crypto/secp256k1r_test.go b/utils/crypto/secp256k1r_test.go index b45eb5de3067..51f7ec3be4a4 100644 --- a/utils/crypto/secp256k1r_test.go +++ b/utils/crypto/secp256k1r_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package crypto @@ -54,7 +54,7 @@ func TestExtensive(t *testing.T) { if key, err := f.NewPrivateKey(); err != nil { t.Fatalf("Generated bad private key") } else if _, err := key.SignHash(hash); err != nil { - t.Fatalf("Failed signing with:\n%s", formatting.DumpBytes{Bytes: key.Bytes()}) + t.Fatalf("Failed signing with:\n%s", formatting.DumpBytes(key.Bytes())) } } } diff --git a/utils/dynamicip/dynamicip.go b/utils/dynamicip/dynamicip.go index 29ad0db86ecf..8457d07f3fb8 100644 --- a/utils/dynamicip/dynamicip.go +++ b/utils/dynamicip/dynamicip.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package dynamicip diff --git a/utils/formatting/address_converter.go b/utils/formatting/address_converter.go new file mode 100644 index 000000000000..cd4012f8bf09 --- /dev/null +++ b/utils/formatting/address_converter.go @@ -0,0 +1,24 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package formatting + +// ConvertAddresses converts a list of addresses with arbitrary chains and HRPs +// (e.g. X-local1....) to a list of addresses with the provided format +// (e.g. P-custom1...). +func ConvertAddresses(destChain string, toHRP string, addresses []string) ([]string, error) { + convertedAddrs := make([]string, len(addresses)) + for i, addr := range addresses { + _, _, addrBytes, err := ParseAddress(addr) + if err != nil { + return nil, err + } + + newAddrStr, err := FormatAddress(destChain, toHRP, addrBytes) + if err != nil { + return nil, err + } + convertedAddrs[i] = newAddrStr + } + return convertedAddrs, nil +} diff --git a/utils/formatting/address_converter_test.go b/utils/formatting/address_converter_test.go new file mode 100644 index 000000000000..f394e9fb2263 --- /dev/null +++ b/utils/formatting/address_converter_test.go @@ -0,0 +1,70 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package formatting + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestAddressConversion(t *testing.T) { + assert := assert.New(t) + + tests := []struct { + chain string + hrp string + srcAddrs []string + expectedErr error + expectedAddrs []string + }{ + { + chain: "X", + hrp: "custom", + srcAddrs: []string{ + "X-local1g65uqn6t77p656w64023nh8nd9updzmxyymev2", + "X-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u", + }, + expectedAddrs: []string{ + "X-custom1g65uqn6t77p656w64023nh8nd9updzmxwd59gh", + "X-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p", + }, + }, + { + chain: "X", + hrp: "local", + srcAddrs: []string{ + "X-local1g65uqn6t77p656w64023nh8nd9updzmxyymev2", + "X-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u", + }, + expectedAddrs: []string{ + "X-local1g65uqn6t77p656w64023nh8nd9updzmxyymev2", + "X-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u", + }, + }, + { + srcAddrs: []string{ + "X-local1g65uqn6t77p656w64023nh8nd9updzmxyymev2", + }, + expectedAddrs: []string{ + "-1g65uqn6t77p656w64023nh8nd9updzmx4x372p", + }, + }, + { + srcAddrs: []string{ + "not a valid address", + }, + expectedErr: errNoSeparator, + }, + } + for _, test := range tests { + result, err := ConvertAddresses(test.chain, test.hrp, test.srcAddrs) + assert.Equal(test.expectedErr, err) + assert.Len(result, len(test.expectedAddrs)) + for i, want := range test.expectedAddrs { + got := result[i] + assert.Equal(want, got) + } + } +} diff --git a/utils/formatting/addresses.go b/utils/formatting/addresses.go index 5475935915dd..30dd1671f0f7 100644 --- a/utils/formatting/addresses.go +++ b/utils/formatting/addresses.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package formatting @@ -70,9 +70,5 @@ func FormatBech32(hrp string, payload []byte) (string, error) { if err != nil { return "", errBits8To5 } - addr, err := bech32.Encode(hrp, fiveBits) - if err != nil { - return "", err - } - return addr, nil + return bech32.Encode(hrp, fiveBits) } diff --git a/utils/formatting/custom_stringer.go b/utils/formatting/custom_stringer.go deleted file mode 100644 index 6017488c25fc..000000000000 --- a/utils/formatting/custom_stringer.go +++ /dev/null @@ -1,8 +0,0 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package formatting - -type CustomStringer struct{ Stringer func() string } - -func (cs CustomStringer) String() string { return cs.Stringer() } diff --git a/utils/formatting/dump_bytes.go b/utils/formatting/dump_bytes.go index 6c32be7de573..33a326bebe2a 100644 --- a/utils/formatting/dump_bytes.go +++ b/utils/formatting/dump_bytes.go @@ -1,13 +1,16 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package formatting import ( "encoding/hex" + "fmt" "strings" ) -type DumpBytes struct{ Bytes []byte } +var _ fmt.Stringer = DumpBytes{} -func (db DumpBytes) String() string { return strings.TrimSpace(hex.Dump(db.Bytes)) } +type DumpBytes []byte + +func (db DumpBytes) String() string { return strings.TrimSpace(hex.Dump(db)) } diff --git a/utils/formatting/encoding.go b/utils/formatting/encoding.go index 7cc18b061f9d..a34f31866a3a 100644 --- a/utils/formatting/encoding.go +++ b/utils/formatting/encoding.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package formatting diff --git a/utils/formatting/encoding_benchmark_test.go b/utils/formatting/encoding_benchmark_test.go index c7f18a104af6..9eb53aebc14f 100644 --- a/utils/formatting/encoding_benchmark_test.go +++ b/utils/formatting/encoding_benchmark_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package formatting diff --git a/utils/formatting/encoding_test.go b/utils/formatting/encoding_test.go index 310bc483f388..521af1dbf7eb 100644 --- a/utils/formatting/encoding_test.go +++ b/utils/formatting/encoding_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package formatting diff --git a/utils/formatting/int_format.go b/utils/formatting/int_format.go index 6c586d58e115..89bc8a35f567 100644 --- a/utils/formatting/int_format.go +++ b/utils/formatting/int_format.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package formatting diff --git a/utils/formatting/int_format_test.go b/utils/formatting/int_format_test.go index 8ec270ddb9ec..311da4326389 100644 --- a/utils/formatting/int_format_test.go +++ b/utils/formatting/int_format_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package formatting diff --git a/utils/formatting/prefixed_stringer.go b/utils/formatting/prefixed_stringer.go index 320dfd6aa890..5a02921c701a 100644 --- a/utils/formatting/prefixed_stringer.go +++ b/utils/formatting/prefixed_stringer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package formatting diff --git a/utils/hashing/hashing.go b/utils/hashing/hashing.go index b7e5ce7527d4..4070ce08f0e0 100644 --- a/utils/hashing/hashing.go +++ b/utils/hashing/hashing.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package hashing diff --git a/utils/ip.go b/utils/ip.go index 3a350d58acfe..cf365e5baa1e 100644 --- a/utils/ip.go +++ b/utils/ip.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package utils diff --git a/utils/ipcert.go b/utils/ipcert.go index db6e66ca6e48..b304b0feddff 100644 --- a/utils/ipcert.go +++ b/utils/ipcert.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package utils diff --git a/utils/json/codec.go b/utils/json/codec.go index df8d0db179db..2a34954f4686 100644 --- a/utils/json/codec.go +++ b/utils/json/codec.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package json diff --git a/utils/json/float32.go b/utils/json/float32.go index 4ed5995a428b..4200a4e37fbc 100644 --- a/utils/json/float32.go +++ b/utils/json/float32.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package json diff --git a/utils/json/float32_test.go b/utils/json/float32_test.go index 45670128cdbe..29b90f6a87b7 100644 --- a/utils/json/float32_test.go +++ b/utils/json/float32_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package json diff --git a/utils/json/float64.go b/utils/json/float64.go index 728950252665..2be592be5746 100644 --- a/utils/json/float64.go +++ b/utils/json/float64.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package json diff --git a/utils/json/uint16.go b/utils/json/uint16.go index e909dfb02a9d..017f70f905b9 100644 --- a/utils/json/uint16.go +++ b/utils/json/uint16.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package json diff --git a/utils/json/uint32.go b/utils/json/uint32.go index 3fa0651fa8fc..02dad836ab1b 100644 --- a/utils/json/uint32.go +++ b/utils/json/uint32.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package json diff --git a/utils/json/uint64.go b/utils/json/uint64.go index 7c971b62be80..06d59bb6a528 100644 --- a/utils/json/uint64.go +++ b/utils/json/uint64.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package json diff --git a/utils/json/uint8.go b/utils/json/uint8.go index da9744344744..957e6cc42f9a 100644 --- a/utils/json/uint8.go +++ b/utils/json/uint8.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package json diff --git a/utils/linkedhashmap/linkedhashmap.go b/utils/linkedhashmap/linkedhashmap.go index dbf80aa22705..42da5d475a9e 100644 --- a/utils/linkedhashmap/linkedhashmap.go +++ b/utils/linkedhashmap/linkedhashmap.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inte. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inte. All rights reserved. // See the file LICENSE for licensing terms. package linkedhashmap diff --git a/utils/linkedhashmap/linkedhashmap_test.go b/utils/linkedhashmap/linkedhashmap_test.go index e104281a39a4..977d2eef6633 100644 --- a/utils/linkedhashmap/linkedhashmap_test.go +++ b/utils/linkedhashmap/linkedhashmap_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package linkedhashmap diff --git a/utils/logging/color.go b/utils/logging/color.go index e28e3d38a10c..25c75028d813 100644 --- a/utils/logging/color.go +++ b/utils/logging/color.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package logging diff --git a/utils/logging/config.go b/utils/logging/config.go index 8a71c9b12be1..c39ee2dfeead 100644 --- a/utils/logging/config.go +++ b/utils/logging/config.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package logging diff --git a/utils/logging/factory.go b/utils/logging/factory.go index 850d05d70271..0a2e335cf3ec 100644 --- a/utils/logging/factory.go +++ b/utils/logging/factory.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package logging diff --git a/utils/logging/level.go b/utils/logging/level.go index 3d16c3fbfde9..fbef50d583b6 100644 --- a/utils/logging/level.go +++ b/utils/logging/level.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package logging diff --git a/utils/logging/level_test.go b/utils/logging/level_test.go index d13d3ece589a..9c445925893e 100644 --- a/utils/logging/level_test.go +++ b/utils/logging/level_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package logging diff --git a/utils/logging/log.go b/utils/logging/log.go index e4fd190eab84..d468cf5de55f 100644 --- a/utils/logging/log.go +++ b/utils/logging/log.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package logging diff --git a/utils/logging/log_test.go b/utils/logging/log_test.go index 3d8d37afa7b4..cfb63aa145b7 100644 --- a/utils/logging/log_test.go +++ b/utils/logging/log_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package logging diff --git a/utils/logging/logger.go b/utils/logging/logger.go index 93c63e3de84e..d4ec98ae7945 100644 --- a/utils/logging/logger.go +++ b/utils/logging/logger.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package logging diff --git a/utils/logging/sanitize.go b/utils/logging/sanitize.go index 16e1c3111013..04f06d291806 100644 --- a/utils/logging/sanitize.go +++ b/utils/logging/sanitize.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package logging diff --git a/utils/logging/stack.go b/utils/logging/stack.go index d2ee123916cf..a26cc860a9e8 100644 --- a/utils/logging/stack.go +++ b/utils/logging/stack.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package logging diff --git a/utils/logging/test_factory.go b/utils/logging/test_factory.go index 88252296243f..f6b58ecfb78c 100644 --- a/utils/logging/test_factory.go +++ b/utils/logging/test_factory.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package logging diff --git a/utils/logging/test_log.go b/utils/logging/test_log.go index 2a3c3aeeabbd..78bb7ab3ae76 100644 --- a/utils/logging/test_log.go +++ b/utils/logging/test_log.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package logging diff --git a/utils/math/averager.go b/utils/math/averager.go index c44742fc3a15..3340978761f9 100644 --- a/utils/math/averager.go +++ b/utils/math/averager.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package math diff --git a/utils/math/continuous_averager.go b/utils/math/continuous_averager.go index c98d869dd6c9..f189b30b1061 100644 --- a/utils/math/continuous_averager.go +++ b/utils/math/continuous_averager.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package math diff --git a/utils/math/continuous_averager_benchmark_test.go b/utils/math/continuous_averager_benchmark_test.go index d80501e9dcb4..200362c68b14 100644 --- a/utils/math/continuous_averager_benchmark_test.go +++ b/utils/math/continuous_averager_benchmark_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package math diff --git a/utils/math/continuous_averager_test.go b/utils/math/continuous_averager_test.go index 24e6fee6937d..cdce6b1817fc 100644 --- a/utils/math/continuous_averager_test.go +++ b/utils/math/continuous_averager_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package math diff --git a/utils/math/safe_math.go b/utils/math/safe_math.go index 3c3e77463833..60d1d184d059 100644 --- a/utils/math/safe_math.go +++ b/utils/math/safe_math.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package math diff --git a/utils/math/safe_math_test.go b/utils/math/safe_math_test.go index e5653ea7bf5f..9a8f6a68d51f 100644 --- a/utils/math/safe_math_test.go +++ b/utils/math/safe_math_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package math diff --git a/utils/math/sync_averager.go b/utils/math/sync_averager.go index 03823c9b5839..9c49a6d988b1 100644 --- a/utils/math/sync_averager.go +++ b/utils/math/sync_averager.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package math diff --git a/utils/metric/api_interceptor.go b/utils/metric/api_interceptor.go index c59b270e9cb1..e13cec8db0b3 100644 --- a/utils/metric/api_interceptor.go +++ b/utils/metric/api_interceptor.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package metric diff --git a/utils/metric/averager.go b/utils/metric/averager.go index 304930510a8e..29fbd5ffa327 100644 --- a/utils/metric/averager.go +++ b/utils/metric/averager.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package metric diff --git a/utils/password/hash.go b/utils/password/hash.go index db8a01d2993e..8c0e6e168008 100644 --- a/utils/password/hash.go +++ b/utils/password/hash.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package password diff --git a/utils/password/hash_test.go b/utils/password/hash_test.go index 12ba3ecda9fd..58643f06c4f7 100644 --- a/utils/password/hash_test.go +++ b/utils/password/hash_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package password diff --git a/utils/password/password.go b/utils/password/password.go index 2d10e9abe2a8..908f7afd2296 100644 --- a/utils/password/password.go +++ b/utils/password/password.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package password diff --git a/utils/password/password_test.go b/utils/password/password_test.go index 63803a340b38..7aebeda91f8d 100644 --- a/utils/password/password_test.go +++ b/utils/password/password_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package password diff --git a/utils/perms/chmod.go b/utils/perms/chmod.go index c3e6e82ae9f0..a61261f2e95b 100644 --- a/utils/perms/chmod.go +++ b/utils/perms/chmod.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package perms diff --git a/utils/perms/create.go b/utils/perms/create.go index ad29705c3427..170483b9ab71 100644 --- a/utils/perms/create.go +++ b/utils/perms/create.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package perms diff --git a/utils/perms/perms.go b/utils/perms/perms.go index 6be2e8ac7204..de552b4a024c 100644 --- a/utils/perms/perms.go +++ b/utils/perms/perms.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package perms diff --git a/utils/perms/write_file.go b/utils/perms/write_file.go index 7daef34e1e63..7a7c2b904854 100644 --- a/utils/perms/write_file.go +++ b/utils/perms/write_file.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package perms diff --git a/utils/profiler/continuous.go b/utils/profiler/continuous.go index 99f6558a0608..cf5b59fb7c75 100644 --- a/utils/profiler/continuous.go +++ b/utils/profiler/continuous.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package profiler diff --git a/utils/profiler/profiler.go b/utils/profiler/profiler.go index e85ac44db26a..758e7fbd1747 100644 --- a/utils/profiler/profiler.go +++ b/utils/profiler/profiler.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package profiler diff --git a/utils/profiler/profiler_test.go b/utils/profiler/profiler_test.go index ddbdb1ff4fc6..7056b1a6f66f 100644 --- a/utils/profiler/profiler_test.go +++ b/utils/profiler/profiler_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package profiler diff --git a/utils/rpc/requester.go b/utils/rpc/requester.go index 939c6c19f4b8..0ae71ab3437f 100644 --- a/utils/rpc/requester.go +++ b/utils/rpc/requester.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package rpc diff --git a/utils/sampler/rand.go b/utils/sampler/rand.go index 02bd1528577b..c486ecf996db 100644 --- a/utils/sampler/rand.go +++ b/utils/sampler/rand.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/uniform.go b/utils/sampler/uniform.go index 67a49553c622..679022568d0f 100644 --- a/utils/sampler/uniform.go +++ b/utils/sampler/uniform.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/uniform_benchmark_test.go b/utils/sampler/uniform_benchmark_test.go index ed51d94aa2b7..f8df06cdcdbf 100644 --- a/utils/sampler/uniform_benchmark_test.go +++ b/utils/sampler/uniform_benchmark_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/uniform_best.go b/utils/sampler/uniform_best.go index fcbc267fa8dd..e1c5ae619aa7 100644 --- a/utils/sampler/uniform_best.go +++ b/utils/sampler/uniform_best.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/uniform_replacer.go b/utils/sampler/uniform_replacer.go index 03ba9a94864d..fc2fddc8f697 100644 --- a/utils/sampler/uniform_replacer.go +++ b/utils/sampler/uniform_replacer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/uniform_resample.go b/utils/sampler/uniform_resample.go index 3809b5ac3181..101f2a67b898 100644 --- a/utils/sampler/uniform_resample.go +++ b/utils/sampler/uniform_resample.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/uniform_test.go b/utils/sampler/uniform_test.go index 045e8fd7e4b5..0e302b810056 100644 --- a/utils/sampler/uniform_test.go +++ b/utils/sampler/uniform_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/weighted.go b/utils/sampler/weighted.go index 761a658317c2..6cdfea9d0c2a 100644 --- a/utils/sampler/weighted.go +++ b/utils/sampler/weighted.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/weighted_array.go b/utils/sampler/weighted_array.go index 7dfc0cce2493..1a40c287e40a 100644 --- a/utils/sampler/weighted_array.go +++ b/utils/sampler/weighted_array.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/weighted_benchmark_test.go b/utils/sampler/weighted_benchmark_test.go index c4e549dc720a..9a5f5ed3ca09 100644 --- a/utils/sampler/weighted_benchmark_test.go +++ b/utils/sampler/weighted_benchmark_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/weighted_best.go b/utils/sampler/weighted_best.go index 4f76fa4cb028..cdbac65a6638 100644 --- a/utils/sampler/weighted_best.go +++ b/utils/sampler/weighted_best.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/weighted_heap.go b/utils/sampler/weighted_heap.go index 1fe5a393ac50..c5bb8f80a319 100644 --- a/utils/sampler/weighted_heap.go +++ b/utils/sampler/weighted_heap.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/weighted_heap_test.go b/utils/sampler/weighted_heap_test.go index 92128a063940..0ea710f39a45 100644 --- a/utils/sampler/weighted_heap_test.go +++ b/utils/sampler/weighted_heap_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/weighted_linear.go b/utils/sampler/weighted_linear.go index 24505bed0a07..4ed52f9994d4 100644 --- a/utils/sampler/weighted_linear.go +++ b/utils/sampler/weighted_linear.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/weighted_test.go b/utils/sampler/weighted_test.go index c56b14820bfa..74e3ed14ab9b 100644 --- a/utils/sampler/weighted_test.go +++ b/utils/sampler/weighted_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/weighted_uniform.go b/utils/sampler/weighted_uniform.go index 5dfc97b1433c..845a4de8a8c7 100644 --- a/utils/sampler/weighted_uniform.go +++ b/utils/sampler/weighted_uniform.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/weighted_without_replacement.go b/utils/sampler/weighted_without_replacement.go index eff1e7d73b2d..9f00c8474760 100644 --- a/utils/sampler/weighted_without_replacement.go +++ b/utils/sampler/weighted_without_replacement.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/weighted_without_replacement_benchmark_test.go b/utils/sampler/weighted_without_replacement_benchmark_test.go index 52d364243b83..17796ff392cb 100644 --- a/utils/sampler/weighted_without_replacement_benchmark_test.go +++ b/utils/sampler/weighted_without_replacement_benchmark_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/weighted_without_replacement_generic.go b/utils/sampler/weighted_without_replacement_generic.go index 552b1ba7f11f..826a10b8e89b 100644 --- a/utils/sampler/weighted_without_replacement_generic.go +++ b/utils/sampler/weighted_without_replacement_generic.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sampler/weighted_without_replacement_test.go b/utils/sampler/weighted_without_replacement_test.go index 1bcd928fc836..0ef23f8217f9 100644 --- a/utils/sampler/weighted_without_replacement_test.go +++ b/utils/sampler/weighted_without_replacement_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package sampler diff --git a/utils/sorting.go b/utils/sorting.go index 5be6b88fd070..865bf7218085 100644 --- a/utils/sorting.go +++ b/utils/sorting.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package utils diff --git a/utils/sorting_test.go b/utils/sorting_test.go index b7565dff8c5d..f5a24bdfd812 100644 --- a/utils/sorting_test.go +++ b/utils/sorting_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package utils diff --git a/utils/storage/storage_common.go b/utils/storage/storage_common.go index d12e3cbaedc5..36916a0ac9a8 100644 --- a/utils/storage/storage_common.go +++ b/utils/storage/storage_common.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package storage diff --git a/utils/storage/storage_unix.go b/utils/storage/storage_unix.go index 3a3bd052a654..b82c57fee1de 100644 --- a/utils/storage/storage_unix.go +++ b/utils/storage/storage_unix.go @@ -1,7 +1,7 @@ //go:build !windows // +build !windows -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package storage diff --git a/utils/storage/storage_windows.go b/utils/storage/storage_windows.go index 80713ee9414d..932838a54057 100644 --- a/utils/storage/storage_windows.go +++ b/utils/storage/storage_windows.go @@ -1,7 +1,7 @@ //go:build windows // +build windows -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package storage diff --git a/utils/subprocess/linux_new.go b/utils/subprocess/linux_new.go index 9e98fb083d0f..52aad156190b 100644 --- a/utils/subprocess/linux_new.go +++ b/utils/subprocess/linux_new.go @@ -3,7 +3,7 @@ // ^ syscall.SysProcAttr only has field Pdeathsig on Linux -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package subprocess diff --git a/utils/subprocess/non_linux_new.go b/utils/subprocess/non_linux_new.go index 8eaccfb7fe64..e3676848c7b2 100644 --- a/utils/subprocess/non_linux_new.go +++ b/utils/subprocess/non_linux_new.go @@ -1,7 +1,7 @@ //go:build !linux // +build !linux -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package subprocess diff --git a/utils/timer/adaptive_timeout_manager.go b/utils/timer/adaptive_timeout_manager.go index e91acbab8512..1d7e5f7400e1 100644 --- a/utils/timer/adaptive_timeout_manager.go +++ b/utils/timer/adaptive_timeout_manager.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timer diff --git a/utils/timer/adaptive_timeout_manager_test.go b/utils/timer/adaptive_timeout_manager_test.go index 8497f268583b..bd5dcbcbc3d0 100644 --- a/utils/timer/adaptive_timeout_manager_test.go +++ b/utils/timer/adaptive_timeout_manager_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timer diff --git a/utils/timer/meter.go b/utils/timer/meter.go index f259a7c51ae2..418e323305e8 100644 --- a/utils/timer/meter.go +++ b/utils/timer/meter.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timer diff --git a/utils/timer/mockable/clock.go b/utils/timer/mockable/clock.go index 52e435108d8d..72bb02023150 100644 --- a/utils/timer/mockable/clock.go +++ b/utils/timer/mockable/clock.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package mockable diff --git a/utils/timer/mockable/clock_test.go b/utils/timer/mockable/clock_test.go index 9d5d45b0cf5f..0070a00d3222 100644 --- a/utils/timer/mockable/clock_test.go +++ b/utils/timer/mockable/clock_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package mockable diff --git a/utils/timer/repeater.go b/utils/timer/repeater.go index 16b035dc5e91..d8844e719d42 100644 --- a/utils/timer/repeater.go +++ b/utils/timer/repeater.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timer diff --git a/utils/timer/repeater_test.go b/utils/timer/repeater_test.go index 5499202cf107..b3f741059769 100644 --- a/utils/timer/repeater_test.go +++ b/utils/timer/repeater_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timer diff --git a/utils/timer/staged_timer.go b/utils/timer/staged_timer.go index 64f0cf87cc91..c807f8f3e934 100644 --- a/utils/timer/staged_timer.go +++ b/utils/timer/staged_timer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timer diff --git a/utils/timer/staged_timer_test.go b/utils/timer/staged_timer_test.go index 952688279243..ffe2bdf277cd 100644 --- a/utils/timer/staged_timer_test.go +++ b/utils/timer/staged_timer_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timer diff --git a/utils/timer/timed_meter.go b/utils/timer/timed_meter.go index 3a35daa90ced..3559c912664f 100644 --- a/utils/timer/timed_meter.go +++ b/utils/timer/timed_meter.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timer diff --git a/utils/timer/timeout_manager.go b/utils/timer/timeout_manager.go index d3f73f32cf8f..2545fc8ec22b 100644 --- a/utils/timer/timeout_manager.go +++ b/utils/timer/timeout_manager.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timer diff --git a/utils/timer/timeout_manager_test.go b/utils/timer/timeout_manager_test.go index fde53acce86e..512513c82371 100644 --- a/utils/timer/timeout_manager_test.go +++ b/utils/timer/timeout_manager_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timer diff --git a/utils/timer/timer.go b/utils/timer/timer.go index 7eaab16ebbbe..45292ab400e3 100644 --- a/utils/timer/timer.go +++ b/utils/timer/timer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timer diff --git a/utils/timer/timer_test.go b/utils/timer/timer_test.go index ddff3d89cfd3..73c1de790b8b 100644 --- a/utils/timer/timer_test.go +++ b/utils/timer/timer_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package timer diff --git a/utils/ulimit/ulimit.go b/utils/ulimit/ulimit.go index eb57c231f65d..078f7ecaca90 100644 --- a/utils/ulimit/ulimit.go +++ b/utils/ulimit/ulimit.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ulimit diff --git a/utils/units/avax.go b/utils/units/avax.go index 6fdc4887608d..227b07af4fc8 100644 --- a/utils/units/avax.go +++ b/utils/units/avax.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package units diff --git a/utils/units/bytes.go b/utils/units/bytes.go index 819f30189c97..fc7f2d164a82 100644 --- a/utils/units/bytes.go +++ b/utils/units/bytes.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package units diff --git a/utils/uptime/continuous_meter.go b/utils/uptime/continuous_meter.go index 1820c271e9f9..188b25431d38 100644 --- a/utils/uptime/continuous_meter.go +++ b/utils/uptime/continuous_meter.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package uptime diff --git a/utils/uptime/factory.go b/utils/uptime/factory.go index c742242b7fdf..455ce1a80ea4 100644 --- a/utils/uptime/factory.go +++ b/utils/uptime/factory.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package uptime diff --git a/utils/uptime/interval_meter.go b/utils/uptime/interval_meter.go index 16b132c8ac08..6565524518a3 100644 --- a/utils/uptime/interval_meter.go +++ b/utils/uptime/interval_meter.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package uptime diff --git a/utils/uptime/meter.go b/utils/uptime/meter.go index 7ae02d44bcc0..ded98de43f03 100644 --- a/utils/uptime/meter.go +++ b/utils/uptime/meter.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package uptime diff --git a/utils/uptime/meter_benchmark_test.go b/utils/uptime/meter_benchmark_test.go index 3b395e89209d..aad62078a702 100644 --- a/utils/uptime/meter_benchmark_test.go +++ b/utils/uptime/meter_benchmark_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package uptime diff --git a/utils/uptime/meter_test.go b/utils/uptime/meter_test.go index 7446c63dec83..872a34fd724d 100644 --- a/utils/uptime/meter_test.go +++ b/utils/uptime/meter_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package uptime diff --git a/utils/wrappers/closers.go b/utils/wrappers/closers.go index ea3275795a47..dc7d44ab23a7 100644 --- a/utils/wrappers/closers.go +++ b/utils/wrappers/closers.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package wrappers diff --git a/utils/wrappers/errors.go b/utils/wrappers/errors.go index 0e7d43673d65..fc6e841877ce 100644 --- a/utils/wrappers/errors.go +++ b/utils/wrappers/errors.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package wrappers diff --git a/utils/wrappers/packing.go b/utils/wrappers/packing.go index 26e41389d32f..a1020dd60577 100644 --- a/utils/wrappers/packing.go +++ b/utils/wrappers/packing.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package wrappers diff --git a/utils/wrappers/packing_test.go b/utils/wrappers/packing_test.go index a6accbe10cb5..2dc169bbb11f 100644 --- a/utils/wrappers/packing_test.go +++ b/utils/wrappers/packing_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package wrappers diff --git a/version/application.go b/version/application.go index fde933885498..764236ca3395 100644 --- a/version/application.go +++ b/version/application.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package version diff --git a/version/application_test.go b/version/application_test.go index 0758c0e89936..e897f54f8e7c 100644 --- a/version/application_test.go +++ b/version/application_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package version diff --git a/version/compatibility.go b/version/compatibility.go index 61b538a92432..ee81e21b282d 100644 --- a/version/compatibility.go +++ b/version/compatibility.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package version diff --git a/version/compatibility_test.go b/version/compatibility_test.go index 9a771c510db4..589388000031 100644 --- a/version/compatibility_test.go +++ b/version/compatibility_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package version diff --git a/version/constants.go b/version/constants.go index d81c3f6087c2..1c0891e8d6ae 100644 --- a/version/constants.go +++ b/version/constants.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package version @@ -11,10 +11,10 @@ import ( // These are globals that describe network upgrades and node versions var ( - Current = NewDefaultVersion(1, 6, 5) + Current = NewDefaultVersion(1, 7, 0) CurrentApp = NewDefaultApplication(constants.PlatformName, Current.Major(), Current.Minor(), Current.Patch()) - MinimumCompatibleVersion = NewDefaultApplication(constants.PlatformName, 1, 6, 0) - PrevMinimumCompatibleVersion = NewDefaultApplication(constants.PlatformName, 1, 5, 0) + MinimumCompatibleVersion = NewDefaultApplication(constants.PlatformName, 1, 7, 0) + PrevMinimumCompatibleVersion = NewDefaultApplication(constants.PlatformName, 1, 6, 0) MinimumUnmaskedVersion = NewDefaultApplication(constants.PlatformName, 1, 1, 0) PrevMinimumUnmaskedVersion = NewDefaultApplication(constants.PlatformName, 1, 0, 0) VersionParser = NewDefaultApplicationParser() @@ -61,6 +61,12 @@ var ( constants.FujiID: 47437, } ApricotPhase4DefaultMinPChainHeight uint64 + + ApricotPhase5Times = map[uint32]time.Time{ + constants.MainnetID: time.Date(3022, time.December, 29, 0, 0, 0, 0, time.UTC), + constants.FujiID: time.Date(2021, time.November, 24, 15, 0, 0, 0, time.UTC), + } + ApricotPhase5DefaultTime = time.Date(2020, time.December, 5, 5, 0, 0, 0, time.UTC) ) func GetApricotPhase0Time(networkID uint32) time.Time { @@ -105,11 +111,18 @@ func GetApricotPhase4MinPChainHeight(networkID uint32) uint64 { return ApricotPhase4DefaultMinPChainHeight } +func GetApricotPhase5Time(networkID uint32) time.Time { + if upgradeTime, exists := ApricotPhase5Times[networkID]; exists { + return upgradeTime + } + return ApricotPhase5DefaultTime +} + func GetCompatibility(networkID uint32) Compatibility { return NewCompatibility( CurrentApp, MinimumCompatibleVersion, - GetApricotPhase4Time(networkID), + GetApricotPhase5Time(networkID), PrevMinimumCompatibleVersion, MinimumUnmaskedVersion, GetApricotPhase0Time(networkID), diff --git a/version/parser.go b/version/parser.go index 7b9d773ab015..89c8bd187f25 100644 --- a/version/parser.go +++ b/version/parser.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package version diff --git a/version/parser_test.go b/version/parser_test.go index 013beb556041..dac73d5dfcb5 100644 --- a/version/parser_test.go +++ b/version/parser_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package version diff --git a/version/string.go b/version/string.go index 0eb7b33f77ae..74d7141caf6e 100644 --- a/version/string.go +++ b/version/string.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package version diff --git a/version/version.go b/version/version.go index cf77ae685ff8..ad3aba4ae8ba 100644 --- a/version/version.go +++ b/version/version.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package version diff --git a/version/version_test.go b/version/version_test.go index 5b700d263d77..8588cd247707 100644 --- a/version/version_test.go +++ b/version/version_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package version diff --git a/vms/avm/base_tx.go b/vms/avm/base_tx.go index b6513ff8d1ee..352074c47149 100644 --- a/vms/avm/base_tx.go +++ b/vms/avm/base_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/base_tx_test.go b/vms/avm/base_tx_test.go index 5b0a495d976e..2c5fc272a280 100644 --- a/vms/avm/base_tx_test.go +++ b/vms/avm/base_tx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/client.go b/vms/avm/client.go index d1dac772a6d8..3e3ae5a7acf2 100644 --- a/vms/avm/client.go +++ b/vms/avm/client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/codec_registry.go b/vms/avm/codec_registry.go index 44a254b4adb2..9f151f2f50c8 100644 --- a/vms/avm/codec_registry.go +++ b/vms/avm/codec_registry.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/create_asset_tx.go b/vms/avm/create_asset_tx.go index a13132f6a11b..f583ea29848b 100644 --- a/vms/avm/create_asset_tx.go +++ b/vms/avm/create_asset_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/create_asset_tx_test.go b/vms/avm/create_asset_tx_test.go index 0308d30da329..9fad027513b1 100644 --- a/vms/avm/create_asset_tx_test.go +++ b/vms/avm/create_asset_tx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/export_tx.go b/vms/avm/export_tx.go index 7824a249887f..e44fcd0106bc 100644 --- a/vms/avm/export_tx.go +++ b/vms/avm/export_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm @@ -80,13 +80,9 @@ func (t *ExportTx) SyntacticVerify( // SemanticVerify that this transaction is valid to be spent. func (t *ExportTx) SemanticVerify(vm *VM, tx UnsignedTx, creds []verify.Verifiable) error { if vm.bootstrapped { - subnetID, err := vm.ctx.SNLookup.SubnetID(t.DestinationChain) - if err != nil { + if err := verify.SameSubnet(vm.ctx, t.DestinationChain); err != nil { return err } - if vm.ctx.SubnetID != subnetID || t.DestinationChain == vm.ctx.ChainID { - return errWrongBlockchainID - } } for _, out := range t.ExportedOuts { diff --git a/vms/avm/export_tx_test.go b/vms/avm/export_tx_test.go index 62b0d4b1d085..f5bd5bc6657e 100644 --- a/vms/avm/export_tx_test.go +++ b/vms/avm/export_tx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/factory.go b/vms/avm/factory.go index d722cb0adcba..7bd53d4e528d 100644 --- a/vms/avm/factory.go +++ b/vms/avm/factory.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/fx.go b/vms/avm/fx.go index b30a2005bd3b..3530ad1478dd 100644 --- a/vms/avm/fx.go +++ b/vms/avm/fx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/fx_test.go b/vms/avm/fx_test.go index bb238fd66016..200a5978209c 100644 --- a/vms/avm/fx_test.go +++ b/vms/avm/fx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/genesis.go b/vms/avm/genesis.go index 8a5b8eec5cfb..feef307b93e3 100644 --- a/vms/avm/genesis.go +++ b/vms/avm/genesis.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/health.go b/vms/avm/health.go index 6ee28152c634..b9dfb4d53dd4 100644 --- a/vms/avm/health.go +++ b/vms/avm/health.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/import_tx.go b/vms/avm/import_tx.go index 026476064565..d2bba6addfba 100644 --- a/vms/avm/import_tx.go +++ b/vms/avm/import_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm @@ -116,13 +116,9 @@ func (t *ImportTx) SemanticVerify(vm *VM, tx UnsignedTx, creds []verify.Verifiab return nil } - subnetID, err := vm.ctx.SNLookup.SubnetID(t.SourceChain) - if err != nil { + if err := verify.SameSubnet(vm.ctx, t.SourceChain); err != nil { return err } - if vm.ctx.SubnetID != subnetID || t.SourceChain == vm.ctx.ChainID { - return errWrongBlockchainID - } utxoIDs := make([][]byte, len(t.ImportedIns)) for i, in := range t.ImportedIns { diff --git a/vms/avm/import_tx_test.go b/vms/avm/import_tx_test.go index 06efda4b12c9..e836209b1566 100644 --- a/vms/avm/import_tx_test.go +++ b/vms/avm/import_tx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/index_test.go b/vms/avm/index_test.go index 59f36a1d5ffc..e17a65168def 100644 --- a/vms/avm/index_test.go +++ b/vms/avm/index_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm @@ -304,7 +304,6 @@ func TestIndexTransaction_UnorderedWrites(t *testing.T) { addressTxMap := map[ids.ShortID]*UniqueTx{} txAssetID := avax.Asset{ID: avaxID} - txIDs := make([]ids.ID, len(keys)) ctx.Lock.Lock() for _, key := range keys { @@ -368,7 +367,6 @@ func TestIndexTransaction_UnorderedWrites(t *testing.T) { // index the transaction, NOT calling Accept(ids.ID) method err := vm.addressTxsIndexer.Accept(uniqueParsedTX.ID(), inputUTXOs, uniqueParsedTX.UTXOs()) assert.NoError(t, err) - txIDs = append(txIDs, uniqueParsedTX.ID()) } // ensure length is same as keys length diff --git a/vms/avm/initial_state.go b/vms/avm/initial_state.go index 4f044d46afee..f10ca44d5f58 100644 --- a/vms/avm/initial_state.go +++ b/vms/avm/initial_state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/initial_state_test.go b/vms/avm/initial_state_test.go index 85a6cd1fb7e1..1d1531d030f3 100644 --- a/vms/avm/initial_state_test.go +++ b/vms/avm/initial_state_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm @@ -173,8 +173,8 @@ func TestInitialStateVerifySerialization(t *testing.T) { } if !bytes.Equal(isBytes, expected) { t.Fatalf("Expected:\n%s\nResult:\n%s", - formatting.DumpBytes{Bytes: expected}, - formatting.DumpBytes{Bytes: isBytes}, + formatting.DumpBytes(expected), + formatting.DumpBytes(isBytes), ) } } diff --git a/vms/avm/metrics.go b/vms/avm/metrics.go index f44b3a03d644..22f96cb53092 100644 --- a/vms/avm/metrics.go +++ b/vms/avm/metrics.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/operation.go b/vms/avm/operation.go index de3af23759fe..12c174ce101d 100644 --- a/vms/avm/operation.go +++ b/vms/avm/operation.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/operation_test.go b/vms/avm/operation_test.go index 909d80ddb2ee..c5f511a80ebe 100644 --- a/vms/avm/operation_test.go +++ b/vms/avm/operation_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/operation_tx.go b/vms/avm/operation_tx.go index 16e6a48b78cf..e89dc8641f2b 100644 --- a/vms/avm/operation_tx.go +++ b/vms/avm/operation_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/pubsub_filterer.go b/vms/avm/pubsub_filterer.go index b3e0b6ce83f7..c3159c37622d 100644 --- a/vms/avm/pubsub_filterer.go +++ b/vms/avm/pubsub_filterer.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/pubsub_filterer_test.go b/vms/avm/pubsub_filterer_test.go index 31ad19ad3475..9e59e177a15d 100644 --- a/vms/avm/pubsub_filterer_test.go +++ b/vms/avm/pubsub_filterer_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/service.go b/vms/avm/service.go index 7459affcae00..1bf3375f08a0 100644 --- a/vms/avm/service.go +++ b/vms/avm/service.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/service_test.go b/vms/avm/service_test.go index 5d4e98746205..aab6d0b4c53e 100644 --- a/vms/avm/service_test.go +++ b/vms/avm/service_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/state.go b/vms/avm/state.go index 8efff818ae30..f53c341b34e5 100644 --- a/vms/avm/state.go +++ b/vms/avm/state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm @@ -63,23 +63,23 @@ func NewState(db database.Database, genesisCodec, codec codec.Manager) State { } } -func NewMeteredState(db database.Database, genesisCodec, codec codec.Manager, namespace string, metrics prometheus.Registerer) (State, error) { +func NewMeteredState(db database.Database, genesisCodec, codec codec.Manager, metrics prometheus.Registerer) (State, error) { utxoDB := prefixdb.New(utxoStatePrefix, db) statusDB := prefixdb.New(statusStatePrefix, db) singletonDB := prefixdb.New(singletonStatePrefix, db) txDB := prefixdb.New(txStatePrefix, db) - utxoState, err := avax.NewMeteredUTXOState(utxoDB, codec, namespace, metrics) + utxoState, err := avax.NewMeteredUTXOState(utxoDB, codec, metrics) if err != nil { return nil, err } - statusState, err := avax.NewMeteredStatusState(statusDB, namespace, metrics) + statusState, err := avax.NewMeteredStatusState(statusDB, metrics) if err != nil { return nil, err } - txState, err := NewMeteredTxState(txDB, genesisCodec, namespace, metrics) + txState, err := NewMeteredTxState(txDB, genesisCodec, metrics) return &state{ UTXOState: utxoState, StatusState: statusState, diff --git a/vms/avm/state_test.go b/vms/avm/state_test.go index 00445cf58235..4f125d5f220c 100644 --- a/vms/avm/state_test.go +++ b/vms/avm/state_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/static_service.go b/vms/avm/static_service.go index ff609370cfcf..b71a8bb8f892 100644 --- a/vms/avm/static_service.go +++ b/vms/avm/static_service.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/static_service_test.go b/vms/avm/static_service_test.go index ff458c84d96b..a98b42186e4c 100644 --- a/vms/avm/static_service_test.go +++ b/vms/avm/static_service_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/tx.go b/vms/avm/tx.go index d11df21d6dd7..9efd1c817596 100644 --- a/vms/avm/tx.go +++ b/vms/avm/tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/tx_state.go b/vms/avm/tx_state.go index c6091b5b7a12..0430e2db2a98 100644 --- a/vms/avm/tx_state.go +++ b/vms/avm/tx_state.go @@ -1,11 +1,9 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm import ( - "fmt" - "github.com/prometheus/client_golang/prometheus" "github.com/ava-labs/avalanchego/cache" @@ -54,9 +52,9 @@ func NewTxState(db database.Database, codec codec.Manager) TxState { } } -func NewMeteredTxState(db database.Database, codec codec.Manager, namespace string, metrics prometheus.Registerer) (TxState, error) { +func NewMeteredTxState(db database.Database, codec codec.Manager, metrics prometheus.Registerer) (TxState, error) { cache, err := metercacher.New( - fmt.Sprintf("%s_tx_cache", namespace), + "tx_cache", metrics, &cache.LRU{Size: txCacheSize}, ) diff --git a/vms/avm/tx_state_test.go b/vms/avm/tx_state_test.go index 8f467d4b9d8f..18388eae6ce2 100644 --- a/vms/avm/tx_state_test.go +++ b/vms/avm/tx_state_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm @@ -85,6 +85,6 @@ func TestMeteredTxState(t *testing.T) { codec, err := staticCodec() assert.NoError(err) - _, err = NewMeteredTxState(db, codec, "", prometheus.NewRegistry()) + _, err = NewMeteredTxState(db, codec, prometheus.NewRegistry()) assert.NoError(err) } diff --git a/vms/avm/tx_test.go b/vms/avm/tx_test.go index 3d720e9fd01e..3ca8800f3e5a 100644 --- a/vms/avm/tx_test.go +++ b/vms/avm/tx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/unique_tx.go b/vms/avm/unique_tx.go index cf1621439c96..ba0e37e2adcb 100644 --- a/vms/avm/unique_tx.go +++ b/vms/avm/unique_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/user_state.go b/vms/avm/user_state.go index 0c03804feeea..01e352f02f11 100644 --- a/vms/avm/user_state.go +++ b/vms/avm/user_state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/vm.go b/vms/avm/vm.go index f3428794cd5a..afbd7cff7a4b 100644 --- a/vms/avm/vm.go +++ b/vms/avm/vm.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm @@ -13,6 +13,7 @@ import ( "time" "github.com/gorilla/rpc/v2" + "github.com/prometheus/client_golang/prometheus" "github.com/ava-labs/avalanchego/cache" "github.com/ava-labs/avalanchego/codec" @@ -51,7 +52,6 @@ var ( errIncompatibleFx = errors.New("incompatible feature extension") errUnknownFx = errors.New("unknown feature extension") errGenesisAssetMustHaveState = errors.New("genesis asset must have non-empty state") - errWrongBlockchainID = errors.New("wrong blockchain ID") errBootstrapping = errors.New("chain is currently bootstrapping") errInsufficientFunds = errors.New("insufficient funds") @@ -144,7 +144,12 @@ func (vm *VM) Initialize( ctx.Log.Info("VM config initialized %+v", avmConfig) } - err := vm.metrics.Initialize(ctx.Namespace, ctx.Metrics) + registerer := prometheus.NewRegistry() + if err := ctx.Metrics.Register(registerer); err != nil { + return err + } + + err := vm.metrics.Initialize("", registerer) if err != nil { return err } @@ -190,7 +195,7 @@ func (vm *VM) Initialize( vm.AtomicUTXOManager = avax.NewAtomicUTXOManager(ctx.SharedMemory, vm.codec) - state, err := NewMeteredState(vm.db, vm.genesisCodec, vm.codec, ctx.Namespace, ctx.Metrics) + state, err := NewMeteredState(vm.db, vm.genesisCodec, vm.codec, registerer) if err != nil { return err } @@ -216,7 +221,7 @@ func (vm *VM) Initialize( // use no op impl when disabled in config if avmConfig.IndexTransactions { vm.ctx.Log.Info("address transaction indexing is enabled") - vm.addressTxsIndexer, err = index.NewIndexer(vm.db, vm.ctx.Log, ctx.Namespace, ctx.Metrics, avmConfig.IndexAllowIncomplete) + vm.addressTxsIndexer, err = index.NewIndexer(vm.db, vm.ctx.Log, "", registerer, avmConfig.IndexAllowIncomplete) if err != nil { return fmt.Errorf("failed to initialize address transaction indexer: %w", err) } diff --git a/vms/avm/vm_benchmark_test.go b/vms/avm/vm_benchmark_test.go index 289bdc5962e4..5b9c9464d713 100644 --- a/vms/avm/vm_benchmark_test.go +++ b/vms/avm/vm_benchmark_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/vm_test.go b/vms/avm/vm_test.go index 0257ba761a4d..ef90c898e207 100644 --- a/vms/avm/vm_test.go +++ b/vms/avm/vm_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm @@ -129,16 +129,16 @@ func GetCreateTxFromGenesisTest(tb testing.TB, genesisBytes []byte, assetName st } if assetTx == nil { tb.Fatal("there is no create tx") + return nil } - tx := Tx{ + tx := &Tx{ UnsignedTx: &assetTx.CreateAssetTx, } if err := tx.SignSECP256K1Fx(c, nil); err != nil { tb.Fatal(err) } - - return &tx + return tx } func GetAVAXTxFromGenesisTest(genesisBytes []byte, tb testing.TB) *Tx { diff --git a/vms/avm/wallet_client.go b/vms/avm/wallet_client.go index 92c6f594c01c..df9df5db9986 100644 --- a/vms/avm/wallet_client.go +++ b/vms/avm/wallet_client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/wallet_service.go b/vms/avm/wallet_service.go index 66f4fdbda0b0..274a89789cdd 100644 --- a/vms/avm/wallet_service.go +++ b/vms/avm/wallet_service.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/avm/wallet_service_test.go b/vms/avm/wallet_service_test.go index 91b97583ba3c..e4a48ef2233d 100644 --- a/vms/avm/wallet_service_test.go +++ b/vms/avm/wallet_service_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avm diff --git a/vms/components/avax/addresses.go b/vms/components/avax/addresses.go index cd4ce23f9188..e00ecc5260d8 100644 --- a/vms/components/avax/addresses.go +++ b/vms/components/avax/addresses.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/asset.go b/vms/components/avax/asset.go index 073b0e651b6c..620f982b11a7 100644 --- a/vms/components/avax/asset.go +++ b/vms/components/avax/asset.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/asset_test.go b/vms/components/avax/asset_test.go index 1fbcb6854b9e..0ffad30e5680 100644 --- a/vms/components/avax/asset_test.go +++ b/vms/components/avax/asset_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/atomic_utxos.go b/vms/components/avax/atomic_utxos.go index 8129a7a5afd6..55ce27b79ed1 100644 --- a/vms/components/avax/atomic_utxos.go +++ b/vms/components/avax/atomic_utxos.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/base_tx.go b/vms/components/avax/base_tx.go index 34459cef2019..77e9274d1ff0 100644 --- a/vms/components/avax/base_tx.go +++ b/vms/components/avax/base_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/flow_checker.go b/vms/components/avax/flow_checker.go index bb2250e7fe66..7a96744c9448 100644 --- a/vms/components/avax/flow_checker.go +++ b/vms/components/avax/flow_checker.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/metadata.go b/vms/components/avax/metadata.go index 80ca84001513..75577d1d459a 100644 --- a/vms/components/avax/metadata.go +++ b/vms/components/avax/metadata.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/metadata_test.go b/vms/components/avax/metadata_test.go index fdbdf9961492..15cf5cd84ccc 100644 --- a/vms/components/avax/metadata_test.go +++ b/vms/components/avax/metadata_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/singleton_state.go b/vms/components/avax/singleton_state.go index 42feafb414b9..467e1f7f1e9e 100644 --- a/vms/components/avax/singleton_state.go +++ b/vms/components/avax/singleton_state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/singleton_state_test.go b/vms/components/avax/singleton_state_test.go index cea825dc0f4a..87f6e95bbc6e 100644 --- a/vms/components/avax/singleton_state_test.go +++ b/vms/components/avax/singleton_state_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/state.go b/vms/components/avax/state.go index b341d70d1421..375ca8a3ce8a 100644 --- a/vms/components/avax/state.go +++ b/vms/components/avax/state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/status_state.go b/vms/components/avax/status_state.go index 6440fde79b14..86a57b024c79 100644 --- a/vms/components/avax/status_state.go +++ b/vms/components/avax/status_state.go @@ -1,11 +1,9 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax import ( - "fmt" - "github.com/prometheus/client_golang/prometheus" "github.com/ava-labs/avalanchego/cache" @@ -46,9 +44,9 @@ func NewStatusState(db database.Database) StatusState { } } -func NewMeteredStatusState(db database.Database, namespace string, metrics prometheus.Registerer) (StatusState, error) { +func NewMeteredStatusState(db database.Database, metrics prometheus.Registerer) (StatusState, error) { cache, err := metercacher.New( - fmt.Sprintf("%s_status_cache", namespace), + "status_cache", metrics, &cache.LRU{Size: statusCacheSize}, ) diff --git a/vms/components/avax/status_state_test.go b/vms/components/avax/status_state_test.go index 4696fb1da040..a0ae3e106a1a 100644 --- a/vms/components/avax/status_state_test.go +++ b/vms/components/avax/status_state_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/test_verifiable.go b/vms/components/avax/test_verifiable.go index 131e1a0cc24a..644f08593404 100644 --- a/vms/components/avax/test_verifiable.go +++ b/vms/components/avax/test_verifiable.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/transferables.go b/vms/components/avax/transferables.go index 1bee362eff29..9dcc23235edd 100644 --- a/vms/components/avax/transferables.go +++ b/vms/components/avax/transferables.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/transferables_test.go b/vms/components/avax/transferables_test.go index ae6c2df80d22..64e0b0ea9045 100644 --- a/vms/components/avax/transferables_test.go +++ b/vms/components/avax/transferables_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax @@ -166,8 +166,8 @@ func TestTransferableOutputSerialization(t *testing.T) { } if !bytes.Equal(outBytes, expected) { t.Fatalf("Expected:\n%s\nResult:\n%s", - formatting.DumpBytes{Bytes: expected}, - formatting.DumpBytes{Bytes: outBytes}, + formatting.DumpBytes(expected), + formatting.DumpBytes(outBytes), ) } } @@ -330,8 +330,8 @@ func TestTransferableInputSerialization(t *testing.T) { } if !bytes.Equal(inBytes, expected) { t.Fatalf("Expected:\n%s\nResult:\n%s", - formatting.DumpBytes{Bytes: expected}, - formatting.DumpBytes{Bytes: inBytes}, + formatting.DumpBytes(expected), + formatting.DumpBytes(inBytes), ) } } diff --git a/vms/components/avax/utxo.go b/vms/components/avax/utxo.go index 40cb110e2a8a..03b1e2c6e4e1 100644 --- a/vms/components/avax/utxo.go +++ b/vms/components/avax/utxo.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/utxo_id.go b/vms/components/avax/utxo_id.go index 607792146153..e4daad2898c4 100644 --- a/vms/components/avax/utxo_id.go +++ b/vms/components/avax/utxo_id.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/utxo_id_test.go b/vms/components/avax/utxo_id_test.go index bc18d67a0a2e..036a3b4eb047 100644 --- a/vms/components/avax/utxo_id_test.go +++ b/vms/components/avax/utxo_id_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/utxo_state.go b/vms/components/avax/utxo_state.go index c74e4aef76ba..a384fe3851b8 100644 --- a/vms/components/avax/utxo_state.go +++ b/vms/components/avax/utxo_state.go @@ -1,11 +1,9 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax import ( - "fmt" - "github.com/prometheus/client_golang/prometheus" "github.com/ava-labs/avalanchego/cache" @@ -69,9 +67,9 @@ func NewUTXOState(db database.Database, codec codec.Manager) UTXOState { } } -func NewMeteredUTXOState(db database.Database, codec codec.Manager, namespace string, metrics prometheus.Registerer) (UTXOState, error) { +func NewMeteredUTXOState(db database.Database, codec codec.Manager, metrics prometheus.Registerer) (UTXOState, error) { utxoCache, err := metercacher.New( - fmt.Sprintf("%s_utxo_cache", namespace), + "utxo_cache", metrics, &cache.LRU{Size: utxoCacheSize}, ) @@ -80,7 +78,7 @@ func NewMeteredUTXOState(db database.Database, codec codec.Manager, namespace st } indexCache, err := metercacher.New( - fmt.Sprintf("%s_index_cache", namespace), + "index_cache", metrics, &cache.LRU{ Size: indexCacheSize, diff --git a/vms/components/avax/utxo_state_test.go b/vms/components/avax/utxo_state_test.go index dbe616be0953..091e028301f0 100644 --- a/vms/components/avax/utxo_state_test.go +++ b/vms/components/avax/utxo_state_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax diff --git a/vms/components/avax/utxo_test.go b/vms/components/avax/utxo_test.go index 097616cc84ed..39fa0f798642 100644 --- a/vms/components/avax/utxo_test.go +++ b/vms/components/avax/utxo_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package avax @@ -122,8 +122,8 @@ func TestUTXOSerialize(t *testing.T) { } if !bytes.Equal(utxoBytes, expected) { t.Fatalf("Expected:\n%s\nResult:\n%s", - formatting.DumpBytes{Bytes: expected}, - formatting.DumpBytes{Bytes: utxoBytes}, + formatting.DumpBytes(expected), + formatting.DumpBytes(utxoBytes), ) } } diff --git a/vms/components/chain/block.go b/vms/components/chain/block.go index 586dc279f93b..f934c9a30fd1 100644 --- a/vms/components/chain/block.go +++ b/vms/components/chain/block.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package chain diff --git a/vms/components/chain/state.go b/vms/components/chain/state.go index 111ef61abc3b..085731be7838 100644 --- a/vms/components/chain/state.go +++ b/vms/components/chain/state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package chain @@ -132,11 +132,10 @@ func NewState(config *Config) *State { func NewMeteredState( registerer prometheus.Registerer, - namespace string, config *Config, ) (*State, error) { decidedCache, err := metercacher.New( - fmt.Sprintf("%s_decided_cache", namespace), + "decided_cache", registerer, &cache.LRU{Size: config.DecidedCacheSize}, ) @@ -144,7 +143,7 @@ func NewMeteredState( return nil, err } missingCache, err := metercacher.New( - fmt.Sprintf("%s_missing_cache", namespace), + "missing_cache", registerer, &cache.LRU{Size: config.MissingCacheSize}, ) @@ -152,7 +151,7 @@ func NewMeteredState( return nil, err } unverifiedCache, err := metercacher.New( - fmt.Sprintf("%s_unverified_cache", namespace), + "unverified_cache", registerer, &cache.LRU{Size: config.UnverifiedCacheSize}, ) @@ -160,7 +159,7 @@ func NewMeteredState( return nil, err } bytesToIDCache, err := metercacher.New( - fmt.Sprintf("%s_bytes_to_id_cache", namespace), + "bytes_to_id_cache", registerer, &cache.LRU{Size: config.BytesToIDCacheSize}, ) diff --git a/vms/components/chain/state_test.go b/vms/components/chain/state_test.go index fd0772b9a03a..fb104a092de0 100644 --- a/vms/components/chain/state_test.go +++ b/vms/components/chain/state_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package chain @@ -635,8 +635,6 @@ func TestBuildBlockError(t *testing.T) { func TestMeteredCache(t *testing.T) { registry := prometheus.NewRegistry() - namespace1 := "Joe" - namespace2 := "Namath" testBlks := NewTestBlocks(1) genesisBlock := testBlks[0] @@ -654,17 +652,13 @@ func TestMeteredCache(t *testing.T) { BuildBlock: cantBuildBlock, GetBlockIDAtHeight: getCanonicalBlockID, } - _, err := NewMeteredState(registry, namespace1, config) + _, err := NewMeteredState(registry, config) if err != nil { t.Fatal(err) } - _, err = NewMeteredState(registry, namespace1, config) + _, err = NewMeteredState(registry, config) if err == nil { - t.Fatal("Expected creating a second NewMeteredState with the same namespace to error due to a registry conflict") - } - _, err = NewMeteredState(registry, namespace2, config) - if err != nil { - t.Fatal(err) + t.Fatal("Expected creating a second NewMeteredState to error due to a registry conflict") } } diff --git a/vms/components/core/block.go b/vms/components/core/block.go index e2f8d9697cd3..20c6c8434762 100644 --- a/vms/components/core/block.go +++ b/vms/components/core/block.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package core diff --git a/vms/components/core/block_test.go b/vms/components/core/block_test.go index 0025e6a413b6..8bb5b62d58d1 100644 --- a/vms/components/core/block_test.go +++ b/vms/components/core/block_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package core diff --git a/vms/components/core/metadata.go b/vms/components/core/metadata.go index 1ee54d84e740..48a75e9b09db 100644 --- a/vms/components/core/metadata.go +++ b/vms/components/core/metadata.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package core diff --git a/vms/components/core/snowman_state.go b/vms/components/core/snowman_state.go index c9bb374194a3..cbf00bb466b0 100644 --- a/vms/components/core/snowman_state.go +++ b/vms/components/core/snowman_state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package core diff --git a/vms/components/core/snowman_vm.go b/vms/components/core/snowman_vm.go index 2ffc03f2a801..aa488b52e1b5 100644 --- a/vms/components/core/snowman_vm.go +++ b/vms/components/core/snowman_vm.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package core diff --git a/vms/components/index/index.go b/vms/components/index/index.go index b01ad7c80818..2cca8ba97161 100644 --- a/vms/components/index/index.go +++ b/vms/components/index/index.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package index diff --git a/vms/components/index/metrics.go b/vms/components/index/metrics.go index 448676d6bdcb..94e1207c3b7c 100644 --- a/vms/components/index/metrics.go +++ b/vms/components/index/metrics.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package index diff --git a/vms/components/state/builtin.go b/vms/components/state/builtin.go index d6c9f9cbd996..91f0c0f21d9b 100644 --- a/vms/components/state/builtin.go +++ b/vms/components/state/builtin.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state diff --git a/vms/components/state/state.go b/vms/components/state/state.go index 04eb5ca6ca8c..b7698fe11493 100644 --- a/vms/components/state/state.go +++ b/vms/components/state/state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state diff --git a/vms/components/state/state_test.go b/vms/components/state/state_test.go index 18706b2394d0..bc8b511e0b65 100644 --- a/vms/components/state/state_test.go +++ b/vms/components/state/state_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state diff --git a/vms/components/state/types.go b/vms/components/state/types.go index fdbd72414e40..23f6b6c68918 100644 --- a/vms/components/state/types.go +++ b/vms/components/state/types.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state diff --git a/vms/components/verify/subnet.go b/vms/components/verify/subnet.go new file mode 100644 index 000000000000..1b905a54d6aa --- /dev/null +++ b/vms/components/verify/subnet.go @@ -0,0 +1,35 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package verify + +import ( + "errors" + "fmt" + + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/snow" +) + +var ( + errSameChainID = errors.New("same chainID") + errMismatchedSubnetIDs = errors.New("mismatched subnetIDs") +) + +// SameSubnet verifies that the provided [ctx] was provided to a chain in the +// same subnet as [peerChainID], but not the same chain. If this verification +// fails, a non-nil error will be returned. +func SameSubnet(ctx *snow.Context, peerChainID ids.ID) error { + if peerChainID == ctx.ChainID { + return errSameChainID + } + + subnetID, err := ctx.SNLookup.SubnetID(peerChainID) + if err != nil { + return fmt.Errorf("failed to get subnet of %q: %w", peerChainID, err) + } + if ctx.SubnetID != subnetID { + return fmt.Errorf("%w; expected %q got %q", errMismatchedSubnetIDs, ctx.SubnetID, subnetID) + } + return nil +} diff --git a/vms/components/verify/subnet_test.go b/vms/components/verify/subnet_test.go new file mode 100644 index 000000000000..be9331fb3d65 --- /dev/null +++ b/vms/components/verify/subnet_test.go @@ -0,0 +1,97 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package verify + +import ( + "errors" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/snow" +) + +var errMissing = errors.New("missing") + +type snLookup struct { + chainsToSubnet map[ids.ID]ids.ID +} + +func (sn *snLookup) SubnetID(chainID ids.ID) (ids.ID, error) { + subnetID, ok := sn.chainsToSubnet[chainID] + if !ok { + return ids.ID{}, errMissing + } + return subnetID, nil +} + +func TestSameSubnet(t *testing.T) { + subnet0 := ids.GenerateTestID() + subnet1 := ids.GenerateTestID() + chain0 := ids.GenerateTestID() + chain1 := ids.GenerateTestID() + + tests := []struct { + name string + ctx *snow.Context + chainID ids.ID + result error + }{ + { + name: "same chain", + ctx: &snow.Context{ + SubnetID: subnet0, + ChainID: chain0, + SNLookup: &snLookup{}, + }, + chainID: chain0, + result: errSameChainID, + }, + { + name: "unknown chain", + ctx: &snow.Context{ + SubnetID: subnet0, + ChainID: chain0, + SNLookup: &snLookup{}, + }, + chainID: chain1, + result: errMissing, + }, + { + name: "wrong subnet", + ctx: &snow.Context{ + SubnetID: subnet0, + ChainID: chain0, + SNLookup: &snLookup{ + chainsToSubnet: map[ids.ID]ids.ID{ + chain1: subnet1, + }, + }, + }, + chainID: chain1, + result: errMismatchedSubnetIDs, + }, + { + name: "same subnet", + ctx: &snow.Context{ + SubnetID: subnet0, + ChainID: chain0, + SNLookup: &snLookup{ + chainsToSubnet: map[ids.ID]ids.ID{ + chain1: subnet0, + }, + }, + }, + chainID: chain1, + result: nil, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + result := SameSubnet(test.ctx, test.chainID) + assert.ErrorIs(t, result, test.result) + }) + } +} diff --git a/vms/components/verify/verification.go b/vms/components/verify/verification.go index d06b336677ba..aed66aba83e5 100644 --- a/vms/components/verify/verification.go +++ b/vms/components/verify/verification.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package verify diff --git a/vms/components/verify/verification_test.go b/vms/components/verify/verification_test.go index 2da83f39131d..7f8b223454db 100644 --- a/vms/components/verify/verification_test.go +++ b/vms/components/verify/verification_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package verify diff --git a/vms/evm/id.go b/vms/evm/id.go index 99cc2e080450..74812601f637 100644 --- a/vms/evm/id.go +++ b/vms/evm/id.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package evm diff --git a/vms/manager.go b/vms/manager.go index 5e07ad567ea3..d8329564f638 100644 --- a/vms/manager.go +++ b/vms/manager.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package vms diff --git a/vms/metervm/block_metrics.go b/vms/metervm/block_metrics.go index b89647420d84..cd039ec3b354 100644 --- a/vms/metervm/block_metrics.go +++ b/vms/metervm/block_metrics.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package metervm diff --git a/vms/metervm/block_vm.go b/vms/metervm/block_vm.go index 8d12b9e818cd..92fca20e8a34 100644 --- a/vms/metervm/block_vm.go +++ b/vms/metervm/block_vm.go @@ -1,12 +1,14 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package metervm import ( - "fmt" "time" + "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/ids" "github.com/ava-labs/avalanchego/snow" @@ -45,10 +47,24 @@ func (vm *blockVM) Initialize( fxs []*common.Fx, appSender common.AppSender, ) error { + registerer := prometheus.NewRegistry() _, supportsBatchedFetching := vm.ChainVM.(block.BatchedChainVM) - if err := vm.blockMetrics.Initialize(supportsBatchedFetching, fmt.Sprintf("%s_metervm", ctx.Namespace), ctx.Metrics); err != nil { + if err := vm.blockMetrics.Initialize(supportsBatchedFetching, "", registerer); err != nil { + return err + } + + optionalGatherer := metrics.NewOptionalGatherer() + multiGatherer := metrics.NewMultiGatherer() + if err := multiGatherer.Register("metervm", registerer); err != nil { + return err + } + if err := multiGatherer.Register("", optionalGatherer); err != nil { + return err + } + if err := ctx.Metrics.Register(multiGatherer); err != nil { return err } + ctx.Metrics = optionalGatherer return vm.ChainVM.Initialize(ctx, db, genesisBytes, upgradeBytes, configBytes, toEngine, fxs, appSender) } diff --git a/vms/metervm/metrics.go b/vms/metervm/metrics.go index 3034e968e24d..0af90696935d 100644 --- a/vms/metervm/metrics.go +++ b/vms/metervm/metrics.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package metervm diff --git a/vms/metervm/vertex_metrics.go b/vms/metervm/vertex_metrics.go index 16b4c6d88939..0f4f58d5062d 100644 --- a/vms/metervm/vertex_metrics.go +++ b/vms/metervm/vertex_metrics.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package metervm diff --git a/vms/metervm/vertex_vm.go b/vms/metervm/vertex_vm.go index dbfdb3cce957..68edecd93fb8 100644 --- a/vms/metervm/vertex_vm.go +++ b/vms/metervm/vertex_vm.go @@ -1,11 +1,12 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package metervm import ( - "fmt" + "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/ids" "github.com/ava-labs/avalanchego/snow" @@ -42,10 +43,24 @@ func (vm *vertexVM) Initialize( fxs []*common.Fx, appSender common.AppSender, ) error { - if err := vm.vertexMetrics.Initialize(fmt.Sprintf("%s_metervm", ctx.Namespace), ctx.Metrics); err != nil { + registerer := prometheus.NewRegistry() + if err := vm.vertexMetrics.Initialize("", registerer); err != nil { return err } + optionalGatherer := metrics.NewOptionalGatherer() + multiGatherer := metrics.NewMultiGatherer() + if err := multiGatherer.Register("metervm", registerer); err != nil { + return err + } + if err := multiGatherer.Register("", optionalGatherer); err != nil { + return err + } + if err := ctx.Metrics.Register(multiGatherer); err != nil { + return err + } + ctx.Metrics = optionalGatherer + return vm.DAGVM.Initialize(ctx, db, genesisBytes, upgradeBytes, configBytes, toEngine, fxs, appSender) } diff --git a/vms/nftfx/credential.go b/vms/nftfx/credential.go index 1b4654368b7f..6cee958b4db8 100644 --- a/vms/nftfx/credential.go +++ b/vms/nftfx/credential.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nftfx diff --git a/vms/nftfx/credential_test.go b/vms/nftfx/credential_test.go index ea21da14bd5b..3b5ee759153c 100644 --- a/vms/nftfx/credential_test.go +++ b/vms/nftfx/credential_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nftfx diff --git a/vms/nftfx/factory.go b/vms/nftfx/factory.go index d10c51438a45..6f524c20a929 100644 --- a/vms/nftfx/factory.go +++ b/vms/nftfx/factory.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nftfx diff --git a/vms/nftfx/factory_test.go b/vms/nftfx/factory_test.go index f160a8d3d55f..06ea1466f15c 100644 --- a/vms/nftfx/factory_test.go +++ b/vms/nftfx/factory_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nftfx diff --git a/vms/nftfx/fx.go b/vms/nftfx/fx.go index 4955cca8fa76..a5b889850c77 100644 --- a/vms/nftfx/fx.go +++ b/vms/nftfx/fx.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nftfx diff --git a/vms/nftfx/fx_test.go b/vms/nftfx/fx_test.go index c1691d4e974d..838ebf9236ef 100644 --- a/vms/nftfx/fx_test.go +++ b/vms/nftfx/fx_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nftfx diff --git a/vms/nftfx/mint_operation.go b/vms/nftfx/mint_operation.go index ed06d347c64d..cf1e5d9d68fd 100644 --- a/vms/nftfx/mint_operation.go +++ b/vms/nftfx/mint_operation.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nftfx diff --git a/vms/nftfx/mint_operation_test.go b/vms/nftfx/mint_operation_test.go index 98cbcba284d5..10c20bea9d32 100644 --- a/vms/nftfx/mint_operation_test.go +++ b/vms/nftfx/mint_operation_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nftfx diff --git a/vms/nftfx/mint_output.go b/vms/nftfx/mint_output.go index 9fc772cc4e9f..2c834f9295c4 100644 --- a/vms/nftfx/mint_output.go +++ b/vms/nftfx/mint_output.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nftfx diff --git a/vms/nftfx/mint_output_test.go b/vms/nftfx/mint_output_test.go index c072b84e9e1b..dead60130367 100644 --- a/vms/nftfx/mint_output_test.go +++ b/vms/nftfx/mint_output_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nftfx diff --git a/vms/nftfx/transfer_operation.go b/vms/nftfx/transfer_operation.go index 004f5265a563..63669091ca02 100644 --- a/vms/nftfx/transfer_operation.go +++ b/vms/nftfx/transfer_operation.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nftfx diff --git a/vms/nftfx/transfer_operation_test.go b/vms/nftfx/transfer_operation_test.go index ee896ba16fcd..9cc03aca9aa8 100644 --- a/vms/nftfx/transfer_operation_test.go +++ b/vms/nftfx/transfer_operation_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nftfx diff --git a/vms/nftfx/transfer_output.go b/vms/nftfx/transfer_output.go index ac301bed94d5..b554b0d6de64 100644 --- a/vms/nftfx/transfer_output.go +++ b/vms/nftfx/transfer_output.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nftfx diff --git a/vms/nftfx/transfer_output_test.go b/vms/nftfx/transfer_output_test.go index b94f385ee26d..acc90277b2c2 100644 --- a/vms/nftfx/transfer_output_test.go +++ b/vms/nftfx/transfer_output_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package nftfx diff --git a/vms/platformvm/abort_block.go b/vms/platformvm/abort_block.go index 83c8930c7f7b..dea4b3c711ca 100644 --- a/vms/platformvm/abort_block.go +++ b/vms/platformvm/abort_block.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -24,7 +24,7 @@ type AbortBlock struct { } func (a *AbortBlock) Accept() error { - if a.vm.bootstrapped { + if a.vm.bootstrapped.GetValue() { if a.wasPreferred { a.vm.metrics.numVotesWon.Inc() } else { diff --git a/vms/platformvm/add_delegator_tx.go b/vms/platformvm/add_delegator_tx.go index f07a3d94f5b1..a47cd28e3159 100644 --- a/vms/platformvm/add_delegator_tx.go +++ b/vms/platformvm/add_delegator_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -154,7 +154,7 @@ func (tx *UnsignedAddDelegatorTx) Execute( currentStakers := parentState.CurrentStakerChainState() pendingStakers := parentState.PendingStakerChainState() - if vm.bootstrapped { + if vm.bootstrapped.GetValue() { currentTimestamp := parentState.GetTimestamp() // Ensure the proposed validator starts after the current timestamp validatorStartTime := tx.StartTime() diff --git a/vms/platformvm/add_delegator_tx_test.go b/vms/platformvm/add_delegator_tx_test.go index 19f581e02a0f..ed9b704b009a 100644 --- a/vms/platformvm/add_delegator_tx_test.go +++ b/vms/platformvm/add_delegator_tx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/add_subnet_validator_tx.go b/vms/platformvm/add_subnet_validator_tx.go index 89d1b054d094..7da1cfdf53f2 100644 --- a/vms/platformvm/add_subnet_validator_tx.go +++ b/vms/platformvm/add_subnet_validator_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -111,7 +111,7 @@ func (tx *UnsignedAddSubnetValidatorTx) Execute( currentStakers := parentState.CurrentStakerChainState() pendingStakers := parentState.PendingStakerChainState() - if vm.bootstrapped { + if vm.bootstrapped.GetValue() { currentTimestamp := parentState.GetTimestamp() // Ensure the proposed validator starts after the current timestamp validatorStartTime := tx.StartTime() diff --git a/vms/platformvm/add_subnet_validator_tx_test.go b/vms/platformvm/add_subnet_validator_tx_test.go index ebd07723701b..bb9dc092cd35 100644 --- a/vms/platformvm/add_subnet_validator_tx_test.go +++ b/vms/platformvm/add_subnet_validator_tx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/add_validator_tx.go b/vms/platformvm/add_validator_tx.go index cb13866c51b6..efb99619206d 100644 --- a/vms/platformvm/add_validator_tx.go +++ b/vms/platformvm/add_validator_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -170,7 +170,7 @@ func (tx *UnsignedAddValidatorTx) Execute( copy(outs, tx.Outs) copy(outs[len(tx.Outs):], tx.Stake) - if vm.bootstrapped { + if vm.bootstrapped.GetValue() { currentTimestamp := parentState.GetTimestamp() // Ensure the proposed validator starts after the current time startTime := tx.StartTime() diff --git a/vms/platformvm/add_validator_tx_test.go b/vms/platformvm/add_validator_tx_test.go index e8fe60effb04..c2b86dd4e2f6 100644 --- a/vms/platformvm/add_validator_tx_test.go +++ b/vms/platformvm/add_validator_tx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/advance_time_tx.go b/vms/platformvm/advance_time_tx.go index 3a6286668f96..0fd91e1b8c39 100644 --- a/vms/platformvm/advance_time_tx.go +++ b/vms/platformvm/advance_time_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/advance_time_tx_test.go b/vms/platformvm/advance_time_tx_test.go index f424f6dabf27..1677238e6f5f 100644 --- a/vms/platformvm/advance_time_tx_test.go +++ b/vms/platformvm/advance_time_tx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/atomic_block.go b/vms/platformvm/atomic_block.go index 3bb7337b7d5f..b80eb580ed02 100644 --- a/vms/platformvm/atomic_block.go +++ b/vms/platformvm/atomic_block.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -110,7 +110,19 @@ func (ab *AtomicBlock) Verify() error { } parentState := parent.onAccept() - onAccept, err := tx.Execute(ab.vm, parentState, &ab.Tx) + + currentTimestamp := parentState.GetTimestamp() + enabledAP5 := !currentTimestamp.Before(ab.vm.ApricotPhase5Time) + + if enabledAP5 { + return fmt.Errorf( + "the chain timestamp (%d) is after the apricot phase 5 time (%d), hence atomic transactions should go through the standard block", + currentTimestamp.Unix(), + ab.vm.ApricotPhase5Time.Unix(), + ) + } + + onAccept, err := tx.AtomicExecute(ab.vm, parentState, &ab.Tx) if err != nil { txID := tx.ID() ab.vm.droppedTxCache.Put(txID, err.Error()) // cache tx as dropped @@ -157,7 +169,8 @@ func (ab *AtomicBlock) Accept() error { err, ) } - if err := tx.Accept(ab.vm.ctx, batch); err != nil { + + if err := tx.AtomicAccept(ab.vm.ctx, batch); err != nil { return fmt.Errorf( "failed to atomically accept tx %s in block %s: %w", tx.ID(), diff --git a/vms/platformvm/base_tx.go b/vms/platformvm/base_tx.go index e758d9a80fa5..441adcffbc0e 100644 --- a/vms/platformvm/base_tx.go +++ b/vms/platformvm/base_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/base_tx_test.go b/vms/platformvm/base_tx_test.go index 32578f69d20a..04ab37441e95 100644 --- a/vms/platformvm/base_tx_test.go +++ b/vms/platformvm/base_tx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/block_builder.go b/vms/platformvm/block_builder.go index 482ddc2ace1b..3c9c74537d74 100644 --- a/vms/platformvm/block_builder.go +++ b/vms/platformvm/block_builder.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -8,6 +8,8 @@ import ( "fmt" "time" + "github.com/prometheus/client_golang/prometheus" + "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/utils/timer" "github.com/ava-labs/avalanchego/utils/timer/mockable" @@ -44,13 +46,13 @@ type blockBuilder struct { } // Initialize this builder. -func (m *blockBuilder) Initialize(vm *VM) error { +func (m *blockBuilder) Initialize(vm *VM, registerer prometheus.Registerer) error { m.vm = vm m.vm.ctx.Log.Verbo("initializing platformVM mempool") mempool, err := NewMempool( - fmt.Sprintf("%s_mempool", vm.ctx.Namespace), - vm.ctx.Metrics, + "mempool", + registerer, ) if err != nil { return err @@ -142,9 +144,28 @@ func (m *blockBuilder) BuildBlock() (snowman.Block, error) { preferredID := preferred.ID() nextHeight := preferred.Height() + 1 + // The state if the preferred block were to be accepted + preferredState := preferredDecision.onAccept() + currentChainTimestamp := preferredState.GetTimestamp() + if !currentChainTimestamp.Before(mockable.MaxTime) { + return nil, errEndOfTime + } + + // TODO: remove after AP5. + enabledAP5 := !currentChainTimestamp.Before(m.vm.ApricotPhase5Time) + // If there are pending decision txs, build a block with a batch of them - if m.HasDecisionTxs() { - txs := m.PopDecisionTxs(BatchSize) + if m.HasDecisionTxs() || (enabledAP5 && m.HasAtomicTx()) { + txs := make([]*Tx, 0, BatchSize) + if m.HasDecisionTxs() { + decisionTxs := m.PopDecisionTxs(BatchSize) + txs = append(txs, decisionTxs...) + } + if enabledAP5 && m.HasAtomicTx() { + atomicTxs := m.PopAtomicTxs(BatchSize - len(txs)) + txs = append(txs, atomicTxs...) + } + blk, err := m.vm.newStandardBlock(preferredID, nextHeight, txs) if err != nil { m.ResetTimer() @@ -162,7 +183,7 @@ func (m *blockBuilder) BuildBlock() (snowman.Block, error) { } // If there is a pending atomic tx, build a block with it - if m.HasAtomicTx() { + if !enabledAP5 && m.HasAtomicTx() { tx := m.PopAtomicTx() blk, err := m.vm.newAtomicBlock(preferredID, nextHeight, *tx) @@ -181,15 +202,6 @@ func (m *blockBuilder) BuildBlock() (snowman.Block, error) { return blk, m.vm.internalState.Commit() } - // The state if the preferred block were to be accepted - preferredState := preferredDecision.onAccept() - - // The chain time if the preferred block were to be committed - currentChainTimestamp := preferredState.GetTimestamp() - if !currentChainTimestamp.Before(mockable.MaxTime) { - return nil, errEndOfTime - } - currentStakers := preferredState.CurrentStakerChainState() // If the chain time would be the time for the next primary network staker diff --git a/vms/platformvm/block_builder_test.go b/vms/platformvm/block_builder_test.go index 7500997c9c69..96d1f832801a 100644 --- a/vms/platformvm/block_builder_test.go +++ b/vms/platformvm/block_builder_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/blockchain_status.go b/vms/platformvm/blockchain_status.go index 01a3a0116e87..255d52b1e7f9 100644 --- a/vms/platformvm/blockchain_status.go +++ b/vms/platformvm/blockchain_status.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/blockchain_status_test.go b/vms/platformvm/blockchain_status_test.go index 0eaeb7f5eccd..5aafea8a7715 100644 --- a/vms/platformvm/blockchain_status_test.go +++ b/vms/platformvm/blockchain_status_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/cache_current_staker_chain_state.go b/vms/platformvm/cache_current_staker_chain_state.go index 353eedd9ccbc..160f61aaad71 100644 --- a/vms/platformvm/cache_current_staker_chain_state.go +++ b/vms/platformvm/cache_current_staker_chain_state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/cache_current_validator.go b/vms/platformvm/cache_current_validator.go index a32e98a6d221..2ebe491160ba 100644 --- a/vms/platformvm/cache_current_validator.go +++ b/vms/platformvm/cache_current_validator.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/cache_internal_state.go b/vms/platformvm/cache_internal_state.go index 2fb4f273687f..4679cd29d763 100644 --- a/vms/platformvm/cache_internal_state.go +++ b/vms/platformvm/cache_internal_state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -313,9 +313,9 @@ func (st *internalStateImpl) initCaches() { st.chainDBCache = &cache.LRU{Size: chainDBCacheSize} } -func (st *internalStateImpl) initMeteredCaches(namespace string, metrics prometheus.Registerer) error { +func (st *internalStateImpl) initMeteredCaches(metrics prometheus.Registerer) error { validatorDiffsCache, err := metercacher.New( - fmt.Sprintf("%s_validator_diffs_cache", namespace), + "validator_diffs_cache", metrics, &cache.LRU{Size: validatorDiffsCacheSize}, ) @@ -324,7 +324,7 @@ func (st *internalStateImpl) initMeteredCaches(namespace string, metrics prometh } blockCache, err := metercacher.New( - fmt.Sprintf("%s_block_cache", namespace), + "block_cache", metrics, &cache.LRU{Size: blockCacheSize}, ) @@ -333,7 +333,7 @@ func (st *internalStateImpl) initMeteredCaches(namespace string, metrics prometh } txCache, err := metercacher.New( - fmt.Sprintf("%s_tx_cache", namespace), + "tx_cache", metrics, &cache.LRU{Size: txCacheSize}, ) @@ -342,7 +342,7 @@ func (st *internalStateImpl) initMeteredCaches(namespace string, metrics prometh } rewardUTXOsCache, err := metercacher.New( - fmt.Sprintf("%s_reward_utxos_cache", namespace), + "reward_utxos_cache", metrics, &cache.LRU{Size: rewardUTXOsCacheSize}, ) @@ -350,13 +350,13 @@ func (st *internalStateImpl) initMeteredCaches(namespace string, metrics prometh return err } - utxoState, err := avax.NewMeteredUTXOState(st.utxoDB, GenesisCodec, namespace, metrics) + utxoState, err := avax.NewMeteredUTXOState(st.utxoDB, GenesisCodec, metrics) if err != nil { return err } chainCache, err := metercacher.New( - fmt.Sprintf("%s_chain_cache", namespace), + "chain_cache", metrics, &cache.LRU{Size: chainCacheSize}, ) @@ -365,7 +365,7 @@ func (st *internalStateImpl) initMeteredCaches(namespace string, metrics prometh } chainDBCache, err := metercacher.New( - fmt.Sprintf("%s_chain_db_cache", namespace), + "chain_db_cache", metrics, &cache.LRU{Size: chainDBCacheSize}, ) @@ -421,9 +421,9 @@ func NewInternalState(vm *VM, db database.Database, genesis []byte) (InternalSta return is, nil } -func NewMeteredInternalState(vm *VM, db database.Database, genesis []byte, namespace string, metrics prometheus.Registerer) (InternalState, error) { +func NewMeteredInternalState(vm *VM, db database.Database, genesis []byte, metrics prometheus.Registerer) (InternalState, error) { is := newInternalStateDatabases(vm, db) - if err := is.initMeteredCaches(namespace, metrics); err != nil { + if err := is.initMeteredCaches(metrics); err != nil { // Drop any errors on close to return the first error _ = is.Close() diff --git a/vms/platformvm/cache_pending_staker_chain_state.go b/vms/platformvm/cache_pending_staker_chain_state.go index a2b9152bc60b..550f842d0449 100644 --- a/vms/platformvm/cache_pending_staker_chain_state.go +++ b/vms/platformvm/cache_pending_staker_chain_state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/cache_validator.go b/vms/platformvm/cache_validator.go index e1963bbf1e32..1d75312d89a3 100644 --- a/vms/platformvm/cache_validator.go +++ b/vms/platformvm/cache_validator.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/cache_versioned_state.go b/vms/platformvm/cache_versioned_state.go index 279076592e3a..04b3581019c9 100644 --- a/vms/platformvm/cache_versioned_state.go +++ b/vms/platformvm/cache_versioned_state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/client.go b/vms/platformvm/client.go index 9c3f856951c1..c8da3b6b6d12 100644 --- a/vms/platformvm/client.go +++ b/vms/platformvm/client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/codec.go b/vms/platformvm/codec.go index 9e1e52898154..184c3e56f2be 100644 --- a/vms/platformvm/codec.go +++ b/vms/platformvm/codec.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/commit_block.go b/vms/platformvm/commit_block.go index 404e1fdb76c4..b366cec6b6f9 100644 --- a/vms/platformvm/commit_block.go +++ b/vms/platformvm/commit_block.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -24,7 +24,7 @@ type CommitBlock struct { } func (c *CommitBlock) Accept() error { - if c.vm.bootstrapped { + if c.vm.bootstrapped.GetValue() { if c.wasPreferred { c.vm.metrics.numVotesWon.Inc() } else { diff --git a/vms/platformvm/common_blocks.go b/vms/platformvm/common_blocks.go index 2f5a546cd281..5b86db31073b 100644 --- a/vms/platformvm/common_blocks.go +++ b/vms/platformvm/common_blocks.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -277,38 +277,6 @@ func (cdb *CommonDecisionBlock) Reject() error { return cdb.vm.internalState.Commit() } -// SingleDecisionBlock contains the accept for standalone decision blocks -type SingleDecisionBlock struct { - CommonDecisionBlock `serialize:"true"` -} - -// Accept implements the snowman.Block interface -func (sdb *SingleDecisionBlock) Accept() error { - sdb.vm.ctx.Log.Verbo("accepting block with ID %s", sdb.ID()) - - if err := sdb.CommonDecisionBlock.Accept(); err != nil { - return fmt.Errorf("failed to accept CommonBlock: %w", err) - } - - // Update the state of the chain in the database - sdb.onAcceptState.Apply(sdb.vm.internalState) - if err := sdb.vm.internalState.Commit(); err != nil { - return fmt.Errorf("failed to commit vm's state: %w", err) - } - - for _, child := range sdb.children { - child.setBaseState() - } - if sdb.onAcceptFunc != nil { - if err := sdb.onAcceptFunc(); err != nil { - return fmt.Errorf("failed to execute onAcceptFunc: %w", err) - } - } - - sdb.free() - return nil -} - // DoubleDecisionBlock contains the accept for a pair of blocks type DoubleDecisionBlock struct { CommonDecisionBlock `serialize:"true"` diff --git a/vms/platformvm/create_chain_tx.go b/vms/platformvm/create_chain_tx.go index 42c8a921b5fa..fc706d7c82b1 100644 --- a/vms/platformvm/create_chain_tx.go +++ b/vms/platformvm/create_chain_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -9,6 +9,7 @@ import ( "time" "unicode" + "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" @@ -52,6 +53,12 @@ type UnsignedCreateChainTx struct { SubnetAuth verify.Verifiable `serialize:"true" json:"subnetAuthorization"` } +func (tx *UnsignedCreateChainTx) InputUTXOs() ids.Set { return nil } + +func (tx *UnsignedCreateChainTx) AtomicOperations() (ids.ID, *atomic.Requests, error) { + return ids.ID{}, nil, nil +} + func (tx *UnsignedCreateChainTx) SyntacticVerify(ctx *snow.Context) error { switch { case tx == nil: diff --git a/vms/platformvm/create_chain_tx_test.go b/vms/platformvm/create_chain_tx_test.go index 327e615a52a3..08abe20b884b 100644 --- a/vms/platformvm/create_chain_tx_test.go +++ b/vms/platformvm/create_chain_tx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/create_subnet_tx.go b/vms/platformvm/create_subnet_tx.go index c07a9a34d826..07519c9606bd 100644 --- a/vms/platformvm/create_subnet_tx.go +++ b/vms/platformvm/create_subnet_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -7,6 +7,7 @@ import ( "fmt" "time" + "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/utils/crypto" @@ -24,6 +25,13 @@ type UnsignedCreateSubnetTx struct { Owner Owner `serialize:"true" json:"owner"` } +// InputUTXOs for [DecisionTxs] will return an empty set to diffrentiate from the [AtomicTxs] input UTXOs +func (tx *UnsignedCreateSubnetTx) InputUTXOs() ids.Set { return nil } + +func (tx *UnsignedCreateSubnetTx) AtomicOperations() (ids.ID, *atomic.Requests, error) { + return ids.ID{}, nil, nil +} + // InitCtx sets the FxID fields in the inputs and outputs of this // [UnsignedCreateSubnetTx]. Also sets the [ctx] to the given [vm.ctx] so that // the addresses can be json marshalled into human readable format diff --git a/vms/platformvm/create_subnet_tx_test.go b/vms/platformvm/create_subnet_tx_test.go index b2166e9a50ce..c60072fbcf48 100644 --- a/vms/platformvm/create_subnet_tx_test.go +++ b/vms/platformvm/create_subnet_tx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/error.go b/vms/platformvm/error.go index 15123aab14e7..ab3c85e16a55 100644 --- a/vms/platformvm/error.go +++ b/vms/platformvm/error.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/export_tx.go b/vms/platformvm/export_tx.go index 204bc41fce0c..a9851d81076b 100644 --- a/vms/platformvm/export_tx.go +++ b/vms/platformvm/export_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -49,7 +49,7 @@ func (tx *UnsignedExportTx) InitCtx(ctx *snow.Context) { } // InputUTXOs returns an empty set -func (tx *UnsignedExportTx) InputUTXOs() ids.Set { return ids.Set{} } +func (tx *UnsignedExportTx) InputUTXOs() ids.Set { return nil } // SyntacticVerify this transaction is well-formed func (tx *UnsignedExportTx) SyntacticVerify(ctx *snow.Context) error { @@ -58,9 +58,6 @@ func (tx *UnsignedExportTx) SyntacticVerify(ctx *snow.Context) error { return errNilTx case tx.syntacticallyVerified: // already passed syntactic verification return nil - case tx.DestinationChain != ctx.XChainID: - // TODO: remove this check if we allow for P->C swaps - return errWrongChainID case len(tx.ExportedOutputs) == 0: return errNoExportOutputs } @@ -87,16 +84,16 @@ func (tx *UnsignedExportTx) SyntacticVerify(ctx *snow.Context) error { // Attempts to verify this transaction with the provided state. func (tx *UnsignedExportTx) SemanticVerify(vm *VM, parentState MutableState, stx *Tx) error { - _, err := tx.Execute(vm, parentState, stx) + _, err := tx.AtomicExecute(vm, parentState, stx) return err } // Execute this transaction. func (tx *UnsignedExportTx) Execute( vm *VM, - parentState MutableState, + vs VersionedState, stx *Tx, -) (VersionedState, TxError) { +) (func() error, TxError) { if err := tx.SyntacticVerify(vm.ctx); err != nil { return nil, permError{err} } @@ -105,8 +102,14 @@ func (tx *UnsignedExportTx) Execute( copy(outs, tx.Outs) copy(outs[len(tx.Outs):], tx.ExportedOutputs) + if vm.bootstrapped.GetValue() { + if err := vm.isValidCrossChainID(vs, tx.DestinationChain); err != nil { + return nil, err + } + } + // Verify the flowcheck - if err := vm.semanticVerifySpend(parentState, tx, tx.Ins, outs, stx.Creds, vm.TxFee, vm.ctx.AVAXAssetID); err != nil { + if err := vm.semanticVerifySpend(vs, tx, tx.Ins, outs, stx.Creds, vm.TxFee, vm.ctx.AVAXAssetID); err != nil { switch err.(type) { case permError: return nil, permError{ @@ -119,22 +122,16 @@ func (tx *UnsignedExportTx) Execute( } } - // Set up the state if this tx is committed - newState := newVersionedState( - parentState, - parentState.CurrentStakerChainState(), - parentState.PendingStakerChainState(), - ) // Consume the UTXOS - consumeInputs(newState, tx.Ins) + consumeInputs(vs, tx.Ins) // Produce the UTXOS txID := tx.ID() - produceOutputs(newState, txID, vm.ctx.AVAXAssetID, tx.Outs) - return newState, nil + produceOutputs(vs, txID, vm.ctx.AVAXAssetID, tx.Outs) + return nil, nil } -// Accept this transaction. -func (tx *UnsignedExportTx) Accept(ctx *snow.Context, batch database.Batch) error { +// AtomicOperations returns the shared memory requests +func (tx *UnsignedExportTx) AtomicOperations() (ids.ID, *atomic.Requests, error) { txID := tx.ID() elems := make([]*atomic.Element, len(tx.ExportedOutputs)) @@ -150,7 +147,7 @@ func (tx *UnsignedExportTx) Accept(ctx *snow.Context, batch database.Batch) erro utxoBytes, err := Codec.Marshal(CodecVersion, utxo) if err != nil { - return fmt.Errorf("failed to marshal UTXO: %w", err) + return ids.ID{}, nil, fmt.Errorf("failed to marshal UTXO: %w", err) } utxoID := utxo.InputID() elem := &atomic.Element{ @@ -163,8 +160,32 @@ func (tx *UnsignedExportTx) Accept(ctx *snow.Context, batch database.Batch) erro elems[i] = elem } + return tx.DestinationChain, &atomic.Requests{PutRequests: elems}, nil +} - return ctx.SharedMemory.Apply(map[ids.ID]*atomic.Requests{tx.DestinationChain: {PutRequests: elems}}, batch) +// Execute this transaction and return the versioned state. +func (tx *UnsignedExportTx) AtomicExecute( + vm *VM, + parentState MutableState, + stx *Tx, +) (VersionedState, TxError) { + // Set up the state if this tx is committed + newState := newVersionedState( + parentState, + parentState.CurrentStakerChainState(), + parentState.PendingStakerChainState(), + ) + _, err := tx.Execute(vm, newState, stx) + return newState, err +} + +// Accept this transaction. +func (tx *UnsignedExportTx) AtomicAccept(ctx *snow.Context, batch database.Batch) error { + chainID, requests, err := tx.AtomicOperations() + if err != nil { + return err + } + return ctx.SharedMemory.Apply(map[ids.ID]*atomic.Requests{chainID: requests}, batch) } // Create a new transaction @@ -175,10 +196,6 @@ func (vm *VM) newExportTx( keys []*crypto.PrivateKeySECP256K1R, // Pay the fee and provide the tokens changeAddr ids.ShortID, // Address to send change to, if there is any ) (*Tx, error) { - if vm.ctx.XChainID != chainID { - return nil, errWrongChainID - } - toBurn, err := math.Add64(amount, vm.TxFee) if err != nil { return nil, errOverflowExport diff --git a/vms/platformvm/export_tx_test.go b/vms/platformvm/export_tx_test.go new file mode 100644 index 000000000000..aeccc2e9a939 --- /dev/null +++ b/vms/platformvm/export_tx_test.go @@ -0,0 +1,98 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package platformvm + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils/crypto" +) + +func TestNewExportTx(t *testing.T) { + vm, _, _ := defaultVM() + vm.ctx.Lock.Lock() + defer func() { + if err := vm.Shutdown(); err != nil { + t.Fatal(err) + } + vm.ctx.Lock.Unlock() + }() + + type test struct { + description string + destinationChainID ids.ID + sourceKeys []*crypto.PrivateKeySECP256K1R + timestamp time.Time + shouldErr bool + shouldVerify bool + } + + sourceKey := keys[0] + + tests := []test{ + { + description: "P->X export", + destinationChainID: xChainID, + sourceKeys: []*crypto.PrivateKeySECP256K1R{sourceKey}, + timestamp: defaultValidateStartTime, + shouldErr: false, + shouldVerify: true, + }, + { + description: "P->C export before AP5", + destinationChainID: cChainID, + sourceKeys: []*crypto.PrivateKeySECP256K1R{sourceKey}, + timestamp: defaultValidateStartTime, + shouldErr: false, + shouldVerify: false, + }, + { + description: "P->C export after AP5", + destinationChainID: cChainID, + sourceKeys: []*crypto.PrivateKeySECP256K1R{sourceKey}, + timestamp: vm.ApricotPhase5Time, + shouldErr: false, + shouldVerify: true, + }, + } + + to := ids.GenerateTestShortID() + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + assert := assert.New(t) + tx, err := vm.newExportTx(defaultBalance-defaultTxFee, tt.destinationChainID, to, tt.sourceKeys, ids.ShortEmpty) + if tt.shouldErr { + assert.Error(err) + return + } + assert.NoError(err) + + // Get the preferred block (which we want to build off) + preferred, err := vm.Preferred() + assert.NoError(err) + + preferredDecision, ok := preferred.(decision) + assert.True(ok) + + preferredState := preferredDecision.onAccept() + fakedState := newVersionedState( + preferredState, + preferredState.CurrentStakerChainState(), + preferredState.PendingStakerChainState(), + ) + fakedState.SetTimestamp(tt.timestamp) + + err = tx.UnsignedTx.SemanticVerify(vm, fakedState, tx) + if tt.shouldVerify { + assert.NoError(err) + } else { + assert.Error(err) + } + }) + } +} diff --git a/vms/platformvm/factory.go b/vms/platformvm/factory.go index e5d1e739cff6..663a43a69bf9 100644 --- a/vms/platformvm/factory.go +++ b/vms/platformvm/factory.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -79,6 +79,9 @@ type Factory struct { // Time of the AP4 network upgrade ApricotPhase4Time time.Time + + // Time of the AP5 network upgrade + ApricotPhase5Time time.Time } // New returns a new instance of the Platform Chain diff --git a/vms/platformvm/fx.go b/vms/platformvm/fx.go index 2621eb95e240..3708e1be95be 100644 --- a/vms/platformvm/fx.go +++ b/vms/platformvm/fx.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/health.go b/vms/platformvm/health.go index b38eaa0eab99..914ed9155be9 100644 --- a/vms/platformvm/health.go +++ b/vms/platformvm/health.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/import_tx.go b/vms/platformvm/import_tx.go index 62f210f547fa..5be1ed0688dd 100644 --- a/vms/platformvm/import_tx.go +++ b/vms/platformvm/import_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -70,9 +70,6 @@ func (tx *UnsignedImportTx) SyntacticVerify(ctx *snow.Context) error { return errNilTx case tx.syntacticallyVerified: // already passed syntactic verification return nil - case tx.SourceChain != ctx.XChainID: - // TODO: remove this check if we allow for P->C swaps - return errWrongChainID case len(tx.ImportedInputs) == 0: return errNoImportInputs } @@ -96,23 +93,23 @@ func (tx *UnsignedImportTx) SyntacticVerify(ctx *snow.Context) error { // Attempts to verify this transaction with the provided state. func (tx *UnsignedImportTx) SemanticVerify(vm *VM, parentState MutableState, stx *Tx) error { - _, err := tx.Execute(vm, parentState, stx) + _, err := tx.AtomicExecute(vm, parentState, stx) return err } // Execute this transaction. func (tx *UnsignedImportTx) Execute( vm *VM, - parentState MutableState, + vs VersionedState, stx *Tx, -) (VersionedState, TxError) { +) (func() error, TxError) { if err := tx.SyntacticVerify(vm.ctx); err != nil { return nil, permError{err} } utxos := make([]*avax.UTXO, len(tx.Ins)+len(tx.ImportedInputs)) for index, input := range tx.Ins { - utxo, err := parentState.GetUTXO(input.InputID()) + utxo, err := vs.GetUTXO(input.InputID()) if err != nil { return nil, tempError{ fmt.Errorf("failed to get UTXO %s: %w", &input.UTXOID, err), @@ -121,7 +118,11 @@ func (tx *UnsignedImportTx) Execute( utxos[index] = utxo } - if vm.bootstrapped { + if vm.bootstrapped.GetValue() { + if err := vm.isValidCrossChainID(vs, tx.SourceChain); err != nil { + return nil, err + } + utxoIDs := make([][]byte, len(tx.ImportedInputs)) for i, in := range tx.ImportedInputs { utxoID := in.UTXOID.InputID() @@ -153,18 +154,38 @@ func (tx *UnsignedImportTx) Execute( } } + // Consume the UTXOS + consumeInputs(vs, tx.Ins) + // Produce the UTXOS + txID := tx.ID() + produceOutputs(vs, txID, vm.ctx.AVAXAssetID, tx.Outs) + return nil, nil +} + +// AtomicOperations returns the shared memory requests +func (tx *UnsignedImportTx) AtomicOperations() (ids.ID, *atomic.Requests, error) { + utxoIDs := make([][]byte, len(tx.ImportedInputs)) + for i, in := range tx.ImportedInputs { + utxoID := in.InputID() + utxoIDs[i] = utxoID[:] + } + return tx.SourceChain, &atomic.Requests{RemoveRequests: utxoIDs}, nil +} + +// [AtomicExecute] to maintain consistency for the standard block. +func (tx *UnsignedImportTx) AtomicExecute( + vm *VM, + parentState MutableState, + stx *Tx, +) (VersionedState, TxError) { // Set up the state if this tx is committed newState := newVersionedState( parentState, parentState.CurrentStakerChainState(), parentState.PendingStakerChainState(), ) - // Consume the UTXOS - consumeInputs(newState, tx.Ins) - // Produce the UTXOS - txID := tx.ID() - produceOutputs(newState, txID, vm.ctx.AVAXAssetID, tx.Outs) - return newState, nil + _, err := tx.Execute(vm, newState, stx) + return newState, err } // Accept this transaction and spend imported inputs @@ -172,13 +193,12 @@ func (tx *UnsignedImportTx) Execute( // we don't want to remove an imported UTXO in semanticVerify // only to have the transaction not be Accepted. This would be inconsistent. // Recall that imported UTXOs are not kept in a versionDB. -func (tx *UnsignedImportTx) Accept(ctx *snow.Context, batch database.Batch) error { - utxoIDs := make([][]byte, len(tx.ImportedInputs)) - for i, in := range tx.ImportedInputs { - utxoID := in.InputID() - utxoIDs[i] = utxoID[:] +func (tx *UnsignedImportTx) AtomicAccept(ctx *snow.Context, batch database.Batch) error { + chainID, requests, err := tx.AtomicOperations() + if err != nil { + return err } - return ctx.SharedMemory.Apply(map[ids.ID]*atomic.Requests{tx.SourceChain: {RemoveRequests: utxoIDs}}, batch) + return ctx.SharedMemory.Apply(map[ids.ID]*atomic.Requests{chainID: requests}, batch) } // Create a new transaction @@ -188,14 +208,7 @@ func (vm *VM) newImportTx( keys []*crypto.PrivateKeySECP256K1R, // Keys to import the funds changeAddr ids.ShortID, // Address to send change to, if there is any ) (*Tx, error) { - if vm.ctx.XChainID != chainID { - return nil, errWrongChainID - } - - kc := secp256k1fx.NewKeychain() - for _, key := range keys { - kc.Add(key) - } + kc := secp256k1fx.NewKeychain(keys...) atomicUTXOs, _, _, err := vm.GetAtomicUTXOs(chainID, kc.Addresses(), ids.ShortEmpty, ids.Empty, -1) if err != nil { diff --git a/vms/platformvm/import_tx_test.go b/vms/platformvm/import_tx_test.go index e5c91c38a8ed..6cd617e7cf1b 100644 --- a/vms/platformvm/import_tx_test.go +++ b/vms/platformvm/import_tx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -6,6 +6,9 @@ package platformvm import ( "math/rand" "testing" + "time" + + "github.com/stretchr/testify/assert" "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/database/prefixdb" @@ -28,23 +31,26 @@ func TestNewImportTx(t *testing.T) { type test struct { description string + sourceChainID ids.ID sharedMemory atomic.SharedMemory - recipientKeys []*crypto.PrivateKeySECP256K1R + sourceKeys []*crypto.PrivateKeySECP256K1R + timestamp time.Time shouldErr bool + shouldVerify bool } factory := crypto.FactorySECP256K1R{} - recipientKeyIntf, err := factory.NewPrivateKey() + sourceKeyIntf, err := factory.NewPrivateKey() if err != nil { t.Fatal(err) } - recipientKey := recipientKeyIntf.(*crypto.PrivateKeySECP256K1R) + sourceKey := sourceKeyIntf.(*crypto.PrivateKeySECP256K1R) cnt := new(byte) // Returns a shared memory where GetDatabase returns a database // where [recipientKey] has a balance of [amt] - fundedSharedMemory := func(amt uint64) atomic.SharedMemory { + fundedSharedMemory := func(peerChain ids.ID, amt uint64) atomic.SharedMemory { *cnt++ m := &atomic.Memory{} err := m.Initialize(logging.NoLog{}, prefixdb.New([]byte{*cnt}, baseDB)) @@ -53,7 +59,7 @@ func TestNewImportTx(t *testing.T) { } sm := m.NewSharedMemory(vm.ctx.ChainID) - peerSharedMemory := m.NewSharedMemory(avmID) + peerSharedMemory := m.NewSharedMemory(peerChain) // #nosec G404 utxo := &avax.UTXO{ @@ -66,7 +72,7 @@ func TestNewImportTx(t *testing.T) { Amt: amt, OutputOwners: secp256k1fx.OutputOwners{ Locktime: 0, - Addrs: []ids.ShortID{recipientKey.PublicKey().Address()}, + Addrs: []ids.ShortID{sourceKey.PublicKey().Address()}, Threshold: 1, }, }, @@ -80,7 +86,7 @@ func TestNewImportTx(t *testing.T) { Key: inputID[:], Value: utxoBytes, Traits: [][]byte{ - recipientKey.PublicKey().Address().Bytes(), + sourceKey.PublicKey().Address().Bytes(), }, }}}}); err != nil { t.Fatal(err) @@ -91,51 +97,96 @@ func TestNewImportTx(t *testing.T) { tests := []test{ { - description: "recipient key can't pay fee;", - sharedMemory: fundedSharedMemory(vm.TxFee - 1), - recipientKeys: []*crypto.PrivateKeySECP256K1R{recipientKey}, + description: "can't pay fee", + sourceChainID: xChainID, + sharedMemory: fundedSharedMemory(xChainID, vm.TxFee-1), + sourceKeys: []*crypto.PrivateKeySECP256K1R{sourceKey}, shouldErr: true, }, { - description: "recipient key pays fee", - sharedMemory: fundedSharedMemory(vm.TxFee), - recipientKeys: []*crypto.PrivateKeySECP256K1R{recipientKey}, + description: "can barely pay fee", + sourceChainID: xChainID, + sharedMemory: fundedSharedMemory(xChainID, vm.TxFee), + sourceKeys: []*crypto.PrivateKeySECP256K1R{sourceKey}, + shouldErr: false, + shouldVerify: true, + }, + { + + description: "attempting to import from C-chain before AP5", + sourceChainID: cChainID, + sharedMemory: fundedSharedMemory(cChainID, vm.TxFee), + sourceKeys: []*crypto.PrivateKeySECP256K1R{sourceKey}, + timestamp: defaultValidateStartTime, + shouldErr: false, + shouldVerify: false, + }, + { + + description: "attempting to import from C-chain after AP5", + sourceChainID: cChainID, + sharedMemory: fundedSharedMemory(cChainID, vm.TxFee), + sourceKeys: []*crypto.PrivateKeySECP256K1R{sourceKey}, + timestamp: vm.ApricotPhase5Time, shouldErr: false, + shouldVerify: true, }, } to := ids.GenerateTestShortID() for _, tt := range tests { - vm.AtomicUTXOManager = avax.NewAtomicUTXOManager(tt.sharedMemory, Codec) - tx, err := vm.newImportTx(avmID, to, tt.recipientKeys, ids.ShortEmpty) - if err != nil { - if !tt.shouldErr { - t.Fatalf("test '%s' unexpectedly errored with: %s", tt.description, err) + t.Run(tt.description, func(t *testing.T) { + assert := assert.New(t) + + vm.ctx.SharedMemory = tt.sharedMemory + vm.AtomicUTXOManager = avax.NewAtomicUTXOManager(tt.sharedMemory, Codec) + tx, err := vm.newImportTx(tt.sourceChainID, to, tt.sourceKeys, ids.ShortEmpty) + if tt.shouldErr { + assert.Error(err) + return } - continue - } else if tt.shouldErr { - t.Fatalf("test '%s' didn't error but it should have", tt.description) - } - unsignedTx := tx.UnsignedTx.(*UnsignedImportTx) - if len(unsignedTx.ImportedInputs) == 0 { - t.Fatalf("in test '%s', tx has no imported inputs", tt.description) - } else if len(tx.Creds) != len(unsignedTx.Ins)+len(unsignedTx.ImportedInputs) { - t.Fatalf("in test '%s', should have same number of credentials as inputs", tt.description) - } - totalIn := uint64(0) - for _, in := range unsignedTx.Ins { - totalIn += in.Input().Amount() - } - for _, in := range unsignedTx.ImportedInputs { - totalIn += in.Input().Amount() - } - totalOut := uint64(0) - for _, out := range unsignedTx.Outs { - totalOut += out.Out.Amount() - } - if totalIn-totalOut != vm.TxFee { - t.Fatalf("in test '%s'. inputs (%d) != outputs (%d) + txFee (%d)", tt.description, totalIn, totalOut, vm.TxFee) - } + assert.NoError(err) + + unsignedTx := tx.UnsignedTx.(*UnsignedImportTx) + assert.NotEmpty(unsignedTx.ImportedInputs) + assert.Equal(len(tx.Creds), len(unsignedTx.Ins)+len(unsignedTx.ImportedInputs), "should have the same number of credentials as inputs") + + totalIn := uint64(0) + for _, in := range unsignedTx.Ins { + totalIn += in.Input().Amount() + } + for _, in := range unsignedTx.ImportedInputs { + totalIn += in.Input().Amount() + } + totalOut := uint64(0) + for _, out := range unsignedTx.Outs { + totalOut += out.Out.Amount() + } + + assert.Equal(vm.TxFee, totalIn-totalOut, "burned too much") + + // Get the preferred block (which we want to build off) + preferred, err := vm.Preferred() + assert.NoError(err) + + preferredDecision, ok := preferred.(decision) + assert.True(ok) + + preferredState := preferredDecision.onAccept() + fakedState := newVersionedState( + preferredState, + preferredState.CurrentStakerChainState(), + preferredState.PendingStakerChainState(), + ) + fakedState.SetTimestamp(tt.timestamp) + + err = tx.UnsignedTx.SemanticVerify(vm, fakedState, tx) + if tt.shouldVerify { + assert.NoError(err) + } else { + assert.Error(err) + } + }) } } diff --git a/vms/platformvm/json.go b/vms/platformvm/json.go index 22bee5eb57b0..bf5481bf33b5 100644 --- a/vms/platformvm/json.go +++ b/vms/platformvm/json.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/mempool.go b/vms/platformvm/mempool.go index 9a58d3b343e8..2e908bca5aad 100644 --- a/vms/platformvm/mempool.go +++ b/vms/platformvm/mempool.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -48,10 +48,12 @@ type Mempool interface { RemoveDecisionTxs(txs []*Tx) RemoveAtomicTx(tx *Tx) + RemoveAtomicTxs(tx []*Tx) RemoveProposalTx(tx *Tx) PopDecisionTxs(numTxs int) []*Tx PopAtomicTx() *Tx + PopAtomicTxs(numTxs int) []*Tx PopProposalTx() *Tx MarkDropped(txID ids.ID) @@ -151,10 +153,10 @@ func (m *mempool) Add(tx *Tx) error { switch tx.UnsignedTx.(type) { case TimedTx: m.AddProposalTx(tx) - case UnsignedDecisionTx: - m.AddDecisionTx(tx) case UnsignedAtomicTx: m.AddAtomicTx(tx) + case UnsignedDecisionTx: + m.AddDecisionTx(tx) default: m.unknownTxs.Inc() return errUnknownTxType @@ -212,6 +214,15 @@ func (m *mempool) RemoveDecisionTxs(txs []*Tx) { } } +func (m *mempool) RemoveAtomicTxs(txs []*Tx) { + for _, tx := range txs { + txID := tx.ID() + if m.unissuedAtomicTxs.Remove(txID) != nil { + m.deregister(tx) + } + } +} + func (m *mempool) RemoveAtomicTx(tx *Tx) { txID := tx.ID() if m.unissuedAtomicTxs.Remove(txID) != nil { @@ -246,6 +257,21 @@ func (m *mempool) PopAtomicTx() *Tx { return tx } +// Pops a batch of atomic txs +func (m *mempool) PopAtomicTxs(numTxs int) []*Tx { + if maxLen := m.unissuedAtomicTxs.Len(); numTxs > maxLen { + numTxs = maxLen + } + + txs := make([]*Tx, numTxs) + for i := range txs { + tx := m.unissuedAtomicTxs.RemoveTop() + m.deregister(tx) + txs[i] = tx + } + return txs +} + func (m *mempool) PopProposalTx() *Tx { tx := m.unissuedProposalTxs.RemoveTop() m.deregister(tx) diff --git a/vms/platformvm/message/codec.go b/vms/platformvm/message/codec.go index 01b14baaad85..effd5c52d7b4 100644 --- a/vms/platformvm/message/codec.go +++ b/vms/platformvm/message/codec.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package message diff --git a/vms/platformvm/message/handler.go b/vms/platformvm/message/handler.go index 28487a465051..02da6152dfe7 100644 --- a/vms/platformvm/message/handler.go +++ b/vms/platformvm/message/handler.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package message diff --git a/vms/platformvm/message/handler_test.go b/vms/platformvm/message/handler_test.go index d58ca14c985a..0ebfff23c500 100644 --- a/vms/platformvm/message/handler_test.go +++ b/vms/platformvm/message/handler_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package message diff --git a/vms/platformvm/message/message.go b/vms/platformvm/message/message.go index 25b896e1d5db..8a84d8cf68b2 100644 --- a/vms/platformvm/message/message.go +++ b/vms/platformvm/message/message.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package message diff --git a/vms/platformvm/message/message_test.go b/vms/platformvm/message/message_test.go index cdccfb163070..8a0bb51aa498 100644 --- a/vms/platformvm/message/message_test.go +++ b/vms/platformvm/message/message_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package message diff --git a/vms/platformvm/metrics.go b/vms/platformvm/metrics.go index fc595357582b..d4f66899339a 100644 --- a/vms/platformvm/metrics.go +++ b/vms/platformvm/metrics.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/network.go b/vms/platformvm/network.go index 234e34a90ce3..8f27d6d5f216 100644 --- a/vms/platformvm/network.go +++ b/vms/platformvm/network.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/network_test.go b/vms/platformvm/network_test.go index dcf57af55f19..1dee9ea9f2c5 100644 --- a/vms/platformvm/network_test.go +++ b/vms/platformvm/network_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/proposal_block.go b/vms/platformvm/proposal_block.go index d000ef5c0093..6f8584b028d9 100644 --- a/vms/platformvm/proposal_block.go +++ b/vms/platformvm/proposal_block.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/reward.go b/vms/platformvm/reward.go index 1b31b57ca7e5..b2c4dbf8412f 100644 --- a/vms/platformvm/reward.go +++ b/vms/platformvm/reward.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/reward_test.go b/vms/platformvm/reward_test.go index 3165cd62e311..4a46902ff0c8 100644 --- a/vms/platformvm/reward_test.go +++ b/vms/platformvm/reward_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/reward_validator_tx.go b/vms/platformvm/reward_validator_tx.go index c6e298594695..78ceb2489618 100644 --- a/vms/platformvm/reward_validator_tx.go +++ b/vms/platformvm/reward_validator_tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/reward_validator_tx_test.go b/vms/platformvm/reward_validator_tx_test.go index c6f8b3e9cfdd..8956f78883e9 100644 --- a/vms/platformvm/reward_validator_tx_test.go +++ b/vms/platformvm/reward_validator_tx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/service.go b/vms/platformvm/service.go index 7e34fc493c87..33de3ae67947 100644 --- a/vms/platformvm/service.go +++ b/vms/platformvm/service.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 1bc90052c350..94af3c1c1652 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -198,7 +198,7 @@ func TestGetTxStatus(t *testing.T) { } sm := m.NewSharedMemory(service.vm.ctx.ChainID) - peerSharedMemory := m.NewSharedMemory(avmID) + peerSharedMemory := m.NewSharedMemory(xChainID) // #nosec G404 utxo := &avax.UTXO{ @@ -235,7 +235,7 @@ func TestGetTxStatus(t *testing.T) { newAtomicUTXOManager := avax.NewAtomicUTXOManager(sm, Codec) service.vm.AtomicUTXOManager = newAtomicUTXOManager - tx, err := service.vm.newImportTx(avmID, ids.ShortEmpty, []*crypto.PrivateKeySECP256K1R{recipientKey}, ids.ShortEmpty) + tx, err := service.vm.newImportTx(xChainID, ids.ShortEmpty, []*crypto.PrivateKeySECP256K1R{recipientKey}, ids.ShortEmpty) if err != nil { t.Fatal(err) } diff --git a/vms/platformvm/spend.go b/vms/platformvm/spend.go index 95b32a4eefed..b1bb33e231ca 100644 --- a/vms/platformvm/spend.go +++ b/vms/platformvm/spend.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -57,10 +57,7 @@ func (vm *VM) stake( return nil, nil, nil, nil, fmt.Errorf("couldn't get UTXOs: %w", err) } - kc := secp256k1fx.NewKeychain() // Keychain consumes UTXOs and creates new ones - for _, key := range keys { - kc.Add(key) - } + kc := secp256k1fx.NewKeychain(keys...) // Keychain consumes UTXOs and creates new ones // Minimum time this transaction will be issued at now := uint64(vm.clock.Time().Unix()) @@ -308,10 +305,7 @@ func (vm *VM) authorize( } // Add the keys to a keychain - kc := secp256k1fx.NewKeychain() - for _, key := range keys { - kc.Add(key) - } + kc := secp256k1fx.NewKeychain(keys...) // Make sure that the operation is valid after a minimum time now := uint64(vm.clock.Time().Unix()) diff --git a/vms/platformvm/spend_test.go b/vms/platformvm/spend_test.go index ce55efb07891..4e8e0d0e6a62 100644 --- a/vms/platformvm/spend_test.go +++ b/vms/platformvm/spend_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/stakeable_lock.go b/vms/platformvm/stakeable_lock.go index 6e0c6b9573b0..147da0a09cc8 100644 --- a/vms/platformvm/stakeable_lock.go +++ b/vms/platformvm/stakeable_lock.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/standard_block.go b/vms/platformvm/standard_block.go index 58cd56cc1588..e1c31ee17e1b 100644 --- a/vms/platformvm/standard_block.go +++ b/vms/platformvm/standard_block.go @@ -1,16 +1,20 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm import ( + "errors" "fmt" + "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/choices" ) var ( + errConflictingBatchTxs = errors.New("block contains conflicting transactions") + _ Block = &StandardBlock{} _ decision = &StandardBlock{} ) @@ -18,13 +22,17 @@ var ( // StandardBlock being accepted results in the transactions contained in the // block to be accepted and committed to the chain. type StandardBlock struct { - SingleDecisionBlock `serialize:"true"` + CommonDecisionBlock `serialize:"true"` Txs []*Tx `serialize:"true" json:"txs"` + + // inputs are the atomic inputs that are consumed by this block's atomic + // transactions + inputs ids.Set } func (sb *StandardBlock) initialize(vm *VM, bytes []byte, status choices.Status, blk Block) error { - if err := sb.SingleDecisionBlock.initialize(vm, bytes, status, blk); err != nil { + if err := sb.CommonDecisionBlock.initialize(vm, bytes, status, blk); err != nil { return fmt.Errorf("failed to initialize: %w", err) } for _, tx := range sb.Txs { @@ -36,6 +44,22 @@ func (sb *StandardBlock) initialize(vm *VM, bytes []byte, status choices.Status, return nil } +// conflicts checks to see if the provided input set contains any conflicts with +// any of this block's non-accepted ancestors or itself. +func (sb *StandardBlock) conflicts(s ids.Set) (bool, error) { + if sb.Status() == choices.Accepted { + return false, nil + } + if sb.inputs.Overlaps(s) { + return true, nil + } + parent, err := sb.parentBlock() + if err != nil { + return false, err + } + return parent.conflicts(s) +} + // Verify this block performs a valid state transition. // // The parent block must be a proposal @@ -44,7 +68,7 @@ func (sb *StandardBlock) initialize(vm *VM, bytes []byte, status choices.Status, func (sb *StandardBlock) Verify() error { blkID := sb.ID() - if err := sb.SingleDecisionBlock.Verify(); err != nil { + if err := sb.CommonDecisionBlock.Verify(); err != nil { if err := sb.Reject(); err != nil { sb.vm.ctx.Log.Error( "failed to reject standard block %s due to %s", @@ -81,13 +105,38 @@ func (sb *StandardBlock) Verify() error { parentState.PendingStakerChainState(), ) + // clear inputs so that multiple [Verify] calls can be made + sb.inputs.Clear() + + currentTimestamp := parentState.GetTimestamp() + enabledAP5 := !currentTimestamp.Before(sb.vm.ApricotPhase5Time) + funcs := make([]func() error, 0, len(sb.Txs)) for _, tx := range sb.Txs { + txID := tx.ID() + utx, ok := tx.UnsignedTx.(UnsignedDecisionTx) if !ok { return errWrongTxType } - txID := tx.ID() + + // TODO: remove after AP5. + if _, ok := tx.UnsignedTx.(UnsignedAtomicTx); ok && !enabledAP5 { + return fmt.Errorf( + "the chain timestamp (%d) is before the apricot phase 5 time (%d), hence atomic transactions should go through the atomic block", + currentTimestamp.Unix(), + sb.vm.ApricotPhase5Time.Unix(), + ) + } + + inputUTXOs := utx.InputUTXOs() + // ensure it doesnt overlap with current input batch + if sb.inputs.Overlaps(inputUTXOs) { + return errConflictingBatchTxs + } + // Add UTXOs to batch + sb.inputs.Union(inputUTXOs) + onAccept, err := utx.Execute(sb.vm, sb.onAcceptState, tx) if err != nil { sb.vm.droppedTxCache.Put(txID, err.Error()) // cache tx as dropped @@ -100,12 +149,24 @@ func (sb *StandardBlock) Verify() error { } return err } + sb.onAcceptState.AddTx(tx, Committed) if onAccept != nil { funcs = append(funcs, onAccept) } } + if sb.inputs.Len() > 0 { + // ensure it doesnt conflict with the parent block + conflicts, err := parentIntf.conflicts(sb.inputs) + if err != nil { + return err + } + if conflicts { + return errConflictingParentTxs + } + } + if numFuncs := len(funcs); numFuncs == 1 { sb.onAcceptFunc = funcs[0] } else if numFuncs > 1 { @@ -122,11 +183,80 @@ func (sb *StandardBlock) Verify() error { sb.timestamp = sb.onAcceptState.GetTimestamp() sb.vm.blockBuilder.RemoveDecisionTxs(sb.Txs) + sb.vm.blockBuilder.RemoveAtomicTxs(sb.Txs) sb.vm.currentBlocks[blkID] = sb parentIntf.addChild(sb) return nil } +func (sb *StandardBlock) Accept() error { + blkID := sb.ID() + sb.vm.ctx.Log.Verbo("accepting block with ID %s", blkID) + + // Set up the shared memory operations + sharedMemoryOps := make(map[ids.ID]*atomic.Requests) + for _, tx := range sb.Txs { + utx, ok := tx.UnsignedTx.(UnsignedDecisionTx) + if !ok { + return errWrongTxType + } + + // Get the shared memory operations this transaction is performing + chainID, txRequests, err := utx.AtomicOperations() + if err != nil { + return err + } + + // Only [AtomicTx]s will return operations to be applied to shared memory + if txRequests == nil { + continue + } + + // Add/merge in the atomic requests represented by [tx] + chainRequests, exists := sharedMemoryOps[chainID] + if !exists { + sharedMemoryOps[chainID] = txRequests + continue + } + + chainRequests.PutRequests = append(chainRequests.PutRequests, txRequests.PutRequests...) + chainRequests.RemoveRequests = append(chainRequests.RemoveRequests, txRequests.RemoveRequests...) + } + + if err := sb.CommonDecisionBlock.Accept(); err != nil { + return fmt.Errorf("failed to accept CommonDecisionBlock: %w", err) + } + + // Update the state of the chain in the database + sb.onAcceptState.Apply(sb.vm.internalState) + + defer sb.vm.internalState.Abort() + batch, err := sb.vm.internalState.CommitBatch() + if err != nil { + return fmt.Errorf( + "failed to commit VM's database for block %s: %w", + blkID, + err, + ) + } + + if err := sb.vm.ctx.SharedMemory.Apply(sharedMemoryOps, batch); err != nil { + return fmt.Errorf("failed to apply vm's state to shared memory: %w", err) + } + + for _, child := range sb.children { + child.setBaseState() + } + if sb.onAcceptFunc != nil { + if err := sb.onAcceptFunc(); err != nil { + return fmt.Errorf("failed to execute onAcceptFunc: %w", err) + } + } + + sb.free() + return nil +} + func (sb *StandardBlock) Reject() error { sb.vm.ctx.Log.Verbo( "Rejecting Standard Block %s at height %d with parent %s", @@ -144,19 +274,17 @@ func (sb *StandardBlock) Reject() error { ) } } - return sb.SingleDecisionBlock.Reject() + return sb.CommonDecisionBlock.Reject() } // newStandardBlock returns a new *StandardBlock where the block's parent, a // decision block, has ID [parentID]. func (vm *VM) newStandardBlock(parentID ids.ID, height uint64, txs []*Tx) (*StandardBlock, error) { sb := &StandardBlock{ - SingleDecisionBlock: SingleDecisionBlock{ - CommonDecisionBlock: CommonDecisionBlock{ - CommonBlock: CommonBlock{ - PrntID: parentID, - Hght: height, - }, + CommonDecisionBlock: CommonDecisionBlock{ + CommonBlock: CommonBlock{ + PrntID: parentID, + Hght: height, }, }, Txs: txs, diff --git a/vms/platformvm/standard_block_test.go b/vms/platformvm/standard_block_test.go new file mode 100644 index 000000000000..1be360d3950a --- /dev/null +++ b/vms/platformvm/standard_block_test.go @@ -0,0 +1,97 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package platformvm + +import ( + "testing" + "time" + + "github.com/ava-labs/avalanchego/chains/atomic" + "github.com/ava-labs/avalanchego/database/prefixdb" + "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/utils/crypto" + "github.com/ava-labs/avalanchego/utils/logging" + "github.com/ava-labs/avalanchego/vms/components/avax" + "github.com/ava-labs/avalanchego/vms/secp256k1fx" + "github.com/stretchr/testify/assert" +) + +func TestAtomicTxImports(t *testing.T) { + vm, baseDB, _ := defaultVM() + vm.ctx.Lock.Lock() + defer func() { + if err := vm.Shutdown(); err != nil { + t.Fatal(err) + } + vm.ctx.Lock.Unlock() + }() + assert := assert.New(t) + + utxoID := avax.UTXOID{ + TxID: ids.Empty.Prefix(1), + OutputIndex: 1, + } + amount := uint64(70000) + recipientKey := keys[1] + + m := &atomic.Memory{} + err := m.Initialize(logging.NoLog{}, prefixdb.New([]byte{5}, baseDB)) + if err != nil { + t.Fatal(err) + } + vm.ctx.SharedMemory = m.NewSharedMemory(vm.ctx.ChainID) + vm.AtomicUTXOManager = avax.NewAtomicUTXOManager(vm.ctx.SharedMemory, Codec) + peerSharedMemory := m.NewSharedMemory(vm.ctx.XChainID) + utxo := &avax.UTXO{ + UTXOID: utxoID, + Asset: avax.Asset{ID: avaxAssetID}, + Out: &secp256k1fx.TransferOutput{ + Amt: amount, + OutputOwners: secp256k1fx.OutputOwners{ + Threshold: 1, + Addrs: []ids.ShortID{recipientKey.PublicKey().Address()}, + }, + }, + } + utxoBytes, err := Codec.Marshal(CodecVersion, utxo) + if err != nil { + t.Fatal(err) + } + inputID := utxo.InputID() + if err := peerSharedMemory.Apply(map[ids.ID]*atomic.Requests{vm.ctx.ChainID: {PutRequests: []*atomic.Element{{ + Key: inputID[:], + Value: utxoBytes, + Traits: [][]byte{ + recipientKey.PublicKey().Address().Bytes(), + }, + }}}}); err != nil { + t.Fatal(err) + } + + tx, err := vm.newImportTx( + vm.ctx.XChainID, + recipientKey.PublicKey().Address(), + []*crypto.PrivateKeySECP256K1R{recipientKey}, + ids.ShortEmpty, // change addr + ) + if err != nil { + t.Fatal(err) + } + vm.internalState.SetTimestamp(vm.ApricotPhase5Time.Add(100 * time.Second)) + + vm.mempool.AddAtomicTx(tx) + b, err := vm.BuildBlock() + assert.NoError(err) + // Test multiple verify calls work + err = b.Verify() + assert.NoError(err) + err = b.Accept() + assert.NoError(err) + _, status, err := vm.internalState.GetTx(tx.ID()) + assert.NoError(err) + // Ensure transaction is in the committed state + assert.Equal(status, Committed) + // Ensure standard block contains one atomic transaction + assert.Equal(b.(*StandardBlock).inputs.Len(), 1) +} diff --git a/vms/platformvm/state.go b/vms/platformvm/state.go index c79882fa9cae..9fb3aba857cc 100644 --- a/vms/platformvm/state.go +++ b/vms/platformvm/state.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/static_service.go b/vms/platformvm/static_service.go index 721dc1b592c0..d941055ea252 100644 --- a/vms/platformvm/static_service.go +++ b/vms/platformvm/static_service.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/static_service_test.go b/vms/platformvm/static_service_test.go index f8f033d2e608..4af1814e1e06 100644 --- a/vms/platformvm/static_service_test.go +++ b/vms/platformvm/static_service_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/status.go b/vms/platformvm/status.go index 7b12f26aa9f0..6a291f770bff 100644 --- a/vms/platformvm/status.go +++ b/vms/platformvm/status.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/status_test.go b/vms/platformvm/status_test.go index 13ebdef15b72..29425205f1da 100644 --- a/vms/platformvm/status_test.go +++ b/vms/platformvm/status_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/subnet.go b/vms/platformvm/subnet.go index c67e186eab70..96d35b0f8742 100644 --- a/vms/platformvm/subnet.go +++ b/vms/platformvm/subnet.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/tx.go b/vms/platformvm/tx.go index bd06df155bcd..eb422d6b0146 100644 --- a/vms/platformvm/tx.go +++ b/vms/platformvm/tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -7,6 +7,7 @@ import ( "fmt" "time" + "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/ids" @@ -55,6 +56,12 @@ type UnsignedDecisionTx interface { onAcceptFunc func() error, err TxError, ) + + // To maintain consistency with the Atomic txs + InputUTXOs() ids.Set + + // AtomicOperations provides the requests to be written to shared memory. + AtomicOperations() (ids.ID, *atomic.Requests, error) } // UnsignedProposalTx is an unsigned operation that can be proposed @@ -74,16 +81,13 @@ type UnsignedProposalTx interface { // UnsignedAtomicTx is an unsigned operation that can be atomically accepted type UnsignedAtomicTx interface { - UnsignedTx - - // UTXOs this tx consumes - InputUTXOs() ids.Set + UnsignedDecisionTx // Execute this transaction with the provided state. - Execute(vm *VM, parentState MutableState, stx *Tx) (VersionedState, TxError) + AtomicExecute(vm *VM, parentState MutableState, stx *Tx) (VersionedState, TxError) // Accept this transaction with the additionally provided state transitions. - Accept(ctx *snow.Context, batch database.Batch) error + AtomicAccept(ctx *snow.Context, batch database.Batch) error } // Tx is a signed transaction diff --git a/vms/platformvm/tx_heap.go b/vms/platformvm/tx_heap.go index 03d54f14797f..b546600ce153 100644 --- a/vms/platformvm/tx_heap.go +++ b/vms/platformvm/tx_heap.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/tx_heap_by_age.go b/vms/platformvm/tx_heap_by_age.go index 367fb2141350..c145bd11150d 100644 --- a/vms/platformvm/tx_heap_by_age.go +++ b/vms/platformvm/tx_heap_by_age.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/tx_heap_by_end_time.go b/vms/platformvm/tx_heap_by_end_time.go index e12b590a78b3..4f003c9aeabb 100644 --- a/vms/platformvm/tx_heap_by_end_time.go +++ b/vms/platformvm/tx_heap_by_end_time.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/tx_heap_by_end_time_test.go b/vms/platformvm/tx_heap_by_end_time_test.go index b6a271d395db..142ebf2aeb1f 100644 --- a/vms/platformvm/tx_heap_by_end_time_test.go +++ b/vms/platformvm/tx_heap_by_end_time_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/tx_heap_by_start_time.go b/vms/platformvm/tx_heap_by_start_time.go index a1f3a10cf45f..d31e58ffa67b 100644 --- a/vms/platformvm/tx_heap_by_start_time.go +++ b/vms/platformvm/tx_heap_by_start_time.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/tx_heap_by_start_time_test.go b/vms/platformvm/tx_heap_by_start_time_test.go index 2a3767a61a94..d23fa5472562 100644 --- a/vms/platformvm/tx_heap_by_start_time_test.go +++ b/vms/platformvm/tx_heap_by_start_time_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/tx_heap_metrics.go b/vms/platformvm/tx_heap_metrics.go index a2964beaad29..c93164e7c5df 100644 --- a/vms/platformvm/tx_heap_metrics.go +++ b/vms/platformvm/tx_heap_metrics.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/user.go b/vms/platformvm/user.go index d63b6c6729db..3fd08d142a94 100644 --- a/vms/platformvm/user.go +++ b/vms/platformvm/user.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/user_test.go b/vms/platformvm/user_test.go index 54ea7064deb0..3d46e2f3347f 100644 --- a/vms/platformvm/user_test.go +++ b/vms/platformvm/user_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/validator.go b/vms/platformvm/validator.go index 6bd515d36221..277cc874d394 100644 --- a/vms/platformvm/validator.go +++ b/vms/platformvm/validator.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/validator_test.go b/vms/platformvm/validator_test.go index 0fbf3f5212f3..7f18cd9ac4e5 100644 --- a/vms/platformvm/validator_test.go +++ b/vms/platformvm/validator_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm diff --git a/vms/platformvm/vm.go b/vms/platformvm/vm.go index f85678232a42..3b49baf3adfc 100644 --- a/vms/platformvm/vm.go +++ b/vms/platformvm/vm.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -10,6 +10,8 @@ import ( "github.com/gorilla/rpc/v2" + "github.com/prometheus/client_golang/prometheus" + "github.com/ava-labs/avalanchego/cache" "github.com/ava-labs/avalanchego/chains" "github.com/ava-labs/avalanchego/codec" @@ -24,6 +26,7 @@ import ( "github.com/ava-labs/avalanchego/snow/engine/snowman/block" "github.com/ava-labs/avalanchego/snow/uptime" "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/crypto" "github.com/ava-labs/avalanchego/utils/json" @@ -33,6 +36,7 @@ import ( "github.com/ava-labs/avalanchego/utils/wrappers" "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/components/avax" + "github.com/ava-labs/avalanchego/vms/components/verify" "github.com/ava-labs/avalanchego/vms/secp256k1fx" safemath "github.com/ava-labs/avalanchego/utils/math" @@ -117,7 +121,7 @@ type VM struct { codecRegistry codec.Registry // Bootstrapped remembers if this chain has finished bootstrapping or not - bootstrapped bool + bootstrapped utils.AtomicBool // Contains the IDs of transactions recently dropped because they failed // verification. These txs may be re-issued and put into accepted blocks, so @@ -153,8 +157,13 @@ func (vm *VM) Initialize( ) error { ctx.Log.Verbo("initializing platform chain") + registerer := prometheus.NewRegistry() + if err := ctx.Metrics.Register(registerer); err != nil { + return err + } + // Initialize metrics as soon as possible - if err := vm.metrics.Initialize(ctx.Namespace, ctx.Metrics); err != nil { + if err := vm.metrics.Initialize("", registerer); err != nil { return err } @@ -179,7 +188,7 @@ func (vm *VM) Initialize( vm.validatorSetCaches = make(map[ids.ID]cache.Cacher) vm.currentBlocks = make(map[ids.ID]Block) - if err := vm.blockBuilder.Initialize(vm); err != nil { + if err := vm.blockBuilder.Initialize(vm, registerer); err != nil { return fmt.Errorf( "failed to initialize the block builder: %w", err, @@ -187,7 +196,7 @@ func (vm *VM) Initialize( } vm.network = newNetwork(vm.ApricotPhase4Time, appSender, vm) - is, err := NewMeteredInternalState(vm, vm.dbManager.Current().Database, genesisBytes, ctx.Namespace, ctx.Metrics) + is, err := NewMeteredInternalState(vm, vm.dbManager.Current().Database, genesisBytes, registerer) if err != nil { return err } @@ -195,7 +204,7 @@ func (vm *VM) Initialize( // Initialize the utility to track validator uptimes vm.uptimeManager = uptime.NewManager(is) - vm.UptimeLockedCalculator.SetCalculator(ctx, vm.uptimeManager) + vm.UptimeLockedCalculator.SetCalculator(&vm.bootstrapped, &ctx.Lock, vm.uptimeManager) if err := vm.updateValidators(true); err != nil { return fmt.Errorf( @@ -289,16 +298,16 @@ func (vm *VM) createChain(tx *Tx) error { // Bootstrapping marks this VM as bootstrapping func (vm *VM) Bootstrapping() error { - vm.bootstrapped = false + vm.bootstrapped.SetValue(false) return vm.fx.Bootstrapping() } // Bootstrapped marks this VM as bootstrapped func (vm *VM) Bootstrapped() error { - if vm.bootstrapped { + if vm.bootstrapped.GetValue() { return nil } - vm.bootstrapped = true + vm.bootstrapped.SetValue(true) errs := wrappers.Errs{} errs.Add( @@ -334,7 +343,7 @@ func (vm *VM) Shutdown() error { vm.blockBuilder.Shutdown() - if vm.bootstrapped { + if vm.bootstrapped.GetValue() { primaryValidatorSet, exist := vm.Validators.GetValidators(constants.PrimaryNetworkID) if !exist { return errNoPrimaryValidators @@ -575,7 +584,7 @@ func (vm *VM) GetCurrentHeight() (uint64, error) { func (vm *VM) updateValidators(force bool) error { now := vm.clock.Time() - if !force && !vm.bootstrapped && now.Sub(vm.lastVdrUpdate) < 5*time.Second { + if !force && !vm.bootstrapped.GetValue() && now.Sub(vm.lastVdrUpdate) < 5*time.Second { return nil } vm.lastVdrUpdate = now @@ -668,3 +677,17 @@ func (vm *VM) getPercentConnected() (float64, error) { } return float64(connectedStake) / float64(vdrSet.Weight()), nil } + +// TODO: remove after AP5 +func (vm *VM) isValidCrossChainID(vs VersionedState, peerChainID ids.ID) TxError { + currentTimestamp := vs.GetTimestamp() + enabledAP5 := !currentTimestamp.Before(vm.ApricotPhase5Time) + if enabledAP5 { + if err := verify.SameSubnet(vm.ctx, peerChainID); err != nil { + return tempError{err} + } + } else if peerChainID != vm.ctx.XChainID { + return permError{errWrongChainID} + } + return nil +} diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 02907858d9a1..9e7adbdc655a 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package platformvm @@ -83,7 +83,8 @@ var ( testSubnet1 *UnsignedCreateSubnetTx testSubnet1ControlKeys []*crypto.PrivateKeySECP256K1R - avmID = ids.Empty.Prefix(0) + xChainID = ids.Empty.Prefix(0) + cChainID = ids.Empty.Prefix(1) ) var ( @@ -115,10 +116,22 @@ func init() { testSubnet1ControlKeys = keys[0:3] } +type snLookup struct { + chainsToSubnet map[ids.ID]ids.ID +} + +func (sn *snLookup) SubnetID(chainID ids.ID) (ids.ID, error) { + subnetID, ok := sn.chainsToSubnet[chainID] + if !ok { + return ids.ID{}, errors.New("") + } + return subnetID, nil +} + func defaultContext() *snow.Context { ctx := snow.DefaultContextTest() ctx.NetworkID = testNetworkID - ctx.XChainID = avmID + ctx.XChainID = xChainID ctx.AVAXAssetID = avaxAssetID aliaser := ids.NewAliaser() @@ -126,13 +139,23 @@ func defaultContext() *snow.Context { errs.Add( aliaser.Alias(constants.PlatformChainID, "P"), aliaser.Alias(constants.PlatformChainID, constants.PlatformChainID.String()), - aliaser.Alias(avmID, "X"), - aliaser.Alias(avmID, avmID.String()), + aliaser.Alias(xChainID, "X"), + aliaser.Alias(xChainID, xChainID.String()), + aliaser.Alias(cChainID, "C"), + aliaser.Alias(cChainID, cChainID.String()), ) if errs.Errored() { panic(errs.Err) } ctx.BCLookup = aliaser + + ctx.SNLookup = &snLookup{ + chainsToSubnet: map[ids.ID]ids.ID{ + constants.PlatformChainID: constants.PrimaryNetworkID, + xChainID: constants.PrimaryNetworkID, + cChainID: constants.PrimaryNetworkID, + }, + } return ctx } @@ -298,6 +321,8 @@ func defaultVM() (*VM, database.Database, *common.SenderTest) { MaxStakeDuration: defaultMaxStakingDuration, StakeMintingPeriod: defaultMaxStakingDuration, ApricotPhase3Time: defaultValidateEndTime, + ApricotPhase4Time: defaultValidateEndTime, + ApricotPhase5Time: defaultValidateEndTime, }} baseDBManager := manager.NewMemDB(version.DefaultVersion1_0_0) @@ -2027,6 +2052,8 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { vm.clock.Set(defaultGenesisTime) ctx := defaultContext() + consensusCtx := snow.DefaultConsensusContextTest() + consensusCtx.Context = ctx ctx.Lock.Lock() msgChan := make(chan common.Message, 1) @@ -2096,7 +2123,7 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { // Passes messages from the consensus engine to the network sender := sender.Sender{} - err = sender.Initialize(ctx, mc, externalSender, chainRouter, &timeoutManager, "", metrics, 1, 1, 1) + err = sender.Initialize(consensusCtx, mc, externalSender, chainRouter, &timeoutManager, 1, 1, 1) assert.NoError(t, err) var reqID uint32 @@ -2125,7 +2152,7 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { err = engine.Initialize(smeng.Config{ Config: bootstrap.Config{ Config: common.Config{ - Ctx: ctx, + Ctx: consensusCtx, Validators: vdrs, Beacons: beacons, SampleK: beacons.Len(), @@ -2140,7 +2167,6 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { VM: vm, }, Params: snowball.Parameters{ - Metrics: prometheus.NewRegistry(), K: 1, Alpha: 1, BetaVirtuous: 20, @@ -2163,8 +2189,6 @@ func TestBootstrapPartiallyAccepted(t *testing.T) { &engine, vdrs, msgChan, - "", - prometheus.NewRegistry(), ) assert.NoError(t, err) @@ -2398,6 +2422,7 @@ func TestUnverifiedParentPanic(t *testing.T) { _, genesisBytes := defaultGenesis() baseDBManager := manager.NewMemDB(version.DefaultVersion1_0_0) + atomicDB := prefixdb.New([]byte{1}, baseDBManager.Current().Database) vm := &VM{Factory: Factory{ Chains: chains.MockManager{}, @@ -2422,6 +2447,12 @@ func TestUnverifiedParentPanic(t *testing.T) { if err := vm.Initialize(ctx, baseDBManager, genesisBytes, nil, nil, msgChan, nil, nil); err != nil { t.Fatal(err) } + m := &atomic.Memory{} + err := m.Initialize(logging.NoLog{}, atomicDB) + if err != nil { + panic(err) + } + vm.ctx.SharedMemory = m.NewSharedMemory(ctx.ChainID) key0 := keys[0] key1 := keys[1] diff --git a/vms/propertyfx/burn_operation.go b/vms/propertyfx/burn_operation.go index 83704f624532..600f3c6ecb7f 100644 --- a/vms/propertyfx/burn_operation.go +++ b/vms/propertyfx/burn_operation.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package propertyfx diff --git a/vms/propertyfx/burn_operation_test.go b/vms/propertyfx/burn_operation_test.go index a369b564709f..dcbbb748a180 100644 --- a/vms/propertyfx/burn_operation_test.go +++ b/vms/propertyfx/burn_operation_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package propertyfx diff --git a/vms/propertyfx/credential.go b/vms/propertyfx/credential.go index a8d14be6a741..007237eb6cdf 100644 --- a/vms/propertyfx/credential.go +++ b/vms/propertyfx/credential.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package propertyfx diff --git a/vms/propertyfx/credential_test.go b/vms/propertyfx/credential_test.go index 920430351bd8..0b6185d9610f 100644 --- a/vms/propertyfx/credential_test.go +++ b/vms/propertyfx/credential_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package propertyfx diff --git a/vms/propertyfx/factory.go b/vms/propertyfx/factory.go index 0953cf2aaeef..91c447cebe97 100644 --- a/vms/propertyfx/factory.go +++ b/vms/propertyfx/factory.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package propertyfx diff --git a/vms/propertyfx/factory_test.go b/vms/propertyfx/factory_test.go index 06016222e6b4..8d89c241c0ed 100644 --- a/vms/propertyfx/factory_test.go +++ b/vms/propertyfx/factory_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package propertyfx diff --git a/vms/propertyfx/fx.go b/vms/propertyfx/fx.go index ec788e85a1c8..fdfb61517cd6 100644 --- a/vms/propertyfx/fx.go +++ b/vms/propertyfx/fx.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package propertyfx diff --git a/vms/propertyfx/fx_test.go b/vms/propertyfx/fx_test.go index 6e487df15486..1d5a195b7448 100644 --- a/vms/propertyfx/fx_test.go +++ b/vms/propertyfx/fx_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package propertyfx diff --git a/vms/propertyfx/mint_operation.go b/vms/propertyfx/mint_operation.go index 2a1a344fbc6d..520fb5814029 100644 --- a/vms/propertyfx/mint_operation.go +++ b/vms/propertyfx/mint_operation.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package propertyfx diff --git a/vms/propertyfx/mint_operation_test.go b/vms/propertyfx/mint_operation_test.go index 9e20c05cf9b4..ec58508595d1 100644 --- a/vms/propertyfx/mint_operation_test.go +++ b/vms/propertyfx/mint_operation_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package propertyfx diff --git a/vms/propertyfx/mint_output.go b/vms/propertyfx/mint_output.go index 7091b466e778..4ca557a56a3c 100644 --- a/vms/propertyfx/mint_output.go +++ b/vms/propertyfx/mint_output.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package propertyfx diff --git a/vms/propertyfx/mint_output_test.go b/vms/propertyfx/mint_output_test.go index 3020b1b1036d..b7858d2dbc04 100644 --- a/vms/propertyfx/mint_output_test.go +++ b/vms/propertyfx/mint_output_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package propertyfx diff --git a/vms/propertyfx/owned_output.go b/vms/propertyfx/owned_output.go index 907595544108..edad8d555f5a 100644 --- a/vms/propertyfx/owned_output.go +++ b/vms/propertyfx/owned_output.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package propertyfx diff --git a/vms/propertyfx/owned_output_test.go b/vms/propertyfx/owned_output_test.go index 1e8091245d94..1ebcaa507cbe 100644 --- a/vms/propertyfx/owned_output_test.go +++ b/vms/propertyfx/owned_output_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package propertyfx diff --git a/vms/proposervm/batched_vm.go b/vms/proposervm/batched_vm.go index 8290ccc7d040..661211347e62 100644 --- a/vms/proposervm/batched_vm.go +++ b/vms/proposervm/batched_vm.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposervm diff --git a/vms/proposervm/batched_vm_test.go b/vms/proposervm/batched_vm_test.go index 2878cf6fe30c..b626e6059f7d 100644 --- a/vms/proposervm/batched_vm_test.go +++ b/vms/proposervm/batched_vm_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposervm @@ -893,7 +893,6 @@ func initTestRemoteProposerVM( ctx.StakingCertLeaf = pTestCert.Leaf ctx.StakingLeafSigner = pTestCert.PrivateKey.(crypto.Signer) ctx.ValidatorState = valState - ctx.Bootstrapped() dummyDBManager := manager.NewMemDB(version.DefaultVersion1_0_0) // make sure that DBs are compressed correctly @@ -905,6 +904,10 @@ func initTestRemoteProposerVM( // Initialize shouldn't be called again coreVM.InitializeF = nil + if err := proVM.Bootstrapped(); err != nil { + t.Fatal(err) + } + if err := proVM.SetPreference(coreGenBlk.IDV); err != nil { t.Fatal(err) } diff --git a/vms/proposervm/block.go b/vms/proposervm/block.go index 77cefc5514d4..cb1ea25c91cd 100644 --- a/vms/proposervm/block.go +++ b/vms/proposervm/block.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposervm @@ -104,7 +104,7 @@ func (p *postForkCommonComponents) Verify(parentTimestamp time.Time, parentPChai // If the node is currently bootstrapping - we don't assume that the P-chain // has been synced up to this point yet. - if p.vm.ctx.IsBootstrapped() { + if p.vm.bootstrapped { childID := child.ID() currentPChainHeight, err := p.vm.ctx.ValidatorState.GetCurrentHeight() if err != nil { diff --git a/vms/proposervm/block/block.go b/vms/proposervm/block/block.go index e18ff3b4570c..c9dca069cb2d 100644 --- a/vms/proposervm/block/block.go +++ b/vms/proposervm/block/block.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/vms/proposervm/block/block_test.go b/vms/proposervm/block/block_test.go index 26f51e1071a9..d6b0f169301d 100644 --- a/vms/proposervm/block/block_test.go +++ b/vms/proposervm/block/block_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/vms/proposervm/block/build.go b/vms/proposervm/block/build.go index a846ded45d8d..7960fa579e19 100644 --- a/vms/proposervm/block/build.go +++ b/vms/proposervm/block/build.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/vms/proposervm/block/build_test.go b/vms/proposervm/block/build_test.go index 110ed7ea0fd2..cd28bf6a572e 100644 --- a/vms/proposervm/block/build_test.go +++ b/vms/proposervm/block/build_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/vms/proposervm/block/codec.go b/vms/proposervm/block/codec.go index 141bb5bbea34..9e0384728946 100644 --- a/vms/proposervm/block/codec.go +++ b/vms/proposervm/block/codec.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/vms/proposervm/block/header.go b/vms/proposervm/block/header.go index ae285acca772..e8c093fd64a3 100644 --- a/vms/proposervm/block/header.go +++ b/vms/proposervm/block/header.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/vms/proposervm/block/header_test.go b/vms/proposervm/block/header_test.go index b014eb7477d6..ae4ff12d0442 100644 --- a/vms/proposervm/block/header_test.go +++ b/vms/proposervm/block/header_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/vms/proposervm/block/option.go b/vms/proposervm/block/option.go index 578fd3c0e6fd..49632fd9e5ce 100644 --- a/vms/proposervm/block/option.go +++ b/vms/proposervm/block/option.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/vms/proposervm/block/option_test.go b/vms/proposervm/block/option_test.go index f1f259ec3d5f..0e9205957db1 100644 --- a/vms/proposervm/block/option_test.go +++ b/vms/proposervm/block/option_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/vms/proposervm/block/parse.go b/vms/proposervm/block/parse.go index 028ee391ce85..1b9bbfa74488 100644 --- a/vms/proposervm/block/parse.go +++ b/vms/proposervm/block/parse.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/vms/proposervm/block/parse_test.go b/vms/proposervm/block/parse_test.go index c1f75e75542d..89209db18168 100644 --- a/vms/proposervm/block/parse_test.go +++ b/vms/proposervm/block/parse_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package block diff --git a/vms/proposervm/post_fork_block.go b/vms/proposervm/post_fork_block.go index 856e4a59b0f2..6aee28ffc16e 100644 --- a/vms/proposervm/post_fork_block.go +++ b/vms/proposervm/post_fork_block.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposervm diff --git a/vms/proposervm/post_fork_block_test.go b/vms/proposervm/post_fork_block_test.go index 850a5b703f0a..e12d9c935f43 100644 --- a/vms/proposervm/post_fork_block_test.go +++ b/vms/proposervm/post_fork_block_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposervm diff --git a/vms/proposervm/post_fork_option.go b/vms/proposervm/post_fork_option.go index 8ff9cf84da0c..a6db9af2e3d1 100644 --- a/vms/proposervm/post_fork_option.go +++ b/vms/proposervm/post_fork_option.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposervm diff --git a/vms/proposervm/post_fork_option_test.go b/vms/proposervm/post_fork_option_test.go index 78824a0a0d9d..128c2449e936 100644 --- a/vms/proposervm/post_fork_option_test.go +++ b/vms/proposervm/post_fork_option_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposervm diff --git a/vms/proposervm/pre_fork_block.go b/vms/proposervm/pre_fork_block.go index ba766d881611..46f2aca9b768 100644 --- a/vms/proposervm/pre_fork_block.go +++ b/vms/proposervm/pre_fork_block.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposervm diff --git a/vms/proposervm/pre_fork_block_test.go b/vms/proposervm/pre_fork_block_test.go index 98070408a2e6..f594fba1690a 100644 --- a/vms/proposervm/pre_fork_block_test.go +++ b/vms/proposervm/pre_fork_block_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposervm diff --git a/vms/proposervm/proposer/validators.go b/vms/proposervm/proposer/validators.go index 366c39a5e047..a7e86debf4d2 100644 --- a/vms/proposervm/proposer/validators.go +++ b/vms/proposervm/proposer/validators.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposer diff --git a/vms/proposervm/proposer/windower.go b/vms/proposervm/proposer/windower.go index 1c496cde51e8..1a3b89227bb3 100644 --- a/vms/proposervm/proposer/windower.go +++ b/vms/proposervm/proposer/windower.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposer diff --git a/vms/proposervm/proposer/windower_test.go b/vms/proposervm/proposer/windower_test.go index e0202c62754e..fde4f8221a5b 100644 --- a/vms/proposervm/proposer/windower_test.go +++ b/vms/proposervm/proposer/windower_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposer diff --git a/vms/proposervm/scheduler/scheduler.go b/vms/proposervm/scheduler/scheduler.go index 440890874132..299743d33b5e 100644 --- a/vms/proposervm/scheduler/scheduler.go +++ b/vms/proposervm/scheduler/scheduler.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package scheduler diff --git a/vms/proposervm/scheduler/scheduler_test.go b/vms/proposervm/scheduler/scheduler_test.go index d19a39b065cb..edf80fb971c1 100644 --- a/vms/proposervm/scheduler/scheduler_test.go +++ b/vms/proposervm/scheduler/scheduler_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package scheduler diff --git a/vms/proposervm/state/block_state.go b/vms/proposervm/state/block_state.go index 6bd771ad6b11..59a976aec03f 100644 --- a/vms/proposervm/state/block_state.go +++ b/vms/proposervm/state/block_state.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state diff --git a/vms/proposervm/state/block_state_test.go b/vms/proposervm/state/block_state_test.go index 3d698842813b..70a993c8ca43 100644 --- a/vms/proposervm/state/block_state_test.go +++ b/vms/proposervm/state/block_state_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state diff --git a/vms/proposervm/state/chain_state.go b/vms/proposervm/state/chain_state.go index f125f8872d72..937b25a42101 100644 --- a/vms/proposervm/state/chain_state.go +++ b/vms/proposervm/state/chain_state.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state diff --git a/vms/proposervm/state/chain_state_test.go b/vms/proposervm/state/chain_state_test.go index 5af54fc8b426..060ba5c1e083 100644 --- a/vms/proposervm/state/chain_state_test.go +++ b/vms/proposervm/state/chain_state_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state diff --git a/vms/proposervm/state/codec.go b/vms/proposervm/state/codec.go index 4d1c215d1a52..e09af4db1174 100644 --- a/vms/proposervm/state/codec.go +++ b/vms/proposervm/state/codec.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state diff --git a/vms/proposervm/state/state.go b/vms/proposervm/state/state.go index 1db9eeb43c63..10c03224c1f2 100644 --- a/vms/proposervm/state/state.go +++ b/vms/proposervm/state/state.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state diff --git a/vms/proposervm/state/state_test.go b/vms/proposervm/state/state_test.go index 24e0b0ecfe39..b26afa603fde 100644 --- a/vms/proposervm/state/state_test.go +++ b/vms/proposervm/state/state_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package state diff --git a/vms/proposervm/tree/tree.go b/vms/proposervm/tree/tree.go index 6b6140d85504..c9d3354b6ede 100644 --- a/vms/proposervm/tree/tree.go +++ b/vms/proposervm/tree/tree.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package tree diff --git a/vms/proposervm/tree/tree_test.go b/vms/proposervm/tree/tree_test.go index 4426dc284ee7..56ebe4717e5a 100644 --- a/vms/proposervm/tree/tree_test.go +++ b/vms/proposervm/tree/tree_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package tree diff --git a/vms/proposervm/vm.go b/vms/proposervm/vm.go index b7b85a66f983..a1714502c39d 100644 --- a/vms/proposervm/vm.go +++ b/vms/proposervm/vm.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposervm @@ -59,6 +59,7 @@ type VM struct { // hasn't yet been accepted/rejected verifiedBlocks map[ids.ID]PostForkBlock preferred ids.ID + bootstrapped bool // lastAcceptedOptionTime is set to the last accepted PostForkBlock's // timestamp if the last accepted block has been a PostForkOption block @@ -123,6 +124,16 @@ func (vm *VM) Initialize( return vm.setLastAcceptedOptionTime() } +func (vm *VM) Bootstrapping() error { + vm.bootstrapped = false + return vm.ChainVM.Bootstrapping() +} + +func (vm *VM) Bootstrapped() error { + vm.bootstrapped = true + return vm.ChainVM.Bootstrapped() +} + func (vm *VM) BuildBlock() (snowman.Block, error) { preferredBlock, err := vm.getBlock(vm.preferred) if err != nil { diff --git a/vms/proposervm/vm_byzantine_test.go b/vms/proposervm/vm_byzantine_test.go index bc336158760b..691b158ec0cc 100644 --- a/vms/proposervm/vm_byzantine_test.go +++ b/vms/proposervm/vm_byzantine_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposervm diff --git a/vms/proposervm/vm_test.go b/vms/proposervm/vm_test.go index 01aebe5391bf..6015819e9af7 100644 --- a/vms/proposervm/vm_test.go +++ b/vms/proposervm/vm_test.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package proposervm @@ -119,7 +119,6 @@ func initTestProposerVM( ctx.StakingCertLeaf = pTestCert.Leaf ctx.StakingLeafSigner = pTestCert.PrivateKey.(crypto.Signer) ctx.ValidatorState = valState - ctx.Bootstrapped() dummyDBManager := manager.NewMemDB(version.DefaultVersion1_0_0) // make sure that DBs are compressed correctly @@ -131,6 +130,10 @@ func initTestProposerVM( // Initialize shouldn't be called again coreVM.InitializeF = nil + if err := proVM.Bootstrapped(); err != nil { + t.Fatal(err) + } + if err := proVM.SetPreference(coreGenBlk.IDV); err != nil { t.Fatal(err) } @@ -856,7 +859,6 @@ func TestExpiredBuildBlock(t *testing.T) { ctx.StakingCertLeaf = pTestCert.Leaf ctx.StakingLeafSigner = pTestCert.PrivateKey.(crypto.Signer) ctx.ValidatorState = valState - ctx.Bootstrapped() dbManager := manager.NewMemDB(version.DefaultVersion1_0_0) toEngine := make(chan common.Message, 1) @@ -884,6 +886,10 @@ func TestExpiredBuildBlock(t *testing.T) { // Initialize shouldn't be called again coreVM.InitializeF = nil + if err := proVM.Bootstrapped(); err != nil { + t.Fatal(err) + } + if err := proVM.SetPreference(coreGenBlk.IDV); err != nil { t.Fatal(err) } @@ -1149,7 +1155,6 @@ func TestInnerVMRollback(t *testing.T) { ctx.StakingCertLeaf = pTestCert.Leaf ctx.StakingLeafSigner = pTestCert.PrivateKey.(crypto.Signer) ctx.ValidatorState = valState - ctx.Bootstrapped() coreVM.InitializeF = func( *snow.Context, @@ -1172,6 +1177,10 @@ func TestInnerVMRollback(t *testing.T) { t.Fatalf("failed to initialize proposerVM with %s", err) } + if err := proVM.Bootstrapped(); err != nil { + t.Fatal(err) + } + if err := proVM.SetPreference(coreGenBlk.IDV); err != nil { t.Fatal(err) } diff --git a/vms/rpcchainvm/factory.go b/vms/rpcchainvm/factory.go index 0ce53275b4d8..5e4d2307131b 100644 --- a/vms/rpcchainvm/factory.go +++ b/vms/rpcchainvm/factory.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package rpcchainvm diff --git a/vms/rpcchainvm/ghttp/gconn/conn_client.go b/vms/rpcchainvm/ghttp/gconn/conn_client.go index f43f106bbd03..58172d16ff1a 100644 --- a/vms/rpcchainvm/ghttp/gconn/conn_client.go +++ b/vms/rpcchainvm/ghttp/gconn/conn_client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package gconn diff --git a/vms/rpcchainvm/ghttp/gconn/conn_server.go b/vms/rpcchainvm/ghttp/gconn/conn_server.go index 7af74eeec2f2..ae555e01c8a8 100644 --- a/vms/rpcchainvm/ghttp/gconn/conn_server.go +++ b/vms/rpcchainvm/ghttp/gconn/conn_server.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package gconn diff --git a/vms/rpcchainvm/ghttp/greadcloser/reader_client.go b/vms/rpcchainvm/ghttp/greadcloser/reader_client.go index 714f95d49b81..4d200ab45659 100644 --- a/vms/rpcchainvm/ghttp/greadcloser/reader_client.go +++ b/vms/rpcchainvm/ghttp/greadcloser/reader_client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package greadcloser diff --git a/vms/rpcchainvm/ghttp/greadcloser/reader_server.go b/vms/rpcchainvm/ghttp/greadcloser/reader_server.go index 7caf33fcc69e..ee66e4b75f11 100644 --- a/vms/rpcchainvm/ghttp/greadcloser/reader_server.go +++ b/vms/rpcchainvm/ghttp/greadcloser/reader_server.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package greadcloser diff --git a/vms/rpcchainvm/ghttp/greader/reader_client.go b/vms/rpcchainvm/ghttp/greader/reader_client.go index 7ea8ee7288b0..471801e1bbca 100644 --- a/vms/rpcchainvm/ghttp/greader/reader_client.go +++ b/vms/rpcchainvm/ghttp/greader/reader_client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package greader diff --git a/vms/rpcchainvm/ghttp/greader/reader_server.go b/vms/rpcchainvm/ghttp/greader/reader_server.go index 9aeec2a08b74..bee21b63da25 100644 --- a/vms/rpcchainvm/ghttp/greader/reader_server.go +++ b/vms/rpcchainvm/ghttp/greader/reader_server.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package greader diff --git a/vms/rpcchainvm/ghttp/gresponsewriter/writer_client.go b/vms/rpcchainvm/ghttp/gresponsewriter/writer_client.go index 5001c495b699..2bcbf0e98c55 100644 --- a/vms/rpcchainvm/ghttp/gresponsewriter/writer_client.go +++ b/vms/rpcchainvm/ghttp/gresponsewriter/writer_client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package gresponsewriter diff --git a/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go b/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go index 3fd0822351f2..261ce83dcfb2 100644 --- a/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go +++ b/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package gresponsewriter diff --git a/vms/rpcchainvm/ghttp/gwriter/writer_client.go b/vms/rpcchainvm/ghttp/gwriter/writer_client.go index c4d9bf6b5661..c823bd9ce355 100644 --- a/vms/rpcchainvm/ghttp/gwriter/writer_client.go +++ b/vms/rpcchainvm/ghttp/gwriter/writer_client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package gwriter diff --git a/vms/rpcchainvm/ghttp/gwriter/writer_server.go b/vms/rpcchainvm/ghttp/gwriter/writer_server.go index c751b7fccb30..82434df3143d 100644 --- a/vms/rpcchainvm/ghttp/gwriter/writer_server.go +++ b/vms/rpcchainvm/ghttp/gwriter/writer_server.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package gwriter diff --git a/vms/rpcchainvm/ghttp/http_client.go b/vms/rpcchainvm/ghttp/http_client.go index ea7fa922d740..fb53d74b4d88 100644 --- a/vms/rpcchainvm/ghttp/http_client.go +++ b/vms/rpcchainvm/ghttp/http_client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ghttp diff --git a/vms/rpcchainvm/ghttp/http_server.go b/vms/rpcchainvm/ghttp/http_server.go index e4f60f2f04a1..9efbe1ce7e92 100644 --- a/vms/rpcchainvm/ghttp/http_server.go +++ b/vms/rpcchainvm/ghttp/http_server.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package ghttp diff --git a/vms/rpcchainvm/grpcutils/server_closer.go b/vms/rpcchainvm/grpcutils/server_closer.go index ad9133bcdaf4..a51323ebd2c8 100644 --- a/vms/rpcchainvm/grpcutils/server_closer.go +++ b/vms/rpcchainvm/grpcutils/server_closer.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package grpcutils diff --git a/vms/rpcchainvm/gsubnetlookup/subnet_lookup_client.go b/vms/rpcchainvm/gsubnetlookup/subnet_lookup_client.go index db85b041bc23..5693e8a39f28 100644 --- a/vms/rpcchainvm/gsubnetlookup/subnet_lookup_client.go +++ b/vms/rpcchainvm/gsubnetlookup/subnet_lookup_client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package gsubnetlookup diff --git a/vms/rpcchainvm/gsubnetlookup/subnet_lookup_server.go b/vms/rpcchainvm/gsubnetlookup/subnet_lookup_server.go index 9cd98f224576..07e359a382b4 100644 --- a/vms/rpcchainvm/gsubnetlookup/subnet_lookup_server.go +++ b/vms/rpcchainvm/gsubnetlookup/subnet_lookup_server.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package gsubnetlookup diff --git a/vms/rpcchainvm/messenger/messenger_client.go b/vms/rpcchainvm/messenger/messenger_client.go index 6170761b4449..d724aa378840 100644 --- a/vms/rpcchainvm/messenger/messenger_client.go +++ b/vms/rpcchainvm/messenger/messenger_client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package messenger diff --git a/vms/rpcchainvm/messenger/messenger_server.go b/vms/rpcchainvm/messenger/messenger_server.go index 52bd39acbecf..93096f1f7206 100644 --- a/vms/rpcchainvm/messenger/messenger_server.go +++ b/vms/rpcchainvm/messenger/messenger_server.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package messenger diff --git a/vms/rpcchainvm/metrics_client.go b/vms/rpcchainvm/metrics_client.go new file mode 100644 index 000000000000..3f9299e688b6 --- /dev/null +++ b/vms/rpcchainvm/metrics_client.go @@ -0,0 +1,22 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package rpcchainvm + +import ( + "context" + + "github.com/prometheus/client_golang/prometheus" + dto "github.com/prometheus/client_model/go" + "google.golang.org/protobuf/types/known/emptypb" +) + +var _ prometheus.Gatherer = &VMClient{} + +func (vm *VMClient) Gather() ([]*dto.MetricFamily, error) { + resp, err := vm.client.Gather(context.Background(), &emptypb.Empty{}) + if err != nil { + return nil, err + } + return resp.MetricFamilies, nil +} diff --git a/vms/rpcchainvm/metrics_server.go b/vms/rpcchainvm/metrics_server.go new file mode 100644 index 000000000000..79bda2fb60e2 --- /dev/null +++ b/vms/rpcchainvm/metrics_server.go @@ -0,0 +1,16 @@ +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package rpcchainvm + +import ( + "context" + + "github.com/ava-labs/avalanchego/vms/rpcchainvm/vmproto" + "google.golang.org/protobuf/types/known/emptypb" +) + +func (vm *VMServer) Gather(context.Context, *emptypb.Empty) (*vmproto.GatherResponse, error) { + mfs, err := vm.ctx.Metrics.Gather() + return &vmproto.GatherResponse{MetricFamilies: mfs}, err +} diff --git a/vms/rpcchainvm/vm.go b/vms/rpcchainvm/vm.go index 1168b5e58d56..aaf1c7785ed5 100644 --- a/vms/rpcchainvm/vm.go +++ b/vms/rpcchainvm/vm.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package rpcchainvm @@ -16,7 +16,7 @@ import ( // Handshake is a common handshake that is shared by plugin and host. var Handshake = plugin.HandshakeConfig{ - ProtocolVersion: 8, + ProtocolVersion: 9, MagicCookieKey: "VM_PLUGIN", MagicCookieValue: "dynamic", } diff --git a/vms/rpcchainvm/vm_client.go b/vms/rpcchainvm/vm_client.go index cf6db986b89c..6c447b38229f 100644 --- a/vms/rpcchainvm/vm_client.go +++ b/vms/rpcchainvm/vm_client.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package rpcchainvm @@ -9,13 +9,16 @@ import ( "fmt" "time" + "github.com/hashicorp/go-plugin" + + "github.com/prometheus/client_golang/prometheus" + "google.golang.org/grpc" "google.golang.org/protobuf/types/known/emptypb" - "github.com/hashicorp/go-plugin" - "github.com/ava-labs/avalanchego/api/keystore/gkeystore" "github.com/ava-labs/avalanchego/api/keystore/gkeystore/gkeystoreproto" + "github.com/ava-labs/avalanchego/api/metrics" "github.com/ava-labs/avalanchego/chains/atomic/gsharedmemory" "github.com/ava-labs/avalanchego/chains/atomic/gsharedmemory/gsharedmemoryproto" "github.com/ava-labs/avalanchego/database/manager" @@ -105,11 +108,6 @@ func (vm *VMClient) Initialize( return errUnsupportedFXs } - epochFirstTransitionBytes, err := ctx.EpochFirstTransition.MarshalBinary() - if err != nil { - return err - } - vm.ctx = ctx // Initialize and serve each database and construct the db manager @@ -162,24 +160,22 @@ func (vm *VMClient) Initialize( go vm.broker.AcceptAndServe(appSenderBrokerID, vm.startAppSenderServer) resp, err := vm.client.Initialize(context.Background(), &vmproto.InitializeRequest{ - NetworkID: ctx.NetworkID, - SubnetID: ctx.SubnetID[:], - ChainID: ctx.ChainID[:], - NodeID: ctx.NodeID.Bytes(), - XChainID: ctx.XChainID[:], - AvaxAssetID: ctx.AVAXAssetID[:], - GenesisBytes: genesisBytes, - UpgradeBytes: upgradeBytes, - ConfigBytes: configBytes, - DbServers: versionedDBServers, - EngineServer: messengerBrokerID, - KeystoreServer: keystoreBrokerID, - SharedMemoryServer: sharedMemoryBrokerID, - BcLookupServer: bcLookupBrokerID, - SnLookupServer: snLookupBrokerID, - AppSenderServer: appSenderBrokerID, - EpochFirstTransition: epochFirstTransitionBytes, - EpochDuration: uint64(ctx.EpochDuration), + NetworkID: ctx.NetworkID, + SubnetID: ctx.SubnetID[:], + ChainID: ctx.ChainID[:], + NodeID: ctx.NodeID.Bytes(), + XChainID: ctx.XChainID[:], + AvaxAssetID: ctx.AVAXAssetID[:], + GenesisBytes: genesisBytes, + UpgradeBytes: upgradeBytes, + ConfigBytes: configBytes, + DbServers: versionedDBServers, + EngineServer: messengerBrokerID, + KeystoreServer: keystoreBrokerID, + SharedMemoryServer: sharedMemoryBrokerID, + BcLookupServer: bcLookupBrokerID, + SnLookupServer: snLookupBrokerID, + AppSenderServer: appSenderBrokerID, }) if err != nil { return err @@ -214,9 +210,17 @@ func (vm *VMClient) Initialize( time: timestamp, } + registerer := prometheus.NewRegistry() + multiGatherer := metrics.NewMultiGatherer() + if err := multiGatherer.Register("rpcchainvm", registerer); err != nil { + return err + } + if err := multiGatherer.Register("", vm); err != nil { + return err + } + chainState, err := chain.NewMeteredState( - ctx.Metrics, - fmt.Sprintf("%s_rpcchainvm", ctx.Namespace), + registerer, &chain.Config{ DecidedCacheSize: decidedCacheSize, MissingCacheSize: missingCacheSize, @@ -233,7 +237,7 @@ func (vm *VMClient) Initialize( } vm.State = chainState - return nil + return vm.ctx.Metrics.Register(multiGatherer) } func (vm *VMClient) startDBServer(opts []grpc.ServerOption) *grpc.Server { diff --git a/vms/rpcchainvm/vm_server.go b/vms/rpcchainvm/vm_server.go index 84e8bcba3fb6..2fc9e7a8ad94 100644 --- a/vms/rpcchainvm/vm_server.go +++ b/vms/rpcchainvm/vm_server.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package rpcchainvm @@ -15,6 +15,7 @@ import ( "github.com/ava-labs/avalanchego/api/keystore/gkeystore" "github.com/ava-labs/avalanchego/api/keystore/gkeystore/gkeystoreproto" + "github.com/ava-labs/avalanchego/api/metrics" "github.com/ava-labs/avalanchego/chains/atomic/gsharedmemory" "github.com/ava-labs/avalanchego/chains/atomic/gsharedmemory/gsharedmemoryproto" "github.com/ava-labs/avalanchego/database/manager" @@ -87,11 +88,6 @@ func (vm *VMServer) Initialize(_ context.Context, req *vmproto.InitializeRequest return nil, err } - epochFirstTransition := time.Time{} - if err := epochFirstTransition.UnmarshalBinary(req.EpochFirstTransition); err != nil { - return nil, err - } - // Dial each database in the request and construct the database manager versionedDBs := make([]*manager.VersionedDatabase, len(req.DbServers)) versionParser := version.NewDefaultParser() @@ -196,21 +192,22 @@ func (vm *VMServer) Initialize(_ context.Context, req *vmproto.InitializeRequest }() vm.ctx = &snow.Context{ - NetworkID: req.NetworkID, - SubnetID: subnetID, - ChainID: chainID, - NodeID: nodeID, - XChainID: xChainID, - AVAXAssetID: avaxAssetID, - Log: logging.NoLog{}, - DecisionDispatcher: nil, - ConsensusDispatcher: nil, - Keystore: keystoreClient, - SharedMemory: sharedMemoryClient, - BCLookup: bcLookupClient, - SNLookup: snLookupClient, - EpochFirstTransition: epochFirstTransition, - EpochDuration: time.Duration(req.EpochDuration), + NetworkID: req.NetworkID, + SubnetID: subnetID, + ChainID: chainID, + NodeID: nodeID, + + XChainID: xChainID, + AVAXAssetID: avaxAssetID, + + Log: logging.NoLog{}, + Keystore: keystoreClient, + SharedMemory: sharedMemoryClient, + BCLookup: bcLookupClient, + SNLookup: snLookupClient, + Metrics: metrics.NewOptionalGatherer(), + + // TODO: support snowman++ fields } if err := vm.vm.Initialize(vm.ctx, dbManager, req.GenesisBytes, req.UpgradeBytes, req.ConfigBytes, toEngine, nil, appSenderClient); err != nil { @@ -254,7 +251,6 @@ func (vm *VMServer) Bootstrapping(context.Context, *emptypb.Empty) (*emptypb.Emp } func (vm *VMServer) Bootstrapped(context.Context, *emptypb.Empty) (*emptypb.Empty, error) { - vm.ctx.Bootstrapped() return &emptypb.Empty{}, vm.vm.Bootstrapped() } diff --git a/vms/rpcchainvm/vmproto/vm.pb.go b/vms/rpcchainvm/vmproto/vm.pb.go index 93b4d3fe43ef..d60f80c60199 100644 --- a/vms/rpcchainvm/vmproto/vm.pb.go +++ b/vms/rpcchainvm/vmproto/vm.pb.go @@ -7,6 +7,7 @@ package vmproto import ( + _go "github.com/prometheus/client_model/go" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" emptypb "google.golang.org/protobuf/types/known/emptypb" @@ -26,24 +27,22 @@ type InitializeRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - NetworkID uint32 `protobuf:"varint,1,opt,name=networkID,proto3" json:"networkID,omitempty"` - SubnetID []byte `protobuf:"bytes,2,opt,name=subnetID,proto3" json:"subnetID,omitempty"` - ChainID []byte `protobuf:"bytes,3,opt,name=chainID,proto3" json:"chainID,omitempty"` - NodeID []byte `protobuf:"bytes,4,opt,name=nodeID,proto3" json:"nodeID,omitempty"` - XChainID []byte `protobuf:"bytes,5,opt,name=xChainID,proto3" json:"xChainID,omitempty"` - AvaxAssetID []byte `protobuf:"bytes,6,opt,name=avaxAssetID,proto3" json:"avaxAssetID,omitempty"` - GenesisBytes []byte `protobuf:"bytes,7,opt,name=genesisBytes,proto3" json:"genesisBytes,omitempty"` - UpgradeBytes []byte `protobuf:"bytes,8,opt,name=upgradeBytes,proto3" json:"upgradeBytes,omitempty"` - ConfigBytes []byte `protobuf:"bytes,9,opt,name=configBytes,proto3" json:"configBytes,omitempty"` - DbServers []*VersionedDBServer `protobuf:"bytes,10,rep,name=dbServers,proto3" json:"dbServers,omitempty"` - EngineServer uint32 `protobuf:"varint,11,opt,name=engineServer,proto3" json:"engineServer,omitempty"` - KeystoreServer uint32 `protobuf:"varint,12,opt,name=keystoreServer,proto3" json:"keystoreServer,omitempty"` - SharedMemoryServer uint32 `protobuf:"varint,13,opt,name=sharedMemoryServer,proto3" json:"sharedMemoryServer,omitempty"` - BcLookupServer uint32 `protobuf:"varint,14,opt,name=bcLookupServer,proto3" json:"bcLookupServer,omitempty"` - SnLookupServer uint32 `protobuf:"varint,15,opt,name=snLookupServer,proto3" json:"snLookupServer,omitempty"` - AppSenderServer uint32 `protobuf:"varint,16,opt,name=appSenderServer,proto3" json:"appSenderServer,omitempty"` - EpochFirstTransition []byte `protobuf:"bytes,17,opt,name=epochFirstTransition,proto3" json:"epochFirstTransition,omitempty"` - EpochDuration uint64 `protobuf:"varint,18,opt,name=EpochDuration,proto3" json:"EpochDuration,omitempty"` + NetworkID uint32 `protobuf:"varint,1,opt,name=networkID,proto3" json:"networkID,omitempty"` + SubnetID []byte `protobuf:"bytes,2,opt,name=subnetID,proto3" json:"subnetID,omitempty"` + ChainID []byte `protobuf:"bytes,3,opt,name=chainID,proto3" json:"chainID,omitempty"` + NodeID []byte `protobuf:"bytes,4,opt,name=nodeID,proto3" json:"nodeID,omitempty"` + XChainID []byte `protobuf:"bytes,5,opt,name=xChainID,proto3" json:"xChainID,omitempty"` + AvaxAssetID []byte `protobuf:"bytes,6,opt,name=avaxAssetID,proto3" json:"avaxAssetID,omitempty"` + GenesisBytes []byte `protobuf:"bytes,7,opt,name=genesisBytes,proto3" json:"genesisBytes,omitempty"` + UpgradeBytes []byte `protobuf:"bytes,8,opt,name=upgradeBytes,proto3" json:"upgradeBytes,omitempty"` + ConfigBytes []byte `protobuf:"bytes,9,opt,name=configBytes,proto3" json:"configBytes,omitempty"` + DbServers []*VersionedDBServer `protobuf:"bytes,10,rep,name=dbServers,proto3" json:"dbServers,omitempty"` + EngineServer uint32 `protobuf:"varint,11,opt,name=engineServer,proto3" json:"engineServer,omitempty"` + KeystoreServer uint32 `protobuf:"varint,12,opt,name=keystoreServer,proto3" json:"keystoreServer,omitempty"` + SharedMemoryServer uint32 `protobuf:"varint,13,opt,name=sharedMemoryServer,proto3" json:"sharedMemoryServer,omitempty"` + BcLookupServer uint32 `protobuf:"varint,14,opt,name=bcLookupServer,proto3" json:"bcLookupServer,omitempty"` + SnLookupServer uint32 `protobuf:"varint,15,opt,name=snLookupServer,proto3" json:"snLookupServer,omitempty"` + AppSenderServer uint32 `protobuf:"varint,16,opt,name=appSenderServer,proto3" json:"appSenderServer,omitempty"` } func (x *InitializeRequest) Reset() { @@ -190,20 +189,6 @@ func (x *InitializeRequest) GetAppSenderServer() uint32 { return 0 } -func (x *InitializeRequest) GetEpochFirstTransition() []byte { - if x != nil { - return x.EpochFirstTransition - } - return nil -} - -func (x *InitializeRequest) GetEpochDuration() uint64 { - if x != nil { - return x.EpochDuration - } - return 0 -} - type InitializeResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1724,295 +1709,347 @@ func (x *BatchedParseBlockResponse) GetResponse() []*ParseBlockResponse { return nil } +type GatherResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + MetricFamilies []*_go.MetricFamily `protobuf:"bytes,1,rep,name=metricFamilies,proto3" json:"metricFamilies,omitempty"` +} + +func (x *GatherResponse) Reset() { + *x = GatherResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_vm_proto_msgTypes[28] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GatherResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GatherResponse) ProtoMessage() {} + +func (x *GatherResponse) ProtoReflect() protoreflect.Message { + mi := &file_vm_proto_msgTypes[28] + 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 GatherResponse.ProtoReflect.Descriptor instead. +func (*GatherResponse) Descriptor() ([]byte, []int) { + return file_vm_proto_rawDescGZIP(), []int{28} +} + +func (x *GatherResponse) GetMetricFamilies() []*_go.MetricFamily { + if x != nil { + return x.MetricFamilies + } + return nil +} + var File_vm_proto protoreflect.FileDescriptor var file_vm_proto_rawDesc = []byte{ 0x0a, 0x08, 0x76, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x22, 0xb1, 0x05, 0x0a, 0x11, 0x49, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, - 0x6b, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x6e, 0x65, 0x74, 0x77, 0x6f, - 0x72, 0x6b, 0x49, 0x44, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x44, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x44, - 0x12, 0x18, 0x0a, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, - 0x64, 0x65, 0x49, 0x44, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, - 0x49, 0x44, 0x12, 0x1a, 0x0a, 0x08, 0x78, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x78, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x12, 0x20, - 0x0a, 0x0b, 0x61, 0x76, 0x61, 0x78, 0x41, 0x73, 0x73, 0x65, 0x74, 0x49, 0x44, 0x18, 0x06, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x61, 0x76, 0x61, 0x78, 0x41, 0x73, 0x73, 0x65, 0x74, 0x49, 0x44, - 0x12, 0x22, 0x0a, 0x0c, 0x67, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x42, 0x79, 0x74, 0x65, 0x73, - 0x18, 0x07, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0c, 0x67, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x42, - 0x79, 0x74, 0x65, 0x73, 0x12, 0x22, 0x0a, 0x0c, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x42, - 0x79, 0x74, 0x65, 0x73, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0c, 0x75, 0x70, 0x67, 0x72, - 0x61, 0x64, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x42, 0x79, 0x74, 0x65, 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, - 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x38, 0x0a, 0x09, 0x64, 0x62, - 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, - 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 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, 0x22, 0x0a, 0x0c, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x53, 0x65, - 0x72, 0x76, 0x65, 0x72, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0c, 0x65, 0x6e, 0x67, 0x69, - 0x6e, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x26, 0x0a, 0x0e, 0x6b, 0x65, 0x79, 0x73, - 0x74, 0x6f, 0x72, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0d, - 0x52, 0x0e, 0x6b, 0x65, 0x79, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x12, 0x2e, 0x0a, 0x12, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x4d, 0x65, 0x6d, 0x6f, 0x72, 0x79, - 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x12, 0x73, 0x68, - 0x61, 0x72, 0x65, 0x64, 0x4d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x12, 0x26, 0x0a, 0x0e, 0x62, 0x63, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x53, 0x65, 0x72, 0x76, - 0x65, 0x72, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0e, 0x62, 0x63, 0x4c, 0x6f, 0x6f, 0x6b, - 0x75, 0x70, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x26, 0x0a, 0x0e, 0x73, 0x6e, 0x4c, 0x6f, - 0x6f, 0x6b, 0x75, 0x70, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x0d, - 0x52, 0x0e, 0x73, 0x6e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x12, 0x28, 0x0a, 0x0f, 0x61, 0x70, 0x70, 0x53, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x53, 0x65, 0x72, - 0x76, 0x65, 0x72, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0f, 0x61, 0x70, 0x70, 0x53, 0x65, - 0x6e, 0x64, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x32, 0x0a, 0x14, 0x65, 0x70, - 0x6f, 0x63, 0x68, 0x46, 0x69, 0x72, 0x73, 0x74, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x69, 0x74, 0x69, - 0x6f, 0x6e, 0x18, 0x11, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x14, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x46, - 0x69, 0x72, 0x73, 0x74, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x24, - 0x0a, 0x0d, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, - 0x12, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x44, 0x75, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x22, 0xd4, 0x01, 0x0a, 0x12, 0x49, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, - 0x69, 0x7a, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x6c, - 0x61, 0x73, 0x74, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x49, 0x44, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x0e, 0x6c, 0x61, 0x73, 0x74, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, - 0x64, 0x49, 0x44, 0x12, 0x32, 0x0a, 0x14, 0x6c, 0x61, 0x73, 0x74, 0x41, 0x63, 0x63, 0x65, 0x70, - 0x74, 0x65, 0x64, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x14, 0x6c, 0x61, 0x73, 0x74, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x50, - 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, - 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, - 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, - 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x12, 0x1c, 0x0a, - 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x49, 0x0a, 0x11, 0x56, - 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x64, 0x44, 0x42, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x62, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0d, 0x52, 0x08, 0x64, 0x62, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x18, 0x0a, 0x07, - 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, - 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x46, 0x0a, 0x16, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x2c, 0x0a, 0x08, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x48, 0x61, 0x6e, - 0x64, 0x6c, 0x65, 0x72, 0x52, 0x08, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x22, 0x4c, - 0x0a, 0x1c, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x69, 0x63, 0x48, 0x61, - 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, - 0x0a, 0x08, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x10, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x48, 0x61, 0x6e, 0x64, 0x6c, - 0x65, 0x72, 0x52, 0x08, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x22, 0x5b, 0x0a, 0x07, - 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, - 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x12, - 0x20, 0x0a, 0x0b, 0x6c, 0x6f, 0x63, 0x6b, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0b, 0x6c, 0x6f, 0x63, 0x6b, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x0d, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x22, 0x8c, 0x01, 0x0a, 0x12, 0x42, 0x75, - 0x69, 0x6c, 0x64, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x1a, 0x0d, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0xd7, 0x04, 0x0a, 0x11, 0x49, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, + 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, + 0x6b, 0x49, 0x44, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x44, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x73, 0x75, 0x62, 0x6e, 0x65, 0x74, 0x49, 0x44, 0x12, + 0x18, 0x0a, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, 0x64, + 0x65, 0x49, 0x44, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, + 0x44, 0x12, 0x1a, 0x0a, 0x08, 0x78, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x18, 0x05, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x08, 0x78, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x12, 0x20, 0x0a, + 0x0b, 0x61, 0x76, 0x61, 0x78, 0x41, 0x73, 0x73, 0x65, 0x74, 0x49, 0x44, 0x18, 0x06, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x0b, 0x61, 0x76, 0x61, 0x78, 0x41, 0x73, 0x73, 0x65, 0x74, 0x49, 0x44, 0x12, + 0x22, 0x0a, 0x0c, 0x67, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x42, 0x79, 0x74, 0x65, 0x73, 0x18, + 0x07, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0c, 0x67, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x42, 0x79, + 0x74, 0x65, 0x73, 0x12, 0x22, 0x0a, 0x0c, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x42, 0x79, + 0x74, 0x65, 0x73, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0c, 0x75, 0x70, 0x67, 0x72, 0x61, + 0x64, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x42, 0x79, 0x74, 0x65, 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x38, 0x0a, 0x09, 0x64, 0x62, 0x53, + 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x76, + 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 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, 0x22, 0x0a, 0x0c, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x53, 0x65, 0x72, + 0x76, 0x65, 0x72, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0c, 0x65, 0x6e, 0x67, 0x69, 0x6e, + 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x26, 0x0a, 0x0e, 0x6b, 0x65, 0x79, 0x73, 0x74, + 0x6f, 0x72, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0d, 0x52, + 0x0e, 0x6b, 0x65, 0x79, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, + 0x2e, 0x0a, 0x12, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x4d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x53, + 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x12, 0x73, 0x68, 0x61, + 0x72, 0x65, 0x64, 0x4d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, + 0x26, 0x0a, 0x0e, 0x62, 0x63, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x53, 0x65, 0x72, 0x76, 0x65, + 0x72, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0e, 0x62, 0x63, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, + 0x70, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x26, 0x0a, 0x0e, 0x73, 0x6e, 0x4c, 0x6f, 0x6f, + 0x6b, 0x75, 0x70, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x0d, 0x52, + 0x0e, 0x73, 0x6e, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, + 0x28, 0x0a, 0x0f, 0x61, 0x70, 0x70, 0x53, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, + 0x65, 0x72, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0f, 0x61, 0x70, 0x70, 0x53, 0x65, 0x6e, + 0x64, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x22, 0xd4, 0x01, 0x0a, 0x12, 0x49, 0x6e, + 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x26, 0x0a, 0x0e, 0x6c, 0x61, 0x73, 0x74, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, + 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0e, 0x6c, 0x61, 0x73, 0x74, 0x41, 0x63, + 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x49, 0x44, 0x12, 0x32, 0x0a, 0x14, 0x6c, 0x61, 0x73, 0x74, + 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x44, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x14, 0x6c, 0x61, 0x73, 0x74, 0x41, 0x63, 0x63, 0x65, + 0x70, 0x74, 0x65, 0x64, 0x50, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, + 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x73, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x14, 0x0a, 0x05, + 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x79, 0x74, + 0x65, 0x73, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, + 0x06, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x22, 0x49, 0x0a, 0x11, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x64, 0x44, 0x42, 0x53, + 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x62, 0x53, 0x65, 0x72, 0x76, 0x65, + 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x64, 0x62, 0x53, 0x65, 0x72, 0x76, 0x65, + 0x72, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x46, 0x0a, 0x16, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x08, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, + 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2e, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x52, 0x08, 0x68, 0x61, 0x6e, 0x64, 0x6c, + 0x65, 0x72, 0x73, 0x22, 0x4c, 0x0a, 0x1c, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x74, 0x61, + 0x74, 0x69, 0x63, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x08, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, + 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x52, 0x08, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, + 0x73, 0x22, 0x5b, 0x0a, 0x07, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, + 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x72, + 0x65, 0x66, 0x69, 0x78, 0x12, 0x20, 0x0a, 0x0b, 0x6c, 0x6f, 0x63, 0x6b, 0x4f, 0x70, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0b, 0x6c, 0x6f, 0x63, 0x6b, 0x4f, + 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x22, 0x8c, + 0x01, 0x0a, 0x12, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, + 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, + 0x44, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, + 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, + 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x29, 0x0a, + 0x11, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x22, 0x8e, 0x01, 0x0a, 0x12, 0x50, 0x61, 0x72, + 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x69, 0x64, 0x12, + 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x73, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x73, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74, + 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, + 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x21, 0x0a, 0x0f, 0x47, 0x65, 0x74, + 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x69, 0x64, 0x22, 0x92, 0x01, 0x0a, + 0x10, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x12, 0x14, 0x0a, + 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x79, + 0x74, 0x65, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x68, + 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x68, 0x65, 0x69, + 0x67, 0x68, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, + 0x70, 0x22, 0x26, 0x0a, 0x14, 0x53, 0x65, 0x74, 0x50, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, + 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2a, 0x0a, 0x12, 0x42, 0x6c, 0x6f, + 0x63, 0x6b, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x14, 0x0a, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, + 0x62, 0x79, 0x74, 0x65, 0x73, 0x22, 0x33, 0x0a, 0x13, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x56, 0x65, + 0x72, 0x69, 0x66, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, + 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x24, 0x0a, 0x12, 0x42, 0x6c, + 0x6f, 0x63, 0x6b, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x69, 0x64, - 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x12, 0x14, 0x0a, 0x05, - 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x79, 0x74, - 0x65, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x04, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, - 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x74, - 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x29, 0x0a, 0x11, 0x50, 0x61, 0x72, 0x73, - 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, - 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x79, - 0x74, 0x65, 0x73, 0x22, 0x8e, 0x01, 0x0a, 0x12, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, - 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, - 0x72, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x70, 0x61, - 0x72, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, - 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, - 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, - 0x61, 0x6d, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, - 0x74, 0x61, 0x6d, 0x70, 0x22, 0x21, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x02, 0x69, 0x64, 0x22, 0x92, 0x01, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x42, - 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, - 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, - 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x44, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x79, 0x74, 0x65, - 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x12, 0x16, - 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, - 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x1c, - 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x26, 0x0a, 0x14, - 0x53, 0x65, 0x74, 0x50, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x02, 0x69, 0x64, 0x22, 0x2a, 0x0a, 0x12, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x56, 0x65, 0x72, - 0x69, 0x66, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x79, - 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, - 0x22, 0x33, 0x0a, 0x13, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, - 0x74, 0x61, 0x6d, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, - 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x24, 0x0a, 0x12, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x41, 0x63, - 0x63, 0x65, 0x70, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x69, 0x64, 0x22, 0x24, 0x0a, 0x12, 0x42, - 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x69, - 0x64, 0x22, 0x2a, 0x0a, 0x0e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x22, 0x2b, 0x0a, - 0x0f, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 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, 0x22, 0x7b, 0x0a, 0x0d, 0x41, 0x70, - 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x6e, + 0x22, 0x24, 0x0a, 0x12, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x6a, 0x65, 0x63, 0x74, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2a, 0x0a, 0x0e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x74, 0x61, + 0x69, 0x6c, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x64, 0x65, 0x74, 0x61, 0x69, + 0x6c, 0x73, 0x22, 0x2b, 0x0a, 0x0f, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 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, 0x22, + 0x7b, 0x0a, 0x0d, 0x41, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x4d, 0x73, 0x67, + 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x49, 0x44, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, + 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, + 0x6e, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x4b, 0x0a, 0x13, + 0x41, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, + 0x4d, 0x73, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, 0x12, 0x1c, 0x0a, 0x09, 0x72, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, + 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x44, 0x22, 0x62, 0x0a, 0x0e, 0x41, 0x70, 0x70, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, - 0x44, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x18, 0x0a, - 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, - 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x4b, 0x0a, 0x13, 0x41, 0x70, 0x70, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x4d, 0x73, 0x67, 0x12, 0x16, - 0x0a, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, - 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x49, 0x44, 0x22, 0x62, 0x0a, 0x0e, 0x41, 0x70, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, 0x12, 0x1c, - 0x0a, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x44, 0x12, 0x1a, 0x0a, 0x08, - 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, - 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x38, 0x0a, 0x0c, 0x41, 0x70, 0x70, 0x47, - 0x6f, 0x73, 0x73, 0x69, 0x70, 0x4d, 0x73, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, 0x64, 0x65, - 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, - 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6d, - 0x73, 0x67, 0x22, 0x2a, 0x0a, 0x10, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, 0x22, 0x2d, - 0x0a, 0x13, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, 0x22, 0xab, 0x01, - 0x0a, 0x13, 0x47, 0x65, 0x74, 0x41, 0x6e, 0x63, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x73, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x6c, 0x6b, 0x49, 0x44, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x6c, 0x6b, 0x49, 0x44, 0x12, 0x22, 0x0a, 0x0c, 0x6d, - 0x61, 0x78, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x4e, 0x75, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x05, 0x52, 0x0c, 0x6d, 0x61, 0x78, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x4e, 0x75, 0x6d, 0x12, - 0x24, 0x0a, 0x0d, 0x6d, 0x61, 0x78, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x53, 0x69, 0x7a, 0x65, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x6d, 0x61, 0x78, 0x42, 0x6c, 0x6f, 0x63, 0x6b, - 0x73, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x34, 0x0a, 0x15, 0x6d, 0x61, 0x78, 0x42, 0x6c, 0x6f, 0x63, - 0x6b, 0x73, 0x52, 0x65, 0x74, 0x72, 0x69, 0x76, 0x61, 0x6c, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x03, 0x52, 0x15, 0x6d, 0x61, 0x78, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x52, - 0x65, 0x74, 0x72, 0x69, 0x76, 0x61, 0x6c, 0x54, 0x69, 0x6d, 0x65, 0x22, 0x34, 0x0a, 0x14, 0x47, - 0x65, 0x74, 0x41, 0x6e, 0x63, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x62, 0x6c, 0x6b, 0x73, 0x42, 0x79, 0x74, 0x65, 0x73, - 0x18, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x09, 0x62, 0x6c, 0x6b, 0x73, 0x42, 0x79, 0x74, 0x65, - 0x73, 0x22, 0x34, 0x0a, 0x18, 0x42, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x50, 0x61, 0x72, 0x73, - 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, - 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x07, - 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x54, 0x0a, 0x19, 0x42, 0x61, 0x74, 0x63, 0x68, - 0x65, 0x64, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x37, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x52, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xba, 0x0c, - 0x0a, 0x02, 0x56, 0x4d, 0x12, 0x45, 0x0a, 0x0a, 0x49, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, - 0x7a, 0x65, 0x12, 0x1a, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x49, 0x6e, 0x69, - 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, - 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x49, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, - 0x69, 0x7a, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3f, 0x0a, 0x0d, 0x42, - 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x12, 0x16, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, - 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x3e, 0x0a, 0x0c, - 0x42, 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x70, 0x65, 0x64, 0x12, 0x16, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, - 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x3a, 0x0a, 0x08, - 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, - 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, - 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x49, 0x0a, 0x0e, 0x43, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, - 0x74, 0x79, 0x1a, 0x1f, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x72, 0x65, - 0x61, 0x74, 0x65, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x55, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x74, 0x61, - 0x74, 0x69, 0x63, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x12, 0x16, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, - 0x70, 0x74, 0x79, 0x1a, 0x25, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x69, 0x63, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, - 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x09, 0x43, 0x6f, - 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x12, 0x19, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2e, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x44, 0x0a, 0x0c, 0x44, 0x69, - 0x73, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x12, 0x1c, 0x2e, 0x76, 0x6d, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, - 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, - 0x12, 0x41, 0x0a, 0x0a, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x16, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x45, 0x0a, 0x0a, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x63, - 0x6b, 0x12, 0x1a, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x61, 0x72, 0x73, - 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, - 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, - 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3f, 0x0a, 0x08, 0x47, 0x65, - 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x18, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x19, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6c, - 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x46, 0x0a, 0x0d, 0x53, - 0x65, 0x74, 0x50, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1d, 0x2e, 0x76, - 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x65, 0x74, 0x50, 0x72, 0x65, 0x66, 0x65, 0x72, - 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, + 0x44, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x38, 0x0a, + 0x0c, 0x41, 0x70, 0x70, 0x47, 0x6f, 0x73, 0x73, 0x69, 0x70, 0x4d, 0x73, 0x67, 0x12, 0x16, 0x0a, + 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6e, + 0x6f, 0x64, 0x65, 0x49, 0x44, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x22, 0x2a, 0x0a, 0x10, 0x43, 0x6f, 0x6e, 0x6e, 0x65, + 0x63, 0x74, 0x65, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6e, + 0x6f, 0x64, 0x65, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6e, 0x6f, 0x64, + 0x65, 0x49, 0x44, 0x22, 0x2d, 0x0a, 0x13, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, + 0x74, 0x65, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, + 0x64, 0x65, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, + 0x49, 0x44, 0x22, 0xab, 0x01, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x41, 0x6e, 0x63, 0x65, 0x73, 0x74, + 0x6f, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x6c, + 0x6b, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x6c, 0x6b, 0x49, 0x44, + 0x12, 0x22, 0x0a, 0x0c, 0x6d, 0x61, 0x78, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x4e, 0x75, 0x6d, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0c, 0x6d, 0x61, 0x78, 0x42, 0x6c, 0x6f, 0x63, 0x6b, + 0x73, 0x4e, 0x75, 0x6d, 0x12, 0x24, 0x0a, 0x0d, 0x6d, 0x61, 0x78, 0x42, 0x6c, 0x6f, 0x63, 0x6b, + 0x73, 0x53, 0x69, 0x7a, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x6d, 0x61, 0x78, + 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x34, 0x0a, 0x15, 0x6d, 0x61, + 0x78, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x52, 0x65, 0x74, 0x72, 0x69, 0x76, 0x61, 0x6c, 0x54, + 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x15, 0x6d, 0x61, 0x78, 0x42, 0x6c, + 0x6f, 0x63, 0x6b, 0x73, 0x52, 0x65, 0x74, 0x72, 0x69, 0x76, 0x61, 0x6c, 0x54, 0x69, 0x6d, 0x65, + 0x22, 0x34, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x41, 0x6e, 0x63, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x73, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x62, 0x6c, 0x6b, 0x73, + 0x42, 0x79, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x09, 0x62, 0x6c, 0x6b, + 0x73, 0x42, 0x79, 0x74, 0x65, 0x73, 0x22, 0x34, 0x0a, 0x18, 0x42, 0x61, 0x74, 0x63, 0x68, 0x65, + 0x64, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0c, 0x52, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x54, 0x0a, 0x19, + 0x42, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x63, + 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x37, 0x0a, 0x08, 0x72, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x76, 0x6d, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x52, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x5c, 0x0a, 0x0e, 0x47, 0x61, 0x74, 0x68, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4a, 0x0a, 0x0e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x46, 0x61, + 0x6d, 0x69, 0x6c, 0x69, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x69, + 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x2e, 0x63, 0x6c, 0x69, + 0x65, 0x6e, 0x74, 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x46, 0x61, 0x6d, 0x69, 0x6c, 0x79, + 0x52, 0x0e, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x46, 0x61, 0x6d, 0x69, 0x6c, 0x69, 0x65, 0x73, + 0x32, 0xf5, 0x0c, 0x0a, 0x02, 0x56, 0x4d, 0x12, 0x45, 0x0a, 0x0a, 0x49, 0x6e, 0x69, 0x74, 0x69, + 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x12, 0x1a, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, + 0x49, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x1b, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x49, 0x6e, 0x69, 0x74, + 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3f, + 0x0a, 0x0d, 0x42, 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x12, + 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, + 0x3e, 0x0a, 0x0c, 0x42, 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x70, 0x65, 0x64, 0x12, + 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, + 0x3a, 0x0a, 0x08, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, - 0x70, 0x74, 0x79, 0x12, 0x39, 0x0a, 0x06, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x12, 0x16, 0x2e, + 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x49, 0x0a, 0x0e, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x17, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, - 0x0a, 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, - 0x79, 0x1a, 0x18, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x56, 0x65, 0x72, 0x73, - 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3c, 0x0a, 0x0a, 0x41, - 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x2e, 0x76, 0x6d, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x4d, 0x73, - 0x67, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x48, 0x0a, 0x10, 0x41, 0x70, 0x70, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x12, 0x1c, 0x2e, - 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x4d, 0x73, 0x67, 0x1a, 0x16, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, - 0x70, 0x74, 0x79, 0x12, 0x3e, 0x0a, 0x0b, 0x41, 0x70, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x17, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x70, 0x70, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x4d, 0x73, 0x67, 0x1a, 0x16, 0x2e, 0x67, 0x6f, + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1f, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x55, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x53, 0x74, 0x61, 0x74, 0x69, 0x63, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x73, 0x12, 0x16, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x25, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x69, 0x63, 0x48, 0x61, 0x6e, + 0x64, 0x6c, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, + 0x09, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x12, 0x19, 0x2e, 0x76, 0x6d, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x44, 0x0a, + 0x0c, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x12, 0x1c, 0x2e, + 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x6e, 0x6e, 0x65, + 0x63, 0x74, 0x65, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, - 0x70, 0x74, 0x79, 0x12, 0x3a, 0x0a, 0x09, 0x41, 0x70, 0x70, 0x47, 0x6f, 0x73, 0x73, 0x69, 0x70, - 0x12, 0x15, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x70, 0x70, 0x47, 0x6f, - 0x73, 0x73, 0x69, 0x70, 0x4d, 0x73, 0x67, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x70, 0x74, 0x79, 0x12, 0x41, 0x0a, 0x0a, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x42, 0x6c, 0x6f, 0x63, + 0x6b, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1b, 0x2e, 0x76, 0x6d, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x45, 0x0a, 0x0a, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x1a, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, + 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1b, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x61, 0x72, 0x73, 0x65, + 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3f, 0x0a, + 0x08, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x18, 0x2e, 0x76, 0x6d, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, + 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x46, + 0x0a, 0x0d, 0x53, 0x65, 0x74, 0x50, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x12, + 0x1d, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x65, 0x74, 0x50, 0x72, 0x65, + 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x39, 0x0a, 0x06, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, + 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x17, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x3b, 0x0a, 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, + 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x18, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x56, + 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3c, + 0x0a, 0x0a, 0x41, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x2e, 0x76, + 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x4d, 0x73, 0x67, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x48, 0x0a, 0x10, + 0x41, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, + 0x12, 0x1c, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x70, 0x70, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x4d, 0x73, 0x67, 0x1a, 0x16, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x3e, 0x0a, 0x0b, 0x41, 0x70, 0x70, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x17, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, + 0x41, 0x70, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x4d, 0x73, 0x67, 0x1a, 0x16, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x3a, 0x0a, 0x09, 0x41, 0x70, 0x70, 0x47, 0x6f, 0x73, + 0x73, 0x69, 0x70, 0x12, 0x15, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x70, + 0x70, 0x47, 0x6f, 0x73, 0x73, 0x69, 0x70, 0x4d, 0x73, 0x67, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, + 0x74, 0x79, 0x12, 0x39, 0x0a, 0x06, 0x47, 0x61, 0x74, 0x68, 0x65, 0x72, 0x12, 0x16, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, + 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x17, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, + 0x61, 0x74, 0x68, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x48, 0x0a, + 0x0b, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x12, 0x1b, 0x2e, 0x76, + 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x56, 0x65, 0x72, 0x69, + 0x66, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x76, 0x6d, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x42, 0x0a, 0x0b, 0x42, 0x6c, 0x6f, 0x63, 0x6b, + 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x12, 0x1b, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x42, 0x0a, 0x0b, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x1b, 0x2e, 0x76, 0x6d, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x6a, 0x65, 0x63, 0x74, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, - 0x48, 0x0a, 0x0b, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x12, 0x1b, - 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x56, 0x65, - 0x72, 0x69, 0x66, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x76, 0x6d, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x56, 0x65, 0x72, 0x69, 0x66, - 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x42, 0x0a, 0x0b, 0x42, 0x6c, 0x6f, - 0x63, 0x6b, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x12, 0x1b, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x42, 0x0a, - 0x0b, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x1b, 0x2e, 0x76, - 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x6a, 0x65, - 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, - 0x79, 0x12, 0x4b, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x41, 0x6e, 0x63, 0x65, 0x73, 0x74, 0x6f, 0x72, - 0x73, 0x12, 0x1c, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x41, - 0x6e, 0x63, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1d, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x6e, 0x63, - 0x65, 0x73, 0x74, 0x6f, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5a, - 0x0a, 0x11, 0x42, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, - 0x6f, 0x63, 0x6b, 0x12, 0x21, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, 0x61, - 0x74, 0x63, 0x68, 0x65, 0x64, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2e, 0x42, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, - 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x38, 0x5a, 0x36, 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, 0x76, 0x6d, - 0x73, 0x2f, 0x72, 0x70, 0x63, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x76, 0x6d, 0x2f, 0x76, 0x6d, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x4b, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x41, 0x6e, 0x63, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x73, 0x12, + 0x1c, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x6e, 0x63, + 0x65, 0x73, 0x74, 0x6f, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, + 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x6e, 0x63, 0x65, 0x73, + 0x74, 0x6f, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5a, 0x0a, 0x11, + 0x42, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x63, + 0x6b, 0x12, 0x21, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, 0x61, 0x74, 0x63, + 0x68, 0x65, 0x64, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x76, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, + 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x50, 0x61, 0x72, 0x73, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x38, 0x5a, 0x36, 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, 0x76, 0x6d, 0x73, 0x2f, + 0x72, 0x70, 0x63, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x76, 0x6d, 0x2f, 0x76, 0x6d, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -2027,7 +2064,7 @@ func file_vm_proto_rawDescGZIP() []byte { return file_vm_proto_rawDescData } -var file_vm_proto_msgTypes = make([]protoimpl.MessageInfo, 28) +var file_vm_proto_msgTypes = make([]protoimpl.MessageInfo, 29) var file_vm_proto_goTypes = []interface{}{ (*InitializeRequest)(nil), // 0: vmproto.InitializeRequest (*InitializeResponse)(nil), // 1: vmproto.InitializeResponse @@ -2057,64 +2094,69 @@ var file_vm_proto_goTypes = []interface{}{ (*GetAncestorsResponse)(nil), // 25: vmproto.GetAncestorsResponse (*BatchedParseBlockRequest)(nil), // 26: vmproto.BatchedParseBlockRequest (*BatchedParseBlockResponse)(nil), // 27: vmproto.BatchedParseBlockResponse - (*emptypb.Empty)(nil), // 28: google.protobuf.Empty + (*GatherResponse)(nil), // 28: vmproto.GatherResponse + (*_go.MetricFamily)(nil), // 29: io.prometheus.client.MetricFamily + (*emptypb.Empty)(nil), // 30: google.protobuf.Empty } var file_vm_proto_depIdxs = []int32{ 2, // 0: vmproto.InitializeRequest.dbServers:type_name -> vmproto.VersionedDBServer 5, // 1: vmproto.CreateHandlersResponse.handlers:type_name -> vmproto.Handler 5, // 2: vmproto.CreateStaticHandlersResponse.handlers:type_name -> vmproto.Handler 8, // 3: vmproto.BatchedParseBlockResponse.response:type_name -> vmproto.ParseBlockResponse - 0, // 4: vmproto.VM.Initialize:input_type -> vmproto.InitializeRequest - 28, // 5: vmproto.VM.Bootstrapping:input_type -> google.protobuf.Empty - 28, // 6: vmproto.VM.Bootstrapped:input_type -> google.protobuf.Empty - 28, // 7: vmproto.VM.Shutdown:input_type -> google.protobuf.Empty - 28, // 8: vmproto.VM.CreateHandlers:input_type -> google.protobuf.Empty - 28, // 9: vmproto.VM.CreateStaticHandlers:input_type -> google.protobuf.Empty - 22, // 10: vmproto.VM.Connected:input_type -> vmproto.ConnectedRequest - 23, // 11: vmproto.VM.Disconnected:input_type -> vmproto.DisconnectedRequest - 28, // 12: vmproto.VM.BuildBlock:input_type -> google.protobuf.Empty - 7, // 13: vmproto.VM.ParseBlock:input_type -> vmproto.ParseBlockRequest - 9, // 14: vmproto.VM.GetBlock:input_type -> vmproto.GetBlockRequest - 11, // 15: vmproto.VM.SetPreference:input_type -> vmproto.SetPreferenceRequest - 28, // 16: vmproto.VM.Health:input_type -> google.protobuf.Empty - 28, // 17: vmproto.VM.Version:input_type -> google.protobuf.Empty - 18, // 18: vmproto.VM.AppRequest:input_type -> vmproto.AppRequestMsg - 19, // 19: vmproto.VM.AppRequestFailed:input_type -> vmproto.AppRequestFailedMsg - 20, // 20: vmproto.VM.AppResponse:input_type -> vmproto.AppResponseMsg - 21, // 21: vmproto.VM.AppGossip:input_type -> vmproto.AppGossipMsg - 12, // 22: vmproto.VM.BlockVerify:input_type -> vmproto.BlockVerifyRequest - 14, // 23: vmproto.VM.BlockAccept:input_type -> vmproto.BlockAcceptRequest - 15, // 24: vmproto.VM.BlockReject:input_type -> vmproto.BlockRejectRequest - 24, // 25: vmproto.VM.GetAncestors:input_type -> vmproto.GetAncestorsRequest - 26, // 26: vmproto.VM.BatchedParseBlock:input_type -> vmproto.BatchedParseBlockRequest - 1, // 27: vmproto.VM.Initialize:output_type -> vmproto.InitializeResponse - 28, // 28: vmproto.VM.Bootstrapping:output_type -> google.protobuf.Empty - 28, // 29: vmproto.VM.Bootstrapped:output_type -> google.protobuf.Empty - 28, // 30: vmproto.VM.Shutdown:output_type -> google.protobuf.Empty - 3, // 31: vmproto.VM.CreateHandlers:output_type -> vmproto.CreateHandlersResponse - 4, // 32: vmproto.VM.CreateStaticHandlers:output_type -> vmproto.CreateStaticHandlersResponse - 28, // 33: vmproto.VM.Connected:output_type -> google.protobuf.Empty - 28, // 34: vmproto.VM.Disconnected:output_type -> google.protobuf.Empty - 6, // 35: vmproto.VM.BuildBlock:output_type -> vmproto.BuildBlockResponse - 8, // 36: vmproto.VM.ParseBlock:output_type -> vmproto.ParseBlockResponse - 10, // 37: vmproto.VM.GetBlock:output_type -> vmproto.GetBlockResponse - 28, // 38: vmproto.VM.SetPreference:output_type -> google.protobuf.Empty - 16, // 39: vmproto.VM.Health:output_type -> vmproto.HealthResponse - 17, // 40: vmproto.VM.Version:output_type -> vmproto.VersionResponse - 28, // 41: vmproto.VM.AppRequest:output_type -> google.protobuf.Empty - 28, // 42: vmproto.VM.AppRequestFailed:output_type -> google.protobuf.Empty - 28, // 43: vmproto.VM.AppResponse:output_type -> google.protobuf.Empty - 28, // 44: vmproto.VM.AppGossip:output_type -> google.protobuf.Empty - 13, // 45: vmproto.VM.BlockVerify:output_type -> vmproto.BlockVerifyResponse - 28, // 46: vmproto.VM.BlockAccept:output_type -> google.protobuf.Empty - 28, // 47: vmproto.VM.BlockReject:output_type -> google.protobuf.Empty - 25, // 48: vmproto.VM.GetAncestors:output_type -> vmproto.GetAncestorsResponse - 27, // 49: vmproto.VM.BatchedParseBlock:output_type -> vmproto.BatchedParseBlockResponse - 27, // [27:50] is the sub-list for method output_type - 4, // [4:27] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name + 29, // 4: vmproto.GatherResponse.metricFamilies:type_name -> io.prometheus.client.MetricFamily + 0, // 5: vmproto.VM.Initialize:input_type -> vmproto.InitializeRequest + 30, // 6: vmproto.VM.Bootstrapping:input_type -> google.protobuf.Empty + 30, // 7: vmproto.VM.Bootstrapped:input_type -> google.protobuf.Empty + 30, // 8: vmproto.VM.Shutdown:input_type -> google.protobuf.Empty + 30, // 9: vmproto.VM.CreateHandlers:input_type -> google.protobuf.Empty + 30, // 10: vmproto.VM.CreateStaticHandlers:input_type -> google.protobuf.Empty + 22, // 11: vmproto.VM.Connected:input_type -> vmproto.ConnectedRequest + 23, // 12: vmproto.VM.Disconnected:input_type -> vmproto.DisconnectedRequest + 30, // 13: vmproto.VM.BuildBlock:input_type -> google.protobuf.Empty + 7, // 14: vmproto.VM.ParseBlock:input_type -> vmproto.ParseBlockRequest + 9, // 15: vmproto.VM.GetBlock:input_type -> vmproto.GetBlockRequest + 11, // 16: vmproto.VM.SetPreference:input_type -> vmproto.SetPreferenceRequest + 30, // 17: vmproto.VM.Health:input_type -> google.protobuf.Empty + 30, // 18: vmproto.VM.Version:input_type -> google.protobuf.Empty + 18, // 19: vmproto.VM.AppRequest:input_type -> vmproto.AppRequestMsg + 19, // 20: vmproto.VM.AppRequestFailed:input_type -> vmproto.AppRequestFailedMsg + 20, // 21: vmproto.VM.AppResponse:input_type -> vmproto.AppResponseMsg + 21, // 22: vmproto.VM.AppGossip:input_type -> vmproto.AppGossipMsg + 30, // 23: vmproto.VM.Gather:input_type -> google.protobuf.Empty + 12, // 24: vmproto.VM.BlockVerify:input_type -> vmproto.BlockVerifyRequest + 14, // 25: vmproto.VM.BlockAccept:input_type -> vmproto.BlockAcceptRequest + 15, // 26: vmproto.VM.BlockReject:input_type -> vmproto.BlockRejectRequest + 24, // 27: vmproto.VM.GetAncestors:input_type -> vmproto.GetAncestorsRequest + 26, // 28: vmproto.VM.BatchedParseBlock:input_type -> vmproto.BatchedParseBlockRequest + 1, // 29: vmproto.VM.Initialize:output_type -> vmproto.InitializeResponse + 30, // 30: vmproto.VM.Bootstrapping:output_type -> google.protobuf.Empty + 30, // 31: vmproto.VM.Bootstrapped:output_type -> google.protobuf.Empty + 30, // 32: vmproto.VM.Shutdown:output_type -> google.protobuf.Empty + 3, // 33: vmproto.VM.CreateHandlers:output_type -> vmproto.CreateHandlersResponse + 4, // 34: vmproto.VM.CreateStaticHandlers:output_type -> vmproto.CreateStaticHandlersResponse + 30, // 35: vmproto.VM.Connected:output_type -> google.protobuf.Empty + 30, // 36: vmproto.VM.Disconnected:output_type -> google.protobuf.Empty + 6, // 37: vmproto.VM.BuildBlock:output_type -> vmproto.BuildBlockResponse + 8, // 38: vmproto.VM.ParseBlock:output_type -> vmproto.ParseBlockResponse + 10, // 39: vmproto.VM.GetBlock:output_type -> vmproto.GetBlockResponse + 30, // 40: vmproto.VM.SetPreference:output_type -> google.protobuf.Empty + 16, // 41: vmproto.VM.Health:output_type -> vmproto.HealthResponse + 17, // 42: vmproto.VM.Version:output_type -> vmproto.VersionResponse + 30, // 43: vmproto.VM.AppRequest:output_type -> google.protobuf.Empty + 30, // 44: vmproto.VM.AppRequestFailed:output_type -> google.protobuf.Empty + 30, // 45: vmproto.VM.AppResponse:output_type -> google.protobuf.Empty + 30, // 46: vmproto.VM.AppGossip:output_type -> google.protobuf.Empty + 28, // 47: vmproto.VM.Gather:output_type -> vmproto.GatherResponse + 13, // 48: vmproto.VM.BlockVerify:output_type -> vmproto.BlockVerifyResponse + 30, // 49: vmproto.VM.BlockAccept:output_type -> google.protobuf.Empty + 30, // 50: vmproto.VM.BlockReject:output_type -> google.protobuf.Empty + 25, // 51: vmproto.VM.GetAncestors:output_type -> vmproto.GetAncestorsResponse + 27, // 52: vmproto.VM.BatchedParseBlock:output_type -> vmproto.BatchedParseBlockResponse + 29, // [29:53] is the sub-list for method output_type + 5, // [5:29] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name } func init() { file_vm_proto_init() } @@ -2459,6 +2501,18 @@ func file_vm_proto_init() { return nil } } + file_vm_proto_msgTypes[28].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GatherResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -2466,7 +2520,7 @@ func file_vm_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_vm_proto_rawDesc, NumEnums: 0, - NumMessages: 28, + NumMessages: 29, NumExtensions: 0, NumServices: 1, }, diff --git a/vms/rpcchainvm/vmproto/vm.proto b/vms/rpcchainvm/vmproto/vm.proto index 7721ad9e926d..632e1a16a06a 100644 --- a/vms/rpcchainvm/vmproto/vm.proto +++ b/vms/rpcchainvm/vmproto/vm.proto @@ -3,8 +3,18 @@ package vmproto; option go_package = "github.com/ava-labs/avalanchego/vms/rpcchainvm/vmproto"; import "google/protobuf/empty.proto"; +// import from https://github.com/prometheus/client_model/blob/master/io/prometheus/client/metrics.proto +// requires "github.com/prometheus/client_model" for reuse in Go code +// requires "io/prometheus/client/metrics.proto" file in "protoc --proto_path" commands +// +// if vended after https://github.com/prometheus/client_model/commit/147c58e9608a4f9628b53b6cc863325ca746f63a +// import "io/prometheus/client/metrics.proto"; + +// for older vendored prometheus +import "metrics.proto"; // To compile: protoc --go_out=plugins=grpc:. vm.proto +// Or run "scripts/protobuf_codegen.sh" message InitializeRequest { uint32 networkID = 1; @@ -24,10 +34,6 @@ message InitializeRequest { uint32 bcLookupServer = 14; uint32 snLookupServer = 15; uint32 appSenderServer = 16; - - bytes epochFirstTransition = 17; - uint64 EpochDuration = 18; - } message InitializeResponse { @@ -180,6 +186,9 @@ message BatchedParseBlockResponse { repeated ParseBlockResponse response = 1; } +message GatherResponse { + repeated io.prometheus.client.MetricFamily metricFamilies = 1; +} service VM { rpc Initialize(InitializeRequest) returns (InitializeResponse); @@ -201,6 +210,8 @@ service VM { rpc AppResponse(AppResponseMsg) returns (google.protobuf.Empty); rpc AppGossip(AppGossipMsg) returns (google.protobuf.Empty); + rpc Gather(google.protobuf.Empty) returns (GatherResponse); + rpc BlockVerify(BlockVerifyRequest) returns (BlockVerifyResponse); rpc BlockAccept(BlockAcceptRequest) returns (google.protobuf.Empty); rpc BlockReject(BlockRejectRequest) returns (google.protobuf.Empty); diff --git a/vms/rpcchainvm/vmproto/vm_grpc.pb.go b/vms/rpcchainvm/vmproto/vm_grpc.pb.go index 45a52eafa8c8..4c535fa0f084 100644 --- a/vms/rpcchainvm/vmproto/vm_grpc.pb.go +++ b/vms/rpcchainvm/vmproto/vm_grpc.pb.go @@ -37,6 +37,7 @@ type VMClient interface { AppRequestFailed(ctx context.Context, in *AppRequestFailedMsg, opts ...grpc.CallOption) (*emptypb.Empty, error) AppResponse(ctx context.Context, in *AppResponseMsg, opts ...grpc.CallOption) (*emptypb.Empty, error) AppGossip(ctx context.Context, in *AppGossipMsg, opts ...grpc.CallOption) (*emptypb.Empty, error) + Gather(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GatherResponse, error) BlockVerify(ctx context.Context, in *BlockVerifyRequest, opts ...grpc.CallOption) (*BlockVerifyResponse, error) BlockAccept(ctx context.Context, in *BlockAcceptRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) BlockReject(ctx context.Context, in *BlockRejectRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) @@ -214,6 +215,15 @@ func (c *vMClient) AppGossip(ctx context.Context, in *AppGossipMsg, opts ...grpc return out, nil } +func (c *vMClient) Gather(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GatherResponse, error) { + out := new(GatherResponse) + err := c.cc.Invoke(ctx, "/vmproto.VM/Gather", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *vMClient) BlockVerify(ctx context.Context, in *BlockVerifyRequest, opts ...grpc.CallOption) (*BlockVerifyResponse, error) { out := new(BlockVerifyResponse) err := c.cc.Invoke(ctx, "/vmproto.VM/BlockVerify", in, out, opts...) @@ -281,6 +291,7 @@ type VMServer interface { AppRequestFailed(context.Context, *AppRequestFailedMsg) (*emptypb.Empty, error) AppResponse(context.Context, *AppResponseMsg) (*emptypb.Empty, error) AppGossip(context.Context, *AppGossipMsg) (*emptypb.Empty, error) + Gather(context.Context, *emptypb.Empty) (*GatherResponse, error) BlockVerify(context.Context, *BlockVerifyRequest) (*BlockVerifyResponse, error) BlockAccept(context.Context, *BlockAcceptRequest) (*emptypb.Empty, error) BlockReject(context.Context, *BlockRejectRequest) (*emptypb.Empty, error) @@ -347,6 +358,9 @@ func (UnimplementedVMServer) AppResponse(context.Context, *AppResponseMsg) (*emp func (UnimplementedVMServer) AppGossip(context.Context, *AppGossipMsg) (*emptypb.Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method AppGossip not implemented") } +func (UnimplementedVMServer) Gather(context.Context, *emptypb.Empty) (*GatherResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Gather not implemented") +} func (UnimplementedVMServer) BlockVerify(context.Context, *BlockVerifyRequest) (*BlockVerifyResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method BlockVerify not implemented") } @@ -699,6 +713,24 @@ func _VM_AppGossip_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } +func _VM_Gather_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(emptypb.Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VMServer).Gather(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/vmproto.VM/Gather", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VMServer).Gather(ctx, req.(*emptypb.Empty)) + } + return interceptor(ctx, in, info, handler) +} + func _VM_BlockVerify_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(BlockVerifyRequest) if err := dec(in); err != nil { @@ -868,6 +900,10 @@ var VM_ServiceDesc = grpc.ServiceDesc{ MethodName: "AppGossip", Handler: _VM_AppGossip_Handler, }, + { + MethodName: "Gather", + Handler: _VM_Gather_Handler, + }, { MethodName: "BlockVerify", Handler: _VM_BlockVerify_Handler, diff --git a/vms/secp256k1fx/credential.go b/vms/secp256k1fx/credential.go index ded26d24b6e6..cf6ff091bab7 100644 --- a/vms/secp256k1fx/credential.go +++ b/vms/secp256k1fx/credential.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/credential_test.go b/vms/secp256k1fx/credential_test.go index 06637250b33b..fe2ac827f99c 100644 --- a/vms/secp256k1fx/credential_test.go +++ b/vms/secp256k1fx/credential_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/factory.go b/vms/secp256k1fx/factory.go index 80c8cf5e9e7c..512146ad885d 100644 --- a/vms/secp256k1fx/factory.go +++ b/vms/secp256k1fx/factory.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/factory_test.go b/vms/secp256k1fx/factory_test.go index 0fadef89456c..8927b092af69 100644 --- a/vms/secp256k1fx/factory_test.go +++ b/vms/secp256k1fx/factory_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/fx.go b/vms/secp256k1fx/fx.go index 2b87b7ba8a3a..5747da9544f3 100644 --- a/vms/secp256k1fx/fx.go +++ b/vms/secp256k1fx/fx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/fx_test.go b/vms/secp256k1fx/fx_test.go index 25f38289fe36..2c7ebea625b7 100644 --- a/vms/secp256k1fx/fx_test.go +++ b/vms/secp256k1fx/fx_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/input.go b/vms/secp256k1fx/input.go index 68794dc9c486..d229554b3415 100644 --- a/vms/secp256k1fx/input.go +++ b/vms/secp256k1fx/input.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/input_test.go b/vms/secp256k1fx/input_test.go index 775f553d8a30..47cd13d3e4ad 100644 --- a/vms/secp256k1fx/input_test.go +++ b/vms/secp256k1fx/input_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/keychain.go b/vms/secp256k1fx/keychain.go index 821abd5341a4..ecfb50c922f8 100644 --- a/vms/secp256k1fx/keychain.go +++ b/vms/secp256k1fx/keychain.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx @@ -26,12 +26,17 @@ type Keychain struct { Keys []*crypto.PrivateKeySECP256K1R } -// NewKeychain returns a new, empty, keychain -func NewKeychain() *Keychain { - return &Keychain{ +// NewKeychain returns a new keychain containing [keys] +func NewKeychain(keys ...*crypto.PrivateKeySECP256K1R) *Keychain { + kc := &Keychain{ factory: &crypto.FactorySECP256K1R{}, addrToKeyIndex: make(map[ids.ShortID]int), } + for _, key := range keys { + kc.Add(key) + } + + return kc } // Add a new key to the key chain diff --git a/vms/secp256k1fx/keychain_test.go b/vms/secp256k1fx/keychain_test.go index e35fb8e79318..4c823a90664e 100644 --- a/vms/secp256k1fx/keychain_test.go +++ b/vms/secp256k1fx/keychain_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/mint_operation.go b/vms/secp256k1fx/mint_operation.go index 4dbb0f984895..748de3a3e34c 100644 --- a/vms/secp256k1fx/mint_operation.go +++ b/vms/secp256k1fx/mint_operation.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/mint_operation_test.go b/vms/secp256k1fx/mint_operation_test.go index f3053572adeb..126ff31f807b 100644 --- a/vms/secp256k1fx/mint_operation_test.go +++ b/vms/secp256k1fx/mint_operation_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/mint_output.go b/vms/secp256k1fx/mint_output.go index 6e3405489806..c3544d95e822 100644 --- a/vms/secp256k1fx/mint_output.go +++ b/vms/secp256k1fx/mint_output.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/mint_output_test.go b/vms/secp256k1fx/mint_output_test.go index 3764e813e60e..0acbca346f42 100644 --- a/vms/secp256k1fx/mint_output_test.go +++ b/vms/secp256k1fx/mint_output_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/output_owners.go b/vms/secp256k1fx/output_owners.go index c7e1c5f3e3ce..af43d83af509 100644 --- a/vms/secp256k1fx/output_owners.go +++ b/vms/secp256k1fx/output_owners.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/output_owners_test.go b/vms/secp256k1fx/output_owners_test.go index 212dc14e49ec..a12323557091 100644 --- a/vms/secp256k1fx/output_owners_test.go +++ b/vms/secp256k1fx/output_owners_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/transfer_input.go b/vms/secp256k1fx/transfer_input.go index d2a586df9d61..5071c47cc30e 100644 --- a/vms/secp256k1fx/transfer_input.go +++ b/vms/secp256k1fx/transfer_input.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/transfer_input_test.go b/vms/secp256k1fx/transfer_input_test.go index 64edb2793ce0..fc620356290e 100644 --- a/vms/secp256k1fx/transfer_input_test.go +++ b/vms/secp256k1fx/transfer_input_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/transfer_output.go b/vms/secp256k1fx/transfer_output.go index 303baf43d4a9..f15305b18e71 100644 --- a/vms/secp256k1fx/transfer_output.go +++ b/vms/secp256k1fx/transfer_output.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/transfer_output_test.go b/vms/secp256k1fx/transfer_output_test.go index 3714cede49cc..20db96e0a1b9 100644 --- a/vms/secp256k1fx/transfer_output_test.go +++ b/vms/secp256k1fx/transfer_output_test.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/tx.go b/vms/secp256k1fx/tx.go index 32e4adb34f4f..6850c9bb4c62 100644 --- a/vms/secp256k1fx/tx.go +++ b/vms/secp256k1fx/tx.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/secp256k1fx/vm.go b/vms/secp256k1fx/vm.go index 94713c5f9a21..3d160a882da1 100644 --- a/vms/secp256k1fx/vm.go +++ b/vms/secp256k1fx/vm.go @@ -1,4 +1,4 @@ -// (c) 2019-2020, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package secp256k1fx diff --git a/vms/types/blob_data.go b/vms/types/blob_data.go index 57311f441900..b2c8adc51265 100644 --- a/vms/types/blob_data.go +++ b/vms/types/blob_data.go @@ -1,4 +1,4 @@ -// (c) 2021, Ava Labs, Inc. All rights reserved. +// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package types