Skip to content

Commit

Permalink
Merge branch 'dev' into tmpnet-genesis-bls
Browse files Browse the repository at this point in the history
  • Loading branch information
maru-ava authored Dec 10, 2023
2 parents a669bb8 + 80fa254 commit 64da06f
Show file tree
Hide file tree
Showing 71 changed files with 1,519 additions and 1,195 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/fuzz_merkledb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Scheduled Fuzz Testing

on:
workflow_dispatch:
schedule:
# Run every 6 hours
- cron: "0 0,6,12,18 * * *"

permissions:
contents: read

jobs:
MerkleDB:
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3
with:
ref: 'dev'
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '~1.20.12'
check-latest: true
- name: Run merkledb fuzz tests
shell: bash
run: ./scripts/build_fuzz.sh 900 ./x/merkledb # Run each merkledb fuzz tests 15 minutes
7 changes: 1 addition & 6 deletions network/p2p/gossip/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package gossip

import (
"context"
"errors"
"time"

bloomfilter "github.com/holiman/bloomfilter/v2"
Expand All @@ -20,11 +19,7 @@ import (
"github.com/ava-labs/avalanchego/utils"
)

var (
_ p2p.Handler = (*Handler[Gossipable])(nil)

ErrInvalidID = errors.New("invalid id")
)
var _ p2p.Handler = (*Handler[Gossipable])(nil)

type HandlerConfig struct {
Namespace string
Expand Down
15 changes: 9 additions & 6 deletions node/beacon_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,35 @@
package node

import (
"sync"
"sync/atomic"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/networking/router"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/timer"
"github.com/ava-labs/avalanchego/version"
)

var _ router.Router = (*beaconManager)(nil)

type beaconManager struct {
router.Router
timer *timer.Timer
beacons validators.Manager
requiredConns int64
numConns int64
beacons validators.Manager
requiredConns int64
numConns int64
onSufficientlyConnected chan struct{}
onceOnSufficientlyConnected sync.Once
}

func (b *beaconManager) Connected(nodeID ids.NodeID, nodeVersion *version.Application, subnetID ids.ID) {
_, isBeacon := b.beacons.GetValidator(constants.PrimaryNetworkID, nodeID)
if isBeacon &&
constants.PrimaryNetworkID == subnetID &&
atomic.AddInt64(&b.numConns, 1) >= b.requiredConns {
b.timer.Cancel()
b.onceOnSufficientlyConnected.Do(func() {
close(b.onSufficientlyConnected)
})
}
b.Router.Connected(nodeID, nodeVersion, subnetID)
}
Expand Down
9 changes: 4 additions & 5 deletions node/beacon_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/ava-labs/avalanchego/snow/networking/router"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/timer"
"github.com/ava-labs/avalanchego/version"
)

Expand All @@ -41,10 +40,10 @@ func TestBeaconManager_DataRace(t *testing.T) {
mockRouter := router.NewMockRouter(ctrl)

b := beaconManager{
Router: mockRouter,
timer: timer.NewTimer(nil),
beacons: validatorSet,
requiredConns: numValidators,
Router: mockRouter,
beacons: validatorSet,
requiredConns: numValidators,
onSufficientlyConnected: make(chan struct{}),
}

// connect numValidators validators, each with a weight of 1
Expand Down
39 changes: 21 additions & 18 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ import (
"github.com/ava-labs/avalanchego/utils/profiler"
"github.com/ava-labs/avalanchego/utils/resource"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/utils/timer"
"github.com/ava-labs/avalanchego/version"
"github.com/ava-labs/avalanchego/vms"
"github.com/ava-labs/avalanchego/vms/avm"
Expand Down Expand Up @@ -480,28 +479,32 @@ func (n *Node) initNetworking() error {
requiredConns := (3*numBootstrappers + 3) / 4

if requiredConns > 0 {
// Set a timer that will fire after a given timeout unless we connect
// to a sufficient portion of nodes. If the timeout fires, the node will
// shutdown.
timer := timer.NewTimer(func() {
// If the timeout fires and we're already shutting down, nothing to do.
if !n.shuttingDown.Get() {
onSufficientlyConnected := make(chan struct{})
consensusRouter = &beaconManager{
Router: consensusRouter,
beacons: n.bootstrappers,
requiredConns: int64(requiredConns),
onSufficientlyConnected: onSufficientlyConnected,
}

// Log a warning if we aren't able to connect to a sufficient portion of
// nodes.
go func() {
timer := time.NewTimer(n.Config.BootstrapBeaconConnectionTimeout)
defer timer.Stop()

select {
case <-timer.C:
if n.shuttingDown.Get() {
return
}
n.Log.Warn("failed to connect to bootstrap nodes",
zap.Stringer("bootstrappers", n.bootstrappers),
zap.Duration("duration", n.Config.BootstrapBeaconConnectionTimeout),
)
case <-onSufficientlyConnected:
}
})

go timer.Dispatch()
timer.SetTimeoutIn(n.Config.BootstrapBeaconConnectionTimeout)

consensusRouter = &beaconManager{
Router: consensusRouter,
timer: timer,
beacons: n.bootstrappers,
requiredConns: int64(requiredConns),
}
}()
}

// initialize gossip tracker
Expand Down
3 changes: 3 additions & 0 deletions scripts/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ export CGO_CFLAGS="-O2 -D__BLST_PORTABLE__"
# While CGO_ENABLED doesn't need to be explicitly set, it produces a much more
# clear error due to the default value change in go1.20.
export CGO_ENABLED=1

# Disable version control fallbacks
export GOPROXY="https://proxy.golang.org"
38 changes: 21 additions & 17 deletions snow/consensus/snowball/consensus_performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ import (
func TestDualAlphaOptimization(t *testing.T) {
require := require.New(t)

numColors := 10
numNodes := 100
params := Parameters{
K: 20,
AlphaPreference: 15,
AlphaConfidence: 15,
BetaVirtuous: 15,
BetaRogue: 20,
}
seed := int64(0)
var (
numColors = 10
numNodes = 100
params = Parameters{
K: 20,
AlphaPreference: 15,
AlphaConfidence: 15,
BetaVirtuous: 15,
BetaRogue: 20,
}
seed uint64 = 0
)

singleAlphaNetwork := Network{}
singleAlphaNetwork.Initialize(params, numColors)
Expand Down Expand Up @@ -54,10 +56,12 @@ func TestDualAlphaOptimization(t *testing.T) {
func TestTreeConvergenceOptimization(t *testing.T) {
require := require.New(t)

numColors := 10
numNodes := 100
params := DefaultParameters
seed := int64(0)
var (
numColors = 10
numNodes = 100
params = DefaultParameters
seed uint64 = 0
)

treeNetwork := Network{}
treeNetwork.Initialize(params, numColors)
Expand All @@ -79,13 +83,13 @@ func TestTreeConvergenceOptimization(t *testing.T) {
runNetworksInLockstep(require, seed, &treeNetwork, &flatNetwork)
}

func runNetworksInLockstep(require *require.Assertions, seed int64, fast *Network, slow *Network) {
func runNetworksInLockstep(require *require.Assertions, seed uint64, fast *Network, slow *Network) {
numRounds := 0
for !fast.Finalized() && !fast.Disagreement() && !slow.Finalized() && !slow.Disagreement() {
sampler.Seed(int64(numRounds) + seed)
sampler.Seed(uint64(numRounds) + seed)
fast.Round()

sampler.Seed(int64(numRounds) + seed)
sampler.Seed(uint64(numRounds) + seed)
slow.Round()
numRounds++
}
Expand Down
14 changes: 8 additions & 6 deletions snow/consensus/snowball/consensus_reversibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import (
func TestSnowballGovernance(t *testing.T) {
require := require.New(t)

numColors := 2
numNodes := 100
numByzantine := 10
numRed := 55
params := DefaultParameters
seed := int64(0)
var (
numColors = 2
numNodes = 100
numByzantine = 10
numRed = 55
params = DefaultParameters
seed uint64 = 0
)

nBitwise := Network{}
nBitwise.Initialize(params, numColors)
Expand Down
22 changes: 12 additions & 10 deletions snow/consensus/snowball/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,16 +796,18 @@ func TestSnowballDoubleAdd(t *testing.T) {
func TestSnowballConsistent(t *testing.T) {
require := require.New(t)

numColors := 50
numNodes := 100
params := Parameters{
K: 20,
AlphaPreference: 15,
AlphaConfidence: 15,
BetaVirtuous: 20,
BetaRogue: 30,
}
seed := int64(0)
var (
numColors = 50
numNodes = 100
params = Parameters{
K: 20,
AlphaPreference: 15,
AlphaConfidence: 15,
BetaVirtuous: 20,
BetaRogue: 30,
}
seed uint64 = 0
)

sampler.Seed(seed)

Expand Down
30 changes: 16 additions & 14 deletions snow/consensus/snowman/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1585,20 +1585,22 @@ func ErrorOnTransitiveRejectionTest(t *testing.T, factory Factory) {
func RandomizedConsistencyTest(t *testing.T, factory Factory) {
require := require.New(t)

numColors := 50
numNodes := 100
params := snowball.Parameters{
K: 20,
AlphaPreference: 15,
AlphaConfidence: 15,
BetaVirtuous: 20,
BetaRogue: 30,
ConcurrentRepolls: 1,
OptimalProcessing: 1,
MaxOutstandingItems: 1,
MaxItemProcessingTime: 1,
}
seed := int64(0)
var (
numColors = 50
numNodes = 100
params = snowball.Parameters{
K: 20,
AlphaPreference: 15,
AlphaConfidence: 15,
BetaVirtuous: 20,
BetaRogue: 30,
ConcurrentRepolls: 1,
OptimalProcessing: 1,
MaxOutstandingItems: 1,
MaxItemProcessingTime: 1,
}
seed uint64 = 0
)

sampler.Seed(seed)

Expand Down
Loading

0 comments on commit 64da06f

Please sign in to comment.