diff --git a/api/management.go b/api/management.go index 6915e9566..e0bc3513c 100644 --- a/api/management.go +++ b/api/management.go @@ -21,70 +21,24 @@ type ( MultiAddresses []iotago.PrefixedStringUint8 `serix:",lenPrefix=uint8"` // The alias to identify the peer. Alias string `serix:",lenPrefix=uint8,omitempty"` - // The relation (static, autopeered) of the peer. + // The relation (manual, autopeered) of the peer. Relation string `serix:",lenPrefix=uint8"` // Whether the peer is connected. Connected bool `serix:""` - // The gossip related information about this peer. - Gossip *GossipInfo `serix:",optional,omitempty"` - } - - PeersResponse struct { - Peers []*PeerInfo `serix:",lenPrefix=uint8"` - } - - // GossipInfo represents information about an ongoing gossip protocol. - GossipInfo struct { - // The last received heartbeat by the given node. - Heartbeat *GossipHeartbeat `serix:",omitempty"` - // The metrics about sent and received protocol messages. - Metrics *PeerGossipMetrics `serix:",omitempty"` - } - - // GossipHeartbeat represents a gossip heartbeat message. - // Peers send each other this gossip protocol message when their - // state is updated, such as when: - // - a new slot was received - // - the solid slot changed - // - the node performed pruning of data - GossipHeartbeat struct { - // The solid slot of the node. - SolidSlot iotago.SlotIndex `serix:""` - // The oldest known slot by the node. - PrunedSlot iotago.SlotIndex `serix:""` - // The latest known slot by the node. - LatestSlot iotago.SlotIndex `serix:""` - // The amount of currently connected peers. - ConnectedPeers uint32 `serix:""` - // The amount of currently connected peers who also - // are synchronized with the network. - SyncedPeers uint32 `serix:""` + // The gossip metrics for this peer. + GossipMetrics *PeerGossipMetrics `serix:""` } // PeerGossipMetrics defines the peer gossip metrics. PeerGossipMetrics struct { - // The total amount of received new blocks. - NewBlocks uint32 `serix:""` - // The total amount of received known blocks. - KnownBlocks uint32 `serix:""` - // The total amount of received blocks. - ReceivedBlocks uint32 `serix:""` - // The total amount of received block requests. - ReceivedBlockRequests uint32 `serix:""` - // The total amount of received slot requests. - ReceivedSlotRequests uint32 `serix:""` - // The total amount of received heartbeats. - ReceivedHeartbeats uint32 `serix:""` - // The total amount of sent blocks. - SentBlocks uint32 `serix:""` - // The total amount of sent block request. - SentBlockRequests uint32 `serix:""` - // The total amount of sent slot request. - SentSlotRequests uint32 `serix:""` - // The total amount of sent heartbeats. - SentHeartbeats uint32 `serix:""` - // The total amount of packets which couldn't be sent. - DroppedPackets uint32 `serix:""` + // The total amount of received packets. + PacketsReceived uint32 `serix:""` + // The total amount of sent packets. + PacketsSent uint32 `serix:""` + } + + PeersResponse struct { + Peers []*PeerInfo `serix:",lenPrefix=uint8"` } // PruneDatabaseRequest defines the request of a prune database REST API call. @@ -102,18 +56,4 @@ type ( // The current oldest epoch in the database. Epoch iotago.EpochIndex `serix:""` } - - // CreateSnapshotsRequest defines the request of a create snapshots REST API call. - CreateSnapshotsRequest struct { - // The slot of the snapshot. - Slot iotago.SlotIndex `serix:""` - } - - // CreateSnapshotResponse defines the response of a create snapshot REST API call. - CreateSnapshotResponse struct { - // The slot of the snapshot. - Slot iotago.SlotIndex `serix:""` - // The file path of the snapshot file. - FilePath string `serix:",lenPrefix=uint8"` - } ) diff --git a/api/management_test.go b/api/management_test.go index 68ab1e30d..f78a34796 100644 --- a/api/management_test.go +++ b/api/management_test.go @@ -26,27 +26,9 @@ func Test_ManagementAPIDeSerialize(t *testing.T) { Alias: "alias", Relation: "relation", Connected: true, - Gossip: &api.GossipInfo{ - Heartbeat: &api.GossipHeartbeat{ - SolidSlot: 1, - PrunedSlot: 2, - LatestSlot: 3, - ConnectedPeers: 4, - SyncedPeers: 5, - }, - Metrics: &api.PeerGossipMetrics{ - NewBlocks: 1, - KnownBlocks: 2, - ReceivedBlocks: 3, - ReceivedBlockRequests: 4, - ReceivedSlotRequests: 5, - ReceivedHeartbeats: 6, - SentBlocks: 7, - SentBlockRequests: 8, - SentSlotRequests: 9, - SentHeartbeats: 10, - DroppedPackets: 11, - }, + GossipMetrics: &api.PeerGossipMetrics{ + PacketsReceived: 1, + PacketsSent: 2, }, }, Target: &api.PeerInfo{}, @@ -61,27 +43,9 @@ func Test_ManagementAPIDeSerialize(t *testing.T) { Alias: "alias", Relation: "relation", Connected: true, - Gossip: &api.GossipInfo{ - Heartbeat: &api.GossipHeartbeat{ - SolidSlot: 1, - PrunedSlot: 2, - LatestSlot: 3, - ConnectedPeers: 4, - SyncedPeers: 5, - }, - Metrics: &api.PeerGossipMetrics{ - NewBlocks: 1, - KnownBlocks: 2, - ReceivedBlocks: 3, - ReceivedBlockRequests: 4, - ReceivedSlotRequests: 5, - ReceivedHeartbeats: 6, - SentBlocks: 7, - SentBlockRequests: 8, - SentSlotRequests: 9, - SentHeartbeats: 10, - DroppedPackets: 11, - }, + GossipMetrics: &api.PeerGossipMetrics{ + PacketsReceived: 1, + PacketsSent: 2, }, }, }, @@ -104,21 +68,6 @@ func Test_ManagementAPIDeSerialize(t *testing.T) { }, Target: &api.PruneDatabaseResponse{}, }, - { - Name: "ok - CreateSnapshotsRequest", - Source: &api.CreateSnapshotsRequest{ - Slot: 1, - }, - Target: &api.CreateSnapshotsRequest{}, - }, - { - Name: "ok - CreateSnapshotResponse", - Source: &api.CreateSnapshotResponse{ - Slot: 1, - FilePath: "filePath", - }, - Target: &api.CreateSnapshotResponse{}, - }, } for _, tt := range tests { @@ -147,27 +96,9 @@ func Test_ManagementAPIJSONSerialization(t *testing.T) { Alias: "alias", Relation: "relation", Connected: true, - Gossip: &api.GossipInfo{ - Heartbeat: &api.GossipHeartbeat{ - SolidSlot: 1, - PrunedSlot: 2, - LatestSlot: 3, - ConnectedPeers: 4, - SyncedPeers: 5, - }, - Metrics: &api.PeerGossipMetrics{ - NewBlocks: 1, - KnownBlocks: 2, - ReceivedBlocks: 3, - ReceivedBlockRequests: 4, - ReceivedSlotRequests: 5, - ReceivedHeartbeats: 6, - SentBlocks: 7, - SentBlockRequests: 8, - SentSlotRequests: 9, - SentHeartbeats: 10, - DroppedPackets: 11, - }, + GossipMetrics: &api.PeerGossipMetrics{ + PacketsReceived: 1, + PacketsSent: 2, }, }, Target: `{ @@ -178,27 +109,9 @@ func Test_ManagementAPIJSONSerialization(t *testing.T) { "alias": "alias", "relation": "relation", "connected": true, - "gossip": { - "heartbeat": { - "solidSlot": 1, - "prunedSlot": 2, - "latestSlot": 3, - "connectedPeers": 4, - "syncedPeers": 5 - }, - "metrics": { - "newBlocks": 1, - "knownBlocks": 2, - "receivedBlocks": 3, - "receivedBlockRequests": 4, - "receivedSlotRequests": 5, - "receivedHeartbeats": 6, - "sentBlocks": 7, - "sentBlockRequests": 8, - "sentSlotRequests": 9, - "sentHeartbeats": 10, - "droppedPackets": 11 - } + "gossipMetrics": { + "packetsReceived": 1, + "packetsSent": 2 } }`, }, @@ -212,27 +125,9 @@ func Test_ManagementAPIJSONSerialization(t *testing.T) { Alias: "alias", Relation: "relation", Connected: true, - Gossip: &api.GossipInfo{ - Heartbeat: &api.GossipHeartbeat{ - SolidSlot: 1, - PrunedSlot: 2, - LatestSlot: 3, - ConnectedPeers: 4, - SyncedPeers: 5, - }, - Metrics: &api.PeerGossipMetrics{ - NewBlocks: 1, - KnownBlocks: 2, - ReceivedBlocks: 3, - ReceivedBlockRequests: 4, - ReceivedSlotRequests: 5, - ReceivedHeartbeats: 6, - SentBlocks: 7, - SentBlockRequests: 8, - SentSlotRequests: 9, - SentHeartbeats: 10, - DroppedPackets: 11, - }, + GossipMetrics: &api.PeerGossipMetrics{ + PacketsReceived: 1, + PacketsSent: 2, }, }, }, @@ -247,27 +142,9 @@ func Test_ManagementAPIJSONSerialization(t *testing.T) { "alias": "alias", "relation": "relation", "connected": true, - "gossip": { - "heartbeat": { - "solidSlot": 1, - "prunedSlot": 2, - "latestSlot": 3, - "connectedPeers": 4, - "syncedPeers": 5 - }, - "metrics": { - "newBlocks": 1, - "knownBlocks": 2, - "receivedBlocks": 3, - "receivedBlockRequests": 4, - "receivedSlotRequests": 5, - "receivedHeartbeats": 6, - "sentBlocks": 7, - "sentBlockRequests": 8, - "sentSlotRequests": 9, - "sentHeartbeats": 10, - "droppedPackets": 11 - } + "gossipMetrics": { + "packetsReceived": 1, + "packetsSent": 2 } } ] @@ -293,26 +170,6 @@ func Test_ManagementAPIJSONSerialization(t *testing.T) { }, Target: `{ "epoch": 1 -}`, - }, - { - Name: "ok - CreateSnapshotsRequest", - Source: &api.CreateSnapshotsRequest{ - Slot: 1, - }, - Target: `{ - "slot": 1 -}`, - }, - { - Name: "ok - CreateSnapshotResponse", - Source: &api.CreateSnapshotResponse{ - Slot: 1, - FilePath: "filePath", - }, - Target: `{ - "slot": 1, - "filePath": "filePath" }`, }, } diff --git a/nodeclient/management_client_test.go b/nodeclient/management_client_test.go index 72f43a6ff..8aa6b39a3 100644 --- a/nodeclient/management_client_test.go +++ b/nodeclient/management_client_test.go @@ -13,29 +13,6 @@ import ( "github.com/iotaledger/iota.go/v4/nodeclient" ) -var sampleGossipInfo = &api.GossipInfo{ - Heartbeat: &api.GossipHeartbeat{ - SolidSlot: 234, - PrunedSlot: 5872, - LatestSlot: 1294, - ConnectedPeers: 2392, - SyncedPeers: 1234, - }, - Metrics: &api.PeerGossipMetrics{ - NewBlocks: 40, - KnownBlocks: 60, - ReceivedBlocks: 100, - ReceivedBlockRequests: 345, - ReceivedSlotRequests: 194, - ReceivedHeartbeats: 5, - SentBlocks: 492, - SentBlockRequests: 2396, - SentSlotRequests: 9837, - SentHeartbeats: 3, - DroppedPackets: 10, - }, -} - func TestManagementClient_Enabled(t *testing.T) { defer gock.Off() @@ -74,7 +51,10 @@ func TestManagementClient_PeerByID(t *testing.T) { ID: peerID, Connected: true, Relation: "autopeered", - Gossip: sampleGossipInfo, + GossipMetrics: &api.PeerGossipMetrics{ + PacketsReceived: 1, + PacketsSent: 2, + }, } originRoutes := &api.RoutesResponse{ @@ -128,16 +108,22 @@ func TestManagementClient_Peers(t *testing.T) { ID: peerID, MultiAddresses: []iotago.PrefixedStringUint8{iotago.PrefixedStringUint8(fmt.Sprintf("/ip4/127.0.0.1/tcp/15600/p2p/%s", peerID))}, Relation: "autopeered", - Gossip: sampleGossipInfo, - Connected: true, + GossipMetrics: &api.PeerGossipMetrics{ + PacketsReceived: 1, + PacketsSent: 2, + }, + Connected: true, }, { ID: peerID2, MultiAddresses: []iotago.PrefixedStringUint8{iotago.PrefixedStringUint8(fmt.Sprintf("/ip4/127.0.0.1/tcp/15600/p2p/%s", peerID2))}, Alias: "Peer2", Relation: "static", - Gossip: sampleGossipInfo, - Connected: true, + GossipMetrics: &api.PeerGossipMetrics{ + PacketsReceived: 1, + PacketsSent: 2, + }, + Connected: true, }, }, } @@ -169,7 +155,10 @@ func TestManagementClient_AddPeer(t *testing.T) { MultiAddresses: []iotago.PrefixedStringUint8{iotago.PrefixedStringUint8(multiAddr)}, Relation: "autopeered", Connected: true, - Gossip: sampleGossipInfo, + GossipMetrics: &api.PeerGossipMetrics{ + PacketsReceived: 1, + PacketsSent: 2, + }, } req := &api.AddPeerRequest{MultiAddress: multiAddr}