Skip to content

Commit 7ea7d67

Browse files
committed
Upgrade to Avalanche 1.9.0 - added missing files
1 parent f9ea756 commit 7ea7d67

File tree

318 files changed

+53069
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

318 files changed

+53069
-0
lines changed

avalanchego/SECURITY.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Security Policy
2+
3+
Avalanche takes the security of the platform and of its users very seriously. We and our community recognize the critical role of external security researchers and developers and welcome responsible disclosures. Valid reports will be eligible for a reward (terms and conditions apply).
4+
5+
## Reporting a Vulnerability
6+
7+
**Please do not file a public ticket** mentioning the vulnerability. To disclose a vulnerability submit it through our [Bug Bounty Program](https://hackenproof.com/avalanche).
8+
9+
Vulnerabilities must be disclosed to us privately with reasonable time to respond, and avoid compromise of other users and accounts, or loss of funds that are not your own. We do not reward spam or social engineering vulnerabilities.
10+
11+
Do not test for or validate any security issues in the live Avalanche networks (Mainnet and Fuji testnet), confirm all exploits in a local private testnet.
12+
13+
Please refer to the [Bug Bounty Page](https://hackenproof.com/avalanche) for the most up-to-date program rules and scope.
14+
15+
## Supported Versions
16+
17+
Please use the [most recently released version](https://github.com/ava-labs/avalanchego/releases/latest) to perform testing and to validate security issues.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package info
5+
6+
import (
7+
"context"
8+
"testing"
9+
"time"
10+
11+
"github.com/stretchr/testify/require"
12+
13+
"github.com/ava-labs/avalanchego/utils/rpc"
14+
)
15+
16+
type mockClient struct {
17+
reply IsBootstrappedResponse
18+
err error
19+
onCall func()
20+
}
21+
22+
func (mc *mockClient) SendRequest(_ context.Context, _ string, _ interface{}, replyIntf interface{}, _ ...rpc.Option) error {
23+
reply := replyIntf.(*IsBootstrappedResponse)
24+
*reply = mc.reply
25+
mc.onCall()
26+
return mc.err
27+
}
28+
29+
func TestNewClient(t *testing.T) {
30+
require := require.New(t)
31+
32+
c := NewClient("")
33+
require.NotNil(c)
34+
}
35+
36+
func TestClient(t *testing.T) {
37+
require := require.New(t)
38+
39+
mc := &mockClient{
40+
reply: IsBootstrappedResponse{true},
41+
err: nil,
42+
onCall: func() {},
43+
}
44+
c := &client{
45+
requester: mc,
46+
}
47+
48+
{
49+
bootstrapped, err := c.IsBootstrapped(context.Background(), "X")
50+
require.NoError(err)
51+
require.True(bootstrapped)
52+
}
53+
54+
mc.reply.IsBootstrapped = false
55+
56+
{
57+
bootstrapped, err := c.IsBootstrapped(context.Background(), "X")
58+
require.NoError(err)
59+
require.False(bootstrapped)
60+
}
61+
62+
mc.onCall = func() {
63+
mc.reply.IsBootstrapped = true
64+
}
65+
66+
{
67+
bootstrapped, err := AwaitBootstrapped(context.Background(), c, "X", time.Microsecond)
68+
require.NoError(err)
69+
require.True(bootstrapped)
70+
}
71+
}

avalanchego/api/server/metrics.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package server
5+
6+
import (
7+
"net/http"
8+
"time"
9+
10+
"github.com/prometheus/client_golang/prometheus"
11+
12+
"github.com/ava-labs/avalanchego/utils/wrappers"
13+
)
14+
15+
type metrics struct {
16+
numProcessing *prometheus.GaugeVec
17+
numCalls *prometheus.CounterVec
18+
totalDuration *prometheus.GaugeVec
19+
}
20+
21+
func newMetrics(namespace string, registerer prometheus.Registerer) (*metrics, error) {
22+
m := &metrics{
23+
numProcessing: prometheus.NewGaugeVec(
24+
prometheus.GaugeOpts{
25+
Namespace: namespace,
26+
Name: "calls_processing",
27+
Help: "The number of calls this API is currently processing",
28+
},
29+
[]string{"base"},
30+
),
31+
numCalls: prometheus.NewCounterVec(
32+
prometheus.CounterOpts{
33+
Namespace: namespace,
34+
Name: "calls",
35+
Help: "The number of calls this API has processed",
36+
},
37+
[]string{"base"},
38+
),
39+
totalDuration: prometheus.NewGaugeVec(
40+
prometheus.GaugeOpts{
41+
Namespace: namespace,
42+
Name: "calls_duration",
43+
Help: "The total amount of time, in nanoseconds, spent handling API calls",
44+
},
45+
[]string{"base"},
46+
),
47+
}
48+
49+
errs := wrappers.Errs{}
50+
errs.Add(
51+
registerer.Register(m.numProcessing),
52+
registerer.Register(m.numCalls),
53+
registerer.Register(m.totalDuration),
54+
)
55+
return m, errs.Err
56+
}
57+
58+
func (m *metrics) wrapHandler(chainName string, handler http.Handler) http.Handler {
59+
numProcessing := m.numProcessing.WithLabelValues(chainName)
60+
numCalls := m.numCalls.WithLabelValues(chainName)
61+
totalDuration := m.totalDuration.WithLabelValues(chainName)
62+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
63+
startTime := time.Now()
64+
numProcessing.Inc()
65+
66+
defer func() {
67+
numProcessing.Dec()
68+
numCalls.Inc()
69+
totalDuration.Add(float64(time.Since(startTime)))
70+
}()
71+
72+
handler.ServeHTTP(w, r)
73+
})
74+
}

avalanchego/api/traced_handler.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package api
5+
6+
import (
7+
"fmt"
8+
"net/http"
9+
10+
"go.opentelemetry.io/otel/attribute"
11+
12+
oteltrace "go.opentelemetry.io/otel/trace"
13+
14+
"github.com/ava-labs/avalanchego/trace"
15+
)
16+
17+
var _ http.Handler = (*tracedHandler)(nil)
18+
19+
type tracedHandler struct {
20+
h http.Handler
21+
serveHTTPTag string
22+
tracer trace.Tracer
23+
}
24+
25+
func TraceHandler(h http.Handler, name string, tracer trace.Tracer) http.Handler {
26+
return &tracedHandler{
27+
h: h,
28+
serveHTTPTag: fmt.Sprintf("%s.ServeHTTP", name),
29+
tracer: tracer,
30+
}
31+
}
32+
33+
func (h *tracedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
34+
ctx := r.Context()
35+
ctx, span := h.tracer.Start(ctx, h.serveHTTPTag, oteltrace.WithAttributes(
36+
attribute.String("method", r.Method),
37+
attribute.String("url", r.URL.Redacted()),
38+
attribute.String("proto", r.Proto),
39+
attribute.String("host", r.Host),
40+
attribute.String("remoteAddr", r.RemoteAddr),
41+
attribute.String("requestURI", r.RequestURI),
42+
))
43+
defer span.End()
44+
45+
r = r.WithContext(ctx)
46+
h.h.ServeHTTP(w, r)
47+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package chains
5+
6+
import (
7+
"context"
8+
9+
"github.com/ava-labs/avalanchego/api/metrics"
10+
"github.com/ava-labs/avalanchego/ids"
11+
"github.com/ava-labs/avalanchego/snow"
12+
"github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex"
13+
"github.com/ava-labs/avalanchego/snow/engine/common"
14+
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
15+
16+
dbManager "github.com/ava-labs/avalanchego/database/manager"
17+
)
18+
19+
var (
20+
_ vertex.LinearizableVM = (*initializeOnLinearizeVM)(nil)
21+
_ block.ChainVM = (*linearizeOnInitializeVM)(nil)
22+
)
23+
24+
// initializeOnLinearizeVM transforms the consensus engine's call to Linearize
25+
// into a call to Initialize. This enables the proposervm to be initialized by
26+
// the call to Linearize. This also provides the stopVertexID to the
27+
// linearizeOnInitializeVM.
28+
type initializeOnLinearizeVM struct {
29+
vertex.DAGVM
30+
vmToInitialize common.VM
31+
vmToLinearize *linearizeOnInitializeVM
32+
33+
registerer metrics.OptionalGatherer
34+
ctx *snow.Context
35+
dbManager dbManager.Manager
36+
genesisBytes []byte
37+
upgradeBytes []byte
38+
configBytes []byte
39+
toEngine chan<- common.Message
40+
fxs []*common.Fx
41+
appSender common.AppSender
42+
}
43+
44+
func (vm *initializeOnLinearizeVM) Linearize(ctx context.Context, stopVertexID ids.ID) error {
45+
vm.vmToLinearize.stopVertexID = stopVertexID
46+
vm.ctx.Metrics = vm.registerer
47+
return vm.vmToInitialize.Initialize(
48+
ctx,
49+
vm.ctx,
50+
vm.dbManager,
51+
vm.genesisBytes,
52+
vm.upgradeBytes,
53+
vm.configBytes,
54+
vm.toEngine,
55+
vm.fxs,
56+
vm.appSender,
57+
)
58+
}
59+
60+
// linearizeOnInitializeVM transforms the proposervm's call to Initialize into a
61+
// call to Linearize. This enables the proposervm to provide its toEngine
62+
// channel to the VM that is being linearized.
63+
type linearizeOnInitializeVM struct {
64+
vertex.LinearizableVMWithEngine
65+
stopVertexID ids.ID
66+
}
67+
68+
func (vm *linearizeOnInitializeVM) Initialize(
69+
ctx context.Context,
70+
_ *snow.Context,
71+
_ dbManager.Manager,
72+
_ []byte,
73+
_ []byte,
74+
_ []byte,
75+
toEngine chan<- common.Message,
76+
_ []*common.Fx,
77+
_ common.AppSender,
78+
) error {
79+
return vm.Linearize(ctx, vm.stopVertexID, toEngine)
80+
}

avalanchego/chains/test_manager.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package chains
5+
6+
import (
7+
"github.com/ava-labs/avalanchego/ids"
8+
"github.com/ava-labs/avalanchego/snow/networking/router"
9+
)
10+
11+
// TestManager implements Manager but does nothing. Always returns nil error.
12+
// To be used only in tests
13+
var TestManager Manager = testManager{}
14+
15+
type testManager struct{}
16+
17+
func (testManager) Router() router.Router {
18+
return nil
19+
}
20+
21+
func (testManager) QueueChainCreation(ChainParameters) {}
22+
23+
func (testManager) ForceCreateChain(ChainParameters) {}
24+
25+
func (testManager) AddRegistrant(Registrant) {}
26+
27+
func (testManager) Aliases(ids.ID) ([]string, error) {
28+
return nil, nil
29+
}
30+
31+
func (testManager) PrimaryAlias(ids.ID) (string, error) {
32+
return "", nil
33+
}
34+
35+
func (testManager) PrimaryAliasOrDefault(ids.ID) string {
36+
return ""
37+
}
38+
39+
func (testManager) Alias(ids.ID, string) error {
40+
return nil
41+
}
42+
43+
func (testManager) RemoveAliases(ids.ID) {}
44+
45+
func (testManager) Shutdown() {}
46+
47+
func (testManager) StartChainCreator(ChainParameters) error {
48+
return nil
49+
}
50+
51+
func (testManager) SubnetID(ids.ID) (ids.ID, error) {
52+
return ids.ID{}, nil
53+
}
54+
55+
func (testManager) IsBootstrapped(ids.ID) bool {
56+
return false
57+
}
58+
59+
func (testManager) Lookup(s string) (ids.ID, error) {
60+
return ids.FromString(s)
61+
}
62+
63+
func (testManager) LookupVM(s string) (ids.ID, error) {
64+
return ids.FromString(s)
65+
}

0 commit comments

Comments
 (0)