Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into merkledb-dynamic-root
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Laine committed Nov 1, 2023
2 parents 7e7c7b9 + 4957ccb commit eb157fd
Show file tree
Hide file tree
Showing 196 changed files with 4,750 additions and 2,628 deletions.
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ linters:
- nakedret
- noctx
- nolintlint
- perfsprint
- prealloc
- revive
- staticcheck
- stylecheck
- typecheck
- tagalign
- typecheck
- unconvert
- unparam
- unused
Expand Down
51 changes: 51 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
# Release Notes

## [v1.10.14](https://github.com/ava-labs/avalanchego/releases/tag/v1.10.14)

This version is backwards compatible to [v1.10.0](https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0). It is optional, but encouraged.

The plugin version is unchanged at `29` and compatible with version `v1.10.13`.

### Configs

- Deprecated `--api-ipcs-enabled`
- Deprecated `--ipcs-chain-ids`
- Deprecated `--ipcs-path`
- Deprecated `--api-keystore-enabled`

### Fixes

- Fixed shutdown of timeout manager
- Fixed racy access of the shutdown time

### What's Changed

- Remove build check from unit tests by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2189
- Update cgo usage by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2184
- Deprecate IPC configs by @danlaine in https://github.com/ava-labs/avalanchego/pull/2168
- Update P2P proto docs by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2181
- Merkle db Make Paths only refer to lists of nodes by @dboehm-avalabs in https://github.com/ava-labs/avalanchego/pull/2143
- Deprecate keystore config by @danlaine in https://github.com/ava-labs/avalanchego/pull/2195
- Add tests for BanffBlock serialization by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2194
- Move Shutdown lock from Handler into Engines by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2179
- Move HealthCheck lock from Handler into Engines by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2173
- Implement Heap Map by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2137
- Move selectStartGear lock from Handler into Engines by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2182
- Add Heap Set by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2136
- Shutdown TimeoutManager during node Shutdown by @abi87 in https://github.com/ava-labs/avalanchego/pull/1707
- Redesign validator set management to enable tracking all subnets by @ceyonur in https://github.com/ava-labs/avalanchego/pull/1857
- Update local network readme by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2203
- Use custom codec for validator metadata by @abi87 in https://github.com/ava-labs/avalanchego/pull/1510
- Add RSA max key length test by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2205
- Remove duplicate networking check by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2204
- Update TestDialContext to use ManuallyTrack by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2209
- Remove contains from validator manager interface by @ceyonur in https://github.com/ava-labs/avalanchego/pull/2198
- Move the overridden manager into the node by @ceyonur in https://github.com/ava-labs/avalanchego/pull/2199
- Remove `aggregate` struct by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2213
- Add log for ungraceful shutdown on startup by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2215
- Add pebble database implementation by @danlaine in https://github.com/ava-labs/avalanchego/pull/1999
- Add `TransferSubnetOwnershipTx` by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2178
- Revert networking AllowConnection change by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2219
- Fix unexpected unlock by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2221
- Improve logging for block verification failure by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2224

**Full Changelog**: https://github.com/ava-labs/avalanchego/compare/v1.10.13...v1.10.14

## [v1.10.13](https://github.com/ava-labs/avalanchego/releases/tag/v1.10.13)

This version is backwards compatible to [v1.10.0](https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0). It is optional, but encouraged.
Expand Down
29 changes: 15 additions & 14 deletions api/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
hashedPassword = password.Hash{}
unAuthorizedResponseRegex = `^{"jsonrpc":"2.0","error":{"code":-32600,"message":"(.*)"},"id":1}`
errTest = errors.New("non-nil error")
hostName = "http://127.0.0.1:9650"
)

