add to verbose data and getInfo

This commit is contained in:
D-Stacks 2022-10-16 12:15:17 +02:00
parent f820acd7df
commit 735f9c29e0
14 changed files with 1002 additions and 867 deletions

View File

@ -24,6 +24,8 @@ type GetInfoResponseMessage struct {
MempoolSize uint64 MempoolSize uint64
ServerVersion string ServerVersion string
IsUtxoIndexed bool IsUtxoIndexed bool
IsTxIndexed bool
IsArchival bool
IsSynced bool IsSynced bool
Error *RPCError Error *RPCError
@ -35,12 +37,15 @@ func (msg *GetInfoResponseMessage) Command() MessageCommand {
} }
// NewGetInfoResponseMessage returns a instance of the message // NewGetInfoResponseMessage returns a instance of the message
func NewGetInfoResponseMessage(p2pID string, mempoolSize uint64, serverVersion string, isUtxoIndexed bool, isSynced bool) *GetInfoResponseMessage { func NewGetInfoResponseMessage(p2pID string, mempoolSize uint64, serverVersion string, isUtxoIndexed bool,
isTxIndexed bool, isArchival bool, isSynced bool) *GetInfoResponseMessage {
return &GetInfoResponseMessage{ return &GetInfoResponseMessage{
P2PID: p2pID, P2PID: p2pID,
MempoolSize: mempoolSize, MempoolSize: mempoolSize,
ServerVersion: serverVersion, ServerVersion: serverVersion,
IsUtxoIndexed: isUtxoIndexed, IsUtxoIndexed: isUtxoIndexed,
IsTxIndexed: isTxIndexed,
IsArchival: isArchival,
IsSynced: isSynced, IsSynced: isSynced,
} }
} }

View File

@ -102,6 +102,9 @@ type RPCTransactionVerboseData struct {
Mass uint64 Mass uint64
BlockHash string BlockHash string
BlockTime uint64 BlockTime uint64
TxIndexed bool
AcceptingBlockHash string
Confirmations uint32
} }
// RPCTransactionInputVerboseData holds data about a transaction input // RPCTransactionInputVerboseData holds data about a transaction input

View File

