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

fix(sync): remove ReachabilityStatus from agent info #956

Merged
merged 3 commits into from
Jan 24, 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
4 changes: 2 additions & 2 deletions sync/bundle/message/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ type HelloMessage struct {
}

func NewHelloMessage(pid peer.ID, moniker string,
height uint32, services service.Services, blockHash, genesisHash hash.Hash, reachability string,
height uint32, services service.Services, blockHash, genesisHash hash.Hash,
) *HelloMessage {
return &HelloMessage{
PeerID: pid,
Agent: fmt.Sprintf("%v/reachability=%v", version.Agent(), reachability),
Agent: version.Agent(),
Moniker: moniker,
GenesisHash: genesisHash,
BlockHash: blockHash,
Expand Down
10 changes: 5 additions & 5 deletions sync/bundle/message/hello_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestHelloMessage(t *testing.T) {

t.Run("Invalid signature", func(t *testing.T) {
valKey := ts.RandValKey()
m := NewHelloMessage(ts.RandPeerID(), "Oscar", 100, 0, ts.RandHash(), ts.RandHash(), "public")
m := NewHelloMessage(ts.RandPeerID(), "Oscar", 100, 0, ts.RandHash(), ts.RandHash())
m.Sign([]*bls.ValidatorKey{valKey})
m.Signature = ts.RandBLSSignature()

Expand All @@ -30,7 +30,7 @@ func TestHelloMessage(t *testing.T) {

t.Run("Signature is nil", func(t *testing.T) {
valKey := ts.RandValKey()
m := NewHelloMessage(ts.RandPeerID(), "Oscar", 100, 0, ts.RandHash(), ts.RandHash(), "public")
m := NewHelloMessage(ts.RandPeerID(), "Oscar", 100, 0, ts.RandHash(), ts.RandHash())
m.Sign([]*bls.ValidatorKey{valKey})
m.Signature = nil

Expand All @@ -39,7 +39,7 @@ func TestHelloMessage(t *testing.T) {

t.Run("PublicKeys are empty", func(t *testing.T) {
valKey := ts.RandValKey()
m := NewHelloMessage(ts.RandPeerID(), "Oscar", 100, 0, ts.RandHash(), ts.RandHash(), "public")
m := NewHelloMessage(ts.RandPeerID(), "Oscar", 100, 0, ts.RandHash(), ts.RandHash())
m.Sign([]*bls.ValidatorKey{valKey})
m.PublicKeys = make([]*bls.PublicKey, 0)

Expand All @@ -50,15 +50,15 @@ func TestHelloMessage(t *testing.T) {
time1 := time.Now()
myTimeUnixMilli := time1.UnixMilli()

m := NewHelloMessage(ts.RandPeerID(), "Alice", 100, 0, ts.RandHash(), ts.RandHash(), "public")
m := NewHelloMessage(ts.RandPeerID(), "Alice", 100, 0, ts.RandHash(), ts.RandHash())

assert.LessOrEqual(t, m.MyTimeUnixMilli, time.Now().UnixMilli())
assert.GreaterOrEqual(t, m.MyTimeUnixMilli, myTimeUnixMilli)
})

t.Run("Ok", func(t *testing.T) {
valKey := ts.RandValKey()
m := NewHelloMessage(ts.RandPeerID(), "Alice", 100, 0, ts.RandHash(), ts.RandHash(), "public")
m := NewHelloMessage(ts.RandPeerID(), "Alice", 100, 0, ts.RandHash(), ts.RandHash())
m.Sign([]*bls.ValidatorKey{valKey})

assert.NoError(t, m.BasicCheck())
Expand Down
12 changes: 6 additions & 6 deletions sync/handler_hello_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestParsingHelloMessages(t *testing.T) {
valKey := td.RandValKey()
pid := td.RandPeerID()
msg := message.NewHelloMessage(pid, "unknown-peer", 0, 0,
td.state.LastBlockHash(), td.state.Genesis().Hash(), "public")
td.state.LastBlockHash(), td.state.Genesis().Hash())
msg.Sign([]*bls.ValidatorKey{valKey})

from := td.RandPeerID()
Expand All @@ -39,7 +39,7 @@ func TestParsingHelloMessages(t *testing.T) {
valKey := td.RandValKey()
pid := td.RandPeerID()
msg := message.NewHelloMessage(pid, "bad-genesis", 0, 0,
td.state.LastBlockHash(), invGenHash, "public")
td.state.LastBlockHash(), invGenHash)
msg.Sign([]*bls.ValidatorKey{valKey})

assert.NoError(t, td.receivingNewMessage(td.sync, msg, pid))
Expand All @@ -54,7 +54,7 @@ func TestParsingHelloMessages(t *testing.T) {
height := td.RandUint32NonZero(td.state.LastBlockHeight())
pid := td.RandPeerID()
msg := message.NewHelloMessage(pid, "kitty", height, service.New(service.Network),
td.state.LastBlockHash(), td.state.Genesis().Hash(), "public")
td.state.LastBlockHash(), td.state.Genesis().Hash())
msg.Sign([]*bls.ValidatorKey{valKey})

msg.MyTimeUnixMilli = msg.MyTime().Add(-10 * time.Second).UnixMilli()
Expand All @@ -70,7 +70,7 @@ func TestParsingHelloMessages(t *testing.T) {
height := td.RandUint32NonZero(td.state.LastBlockHeight())
pid := td.RandPeerID()
msg := message.NewHelloMessage(pid, "kitty", height, service.New(service.Network),
td.state.LastBlockHash(), td.state.Genesis().Hash(), "public")
td.state.LastBlockHash(), td.state.Genesis().Hash())
msg.Sign([]*bls.ValidatorKey{valKey})

msg.MyTimeUnixMilli = msg.MyTime().Add(20 * time.Second).UnixMilli()
Expand All @@ -86,7 +86,7 @@ func TestParsingHelloMessages(t *testing.T) {
height := td.RandUint32NonZero(td.state.LastBlockHeight())
pid := td.RandPeerID()
msg := message.NewHelloMessage(pid, "kitty", height, service.New(service.Network),
td.state.LastBlockHash(), td.state.Genesis().Hash(), "public")
td.state.LastBlockHash(), td.state.Genesis().Hash())
msg.Sign([]*bls.ValidatorKey{valKey})

assert.NoError(t, td.receivingNewMessage(td.sync, msg, pid))
Expand All @@ -99,7 +99,7 @@ func TestParsingHelloMessages(t *testing.T) {

pub := valKey.PublicKey()
assert.Equal(t, p.Status, peerset.StatusCodeKnown)
assert.Equal(t, p.Agent, version.Agent()+"/reachability=public")
assert.Equal(t, p.Agent, version.Agent())
assert.Equal(t, p.Moniker, "kitty")
assert.Contains(t, p.ConsensusKeys, pub)
assert.Equal(t, p.PeerID, pid)
Expand Down
1 change: 0 additions & 1 deletion sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ func (sync *synchronizer) sayHello(to peer.ID) {
sync.config.Services(),
sync.state.LastBlockHash(),
sync.state.Genesis().Hash(),
sync.network.ReachabilityStatus(),
)
msg.Sign(sync.valKeys)

Expand Down
3 changes: 1 addition & 2 deletions www/grpc/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package grpc

import (
"context"
"fmt"
"unsafe"

"github.com/fxamacker/cbor/v2"
Expand Down Expand Up @@ -42,7 +41,7 @@ func (s *networkServer) GetNodeInfo(_ context.Context,

return &pactus.GetNodeInfoResponse{
Moniker: s.sync.Moniker(),
Agent: fmt.Sprintf("%s/reachability=%s", version.Agent(), s.net.ReachabilityStatus()),
Agent: version.Agent(),
PeerId: []byte(s.sync.SelfID()),
Reachability: s.net.ReachabilityStatus(),
Addrs: s.net.HostAddrs(),
Expand Down
3 changes: 1 addition & 2 deletions www/grpc/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package grpc

import (
"context"
"fmt"
"testing"

"github.com/libp2p/go-libp2p/core/peer"
Expand Down Expand Up @@ -55,7 +54,7 @@ func TestGetNodeInfo(t *testing.T) {
&pactus.GetNodeInfoRequest{})
assert.NoError(t, err)
assert.Nil(t, err)
assert.Equal(t, fmt.Sprintf("%v/reachability=%v", version.Agent(), "Unknown"), res.Agent)
assert.Equal(t, version.Agent(), res.Agent)
assert.Equal(t, []byte(td.mockSync.SelfID()), res.PeerId)
assert.Equal(t, "test-moniker", res.Moniker)

Expand Down
Loading