Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into discon_restart
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Laine committed Nov 16, 2020
2 parents 3db6f5b + 4eac78d commit 47b2928
Show file tree
Hide file tree
Showing 14 changed files with 554 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .ci/run_e2e_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ echo "Using Avalanche Image: $AVALANCHE_IMAGE"

DOCKER_REPO="avaplatform"
BYZANTINE_IMAGE="$DOCKER_REPO/avalanche-byzantine:v0.1.3-rc.1"
TEST_SUITE_IMAGE="$DOCKER_REPO/avalanche-testing:v0.10.1-rc.1"
TEST_SUITE_IMAGE="$DOCKER_REPO/avalanche-testing:v0.10.2"

# If Docker Credentials are not available skip the Byzantine Tests
if [[ -z ${DOCKER_USERNAME} ]]; then
Expand All @@ -21,7 +21,7 @@ else
fi

# Kurtosis Environment Parameters
KURTOSIS_CORE_CHANNEL="master"
KURTOSIS_CORE_CHANNEL="1.0.3"
INITIALIZER_IMAGE="kurtosistech/kurtosis-core_initializer:${KURTOSIS_CORE_CHANNEL}"
API_IMAGE="kurtosistech/kurtosis-core_api:${KURTOSIS_CORE_CHANNEL}"
PARALLELISM=4
Expand Down
7 changes: 5 additions & 2 deletions network/conn_meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ func NewConnMeter(resetDuration time.Duration, size int) ConnMeter {
if resetDuration == 0 {
return &noConnMeter{}
}
return &connMeter{cache: &cache.LRU{Size: size}}
return &connMeter{
cache: &cache.LRU{Size: size},
resetDuration: resetDuration,
}
}

