mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +00:00
Add blockVerboseData to blockAddedNotifications (#1508)
* Add blockVerboseData to blockAddedNotifications. * Run the documentation generator.
This commit is contained in:
parent
2edf6bfd07
commit
3a4fa6e0e1
@ -37,7 +37,8 @@ func NewNotifyBlockAddedResponseMessage() *NotifyBlockAddedResponseMessage {
|
|||||||
// its respective RPC message
|
// its respective RPC message
|
||||||
type BlockAddedNotificationMessage struct {
|
type BlockAddedNotificationMessage struct {
|
||||||
baseMessage
|
baseMessage
|
||||||
Block *MsgBlock
|
Block *MsgBlock
|
||||||
|
BlockVerboseData *BlockVerboseData
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command returns the protocol command string for the message
|
// Command returns the protocol command string for the message
|
||||||
@ -46,8 +47,9 @@ func (msg *BlockAddedNotificationMessage) Command() MessageCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewBlockAddedNotificationMessage returns a instance of the message
|
// NewBlockAddedNotificationMessage returns a instance of the message
|
||||||
func NewBlockAddedNotificationMessage(block *MsgBlock) *BlockAddedNotificationMessage {
|
func NewBlockAddedNotificationMessage(block *MsgBlock, blockVerboseData *BlockVerboseData) *BlockAddedNotificationMessage {
|
||||||
return &BlockAddedNotificationMessage{
|
return &BlockAddedNotificationMessage{
|
||||||
Block: block,
|
Block: block,
|
||||||
|
BlockVerboseData: blockVerboseData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,12 @@ func (m *Manager) NotifyBlockAddedToDAG(block *externalapi.DomainBlock, blockIns
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
blockAddedNotification := appmessage.NewBlockAddedNotificationMessage(appmessage.DomainBlockToMsgBlock(block))
|
msgBlock := appmessage.DomainBlockToMsgBlock(block)
|
||||||
|
blockVerboseData, err := m.context.BuildBlockVerboseData(block.Header, block, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
blockAddedNotification := appmessage.NewBlockAddedNotificationMessage(msgBlock, blockVerboseData)
|
||||||
return m.context.NotificationManager.NotifyBlockAdded(blockAddedNotification)
|
return m.context.NotificationManager.NotifyBlockAdded(blockAddedNotification)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
||||||
|
"github.com/kaspanet/kaspad/infrastructure/logger"
|
||||||
"github.com/kaspanet/kaspad/util/difficulty"
|
"github.com/kaspanet/kaspad/util/difficulty"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
@ -23,8 +24,14 @@ import (
|
|||||||
"github.com/kaspanet/kaspad/util/pointers"
|
"github.com/kaspanet/kaspad/util/pointers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BuildBlockVerboseData builds a BlockVerboseData from the given block.
|
// BuildBlockVerboseData builds a BlockVerboseData from the given blockHeader.
|
||||||
func (ctx *Context) BuildBlockVerboseData(blockHeader externalapi.BlockHeader, includeTransactionVerboseData bool) (*appmessage.BlockVerboseData, error) {
|
// A block may optionally also be given if it's available in the calling context.
|
||||||
|
func (ctx *Context) BuildBlockVerboseData(blockHeader externalapi.BlockHeader, block *externalapi.DomainBlock,
|
||||||
|
includeTransactionVerboseData bool) (*appmessage.BlockVerboseData, error) {
|
||||||
|
|
||||||
|
onEnd := logger.LogAndMeasureExecutionTime(log, "BuildBlockVerboseData")
|
||||||
|
defer onEnd()
|
||||||
|
|
||||||
hash := consensushashing.HeaderHash(blockHeader)
|
hash := consensushashing.HeaderHash(blockHeader)
|
||||||
|
|
||||||
blockInfo, err := ctx.Domain.Consensus().GetBlockInfo(hash)
|
blockInfo, err := ctx.Domain.Consensus().GetBlockInfo(hash)
|
||||||
@ -48,9 +55,11 @@ func (ctx *Context) BuildBlockVerboseData(blockHeader externalapi.BlockHeader, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
if blockInfo.BlockStatus != externalapi.StatusHeaderOnly {
|
if blockInfo.BlockStatus != externalapi.StatusHeaderOnly {
|
||||||
block, err := ctx.Domain.Consensus().GetBlock(hash)
|
if block == nil {
|
||||||
if err != nil {
|
block, err = ctx.Domain.Consensus().GetBlock(hash)
|
||||||
return nil, err
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
txIDs := make([]string, len(block.Transactions))
|
txIDs := make([]string, len(block.Transactions))
|
||||||
@ -100,6 +109,9 @@ func (ctx *Context) BuildTransactionVerboseData(tx *externalapi.DomainTransactio
|
|||||||
blockHeader externalapi.BlockHeader, blockHash string) (
|
blockHeader externalapi.BlockHeader, blockHash string) (
|
||||||
*appmessage.TransactionVerboseData, error) {
|
*appmessage.TransactionVerboseData, error) {
|
||||||
|
|
||||||
|
onEnd := logger.LogAndMeasureExecutionTime(log, "BuildTransactionVerboseData")
|
||||||
|
defer onEnd()
|
||||||
|
|
||||||
var payloadHash string
|
var payloadHash string
|
||||||
if tx.SubnetworkID != subnetworks.SubnetworkIDNative {
|
if tx.SubnetworkID != subnetworks.SubnetworkIDNative {
|
||||||
payloadHash = tx.PayloadHash.String()
|
payloadHash = tx.PayloadHash.String()
|
||||||
|
@ -28,7 +28,7 @@ func HandleGetBlock(context *rpccontext.Context, _ *router.Router, request appme
|
|||||||
|
|
||||||
response := appmessage.NewGetBlockResponseMessage()
|
response := appmessage.NewGetBlockResponseMessage()
|
||||||
|
|
||||||
blockVerboseData, err := context.BuildBlockVerboseData(header, getBlockRequest.IncludeTransactionVerboseData)
|
blockVerboseData, err := context.BuildBlockVerboseData(header, nil, getBlockRequest.IncludeTransactionVerboseData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -261,6 +261,7 @@ See: NotifyBlockAddedRequestMessage
|
|||||||
| Field | Type | Label | Description |
|
| Field | Type | Label | Description |
|
||||||
| ----- | ---- | ----- | ----------- |
|
| ----- | ---- | ----- | ----------- |
|
||||||
| block | [BlockMessage](#protowire.BlockMessage) | | |
|
| block | [BlockMessage](#protowire.BlockMessage) | | |
|
||||||
|
| blockVerboseData | [BlockVerboseData](#protowire.BlockVerboseData) | | |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -87,6 +87,7 @@ message NotifyBlockAddedResponseMessage{
|
|||||||
// See: NotifyBlockAddedRequestMessage
|
// See: NotifyBlockAddedRequestMessage
|
||||||
message BlockAddedNotificationMessage{
|
message BlockAddedNotificationMessage{
|
||||||
BlockMessage block = 1;
|
BlockMessage block = 1;
|
||||||
|
BlockVerboseData blockVerboseData = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPeerAddressesRequestMessage requests the list of known kaspad addresses in the
|
// GetPeerAddressesRequestMessage requests the list of known kaspad addresses in the
|
||||||
|
@ -37,8 +37,13 @@ func (x *KaspadMessage_BlockAddedNotification) toAppMessage() (appmessage.Messag
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
blockVerboseData, err := x.BlockAddedNotification.BlockVerboseData.toAppMessage()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &appmessage.BlockAddedNotificationMessage{
|
return &appmessage.BlockAddedNotificationMessage{
|
||||||
Block: block,
|
Block: block,
|
||||||
|
BlockVerboseData: blockVerboseData,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,8 +53,14 @@ func (x *KaspadMessage_BlockAddedNotification) fromAppMessage(message *appmessag
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
blockVerboseData := &BlockVerboseData{}
|
||||||
|
err = blockVerboseData.fromAppMessage(message.BlockVerboseData)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
x.BlockAddedNotification = &BlockAddedNotificationMessage{
|
x.BlockAddedNotification = &BlockAddedNotificationMessage{
|
||||||
Block: blockMessage,
|
Block: blockMessage,
|
||||||
|
BlockVerboseData: blockVerboseData,
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user