Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ava-labs/avalanchego
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: fa51ef2075760c34dc179e483a04042ca54e2113
Choose a base ref
..
head repository: ava-labs/avalanchego
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 17f3d664a07af8f999dd05accb373b0923b3f59c
Choose a head ref
Showing with 27 additions and 25 deletions.
  1. +6 −1 network/acp118/aggregator.go
  2. +7 −6 network/acp118/aggregator_test.go
  3. +5 −2 network/acp118/handler.go
  4. +9 −16 network/acp118/handler_test.go
7 changes: 6 additions & 1 deletion network/acp118/aggregator.go
Original file line number Diff line number Diff line change
@@ -44,7 +44,8 @@ type indexedValidator struct {
I int
}

func NewAggregator(
// NewSignatureAggregator returns an instance of SignatureAggregator
func NewSignatureAggregator(
log logging.Logger,
client *p2p.Client,
maxPending int,
@@ -56,13 +57,17 @@ func NewAggregator(
}
}

// SignatureAggregator aggregates validator signatures for warp messages
type SignatureAggregator struct {
log logging.Logger
client *p2p.Client
codec codec.Codec

Check failure on line 64 in network/acp118/aggregator.go

GitHub Actions / Lint

field `codec` is unused (unused)
maxPending int64
}

// AggregateSignatures blocks until stakeWeightThreshold of validators signs the
// provided message. Validators are issued requests in the caller-specified
// order.
func (s *SignatureAggregator) AggregateSignatures(
parentCtx context.Context,
message *warp.UnsignedMessage,
13 changes: 7 additions & 6 deletions network/acp118/aggregator_test.go
Original file line number Diff line number Diff line change
@@ -62,11 +62,12 @@ func TestVerifier_Verify(t *testing.T) {
},
},
threshold: 1,
handler: NewHandler(&testAttestor{
AttestF: func([]byte, []byte) (bool, error) {
return false, errors.New("foobar")
},
}, signer, networkID, chainID),
handler: NewHandler(
&testAttestor{Err: errors.New("foobar")},
signer,
networkID,
chainID,
),
wantErr: ErrInsufficientSignatures,
},
{
@@ -107,7 +108,7 @@ func TestVerifier_Verify(t *testing.T) {
message, err := warp.NewUnsignedMessage(networkID, chainID, []byte("payload"))
require.NoError(err)
client := p2ptest.NewClient(t, ctx, tt.handler, ids.GenerateTestNodeID(), nodeID0)
verifier := NewAggregator(logging.NoLog{}, client, 1)
verifier := NewSignatureAggregator(logging.NoLog{}, client, 1)

_, err = verifier.AggregateSignatures(
tt.ctx,
7 changes: 5 additions & 2 deletions network/acp118/handler.go
Original file line number Diff line number Diff line change
@@ -19,10 +19,12 @@ import (

var _ p2p.Handler = (*Handler)(nil)

// Attestor defines whether to a warp message payload should be attested to
type Attestor interface {
Attest(message []byte, justification []byte) (bool, error)
Attest(message *warp.UnsignedMessage, justification []byte) (bool, error)
}

// NewHandler returns an instance of Handler
func NewHandler(
attestor Attestor,
signer warp.Signer,
@@ -37,6 +39,7 @@ func NewHandler(
}
}

// Handler signs warp messages
type Handler struct {
p2p.NoOpHandler

@@ -68,7 +71,7 @@ func (h *Handler) AppRequest(
}
}

ok, err := h.attestor.Attest(msg.Payload, request.Justification)
ok, err := h.attestor.Attest(msg, request.Justification)
if err != nil {
return nil, &common.AppError{
Code: p2p.ErrUnexpected.Code,
25 changes: 9 additions & 16 deletions network/acp118/handler_test.go
Original file line number Diff line number Diff line change
@@ -27,18 +27,13 @@ func TestHandler(t *testing.T) {
expectedVerify bool
}{
{
name: "signature fails attestation",
attestor: &testAttestor{AttestF: func([]byte, []byte) (bool, error) {
return false, errors.New("foo")
}},
name: "signature fails attestation",
attestor: &testAttestor{Err: errors.New("foo")},
expectedErr: p2p.ErrUnexpected,
},
{
name: "signature not attested",
attestor: &testAttestor{AttestF: func([]byte, []byte) (bool, error) {
return false, nil

}},
name: "signature not attested",
attestor: &testAttestor{CantAttest: true},
expectedErr: p2p.ErrAttestFailed,
},
{
@@ -112,14 +107,12 @@ func TestHandler(t *testing.T) {

}

Check failure on line 108 in network/acp118/handler_test.go

GitHub Actions / Lint

unnecessary trailing newline (whitespace)

// The zero value of testAttestor attests
type testAttestor struct {
AttestF func([]byte, []byte) (bool, error)
CantAttest bool
Err error
}

func (t testAttestor) Attest(message []byte, justification []byte) (bool, error) {
if t.AttestF != nil {
return t.AttestF(message, justification)
}

return true, nil
func (t testAttestor) Attest(*warp.UnsignedMessage, []byte) (bool, error) {
return !t.CantAttest, t.Err
}