Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pre-Durango checks in BLS key verification #2824

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions network/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,22 +716,14 @@ func (p *peer) shouldDisconnect() bool {
return false
}

postDurango := p.Clock.Time().After(version.GetDurangoTime(constants.MainnetID))
if postDurango && p.ip.BLSSignature == nil {
if p.ip.BLSSignature == nil {
p.Log.Debug("disconnecting from peer",
zap.String("reason", "missing BLS signature"),
zap.Stringer("nodeID", p.id),
)
return true
}

// If Durango hasn't activated on mainnet yet, we don't require BLS
// signatures to be provided. However, if they are provided, verify that
// they are correct.
if p.ip.BLSSignature == nil {
return false
}

validSignature := bls.VerifyProofOfPossession(
vdr.PublicKey,
p.ip.BLSSignature,
Expand Down
91 changes: 3 additions & 88 deletions network/peer/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/ava-labs/avalanchego/utils/math/meter"
"github.com/ava-labs/avalanchego/utils/resource"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
"github.com/ava-labs/avalanchego/version"
)

Expand Down Expand Up @@ -591,14 +590,9 @@ func TestShouldDisconnect(t *testing.T) {
expectedShouldDisconnect: false,
},
{
name: "past durango without a signature",
name: "peer without signature",
initialPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(mockable.MaxTime)
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
Expand All @@ -619,11 +613,6 @@ func TestShouldDisconnect(t *testing.T) {
},
expectedPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(mockable.MaxTime)
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
Expand All @@ -645,68 +634,9 @@ func TestShouldDisconnect(t *testing.T) {
expectedShouldDisconnect: true,
},
{
name: "pre durango without a signature",
name: "peer with invalid signature",
initialPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(time.Time{})
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
vdrs := validators.NewManager()
require.NoError(t, vdrs.AddStaker(
constants.PrimaryNetworkID,
peerID,
bls.PublicFromSecretKey(blsKey),
txID,
1,
))
return vdrs
}(),
},
id: peerID,
version: version.CurrentApp,
ip: &SignedIP{},
},
expectedPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(time.Time{})
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
vdrs := validators.NewManager()
require.NoError(t, vdrs.AddStaker(
constants.PrimaryNetworkID,
peerID,
bls.PublicFromSecretKey(blsKey),
txID,
1,
))
return vdrs
}(),
},
id: peerID,
version: version.CurrentApp,
ip: &SignedIP{},
},
expectedShouldDisconnect: false,
},
{
name: "pre durango with an invalid signature",
initialPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(time.Time{})
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
Expand All @@ -729,11 +659,6 @@ func TestShouldDisconnect(t *testing.T) {
},
expectedPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(time.Time{})
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
Expand All @@ -757,14 +682,9 @@ func TestShouldDisconnect(t *testing.T) {
expectedShouldDisconnect: true,
},
{
name: "pre durango with a valid signature",
name: "peer with valid signature",
initialPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(time.Time{})
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
Expand All @@ -787,11 +707,6 @@ func TestShouldDisconnect(t *testing.T) {
},
expectedPeer: &peer{
Config: &Config{
Clock: func() mockable.Clock {
clk := mockable.Clock{}
clk.Set(time.Time{})
return clk
}(),
Log: logging.NoLog{},
VersionCompatibility: version.GetCompatibility(constants.UnitTestID),
Validators: func() validators.Manager {
Expand Down
Loading