func init() {
Expand Down Expand Up @@ -161,8 +162,8 @@ func TestWrapHandlerHappyPath(t *testing.T) {
wrappedHandler := auth.WrapHandler(dummyHandler)

for _, endpoint := range endpoints {
req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader(""))
req.Header.Add("Authorization", "Bearer "+tokenStr)
req := httptest.NewRequest(http.MethodPost, hostName+endpoint, strings.NewReader(""))
req.Header.Add("Authorization", headerValStart+tokenStr)
rr := httptest.NewRecorder()
wrappedHandler.ServeHTTP(rr, req)
require.Equal(http.StatusOK, rr.Code)
Expand All @@ -184,8 +185,8 @@ func TestWrapHandlerRevokedToken(t *testing.T) {
wrappedHandler := auth.WrapHandler(dummyHandler)

for _, endpoint := range endpoints {
req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader(""))
req.Header.Add("Authorization", "Bearer "+tokenStr)
req := httptest.NewRequest(http.MethodPost, hostName+endpoint, strings.NewReader(""))
req.Header.Add("Authorization", headerValStart+tokenStr)
rr := httptest.NewRecorder()
wrappedHandler.ServeHTTP(rr, req)
require.Equal(http.StatusUnauthorized, rr.Code)
Expand All @@ -209,8 +210,8 @@ func TestWrapHandlerExpiredToken(t *testing.T) {
wrappedHandler := auth.WrapHandler(dummyHandler)

for _, endpoint := range endpoints {
req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader(""))
req.Header.Add("Authorization", "Bearer "+tokenStr)
req := httptest.NewRequest(http.MethodPost, hostName+endpoint, strings.NewReader(""))
req.Header.Add("Authorization", headerValStart+tokenStr)
rr := httptest.NewRecorder()
wrappedHandler.ServeHTTP(rr, req)
require.Equal(http.StatusUnauthorized, rr.Code)
Expand Down Expand Up @@ -250,8 +251,8 @@ func TestWrapHandlerUnauthorizedEndpoint(t *testing.T) {

wrappedHandler := auth.WrapHandler(dummyHandler)
for _, endpoint := range unauthorizedEndpoints {
req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader(""))
req.Header.Add("Authorization", "Bearer "+tokenStr)
req := httptest.NewRequest(http.MethodPost, hostName+endpoint, strings.NewReader(""))
req.Header.Add("Authorization", headerValStart+tokenStr)
rr := httptest.NewRecorder()
wrappedHandler.ServeHTTP(rr, req)
require.Equal(http.StatusUnauthorized, rr.Code)
Expand All @@ -272,7 +273,7 @@ func TestWrapHandlerAuthEndpoint(t *testing.T) {

wrappedHandler := auth.WrapHandler(dummyHandler)
req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650/ext/auth", strings.NewReader(""))
req.Header.Add("Authorization", "Bearer "+tokenStr)
req.Header.Add("Authorization", headerValStart+tokenStr)
rr := httptest.NewRecorder()
wrappedHandler.ServeHTTP(rr, req)
require.Equal(http.StatusOK, rr.Code)
Expand All @@ -290,8 +291,8 @@ func TestWrapHandlerAccessAll(t *testing.T) {

wrappedHandler := auth.WrapHandler(dummyHandler)
for _, endpoint := range endpoints {
req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader(""))
req.Header.Add("Authorization", "Bearer "+tokenStr)
req := httptest.NewRequest(http.MethodPost, hostName+endpoint, strings.NewReader(""))
req.Header.Add("Authorization", headerValStart+tokenStr)
rr := httptest.NewRecorder()
wrappedHandler.ServeHTTP(rr, req)
require.Equal(http.StatusOK, rr.Code)
Expand Down Expand Up @@ -322,7 +323,7 @@ func TestWrapHandlerMutatedRevokedToken(t *testing.T) {
wrappedHandler := auth.WrapHandler(dummyHandler)

for _, endpoint := range endpoints {
req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader(""))
req := httptest.NewRequest(http.MethodPost, hostName+endpoint, strings.NewReader(""))
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s=", tokenStr)) // The appended = at the end looks like padding
rr := httptest.NewRecorder()
wrappedHandler.ServeHTTP(rr, req)
Expand Down Expand Up @@ -356,8 +357,8 @@ func TestWrapHandlerInvalidSigningMethod(t *testing.T) {
wrappedHandler := auth.WrapHandler(dummyHandler)

for _, endpoint := range endpoints {
req := httptest.NewRequest(http.MethodPost, "http://127.0.0.1:9650"+endpoint, strings.NewReader(""))
req.Header.Add("Authorization", "Bearer "+tokenStr)
req := httptest.NewRequest(http.MethodPost, hostName+endpoint, strings.NewReader(""))
req.Header.Add("Authorization", headerValStart+tokenStr)
rr := httptest.NewRecorder()
wrappedHandler.ServeHTTP(rr, req)
require.Equal(http.StatusUnauthorized, rr.Code)
Expand Down
8 changes: 3 additions & 5 deletions api/keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/ava-labs/avalanchego/chains/atomic"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/encdb"
"github.com/ava-labs/avalanchego/database/manager"
"github.com/ava-labs/avalanchego/database/prefixdb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/json"
Expand Down Expand Up @@ -105,13 +104,12 @@ type keystore struct {
bcDB database.Database
}

func New(log logging.Logger, dbManager manager.Manager) Keystore {
currentDB := dbManager.Current()
func New(log logging.Logger, db database.Database) Keystore {
return &keystore{
log: log,
usernameToPassword: make(map[string]*password.Hash),
userDB: prefixdb.New(usersPrefix, currentDB.Database),
bcDB: prefixdb.New(bcsPrefix, currentDB.Database),
userDB: prefixdb.New(usersPrefix, db),
bcDB: prefixdb.New(bcsPrefix, db),
}
}

Expand Down
17 changes: 0 additions & 17 deletions api/keystore/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ import (
"go.uber.org/zap"

"github.com/ava-labs/avalanchego/api"
"github.com/ava-labs/avalanchego/database/manager"
"github.com/ava-labs/avalanchego/database/memdb"
"github.com/ava-labs/avalanchego/utils/formatting"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/version"
)

type service struct {
Expand Down Expand Up @@ -115,17 +112,3 @@ func (s *service) ExportUser(_ *http.Request, args *ExportUserArgs, reply *Expor
reply.Encoding = args.Encoding
return nil
}

// CreateTestKeystore returns a new keystore that can be utilized for testing
func CreateTestKeystore() (Keystore, error) {
dbManager, err := manager.NewManagerFromDBs([]*manager.VersionedDatabase{
{
Database: memdb.New(),
Version: version.Semantic1_0_0,
},
})
if err != nil {
return nil, err
}
return New(logging.NoLog{}, dbManager), nil
}
40 changes: 16 additions & 24 deletions api/keystore/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
package keystore

import (
"fmt"
"encoding/hex"
"math/rand"
"testing"

"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/api"
"github.com/ava-labs/avalanchego/database/memdb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/formatting"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/password"
)

Expand All @@ -23,8 +25,7 @@ var strongPassword = "N_+=_jJ;^(<;{4,:*m6CET}'&N;83FYK.wtNpwp-Jt" // #nosec G101
func TestServiceListNoUsers(t *testing.T) {
require := require.New(t)

ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

reply := ListUsersReply{}
Expand All @@ -35,8 +36,7 @@ func TestServiceListNoUsers(t *testing.T) {
func TestServiceCreateUser(t *testing.T) {
require := require.New(t)

ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

{
Expand All @@ -58,16 +58,15 @@ func TestServiceCreateUser(t *testing.T) {
func genStr(n int) string {
b := make([]byte, n)
rand.Read(b) // #nosec G404
return fmt.Sprintf("%x", b)[:n]
return hex.EncodeToString(b)[:n]
}

// TestServiceCreateUserArgsCheck generates excessively long usernames or
// passwords to assure the sanity checks on string length are not exceeded
func TestServiceCreateUserArgsCheck(t *testing.T) {
require := require.New(t)

ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

{
Expand Down Expand Up @@ -100,8 +99,7 @@ func TestServiceCreateUserArgsCheck(t *testing.T) {
func TestServiceCreateUserWeakPassword(t *testing.T) {
require := require.New(t)

ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

{
Expand All @@ -117,8 +115,7 @@ func TestServiceCreateUserWeakPassword(t *testing.T) {
func TestServiceCreateDuplicate(t *testing.T) {
require := require.New(t)

ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

{
Expand All @@ -140,12 +137,11 @@ func TestServiceCreateDuplicate(t *testing.T) {
func TestServiceCreateUserNoName(t *testing.T) {
require := require.New(t)

ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

reply := api.EmptyReply{}
err = s.CreateUser(nil, &api.UserPass{
err := s.CreateUser(nil, &api.UserPass{
Password: strongPassword,
}, &reply)
require.ErrorIs(err, errEmptyUsername)
Expand All @@ -154,8 +150,7 @@ func TestServiceCreateUserNoName(t *testing.T) {
func TestServiceUseBlockchainDB(t *testing.T) {
require := require.New(t)

ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

{
Expand Down Expand Up @@ -185,8 +180,7 @@ func TestServiceExportImport(t *testing.T) {

encodings := []formatting.Encoding{formatting.Hex}
for _, encoding := range encodings {
ks, err := CreateTestKeystore()
require.NoError(err)
ks := New(logging.NoLog{}, memdb.New())
s := service{ks: ks.(*keystore)}

{
Expand All @@ -212,8 +206,7 @@ func TestServiceExportImport(t *testing.T) {
exportReply := ExportUserReply{}
require.NoError(s.ExportUser(nil, &exportArgs, &exportReply))

newKS, err := CreateTestKeystore()
require.NoError(err)
newKS := New(logging.NoLog{}, memdb.New())
newS := service{ks: newKS.(*keystore)}

{
Expand Down Expand Up @@ -324,16 +317,15 @@ func TestServiceDeleteUser(t *testing.T) {
t.Run(tt.desc, func(t *testing.T) {
require := require.New(t)

ksIntf, err := CreateTestKeystore()
require.NoError(err)
ksIntf := New(logging.NoLog{}, memdb.New())
ks := ksIntf.(*keystore)
s := service{ks: ks}

if tt.setup != nil {
require.NoError(tt.setup(ks))
}
got := &api.EmptyReply{}
err = s.DeleteUser(nil, tt.request, got)
err := s.DeleteUser(nil, tt.request, got)
require.ErrorIs(err, tt.expectedErr)
if tt.expectedErr != nil {
return
Expand Down
7 changes: 3 additions & 4 deletions api/server/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/prometheus/client_golang/prometheus"

"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/avalanchego/utils"
)

type metrics struct {
Expand Down Expand Up @@ -46,13 +46,12 @@ func newMetrics(namespace string, registerer prometheus.Registerer) (*metrics, e
),
}

errs := wrappers.Errs{}
errs.Add(
err := utils.Err(
registerer.Register(m.numProcessing),
registerer.Register(m.numCalls),
registerer.Register(m.totalDuration),
)
return m, errs.Err
return m, err
}

func (m *metrics) wrapHandler(chainName string, handler http.Handler) http.Handler {
Expand Down
Loading

0 comments on commit eb157fd

Please sign in to comment.