Skip to content

Commit

Permalink
Merge branch 'master' into antithesis-xsvm
Browse files Browse the repository at this point in the history
  • Loading branch information
marun authored May 20, 2024
2 parents 998f28d + eb7ddd7 commit a16c79a
Show file tree
Hide file tree
Showing 39 changed files with 225 additions and 225 deletions.
10 changes: 5 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
run:
timeout: 10m

# Enables skipping of directories:
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
# Default: true
skip-dirs-use-default: false

# If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
Expand Down Expand Up @@ -36,6 +31,11 @@ issues:
# Default: 3
max-same-issues: 0

# Enables skipping of directories:
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
# Default: true
exclude-dirs-use-default: false

linters:
disable-all: true
enable:
Expand Down
2 changes: 1 addition & 1 deletion api/admin/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Now, calls to the X-Chain can be made to either `/ext/bc/X` or, equivalently, to

Give a blockchain an alias, a different name that can be used any place the blockchain’s ID is used.

:::note Aliasing a chain can also be done via the [Node API](https://docs.avax.network/nodes/configure/avalanchego-config-flags.md#--chain-aliases-file-string).
:::note Aliasing a chain can also be done via the [Node API](/nodes/configure/avalanchego-config-flags.md#--chain-aliases-file-string).
Note that the alias is set for each chain on each node individually. In a multi-node Subnet, the
same alias should be configured on each node to use an alias across a Subnet successfully. Setting
an alias for a chain on one node does not register that alias with other nodes automatically.
Expand Down
8 changes: 5 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/ava-labs/avalanchego/subnets"
)

const chainConfigFilenameExtention = ".ex"

func TestGetChainConfigsFromFiles(t *testing.T) {
tests := map[string]struct {
configs map[string]string
Expand Down Expand Up @@ -72,11 +74,11 @@ func TestGetChainConfigsFromFiles(t *testing.T) {
// Create custom configs
for key, value := range test.configs {
chainDir := filepath.Join(chainsDir, key)
setupFile(t, chainDir, chainConfigFileName+".ex", value) //nolint:goconst
setupFile(t, chainDir, chainConfigFileName+chainConfigFilenameExtention, value)
}
for key, value := range test.upgrades {
chainDir := filepath.Join(chainsDir, key)
setupFile(t, chainDir, chainUpgradeFileName+".ex", value)
setupFile(t, chainDir, chainUpgradeFileName+chainConfigFilenameExtention, value)
}

v := setupViper(configFile)
Expand Down Expand Up @@ -161,7 +163,7 @@ func TestSetChainConfigDefaultDir(t *testing.T) {
require.Equal(defaultChainConfigDir, v.GetString(ChainConfigDirKey))

chainsDir := filepath.Join(defaultChainConfigDir, "C")
setupFile(t, chainsDir, chainConfigFileName+".ex", "helloworld")
setupFile(t, chainsDir, chainConfigFileName+chainConfigFilenameExtention, "helloworld")
chainConfigs, err := getChainConfigs(v)
require.NoError(err)
expected := map[string]chains.ChainConfig{"C": {Config: []byte("helloworld"), Upgrade: []byte(nil)}}
Expand Down
110 changes: 57 additions & 53 deletions config/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,64 @@

package config

// #nosec G101
// the HTTPWriteTimeoutKey was moved here so that it would not generate the
// false-positive linter error "G101: Potential hardcoded credentials" when running golangci-lint.
const HTTPWriteTimeoutKey = "http-write-timeout" // #nosec G101

const (
DataDirKey = "data-dir"
ConfigFileKey = "config-file"
ConfigContentKey = "config-file-content"
ConfigContentTypeKey = "config-file-content-type"
VersionKey = "version"
GenesisFileKey = "genesis-file"
GenesisFileContentKey = "genesis-file-content"
NetworkNameKey = "network-id"
ACPSupportKey = "acp-support"
ACPObjectKey = "acp-object"
TxFeeKey = "tx-fee"
CreateAssetTxFeeKey = "create-asset-tx-fee"
CreateSubnetTxFeeKey = "create-subnet-tx-fee"
TransformSubnetTxFeeKey = "transform-subnet-tx-fee"
CreateBlockchainTxFeeKey = "create-blockchain-tx-fee"
AddPrimaryNetworkValidatorFeeKey = "add-primary-network-validator-fee"
AddPrimaryNetworkDelegatorFeeKey = "add-primary-network-delegator-fee"
AddSubnetValidatorFeeKey = "add-subnet-validator-fee"
AddSubnetDelegatorFeeKey = "add-subnet-delegator-fee"
UptimeRequirementKey = "uptime-requirement"
MinValidatorStakeKey = "min-validator-stake"
MaxValidatorStakeKey = "max-validator-stake"
MinDelegatorStakeKey = "min-delegator-stake"
MinDelegatorFeeKey = "min-delegation-fee"
MinStakeDurationKey = "min-stake-duration"
MaxStakeDurationKey = "max-stake-duration"
StakeMaxConsumptionRateKey = "stake-max-consumption-rate"
StakeMinConsumptionRateKey = "stake-min-consumption-rate"
StakeMintingPeriodKey = "stake-minting-period"
StakeSupplyCapKey = "stake-supply-cap"
DBTypeKey = "db-type"
DBReadOnlyKey = "db-read-only"
DBPathKey = "db-dir"
DBConfigFileKey = "db-config-file"
DBConfigContentKey = "db-config-file-content"
PublicIPKey = "public-ip"
PublicIPResolutionFreqKey = "public-ip-resolution-frequency"
PublicIPResolutionServiceKey = "public-ip-resolution-service"
HTTPHostKey = "http-host"
HTTPPortKey = "http-port"
HTTPSEnabledKey = "http-tls-enabled"
HTTPSKeyFileKey = "http-tls-key-file"
HTTPSKeyContentKey = "http-tls-key-file-content"
HTTPSCertFileKey = "http-tls-cert-file"
HTTPSCertContentKey = "http-tls-cert-file-content"
HTTPAllowedOrigins = "http-allowed-origins"
HTTPAllowedHostsKey = "http-allowed-hosts"
HTTPShutdownTimeoutKey = "http-shutdown-timeout"
HTTPShutdownWaitKey = "http-shutdown-wait"
HTTPReadTimeoutKey = "http-read-timeout"
HTTPReadHeaderTimeoutKey = "http-read-header-timeout"
HTTPWriteTimeoutKey = "http-write-timeout"
DataDirKey = "data-dir"
ConfigFileKey = "config-file"
ConfigContentKey = "config-file-content"
ConfigContentTypeKey = "config-file-content-type"
VersionKey = "version"
GenesisFileKey = "genesis-file"
GenesisFileContentKey = "genesis-file-content"
NetworkNameKey = "network-id"
ACPSupportKey = "acp-support"
ACPObjectKey = "acp-object"
TxFeeKey = "tx-fee"
CreateAssetTxFeeKey = "create-asset-tx-fee"
CreateSubnetTxFeeKey = "create-subnet-tx-fee"
TransformSubnetTxFeeKey = "transform-subnet-tx-fee"
CreateBlockchainTxFeeKey = "create-blockchain-tx-fee"
AddPrimaryNetworkValidatorFeeKey = "add-primary-network-validator-fee"
AddPrimaryNetworkDelegatorFeeKey = "add-primary-network-delegator-fee"
AddSubnetValidatorFeeKey = "add-subnet-validator-fee"
AddSubnetDelegatorFeeKey = "add-subnet-delegator-fee"
UptimeRequirementKey = "uptime-requirement"
MinValidatorStakeKey = "min-validator-stake"
MaxValidatorStakeKey = "max-validator-stake"
MinDelegatorStakeKey = "min-delegator-stake"
MinDelegatorFeeKey = "min-delegation-fee"
MinStakeDurationKey = "min-stake-duration"
MaxStakeDurationKey = "max-stake-duration"
StakeMaxConsumptionRateKey = "stake-max-consumption-rate"
StakeMinConsumptionRateKey = "stake-min-consumption-rate"
StakeMintingPeriodKey = "stake-minting-period"
StakeSupplyCapKey = "stake-supply-cap"
DBTypeKey = "db-type"
DBReadOnlyKey = "db-read-only"
DBPathKey = "db-dir"
DBConfigFileKey = "db-config-file"
DBConfigContentKey = "db-config-file-content"
PublicIPKey = "public-ip"
PublicIPResolutionFreqKey = "public-ip-resolution-frequency"
PublicIPResolutionServiceKey = "public-ip-resolution-service"
HTTPHostKey = "http-host"
HTTPPortKey = "http-port"
HTTPSEnabledKey = "http-tls-enabled"
HTTPSKeyFileKey = "http-tls-key-file"
HTTPSKeyContentKey = "http-tls-key-file-content"
HTTPSCertFileKey = "http-tls-cert-file"
HTTPSCertContentKey = "http-tls-cert-file-content"

HTTPAllowedOrigins = "http-allowed-origins"
HTTPAllowedHostsKey = "http-allowed-hosts"
HTTPShutdownTimeoutKey = "http-shutdown-timeout"
HTTPShutdownWaitKey = "http-shutdown-wait"
HTTPReadTimeoutKey = "http-read-timeout"
HTTPReadHeaderTimeoutKey = "http-read-header-timeout"

HTTPIdleTimeoutKey = "http-idle-timeout"
StateSyncIPsKey = "state-sync-ips"
StateSyncIDsKey = "state-sync-ids"
Expand Down
24 changes: 8 additions & 16 deletions database/pebble/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,18 @@ func (b *batch) Write() error {
return database.ErrClosed
}

if !b.written {
// This batch has not been written to the database yet.
if err := updateError(b.batch.Commit(pebble.Sync)); err != nil {
if b.written {
// pebble doesn't support writing a batch twice so we have to clone the
// batch before writing it.
newBatch := b.db.pebbleDB.NewBatch()
if err := newBatch.Apply(b.batch, nil); err != nil {
return err
}
b.written = true
return nil
b.batch = newBatch
}

// pebble doesn't support writing a batch twice so we have to clone
// [b] and commit the clone.
batchClone := b.db.pebbleDB.NewBatch()

// Copy the batch.
if err := batchClone.Apply(b.batch, nil); err != nil {
return err
}

// Commit the new batch.
return updateError(batchClone.Commit(pebble.Sync))
b.written = true
return updateError(b.batch.Commit(pebble.Sync))
}

func (b *batch) Reset() {
Expand Down
2 changes: 1 addition & 1 deletion database/pebble/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestBatch(t *testing.T) {
require := require.New(t)
dirName := t.TempDir()

db, err := New(dirName, DefaultConfigBytes, logging.NoLog{}, "", prometheus.NewRegistry())
db, err := New(dirName, nil, logging.NoLog{}, "", prometheus.NewRegistry())
require.NoError(err)

batchIntf := db.NewBatch()
Expand Down
22 changes: 6 additions & 16 deletions database/pebble/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package pebble

import (
"bytes"
"context"
"encoding/json"
"errors"
Expand Down Expand Up @@ -44,18 +43,8 @@ var (
MaxOpenFiles: 4096,
MaxConcurrentCompactions: 1,
}

DefaultConfigBytes []byte
)

func init() {
var err error
DefaultConfigBytes, err = json.Marshal(DefaultConfig)
if err != nil {
panic(err)
}
}

type Database struct {
lock sync.RWMutex
pebbleDB *pebble.DB
Expand Down Expand Up @@ -200,17 +189,18 @@ func (db *Database) Compact(start []byte, end []byte) error {
}

if end == nil {
// The database.Database spec treats a nil [limit] as a key after all keys
// but pebble treats a nil [limit] as a key before all keys in Compact.
// Use the greatest key in the database as the [limit] to get the desired behavior.
// The database.Database spec treats a nil [limit] as a key after all
// keys but pebble treats a nil [limit] as a key before all keys in
// Compact. Use the greatest key in the database as the [limit] to get
// the desired behavior.
it := db.pebbleDB.NewIter(&pebble.IterOptions{})

if !it.Last() {
// The database is empty.
return it.Close()
}

end = it.Key()
end = slices.Clone(it.Key())
if err := it.Close(); err != nil {
return err
}
Expand Down Expand Up @@ -273,7 +263,7 @@ func keyRange(start, prefix []byte) *pebble.IterOptions {
LowerBound: prefix,
UpperBound: prefixToUpperBound(prefix),
}
if bytes.Compare(start, prefix) == 1 {
if pebble.DefaultComparer.Compare(start, prefix) == 1 {
opt.LowerBound = start
}
return opt
Expand Down
2 changes: 1 addition & 1 deletion database/pebble/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func newDB(t testing.TB) *Database {
folder := t.TempDir()
db, err := New(folder, DefaultConfigBytes, logging.NoLog{}, "pebble", prometheus.NewRegistry())
db, err := New(folder, nil, logging.NoLog{}, "pebble", prometheus.NewRegistry())
require.NoError(t, err)
return db.(*Database)
}
Expand Down
17 changes: 11 additions & 6 deletions database/pebble/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
var (
_ database.Iterator = (*iter)(nil)

errCouldntGetValue = errors.New("couldnt get iterator value")
errCouldNotGetValue = errors.New("could not get iterator value")
)

type iter struct {
Expand Down Expand Up @@ -63,16 +63,16 @@ func (it *iter) Next() bool {
return false
}

it.nextKey = it.iter.Key()

var err error
it.nextVal, err = it.iter.ValueAndErr()
key := it.iter.Key()
value, err := it.iter.ValueAndErr()
if err != nil {
it.hasNext = false
it.err = fmt.Errorf("%w: %w", errCouldntGetValue, err)
it.err = fmt.Errorf("%w: %w", errCouldNotGetValue, err)
return false
}

it.nextKey = key
it.nextVal = value
return true
}

Expand Down Expand Up @@ -122,6 +122,11 @@ func (it *iter) release() {
return
}

// Cloning these values ensures that calling it.Key() or it.Value() after
// releasing the iterator will not segfault.
it.nextKey = slices.Clone(it.nextKey)
it.nextVal = slices.Clone(it.nextVal)

// Remove the iterator from the list of open iterators.
it.db.openIterators.Remove(it)

Expand Down
4 changes: 2 additions & 2 deletions network/ip_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ func (i *ipTracker) GetGossipableIPs(

uniform.Initialize(uint64(len(i.gossipableIPs)))
for len(ips) < maxNumIPs {
index, err := uniform.Next()
if err != nil {
index, hasNext := uniform.Next()
if !hasNext {
return ips
}

Expand Down
4 changes: 2 additions & 2 deletions network/p2p/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func (v *Validators) Sample(ctx context.Context, limit int) []ids.NodeID {

uniform.Initialize(uint64(len(v.validatorList)))
for len(sampled) < limit {
i, err := uniform.Next()
if err != nil {
i, hasNext := uniform.Next()
if !hasNext {
break
}

Expand Down
4 changes: 2 additions & 2 deletions network/peer/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func (s *peerSet) Sample(n int, precondition func(Peer) bool) []Peer {

peers := make([]Peer, 0, n)
for len(peers) < n {
index, err := sampler.Next()
if err != nil {
index, hasNext := sampler.Next()
if !hasNext {
// We have run out of peers to attempt to sample.
break
}
Expand Down
3 changes: 1 addition & 2 deletions network/peer/tls_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
// It is safe, and typically expected, for [keyLogWriter] to be [nil].
// [keyLogWriter] should only be enabled for debugging.
func TLSConfig(cert tls.Certificate, keyLogWriter io.Writer) *tls.Config {
// #nosec G402
return &tls.Config{
Certificates: []tls.Certificate{cert},
ClientAuth: tls.RequireAnyClientCert,
Expand All @@ -24,7 +23,7 @@ func TLSConfig(cert tls.Certificate, keyLogWriter io.Writer) *tls.Config {
//
// During our security audit by Quantstamp, this was investigated
// and confirmed to be safe and correct.
InsecureSkipVerify: true,
InsecureSkipVerify: true, //#nosec G402
MinVersion: tls.VersionTLS13,
KeyLogWriter: keyLogWriter,
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fi
TESTS=${TESTS:-"golangci_lint license_header require_error_is_no_funcs_as_params single_import interface_compliance_nil require_no_error_inline_func"}

function test_golangci_lint {
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.1
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.58.1
golangci-lint run --config .golangci.yml
}

Expand Down
Loading

0 comments on commit a16c79a

Please sign in to comment.