Skip to content

Commit

Permalink
Merge branch 'master' into version-bump-v1.11.9
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Jul 2, 2024
2 parents b86071e + e20115c commit 574ea8f
Show file tree
Hide file tree
Showing 79 changed files with 190 additions and 218 deletions.
5 changes: 2 additions & 3 deletions api/server/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
package server

import (
"errors"
"net/http"
"time"

"github.com/prometheus/client_golang/prometheus"

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

type metrics struct {
Expand Down Expand Up @@ -43,7 +42,7 @@ func newMetrics(registerer prometheus.Registerer) (*metrics, error) {
),
}

err := utils.Err(
err := errors.Join(
registerer.Register(m.numProcessing),
registerer.Register(m.numCalls),
registerer.Register(m.totalDuration),
Expand Down
6 changes: 3 additions & 3 deletions cache/metercacher/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
package metercacher

import (
"github.com/prometheus/client_golang/prometheus"
"errors"

"github.com/ava-labs/avalanchego/utils"
"github.com/prometheus/client_golang/prometheus"
)

const (
Expand Down Expand Up @@ -78,7 +78,7 @@ func newMetrics(
Help: "fraction of cache filled",
}),
}
return m, utils.Err(
return m, errors.Join(
reg.Register(m.getCount),
reg.Register(m.getTime),
reg.Register(m.putCount),
Expand Down
2 changes: 1 addition & 1 deletion chains/test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (testManager) StartChainCreator(ChainParameters) error {
}

func (testManager) SubnetID(ids.ID) (ids.ID, error) {
return ids.ID{}, nil
return ids.Empty, nil
}

func (testManager) IsBootstrapped(ids.ID) bool {
Expand Down
2 changes: 1 addition & 1 deletion database/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func PutID(db KeyValueWriter, key []byte, val ids.ID) error {
func GetID(db KeyValueReader, key []byte) (ids.ID, error) {
b, err := db.Get(key)
if err != nil {
return ids.ID{}, err
return ids.Empty, err
}
return ids.ToID(b)
}
Expand Down
5 changes: 2 additions & 3 deletions database/leveldb/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
package leveldb

import (
"errors"
"strconv"

"github.com/prometheus/client_golang/prometheus"
"github.com/syndtr/goleveldb/leveldb"

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

var levelLabels = []string{"level"}
Expand Down Expand Up @@ -161,7 +160,7 @@ func newMetrics(reg prometheus.Registerer) (metrics, error) {
currentStats: &leveldb.DBStats{},
}

err := utils.Err(
err := errors.Join(
reg.Register(m.writesDelayedCount),
reg.Register(m.writesDelayedDuration),
reg.Register(m.writeIsDelayed),
Expand Down
4 changes: 2 additions & 2 deletions database/meterdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package meterdb

import (
"context"
"errors"
"time"

"github.com/prometheus/client_golang/prometheus"

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

const methodLabel = "method"
Expand Down Expand Up @@ -125,7 +125,7 @@ func New(
methodLabels,
),
}
return meterDB, utils.Err(
return meterDB, errors.Join(
reg.Register(meterDB.calls),
reg.Register(meterDB.duration),
reg.Register(meterDB.size),
Expand Down
2 changes: 1 addition & 1 deletion genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func init() {
unparsedFujiConfig := UnparsedConfig{}
unparsedLocalConfig := UnparsedConfig{}

err := utils.Err(
err := errors.Join(
json.Unmarshal(mainnetGenesisConfigJSON, &unparsedMainnetConfig),
json.Unmarshal(fujiGenesisConfigJSON, &unparsedFujiConfig),
json.Unmarshal(localGenesisConfigJSON, &unparsedLocalConfig),
Expand Down
32 changes: 16 additions & 16 deletions genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func validateConfig(networkID uint32, config *Config, stakingCfg *StakingConfig)
func FromFile(networkID uint32, filepath string, stakingCfg *StakingConfig) ([]byte, ids.ID, error) {
switch networkID {
case constants.MainnetID, constants.TestnetID, constants.LocalID:
return nil, ids.ID{}, fmt.Errorf(
return nil, ids.Empty, fmt.Errorf(
"%w: %s",
errOverridesStandardNetworkConfig,
constants.NetworkName(networkID),
Expand All @@ -212,11 +212,11 @@ func FromFile(networkID uint32, filepath string, stakingCfg *StakingConfig) ([]b

config, err := GetConfigFile(filepath)
if err != nil {
return nil, ids.ID{}, fmt.Errorf("unable to load provided genesis config at %s: %w", filepath, err)
return nil, ids.Empty, fmt.Errorf("unable to load provided genesis config at %s: %w", filepath, err)
}

if err := validateConfig(networkID, config, stakingCfg); err != nil {
return nil, ids.ID{}, fmt.Errorf("genesis config validation failed: %w", err)
return nil, ids.Empty, fmt.Errorf("genesis config validation failed: %w", err)
}

return FromConfig(config)
Expand Down Expand Up @@ -245,7 +245,7 @@ func FromFile(networkID uint32, filepath string, stakingCfg *StakingConfig) ([]b
func FromFlag(networkID uint32, genesisContent string, stakingCfg *StakingConfig) ([]byte, ids.ID, error) {
switch networkID {
case constants.MainnetID, constants.TestnetID, constants.LocalID:
return nil, ids.ID{}, fmt.Errorf(
return nil, ids.Empty, fmt.Errorf(
"%w: %s",
errOverridesStandardNetworkConfig,
constants.NetworkName(networkID),
Expand All @@ -254,11 +254,11 @@ func FromFlag(networkID uint32, genesisContent string, stakingCfg *StakingConfig

customConfig, err := GetConfigContent(genesisContent)
if err != nil {
return nil, ids.ID{}, fmt.Errorf("unable to load genesis content from flag: %w", err)
return nil, ids.Empty, fmt.Errorf("unable to load genesis content from flag: %w", err)
}

if err := validateConfig(networkID, customConfig, stakingCfg); err != nil {
return nil, ids.ID{}, fmt.Errorf("genesis config validation failed: %w", err)
return nil, ids.Empty, fmt.Errorf("genesis config validation failed: %w", err)
}

return FromConfig(customConfig)
Expand Down Expand Up @@ -298,7 +298,7 @@ func FromConfig(config *Config) ([]byte, ids.ID, error) {
for _, allocation := range xAllocations {
addr, err := address.FormatBech32(hrp, allocation.AVAXAddr.Bytes())
if err != nil {
return nil, ids.ID{}, err
return nil, ids.Empty, err
}

avax.InitialState["fixedCap"] = append(avax.InitialState["fixedCap"], avm.Holder{
Expand All @@ -323,22 +323,22 @@ func FromConfig(config *Config) ([]byte, ids.ID, error) {
avmSS := avm.CreateStaticService()
err := avmSS.BuildGenesis(nil, &avmArgs, &avmReply)
if err != nil {
return nil, ids.ID{}, err
return nil, ids.Empty, err
}

bytes, err := formatting.Decode(defaultEncoding, avmReply.Bytes)
if err != nil {
return nil, ids.ID{}, fmt.Errorf("couldn't parse avm genesis reply: %w", err)
return nil, ids.Empty, fmt.Errorf("couldn't parse avm genesis reply: %w", err)
}
avaxAssetID, err := AVAXAssetID(bytes)
if err != nil {
return nil, ids.ID{}, fmt.Errorf("couldn't generate AVAX asset ID: %w", err)
return nil, ids.Empty, fmt.Errorf("couldn't generate AVAX asset ID: %w", err)
}

genesisTime := time.Unix(int64(config.StartTime), 0)
initialSupply, err := config.InitialSupply()
if err != nil {
return nil, ids.ID{}, fmt.Errorf("couldn't calculate the initial supply: %w", err)
return nil, ids.Empty, fmt.Errorf("couldn't calculate the initial supply: %w", err)
}

initiallyStaked := set.Of(config.InitialStakedFunds...)
Expand All @@ -360,7 +360,7 @@ func FromConfig(config *Config) ([]byte, ids.ID, error) {
}
addr, err := address.FormatBech32(hrp, allocation.AVAXAddr.Bytes())
if err != nil {
return nil, ids.ID{}, err
return nil, ids.Empty, err
}
for _, unlock := range allocation.UnlockSchedule {
if unlock.Amount > 0 {
Expand Down Expand Up @@ -391,14 +391,14 @@ func FromConfig(config *Config) ([]byte, ids.ID, error) {

destAddrStr, err := address.FormatBech32(hrp, staker.RewardAddress.Bytes())
if err != nil {
return nil, ids.ID{}, err
return nil, ids.Empty, err
}

utxos := []api.UTXO(nil)
for _, allocation := range nodeAllocations {
addr, err := address.FormatBech32(hrp, allocation.AVAXAddr.Bytes())
if err != nil {
return nil, ids.ID{}, err
return nil, ids.Empty, err
}
for _, unlock := range allocation.UnlockSchedule {
msgStr, err := formatting.Encode(defaultEncoding, allocation.ETHAddr.Bytes())
Expand Down Expand Up @@ -463,12 +463,12 @@ func FromConfig(config *Config) ([]byte, ids.ID, error) {
platformvmReply := api.BuildGenesisReply{}
platformvmSS := api.StaticService{}
if err := platformvmSS.BuildGenesis(nil, &platformvmArgs, &platformvmReply); err != nil {
return nil, ids.ID{}, fmt.Errorf("problem while building platform chain's genesis state: %w", err)
return nil, ids.Empty, fmt.Errorf("problem while building platform chain's genesis state: %w", err)
}

genesisBytes, err := formatting.Decode(platformvmReply.Encoding, platformvmReply.Bytes)
if err != nil {
return nil, ids.ID{}, fmt.Errorf("problem parsing platformvm genesis bytes: %w", err)
return nil, ids.Empty, fmt.Errorf("problem parsing platformvm genesis bytes: %w", err)
}

return genesisBytes, avaxAssetID, nil
Expand Down
2 changes: 1 addition & 1 deletion ids/galiasreader/alias_reader_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (c *Client) Lookup(alias string) (ids.ID, error) {
Alias: alias,
})
if err != nil {
return ids.ID{}, err
return ids.Empty, err
}
return ids.ToID(resp.Id)
}
Expand Down
3 changes: 1 addition & 2 deletions indexer/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/ava-labs/avalanchego/database/versiondb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
)
Expand Down Expand Up @@ -99,7 +98,7 @@ func newIndex(

// Close this index
func (i *index) Close() error {
return utils.Err(
return errors.Join(
i.indexToContainer.Close(),
i.containerToIndex.Close(),
i.vDB.Close(),
Expand Down
3 changes: 1 addition & 2 deletions message/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/proto/pb/p2p"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/compression"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/logging"
Expand Down Expand Up @@ -178,7 +177,7 @@ func newMsgBuilder(

maxMessageTimeout: maxMessageTimeout,
}
return mb, utils.Err(
return mb, errors.Join(
metrics.Register(mb.count),
metrics.Register(mb.duration),
)
Expand Down
4 changes: 2 additions & 2 deletions network/ip_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package network

import (
"crypto/rand"
"errors"
"sync"

"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"

"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/bloom"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/ips"
Expand Down Expand Up @@ -63,7 +63,7 @@ func newIPTracker(
connected: make(map[ids.NodeID]*ips.ClaimedIPPort),
gossipableIndices: make(map[ids.NodeID]int),
}
err = utils.Err(
err = errors.Join(
registerer.Register(tracker.numTrackedIPs),
registerer.Register(tracker.numGossipableIPs),
)
Expand Down
4 changes: 2 additions & 2 deletions network/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
package network

import (
"errors"
"sync"
"time"

"github.com/prometheus/client_golang/prometheus"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/network/peer"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/set"
)

Expand Down Expand Up @@ -135,7 +135,7 @@ func newMetrics(
peerConnectedStartTimes: make(map[ids.NodeID]float64),
}

err := utils.Err(
err := errors.Join(
registerer.Register(m.numTracked),
registerer.Register(m.numPeers),
registerer.Register(m.numSubnetPeers),
Expand Down
3 changes: 1 addition & 2 deletions network/p2p/gossip/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/network/p2p"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/bloom"
"github.com/ava-labs/avalanchego/utils/buffer"
"github.com/ava-labs/avalanchego/utils/logging"
Expand Down Expand Up @@ -150,7 +149,7 @@ func NewMetrics(
typeLabels,
),
}
err := utils.Err(
err := errors.Join(
metrics.Register(m.count),
metrics.Register(m.bytes),
metrics.Register(m.tracking),
Expand Down
4 changes: 2 additions & 2 deletions network/p2p/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package p2p
import (
"context"
"encoding/binary"
"errors"
"strconv"
"sync"
"time"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/engine/common"
"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/set"
"github.com/ava-labs/avalanchego/version"
Expand Down Expand Up @@ -81,7 +81,7 @@ func NewNetwork(
),
}

err := utils.Err(
err := errors.Join(
registerer.Register(metrics.msgTime),
registerer.Register(metrics.msgCount),
)
Expand Down
4 changes: 2 additions & 2 deletions network/p2p/peer_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package p2p

import (
"errors"
"math"
"math/rand"
"sync"
Expand All @@ -13,7 +14,6 @@ import (
"go.uber.org/zap"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/heap"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/set"
Expand Down Expand Up @@ -113,7 +113,7 @@ func NewPeerTracker(
},
}

err := utils.Err(
err := errors.Join(
registerer.Register(t.metrics.numTrackedPeers),
registerer.Register(t.metrics.numResponsivePeers),
registerer.Register(t.metrics.averageBandwidth),
Expand Down
Loading

0 comments on commit 574ea8f

Please sign in to comment.