Skip to content
Merged
6 changes: 3 additions & 3 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ func (n *Node) initNetworking() error {
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
ClientAuth: tls.RequireAnyClientCert,
// We do not use TLS's CA functionality, we just require an
// authenticated channel. Therefore, we can safely skip verification
// here.
// We do not use TLS's CA functionality to authenticate a hostname.
// We only require an authenticated channel based on the peer's
// public key. Therefore, we can safely skip CA verification.
//
// TODO: Security audit required
InsecureSkipVerify: true,
Expand Down
2 changes: 1 addition & 1 deletion snow/consensus/avalanche/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Consensus interface {
// called, the status maps should be immediately updated accordingly.
// Assumes each element in the accepted frontier will return accepted from
// the join status map.
Initialize(*snow.Context, Parameters, []Vertex)
Initialize(*snow.Context, Parameters, []Vertex) error

// Returns the parameters that describe this avalanche instance
Parameters() Parameters
Expand Down
77 changes: 46 additions & 31 deletions snow/consensus/avalanche/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,21 @@ func ParamsTest(t *testing.T, factory Factory) {
ctx := snow.DefaultContextTest()
params := Parameters{
Parameters: snowball.Parameters{
Namespace: fmt.Sprintf("gecko_%s", ctx.ChainID.String()),
Metrics: prometheus.NewRegistry(),
K: 2,
Alpha: 2,
BetaVirtuous: 1,
BetaRogue: 2,
Namespace: fmt.Sprintf("gecko_%s", ctx.ChainID.String()),
Metrics: prometheus.NewRegistry(),
K: 2,
Alpha: 2,
BetaVirtuous: 1,
BetaRogue: 2,
ConcurrentRepolls: 1,
},
Parents: 2,
BatchSize: 1,
}

avl.Initialize(ctx, params, nil)
if err := avl.Initialize(ctx, params, nil); err != nil {
t.Fatal(err)
}

if p := avl.Parameters(); p.K != params.K {
t.Fatalf("Wrong K parameter")
Expand All @@ -153,11 +156,12 @@ func AddTest(t *testing.T, factory Factory) {

params := Parameters{
Parameters: snowball.Parameters{
Metrics: prometheus.NewRegistry(),
K: 2,
Alpha: 2,
BetaVirtuous: 1,
BetaRogue: 2,
Metrics: prometheus.NewRegistry(),
K: 2,
Alpha: 2,
BetaVirtuous: 1,
BetaRogue: 2,
ConcurrentRepolls: 1,
},
Parents: 2,
BatchSize: 1,
Expand All @@ -174,7 +178,9 @@ func AddTest(t *testing.T, factory Factory) {
}
utxos := []ids.ID{ids.GenerateTestID()}

avl.Initialize(snow.DefaultContextTest(), params, vts)
if err := avl.Initialize(snow.DefaultContextTest(), params, vts); err != nil {
t.Fatal(err)
}

if !avl.Finalized() {
t.Fatalf("An empty avalanche instance is not finalized")
Expand Down Expand Up @@ -248,11 +254,12 @@ func VertexIssuedTest(t *testing.T, factory Factory) {

params := Parameters{
Parameters: snowball.Parameters{
Metrics: prometheus.NewRegistry(),
K: 2,
Alpha: 2,
BetaVirtuous: 1,
BetaRogue: 2,
Metrics: prometheus.NewRegistry(),
K: 2,
Alpha: 2,
BetaVirtuous: 1,
BetaRogue: 2,
ConcurrentRepolls: 1,
},
Parents: 2,
BatchSize: 1,
Expand All @@ -269,7 +276,9 @@ func VertexIssuedTest(t *testing.T, factory Factory) {
}
utxos := []ids.ID{ids.GenerateTestID()}

avl.Initialize(snow.DefaultContextTest(), params, vts)
if err := avl.Initialize(snow.DefaultContextTest(), params, vts); err != nil {
t.Fatal(err)
}

if !avl.VertexIssued(vts[0]) {
t.Fatalf("Genesis Vertex not reported as issued")
Expand Down Expand Up @@ -305,11 +314,12 @@ func TxIssuedTest(t *testing.T, factory Factory) {

params := Parameters{
Parameters: snowball.Parameters{
Metrics: prometheus.NewRegistry(),
K: 2,
Alpha: 2,
BetaVirtuous: 1,
BetaRogue: 2,
Metrics: prometheus.NewRegistry(),
K: 2,
Alpha: 2,
BetaVirtuous: 1,
BetaRogue: 2,
ConcurrentRepolls: 1,
},
Parents: 2,
BatchSize: 1,
Expand All @@ -334,7 +344,9 @@ func TxIssuedTest(t *testing.T, factory Factory) {
}}
tx1.InputIDsV.Add(utxos[0])

avl.Initialize(snow.DefaultContextTest(), params, vts)
if err := avl.Initialize(snow.DefaultContextTest(), params, vts); err != nil {
t.Fatal(err)
}

if !avl.TxIssued(tx0) {
t.Fatalf("Genesis Tx not reported as issued")
Expand Down Expand Up @@ -675,11 +687,12 @@ func IgnoreInvalidVotingTest(t *testing.T, factory Factory) {

params := Parameters{
Parameters: snowball.Parameters{
Metrics: prometheus.NewRegistry(),
K: 3,
Alpha: 2,
BetaVirtuous: 1,
BetaRogue: 1,
Metrics: prometheus.NewRegistry(),
K: 3,
Alpha: 2,
BetaVirtuous: 1,
BetaRogue: 1,
ConcurrentRepolls: 1,
},
Parents: 2,
BatchSize: 1,
Expand All @@ -697,7 +710,9 @@ func IgnoreInvalidVotingTest(t *testing.T, factory Factory) {
}
utxos := []ids.ID{ids.GenerateTestID()}

avl.Initialize(snow.DefaultContextTest(), params, vts)
if err := avl.Initialize(snow.DefaultContextTest(), params, vts); err != nil {
t.Fatal(err)
}

tx0 := &snowstorm.TestTx{TestDecidable: choices.TestDecidable{
IDV: ids.GenerateTestID(),
Expand Down
18 changes: 13 additions & 5 deletions snow/consensus/avalanche/topological.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,34 @@ type kahnNode struct {
}

// Initialize implements the Avalanche interface
func (ta *Topological) Initialize(ctx *snow.Context, params Parameters, frontier []Vertex) {
ctx.Log.AssertDeferredNoError(params.Valid)
func (ta *Topological) Initialize(
ctx *snow.Context,
params Parameters,
frontier []Vertex,
) error {
if err := params.Valid(); err != nil {
return err
}

ta.ctx = ctx
ta.params = params

if err := ta.metrics.Initialize(ctx.Log, params.Namespace, params.Metrics); err != nil {
ta.ctx.Log.Error("%s", err)
return err
}

ta.nodes = make(map[[32]byte]Vertex, minMapSize)

ta.cg = &snowstorm.Directed{}
ta.cg.Initialize(ctx, params.Parameters)
if err := ta.cg.Initialize(ctx, params.Parameters); err != nil {
return err
}

ta.frontier = make(map[[32]byte]Vertex, minMapSize)
for _, vtx := range frontier {
ta.frontier[vtx.ID().Key()] = vtx
}
ctx.Log.AssertNoError(ta.updateFrontiers())
return ta.updateFrontiers()
}

// Parameters implements the Avalanche interface
Expand Down
20 changes: 10 additions & 10 deletions snow/consensus/snowstorm/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (

"github.com/prometheus/client_golang/prometheus"

"github.com/ava-labs/gecko/snow/consensus/snowball"
sbcon "github.com/ava-labs/gecko/snow/consensus/snowball"
)

func Simulate(
numColors, colorsPerConsumer, maxInputConflicts, numNodes int,
params snowball.Parameters,
params sbcon.Parameters,
seed int64,
fact Factory,
) {
Expand Down Expand Up @@ -53,7 +53,7 @@ func BenchmarkVirtuousDirected(b *testing.B) {
/*colorsPerConsumer=*/ 1,
/*maxInputConflicts=*/ 1,
/*numNodes=*/ 50,
/*params=*/ snowball.Parameters{
/*params=*/ sbcon.Parameters{
Metrics: prometheus.NewRegistry(),
K: 20,
Alpha: 11,
Expand All @@ -73,7 +73,7 @@ func BenchmarkVirtuousInput(b *testing.B) {
/*colorsPerConsumer=*/ 1,
/*maxInputConflicts=*/ 1,
/*numNodes=*/ 50,
/*params=*/ snowball.Parameters{
/*params=*/ sbcon.Parameters{
Metrics: prometheus.NewRegistry(),
K: 20,
Alpha: 11,
Expand All @@ -99,7 +99,7 @@ func BenchmarkRogueDirected(b *testing.B) {
/*colorsPerConsumer=*/ 1,
/*maxInputConflicts=*/ 3,
/*numNodes=*/ 50,
/*params=*/ snowball.Parameters{
/*params=*/ sbcon.Parameters{
Metrics: prometheus.NewRegistry(),
K: 20,
Alpha: 11,
Expand All @@ -119,7 +119,7 @@ func BenchmarkRogueInput(b *testing.B) {
/*colorsPerConsumer=*/ 1,
/*maxInputConflicts=*/ 3,
/*numNodes=*/ 50,
/*params=*/ snowball.Parameters{
/*params=*/ sbcon.Parameters{
Metrics: prometheus.NewRegistry(),
K: 20,
Alpha: 11,
Expand All @@ -145,7 +145,7 @@ func BenchmarkMultiDirected(b *testing.B) {
/*colorsPerConsumer=*/ 10,
/*maxInputConflicts=*/ 1,
/*numNodes=*/ 50,
/*params=*/ snowball.Parameters{
/*params=*/ sbcon.Parameters{
Metrics: prometheus.NewRegistry(),
K: 20,
Alpha: 11,
Expand All @@ -165,7 +165,7 @@ func BenchmarkMultiInput(b *testing.B) {
/*colorsPerConsumer=*/ 10,
/*maxInputConflicts=*/ 1,
/*numNodes=*/ 50,
/*params=*/ snowball.Parameters{
/*params=*/ sbcon.Parameters{
Metrics: prometheus.NewRegistry(),
K: 20,
Alpha: 11,
Expand All @@ -191,7 +191,7 @@ func BenchmarkMultiRogueDirected(b *testing.B) {
/*colorsPerConsumer=*/ 10,
/*maxInputConflicts=*/ 3,
/*numNodes=*/ 50,
/*params=*/ snowball.Parameters{
/*params=*/ sbcon.Parameters{
Metrics: prometheus.NewRegistry(),
K: 20,
Alpha: 11,
Expand All @@ -211,7 +211,7 @@ func BenchmarkMultiRogueInput(b *testing.B) {
/*colorsPerConsumer=*/ 10,
/*maxInputConflicts=*/ 3,
/*numNodes=*/ 50,
/*params=*/ snowball.Parameters{
/*params=*/ sbcon.Parameters{
Metrics: prometheus.NewRegistry(),
K: 20,
Alpha: 11,
Expand Down
39 changes: 32 additions & 7 deletions snow/consensus/snowstorm/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
package snowstorm

import (
"fmt"

"github.com/ava-labs/gecko/ids"
"github.com/ava-labs/gecko/snow"
"github.com/ava-labs/gecko/snow/consensus/snowball"
"github.com/ava-labs/gecko/snow/events"
"github.com/ava-labs/gecko/utils/wrappers"

sbcon "github.com/ava-labs/gecko/snow/consensus/snowball"
)

type common struct {
Expand All @@ -19,7 +22,7 @@ type common struct {
ctx *snow.Context

// params describes how this instance was parameterized
params snowball.Parameters
params sbcon.Parameters

// each element of preferences is the ID of a transaction that is preferred
preferences ids.Set
Expand All @@ -44,19 +47,18 @@ type common struct {
}

// Initialize implements the ConflictGraph interface
func (c *common) Initialize(ctx *snow.Context, params snowball.Parameters) {
ctx.Log.AssertDeferredNoError(params.Valid)

func (c *common) Initialize(ctx *snow.Context, params sbcon.Parameters) error {
c.ctx = ctx
c.params = params

if err := c.metrics.Initialize(params.Namespace, params.Metrics); err != nil {
ctx.Log.Error("failed to initialize metrics: %s", err)
return fmt.Errorf("failed to initialize metrics: %s", err)
}
return params.Valid()
}

// Parameters implements the Snowstorm interface
func (c *common) Parameters() snowball.Parameters { return c.params }
func (c *common) Parameters() sbcon.Parameters { return c.params }

// Virtuous implements the ConflictGraph interface
func (c *common) Virtuous() ids.Set { return c.virtuous }
Expand All @@ -79,3 +81,26 @@ func (c *common) Finalized() bool {
numPreferences)
return numPreferences == 0
}

// rejector implements Blockable
type rejector struct {
g Consensus
deps ids.Set
errs *wrappers.Errs
rejected bool // true if the tx has been rejected
txID ids.ID
}

func (r *rejector) Dependencies() ids.Set { return r.deps }

func (r *rejector) Fulfill(ids.ID) {
if r.rejected || r.errs.Errored() {
return
}
r.rejected = true
r.errs.Add(r.g.reject(r.txID))
}

func (*rejector) Abandon(ids.ID) {}

func (*rejector) Update() {}
Loading