diff --git a/cmd/cmd.go b/cmd/cmd.go index 1a2392364..b59cc6bf5 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -393,17 +393,17 @@ func StartNode(workingDir string, passwordFetcher func(*wallet.Wallet) (string, return nil, nil, err } - nodeInstance, err := node.NewNode(gen, conf, valKeys, rewardAddrs) + nd, err := node.NewNode(gen, conf, valKeys, rewardAddrs) if err != nil { return nil, nil, err } - err = nodeInstance.Start() + err = nd.Start() if err != nil { return nil, nil, err } - return nodeInstance, walletInstance, nil + return nd, walletInstance, nil } // makeLocalGenesis makes genesis file for the local network. diff --git a/cmd/gtk/main.go b/cmd/gtk/main.go index 05b0891f0..451466828 100644 --- a/cmd/gtk/main.go +++ b/cmd/gtk/main.go @@ -84,7 +84,7 @@ func main() { log.Println("application startup") }) - n, wlt, err := newNode(workingDir) + nd, wlt, err := newNode(workingDir) fatalErrorCheck(err) // Connect function to application activate event @@ -111,7 +111,7 @@ func main() { // Running the run-up logic in a separate goroutine glib.TimeoutAdd(uint(100), func() bool { - run(n, wlt, app) + run(nd, wlt, app) splashDlg.Destroy() // Ensures the function is not called again @@ -122,14 +122,14 @@ func main() { // Connect function to application shutdown event, this is not required. app.Connect("shutdown", func() { log.Println("Application shutdown") - n.Stop() + nd.Stop() _ = fileLock.Unlock() }) cmd.TrapSignal(func() { cmd.PrintInfoMsgf("Exiting...") - n.Stop() + nd.Stop() _ = fileLock.Unlock() }) diff --git a/config/example_config.toml b/config/example_config.toml index f34fbaef3..f5e313de7 100644 --- a/config/example_config.toml +++ b/config/example_config.toml @@ -92,10 +92,6 @@ # Default is `10s`. session_timeout = "10s" - # `node_network` indicates whether the node is capable of serving the complete blockchain. - # Default is `true`. - node_network = true - # `sync.firewall` contains configuration options for the sync firewall. [sync.firewall] # `banned_nets` contains the list of IPs and subnets that should be banned. diff --git a/node/node.go b/node/node.go index 3ff0f80b0..b4858d1d3 100644 --- a/node/node.go +++ b/node/node.go @@ -13,6 +13,7 @@ import ( "github.com/pactus-project/pactus/store" "github.com/pactus-project/pactus/sync" "github.com/pactus-project/pactus/sync/bundle/message" + "github.com/pactus-project/pactus/sync/peerset/peer/service" "github.com/pactus-project/pactus/txpool" "github.com/pactus-project/pactus/util" "github.com/pactus-project/pactus/util/logger" @@ -79,6 +80,9 @@ func NewNode(genDoc *genesis.Genesis, conf *config.Config, consMgr := consensus.NewManager(conf.Consensus, st, valKeys, rewardAddrs, messageCh) walletMgr := wallet.NewWalletManager(conf.WalletManager) + if !str.IsPruned() { + conf.Sync.Services.Append(service.FullNode) + } syn, err := sync.NewSynchronizer(conf.Sync, valKeys, st, consMgr, net, messageCh) if err != nil { return nil, err diff --git a/node/node_test.go b/node/node_test.go index 566f874e3..46785f3bc 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -40,12 +40,14 @@ func TestRunningNode(t *testing.T) { valKeys := []*bls.ValidatorKey{ts.RandValKey(), ts.RandValKey()} rewardAddrs := []crypto.Address{ts.RandAccAddress(), ts.RandAccAddress()} - n, err := NewNode(gen, conf, valKeys, rewardAddrs) + nd, err := NewNode(gen, conf, valKeys, rewardAddrs) + assert.True(t, conf.Sync.Services.IsFullNode()) + assert.True(t, conf.Sync.Services.IsPrunedNode()) require.NoError(t, err) - assert.Equal(t, n.state.LastBlockHash(), hash.UndefHash) + assert.Equal(t, nd.state.LastBlockHash(), hash.UndefHash) - err = n.Start() + err = nd.Start() require.NoError(t, err) - n.Stop() + nd.Stop() } diff --git a/sync/bundle/message/hello.go b/sync/bundle/message/hello.go index 081b3c2e8..5457228a3 100644 --- a/sync/bundle/message/hello.go +++ b/sync/bundle/message/hello.go @@ -27,7 +27,7 @@ type HelloMessage struct { } func NewHelloMessage(pid peer.ID, moniker string, - height uint32, services service.Services, blockHash, genesisHash hash.Hash, + services service.Services, height uint32, blockHash, genesisHash hash.Hash, ) *HelloMessage { return &HelloMessage{ PeerID: pid, diff --git a/sync/bundle/message/hello_test.go b/sync/bundle/message/hello_test.go index f0e149430..d54571f98 100644 --- a/sync/bundle/message/hello_test.go +++ b/sync/bundle/message/hello_test.go @@ -6,6 +6,7 @@ import ( "github.com/pactus-project/pactus/crypto" "github.com/pactus-project/pactus/crypto/bls" + "github.com/pactus-project/pactus/sync/peerset/peer/service" "github.com/pactus-project/pactus/util/errors" "github.com/pactus-project/pactus/util/testsuite" "github.com/stretchr/testify/assert" @@ -21,7 +22,8 @@ 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()) + m := NewHelloMessage(ts.RandPeerID(), "Oscar", service.New(service.FullNode), + ts.RandHeight(), ts.RandHash(), ts.RandHash()) m.Sign([]*bls.ValidatorKey{valKey}) m.Signature = ts.RandBLSSignature() @@ -30,7 +32,8 @@ 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()) + m := NewHelloMessage(ts.RandPeerID(), "Oscar", service.New(service.FullNode), + ts.RandHeight(), ts.RandHash(), ts.RandHash()) m.Sign([]*bls.ValidatorKey{valKey}) m.Signature = nil @@ -39,7 +42,8 @@ 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()) + m := NewHelloMessage(ts.RandPeerID(), "Oscar", service.New(service.FullNode), + ts.RandHeight(), ts.RandHash(), ts.RandHash()) m.Sign([]*bls.ValidatorKey{valKey}) m.PublicKeys = make([]*bls.PublicKey, 0) @@ -50,7 +54,8 @@ func TestHelloMessage(t *testing.T) { time1 := time.Now() myTimeUnixMilli := time1.UnixMilli() - m := NewHelloMessage(ts.RandPeerID(), "Alice", 100, 0, ts.RandHash(), ts.RandHash()) + m := NewHelloMessage(ts.RandPeerID(), "Alice", service.New(service.FullNode), + ts.RandHeight(), ts.RandHash(), ts.RandHash()) assert.LessOrEqual(t, m.MyTimeUnixMilli, time.Now().UnixMilli()) assert.GreaterOrEqual(t, m.MyTimeUnixMilli, myTimeUnixMilli) @@ -58,10 +63,12 @@ func TestHelloMessage(t *testing.T) { t.Run("Ok", func(t *testing.T) { valKey := ts.RandValKey() - m := NewHelloMessage(ts.RandPeerID(), "Alice", 100, 0, ts.RandHash(), ts.RandHash()) + m := NewHelloMessage(ts.RandPeerID(), "Alice", service.New(service.FullNode), + ts.RandHeight(), ts.RandHash(), ts.RandHash()) m.Sign([]*bls.ValidatorKey{valKey}) assert.NoError(t, m.BasicCheck()) assert.Contains(t, m.String(), "Alice") + assert.Contains(t, m.String(), "FULL") }) } diff --git a/sync/config.go b/sync/config.go index 7264672a2..51b95f5e7 100644 --- a/sync/config.go +++ b/sync/config.go @@ -12,23 +12,23 @@ import ( type Config struct { Moniker string `toml:"moniker"` SessionTimeout time.Duration `toml:"session_timeout"` - NodeNetwork bool `toml:"node_network"` Firewall *firewall.Config `toml:"firewall"` // Private configs - MaxSessions int `toml:"-"` - LatestBlockInterval uint32 `toml:"-"` - BlockPerMessage uint32 `toml:"-"` - LatestSupportingVer version.Version `toml:"-"` + MaxSessions int `toml:"-"` + LatestBlockInterval uint32 `toml:"-"` + BlockPerMessage uint32 `toml:"-"` + LatestSupportingVer version.Version `toml:"-"` + Services service.Services `toml:"-"` } func DefaultConfig() *Config { return &Config{ SessionTimeout: time.Second * 10, - NodeNetwork: true, + Services: service.New(service.PrunedNode), BlockPerMessage: 60, MaxSessions: 8, - LatestBlockInterval: 720, + LatestBlockInterval: 10 * 8640, // 10 days, same as default retention blocks in prune node Firewall: firewall.DefaultConfig(), LatestSupportingVer: version.Version{ Major: 1, @@ -47,12 +47,3 @@ func (conf *Config) CacheSize() int { return util.LogScale( int(conf.BlockPerMessage * conf.LatestBlockInterval)) } - -func (conf *Config) Services() service.Services { - s := service.New() - if conf.NodeNetwork { - s.Append(service.Network) - } - - return s -} diff --git a/sync/handler_blocks_request.go b/sync/handler_blocks_request.go index b49196791..69af88314 100644 --- a/sync/handler_blocks_request.go +++ b/sync/handler_blocks_request.go @@ -43,7 +43,7 @@ func (handler *blocksRequestHandler) ParseMessage(m message.Message, pid peer.ID } ourHeight := handler.state.LastBlockHeight() - if !handler.config.NodeNetwork { + if !handler.config.Services.IsFullNode() { if ourHeight > handler.config.LatestBlockInterval && msg.From < ourHeight-handler.config.LatestBlockInterval { response := message.NewBlocksResponseMessage(message.ResponseCodeRejected, fmt.Sprintf("the request height is not acceptable: %v", msg.From), msg.SessionID, 0, nil, nil) diff --git a/sync/handler_blocks_request_test.go b/sync/handler_blocks_request_test.go index 22a4ccc3b..ecbf777f7 100644 --- a/sync/handler_blocks_request_test.go +++ b/sync/handler_blocks_request_test.go @@ -10,15 +10,14 @@ import ( ) func TestBlocksRequestMessages(t *testing.T) { - config := testConfig() - config.NodeNetwork = false + t.Run("NetworkLimited service is enabled", func(t *testing.T) { + config := testConfig() + config.Services = service.Services(service.PrunedNode) - td := setup(t, config) - sid := td.RandInt(100) + td := setup(t, config) + sid := td.RandInt(100) - td.state.CommitTestBlocks(31) - - t.Run("NodeNetwork flag is not set", func(t *testing.T) { + td.state.CommitTestBlocks(31) curHeight := td.state.LastBlockHeight() t.Run("Reject request from unknown peers", func(t *testing.T) { @@ -118,8 +117,14 @@ func TestBlocksRequestMessages(t *testing.T) { }) }) - t.Run("NodeNetwork flag set", func(t *testing.T) { - td.sync.config.NodeNetwork = true + t.Run("Network service is enabled", func(t *testing.T) { + config := testConfig() + config.Services = service.New(service.FullNode) + + td := setup(t, config) + sid := td.RandInt(100) + + td.state.CommitTestBlocks(31) pid := td.addPeer(t, status.StatusKnown, service.New(service.None)) t.Run("Requesting one block", func(t *testing.T) { diff --git a/sync/handler_blocks_response_test.go b/sync/handler_blocks_response_test.go index 42093b6fd..0a31fcdaa 100644 --- a/sync/handler_blocks_response_test.go +++ b/sync/handler_blocks_response_test.go @@ -174,7 +174,6 @@ func makeAliceAndBobNetworks(t *testing.T) *networkAliceBob { networkAlice := network.MockingNetwork(ts, ts.RandPeerID()) networkBob := network.MockingNetwork(ts, ts.RandPeerID()) - configBob.NodeNetwork = true networkAlice.AddAnotherNetwork(networkBob) networkBob.AddAnotherNetwork(networkAlice) diff --git a/sync/handler_hello_test.go b/sync/handler_hello_test.go index f97b9cb8a..50c47bea7 100644 --- a/sync/handler_hello_test.go +++ b/sync/handler_hello_test.go @@ -23,8 +23,8 @@ func TestParsingHelloMessages(t *testing.T) { func(t *testing.T) { valKey := td.RandValKey() pid := td.RandPeerID() - msg := message.NewHelloMessage(pid, "unknown-peer", 0, 0, - td.state.LastBlockHash(), td.state.Genesis().Hash()) + msg := message.NewHelloMessage(pid, "unknown-peer", service.New(service.FullNode), + td.RandHeight(), td.RandHash(), td.state.Genesis().Hash()) msg.Sign([]*bls.ValidatorKey{valKey}) from := td.RandPeerID() @@ -38,8 +38,8 @@ func TestParsingHelloMessages(t *testing.T) { invGenHash := td.RandHash() valKey := td.RandValKey() pid := td.RandPeerID() - msg := message.NewHelloMessage(pid, "bad-genesis", 0, 0, - td.state.LastBlockHash(), invGenHash) + msg := message.NewHelloMessage(pid, "bad-genesis", service.New(service.FullNode), + td.RandHeight(), td.RandHash(), invGenHash) msg.Sign([]*bls.ValidatorKey{valKey}) td.receivingNewMessage(td.sync, msg, pid) @@ -51,10 +51,9 @@ func TestParsingHelloMessages(t *testing.T) { t.Run("Receiving a Hello message from a peer. The time difference is greater than or equal to -10", func(t *testing.T) { valKey := td.RandValKey() - 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()) + msg := message.NewHelloMessage(pid, "kitty", service.New(service.FullNode), + td.RandHeight(), td.RandHash(), td.state.Genesis().Hash()) msg.Sign([]*bls.ValidatorKey{valKey}) msg.MyTimeUnixMilli = msg.MyTime().Add(-10 * time.Second).UnixMilli() @@ -67,10 +66,9 @@ func TestParsingHelloMessages(t *testing.T) { t.Run("Receiving Hello message from a peer. Difference is less or equal than 20 seconds.", func(t *testing.T) { valKey := td.RandValKey() - 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()) + msg := message.NewHelloMessage(pid, "kitty", service.New(service.FullNode), + td.RandHeight(), td.RandHash(), td.state.Genesis().Hash()) msg.Sign([]*bls.ValidatorKey{valKey}) msg.MyTimeUnixMilli = msg.MyTime().Add(20 * time.Second).UnixMilli() @@ -83,10 +81,9 @@ func TestParsingHelloMessages(t *testing.T) { t.Run("Non supporting version.", func(t *testing.T) { valKey := td.RandValKey() - 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()) + msg := message.NewHelloMessage(pid, "kitty", service.New(service.FullNode), + td.RandHeight(), td.RandHash(), td.state.Genesis().Hash()) nodeAgent := version.NodeAgent nodeAgent.Version = version.Version{ Major: 1, @@ -105,10 +102,9 @@ func TestParsingHelloMessages(t *testing.T) { t.Run("Invalid agent.", func(t *testing.T) { valKey := td.RandValKey() - 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()) + msg := message.NewHelloMessage(pid, "kitty", service.New(service.FullNode), + td.RandHeight(), td.RandHash(), td.state.Genesis().Hash()) msg.Agent = "invalid-agent" msg.Sign([]*bls.ValidatorKey{valKey}) @@ -121,10 +117,10 @@ func TestParsingHelloMessages(t *testing.T) { t.Run("Receiving Hello message from a peer. It should be acknowledged and updates the peer info", func(t *testing.T) { valKey := td.RandValKey() - 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()) + peerHeight := td.RandHeight() + msg := message.NewHelloMessage(pid, "kitty", service.New(service.FullNode), + peerHeight, td.RandHash(), td.state.Genesis().Hash()) msg.Sign([]*bls.ValidatorKey{valKey}) td.receivingNewMessage(td.sync, msg, pid) @@ -141,8 +137,8 @@ func TestParsingHelloMessages(t *testing.T) { assert.Equal(t, p.Moniker, "kitty") assert.Contains(t, p.ConsensusKeys, pub) assert.Equal(t, p.PeerID, pid) - assert.Equal(t, p.Height, height) - assert.True(t, p.HasNetworkService()) + assert.Equal(t, p.Height, peerHeight) + assert.True(t, p.IsFullNode()) }) } @@ -154,5 +150,5 @@ func TestSendingHelloMessage(t *testing.T) { bdl := td.shouldPublishMessageWithThisType(t, message.TypeHello) assert.True(t, util.IsFlagSet(bdl.Flags, bundle.BundleFlagHandshaking)) - assert.True(t, util.IsFlagSet(bdl.Message.(*message.HelloMessage).Services, service.New(service.Network))) + assert.True(t, util.IsFlagSet(bdl.Message.(*message.HelloMessage).Services, service.New(service.FullNode))) } diff --git a/sync/mock.go b/sync/mock.go index 6e52d4be9..542fb182a 100644 --- a/sync/mock.go +++ b/sync/mock.go @@ -30,7 +30,7 @@ func MockingSync(ts *testsuite.TestSuite) *MockSync { "test-peer-1", version.NodeAgent.String(), []*bls.PublicKey{pub1}, - service.New(service.Network)) + service.New(service.FullNode)) ps.UpdateHeight(pid1, ts.RandHeight(), ts.RandHash()) ps.UpdateInfo( diff --git a/sync/peerset/peer/peer.go b/sync/peerset/peer/peer.go index c21b70b50..6de44a115 100644 --- a/sync/peerset/peer/peer.go +++ b/sync/peerset/peer/peer.go @@ -46,8 +46,8 @@ func NewPeer(peerID ID) *Peer { } } -func (p *Peer) HasNetworkService() bool { - return p.Services.IsNetwork() +func (p *Peer) IsFullNode() bool { + return p.Services.IsFullNode() } func (p *Peer) DownloadScore() int { diff --git a/sync/peerset/peer/peer_test.go b/sync/peerset/peer/peer_test.go index b06b9dc08..57eadba25 100644 --- a/sync/peerset/peer/peer_test.go +++ b/sync/peerset/peer/peer_test.go @@ -35,13 +35,14 @@ func TestPeerStatus(t *testing.T) { } } -func TestHasNetworkService(t *testing.T) { +func TestIsFullNode(t *testing.T) { p1 := NewPeer("peer-1") p2 := NewPeer("peer-1") - p2.Services = service.New(service.Network) + p1.Services = service.New(service.PrunedNode) + p2.Services = service.New(service.FullNode) - assert.False(t, p1.HasNetworkService()) - assert.True(t, p2.HasNetworkService()) + assert.False(t, p1.IsFullNode()) + assert.True(t, p2.IsFullNode()) } func TestDownloadScore(t *testing.T) { diff --git a/sync/peerset/peer/service/services.go b/sync/peerset/peer/service/services.go index b02a51ad7..424b3418c 100644 --- a/sync/peerset/peer/service/services.go +++ b/sync/peerset/peer/service/services.go @@ -12,9 +12,13 @@ type ( ) const ( - None Service = 0x00 - Network Service = 0x01 - Foo Service = 0x02 // For future use + None Service = 0x00 + + // FullNode indicates that the node has a full blockchain history. + FullNode Service = 0x01 + + // PrunedNode indicates that the node has a pruned blockchain history. + PrunedNode Service = 0x02 ) func New(flags ...Service) Services { @@ -33,14 +37,14 @@ func (s *Services) Append(flag Service) { func (s Services) String() string { services := "" flags := s - if util.IsFlagSet(flags, Services(Network)) { - services += "NETWORK | " - flags = util.UnsetFlag(flags, Services(Network)) + if util.IsFlagSet(flags, Services(FullNode)) { + services += "FULL | " + flags = util.UnsetFlag(flags, Services(FullNode)) } - if util.IsFlagSet(flags, Services(Foo)) { - services += "FOO | " - flags = util.UnsetFlag(flags, Services(Foo)) + if util.IsFlagSet(flags, Services(PrunedNode)) { + services += "PRUNED | " + flags = util.UnsetFlag(flags, Services(PrunedNode)) } if flags != 0 { @@ -52,10 +56,10 @@ func (s Services) String() string { return services } -func (s Services) IsNetwork() bool { - return util.IsFlagSet(s, Services(Network)) +func (s Services) IsFullNode() bool { + return util.IsFlagSet(s, Services(FullNode)) } -func (s Services) IsFoo() bool { - return util.IsFlagSet(s, Services(Foo)) +func (s Services) IsPrunedNode() bool { + return util.IsFlagSet(s, Services(PrunedNode)) } diff --git a/sync/peerset/peer/service/services_test.go b/sync/peerset/peer/service/services_test.go index cf93b13d3..5ea288e9a 100644 --- a/sync/peerset/peer/service/services_test.go +++ b/sync/peerset/peer/service/services_test.go @@ -8,33 +8,19 @@ import ( func TestServicesString(t *testing.T) { assert.Equal(t, New(None).String(), "") - assert.Equal(t, New(Network).String(), "NETWORK") - assert.Equal(t, New(Foo).String(), "FOO") - assert.Equal(t, New(Network, Foo).String(), "NETWORK | FOO") - assert.Equal(t, New(5).String(), "NETWORK | 4") - assert.Equal(t, New(6).String(), "FOO | 4") + assert.Equal(t, New(FullNode).String(), "FULL") + assert.Equal(t, New(PrunedNode).String(), "PRUNED") + assert.Equal(t, New(FullNode, PrunedNode).String(), "FULL | PRUNED") + assert.Equal(t, New(5).String(), "FULL | 4") + assert.Equal(t, New(6).String(), "PRUNED | 4") } func TestAppend(t *testing.T) { - s := New(Network) - assert.True(t, s.IsNetwork()) - assert.False(t, s.IsFoo()) + s := New(FullNode) + assert.True(t, s.IsFullNode()) + assert.False(t, s.IsPrunedNode()) - s.Append(Foo) - assert.True(t, s.IsNetwork()) - assert.True(t, s.IsFoo()) -} - -func TestIsNetwork(t *testing.T) { - assert.False(t, New(None).IsNetwork()) - assert.True(t, New(Network).IsNetwork()) - assert.False(t, New(Foo).IsNetwork()) - assert.True(t, New(Foo, Network).IsNetwork()) -} - -func TestIsFoo(t *testing.T) { - assert.False(t, New(None).IsFoo()) - assert.False(t, New(Network).IsFoo()) - assert.True(t, New(Foo).IsFoo()) - assert.True(t, New(Foo, Network).IsNetwork()) + s.Append(PrunedNode) + assert.True(t, s.IsFullNode()) + assert.True(t, s.IsPrunedNode()) } diff --git a/sync/peerset/peer_set_test.go b/sync/peerset/peer_set_test.go index 1679fd831..3091f54b4 100644 --- a/sync/peerset/peer_set_test.go +++ b/sync/peerset/peer_set_test.go @@ -40,11 +40,11 @@ func TestPeerSet(t *testing.T) { pid2 := ts.RandPeerID() pid3 := ts.RandPeerID() peerSet.UpdateInfo(pid1, "Moniker1", "Agent1", - []*bls.PublicKey{pk1, pk2}, service.New(service.Network)) + []*bls.PublicKey{pk1, pk2}, service.New(service.FullNode)) peerSet.UpdateInfo(pid2, "Moniker2", "Agent2", []*bls.PublicKey{pk3}, service.New(service.None)) peerSet.UpdateInfo(pid3, "Moniker3", "Agent3", - []*bls.PublicKey{pk4, pk5}, service.New(service.Network)) + []*bls.PublicKey{pk4, pk5}, service.New(service.FullNode)) t.Run("Testing Len", func(t *testing.T) { assert.Equal(t, 3, peerSet.Len()) diff --git a/sync/sync.go b/sync/sync.go index 35f7ca260..29a51fac0 100644 --- a/sync/sync.go +++ b/sync/sync.go @@ -234,7 +234,7 @@ func (sync *synchronizer) PeerSet() *peerset.PeerSet { } func (sync *synchronizer) Services() service.Services { - return sync.config.Services() + return sync.config.Services } func (sync *synchronizer) sayHello(to peer.ID) { @@ -246,8 +246,8 @@ func (sync *synchronizer) sayHello(to peer.ID) { msg := message.NewHelloMessage( sync.SelfID(), sync.config.Moniker, + sync.config.Services, sync.stateHeight(), - sync.config.Services(), sync.state.LastBlockHash(), sync.state.Genesis().Hash(), ) @@ -441,12 +441,12 @@ func (sync *synchronizer) updateBlockchain() { } // downloadBlocks starts downloading blocks from the network. -func (sync *synchronizer) downloadBlocks(from uint32, onlyNodeNetwork bool) { +func (sync *synchronizer) downloadBlocks(from uint32, onlyFullNodes bool) { sync.logger.Debug("downloading blocks", "from", from) for i := sync.peerSet.NumberOfSessions(); i < sync.config.MaxSessions; i++ { count := sync.config.LatestBlockInterval - sent := sync.sendBlockRequestToRandomPeer(from, count, onlyNodeNetwork) + sent := sync.sendBlockRequestToRandomPeer(from, count, onlyFullNodes) if !sent { return } @@ -455,7 +455,7 @@ func (sync *synchronizer) downloadBlocks(from uint32, onlyNodeNetwork bool) { } } -func (sync *synchronizer) sendBlockRequestToRandomPeer(from, count uint32, onlyNodeNetwork bool) bool { +func (sync *synchronizer) sendBlockRequestToRandomPeer(from, count uint32, onlyFullNodes bool) bool { // Prevent downloading blocks that might be cached before for sync.cache.HasBlockInCache(from) { from++ @@ -483,15 +483,15 @@ func (sync *synchronizer) sendBlockRequestToRandomPeer(from, count uint32, onlyN // We haven't completed the handshake with this peer. if !p.Status.IsKnown() { - if onlyNodeNetwork { + if onlyFullNodes { sync.network.CloseConnection(p.PeerID) } continue } - if onlyNodeNetwork && !p.HasNetworkService() { - if onlyNodeNetwork { + if onlyFullNodes && !p.IsFullNode() { + if onlyFullNodes { sync.network.CloseConnection(p.PeerID) } diff --git a/sync/sync_test.go b/sync/sync_test.go index 92c1e84fd..cb06ac23a 100644 --- a/sync/sync_test.go +++ b/sync/sync_test.go @@ -43,12 +43,12 @@ func testConfig() *Config { return &Config{ Moniker: "test", SessionTimeout: time.Second * 1, - NodeNetwork: true, BlockPerMessage: 11, MaxSessions: 8, LatestBlockInterval: 23, Firewall: firewall.DefaultConfig(), LatestSupportingVer: DefaultConfig().LatestSupportingVer, + Services: service.New(service.FullNode, service.PrunedNode), } } @@ -330,7 +330,7 @@ func TestDownload(t *testing.T) { t.Run("try to download blocks and the peer is a network node", func(t *testing.T) { td := setup(t, conf) - pid := td.addPeer(t, status.StatusKnown, service.New(service.Network)) + pid := td.addPeer(t, status.StatusKnown, service.New(service.FullNode)) blk, cert := td.GenerateTestBlock(td.RandHeight()) baMsg := message.NewBlockAnnounceMessage(blk, cert) td.receivingNewMessage(td.sync, baMsg, pid) diff --git a/tests/main_test.go b/tests/main_test.go index 749327dd6..854e1f328 100644 --- a/tests/main_test.go +++ b/tests/main_test.go @@ -81,7 +81,6 @@ func TestMain(m *testing.M) { tConfigs[i].Logger.Levels["_consensus"] = "info" tConfigs[i].Logger.Levels["_network"] = "info" tConfigs[i].Logger.Levels["_pool"] = "info" - tConfigs[i].Sync.NodeNetwork = false tConfigs[i].Sync.Firewall.BannedNets = make([]string, 0) tConfigs[i].Sync.LatestBlockInterval = 10 tConfigs[i].Network.EnableMdns = true @@ -98,7 +97,6 @@ func TestMain(m *testing.M) { tConfigs[i].GRPC.Enable = false if i == 0 { - tConfigs[i].Sync.NodeNetwork = true tConfigs[i].GRPC.Enable = true tConfigs[i].GRPC.Listen = tGRPCAddress } diff --git a/www/grpc/gen/dart/network.pb.dart b/www/grpc/gen/dart/network.pb.dart index 9ea913ccc..6f61b6a97 100644 --- a/www/grpc/gen/dart/network.pb.dart +++ b/www/grpc/gen/dart/network.pb.dart @@ -282,8 +282,8 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage { ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'peerId') ..a<$fixnum.Int64>(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'startedAt', $pb.PbFieldType.OU6, defaultOrMaker: $fixnum.Int64.ZERO) ..aOS(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'reachability') - ..p<$core.int>(6, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'services', $pb.PbFieldType.K3) - ..pPS(7, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'servicesNames') + ..a<$core.int>(6, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'services', $pb.PbFieldType.O3) + ..aOS(7, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'servicesNames') ..pPS(8, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'localAddrs') ..pPS(9, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'protocols') ..a<$core.double>(13, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'clockOffset', $pb.PbFieldType.OD) @@ -298,8 +298,8 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage { $core.String? peerId, $fixnum.Int64? startedAt, $core.String? reachability, - $core.Iterable<$core.int>? services, - $core.Iterable<$core.String>? servicesNames, + $core.int? services, + $core.String? servicesNames, $core.Iterable<$core.String>? localAddrs, $core.Iterable<$core.String>? protocols, $core.double? clockOffset, @@ -322,10 +322,10 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage { _result.reachability = reachability; } if (services != null) { - _result.services.addAll(services); + _result.services = services; } if (servicesNames != null) { - _result.servicesNames.addAll(servicesNames); + _result.servicesNames = servicesNames; } if (localAddrs != null) { _result.localAddrs.addAll(localAddrs); @@ -408,10 +408,22 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage { void clearReachability() => clearField(5); @$pb.TagNumber(6) - $core.List<$core.int> get services => $_getList(5); + $core.int get services => $_getIZ(5); + @$pb.TagNumber(6) + set services($core.int v) { $_setSignedInt32(5, v); } + @$pb.TagNumber(6) + $core.bool hasServices() => $_has(5); + @$pb.TagNumber(6) + void clearServices() => clearField(6); @$pb.TagNumber(7) - $core.List<$core.String> get servicesNames => $_getList(6); + $core.String get servicesNames => $_getSZ(6); + @$pb.TagNumber(7) + set servicesNames($core.String v) { $_setString(6, v); } + @$pb.TagNumber(7) + $core.bool hasServicesNames() => $_has(6); + @$pb.TagNumber(7) + void clearServicesNames() => clearField(7); @$pb.TagNumber(8) $core.List<$core.String> get localAddrs => $_getList(7); diff --git a/www/grpc/gen/dart/network.pbjson.dart b/www/grpc/gen/dart/network.pbjson.dart index a6466da55..bbebe63f5 100644 --- a/www/grpc/gen/dart/network.pbjson.dart +++ b/www/grpc/gen/dart/network.pbjson.dart @@ -83,8 +83,8 @@ const GetNodeInfoResponse$json = const { const {'1': 'peer_id', '3': 3, '4': 1, '5': 9, '10': 'peerId'}, const {'1': 'started_at', '3': 4, '4': 1, '5': 4, '10': 'startedAt'}, const {'1': 'reachability', '3': 5, '4': 1, '5': 9, '10': 'reachability'}, - const {'1': 'services', '3': 6, '4': 3, '5': 5, '10': 'services'}, - const {'1': 'services_names', '3': 7, '4': 3, '5': 9, '10': 'servicesNames'}, + const {'1': 'services', '3': 6, '4': 1, '5': 5, '10': 'services'}, + const {'1': 'services_names', '3': 7, '4': 1, '5': 9, '10': 'servicesNames'}, const {'1': 'local_addrs', '3': 8, '4': 3, '5': 9, '10': 'localAddrs'}, const {'1': 'protocols', '3': 9, '4': 3, '5': 9, '10': 'protocols'}, const {'1': 'clock_offset', '3': 13, '4': 1, '5': 1, '10': 'clockOffset'}, @@ -93,7 +93,7 @@ const GetNodeInfoResponse$json = const { }; /// Descriptor for `GetNodeInfoResponse`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List getNodeInfoResponseDescriptor = $convert.base64Decode('ChNHZXROb2RlSW5mb1Jlc3BvbnNlEhgKB21vbmlrZXIYASABKAlSB21vbmlrZXISFAoFYWdlbnQYAiABKAlSBWFnZW50EhcKB3BlZXJfaWQYAyABKAlSBnBlZXJJZBIdCgpzdGFydGVkX2F0GAQgASgEUglzdGFydGVkQXQSIgoMcmVhY2hhYmlsaXR5GAUgASgJUgxyZWFjaGFiaWxpdHkSGgoIc2VydmljZXMYBiADKAVSCHNlcnZpY2VzEiUKDnNlcnZpY2VzX25hbWVzGAcgAygJUg1zZXJ2aWNlc05hbWVzEh8KC2xvY2FsX2FkZHJzGAggAygJUgpsb2NhbEFkZHJzEhwKCXByb3RvY29scxgJIAMoCVIJcHJvdG9jb2xzEiEKDGNsb2NrX29mZnNldBgNIAEoAVILY2xvY2tPZmZzZXQSPwoPY29ubmVjdGlvbl9pbmZvGA4gASgLMhYucGFjdHVzLkNvbm5lY3Rpb25JbmZvUg5jb25uZWN0aW9uSW5mbw=='); +final $typed_data.Uint8List getNodeInfoResponseDescriptor = $convert.base64Decode('ChNHZXROb2RlSW5mb1Jlc3BvbnNlEhgKB21vbmlrZXIYASABKAlSB21vbmlrZXISFAoFYWdlbnQYAiABKAlSBWFnZW50EhcKB3BlZXJfaWQYAyABKAlSBnBlZXJJZBIdCgpzdGFydGVkX2F0GAQgASgEUglzdGFydGVkQXQSIgoMcmVhY2hhYmlsaXR5GAUgASgJUgxyZWFjaGFiaWxpdHkSGgoIc2VydmljZXMYBiABKAVSCHNlcnZpY2VzEiUKDnNlcnZpY2VzX25hbWVzGAcgASgJUg1zZXJ2aWNlc05hbWVzEh8KC2xvY2FsX2FkZHJzGAggAygJUgpsb2NhbEFkZHJzEhwKCXByb3RvY29scxgJIAMoCVIJcHJvdG9jb2xzEiEKDGNsb2NrX29mZnNldBgNIAEoAVILY2xvY2tPZmZzZXQSPwoPY29ubmVjdGlvbl9pbmZvGA4gASgLMhYucGFjdHVzLkNvbm5lY3Rpb25JbmZvUg5jb25uZWN0aW9uSW5mbw=='); @$core.Deprecated('Use peerInfoDescriptor instead') const PeerInfo$json = const { '1': 'PeerInfo', diff --git a/www/grpc/gen/docs/grpc.md b/www/grpc/gen/docs/grpc.md index 8e11dd6e3..79f76ae0b 100644 --- a/www/grpc/gen/docs/grpc.md +++ b/www/grpc/gen/docs/grpc.md @@ -2363,14 +2363,14 @@ Message has no fields. services - repeated int32 + int32 - List of services provided by the node. + A bitfield indicating the services provided by the node. services_names - repeated string + string Names of services provided by the node. diff --git a/www/grpc/gen/docs/json-rpc.md b/www/grpc/gen/docs/json-rpc.md index 4592fcd9a..92c3e61ef 100644 --- a/www/grpc/gen/docs/json-rpc.md +++ b/www/grpc/gen/docs/json-rpc.md @@ -2364,14 +2364,14 @@ Parameters has no fields. services - repeated numeric + numeric - List of services provided by the node. + A bitfield indicating the services provided by the node. services_names - repeated string + string Names of services provided by the node. diff --git a/www/grpc/gen/go/network.pb.go b/www/grpc/gen/go/network.pb.go index a78fd4ef2..9df0b1890 100644 --- a/www/grpc/gen/go/network.pb.go +++ b/www/grpc/gen/go/network.pb.go @@ -295,10 +295,10 @@ type GetNodeInfoResponse struct { StartedAt uint64 `protobuf:"varint,4,opt,name=started_at,json=startedAt,proto3" json:"started_at,omitempty"` // Reachability status of the node. Reachability string `protobuf:"bytes,5,opt,name=reachability,proto3" json:"reachability,omitempty"` - // List of services provided by the node. - Services []int32 `protobuf:"varint,6,rep,packed,name=services,proto3" json:"services,omitempty"` + // A bitfield indicating the services provided by the node. + Services int32 `protobuf:"varint,6,opt,name=services,proto3" json:"services,omitempty"` // Names of services provided by the node. - ServicesNames []string `protobuf:"bytes,7,rep,name=services_names,json=servicesNames,proto3" json:"services_names,omitempty"` + ServicesNames string `protobuf:"bytes,7,opt,name=services_names,json=servicesNames,proto3" json:"services_names,omitempty"` // List of addresses associated with the node. LocalAddrs []string `protobuf:"bytes,8,rep,name=local_addrs,json=localAddrs,proto3" json:"local_addrs,omitempty"` // List of protocols supported by the node. @@ -376,18 +376,18 @@ func (x *GetNodeInfoResponse) GetReachability() string { return "" } -func (x *GetNodeInfoResponse) GetServices() []int32 { +func (x *GetNodeInfoResponse) GetServices() int32 { if x != nil { return x.Services } - return nil + return 0 } -func (x *GetNodeInfoResponse) GetServicesNames() []string { +func (x *GetNodeInfoResponse) GetServicesNames() string { if x != nil { return x.ServicesNames } - return nil + return "" } func (x *GetNodeInfoResponse) GetLocalAddrs() []string { @@ -703,9 +703,9 @@ var file_network_proto_rawDesc = []byte{ 0x61, 0x72, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x72, 0x65, 0x61, 0x63, 0x68, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, 0x61, 0x63, 0x68, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x73, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x05, 0x52, 0x08, 0x73, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x65, 0x72, 0x76, 0x69, - 0x63, 0x65, 0x73, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x09, 0x52, + 0x63, 0x65, 0x73, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x73, 0x12, diff --git a/www/grpc/gen/java/pactus/network/NetworkOuterClass.java b/www/grpc/gen/java/pactus/network/NetworkOuterClass.java index 7df6a1fe5..c4c5376fe 100644 --- a/www/grpc/gen/java/pactus/network/NetworkOuterClass.java +++ b/www/grpc/gen/java/pactus/network/NetworkOuterClass.java @@ -3780,73 +3780,33 @@ public interface GetNodeInfoResponseOrBuilder extends /** *
-     * List of services provided by the node.
+     * A bitfield indicating the services provided by the node.
      * 
