diff --git a/app/appmessage/rpc_get_info.go b/app/appmessage/rpc_get_info.go index 4fff7ddeb..79729ab39 100644 --- a/app/appmessage/rpc_get_info.go +++ b/app/appmessage/rpc_get_info.go @@ -20,7 +20,8 @@ func NewGeInfoRequestMessage() *GetInfoRequestMessage { // its respective RPC message type GetInfoResponseMessage struct { baseMessage - P2PID string + P2PID string + MempoolSize uint64 Error *RPCError } @@ -31,8 +32,9 @@ func (msg *GetInfoResponseMessage) Command() MessageCommand { } // NewGetInfoResponseMessage returns a instance of the message -func NewGetInfoResponseMessage(p2pID string) *GetInfoResponseMessage { +func NewGetInfoResponseMessage(p2pID string, mempoolSize uint64) *GetInfoResponseMessage { return &GetInfoResponseMessage{ - P2PID: p2pID, + P2PID: p2pID, + MempoolSize: mempoolSize, } } diff --git a/app/rpc/rpchandlers/get_info.go b/app/rpc/rpchandlers/get_info.go index 3cdc43e0b..41fc033eb 100644 --- a/app/rpc/rpchandlers/get_info.go +++ b/app/rpc/rpchandlers/get_info.go @@ -8,6 +8,10 @@ import ( // HandleGetInfo handles the respectively named RPC command func HandleGetInfo(context *rpccontext.Context, _ *router.Router, _ appmessage.Message) (appmessage.Message, error) { - response := appmessage.NewGetInfoResponseMessage(context.NetAdapter.ID().String()) + response := appmessage.NewGetInfoResponseMessage( + context.NetAdapter.ID().String(), + uint64(context.Domain.MiningManager().TransactionCount()), + ) + return response, nil } diff --git a/domain/miningmanager/mempool/mempool.go b/domain/miningmanager/mempool/mempool.go index bb935dc35..397b0bc49 100644 --- a/domain/miningmanager/mempool/mempool.go +++ b/domain/miningmanager/mempool/mempool.go @@ -145,6 +145,13 @@ func (mp *mempool) AllTransactions() []*consensusexternalapi.DomainTransaction { return transactions } +func (mp *mempool) TransactionCount() int { + mp.mtx.RLock() + defer mp.mtx.RUnlock() + + return len(mp.pool) + len(mp.chainedTransactions) +} + // txDescriptor is a descriptor containing a transaction in the mempool along with // additional metadata. type txDescriptor struct { diff --git a/domain/miningmanager/miningmanager.go b/domain/miningmanager/miningmanager.go index bbbeb2b9b..bb393c100 100644 --- a/domain/miningmanager/miningmanager.go +++ b/domain/miningmanager/miningmanager.go @@ -11,6 +11,7 @@ type MiningManager interface { GetBlockTemplate(coinbaseData *consensusexternalapi.DomainCoinbaseData) (*consensusexternalapi.DomainBlock, error) GetTransaction(transactionID *consensusexternalapi.DomainTransactionID) (*consensusexternalapi.DomainTransaction, bool) AllTransactions() []*consensusexternalapi.DomainTransaction + TransactionCount() int HandleNewBlockTransactions(txs []*consensusexternalapi.DomainTransaction) ([]*consensusexternalapi.DomainTransaction, error) ValidateAndInsertTransaction(transaction *consensusexternalapi.DomainTransaction, allowOrphan bool) error } @@ -46,3 +47,7 @@ func (mm *miningManager) GetTransaction( func (mm *miningManager) AllTransactions() []*consensusexternalapi.DomainTransaction { return mm.mempool.AllTransactions() } + +func (mm *miningManager) TransactionCount() int { + return mm.mempool.TransactionCount() +} diff --git a/domain/miningmanager/model/interface_mempool.go b/domain/miningmanager/model/interface_mempool.go index 16b9b7ba8..e4a3a5f6a 100644 --- a/domain/miningmanager/model/interface_mempool.go +++ b/domain/miningmanager/model/interface_mempool.go @@ -13,4 +13,5 @@ type Mempool interface { RemoveTransactions(txs []*consensusexternalapi.DomainTransaction) error GetTransaction(transactionID *consensusexternalapi.DomainTransactionID) (*consensusexternalapi.DomainTransaction, bool) AllTransactions() []*consensusexternalapi.DomainTransaction + TransactionCount() int } diff --git a/infrastructure/network/netadapter/server/grpcserver/protowire/rpc.md b/infrastructure/network/netadapter/server/grpcserver/protowire/rpc.md index 8bbf73635..f0552e884 100644 --- a/infrastructure/network/netadapter/server/grpcserver/protowire/rpc.md +++ b/infrastructure/network/netadapter/server/grpcserver/protowire/rpc.md @@ -1546,6 +1546,7 @@ GetInfoRequestMessage returns info about the node. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | p2pId | [string](#string) | | | +| mempoolSize | [uint64](#uint64) | | | | error | [RPCError](#protowire.RPCError) | | | diff --git a/infrastructure/network/netadapter/server/grpcserver/protowire/rpc.pb.go b/infrastructure/network/netadapter/server/grpcserver/protowire/rpc.pb.go index 33e0ad4f4..290cb659a 100644 --- a/infrastructure/network/netadapter/server/grpcserver/protowire/rpc.pb.go +++ b/infrastructure/network/netadapter/server/grpcserver/protowire/rpc.pb.go @@ -5081,8 +5081,9 @@ type GetInfoResponseMessage struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - P2PId string `protobuf:"bytes,1,opt,name=p2pId,proto3" json:"p2pId,omitempty"` - Error *RPCError `protobuf:"bytes,1000,opt,name=error,proto3" json:"error,omitempty"` + P2PId string `protobuf:"bytes,1,opt,name=p2pId,proto3" json:"p2pId,omitempty"` + MempoolSize uint64 `protobuf:"varint,2,opt,name=mempoolSize,proto3" json:"mempoolSize,omitempty"` + Error *RPCError `protobuf:"bytes,1000,opt,name=error,proto3" json:"error,omitempty"` } func (x *GetInfoResponseMessage) Reset() { @@ -5124,6 +5125,13 @@ func (x *GetInfoResponseMessage) GetP2PId() string { return "" } +func (x *GetInfoResponseMessage) GetMempoolSize() uint64 { + if x != nil { + return x.MempoolSize + } + return 0 +} + func (x *GetInfoResponseMessage) GetError() *RPCError { if x != nil { return x.Error @@ -5782,15 +5790,18 @@ var file_rpc_proto_rawDesc = []byte{ 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x52, 0x50, 0x43, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x17, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x4d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x22, 0x5a, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, + 0x73, 0x61, 0x67, 0x65, 0x22, 0x7c, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x32, 0x70, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x70, - 0x32, 0x70, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0xe8, 0x07, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x77, 0x69, 0x72, 0x65, - 0x2e, 0x52, 0x50, 0x43, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, - 0x42, 0x26, 0x5a, 0x24, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6b, - 0x61, 0x73, 0x70, 0x61, 0x6e, 0x65, 0x74, 0x2f, 0x6b, 0x61, 0x73, 0x70, 0x61, 0x64, 0x2f, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x77, 0x69, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x32, 0x70, 0x49, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x6d, 0x65, 0x6d, 0x70, 0x6f, 0x6f, 0x6c, 0x53, + 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x6d, 0x65, 0x6d, 0x70, 0x6f, + 0x6f, 0x6c, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x2a, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, + 0xe8, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x77, 0x69, + 0x72, 0x65, 0x2e, 0x52, 0x50, 0x43, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x52, 0x05, 0x65, 0x72, 0x72, + 0x6f, 0x72, 0x42, 0x26, 0x5a, 0x24, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x6b, 0x61, 0x73, 0x70, 0x61, 0x6e, 0x65, 0x74, 0x2f, 0x6b, 0x61, 0x73, 0x70, 0x61, 0x64, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x77, 0x69, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( diff --git a/infrastructure/network/netadapter/server/grpcserver/protowire/rpc.proto b/infrastructure/network/netadapter/server/grpcserver/protowire/rpc.proto index 326a679df..2fb80d0d6 100644 --- a/infrastructure/network/netadapter/server/grpcserver/protowire/rpc.proto +++ b/infrastructure/network/netadapter/server/grpcserver/protowire/rpc.proto @@ -605,5 +605,6 @@ message GetInfoRequestMessage{ message GetInfoResponseMessage{ string p2pId = 1; + uint64 mempoolSize = 2; RPCError error = 1000; } diff --git a/infrastructure/network/netadapter/server/grpcserver/protowire/rpc_get_info.go b/infrastructure/network/netadapter/server/grpcserver/protowire/rpc_get_info.go index e89fd2f93..9baf4c2ec 100644 --- a/infrastructure/network/netadapter/server/grpcserver/protowire/rpc_get_info.go +++ b/infrastructure/network/netadapter/server/grpcserver/protowire/rpc_get_info.go @@ -27,8 +27,9 @@ func (x *KaspadMessage_GetInfoResponse) fromAppMessage(message *appmessage.GetIn err = &RPCError{Message: message.Error.Message} } x.GetInfoResponse = &GetInfoResponseMessage{ - P2PId: message.P2PID, - Error: err, + P2PId: message.P2PID, + MempoolSize: message.MempoolSize, + Error: err, } return nil } @@ -48,7 +49,8 @@ func (x *GetInfoResponseMessage) toAppMessage() (appmessage.Message, error) { } return &appmessage.GetInfoResponseMessage{ - P2PID: x.P2PId, - Error: rpcErr, + P2PID: x.P2PId, + MempoolSize: x.MempoolSize, + Error: rpcErr, }, nil }