Skip to content

Commit

Permalink
Merge branch 'dev' into sdk-app-gossip-error
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Nov 6, 2023
2 parents 2a82a8d + 10bd428 commit 1863525
Show file tree
Hide file tree
Showing 61 changed files with 1,103 additions and 1,334 deletions.
2 changes: 1 addition & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ This version is backwards compatible to [v1.10.0](https://github.com/ava-labs/av
- Add workflow to mark stale issues and PRs by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/1443
- Enforce inlining functions with a single error return in `require.NoError` by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/1500
- `x/sync` / `x/merkledb` -- add `SyncableDB` interface by @danlaine in https://github.com/ava-labs/avalanchego/pull/1555
- Rename beacon to boostrapper, define bootstrappers in JSON file for cross-language compatiblity by @gyuho in https://github.com/ava-labs/avalanchego/pull/1439
- Rename beacon to boostrapper, define bootstrappers in JSON file for cross-language compatibility by @gyuho in https://github.com/ava-labs/avalanchego/pull/1439
- add P-chain height indexing by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/1447
- Add P-chain `GetBlockByHeight` API method by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/1448
- `x/sync` -- use for sending Range Proofs by @danlaine in https://github.com/ava-labs/avalanchego/pull/1537
Expand Down
13 changes: 11 additions & 2 deletions api/info/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ type PeersArgs struct {
type Peer struct {
peer.Info

Benched []ids.ID `json:"benched"`
Benched []string `json:"benched"`
}

// PeersReply are the results from calling Peers
Expand All @@ -229,9 +229,18 @@ func (i *Info) Peers(_ *http.Request, args *PeersArgs, reply *PeersReply) error
peers := i.networking.PeerInfo(args.NodeIDs)
peerInfo := make([]Peer, len(peers))
for index, peer := range peers {
benchedIDs := i.benchlist.GetBenched(peer.ID)
benchedAliases := make([]string, len(benchedIDs))
for idx, id := range benchedIDs {
alias, err := i.chainManager.PrimaryAlias(id)
if err != nil {
return fmt.Errorf("failed to get primary alias for chain ID %s: %w", id, err)
}
benchedAliases[idx] = alias
}
peerInfo[index] = Peer{
Info: peer,
Benched: i.benchlist.GetBenched(peer.ID),
Benched: benchedAliases,
}
}

Expand Down
4 changes: 3 additions & 1 deletion ipcs/socket/socket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"testing"

"github.com/stretchr/testify/require"

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

func TestSocketSendAndReceive(t *testing.T) {
Expand All @@ -21,7 +23,7 @@ func TestSocketSendAndReceive(t *testing.T) {
)

// Create socket and client; wait for client to connect
socket := NewSocket(socketName, nil)
socket := NewSocket(socketName, logging.NoLog{})
socket.accept, connCh = newTestAcceptFn(t)
require.NoError(socket.Listen())

Expand Down
18 changes: 10 additions & 8 deletions snow/consensus/snowman/poll/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package poll

import (
"errors"
"fmt"
"strings"
"time"
Expand All @@ -19,6 +20,11 @@ import (
"github.com/ava-labs/avalanchego/utils/metric"
)

var (
errFailedPollsMetric = errors.New("failed to register polls metric")
errFailedPollDurationMetrics = errors.New("failed to register poll_duration metrics")
)

type pollHolder interface {
GetPoll() Poll
StartTime() time.Time
Expand Down Expand Up @@ -52,16 +58,14 @@ func NewSet(
log logging.Logger,
namespace string,
reg prometheus.Registerer,
) Set {
) (Set, error) {
numPolls := prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "polls",
Help: "Number of pending network polls",
})
if err := reg.Register(numPolls); err != nil {
log.Error("failed to register polls statistics",
zap.Error(err),
)
return nil, fmt.Errorf("%w: %w", errFailedPollsMetric, err)
}

durPolls, err := metric.NewAverager(
Expand All @@ -71,9 +75,7 @@ func NewSet(
reg,
)
if err != nil {
log.Error("failed to register poll_duration statistics",
zap.Error(err),
)
return nil, fmt.Errorf("%w: %w", errFailedPollDurationMetrics, err)
}

return &set{
Expand All @@ -82,7 +84,7 @@ func NewSet(
durPolls: durPolls,
factory: factory,
polls: linkedhashmap.New[uint32, pollHolder](),
}
}, nil
}

// Add to the current set of polls
Expand Down
42 changes: 32 additions & 10 deletions snow/consensus/snowman/poll/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var (
vdr5 = ids.NodeID{5}
)

func TestNewSetErrorOnMetrics(t *testing.T) {
func TestNewSetErrorOnPollsMetrics(t *testing.T) {
require := require.New(t)

factory := NewEarlyTermNoTraversalFactory(1, 1)
Expand All @@ -37,13 +37,29 @@ func TestNewSetErrorOnMetrics(t *testing.T) {
registerer := prometheus.NewRegistry()

require.NoError(registerer.Register(prometheus.NewCounter(prometheus.CounterOpts{
Name: "polls",
Namespace: namespace,
Name: "polls",
})))

_, err := NewSet(factory, log, namespace, registerer)
require.ErrorIs(err, errFailedPollsMetric)
}

func TestNewSetErrorOnPollDurationMetrics(t *testing.T) {
require := require.New(t)

factory := NewEarlyTermNoTraversalFactory(1, 1)
log := logging.NoLog{}
namespace := ""
registerer := prometheus.NewRegistry()

require.NoError(registerer.Register(prometheus.NewCounter(prometheus.CounterOpts{
Name: "poll_duration",
Namespace: namespace,
Name: "poll_duration_count",
})))

require.NotNil(NewSet(factory, log, namespace, registerer))
_, err := NewSet(factory, log, namespace, registerer)
require.ErrorIs(err, errFailedPollDurationMetrics)
}

func TestCreateAndFinishPollOutOfOrder_NewerFinishesFirst(t *testing.T) {
Expand All @@ -56,7 +72,8 @@ func TestCreateAndFinishPollOutOfOrder_NewerFinishesFirst(t *testing.T) {
log := logging.NoLog{}
namespace := ""
registerer := prometheus.NewRegistry()
s := NewSet(factory, log, namespace, registerer)
s, err := NewSet(factory, log, namespace, registerer)
require.NoError(err)

// create two polls for the two blocks
vdrBag := bag.Of(vdrs...)
Expand Down Expand Up @@ -92,7 +109,8 @@ func TestCreateAndFinishPollOutOfOrder_OlderFinishesFirst(t *testing.T) {
log := logging.NoLog{}
namespace := ""
registerer := prometheus.NewRegistry()
s := NewSet(factory, log, namespace, registerer)
s, err := NewSet(factory, log, namespace, registerer)
require.NoError(err)

// create two polls for the two blocks
vdrBag := bag.Of(vdrs...)
Expand Down Expand Up @@ -128,7 +146,8 @@ func TestCreateAndFinishPollOutOfOrder_UnfinishedPollsGaps(t *testing.T) {
log := logging.NoLog{}
namespace := ""
registerer := prometheus.NewRegistry()
s := NewSet(factory, log, namespace, registerer)
s, err := NewSet(factory, log, namespace, registerer)
require.NoError(err)

// create three polls for the two blocks
vdrBag := bag.Of(vdrs...)
Expand Down Expand Up @@ -172,7 +191,8 @@ func TestCreateAndFinishSuccessfulPoll(t *testing.T) {
log := logging.NoLog{}
namespace := ""
registerer := prometheus.NewRegistry()
s := NewSet(factory, log, namespace, registerer)
s, err := NewSet(factory, log, namespace, registerer)
require.NoError(err)

require.Zero(s.Len())

Expand Down Expand Up @@ -204,7 +224,8 @@ func TestCreateAndFinishFailedPoll(t *testing.T) {
log := logging.NoLog{}
namespace := ""
registerer := prometheus.NewRegistry()
s := NewSet(factory, log, namespace, registerer)
s, err := NewSet(factory, log, namespace, registerer)
require.NoError(err)

require.Zero(s.Len())

Expand Down Expand Up @@ -233,7 +254,8 @@ func TestSetString(t *testing.T) {
log := logging.NoLog{}
namespace := ""
registerer := prometheus.NewRegistry()
s := NewSet(factory, log, namespace, registerer)
s, err := NewSet(factory, log, namespace, registerer)
require.NoError(err)

expected := `current polls: (Size = 1)
RequestID 0:
Expand Down
3 changes: 1 addition & 2 deletions snow/engine/common/test_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package common
import (
"context"
"errors"
"testing"

"github.com/stretchr/testify/require"

Expand All @@ -27,7 +26,7 @@ var (

// SenderTest is a test sender
type SenderTest struct {
T *testing.T
T require.TestingT

CantAccept,
CantSendGetStateSummaryFrontier, CantSendStateSummaryFrontier,
Expand Down
17 changes: 11 additions & 6 deletions snow/engine/snowman/transitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ func newTransitive(config Config) (*Transitive, error) {
config.Params.AlphaPreference,
config.Params.AlphaConfidence,
)
polls, err := poll.NewSet(
factory,
config.Ctx.Log,
"",
config.Ctx.Registerer,
)
if err != nil {
return nil, err
}

t := &Transitive{
Config: config,
StateSummaryFrontierHandler: common.NewNoOpStateSummaryFrontierHandler(config.Ctx.Log),
Expand All @@ -129,12 +139,7 @@ func newTransitive(config Config) (*Transitive, error) {
nonVerifieds: ancestor.NewTree(),
nonVerifiedCache: nonVerifiedCache,
acceptedFrontiers: acceptedFrontiers,
polls: poll.NewSet(
factory,
config.Ctx.Log,
"",
config.Ctx.Registerer,
),
polls: polls,
}

return t, t.metrics.Initialize("", config.Ctx.Registerer)
Expand Down
10 changes: 3 additions & 7 deletions snow/validators/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"go.uber.org/zap"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/set"
Expand All @@ -18,7 +17,6 @@ var _ SetCallbackListener = (*logger)(nil)

type logger struct {
log logging.Logger
enabled *utils.Atomic[bool]
subnetID ids.ID
nodeIDs set.Set[ids.NodeID]
}
Expand All @@ -27,14 +25,12 @@ type logger struct {
// the specified validators
func NewLogger(
log logging.Logger,
enabled *utils.Atomic[bool],
subnetID ids.ID,
nodeIDs ...ids.NodeID,
) SetCallbackListener {
nodeIDSet := set.Of(nodeIDs...)
return &logger{
log: log,
enabled: enabled,
subnetID: subnetID,
nodeIDs: nodeIDSet,
}
Expand All @@ -46,7 +42,7 @@ func (l *logger) OnValidatorAdded(
txID ids.ID,
weight uint64,
) {
if l.enabled.Get() && l.nodeIDs.Contains(nodeID) {
if l.nodeIDs.Contains(nodeID) {
var pkBytes []byte
if pk != nil {
pkBytes = bls.PublicKeyToBytes(pk)
Expand All @@ -65,7 +61,7 @@ func (l *logger) OnValidatorRemoved(
nodeID ids.NodeID,
weight uint64,
) {
if l.enabled.Get() && l.nodeIDs.Contains(nodeID) {
if l.nodeIDs.Contains(nodeID) {
l.log.Info("node removed from validator set",
zap.Stringer("subnetID", l.subnetID),
zap.Stringer("nodeID", nodeID),
Expand All @@ -79,7 +75,7 @@ func (l *logger) OnValidatorWeightChanged(
oldWeight uint64,
newWeight uint64,
) {
if l.enabled.Get() && l.nodeIDs.Contains(nodeID) {
if l.nodeIDs.Contains(nodeID) {
l.log.Info("validator weight changed",
zap.Stringer("subnetID", l.subnetID),
zap.Stringer("nodeID", nodeID),
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/banff/suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = ginkgo.Describe("[Banff]", func() {
ginkgo.It("can send custom assets X->P and P->X",
func() {
keychain := e2e.Env.NewKeychain(1)
wallet := e2e.Env.NewWallet(keychain, e2e.Env.GetRandomNodeURI())
wallet := e2e.NewWallet(keychain, e2e.Env.GetRandomNodeURI())

// Get the P-chain and the X-chain wallets
pWallet := wallet.P()
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/c/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() {
NodeID: node.GetID(),
URI: node.GetProcessContext().URI,
}
ethClient := e2e.Env.NewEthClient(nodeURI)
ethClient := e2e.NewEthClient(nodeURI)

ginkgo.By("initializing a transaction signer")
cChainID, err := ethClient.ChainID(e2e.DefaultContext())
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/c/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = e2e.DescribeCChain("[Interchain Workflow]", func() {
// the wallet to avoid having to verify that all nodes are at
// the same height before initializing the wallet.
nodeURI := e2e.Env.GetRandomNodeURI()
ethClient := e2e.Env.NewEthClient(nodeURI)
ethClient := e2e.NewEthClient(nodeURI)

ginkgo.By("allocating a pre-funded key to send from and a recipient key to deliver to")
senderKey := e2e.Env.AllocateFundedKey()
Expand Down Expand Up @@ -79,7 +79,7 @@ var _ = e2e.DescribeCChain("[Interchain Workflow]", func() {
// matches on-chain state.
ginkgo.By("initializing a keychain and associated wallet")
keychain := secp256k1fx.NewKeychain(senderKey, recipientKey)
baseWallet := e2e.Env.NewWallet(keychain, nodeURI)
baseWallet := e2e.NewWallet(keychain, nodeURI)
xWallet := baseWallet.X()
cWallet := baseWallet.C()
pWallet := baseWallet.P()
Expand Down
Loading

0 comments on commit 1863525

Please sign in to comment.