* - * repeated int32 services = 6 [json_name = "services"]; - * @return A list containing the services. - */ - java.util.List getServicesList(); - /** - *
-     * List of services provided by the node.
-     * 
- * - * repeated int32 services = 6 [json_name = "services"]; - * @return The count of services. - */ - int getServicesCount(); - /** - *
-     * List of services provided by the node.
-     * 
- * - * repeated int32 services = 6 [json_name = "services"]; - * @param index The index of the element to return. - * @return The services at the given index. + * int32 services = 6 [json_name = "services"]; + * @return The services. */ - int getServices(int index); + int getServices(); /** *
      * Names of services provided by the node.
      * 
* - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @return A list containing the servicesNames. - */ - java.util.List - getServicesNamesList(); - /** - *
-     * Names of services provided by the node.
-     * 
- * - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @return The count of servicesNames. - */ - int getServicesNamesCount(); - /** - *
-     * Names of services provided by the node.
-     * 
- * - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @param index The index of the element to return. - * @return The servicesNames at the given index. + * string services_names = 7 [json_name = "servicesNames"]; + * @return The servicesNames. */ - java.lang.String getServicesNames(int index); + java.lang.String getServicesNames(); /** *
      * Names of services provided by the node.
      * 
* - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @param index The index of the value to return. - * @return The bytes of the servicesNames at the given index. + * string services_names = 7 [json_name = "servicesNames"]; + * @return The bytes for servicesNames. */ com.google.protobuf.ByteString - getServicesNamesBytes(int index); + getServicesNamesBytes(); /** *
@@ -3988,8 +3948,7 @@ private GetNodeInfoResponse() {
       agent_ = "";
       peerId_ = "";
       reachability_ = "";
-      services_ = emptyIntList();
-      servicesNames_ = com.google.protobuf.LazyStringArrayList.EMPTY;
+      servicesNames_ = "";
       localAddrs_ = com.google.protobuf.LazyStringArrayList.EMPTY;
       protocols_ = com.google.protobuf.LazyStringArrayList.EMPTY;
     }
@@ -4219,94 +4178,64 @@ public java.lang.String getReachability() {
     }
 
     public static final int SERVICES_FIELD_NUMBER = 6;
-    private com.google.protobuf.Internal.IntList services_;
+    private int services_;
     /**
      * 
-     * List of services provided by the node.
+     * A bitfield indicating the services provided by the node.
      * 
* - * repeated int32 services = 6 [json_name = "services"]; - * @return A list containing the services. + * int32 services = 6 [json_name = "services"]; + * @return The services. */ @java.lang.Override - public java.util.List - getServicesList() { + public int getServices() { return services_; } - /** - *
-     * List of services provided by the node.
-     * 
- * - * repeated int32 services = 6 [json_name = "services"]; - * @return The count of services. - */ - public int getServicesCount() { - return services_.size(); - } - /** - *
-     * List of services provided by the node.
-     * 
- * - * repeated int32 services = 6 [json_name = "services"]; - * @param index The index of the element to return. - * @return The services at the given index. - */ - public int getServices(int index) { - return services_.getInt(index); - } - private int servicesMemoizedSerializedSize = -1; public static final int SERVICES_NAMES_FIELD_NUMBER = 7; - private com.google.protobuf.LazyStringList servicesNames_; - /** - *
-     * Names of services provided by the node.
-     * 
- * - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @return A list containing the servicesNames. - */ - public com.google.protobuf.ProtocolStringList - getServicesNamesList() { - return servicesNames_; - } - /** - *
-     * Names of services provided by the node.
-     * 
- * - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @return The count of servicesNames. - */ - public int getServicesNamesCount() { - return servicesNames_.size(); - } + private volatile java.lang.Object servicesNames_; /** *
      * Names of services provided by the node.
      * 
* - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @param index The index of the element to return. - * @return The servicesNames at the given index. + * string services_names = 7 [json_name = "servicesNames"]; + * @return The servicesNames. */ - public java.lang.String getServicesNames(int index) { - return servicesNames_.get(index); + @java.lang.Override + public java.lang.String getServicesNames() { + java.lang.Object ref = servicesNames_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + servicesNames_ = s; + return s; + } } /** *
      * Names of services provided by the node.
      * 
* - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @param index The index of the value to return. - * @return The bytes of the servicesNames at the given index. + * string services_names = 7 [json_name = "servicesNames"]; + * @return The bytes for servicesNames. */ + @java.lang.Override public com.google.protobuf.ByteString - getServicesNamesBytes(int index) { - return servicesNames_.getByteString(index); + getServicesNamesBytes() { + java.lang.Object ref = servicesNames_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + servicesNames_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } } public static final int LOCAL_ADDRS_FIELD_NUMBER = 8; @@ -4478,7 +4407,6 @@ public final boolean isInitialized() { @java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - getSerializedSize(); if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(moniker_)) { com.google.protobuf.GeneratedMessageV3.writeString(output, 1, moniker_); } @@ -4494,15 +4422,11 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reachability_)) { com.google.protobuf.GeneratedMessageV3.writeString(output, 5, reachability_); } - if (getServicesList().size() > 0) { - output.writeUInt32NoTag(50); - output.writeUInt32NoTag(servicesMemoizedSerializedSize); - } - for (int i = 0; i < services_.size(); i++) { - output.writeInt32NoTag(services_.getInt(i)); + if (services_ != 0) { + output.writeInt32(6, services_); } - for (int i = 0; i < servicesNames_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 7, servicesNames_.getRaw(i)); + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(servicesNames_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 7, servicesNames_); } for (int i = 0; i < localAddrs_.size(); i++) { com.google.protobuf.GeneratedMessageV3.writeString(output, 8, localAddrs_.getRaw(i)); @@ -4541,27 +4465,12 @@ public int getSerializedSize() { if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(reachability_)) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, reachability_); } - { - int dataSize = 0; - for (int i = 0; i < services_.size(); i++) { - dataSize += com.google.protobuf.CodedOutputStream - .computeInt32SizeNoTag(services_.getInt(i)); - } - size += dataSize; - if (!getServicesList().isEmpty()) { - size += 1; - size += com.google.protobuf.CodedOutputStream - .computeInt32SizeNoTag(dataSize); - } - servicesMemoizedSerializedSize = dataSize; + if (services_ != 0) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(6, services_); } - { - int dataSize = 0; - for (int i = 0; i < servicesNames_.size(); i++) { - dataSize += computeStringSizeNoTag(servicesNames_.getRaw(i)); - } - size += dataSize; - size += 1 * getServicesNamesList().size(); + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(servicesNames_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, servicesNames_); } { int dataSize = 0; @@ -4612,10 +4521,10 @@ public boolean equals(final java.lang.Object obj) { != other.getStartedAt()) return false; if (!getReachability() .equals(other.getReachability())) return false; - if (!getServicesList() - .equals(other.getServicesList())) return false; - if (!getServicesNamesList() - .equals(other.getServicesNamesList())) return false; + if (getServices() + != other.getServices()) return false; + if (!getServicesNames() + .equals(other.getServicesNames())) return false; if (!getLocalAddrsList() .equals(other.getLocalAddrsList())) return false; if (!getProtocolsList() @@ -4650,14 +4559,10 @@ public int hashCode() { getStartedAt()); hash = (37 * hash) + REACHABILITY_FIELD_NUMBER; hash = (53 * hash) + getReachability().hashCode(); - if (getServicesCount() > 0) { - hash = (37 * hash) + SERVICES_FIELD_NUMBER; - hash = (53 * hash) + getServicesList().hashCode(); - } - if (getServicesNamesCount() > 0) { - hash = (37 * hash) + SERVICES_NAMES_FIELD_NUMBER; - hash = (53 * hash) + getServicesNamesList().hashCode(); - } + hash = (37 * hash) + SERVICES_FIELD_NUMBER; + hash = (53 * hash) + getServices(); + hash = (37 * hash) + SERVICES_NAMES_FIELD_NUMBER; + hash = (53 * hash) + getServicesNames().hashCode(); if (getLocalAddrsCount() > 0) { hash = (37 * hash) + LOCAL_ADDRS_FIELD_NUMBER; hash = (53 * hash) + getLocalAddrsList().hashCode(); @@ -4815,14 +4720,14 @@ public Builder clear() { reachability_ = ""; - services_ = emptyIntList(); - bitField0_ = (bitField0_ & ~0x00000001); - servicesNames_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000002); + services_ = 0; + + servicesNames_ = ""; + localAddrs_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000004); + bitField0_ = (bitField0_ & ~0x00000001); protocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000008); + bitField0_ = (bitField0_ & ~0x00000002); clockOffset_ = 0D; if (connectionInfoBuilder_ == null) { @@ -4863,24 +4768,16 @@ public pactus.network.NetworkOuterClass.GetNodeInfoResponse buildPartial() { result.peerId_ = peerId_; result.startedAt_ = startedAt_; result.reachability_ = reachability_; - if (((bitField0_ & 0x00000001) != 0)) { - services_.makeImmutable(); - bitField0_ = (bitField0_ & ~0x00000001); - } result.services_ = services_; - if (((bitField0_ & 0x00000002) != 0)) { - servicesNames_ = servicesNames_.getUnmodifiableView(); - bitField0_ = (bitField0_ & ~0x00000002); - } result.servicesNames_ = servicesNames_; - if (((bitField0_ & 0x00000004) != 0)) { + if (((bitField0_ & 0x00000001) != 0)) { localAddrs_ = localAddrs_.getUnmodifiableView(); - bitField0_ = (bitField0_ & ~0x00000004); + bitField0_ = (bitField0_ & ~0x00000001); } result.localAddrs_ = localAddrs_; - if (((bitField0_ & 0x00000008) != 0)) { + if (((bitField0_ & 0x00000002) != 0)) { protocols_ = protocols_.getUnmodifiableView(); - bitField0_ = (bitField0_ & ~0x00000008); + bitField0_ = (bitField0_ & ~0x00000002); } result.protocols_ = protocols_; result.clockOffset_ = clockOffset_; @@ -4956,30 +4853,17 @@ public Builder mergeFrom(pactus.network.NetworkOuterClass.GetNodeInfoResponse ot reachability_ = other.reachability_; onChanged(); } - if (!other.services_.isEmpty()) { - if (services_.isEmpty()) { - services_ = other.services_; - bitField0_ = (bitField0_ & ~0x00000001); - } else { - ensureServicesIsMutable(); - services_.addAll(other.services_); - } - onChanged(); + if (other.getServices() != 0) { + setServices(other.getServices()); } - if (!other.servicesNames_.isEmpty()) { - if (servicesNames_.isEmpty()) { - servicesNames_ = other.servicesNames_; - bitField0_ = (bitField0_ & ~0x00000002); - } else { - ensureServicesNamesIsMutable(); - servicesNames_.addAll(other.servicesNames_); - } + if (!other.getServicesNames().isEmpty()) { + servicesNames_ = other.servicesNames_; onChanged(); } if (!other.localAddrs_.isEmpty()) { if (localAddrs_.isEmpty()) { localAddrs_ = other.localAddrs_; - bitField0_ = (bitField0_ & ~0x00000004); + bitField0_ = (bitField0_ & ~0x00000001); } else { ensureLocalAddrsIsMutable(); localAddrs_.addAll(other.localAddrs_); @@ -4989,7 +4873,7 @@ public Builder mergeFrom(pactus.network.NetworkOuterClass.GetNodeInfoResponse ot if (!other.protocols_.isEmpty()) { if (protocols_.isEmpty()) { protocols_ = other.protocols_; - bitField0_ = (bitField0_ & ~0x00000008); + bitField0_ = (bitField0_ & ~0x00000002); } else { ensureProtocolsIsMutable(); protocols_.addAll(other.protocols_); @@ -5054,25 +4938,13 @@ public Builder mergeFrom( break; } // case 42 case 48: { - int v = input.readInt32(); - ensureServicesIsMutable(); - services_.addInt(v); + services_ = input.readInt32(); + break; } // case 48 - case 50: { - int length = input.readRawVarint32(); - int limit = input.pushLimit(length); - ensureServicesIsMutable(); - while (input.getBytesUntilLimit() > 0) { - services_.addInt(input.readInt32()); - } - input.popLimit(limit); - break; - } // case 50 case 58: { - java.lang.String s = input.readStringRequireUtf8(); - ensureServicesNamesIsMutable(); - servicesNames_.add(s); + servicesNames_ = input.readStringRequireUtf8(); + break; } // case 58 case 66: { @@ -5543,221 +5415,107 @@ public Builder setReachabilityBytes( return this; } - private com.google.protobuf.Internal.IntList services_ = emptyIntList(); - private void ensureServicesIsMutable() { - if (!((bitField0_ & 0x00000001) != 0)) { - services_ = mutableCopy(services_); - bitField0_ |= 0x00000001; - } - } - /** - *
-       * List of services provided by the node.
-       * 
- * - * repeated int32 services = 6 [json_name = "services"]; - * @return A list containing the services. - */ - public java.util.List - getServicesList() { - return ((bitField0_ & 0x00000001) != 0) ? - java.util.Collections.unmodifiableList(services_) : services_; - } - /** - *
-       * List of services provided by the node.
-       * 
- * - * repeated int32 services = 6 [json_name = "services"]; - * @return The count of services. - */ - public int getServicesCount() { - return services_.size(); - } + private int services_ ; /** *
-       * List of services provided by the node.
+       * A bitfield indicating the services provided by the node.
        * 
* - * repeated int32 services = 6 [json_name = "services"]; - * @param index The index of the element to return. - * @return The services at the given index. + * int32 services = 6 [json_name = "services"]; + * @return The services. */ - public int getServices(int index) { - return services_.getInt(index); + @java.lang.Override + public int getServices() { + return services_; } /** *
-       * List of services provided by the node.
+       * A bitfield indicating the services provided by the node.
        * 
* - * repeated int32 services = 6 [json_name = "services"]; - * @param index The index to set the value at. + * int32 services = 6 [json_name = "services"]; * @param value The services to set. * @return This builder for chaining. */ - public Builder setServices( - int index, int value) { - ensureServicesIsMutable(); - services_.setInt(index, value); - onChanged(); - return this; - } - /** - *
-       * List of services provided by the node.
-       * 
- * - * repeated int32 services = 6 [json_name = "services"]; - * @param value The services to add. - * @return This builder for chaining. - */ - public Builder addServices(int value) { - ensureServicesIsMutable(); - services_.addInt(value); - onChanged(); - return this; - } - /** - *
-       * List of services provided by the node.
-       * 
- * - * repeated int32 services = 6 [json_name = "services"]; - * @param values The services to add. - * @return This builder for chaining. - */ - public Builder addAllServices( - java.lang.Iterable values) { - ensureServicesIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, services_); + public Builder setServices(int value) { + + services_ = value; onChanged(); return this; } /** *
-       * List of services provided by the node.
+       * A bitfield indicating the services provided by the node.
        * 
* - * repeated int32 services = 6 [json_name = "services"]; + * int32 services = 6 [json_name = "services"]; * @return This builder for chaining. */ public Builder clearServices() { - services_ = emptyIntList(); - bitField0_ = (bitField0_ & ~0x00000001); + + services_ = 0; onChanged(); return this; } - private com.google.protobuf.LazyStringList servicesNames_ = com.google.protobuf.LazyStringArrayList.EMPTY; - private void ensureServicesNamesIsMutable() { - if (!((bitField0_ & 0x00000002) != 0)) { - servicesNames_ = new com.google.protobuf.LazyStringArrayList(servicesNames_); - bitField0_ |= 0x00000002; - } - } + private java.lang.Object servicesNames_ = ""; /** *
        * Names of services provided by the node.
        * 
* - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @return A list containing the servicesNames. + * string services_names = 7 [json_name = "servicesNames"]; + * @return The servicesNames. */ - public com.google.protobuf.ProtocolStringList - getServicesNamesList() { - return servicesNames_.getUnmodifiableView(); - } - /** - *
-       * Names of services provided by the node.
-       * 
- * - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @return The count of servicesNames. - */ - public int getServicesNamesCount() { - return servicesNames_.size(); - } - /** - *
-       * Names of services provided by the node.
-       * 
- * - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @param index The index of the element to return. - * @return The servicesNames at the given index. - */ - public java.lang.String getServicesNames(int index) { - return servicesNames_.get(index); + public java.lang.String getServicesNames() { + java.lang.Object ref = servicesNames_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + servicesNames_ = s; + return s; + } else { + return (java.lang.String) ref; + } } /** *
        * Names of services provided by the node.
        * 
* - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @param index The index of the value to return. - * @return The bytes of the servicesNames at the given index. + * string services_names = 7 [json_name = "servicesNames"]; + * @return The bytes for servicesNames. */ public com.google.protobuf.ByteString - getServicesNamesBytes(int index) { - return servicesNames_.getByteString(index); + getServicesNamesBytes() { + java.lang.Object ref = servicesNames_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + servicesNames_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } } /** *
        * Names of services provided by the node.
        * 
* - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @param index The index to set the value at. + * string services_names = 7 [json_name = "servicesNames"]; * @param value The servicesNames to set. * @return This builder for chaining. */ public Builder setServicesNames( - int index, java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - ensureServicesNamesIsMutable(); - servicesNames_.set(index, value); - onChanged(); - return this; - } - /** - *
-       * Names of services provided by the node.
-       * 
- * - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @param value The servicesNames to add. - * @return This builder for chaining. - */ - public Builder addServicesNames( java.lang.String value) { if (value == null) { throw new NullPointerException(); } - ensureServicesNamesIsMutable(); - servicesNames_.add(value); - onChanged(); - return this; - } - /** - *
-       * Names of services provided by the node.
-       * 
- * - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @param values The servicesNames to add. - * @return This builder for chaining. - */ - public Builder addAllServicesNames( - java.lang.Iterable values) { - ensureServicesNamesIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, servicesNames_); + + servicesNames_ = value; onChanged(); return this; } @@ -5766,12 +5524,12 @@ public Builder addAllServicesNames( * Names of services provided by the node. *
* - * repeated string services_names = 7 [json_name = "servicesNames"]; + * string services_names = 7 [json_name = "servicesNames"]; * @return This builder for chaining. */ public Builder clearServicesNames() { - servicesNames_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000002); + + servicesNames_ = getDefaultInstance().getServicesNames(); onChanged(); return this; } @@ -5780,27 +5538,27 @@ public Builder clearServicesNames() { * Names of services provided by the node. * * - * repeated string services_names = 7 [json_name = "servicesNames"]; - * @param value The bytes of the servicesNames to add. + * string services_names = 7 [json_name = "servicesNames"]; + * @param value The bytes for servicesNames to set. * @return This builder for chaining. */ - public Builder addServicesNamesBytes( + public Builder setServicesNamesBytes( com.google.protobuf.ByteString value) { if (value == null) { throw new NullPointerException(); } checkByteStringIsUtf8(value); - ensureServicesNamesIsMutable(); - servicesNames_.add(value); + + servicesNames_ = value; onChanged(); return this; } private com.google.protobuf.LazyStringList localAddrs_ = com.google.protobuf.LazyStringArrayList.EMPTY; private void ensureLocalAddrsIsMutable() { - if (!((bitField0_ & 0x00000004) != 0)) { + if (!((bitField0_ & 0x00000001) != 0)) { localAddrs_ = new com.google.protobuf.LazyStringArrayList(localAddrs_); - bitField0_ |= 0x00000004; + bitField0_ |= 0x00000001; } } /** @@ -5917,7 +5675,7 @@ public Builder addAllLocalAddrs( */ public Builder clearLocalAddrs() { localAddrs_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000004); + bitField0_ = (bitField0_ & ~0x00000001); onChanged(); return this; } @@ -5944,9 +5702,9 @@ public Builder addLocalAddrsBytes( private com.google.protobuf.LazyStringList protocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; private void ensureProtocolsIsMutable() { - if (!((bitField0_ & 0x00000008) != 0)) { + if (!((bitField0_ & 0x00000002) != 0)) { protocols_ = new com.google.protobuf.LazyStringArrayList(protocols_); - bitField0_ |= 0x00000008; + bitField0_ |= 0x00000002; } } /** @@ -6063,7 +5821,7 @@ public Builder addAllProtocols( */ public Builder clearProtocols() { protocols_ = com.google.protobuf.LazyStringArrayList.EMPTY; - bitField0_ = (bitField0_ & ~0x00000008); + bitField0_ = (bitField0_ & ~0x00000002); onChanged(); return this; } @@ -10326,7 +10084,7 @@ public pactus.network.NetworkOuterClass.PeerInfo getDefaultInstanceForType() { "nt\030\002 \001(\tR\005agent\022\027\n\007peer_id\030\003 \001(\tR\006peerId" + "\022\035\n\nstarted_at\030\004 \001(\004R\tstartedAt\022\"\n\014reach" + "ability\030\005 \001(\tR\014reachability\022\032\n\010services\030" + - "\006 \003(\005R\010services\022%\n\016services_names\030\007 \003(\tR" + + "\006 \001(\005R\010services\022%\n\016services_names\030\007 \001(\tR" + "\rservicesNames\022\037\n\013local_addrs\030\010 \003(\tR\nloc" + "alAddrs\022\034\n\tprotocols\030\t \003(\tR\tprotocols\022!\n" + "\014clock_offset\030\r \001(\001R\013clockOffset\022?\n\017conn" + diff --git a/www/grpc/gen/js/network_pb.js b/www/grpc/gen/js/network_pb.js index 54753c111..6e10b07af 100644 --- a/www/grpc/gen/js/network_pb.js +++ b/www/grpc/gen/js/network_pb.js @@ -928,7 +928,7 @@ proto.pactus.ConnectionInfo.prototype.setOutboundConnections = function(value) { * @private {!Array} * @const */ -proto.pactus.GetNodeInfoResponse.repeatedFields_ = [6,7,8,9]; +proto.pactus.GetNodeInfoResponse.repeatedFields_ = [8,9]; @@ -966,8 +966,8 @@ proto.pactus.GetNodeInfoResponse.toObject = function(includeInstance, msg) { peerId: jspb.Message.getFieldWithDefault(msg, 3, ""), startedAt: jspb.Message.getFieldWithDefault(msg, 4, 0), reachability: jspb.Message.getFieldWithDefault(msg, 5, ""), - servicesList: (f = jspb.Message.getRepeatedField(msg, 6)) == null ? undefined : f, - servicesNamesList: (f = jspb.Message.getRepeatedField(msg, 7)) == null ? undefined : f, + services: jspb.Message.getFieldWithDefault(msg, 6, 0), + servicesNames: jspb.Message.getFieldWithDefault(msg, 7, ""), localAddrsList: (f = jspb.Message.getRepeatedField(msg, 8)) == null ? undefined : f, protocolsList: (f = jspb.Message.getRepeatedField(msg, 9)) == null ? undefined : f, clockOffset: jspb.Message.getFloatingPointFieldWithDefault(msg, 13, 0.0), @@ -1029,14 +1029,12 @@ proto.pactus.GetNodeInfoResponse.deserializeBinaryFromReader = function(msg, rea msg.setReachability(value); break; case 6: - var values = /** @type {!Array} */ (reader.isDelimited() ? reader.readPackedInt32() : [reader.readInt32()]); - for (var i = 0; i < values.length; i++) { - msg.addServices(values[i]); - } + var value = /** @type {number} */ (reader.readInt32()); + msg.setServices(value); break; case 7: var value = /** @type {string} */ (reader.readString()); - msg.addServicesNames(value); + msg.setServicesNames(value); break; case 8: var value = /** @type {string} */ (reader.readString()); @@ -1119,16 +1117,16 @@ proto.pactus.GetNodeInfoResponse.serializeBinaryToWriter = function(message, wri f ); } - f = message.getServicesList(); - if (f.length > 0) { - writer.writePackedInt32( + f = message.getServices(); + if (f !== 0) { + writer.writeInt32( 6, f ); } - f = message.getServicesNamesList(); + f = message.getServicesNames(); if (f.length > 0) { - writer.writeRepeatedString( + writer.writeString( 7, f ); @@ -1256,76 +1254,38 @@ proto.pactus.GetNodeInfoResponse.prototype.setReachability = function(value) { /** - * repeated int32 services = 6; - * @return {!Array} - */ -proto.pactus.GetNodeInfoResponse.prototype.getServicesList = function() { - return /** @type {!Array} */ (jspb.Message.getRepeatedField(this, 6)); -}; - - -/** - * @param {!Array} value - * @return {!proto.pactus.GetNodeInfoResponse} returns this + * optional int32 services = 6; + * @return {number} */ -proto.pactus.GetNodeInfoResponse.prototype.setServicesList = function(value) { - return jspb.Message.setField(this, 6, value || []); +proto.pactus.GetNodeInfoResponse.prototype.getServices = function() { + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 6, 0)); }; /** * @param {number} value - * @param {number=} opt_index - * @return {!proto.pactus.GetNodeInfoResponse} returns this - */ -proto.pactus.GetNodeInfoResponse.prototype.addServices = function(value, opt_index) { - return jspb.Message.addToRepeatedField(this, 6, value, opt_index); -}; - - -/** - * Clears the list making it empty but non-null. * @return {!proto.pactus.GetNodeInfoResponse} returns this */ -proto.pactus.GetNodeInfoResponse.prototype.clearServicesList = function() { - return this.setServicesList([]); +proto.pactus.GetNodeInfoResponse.prototype.setServices = function(value) { + return jspb.Message.setProto3IntField(this, 6, value); }; /** - * repeated string services_names = 7; - * @return {!Array} - */ -proto.pactus.GetNodeInfoResponse.prototype.getServicesNamesList = function() { - return /** @type {!Array} */ (jspb.Message.getRepeatedField(this, 7)); -}; - - -/** - * @param {!Array} value - * @return {!proto.pactus.GetNodeInfoResponse} returns this + * optional string services_names = 7; + * @return {string} */ -proto.pactus.GetNodeInfoResponse.prototype.setServicesNamesList = function(value) { - return jspb.Message.setField(this, 7, value || []); +proto.pactus.GetNodeInfoResponse.prototype.getServicesNames = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 7, "")); }; /** * @param {string} value - * @param {number=} opt_index - * @return {!proto.pactus.GetNodeInfoResponse} returns this - */ -proto.pactus.GetNodeInfoResponse.prototype.addServicesNames = function(value, opt_index) { - return jspb.Message.addToRepeatedField(this, 7, value, opt_index); -}; - - -/** - * Clears the list making it empty but non-null. * @return {!proto.pactus.GetNodeInfoResponse} returns this */ -proto.pactus.GetNodeInfoResponse.prototype.clearServicesNamesList = function() { - return this.setServicesNamesList([]); +proto.pactus.GetNodeInfoResponse.prototype.setServicesNames = function(value) { + return jspb.Message.setProto3StringField(this, 7, value); }; diff --git a/www/grpc/gen/python/network_pb2.py b/www/grpc/gen/python/network_pb2.py index 1112bd426..c5b3553e0 100644 --- a/www/grpc/gen/python/network_pb2.py +++ b/www/grpc/gen/python/network_pb2.py @@ -13,7 +13,7 @@ -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rnetwork.proto\x12\x06pactus\">\n\x15GetNetworkInfoRequest\x12%\n\x0eonly_connected\x18\x01 \x01(\x08R\ronlyConnected\"\xae\x04\n\x16GetNetworkInfoResponse\x12!\n\x0cnetwork_name\x18\x01 \x01(\tR\x0bnetworkName\x12(\n\x10total_sent_bytes\x18\x02 \x01(\x03R\x0etotalSentBytes\x12\x30\n\x14total_received_bytes\x18\x03 \x01(\x03R\x12totalReceivedBytes\x12\x32\n\x15\x63onnected_peers_count\x18\x04 \x01(\rR\x13\x63onnectedPeersCount\x12\x39\n\x0f\x63onnected_peers\x18\x05 \x03(\x0b\x32\x10.pactus.PeerInfoR\x0e\x63onnectedPeers\x12L\n\nsent_bytes\x18\x06 \x03(\x0b\x32-.pactus.GetNetworkInfoResponse.SentBytesEntryR\tsentBytes\x12X\n\x0ereceived_bytes\x18\x07 \x03(\x0b\x32\x31.pactus.GetNetworkInfoResponse.ReceivedBytesEntryR\rreceivedBytes\x1a<\n\x0eSentBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\x1a@\n\x12ReceivedBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\"\x14\n\x12GetNodeInfoRequest\"\x96\x01\n\x0e\x43onnectionInfo\x12 \n\x0b\x63onnections\x18\x01 \x01(\x04R\x0b\x63onnections\x12/\n\x13inbound_connections\x18\x02 \x01(\x04R\x12inboundConnections\x12\x31\n\x14outbound_connections\x18\x03 \x01(\x04R\x13outboundConnections\"\x87\x03\n\x13GetNodeInfoResponse\x12\x18\n\x07moniker\x18\x01 \x01(\tR\x07moniker\x12\x14\n\x05\x61gent\x18\x02 \x01(\tR\x05\x61gent\x12\x17\n\x07peer_id\x18\x03 \x01(\tR\x06peerId\x12\x1d\n\nstarted_at\x18\x04 \x01(\x04R\tstartedAt\x12\"\n\x0creachability\x18\x05 \x01(\tR\x0creachability\x12\x1a\n\x08services\x18\x06 \x03(\x05R\x08services\x12%\n\x0eservices_names\x18\x07 \x03(\tR\rservicesNames\x12\x1f\n\x0blocal_addrs\x18\x08 \x03(\tR\nlocalAddrs\x12\x1c\n\tprotocols\x18\t \x03(\tR\tprotocols\x12!\n\x0c\x63lock_offset\x18\r \x01(\x01R\x0b\x63lockOffset\x12?\n\x0f\x63onnection_info\x18\x0e \x01(\x0b\x32\x16.pactus.ConnectionInfoR\x0e\x63onnectionInfo\"\xed\x06\n\x08PeerInfo\x12\x16\n\x06status\x18\x01 \x01(\x05R\x06status\x12\x18\n\x07moniker\x18\x02 \x01(\tR\x07moniker\x12\x14\n\x05\x61gent\x18\x03 \x01(\tR\x05\x61gent\x12\x17\n\x07peer_id\x18\x04 \x01(\tR\x06peerId\x12%\n\x0e\x63onsensus_keys\x18\x05 \x03(\tR\rconsensusKeys\x12/\n\x13\x63onsensus_addresses\x18\x06 \x03(\tR\x12\x63onsensusAddresses\x12\x1a\n\x08services\x18\x07 \x01(\rR\x08services\x12&\n\x0flast_block_hash\x18\x08 \x01(\tR\rlastBlockHash\x12\x16\n\x06height\x18\t \x01(\rR\x06height\x12)\n\x10received_bundles\x18\n \x01(\x05R\x0freceivedBundles\x12\'\n\x0finvalid_bundles\x18\x0b \x01(\x05R\x0einvalidBundles\x12\x1b\n\tlast_sent\x18\x0c \x01(\x03R\x08lastSent\x12#\n\rlast_received\x18\r \x01(\x03R\x0clastReceived\x12>\n\nsent_bytes\x18\x0e \x03(\x0b\x32\x1f.pactus.PeerInfo.SentBytesEntryR\tsentBytes\x12J\n\x0ereceived_bytes\x18\x0f \x03(\x0b\x32#.pactus.PeerInfo.ReceivedBytesEntryR\rreceivedBytes\x12\x18\n\x07\x61\x64\x64ress\x18\x10 \x01(\tR\x07\x61\x64\x64ress\x12\x1c\n\tdirection\x18\x11 \x01(\tR\tdirection\x12\x1c\n\tprotocols\x18\x12 \x03(\tR\tprotocols\x12%\n\x0etotal_sessions\x18\x13 \x01(\x05R\rtotalSessions\x12-\n\x12\x63ompleted_sessions\x18\x14 \x01(\x05R\x11\x63ompletedSessions\x1a<\n\x0eSentBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\x1a@\n\x12ReceivedBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\x32\xa2\x01\n\x07Network\x12O\n\x0eGetNetworkInfo\x12\x1d.pactus.GetNetworkInfoRequest\x1a\x1e.pactus.GetNetworkInfoResponse\x12\x46\n\x0bGetNodeInfo\x12\x1a.pactus.GetNodeInfoRequest\x1a\x1b.pactus.GetNodeInfoResponseBB\n\x0epactus.networkZ0github.com/pactus-project/pactus/www/grpc/pactusb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rnetwork.proto\x12\x06pactus\">\n\x15GetNetworkInfoRequest\x12%\n\x0eonly_connected\x18\x01 \x01(\x08R\ronlyConnected\"\xae\x04\n\x16GetNetworkInfoResponse\x12!\n\x0cnetwork_name\x18\x01 \x01(\tR\x0bnetworkName\x12(\n\x10total_sent_bytes\x18\x02 \x01(\x03R\x0etotalSentBytes\x12\x30\n\x14total_received_bytes\x18\x03 \x01(\x03R\x12totalReceivedBytes\x12\x32\n\x15\x63onnected_peers_count\x18\x04 \x01(\rR\x13\x63onnectedPeersCount\x12\x39\n\x0f\x63onnected_peers\x18\x05 \x03(\x0b\x32\x10.pactus.PeerInfoR\x0e\x63onnectedPeers\x12L\n\nsent_bytes\x18\x06 \x03(\x0b\x32-.pactus.GetNetworkInfoResponse.SentBytesEntryR\tsentBytes\x12X\n\x0ereceived_bytes\x18\x07 \x03(\x0b\x32\x31.pactus.GetNetworkInfoResponse.ReceivedBytesEntryR\rreceivedBytes\x1a<\n\x0eSentBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\x1a@\n\x12ReceivedBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\"\x14\n\x12GetNodeInfoRequest\"\x96\x01\n\x0e\x43onnectionInfo\x12 \n\x0b\x63onnections\x18\x01 \x01(\x04R\x0b\x63onnections\x12/\n\x13inbound_connections\x18\x02 \x01(\x04R\x12inboundConnections\x12\x31\n\x14outbound_connections\x18\x03 \x01(\x04R\x13outboundConnections\"\x87\x03\n\x13GetNodeInfoResponse\x12\x18\n\x07moniker\x18\x01 \x01(\tR\x07moniker\x12\x14\n\x05\x61gent\x18\x02 \x01(\tR\x05\x61gent\x12\x17\n\x07peer_id\x18\x03 \x01(\tR\x06peerId\x12\x1d\n\nstarted_at\x18\x04 \x01(\x04R\tstartedAt\x12\"\n\x0creachability\x18\x05 \x01(\tR\x0creachability\x12\x1a\n\x08services\x18\x06 \x01(\x05R\x08services\x12%\n\x0eservices_names\x18\x07 \x01(\tR\rservicesNames\x12\x1f\n\x0blocal_addrs\x18\x08 \x03(\tR\nlocalAddrs\x12\x1c\n\tprotocols\x18\t \x03(\tR\tprotocols\x12!\n\x0c\x63lock_offset\x18\r \x01(\x01R\x0b\x63lockOffset\x12?\n\x0f\x63onnection_info\x18\x0e \x01(\x0b\x32\x16.pactus.ConnectionInfoR\x0e\x63onnectionInfo\"\xed\x06\n\x08PeerInfo\x12\x16\n\x06status\x18\x01 \x01(\x05R\x06status\x12\x18\n\x07moniker\x18\x02 \x01(\tR\x07moniker\x12\x14\n\x05\x61gent\x18\x03 \x01(\tR\x05\x61gent\x12\x17\n\x07peer_id\x18\x04 \x01(\tR\x06peerId\x12%\n\x0e\x63onsensus_keys\x18\x05 \x03(\tR\rconsensusKeys\x12/\n\x13\x63onsensus_addresses\x18\x06 \x03(\tR\x12\x63onsensusAddresses\x12\x1a\n\x08services\x18\x07 \x01(\rR\x08services\x12&\n\x0flast_block_hash\x18\x08 \x01(\tR\rlastBlockHash\x12\x16\n\x06height\x18\t \x01(\rR\x06height\x12)\n\x10received_bundles\x18\n \x01(\x05R\x0freceivedBundles\x12\'\n\x0finvalid_bundles\x18\x0b \x01(\x05R\x0einvalidBundles\x12\x1b\n\tlast_sent\x18\x0c \x01(\x03R\x08lastSent\x12#\n\rlast_received\x18\r \x01(\x03R\x0clastReceived\x12>\n\nsent_bytes\x18\x0e \x03(\x0b\x32\x1f.pactus.PeerInfo.SentBytesEntryR\tsentBytes\x12J\n\x0ereceived_bytes\x18\x0f \x03(\x0b\x32#.pactus.PeerInfo.ReceivedBytesEntryR\rreceivedBytes\x12\x18\n\x07\x61\x64\x64ress\x18\x10 \x01(\tR\x07\x61\x64\x64ress\x12\x1c\n\tdirection\x18\x11 \x01(\tR\tdirection\x12\x1c\n\tprotocols\x18\x12 \x03(\tR\tprotocols\x12%\n\x0etotal_sessions\x18\x13 \x01(\x05R\rtotalSessions\x12-\n\x12\x63ompleted_sessions\x18\x14 \x01(\x05R\x11\x63ompletedSessions\x1a<\n\x0eSentBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\x1a@\n\x12ReceivedBytesEntry\x12\x10\n\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n\x05value\x18\x02 \x01(\x03R\x05value:\x02\x38\x01\x32\xa2\x01\n\x07Network\x12O\n\x0eGetNetworkInfo\x12\x1d.pactus.GetNetworkInfoRequest\x1a\x1e.pactus.GetNetworkInfoResponse\x12\x46\n\x0bGetNodeInfo\x12\x1a.pactus.GetNodeInfoRequest\x1a\x1b.pactus.GetNodeInfoResponseBB\n\x0epactus.networkZ0github.com/pactus-project/pactus/www/grpc/pactusb\x06proto3') _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'network_pb2', globals()) diff --git a/www/grpc/gen/rust/pactus.rs b/www/grpc/gen/rust/pactus.rs index 8bbe8bd42..45669cf95 100644 --- a/www/grpc/gen/rust/pactus.rs +++ b/www/grpc/gen/rust/pactus.rs @@ -839,12 +839,12 @@ pub struct GetNodeInfoResponse { /// Reachability status of the node. #[prost(string, tag="5")] pub reachability: ::prost::alloc::string::String, - /// List of services provided by the node. - #[prost(int32, repeated, tag="6")] - pub services: ::prost::alloc::vec::Vec, + /// A bitfield indicating the services provided by the node. + #[prost(int32, tag="6")] + pub services: i32, /// Names of services provided by the node. - #[prost(string, repeated, tag="7")] - pub services_names: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, + #[prost(string, tag="7")] + pub services_names: ::prost::alloc::string::String, /// List of addresses associated with the node. #[prost(string, repeated, tag="8")] pub local_addrs: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, diff --git a/www/grpc/gen/rust/pactus.serde.rs b/www/grpc/gen/rust/pactus.serde.rs index 7cd19d589..04d1eaf0b 100644 --- a/www/grpc/gen/rust/pactus.serde.rs +++ b/www/grpc/gen/rust/pactus.serde.rs @@ -3857,7 +3857,7 @@ impl serde::Serialize for GetNodeInfoResponse { if !self.reachability.is_empty() { len += 1; } - if !self.services.is_empty() { + if self.services != 0 { len += 1; } if !self.services_names.is_empty() { @@ -3891,7 +3891,7 @@ impl serde::Serialize for GetNodeInfoResponse { if !self.reachability.is_empty() { struct_ser.serialize_field("reachability", &self.reachability)?; } - if !self.services.is_empty() { + if self.services != 0 { struct_ser.serialize_field("services", &self.services)?; } if !self.services_names.is_empty() { @@ -4052,8 +4052,7 @@ impl<'de> serde::Deserialize<'de> for GetNodeInfoResponse { return Err(serde::de::Error::duplicate_field("services")); } services__ = - Some(map.next_value::>>()? - .into_iter().map(|x| x.0).collect()) + Some(map.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0) ; } GeneratedField::ServicesNames => { diff --git a/www/grpc/network.go b/www/grpc/network.go index 078c66600..ce2bd75a8 100644 --- a/www/grpc/network.go +++ b/www/grpc/network.go @@ -6,7 +6,6 @@ import ( "github.com/fxamacker/cbor/v2" "github.com/pactus-project/pactus/sync/peerset/peer" - "github.com/pactus-project/pactus/sync/peerset/peer/service" "github.com/pactus-project/pactus/version" pactus "github.com/pactus-project/pactus/www/grpc/gen/go" ) @@ -26,14 +25,6 @@ func (s *networkServer) GetNodeInfo(_ context.Context, ) (*pactus.GetNodeInfoResponse, error) { ps := s.sync.PeerSet() - services := []int32{} - servicesNames := []string{} - - if s.sync.Services().IsNetwork() { - services = append(services, int32(service.Network)) - servicesNames = append(servicesNames, "NETWORK") - } - clockOffset, err := s.sync.ClockOffset() if err != nil { s.logger.Warn("failed to get clock offset", "err", err) @@ -47,8 +38,8 @@ func (s *networkServer) GetNodeInfo(_ context.Context, LocalAddrs: s.net.HostAddrs(), StartedAt: uint64(ps.StartedAt().Unix()), Protocols: s.net.Protocols(), - Services: services, - ServicesNames: servicesNames, + Services: int32(s.sync.Services()), + ServicesNames: s.sync.Services().String(), ClockOffset: clockOffset.Seconds(), ConnectionInfo: &pactus.ConnectionInfo{ Connections: uint64(s.net.NumConnectedPeers()), diff --git a/www/grpc/proto/network.proto b/www/grpc/proto/network.proto index 39461493b..58387db86 100644 --- a/www/grpc/proto/network.proto +++ b/www/grpc/proto/network.proto @@ -63,10 +63,10 @@ message GetNodeInfoResponse { uint64 started_at = 4; // Reachability status of the node. string reachability = 5; - // List of services provided by the node. - repeated int32 services = 6; + // A bitfield indicating the services provided by the node. + int32 services = 6; // Names of services provided by the node. - repeated string services_names = 7; + string services_names = 7; // List of addresses associated with the node. repeated string local_addrs = 8; // List of protocols supported by the node. diff --git a/www/grpc/swagger-ui/pactus.swagger.json b/www/grpc/swagger-ui/pactus.swagger.json index ccf851722..b36f293e7 100644 --- a/www/grpc/swagger-ui/pactus.swagger.json +++ b/www/grpc/swagger-ui/pactus.swagger.json @@ -1721,18 +1721,12 @@ "description": "Reachability status of the node." }, "services": { - "type": "array", - "items": { - "type": "integer", - "format": "int32" - }, - "description": "List of services provided by the node." + "type": "integer", + "format": "int32", + "description": "A bitfield indicating the services provided by the node." }, "servicesNames": { - "type": "array", - "items": { - "type": "string" - }, + "type": "string", "description": "Names of services provided by the node." }, "localAddrs": { diff --git a/www/http/network.go b/www/http/network.go index 48e9d3faf..713f7aa0f 100644 --- a/www/http/network.go +++ b/www/http/network.go @@ -123,13 +123,13 @@ func (s *Server) NodeHandler(w http.ResponseWriter, r *http.Request) { tm.addRowTime("Started at", int64(res.StartedAt)) tm.addRowString("Reachability", res.Reachability) tm.addRowFloat64("Clock Offset", res.ClockOffset) - tm.addRowInts("Services", res.Services) - tm.addRowStrings("Services Names", res.ServicesNames) + tm.addRowInt("Services", int(res.Services)) + tm.addRowString("Services Names", res.ServicesNames) tm.addRowString("Connection Info", "---") - tm.addRowInt(" Total connections", int(res.ConnectionInfo.Connections)) - tm.addRowInt(" Inbound connections", int(res.ConnectionInfo.InboundConnections)) - tm.addRowInt(" Outbound connections", int(res.ConnectionInfo.OutboundConnections)) + tm.addRowInt("-- Total connections", int(res.ConnectionInfo.Connections)) + tm.addRowInt("-- Inbound connections", int(res.ConnectionInfo.InboundConnections)) + tm.addRowInt("-- Outbound connections", int(res.ConnectionInfo.OutboundConnections)) tm.addRowString("Protocols", "---") for i, p := range res.Protocols { diff --git a/www/http/server.go b/www/http/server.go index b5f0c3745..0a451a168 100644 --- a/www/http/server.go +++ b/www/http/server.go @@ -117,7 +117,6 @@ func (s *Server) StartServer(grpcServer string) error { s.logger.Error("error on a connection", "error", err) } } - s.logger.Info("http server started", "addr", listener.Addr()) } }()