mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-05 13:46:42 +00:00
Add the mempool size to getInfo RPC command (#1584)
* Add the mempool size to getInfo RPC command * Add mempool.Len() * Rename mempool.Len() to mempool.TransactionCount() Co-authored-by: Svarog <feanorr@gmail.com>
This commit is contained in:
parent
c084c69771
commit
b8413fcecb
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -13,4 +13,5 @@ type Mempool interface {
|
||||
RemoveTransactions(txs []*consensusexternalapi.DomainTransaction) error
|
||||
GetTransaction(transactionID *consensusexternalapi.DomainTransactionID) (*consensusexternalapi.DomainTransaction, bool)
|
||||
AllTransactions() []*consensusexternalapi.DomainTransaction
|
||||
TransactionCount() int
|
||||
}
|
||||
|
@ -1546,6 +1546,7 @@ GetInfoRequestMessage returns info about the node.
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| p2pId | [string](#string) | | |
|
||||
| mempoolSize | [uint64](#uint64) | | |
|
||||
| error | [RPCError](#protowire.RPCError) | | |
|
||||
|
||||
|
||||
|
@ -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 (
|
||||
|
@ -605,5 +605,6 @@ message GetInfoRequestMessage{
|
||||
|
||||
message GetInfoResponseMessage{
|
||||
string p2pId = 1;
|
||||
uint64 mempoolSize = 2;
|
||||
RPCError error = 1000;
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user