@ -128,6 +128,26 @@ func (ctx *Context) PopulateTransactionWithVerboseData(
Hash: consensushashing.TransactionHash(domainTransaction).String(), Hash: consensushashing.TransactionHash(domainTransaction).String(),
Mass: domainTransaction.Mass, Mass: domainTransaction.Mass,
} }
if ctx.Config.TXIndex {
acceptingBlockHash, foundAcceptingBlockHash, err := ctx.TXIndex.TXAcceptingBlockHash(domainTransaction.ID)
if err != nil {
return err
}
confirmations, foundConfirmations, err := ctx.TXIndex.GetTXConfirmations(domainTransaction.ID)
if err != nil {
return err
}
if !foundAcceptingBlockHash || !foundConfirmations {
transaction.VerboseData.TxIndexed = false
} else {
transaction.VerboseData.TxIndexed = true
transaction.VerboseData.AcceptingBlockHash = acceptingBlockHash.String()
transaction.VerboseData.Confirmations = uint32(confirmations)
}
} else {
transaction.VerboseData.TxIndexed = false
}
if domainBlockHeader != nil { if domainBlockHeader != nil {
transaction.VerboseData.BlockHash = consensushashing.HeaderHash(domainBlockHeader).String() transaction.VerboseData.BlockHash = consensushashing.HeaderHash(domainBlockHeader).String()
transaction.VerboseData.BlockTime = uint64(domainBlockHeader.TimeInMilliseconds()) transaction.VerboseData.BlockTime = uint64(domainBlockHeader.TimeInMilliseconds())

View File

@ -19,6 +19,8 @@ func HandleGetInfo(context *rpccontext.Context, _ *router.Router, _ appmessage.M
uint64(context.Domain.MiningManager().TransactionCount(true, false)), uint64(context.Domain.MiningManager().TransactionCount(true, false)),
version.Version(), version.Version(),
context.Config.UTXOIndex, context.Config.UTXOIndex,
context.Config.TXIndex,
context.Config.IsArchivalNode,
context.ProtocolManager.Context().HasPeers() && isNearlySynced, context.ProtocolManager.Context().HasPeers() && isNearlySynced,
) )

View File

@ -249,6 +249,26 @@ func (ti *TXIndex) removeTXIDs(selectedParentChainChanges *externalapi.SelectedC
return nil return nil
} }
// TXAcceptingBlockHash returns the accepting block hash for for the given txID
func (ti *TXIndex) TXAcceptingBlockHash(txID *externalapi.DomainTransactionID) (
acceptingBlockHash *externalapi.DomainHash, found bool, err error) {
onEnd := logger.LogAndMeasureExecutionTime(log, "TXIndex.TXAcceptingBlockHash")
defer onEnd()
ti.mutex.Lock()
defer ti.mutex.Unlock()
txData, found, err := ti.store.getTxData(txID)
if err != nil {
return nil, false, err
}
if !found {
return nil, false, nil
}
return txData.AcceptingBlockHash, found, nil
}
// TXAcceptingBlockHashes returns the accepting block hashes for for the given txIDs // TXAcceptingBlockHashes returns the accepting block hashes for for the given txIDs
func (ti *TXIndex) TXAcceptingBlockHashes(txIDs []*externalapi.DomainTransactionID) ( func (ti *TXIndex) TXAcceptingBlockHashes(txIDs []*externalapi.DomainTransactionID) (
txIDsToAcceptingBlockHashes TxIDsToBlockHashes, missingTxIds []*externalapi.DomainTransactionID, err error) { txIDsToAcceptingBlockHashes TxIDsToBlockHashes, missingTxIds []*externalapi.DomainTransactionID, err error) {
@ -305,6 +325,33 @@ func (ti *TXIndex) GetTXs(txIDs []*externalapi.DomainTransactionID) (
return txs, notFound, nil return txs, notFound, nil
} }
// GetTXConfirmations returns the tx confirmations for for the given txID
func (ti *TXIndex) GetTXConfirmations(txID *externalapi.DomainTransactionID) (
confirmations int64, found bool, err error) {
onEnd := logger.LogAndMeasureExecutionTime(log, "TXIndex.GetTXConfirmations")
defer onEnd()
ti.mutex.Lock()
defer ti.mutex.Unlock()
txdata, found, err := ti.store.getTxData(txID)
if err != nil {
return 0, false, err
}
acceptingBlockHeader, err := ti.domain.Consensus().GetBlockHeader(txdata.AcceptingBlockHash)
if err != nil {
return -1, false, err
}
virtualBlock, err := ti.domain.Consensus().GetVirtualInfo()
if err != nil {
return 0, false, err
}
return int64(virtualBlock.BlueScore - acceptingBlockHeader.BlueScore()), true, nil
}
// GetTXsConfirmations returns the tx confirmations for for the given txIDs // GetTXsConfirmations returns the tx confirmations for for the given txIDs
func (ti *TXIndex) GetTXsConfirmations(txIDs []*externalapi.DomainTransactionID) ( func (ti *TXIndex) GetTXsConfirmations(txIDs []*externalapi.DomainTransactionID) (
txIDsToConfirmations TxIDsToConfirmations, notFound []*externalapi.DomainTransactionID, err error) { txIDsToConfirmations TxIDsToConfirmations, notFound []*externalapi.DomainTransactionID, err error) {

View File

@ -376,6 +376,9 @@ Receivers of any ResponseMessage are expected to check whether its error field i
| mass | [uint64](#uint64) | | | | mass | [uint64](#uint64) | | |
| blockHash | [string](#string) | | | | blockHash | [string](#string) | | |
| blockTime | [uint64](#uint64) | | | | blockTime | [uint64](#uint64) | | |
| txIndexed | [bool](#bool) | | whether the transaction is stored in the txindex database. Kaspad must be started with the `--txindex` flag, for parameter to display. |
| acceptingBlockHash | [string](#string) | | Kaspad must be started with the `--txindex` flag, for parameter to display. |
| confirmations | [uint32](#uint32) | | Kaspad must be started with the `--txindex` flag for parameter to display. |
@ -1963,7 +1966,7 @@ See NotifyNewBlockTemplateRequestMessage
<a name="protowire.GetAcceptingBlockHashesOfTxsRequestMessage"></a> <a name="protowire.GetAcceptingBlockHashesOfTxsRequestMessage"></a>
### GetAcceptingBlockHashesOfTxsRequestMessage ### GetAcceptingBlockHashesOfTxsRequestMessage
Kaspad most be started with the `--txindex` flag for this Request to work. Kaspad must be started with the `--txindex` flag for this Request to work.
| Field | Type | Label | Description | | Field | Type | Label | Description |
@ -1994,7 +1997,7 @@ Kaspad most be started with the `--txindex` flag for this Request to work.
<a name="protowire.GetTxsRequestMessage"></a> <a name="protowire.GetTxsRequestMessage"></a>
### GetTxsRequestMessage ### GetTxsRequestMessage
Kaspad most be started with the `--txindex` flag for this Request to work. Kaspad must be started with the `--txindex` flag for this Request to work.
| Field | Type | Label | Description | | Field | Type | Label | Description |
@ -2025,7 +2028,7 @@ Kaspad most be started with the `--txindex` flag for this Request to work.
<a name="protowire.GetTxsConfirmationsRequestMessage"></a> <a name="protowire.GetTxsConfirmationsRequestMessage"></a>
### GetTxsConfirmationsRequestMessage ### GetTxsConfirmationsRequestMessage
Kaspad most be started with the `--txindex` flag for this Request to work. Kaspad must be started with the `--txindex` flag for this Request to work.
| Field | Type | Label | Description | | Field | Type | Label | Description |
@ -2057,7 +2060,7 @@ Kaspad most be started with the `--txindex` flag for this Request to work.
### NotifyTxsConfirmationChangedRequestMessage ### NotifyTxsConfirmationChangedRequestMessage
NotifyTxsConfirmationChangedRequstMessage is a listener that registers confirmations from supplied TxIDs NotifyTxsConfirmationChangedRequstMessage is a listener that registers confirmations from supplied TxIDs
Kaspad most be started with the `--txindex` flag for this Request to work. Kaspad must be started with the `--txindex` flag for this Request to work.
| Field | Type | Label | Description | | Field | Type | Label | Description |
@ -2109,13 +2112,13 @@ TxsConfirmationChangedNotificationMessage is the notification about txs pertaini
### ModifyNotifyingTxsConfirmationChangedRequestMessage ### ModifyNotifyingTxsConfirmationChangedRequestMessage
ModifyNotifyingTxsConfirmationChangedRequestMessage modfies the params of a registered `NotifyTxsConfirmationChangedRequstMessage` ModifyNotifyingTxsConfirmationChangedRequestMessage modfies the params of a registered `NotifyTxsConfirmationChangedRequstMessage`
most be registered to NotifyTxsConfirmationChangedRequstMessage for this command to work must be registered to NotifyTxsConfirmationChangedRequstMessage for this command to work
| Field | Type | Label | Description | | Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- | | ----- | ---- | ----- | ----------- |
| addTxIDs | [string](#string) | repeated | | | addTxIDs | [string](#string) | repeated | add txIds to the notification stream |
| removeTxIDs | [string](#string) | repeated | | | removeTxIDs | [string](#string) | repeated | remove txIds to the notification stream |
| requiredConfirmations | [uint32](#uint32) | | | | requiredConfirmations | [uint32](#uint32) | | |
| includePending | [bool](#bool) | | | | includePending | [bool](#bool) | | |
@ -2210,13 +2213,13 @@ NotifyAddressesTxsChangedRequestMessage Listens for Txs pertaining to specified
### ModifyNotifyingAddressesTxsRequestMessage ### ModifyNotifyingAddressesTxsRequestMessage
ModifyNotifyAddressesTxsParamsRequestMessage modifies the params used for a regesitered `NotifyAddressesTxsRequest` ModifyNotifyAddressesTxsParamsRequestMessage modifies the params used for a regesitered `NotifyAddressesTxsRequest`
Most be registered to NotifyAddressTxChangedRequestMessage for this command to work Must be registered to NotifyAddressTxChangedRequestMessage for this command to work
| Field | Type | Label | Description | | Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- | | ----- | ---- | ----- | ----------- |
| AddAddresses | [string](#string) | repeated | | | AddAddresses | [string](#string) | repeated | add addresses to the notification stream |
| RemoveAddresses | [string](#string) | repeated | | | RemoveAddresses | [string](#string) | repeated | remove addresses to the notification stream |
| requiredConfirmations | [uint32](#uint32) | | | | requiredConfirmations | [uint32](#uint32) | | |
| includePending | [bool](#bool) | | | | includePending | [bool](#bool) | | |
| includeSending | [bool](#bool) | | | | includeSending | [bool](#bool) | | |

View File

@ -105,6 +105,9 @@ message RpcTransactionVerboseData{
uint64 mass = 4; uint64 mass = 4;
string blockHash = 12; string blockHash = 12;
uint64 blockTime = 14; uint64 blockTime = 14;
bool txIndexed = 15; //whether the transaction is stored in the txindex database, regardless if kaspad is run with the `--txindex` flag, or not.
string acceptingBlockHash = 16; // Kaspad must be started with the `--txindex` flag, for parameter to display.
uint32 confirmations = 17; // Kaspad must be started with the `--txindex` flag for parameter to display.
} }
message RpcTransactionInputVerboseData{ message RpcTransactionInputVerboseData{
@ -662,7 +665,10 @@ message GetInfoResponseMessage{
uint64 mempoolSize = 2; uint64 mempoolSize = 2;
string serverVersion = 3; string serverVersion = 3;
bool isUtxoIndexed = 4; bool isUtxoIndexed = 4;
bool isSynced = 5; bool isTxIndexed = 5;
bool isArchival = 6;
bool isSynced = 7;
RPCError error = 1000; RPCError error = 1000;
} }
@ -749,7 +755,7 @@ message RpcTxIDBlockPair {
RpcBlock block = 2; RpcBlock block = 2;
} }
// Kaspad most be started with the `--txindex` flag for this Request to work. // Kaspad must be started with the `--txindex` flag for this Request to work.
message GetAcceptingBlockHashesOfTxsRequestMessage{ message GetAcceptingBlockHashesOfTxsRequestMessage{
repeated string txIDs = 1; repeated string txIDs = 1;
} }
@ -759,7 +765,7 @@ message GetAcceptingBlockHashesOfTxsResponseMessage{
RPCError error = 1000; RPCError error = 1000;
} }
// Kaspad most be started with the `--txindex` flag for this Request to work. // Kaspad must be started with the `--txindex` flag for this Request to work.
message GetTxsRequestMessage{ message GetTxsRequestMessage{
repeated string txIDs = 1; repeated string txIDs = 1;
} }
@ -772,7 +778,7 @@ message GetTxsResponseMessage{
} }
//Kaspad most be started with the `--txindex` flag for this Request to work. // Kaspad must be started with the `--txindex` flag for this Request to work.
message GetTxsConfirmationsRequestMessage{ message GetTxsConfirmationsRequestMessage{
repeated string txIDs = 1; repeated string txIDs = 1;
} }
@ -784,7 +790,7 @@ message GetTxsConfirmationsResponseMessage{
} }
// NotifyTxsConfirmationChangedRequstMessage is a listener that registers confirmations from supplied TxIDs // NotifyTxsConfirmationChangedRequstMessage is a listener that registers confirmations from supplied TxIDs
// Kaspad most be started with the `--txindex` flag for this Request to work. // Kaspad must be started with the `--txindex` flag for this Request to work.
message NotifyTxsConfirmationChangedRequestMessage{ message NotifyTxsConfirmationChangedRequestMessage{
repeated string TxIDs = 1; //initial TxIds to listen for when regestering for notifications repeated string TxIDs = 1; //initial TxIds to listen for when regestering for notifications
@ -809,10 +815,10 @@ message TxsConfirmationChangedNotificationMessage{
} }
// ModifyNotifyingTxsConfirmationChangedRequestMessage modfies the params of a registered `NotifyTxsConfirmationChangedRequstMessage` // ModifyNotifyingTxsConfirmationChangedRequestMessage modfies the params of a registered `NotifyTxsConfirmationChangedRequstMessage`
// most be registered to NotifyTxsConfirmationChangedRequstMessage for this command to work // must be registered to NotifyTxsConfirmationChangedRequstMessage for this command to work
message ModifyNotifyingTxsConfirmationChangedRequestMessage{ message ModifyNotifyingTxsConfirmationChangedRequestMessage{
repeated string addTxIDs = 1; repeated string addTxIDs = 1; //add txIds to the notification stream
repeated string removeTxIDs = 2; repeated string removeTxIDs = 2; //remove txIds to the notification stream
uint32 requiredConfirmations = 3; uint32 requiredConfirmations = 3;
bool includePending = 4; bool includePending = 4;
} }
@ -842,15 +848,14 @@ message NotifyAddressesTxsRequestMessage{
} }
message NotifyAddressesTxsResponseMessage{ message NotifyAddressesTxsResponseMessage{
RPCError error = 1000; RPCError error = 1000;
} }
// ModifyNotifyAddressesTxsParamsRequestMessage modifies the params used for a regesitered `NotifyAddressesTxsRequest` // ModifyNotifyAddressesTxsParamsRequestMessage modifies the params used for a regesitered `NotifyAddressesTxsRequest`
// Most be registered to NotifyAddressTxChangedRequestMessage for this command to work // Must be registered to NotifyAddressTxChangedRequestMessage for this command to work
message ModifyNotifyingAddressesTxsRequestMessage{ message ModifyNotifyingAddressesTxsRequestMessage{
repeated string AddAddresses = 1; repeated string AddAddresses = 1; //add addresses to the notification stream
repeated string RemoveAddresses = 2; repeated string RemoveAddresses = 2; //remove addresses to the notification stream
uint32 requiredConfirmations = 3; uint32 requiredConfirmations = 3;
bool includePending = 4; bool includePending = 4;
bool includeSending = 5; bool includeSending = 5;

View File

@ -31,6 +31,8 @@ func (x *KaspadMessage_GetInfoResponse) fromAppMessage(message *appmessage.GetIn
ServerVersion: message.ServerVersion, ServerVersion: message.ServerVersion,
MempoolSize: message.MempoolSize, MempoolSize: message.MempoolSize,
IsUtxoIndexed: message.IsUtxoIndexed, IsUtxoIndexed: message.IsUtxoIndexed,
IsTxIndexed: message.IsTxIndexed;
IsArchival: message.IsArchival;
IsSynced: message.IsSynced, IsSynced: message.IsSynced,
Error: err, Error: err,
} }
@ -56,6 +58,8 @@ func (x *GetInfoResponseMessage) toAppMessage() (appmessage.Message, error) {
MempoolSize: x.MempoolSize, MempoolSize: x.MempoolSize,
ServerVersion: x.ServerVersion, ServerVersion: x.ServerVersion,
IsUtxoIndexed: x.IsUtxoIndexed, IsUtxoIndexed: x.IsUtxoIndexed,
IsTxIndexed: x.IsTxIndexed;
IsArchival: x.IsArchival;
IsSynced: x.IsSynced, IsSynced: x.IsSynced,
Error: rpcErr, Error: rpcErr,

View File

@ -14,6 +14,8 @@ func (x *KaspadMessage_ModifyNotifyingAddressesTxsRequest) toAppMessage() (appme
func (x *KaspadMessage_ModifyNotifyingAddressesTxsRequest) fromAppMessage(message *appmessage.ModifyNotifyingAddressesTxsRequestMessage) error { func (x *KaspadMessage_ModifyNotifyingAddressesTxsRequest) fromAppMessage(message *appmessage.ModifyNotifyingAddressesTxsRequestMessage) error {
x.ModifyNotifyingAddressesTxsRequest = &ModifyNotifyingAddressesTxsRequestMessage{ x.ModifyNotifyingAddressesTxsRequest = &ModifyNotifyingAddressesTxsRequestMessage{
AddAddresses: message.AddAddresses,
RemoveAddresses: message.RemoveAddresses,
RequiredConfirmations: message.RequiredConfirmations, RequiredConfirmations: message.RequiredConfirmations,
IncludePending: message.IncludePending, IncludePending: message.IncludePending,
IncludeSending: message.IncludeSending, IncludeSending: message.IncludeSending,
@ -27,6 +29,8 @@ func (x *ModifyNotifyingAddressesTxsRequestMessage) toAppMessage() (appmessage.M
return nil, errors.Wrapf(errorNil, "ModifyNotifyingAddressesTxsRequestMessage is nil") return nil, errors.Wrapf(errorNil, "ModifyNotifyingAddressesTxsRequestMessage is nil")
} }
return &appmessage.ModifyNotifyingAddressesTxsRequestMessage{ return &appmessage.ModifyNotifyingAddressesTxsRequestMessage{
AddAddresses: x.AddAddresses,
RemoveAddresses: x.RemoveAddresses,
RequiredConfirmations: x.RequiredConfirmations, RequiredConfirmations: x.RequiredConfirmations,
IncludePending: x.IncludePending, IncludePending: x.IncludePending,
IncludeSending: x.IncludeSending, IncludeSending: x.IncludeSending,

View File

@ -14,6 +14,8 @@ func (x *KaspadMessage_ModifyNotifyingTxsConfirmationChangedRequest) toAppMessag
func (x *KaspadMessage_ModifyNotifyingTxsConfirmationChangedRequest) fromAppMessage(message *appmessage.ModifyNotifyingTxsConfirmationChangedRequestMessage) error { func (x *KaspadMessage_ModifyNotifyingTxsConfirmationChangedRequest) fromAppMessage(message *appmessage.ModifyNotifyingTxsConfirmationChangedRequestMessage) error {
x.ModifyNotifyingTxsConfirmationChangedRequest = &ModifyNotifyingTxsConfirmationChangedRequestMessage{ x.ModifyNotifyingTxsConfirmationChangedRequest = &ModifyNotifyingTxsConfirmationChangedRequestMessage{
AddTxIDs: message.AddTxIDs,
RemoveTxIDs: message.RemoveTxIDs,
RequiredConfirmations: message.RequiredConfirmations, RequiredConfirmations: message.RequiredConfirmations,
IncludePending: message.IncludePending, IncludePending: message.IncludePending,
} }
@ -25,6 +27,8 @@ func (x *ModifyNotifyingTxsConfirmationChangedRequestMessage) toAppMessage() (ap
return nil, errors.Wrapf(errorNil, "ModifyNotifyingTxsConfirmationChangedRequestMessage is nil") return nil, errors.Wrapf(errorNil, "ModifyNotifyingTxsConfirmationChangedRequestMessage is nil")
} }
return &appmessage.ModifyNotifyingTxsConfirmationChangedRequestMessage{ return &appmessage.ModifyNotifyingTxsConfirmationChangedRequestMessage{
AddTxIDs: x.AddTxIDs,
RemoveTxIDs: x.RemoveTxIDs,
RequiredConfirmations: x.RequiredConfirmations, RequiredConfirmations: x.RequiredConfirmations,
IncludePending: x.IncludePending, IncludePending: x.IncludePending,
}, nil }, nil

View File

@ -299,6 +299,9 @@ func (x *RpcTransactionVerboseData) toAppMessage() (*appmessage.RPCTransactionVe
Mass: x.Mass, Mass: x.Mass,
BlockHash: x.BlockHash, BlockHash: x.BlockHash,
BlockTime: x.BlockTime, BlockTime: x.BlockTime,
TxIndexed: x.TxIndexed,
AcceptingBlockHash: x.AcceptingBlockHash,
Confirmations: x.Confirmations,
}, nil }, nil
} }
@ -309,6 +312,9 @@ func (x *RpcTransactionVerboseData) fromAppMessage(message *appmessage.RPCTransa
Mass: message.Mass, Mass: message.Mass,
BlockHash: message.BlockHash, BlockHash: message.BlockHash,
BlockTime: message.BlockTime, BlockTime: message.BlockTime,
TxIndexed: message.TxIndexed,
AcceptingBlockHash: message.AcceptingBlockHash,
Confirmations: message.Confirmations,
} }
} }