type noConnMeter struct{}
Expand All @@ -36,9 +39,9 @@ func (n *noConnMeter) Register(addr string) (int, error) {

// connMeter implements ConnMeter
type connMeter struct {
lock sync.RWMutex
cache *cache.LRU
resetDuration time.Duration
lock sync.RWMutex
}

func (n *connMeter) Register(addr string) (int, error) {
Expand Down
61 changes: 61 additions & 0 deletions network/conn_meter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package network

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
)

const (
localhost = "127.0.0.1:9651"
)

func TestNoConnMeter(t *testing.T) {
m := NewConnMeter(0, 1)

count, err := m.Register(localhost)
assert.NoError(t, err)
assert.Equal(t, 0, count)

count, err = m.Register(localhost)
assert.NoError(t, err)
assert.Equal(t, 0, count)
}

func TestConnMeter(t *testing.T) {
m := NewConnMeter(time.Hour, 1)

count, err := m.Register(localhost)
assert.NoError(t, err)
assert.Equal(t, 0, count)

count, err = m.Register(localhost)
assert.NoError(t, err)
assert.Equal(t, 1, count)
}

func TestConnMeterReplace(t *testing.T) {
remote := "127.0.0.2:9651"
differentPort := "127.0.0.1:9650"
m := NewConnMeter(time.Hour, 1)

count, err := m.Register(localhost)
assert.NoError(t, err)
assert.Equal(t, 0, count)

count, err = m.Register(differentPort)
assert.NoError(t, err)
assert.Equal(t, 1, count)

count, err = m.Register(remote)
assert.NoError(t, err)
assert.Equal(t, 0, count)

count, err = m.Register(localhost)
assert.NoError(t, err)
assert.Equal(t, 0, count)
}
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var (
genesisHashKey = []byte("genesisID")

// Version is the version of this code
Version = version.NewDefaultVersion(constants.PlatformName, 1, 0, 4)
Version = version.NewDefaultVersion(constants.PlatformName, 1, 0, 5)
versionParser = version.NewDefaultParser()
beaconConnectionTimeout = 1 * time.Minute
)
Expand Down
89 changes: 89 additions & 0 deletions utils/formatting/encoding_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package formatting

import (
"fmt"
"math/rand"
"testing"
)

func BenchmarkEncodings(b *testing.B) {
benchmarks := []struct {
encoding string
size int
}{
{
encoding: CB58Encoding,
size: 1 << 10, // 1kb
},
{
encoding: CB58Encoding,
size: 1 << 11, // 2kb
},
{
encoding: CB58Encoding,
size: 1 << 12, // 4kb
},
{
encoding: CB58Encoding,
size: 1 << 13, // 8kb
},
{
encoding: CB58Encoding,
size: 1 << 14, // 16kb
},
{
encoding: CB58Encoding,
size: 1 << 15, // 32kb
},
{
encoding: HexEncoding,
size: 1 << 10, // 1kb
},
{
encoding: HexEncoding,
size: 1 << 12, // 4kb
},
{
encoding: HexEncoding,
size: 1 << 15, // 32kb
},
{
encoding: HexEncoding,
size: 1 << 17, // 128kb
},
{
encoding: HexEncoding,
size: 1 << 18, // 256kb
},
{
encoding: HexEncoding,
size: 1 << 19, // 512kb
},
{
encoding: HexEncoding,
size: 1 << 20, // 1mb
},
{
encoding: HexEncoding,
size: 1 << 21, // 2mb
},
{
encoding: HexEncoding,
size: 1 << 22, // 4mb
},
}
manager, _ := NewEncodingManager(HexEncoding)
for _, benchmark := range benchmarks {
enc, _ := manager.GetEncoding(benchmark.encoding)
bytes := make([]byte, benchmark.size)
_, _ = rand.Read(bytes) // #nosec G404
b.Run(fmt.Sprintf("%s-%d bytes", benchmark.encoding, benchmark.size), func(b *testing.B) {
for n := 0; n < b.N; n++ {
_ = enc.ConvertBytes(bytes)
}
})
}
}
5 changes: 3 additions & 2 deletions vms/avm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func (service *Service) GetUTXOs(r *http.Request, args *GetUTXOsArgs, reply *Get
startAddr,
startUTXO,
int(args.Limit),
true,
)
} else {
utxos, endAddr, endUTXOID, err = service.vm.GetAtomicUTXOs(
Expand Down Expand Up @@ -336,7 +337,7 @@ func (service *Service) GetBalance(r *http.Request, args *GetBalanceArgs, reply
addrSet := ids.ShortSet{}
addrSet.Add(addr)

utxos, _, _, err := service.vm.GetUTXOs(addrSet, ids.ShortEmpty, ids.Empty, -1)
utxos, _, _, err := service.vm.GetUTXOs(addrSet, ids.ShortEmpty, ids.Empty, -1, false)
if err != nil {
return fmt.Errorf("problem retrieving UTXOs: %w", err)
}
Expand Down Expand Up @@ -387,7 +388,7 @@ func (service *Service) GetAllBalances(r *http.Request, args *api.JSONAddress, r
addrSet := ids.ShortSet{}
addrSet.Add(address)

utxos, _, _, err := service.vm.GetUTXOs(addrSet, ids.ShortEmpty, ids.Empty, -1)
utxos, _, _, err := service.vm.GetUTXOs(addrSet, ids.ShortEmpty, ids.Empty, -1, false)
if err != nil {
return fmt.Errorf("couldn't get address's UTXOs: %w", err)
}
Expand Down
46 changes: 28 additions & 18 deletions vms/avm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ func (vm *VM) GetUTXOs(
startAddr ids.ShortID,
startUTXOID ids.ID,
limit int,
paginate bool,
) ([]*avax.UTXO, ids.ShortID, ids.ID, error) {
if limit <= 0 || limit > maxUTXOsToFetch {
limit = maxUTXOsToFetch
Expand All @@ -495,26 +496,34 @@ func (vm *VM) GetUTXOs(
} else if comp == 0 {
start = startUTXOID
}
utxoIDs, err := vm.state.Funds(addr.Bytes(), start, limit) // Get UTXOs associated with [addr]
if err != nil {
return nil, ids.ShortID{}, ids.ID{}, fmt.Errorf("couldn't get UTXOs for address %s", addr)
}
for _, utxoID := range utxoIDs {
if seen.Contains(utxoID) { // Already have this UTXO in the list
continue
}
utxo, err := vm.state.UTXO(utxoID)
for {
currLimit := limit
utxoIDs, err := vm.state.Funds(addr.Bytes(), start, limit) // Get UTXOs associated with [addr]
if err != nil {
return nil, ids.ShortID{}, ids.ID{}, fmt.Errorf("couldn't get UTXO %s: %w", utxoID, err)
return nil, ids.ShortID{}, ids.ID{}, fmt.Errorf("couldn't get UTXOs for address %s: %w", addr, err)
}
utxos = append(utxos, utxo)
seen.Add(utxoID)
lastAddr = addr
lastIndex = utxoID
limit--
if limit <= 0 {
break // Found [limit] utxos; stop.
for _, utxoID := range utxoIDs {
if seen.Contains(utxoID) { // Already have this UTXO in the list
continue
}
utxo, err := vm.state.UTXO(utxoID)
if err != nil {
return nil, ids.ShortID{}, ids.ID{}, fmt.Errorf("couldn't get UTXO %s: %w", utxoID, err)
}
utxos = append(utxos, utxo)
seen.Add(utxoID)
lastAddr = addr
lastIndex = utxoID
currLimit--
if currLimit <= 0 {
break // Found [currLimit] utxos; stop current set.
}
}

if paginate || len(utxoIDs) == 0 { // Avoiding a downstream make([]) making this an infinite loop
break // No more utxos available for that address | Don't fetch more utxos
}
start = utxoIDs[len(utxoIDs)-1]
}
}
return utxos, lastAddr, lastIndex, nil
Expand Down Expand Up @@ -824,12 +833,13 @@ func (vm *VM) LoadUser(
defer db.Close()

user := userState{vm: vm}

kc, err := user.Keychain(db, addrsToUse)
if err != nil {
return nil, nil, err
}

utxos, _, _, err := vm.GetUTXOs(kc.Addresses(), ids.ShortEmpty, ids.Empty, -1)
utxos, _, _, err := vm.GetUTXOs(kc.Addresses(), ids.ShortEmpty, ids.Empty, -1, false)
if err != nil {
return nil, nil, fmt.Errorf("problem retrieving user's UTXOs: %w", err)
}
Expand Down
Loading

0 comments on commit 47b2928

Please sign in to comment.