Merge 9efaa52d9fb589ef0cef170d2014e9e6f41a7619 into 4bb5bf25d3f2279ec2a61c3b4f7bb083b5f522b2

This commit is contained in:
Ori Newman 2025-05-08 12:29:28 +02:00 committed by GitHub
commit 0f18982eb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 6640 additions and 2507 deletions

View File

@ -167,6 +167,10 @@ const (
CmdGetFeeEstimateResponseMessage CmdGetFeeEstimateResponseMessage
CmdSubmitTransactionReplacementRequestMessage CmdSubmitTransactionReplacementRequestMessage
CmdSubmitTransactionReplacementResponseMessage CmdSubmitTransactionReplacementResponseMessage
CmdGetPruningWindowRootsRequestMessage
CmdGetPruningWindowRootsResponseMessage
CmdAddArchivalBlocksRequestMessage
CmdAddArchivalBlocksResponseMessage
) )
// ProtocolMessageCommandToString maps all MessageCommands to their string representation // ProtocolMessageCommandToString maps all MessageCommands to their string representation
@ -308,6 +312,10 @@ var RPCMessageCommandToString = map[MessageCommand]string{
CmdGetFeeEstimateResponseMessage: "GetFeeEstimateResponse", CmdGetFeeEstimateResponseMessage: "GetFeeEstimateResponse",
CmdSubmitTransactionReplacementRequestMessage: "SubmitTransactionReplacementRequest", CmdSubmitTransactionReplacementRequestMessage: "SubmitTransactionReplacementRequest",
CmdSubmitTransactionReplacementResponseMessage: "SubmitTransactionReplacementResponse", CmdSubmitTransactionReplacementResponseMessage: "SubmitTransactionReplacementResponse",
CmdGetPruningWindowRootsRequestMessage: "GetPruningWindowRootsRequestMessage",
CmdGetPruningWindowRootsResponseMessage: "GetPruningWindowRootsResponseMessage",
CmdAddArchivalBlocksRequestMessage: "AddArchivalBlocksRequestMessage",
CmdAddArchivalBlocksResponseMessage: "AddArchivalBlocksResponseMessage",
} }
// Message is an interface that describes a kaspa message. A type that // Message is an interface that describes a kaspa message. A type that

View File

@ -0,0 +1,54 @@
package appmessage
type AcceptedTxEntry struct {
TransactionID string
IndexWithinBlock uint32
}
type MergesetBlockAcceptanceData struct {
BlockHash string
AcceptedTxs []*AcceptedTxEntry
}
type ArchivalBlock struct {
Block *RPCBlock
Child string
AcceptanceData []*MergesetBlockAcceptanceData
SelectedParent string
}
// AddArchivalBlocksRequestMessage represents a request to add archival blocks
type AddArchivalBlocksRequestMessage struct {
baseMessage
Blocks []*ArchivalBlock
}
// Command returns the protocol command string for the message
func (msg *AddArchivalBlocksRequestMessage) Command() MessageCommand {
return CmdAddArchivalBlocksRequestMessage
}
// NewAddArchivalBlocksRequestMessage returns a instance of the message
func NewAddArchivalBlocksRequestMessage(blocks []*ArchivalBlock) *AddArchivalBlocksRequestMessage {
return &AddArchivalBlocksRequestMessage{
Blocks: blocks,
}
}
// AddArchivalBlocksResponseMessage represents a response to the AddArchivalBlocks request
type AddArchivalBlocksResponseMessage struct {
baseMessage
Error *RPCError
}
// Command returns the protocol command string for the message
func (msg *AddArchivalBlocksResponseMessage) Command() MessageCommand {
return CmdAddArchivalBlocksResponseMessage
}
// NewAddArchivalBlocksResponseMessage returns a instance of the message
func NewAddArchivalBlocksResponseMessage(err *RPCError) *AddArchivalBlocksResponseMessage {
return &AddArchivalBlocksResponseMessage{
Error: err,
}
}

View File

@ -0,0 +1,30 @@
package appmessage
// GetPruningWindowRootsRequestMessage is an appmessage corresponding to
// its respective RPC message
type GetPruningWindowRootsRequestMessage struct {
baseMessage
}
// Command returns the protocol command string for the message
func (msg *GetPruningWindowRootsRequestMessage) Command() MessageCommand {
return CmdGetPruningWindowRootsRequestMessage
}
type PruningWindowRoots struct {
PPRoots []string
PPIndex uint64
}
// GetPruningWindowRootsResponseMessage is an appmessage corresponding to
// its respective RPC message
type GetPruningWindowRootsResponseMessage struct {
baseMessage
Roots []*PruningWindowRoots
Error *RPCError
}
// Command returns the protocol command string for the message
func (msg *GetPruningWindowRootsResponseMessage) Command() MessageCommand {
return CmdGetPruningWindowRootsResponseMessage
}

View File

@ -0,0 +1,76 @@
package main
import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/kaspanet/kaspad/infrastructure/config"
"github.com/kaspanet/kaspad/util"
"github.com/pkg/errors"
"github.com/jessevdk/go-flags"
"github.com/kaspanet/kaspad/version"
)
const (
defaultLogFilename = "archiveexport.log"
defaultErrLogFilename = "archiveexport_err.log"
)
var (
// Default configuration options
defaultAppDir = util.AppDir("archiveexport", false)
defaultLogFile = filepath.Join(defaultAppDir, defaultLogFilename)
defaultErrLogFile = filepath.Join(defaultAppDir, defaultErrLogFilename)
defaultRPCServer = "localhost"
defaultDataDir = filepath.Join(config.DefaultAppDir)
)
type configFlags struct {
ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"`
RPCServer string `short:"s" long:"rpcserver" description:"RPC server to connect to"`
Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536"`
AppDir string `short:"b" long:"appdir" description:"Node datadir"`
config.NetworkFlags
}
func parseConfig() (*configFlags, error) {
cfg := &configFlags{
RPCServer: defaultRPCServer,
AppDir: defaultDataDir,
}
parser := flags.NewParser(cfg, flags.PrintErrors|flags.HelpFlag)
_, err := parser.Parse()
// Show the version and exit if the version flag was specified.
if cfg.ShowVersion {
appName := filepath.Base(os.Args[0])
appName = strings.TrimSuffix(appName, filepath.Ext(appName))
fmt.Println(appName, "version", version.Version())
os.Exit(0)
}
if err != nil {
return nil, err
}
err = cfg.ResolveNetwork(parser)
if err != nil {
return nil, err
}
if cfg.Profile != "" {
profilePort, err := strconv.Atoi(cfg.Profile)
if err != nil || profilePort < 1024 || profilePort > 65535 {
return nil, errors.New("The profile port must be between 1024 and 65535")
}
}
initLog(defaultLogFile, defaultErrLogFile)
return cfg, nil
}

39
cmd/archiveexport/log.go Normal file
View File

@ -0,0 +1,39 @@
package main
import (
"fmt"
"github.com/kaspanet/kaspad/infrastructure/logger"
"github.com/kaspanet/kaspad/util/panics"
"os"
)
var (
backendLog = logger.NewBackend()
log = backendLog.Logger("ARCH")
spawn = panics.GoroutineWrapperFunc(log)
)
func initLog(logFile, errLogFile string) {
log.SetLevel(logger.LevelDebug)
err := backendLog.AddLogFile(logFile, logger.LevelTrace)
if err != nil {
fmt.Fprintf(os.Stderr, "Error adding log file %s as log rotator for level %s: %s", logFile, logger.LevelTrace, err)
os.Exit(1)
}
err = backendLog.AddLogFile(errLogFile, logger.LevelWarn)
if err != nil {
fmt.Fprintf(os.Stderr, "Error adding log file %s as log rotator for level %s: %s", errLogFile, logger.LevelWarn, err)
os.Exit(1)
}
err = backendLog.AddLogWriter(os.Stdout, logger.LevelInfo)
if err != nil {
fmt.Fprintf(os.Stderr, "Error adding stdout to the loggerfor level %s: %s", logger.LevelWarn, err)
os.Exit(1)
}
err = backendLog.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "Error starting the logger: %s ", err)
os.Exit(1)
}
}

247
cmd/archiveexport/main.go Normal file
View File

@ -0,0 +1,247 @@
package main
import (
"fmt"
"os"
"path/filepath"
"time"
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/kaspanet/kaspad/domain/consensus"
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
"github.com/kaspanet/kaspad/infrastructure/config"
"github.com/kaspanet/kaspad/infrastructure/db/database"
"github.com/kaspanet/kaspad/infrastructure/network/rpcclient"
"github.com/kaspanet/kaspad/util/profiling"
"github.com/kaspanet/kaspad/version"
"github.com/pkg/errors"
)
func main() {
// defer panics.HandlePanic(log, "MAIN", nil)
cfg, err := parseConfig()
if err != nil {
printErrorAndExit(errors.Errorf("Error parsing command-line arguments: %s", err))
}
defer backendLog.Close()
// Show version at startup.
log.Infof("Version %s", version.Version())
// Enable http profiling server if requested.
if cfg.Profile != "" {
profiling.Start(cfg.Profile, log)
}
err = mainImpl(cfg)
if err != nil {
printErrorAndExit(err)
}
}
func mainImpl(cfg *configFlags) error {
appDir := config.CleanAndExpandPath(cfg.AppDir)
appDir = filepath.Join(appDir, cfg.NetParams().Name)
dataDir := filepath.Join(appDir, "datadir2")
consensusConfig := &consensus.Config{Params: *cfg.NetParams()}
factory := consensus.NewFactory()
factory.SetTestDataDir(dataDir)
factory.AutoSetActivePrefix(true)
tc, tearDownFunc, err := factory.NewTestConsensus(consensusConfig, "archiveexport")
if err != nil {
return err
}
defer tearDownFunc(true)
rpcAddress, err := cfg.NetParams().NormalizeRPCServerAddress(cfg.RPCServer)
if err != nil {
return err
}
rpcClient, err := rpcclient.NewRPCClient(rpcAddress)
if err != nil {
return err
}
rootsResp, err := rpcClient.GetPruningWindowRoots()
if err != nil {
return err
}
ppHeaders, err := tc.PruningPointHeaders()
if err != nil {
return err
}
for _, root := range rootsResp.Roots {
log.Infof("Got root %s", root.PPRoots)
}
counterStart := time.Now()
counter := 0
for _, root := range rootsResp.Roots {
ppRoots, err := externalapi.NewDomainHashesFromStrings(root.PPRoots)
if err != nil {
return err
}
log.Infof("Adding past of %s", ppRoots)
if err != nil {
return err
}
if int(root.PPIndex-1) >= len(ppHeaders) {
continue
}
nextPP := ppHeaders[root.PPIndex-1]
blockToChild := make(map[externalapi.DomainHash]externalapi.DomainHash)
// TODO: Since GD data is not always available, we should extract the blue work from the header and use that for topological traversal
heap := tc.DAGTraversalManager().NewDownHeap(model.NewStagingArea())
for _, ppRoot := range ppRoots {
heap.Push(ppRoot)
}
visited := make(map[externalapi.DomainHash]struct{})
chunk := make([]*appmessage.ArchivalBlock, 0, 1000)
for heap.Len() > 0 {
hash := heap.Pop()
if _, ok := visited[*hash]; ok {
continue
}
visited[*hash] = struct{}{}
// TODO: Use header data instead of GD data
blockGHOSTDAGData, err := tc.GHOSTDAGDataStore().Get(tc.DatabaseContext(), model.NewStagingArea(), hash, false)
if err != nil {
return err
}
if blockGHOSTDAGData.BlueWork().Cmp(nextPP.BlueWork()) <= 0 {
break
}
block, err := tc.BlockStore().Block(tc.DatabaseContext(), model.NewStagingArea(), hash)
if database.IsNotFoundError(err) {
continue
}
if err != nil {
return err
}
archivalBlock := &appmessage.ArchivalBlock{
Block: appmessage.DomainBlockToRPCBlock(block),
}
if child, ok := blockToChild[*hash]; ok {
archivalBlock.Child = child.String()
}
acceptanceData, err := tc.AcceptanceDataStore().Get(tc.DatabaseContext(), model.NewStagingArea(), hash)
isNotFoundErr := database.IsNotFoundError(err)
if !isNotFoundErr && err != nil {
return err
}
if blockGHOSTDAGData.SelectedParent() != model.VirtualGenesisBlockHash && !isNotFoundErr && len(acceptanceData) > 0 {
acceptanceDataRPC := make([]*appmessage.MergesetBlockAcceptanceData, 0, len(acceptanceData))
for _, data := range acceptanceData {
acceptedTxs := make([]*appmessage.AcceptedTxEntry, 0, len(data.TransactionAcceptanceData))
for i, tx := range data.TransactionAcceptanceData {
if !tx.IsAccepted {
continue
}
acceptedTxs = append(acceptedTxs, &appmessage.AcceptedTxEntry{
TransactionID: consensushashing.TransactionID(tx.Transaction).String(),
IndexWithinBlock: uint32(i),
})
}
acceptanceDataRPC = append(acceptanceDataRPC, &appmessage.MergesetBlockAcceptanceData{
BlockHash: data.BlockHash.String(),
AcceptedTxs: acceptedTxs,
})
}
archivalBlock.AcceptanceData = acceptanceDataRPC
archivalBlock.SelectedParent = blockGHOSTDAGData.SelectedParent().String()
}
chunk = append(chunk, archivalBlock)
if len(chunk) == 1 {
log.Infof("Added %s to chunk", consensushashing.BlockHash(block))
}
if len(chunk) == cap(chunk) {
err := sendChunk(rpcClient, chunk)
if err != nil {
return err
}
counter += len(chunk)
counterDuration := time.Since(counterStart)
if counterDuration > 10*time.Second {
rate := float64(counter) / counterDuration.Seconds()
log.Infof("Sent %d blocks in the last %.2f seconds (%.2f blocks/second)", counter, counterDuration.Seconds(), rate)
counterStart = time.Now()
counter = 0
}
chunk = chunk[:0]
}
for _, parent := range block.Header.DirectParents() {
heap.Push(parent)
blockToChild[*parent] = *hash
}
}
if len(chunk) > 0 {
sendChunk(rpcClient, chunk)
}
}
return nil
}
func sendChunk(rpcClient *rpcclient.RPCClient, chunk []*appmessage.ArchivalBlock) error {
log.Infof("Sending chunk")
_, err := rpcClient.AddArchivalBlocks(chunk)
if err != nil {
return err
}
log.Infof("Sent chunk")
// Checking existence of first block for sanity
block := chunk[0]
domainBlock, err := appmessage.RPCBlockToDomainBlock(block.Block)
if err != nil {
return err
}
blockHash := consensushashing.BlockHash(domainBlock)
log.Infof("Checking block %s", blockHash)
resp, err := rpcClient.GetBlock(blockHash.String(), true)
if err != nil {
return err
}
if len(resp.Block.Transactions) == 0 {
return errors.Errorf("Block %s has no transactions on the server", blockHash)
}
return nil
}
func printErrorAndExit(err error) {
fmt.Fprintf(os.Stderr, "%+v\n", err)
os.Exit(1)
}

View File

@ -41,6 +41,9 @@ var commandTypes = []reflect.Type{
reflect.TypeOf(protowire.KaspadMessage_BanRequest{}), reflect.TypeOf(protowire.KaspadMessage_BanRequest{}),
reflect.TypeOf(protowire.KaspadMessage_UnbanRequest{}), reflect.TypeOf(protowire.KaspadMessage_UnbanRequest{}),
reflect.TypeOf(protowire.KaspadMessage_GetPruningWindowRootsRequest{}),
reflect.TypeOf(protowire.KaspadMessage_AddArchivalBlocksRequest{}),
} }
type commandDescription struct { type commandDescription struct {

View File

@ -12,6 +12,7 @@ import (
"github.com/kaspanet/kaspad/domain/consensus/processes/blockparentbuilder" "github.com/kaspanet/kaspad/domain/consensus/processes/blockparentbuilder"
parentssanager "github.com/kaspanet/kaspad/domain/consensus/processes/parentsmanager" parentssanager "github.com/kaspanet/kaspad/domain/consensus/processes/parentsmanager"
"github.com/kaspanet/kaspad/domain/consensus/processes/pruningproofmanager" "github.com/kaspanet/kaspad/domain/consensus/processes/pruningproofmanager"
"github.com/kaspanet/kaspad/domain/prefixmanager"
"github.com/kaspanet/kaspad/util/staging" "github.com/kaspanet/kaspad/util/staging"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -89,6 +90,8 @@ type Factory interface {
SetTestPreAllocateCache(preallocateCaches bool) SetTestPreAllocateCache(preallocateCaches bool)
SetTestPastMedianTimeManager(medianTimeConstructor PastMedianTimeManagerConstructor) SetTestPastMedianTimeManager(medianTimeConstructor PastMedianTimeManagerConstructor)
SetTestDifficultyManager(difficultyConstructor DifficultyManagerConstructor) SetTestDifficultyManager(difficultyConstructor DifficultyManagerConstructor)
AutoSetActivePrefix(value bool)
} }
type factory struct { type factory struct {
@ -98,6 +101,7 @@ type factory struct {
difficultyConstructor DifficultyManagerConstructor difficultyConstructor DifficultyManagerConstructor
cacheSizeMiB *int cacheSizeMiB *int
preallocateCaches *bool preallocateCaches *bool
autoCheckActivePrefix bool
} }
// NewFactory creates a new Consensus factory // NewFactory creates a new Consensus factory
@ -106,6 +110,7 @@ func NewFactory() Factory {
ghostdagConstructor: ghostdagmanager.New, ghostdagConstructor: ghostdagmanager.New,
pastMedianTimeConsructor: pastmediantimemanager.New, pastMedianTimeConsructor: pastmediantimemanager.New,
difficultyConstructor: difficultymanager.New, difficultyConstructor: difficultymanager.New,
autoCheckActivePrefix: false,
} }
} }
@ -588,8 +593,19 @@ func (f *factory) NewTestConsensus(config *Config, testName string) (
return nil, nil, err return nil, nil, err
} }
testConsensusDBPrefix := &prefix.Prefix{} prefix := &prefix.Prefix{}
consensusAsInterface, shouldMigrate, err := f.NewConsensus(config, db, testConsensusDBPrefix, nil) if f.autoCheckActivePrefix {
activePrefix, exists, err := prefixmanager.ActivePrefix(db)
if err != nil {
return nil, nil, err
}
if exists {
prefix = activePrefix
}
}
consensusAsInterface, shouldMigrate, err := f.NewConsensus(config, db, prefix, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -648,6 +664,11 @@ func (f *factory) SetTestPreAllocateCache(preallocateCaches bool) {
f.preallocateCaches = &preallocateCaches f.preallocateCaches = &preallocateCaches
} }
// AutoSetActivePrefix implements Factory.
func (f *factory) AutoSetActivePrefix(value bool) {
f.autoCheckActivePrefix = value
}
func dagStores(config *Config, func dagStores(config *Config,
prefixBucket model.DBBucket, prefixBucket model.DBBucket,
pruningWindowSizePlusFinalityDepthForCache, pruningWindowSizeForCaches int, pruningWindowSizePlusFinalityDepthForCache, pruningWindowSizeForCaches int,

View File

@ -59,6 +59,18 @@ func NewDomainHashFromString(hashString string) (*DomainHash, error) {
return NewDomainHashFromByteSlice(hashBytes) return NewDomainHashFromByteSlice(hashBytes)
} }
func NewDomainHashesFromStrings(hashStrings []string) ([]*DomainHash, error) {
hashes := make([]*DomainHash, len(hashStrings))
for i, hashString := range hashStrings {
hash, err := NewDomainHashFromString(hashString)
if err != nil {
return nil, err
}
hashes[i] = hash
}
return hashes, nil
}
// String returns the Hash as the hexadecimal string of the hash. // String returns the Hash as the hexadecimal string of the hash.
func (hash DomainHash) String() string { func (hash DomainHash) String() string {
return hex.EncodeToString(hash.hashArray[:]) return hex.EncodeToString(hash.hashArray[:])

View File

@ -149,9 +149,9 @@ type ServiceOptions struct {
ServiceCommand string `short:"s" long:"service" description:"Service command {install, remove, start, stop}"` ServiceCommand string `short:"s" long:"service" description:"Service command {install, remove, start, stop}"`
} }
// cleanAndExpandPath expands environment variables and leading ~ in the // CleanAndExpandPath expands environment variables and leading ~ in the
// passed path, cleans the result, and returns it. // passed path, cleans the result, and returns it.
func cleanAndExpandPath(path string) string { func CleanAndExpandPath(path string) string {
// Expand initial ~ to OS specific home directory. // Expand initial ~ to OS specific home directory.
if strings.HasPrefix(path, "~") { if strings.HasPrefix(path, "~") {
homeDir := filepath.Dir(DefaultAppDir) homeDir := filepath.Dir(DefaultAppDir)
@ -320,7 +320,7 @@ func LoadConfig() (*Config, error) {
} }
cfg.RelayNonStd = relayNonStd cfg.RelayNonStd = relayNonStd
cfg.AppDir = cleanAndExpandPath(cfg.AppDir) cfg.AppDir = CleanAndExpandPath(cfg.AppDir)
// Append the network type to the app directory so it is "namespaced" // Append the network type to the app directory so it is "namespaced"
// per network. // per network.
// All data is specific to a network, so namespacing the data directory // All data is specific to a network, so namespacing the data directory
@ -332,7 +332,7 @@ func LoadConfig() (*Config, error) {
if cfg.LogDir == "" { if cfg.LogDir == "" {
cfg.LogDir = filepath.Join(cfg.AppDir, defaultLogDirname) cfg.LogDir = filepath.Join(cfg.AppDir, defaultLogDirname)
} }
cfg.LogDir = cleanAndExpandPath(cfg.LogDir) cfg.LogDir = CleanAndExpandPath(cfg.LogDir)
// Special show command to list supported subsystems and exit. // Special show command to list supported subsystems and exit.
if cfg.LogLevel == "show" { if cfg.LogLevel == "show" {

View File

@ -29,12 +29,15 @@ message KaspadMessage {
UnexpectedPruningPointMessage unexpectedPruningPoint = 27; UnexpectedPruningPointMessage unexpectedPruningPoint = 27;
IbdBlockLocatorMessage ibdBlockLocator = 30; IbdBlockLocatorMessage ibdBlockLocator = 30;
IbdBlockLocatorHighestHashMessage ibdBlockLocatorHighestHash = 31; IbdBlockLocatorHighestHashMessage ibdBlockLocatorHighestHash = 31;
RequestNextPruningPointUtxoSetChunkMessage requestNextPruningPointUtxoSetChunk = 33; RequestNextPruningPointUtxoSetChunkMessage
requestNextPruningPointUtxoSetChunk = 33;
DonePruningPointUtxoSetChunksMessage donePruningPointUtxoSetChunks = 34; DonePruningPointUtxoSetChunksMessage donePruningPointUtxoSetChunks = 34;
IbdBlockLocatorHighestHashNotFoundMessage ibdBlockLocatorHighestHashNotFound = 35; IbdBlockLocatorHighestHashNotFoundMessage
ibdBlockLocatorHighestHashNotFound = 35;
BlockWithTrustedDataMessage blockWithTrustedData = 36; BlockWithTrustedDataMessage blockWithTrustedData = 36;
DoneBlocksWithTrustedDataMessage doneBlocksWithTrustedData = 37; DoneBlocksWithTrustedDataMessage doneBlocksWithTrustedData = 37;
RequestPruningPointAndItsAnticoneMessage requestPruningPointAndItsAnticone = 40; RequestPruningPointAndItsAnticoneMessage requestPruningPointAndItsAnticone =
40;
BlockHeadersMessage blockHeaders = 41; BlockHeadersMessage blockHeaders = 41;
RequestNextHeadersMessage requestNextHeaders = 42; RequestNextHeadersMessage requestNextHeaders = 42;
DoneHeadersMessage DoneHeaders = 43; DoneHeadersMessage DoneHeaders = 43;
@ -50,7 +53,8 @@ message KaspadMessage {
RequestIBDChainBlockLocatorMessage requestIBDChainBlockLocator = 53; RequestIBDChainBlockLocatorMessage requestIBDChainBlockLocator = 53;
IbdChainBlockLocatorMessage ibdChainBlockLocator = 54; IbdChainBlockLocatorMessage ibdChainBlockLocator = 54;
RequestAnticoneMessage requestAnticone = 55; RequestAnticoneMessage requestAnticone = 55;
RequestNextPruningPointAndItsAnticoneBlocksMessage requestNextPruningPointAndItsAnticoneBlocks = 56; RequestNextPruningPointAndItsAnticoneBlocksMessage
requestNextPruningPointAndItsAnticoneBlocks = 56;
GetCurrentNetworkRequestMessage getCurrentNetworkRequest = 1001; GetCurrentNetworkRequestMessage getCurrentNetworkRequest = 1001;
GetCurrentNetworkResponseMessage getCurrentNetworkResponse = 1002; GetCurrentNetworkResponseMessage getCurrentNetworkResponse = 1002;
@ -73,15 +77,20 @@ message KaspadMessage {
AddPeerResponseMessage addPeerResponse = 1019; AddPeerResponseMessage addPeerResponse = 1019;
SubmitTransactionRequestMessage submitTransactionRequest = 1020; SubmitTransactionRequestMessage submitTransactionRequest = 1020;
SubmitTransactionResponseMessage submitTransactionResponse = 1021; SubmitTransactionResponseMessage submitTransactionResponse = 1021;
NotifyVirtualSelectedParentChainChangedRequestMessage notifyVirtualSelectedParentChainChangedRequest = 1022; NotifyVirtualSelectedParentChainChangedRequestMessage
NotifyVirtualSelectedParentChainChangedResponseMessage notifyVirtualSelectedParentChainChangedResponse = 1023; notifyVirtualSelectedParentChainChangedRequest = 1022;
VirtualSelectedParentChainChangedNotificationMessage virtualSelectedParentChainChangedNotification = 1024; NotifyVirtualSelectedParentChainChangedResponseMessage
notifyVirtualSelectedParentChainChangedResponse = 1023;
VirtualSelectedParentChainChangedNotificationMessage
virtualSelectedParentChainChangedNotification = 1024;
GetBlockRequestMessage getBlockRequest = 1025; GetBlockRequestMessage getBlockRequest = 1025;
GetBlockResponseMessage getBlockResponse = 1026; GetBlockResponseMessage getBlockResponse = 1026;
GetSubnetworkRequestMessage getSubnetworkRequest = 1027; GetSubnetworkRequestMessage getSubnetworkRequest = 1027;
GetSubnetworkResponseMessage getSubnetworkResponse = 1028; GetSubnetworkResponseMessage getSubnetworkResponse = 1028;
GetVirtualSelectedParentChainFromBlockRequestMessage getVirtualSelectedParentChainFromBlockRequest = 1029; GetVirtualSelectedParentChainFromBlockRequestMessage
GetVirtualSelectedParentChainFromBlockResponseMessage getVirtualSelectedParentChainFromBlockResponse = 1030; getVirtualSelectedParentChainFromBlockRequest = 1029;
GetVirtualSelectedParentChainFromBlockResponseMessage
getVirtualSelectedParentChainFromBlockResponse = 1030;
GetBlocksRequestMessage getBlocksRequest = 1031; GetBlocksRequestMessage getBlocksRequest = 1031;
GetBlocksResponseMessage getBlocksResponse = 1032; GetBlocksResponseMessage getBlocksResponse = 1032;
GetBlockCountRequestMessage getBlockCountRequest = 1033; GetBlockCountRequestMessage getBlockCountRequest = 1033;
@ -89,11 +98,14 @@ message KaspadMessage {
GetBlockDagInfoRequestMessage getBlockDagInfoRequest = 1035; GetBlockDagInfoRequestMessage getBlockDagInfoRequest = 1035;
GetBlockDagInfoResponseMessage getBlockDagInfoResponse = 1036; GetBlockDagInfoResponseMessage getBlockDagInfoResponse = 1036;
ResolveFinalityConflictRequestMessage resolveFinalityConflictRequest = 1037; ResolveFinalityConflictRequestMessage resolveFinalityConflictRequest = 1037;
ResolveFinalityConflictResponseMessage resolveFinalityConflictResponse = 1038; ResolveFinalityConflictResponseMessage resolveFinalityConflictResponse =
1038;
NotifyFinalityConflictsRequestMessage notifyFinalityConflictsRequest = 1039; NotifyFinalityConflictsRequestMessage notifyFinalityConflictsRequest = 1039;
NotifyFinalityConflictsResponseMessage notifyFinalityConflictsResponse = 1040; NotifyFinalityConflictsResponseMessage notifyFinalityConflictsResponse =
1040;
FinalityConflictNotificationMessage finalityConflictNotification = 1041; FinalityConflictNotificationMessage finalityConflictNotification = 1041;
FinalityConflictResolvedNotificationMessage finalityConflictResolvedNotification = 1042; FinalityConflictResolvedNotificationMessage
finalityConflictResolvedNotification = 1042;
GetMempoolEntriesRequestMessage getMempoolEntriesRequest = 1043; GetMempoolEntriesRequestMessage getMempoolEntriesRequest = 1043;
GetMempoolEntriesResponseMessage getMempoolEntriesResponse = 1044; GetMempoolEntriesResponseMessage getMempoolEntriesResponse = 1044;
ShutDownRequestMessage shutDownRequest = 1045; ShutDownRequestMessage shutDownRequest = 1045;
@ -105,29 +117,46 @@ message KaspadMessage {
UtxosChangedNotificationMessage utxosChangedNotification = 1051; UtxosChangedNotificationMessage utxosChangedNotification = 1051;
GetUtxosByAddressesRequestMessage getUtxosByAddressesRequest = 1052; GetUtxosByAddressesRequestMessage getUtxosByAddressesRequest = 1052;
GetUtxosByAddressesResponseMessage getUtxosByAddressesResponse = 1053; GetUtxosByAddressesResponseMessage getUtxosByAddressesResponse = 1053;
GetVirtualSelectedParentBlueScoreRequestMessage getVirtualSelectedParentBlueScoreRequest = 1054; GetVirtualSelectedParentBlueScoreRequestMessage
GetVirtualSelectedParentBlueScoreResponseMessage getVirtualSelectedParentBlueScoreResponse = 1055; getVirtualSelectedParentBlueScoreRequest = 1054;
NotifyVirtualSelectedParentBlueScoreChangedRequestMessage notifyVirtualSelectedParentBlueScoreChangedRequest = 1056; GetVirtualSelectedParentBlueScoreResponseMessage
NotifyVirtualSelectedParentBlueScoreChangedResponseMessage notifyVirtualSelectedParentBlueScoreChangedResponse = 1057; getVirtualSelectedParentBlueScoreResponse = 1055;
VirtualSelectedParentBlueScoreChangedNotificationMessage virtualSelectedParentBlueScoreChangedNotification = 1058; NotifyVirtualSelectedParentBlueScoreChangedRequestMessage
notifyVirtualSelectedParentBlueScoreChangedRequest = 1056;
NotifyVirtualSelectedParentBlueScoreChangedResponseMessage
notifyVirtualSelectedParentBlueScoreChangedResponse = 1057;
VirtualSelectedParentBlueScoreChangedNotificationMessage
virtualSelectedParentBlueScoreChangedNotification = 1058;
BanRequestMessage banRequest = 1059; BanRequestMessage banRequest = 1059;
BanResponseMessage banResponse = 1060; BanResponseMessage banResponse = 1060;
UnbanRequestMessage unbanRequest = 1061; UnbanRequestMessage unbanRequest = 1061;
UnbanResponseMessage unbanResponse = 1062; UnbanResponseMessage unbanResponse = 1062;
GetInfoRequestMessage getInfoRequest = 1063; GetInfoRequestMessage getInfoRequest = 1063;
GetInfoResponseMessage getInfoResponse = 1064; GetInfoResponseMessage getInfoResponse = 1064;
StopNotifyingUtxosChangedRequestMessage stopNotifyingUtxosChangedRequest = 1065; StopNotifyingUtxosChangedRequestMessage stopNotifyingUtxosChangedRequest =
StopNotifyingUtxosChangedResponseMessage stopNotifyingUtxosChangedResponse = 1066; 1065;
NotifyPruningPointUTXOSetOverrideRequestMessage notifyPruningPointUTXOSetOverrideRequest = 1067; StopNotifyingUtxosChangedResponseMessage stopNotifyingUtxosChangedResponse =
NotifyPruningPointUTXOSetOverrideResponseMessage notifyPruningPointUTXOSetOverrideResponse = 1068; 1066;
PruningPointUTXOSetOverrideNotificationMessage pruningPointUTXOSetOverrideNotification = 1069; NotifyPruningPointUTXOSetOverrideRequestMessage
StopNotifyingPruningPointUTXOSetOverrideRequestMessage stopNotifyingPruningPointUTXOSetOverrideRequest = 1070; notifyPruningPointUTXOSetOverrideRequest = 1067;
StopNotifyingPruningPointUTXOSetOverrideResponseMessage stopNotifyingPruningPointUTXOSetOverrideResponse = 1071; NotifyPruningPointUTXOSetOverrideResponseMessage
EstimateNetworkHashesPerSecondRequestMessage estimateNetworkHashesPerSecondRequest = 1072; notifyPruningPointUTXOSetOverrideResponse = 1068;
EstimateNetworkHashesPerSecondResponseMessage estimateNetworkHashesPerSecondResponse = 1073; PruningPointUTXOSetOverrideNotificationMessage
NotifyVirtualDaaScoreChangedRequestMessage notifyVirtualDaaScoreChangedRequest = 1074; pruningPointUTXOSetOverrideNotification = 1069;
NotifyVirtualDaaScoreChangedResponseMessage notifyVirtualDaaScoreChangedResponse = 1075; StopNotifyingPruningPointUTXOSetOverrideRequestMessage
VirtualDaaScoreChangedNotificationMessage virtualDaaScoreChangedNotification = 1076; stopNotifyingPruningPointUTXOSetOverrideRequest = 1070;
StopNotifyingPruningPointUTXOSetOverrideResponseMessage
stopNotifyingPruningPointUTXOSetOverrideResponse = 1071;
EstimateNetworkHashesPerSecondRequestMessage
estimateNetworkHashesPerSecondRequest = 1072;
EstimateNetworkHashesPerSecondResponseMessage
estimateNetworkHashesPerSecondResponse = 1073;
NotifyVirtualDaaScoreChangedRequestMessage
notifyVirtualDaaScoreChangedRequest = 1074;
NotifyVirtualDaaScoreChangedResponseMessage
notifyVirtualDaaScoreChangedResponse = 1075;
VirtualDaaScoreChangedNotificationMessage
virtualDaaScoreChangedNotification = 1076;
GetBalanceByAddressRequestMessage getBalanceByAddressRequest = 1077; GetBalanceByAddressRequestMessage getBalanceByAddressRequest = 1077;
GetBalanceByAddressResponseMessage getBalanceByAddressResponse = 1078; GetBalanceByAddressResponseMessage getBalanceByAddressResponse = 1078;
GetBalancesByAddressesRequestMessage getBalancesByAddressesRequest = 1079; GetBalancesByAddressesRequestMessage getBalancesByAddressesRequest = 1079;
@ -135,39 +164,51 @@ message KaspadMessage {
NotifyNewBlockTemplateRequestMessage notifyNewBlockTemplateRequest = 1081; NotifyNewBlockTemplateRequestMessage notifyNewBlockTemplateRequest = 1081;
NotifyNewBlockTemplateResponseMessage notifyNewBlockTemplateResponse = 1082; NotifyNewBlockTemplateResponseMessage notifyNewBlockTemplateResponse = 1082;
NewBlockTemplateNotificationMessage newBlockTemplateNotification = 1083; NewBlockTemplateNotificationMessage newBlockTemplateNotification = 1083;
GetMempoolEntriesByAddressesRequestMessage getMempoolEntriesByAddressesRequest = 1084; GetMempoolEntriesByAddressesRequestMessage
GetMempoolEntriesByAddressesResponseMessage getMempoolEntriesByAddressesResponse = 1085; getMempoolEntriesByAddressesRequest = 1084;
GetMempoolEntriesByAddressesResponseMessage
getMempoolEntriesByAddressesResponse = 1085;
GetCoinSupplyRequestMessage getCoinSupplyRequest = 1086; GetCoinSupplyRequestMessage getCoinSupplyRequest = 1086;
GetCoinSupplyResponseMessage getCoinSupplyResponse= 1087; GetCoinSupplyResponseMessage getCoinSupplyResponse = 1087;
PingRequestMessage pingRequest = 1088; PingRequestMessage pingRequest = 1088;
GetMetricsRequestMessage getMetricsRequest = 1090; GetMetricsRequestMessage getMetricsRequest = 1090;
GetServerInfoRequestMessage getServerInfoRequest = 1092; GetServerInfoRequestMessage getServerInfoRequest = 1092;
GetSyncStatusRequestMessage getSyncStatusRequest = 1094; GetSyncStatusRequestMessage getSyncStatusRequest = 1094;
GetDaaScoreTimestampEstimateRequestMessage getDaaScoreTimestampEstimateRequest = 1096; GetDaaScoreTimestampEstimateRequestMessage
SubmitTransactionReplacementRequestMessage submitTransactionReplacementRequest = 1100; getDaaScoreTimestampEstimateRequest = 1096;
SubmitTransactionReplacementRequestMessage
submitTransactionReplacementRequest = 1100;
GetConnectionsRequestMessage getConnectionsRequest = 1102; GetConnectionsRequestMessage getConnectionsRequest = 1102;
GetSystemInfoRequestMessage getSystemInfoRequest = 1104; GetSystemInfoRequestMessage getSystemInfoRequest = 1104;
GetFeeEstimateRequestMessage getFeeEstimateRequest = 1106; GetFeeEstimateRequestMessage getFeeEstimateRequest = 1106;
GetFeeEstimateExperimentalRequestMessage getFeeEstimateExperimentalRequest = 1108; GetFeeEstimateExperimentalRequestMessage getFeeEstimateExperimentalRequest =
1108;
GetCurrentBlockColorRequestMessage getCurrentBlockColorRequest = 1110; GetCurrentBlockColorRequestMessage getCurrentBlockColorRequest = 1110;
PingResponseMessage pingResponse= 1089; PingResponseMessage pingResponse = 1089;
GetMetricsResponseMessage getMetricsResponse= 1091; GetMetricsResponseMessage getMetricsResponse = 1091;
GetServerInfoResponseMessage getServerInfoResponse = 1093; GetServerInfoResponseMessage getServerInfoResponse = 1093;
GetSyncStatusResponseMessage getSyncStatusResponse = 1095; GetSyncStatusResponseMessage getSyncStatusResponse = 1095;
GetDaaScoreTimestampEstimateResponseMessage getDaaScoreTimestampEstimateResponse = 1097; GetDaaScoreTimestampEstimateResponseMessage
SubmitTransactionReplacementResponseMessage submitTransactionReplacementResponse = 1101; getDaaScoreTimestampEstimateResponse = 1097;
GetConnectionsResponseMessage getConnectionsResponse= 1103; SubmitTransactionReplacementResponseMessage
GetSystemInfoResponseMessage getSystemInfoResponse= 1105; submitTransactionReplacementResponse = 1101;
GetConnectionsResponseMessage getConnectionsResponse = 1103;
GetSystemInfoResponseMessage getSystemInfoResponse = 1105;
GetFeeEstimateResponseMessage getFeeEstimateResponse = 1107; GetFeeEstimateResponseMessage getFeeEstimateResponse = 1107;
GetFeeEstimateExperimentalResponseMessage getFeeEstimateExperimentalResponse = 1109; GetFeeEstimateExperimentalResponseMessage
getFeeEstimateExperimentalResponse = 1109;
GetCurrentBlockColorResponseMessage getCurrentBlockColorResponse = 1111; GetCurrentBlockColorResponseMessage getCurrentBlockColorResponse = 1111;
GetPruningWindowRootsRequestMessage getPruningWindowRootsRequest = 1113;
GetPruningWindowRootsResponseMessage getPruningWindowRootsResponse = 1114;
AddArchivalBlocksRequestMessage addArchivalBlocksRequest = 1115;
AddArchivalBlocksResponseMessage addArchivalBlocksResponse = 1116;
} }
} }
service P2P { service P2P {
rpc MessageStream (stream KaspadMessage) returns (stream KaspadMessage) {} rpc MessageStream(stream KaspadMessage) returns (stream KaspadMessage) {}
} }
service RPC { service RPC {
rpc MessageStream (stream KaspadMessage) returns (stream KaspadMessage) {} rpc MessageStream(stream KaspadMessage) returns (stream KaspadMessage) {}
} }

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT. // Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions: // versions:
// - protoc-gen-go-grpc v1.2.0 // - protoc-gen-go-grpc v1.5.1
// - protoc v3.12.3 // - protoc v3.12.4
// source: messages.proto // source: messages.proto
package protowire package protowire
@ -15,14 +15,18 @@ import (
// This is a compile-time assertion to ensure that this generated file // This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against. // is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later. // Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion7 const _ = grpc.SupportPackageIsVersion9
const (
P2P_MessageStream_FullMethodName = "/protowire.P2P/MessageStream"
)
// P2PClient is the client API for P2P service. // P2PClient is the client API for P2P service.
// //
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type P2PClient interface { type P2PClient interface {
MessageStream(ctx context.Context, opts ...grpc.CallOption) (P2P_MessageStreamClient, error) MessageStream(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[KaspadMessage, KaspadMessage], error)
} }
type p2PClient struct { type p2PClient struct {
@ -33,53 +37,39 @@ func NewP2PClient(cc grpc.ClientConnInterface) P2PClient {
return &p2PClient{cc} return &p2PClient{cc}
} }
func (c *p2PClient) MessageStream(ctx context.Context, opts ...grpc.CallOption) (P2P_MessageStreamClient, error) { func (c *p2PClient) MessageStream(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[KaspadMessage, KaspadMessage], error) {
stream, err := c.cc.NewStream(ctx, &P2P_ServiceDesc.Streams[0], "/protowire.P2P/MessageStream", opts...) cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
stream, err := c.cc.NewStream(ctx, &P2P_ServiceDesc.Streams[0], P2P_MessageStream_FullMethodName, cOpts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
x := &p2PMessageStreamClient{stream} x := &grpc.GenericClientStream[KaspadMessage, KaspadMessage]{ClientStream: stream}
return x, nil return x, nil
} }
type P2P_MessageStreamClient interface { // This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
Send(*KaspadMessage) error type P2P_MessageStreamClient = grpc.BidiStreamingClient[KaspadMessage, KaspadMessage]
Recv() (*KaspadMessage, error)
grpc.ClientStream
}
type p2PMessageStreamClient struct {
grpc.ClientStream
}
func (x *p2PMessageStreamClient) Send(m *KaspadMessage) error {
return x.ClientStream.SendMsg(m)
}
func (x *p2PMessageStreamClient) Recv() (*KaspadMessage, error) {
m := new(KaspadMessage)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// P2PServer is the server API for P2P service. // P2PServer is the server API for P2P service.
// All implementations must embed UnimplementedP2PServer // All implementations must embed UnimplementedP2PServer
// for forward compatibility // for forward compatibility.
type P2PServer interface { type P2PServer interface {
MessageStream(P2P_MessageStreamServer) error MessageStream(grpc.BidiStreamingServer[KaspadMessage, KaspadMessage]) error
mustEmbedUnimplementedP2PServer() mustEmbedUnimplementedP2PServer()
} }
// UnimplementedP2PServer must be embedded to have forward compatible implementations. // UnimplementedP2PServer must be embedded to have
type UnimplementedP2PServer struct { // forward compatible implementations.
} //
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedP2PServer struct{}
func (UnimplementedP2PServer) MessageStream(P2P_MessageStreamServer) error { func (UnimplementedP2PServer) MessageStream(grpc.BidiStreamingServer[KaspadMessage, KaspadMessage]) error {
return status.Errorf(codes.Unimplemented, "method MessageStream not implemented") return status.Errorf(codes.Unimplemented, "method MessageStream not implemented")
} }
func (UnimplementedP2PServer) mustEmbedUnimplementedP2PServer() {} func (UnimplementedP2PServer) mustEmbedUnimplementedP2PServer() {}
func (UnimplementedP2PServer) testEmbeddedByValue() {}
// UnsafeP2PServer may be embedded to opt out of forward compatibility for this service. // UnsafeP2PServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to P2PServer will // Use of this interface is not recommended, as added methods to P2PServer will
@ -89,34 +79,22 @@ type UnsafeP2PServer interface {
} }
func RegisterP2PServer(s grpc.ServiceRegistrar, srv P2PServer) { func RegisterP2PServer(s grpc.ServiceRegistrar, srv P2PServer) {
// If the following call pancis, it indicates UnimplementedP2PServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&P2P_ServiceDesc, srv) s.RegisterService(&P2P_ServiceDesc, srv)
} }
func _P2P_MessageStream_Handler(srv interface{}, stream grpc.ServerStream) error { func _P2P_MessageStream_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(P2PServer).MessageStream(&p2PMessageStreamServer{stream}) return srv.(P2PServer).MessageStream(&grpc.GenericServerStream[KaspadMessage, KaspadMessage]{ServerStream: stream})
} }
type P2P_MessageStreamServer interface { // This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
Send(*KaspadMessage) error type P2P_MessageStreamServer = grpc.BidiStreamingServer[KaspadMessage, KaspadMessage]
Recv() (*KaspadMessage, error)
grpc.ServerStream
}
type p2PMessageStreamServer struct {
grpc.ServerStream
}
func (x *p2PMessageStreamServer) Send(m *KaspadMessage) error {
return x.ServerStream.SendMsg(m)
}
func (x *p2PMessageStreamServer) Recv() (*KaspadMessage, error) {
m := new(KaspadMessage)
if err := x.ServerStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// P2P_ServiceDesc is the grpc.ServiceDesc for P2P service. // P2P_ServiceDesc is the grpc.ServiceDesc for P2P service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
@ -136,11 +114,15 @@ var P2P_ServiceDesc = grpc.ServiceDesc{
Metadata: "messages.proto", Metadata: "messages.proto",
} }
const (
RPC_MessageStream_FullMethodName = "/protowire.RPC/MessageStream"
)
// RPCClient is the client API for RPC service. // RPCClient is the client API for RPC service.
// //
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type RPCClient interface { type RPCClient interface {
MessageStream(ctx context.Context, opts ...grpc.CallOption) (RPC_MessageStreamClient, error) MessageStream(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[KaspadMessage, KaspadMessage], error)
} }
type rPCClient struct { type rPCClient struct {
@ -151,53 +133,39 @@ func NewRPCClient(cc grpc.ClientConnInterface) RPCClient {
return &rPCClient{cc} return &rPCClient{cc}
} }
func (c *rPCClient) MessageStream(ctx context.Context, opts ...grpc.CallOption) (RPC_MessageStreamClient, error) { func (c *rPCClient) MessageStream(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[KaspadMessage, KaspadMessage], error) {
stream, err := c.cc.NewStream(ctx, &RPC_ServiceDesc.Streams[0], "/protowire.RPC/MessageStream", opts...) cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
stream, err := c.cc.NewStream(ctx, &RPC_ServiceDesc.Streams[0], RPC_MessageStream_FullMethodName, cOpts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
x := &rPCMessageStreamClient{stream} x := &grpc.GenericClientStream[KaspadMessage, KaspadMessage]{ClientStream: stream}
return x, nil return x, nil
} }
type RPC_MessageStreamClient interface { // This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
Send(*KaspadMessage) error type RPC_MessageStreamClient = grpc.BidiStreamingClient[KaspadMessage, KaspadMessage]
Recv() (*KaspadMessage, error)
grpc.ClientStream
}
type rPCMessageStreamClient struct {
grpc.ClientStream
}
func (x *rPCMessageStreamClient) Send(m *KaspadMessage) error {
return x.ClientStream.SendMsg(m)
}
func (x *rPCMessageStreamClient) Recv() (*KaspadMessage, error) {
m := new(KaspadMessage)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// RPCServer is the server API for RPC service. // RPCServer is the server API for RPC service.
// All implementations must embed UnimplementedRPCServer // All implementations must embed UnimplementedRPCServer
// for forward compatibility // for forward compatibility.
type RPCServer interface { type RPCServer interface {
MessageStream(RPC_MessageStreamServer) error MessageStream(grpc.BidiStreamingServer[KaspadMessage, KaspadMessage]) error
mustEmbedUnimplementedRPCServer() mustEmbedUnimplementedRPCServer()
} }
// UnimplementedRPCServer must be embedded to have forward compatible implementations. // UnimplementedRPCServer must be embedded to have
type UnimplementedRPCServer struct { // forward compatible implementations.
} //
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedRPCServer struct{}
func (UnimplementedRPCServer) MessageStream(RPC_MessageStreamServer) error { func (UnimplementedRPCServer) MessageStream(grpc.BidiStreamingServer[KaspadMessage, KaspadMessage]) error {
return status.Errorf(codes.Unimplemented, "method MessageStream not implemented") return status.Errorf(codes.Unimplemented, "method MessageStream not implemented")
} }
func (UnimplementedRPCServer) mustEmbedUnimplementedRPCServer() {} func (UnimplementedRPCServer) mustEmbedUnimplementedRPCServer() {}
func (UnimplementedRPCServer) testEmbeddedByValue() {}
// UnsafeRPCServer may be embedded to opt out of forward compatibility for this service. // UnsafeRPCServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to RPCServer will // Use of this interface is not recommended, as added methods to RPCServer will
@ -207,34 +175,22 @@ type UnsafeRPCServer interface {
} }
func RegisterRPCServer(s grpc.ServiceRegistrar, srv RPCServer) { func RegisterRPCServer(s grpc.ServiceRegistrar, srv RPCServer) {
// If the following call pancis, it indicates UnimplementedRPCServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&RPC_ServiceDesc, srv) s.RegisterService(&RPC_ServiceDesc, srv)
} }
func _RPC_MessageStream_Handler(srv interface{}, stream grpc.ServerStream) error { func _RPC_MessageStream_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(RPCServer).MessageStream(&rPCMessageStreamServer{stream}) return srv.(RPCServer).MessageStream(&grpc.GenericServerStream[KaspadMessage, KaspadMessage]{ServerStream: stream})
} }
type RPC_MessageStreamServer interface { // This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
Send(*KaspadMessage) error type RPC_MessageStreamServer = grpc.BidiStreamingServer[KaspadMessage, KaspadMessage]
Recv() (*KaspadMessage, error)
grpc.ServerStream
}
type rPCMessageStreamServer struct {
grpc.ServerStream
}
func (x *rPCMessageStreamServer) Send(m *KaspadMessage) error {
return x.ServerStream.SendMsg(m)
}
func (x *rPCMessageStreamServer) Recv() (*KaspadMessage, error) {
m := new(KaspadMessage)
if err := x.ServerStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
// RPC_ServiceDesc is the grpc.ServiceDesc for RPC service. // RPC_ServiceDesc is the grpc.ServiceDesc for RPC service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,

View File

@ -889,3 +889,37 @@ message SubmitTransactionReplacementResponseMessage {
RPCError error = 1000; RPCError error = 1000;
} }
message GetPruningWindowRootsRequestMessage {}
message PruningWindowRoots {
repeated string pp_roots = 1;
uint64 pp_index = 2;
}
message GetPruningWindowRootsResponseMessage {
repeated PruningWindowRoots roots = 1;
RPCError error = 1000;
}
message AcceptedTxEntry{
string transactionId = 1;
uint32 index_within_block = 2;
}
message MergesetBlockAcceptanceData{
string blockHash = 1;
repeated AcceptedTxEntry acceptedTxs = 3;
}
message ArchivalBlock{
string child = 1;
RpcBlock block = 2;
repeated MergesetBlockAcceptanceData acceptanceData = 3;
string selectedParent = 4;
}
message AddArchivalBlocksRequestMessage { repeated ArchivalBlock blocks = 1; }
message AddArchivalBlocksResponseMessage { RPCError error = 1000; }

View File

@ -0,0 +1,112 @@
package protowire
import (
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/pkg/errors"
)
func (x *KaspadMessage_AddArchivalBlocksRequest) toAppMessage() (appmessage.Message, error) {
panic("we need to implement acceptance data conversion")
if x == nil {
return nil, errors.Wrapf(errorNil, "KaspadMessage_AddArchivalBlocksRequest is nil")
}
blocks := make([]*appmessage.ArchivalBlock, len(x.AddArchivalBlocksRequest.Blocks))
for i, block := range x.AddArchivalBlocksRequest.Blocks {
rpcBlock, err := block.Block.toAppMessage()
if err != nil {
return nil, err
}
blocks[i] = &appmessage.ArchivalBlock{
Block: rpcBlock,
Child: block.Child,
}
}
return &appmessage.AddArchivalBlocksRequestMessage{
Blocks: blocks,
}, nil
}
func (x *KaspadMessage_AddArchivalBlocksRequest) fromAppMessage(message *appmessage.AddArchivalBlocksRequestMessage) error {
blocks := make([]*ArchivalBlock, len(message.Blocks))
for i, block := range message.Blocks {
protoBlock := &ArchivalBlock{
Child: block.Child,
SelectedParent: block.SelectedParent,
}
if block.Block != nil {
protoBlock.Block = &RpcBlock{}
err := protoBlock.Block.fromAppMessage(block.Block)
if err != nil {
return err
}
}
protoBlock.AcceptanceData = make([]*MergesetBlockAcceptanceData, len(block.AcceptanceData))
for j, acceptanceData := range block.AcceptanceData {
protoBlock.AcceptanceData[j] = &MergesetBlockAcceptanceData{}
protoBlock.AcceptanceData[j].fromAppMessage(acceptanceData)
}
blocks[i] = protoBlock
}
x.AddArchivalBlocksRequest = &AddArchivalBlocksRequestMessage{
Blocks: blocks,
}
return nil
}
func (x *MergesetBlockAcceptanceData) fromAppMessage(message *appmessage.MergesetBlockAcceptanceData) error {
if message == nil {
return errors.Wrapf(errorNil, "MergesetBlockAcceptanceData is nil")
}
x.BlockHash = message.BlockHash
x.AcceptedTxs = make([]*AcceptedTxEntry, len(message.AcceptedTxs))
for i, tx := range message.AcceptedTxs {
x.AcceptedTxs[i] = &AcceptedTxEntry{
TransactionId: tx.TransactionID,
IndexWithinBlock: tx.IndexWithinBlock,
}
}
return nil
}
func (x *KaspadMessage_AddArchivalBlocksResponse) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "KaspadMessage_AddArchivalBlocksResponse is nil")
}
return x.AddArchivalBlocksResponse.toAppMessage()
}
func (x *KaspadMessage_AddArchivalBlocksResponse) fromAppMessage(message *appmessage.AddArchivalBlocksResponseMessage) error {
var err *RPCError
if message.Error != nil {
err = &RPCError{Message: message.Error.Message}
}
x.AddArchivalBlocksResponse = &AddArchivalBlocksResponseMessage{
Error: err,
}
return nil
}
func (x *AddArchivalBlocksResponseMessage) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "AddArchivalBlocksResponseMessage is nil")
}
rpcErr, err := x.Error.toAppMessage()
// Error is an optional field
if err != nil && !errors.Is(err, errorNil) {
return nil, err
}
return &appmessage.AddArchivalBlocksResponseMessage{
Error: rpcErr,
}, nil
}

View File

@ -0,0 +1,70 @@
package protowire
import (
"github.com/kaspanet/kaspad/app/appmessage"
"github.com/pkg/errors"
)
func (x *KaspadMessage_GetPruningWindowRootsRequest) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "KaspadMessage_GetPruningWindowRootsRequest is nil")
}
return &appmessage.GetPeerAddressesRequestMessage{}, nil
}
func (x *KaspadMessage_GetPruningWindowRootsRequest) fromAppMessage(_ *appmessage.GetPruningWindowRootsRequestMessage) error {
return nil
}
func (x *KaspadMessage_GetPruningWindowRootsResponse) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "KaspadMessage_GetPruningWindowRootsResponse is nil")
}
return x.GetPruningWindowRootsResponse.toAppMessage()
}
func (x *KaspadMessage_GetPruningWindowRootsResponse) fromAppMessage(message *appmessage.GetPruningWindowRootsResponseMessage) error {
var err *RPCError
if message.Error != nil {
err = &RPCError{Message: message.Error.Message}
}
roots := make([]*PruningWindowRoots, len(message.Roots))
for i, root := range message.Roots {
roots[i] = &PruningWindowRoots{
PpRoots: root.PPRoots,
PpIndex: root.PPIndex,
}
}
x.GetPruningWindowRootsResponse = &GetPruningWindowRootsResponseMessage{
Roots: roots,
Error: err,
}
return nil
}
func (x *GetPruningWindowRootsResponseMessage) toAppMessage() (appmessage.Message, error) {
if x == nil {
return nil, errors.Wrapf(errorNil, "GetPeerAddressesResponseMessage is nil")
}
rpcErr, err := x.Error.toAppMessage()
// Error is an optional field
if err != nil && !errors.Is(err, errorNil) {
return nil, err
}
roots := make([]*appmessage.PruningWindowRoots, len(x.Roots))
for i, root := range x.Roots {
roots[i] = &appmessage.PruningWindowRoots{
PPRoots: root.PpRoots,
PPIndex: root.PpIndex,
}
}
return &appmessage.GetPruningWindowRootsResponseMessage{
Roots: roots,
Error: rpcErr,
}, nil
}

View File

@ -989,6 +989,34 @@ func toRPCPayload(message appmessage.Message) (isKaspadMessage_Payload, error) {
return nil, err return nil, err
} }
return payload, nil return payload, nil
case *appmessage.GetPruningWindowRootsRequestMessage:
payload := new(KaspadMessage_GetPruningWindowRootsRequest)
err := payload.fromAppMessage(message)
if err != nil {
return nil, err
}
return payload, nil
case *appmessage.GetPruningWindowRootsResponseMessage:
payload := new(KaspadMessage_GetPruningWindowRootsResponse)
err := payload.fromAppMessage(message)
if err != nil {
return nil, err
}
return payload, nil
case *appmessage.AddArchivalBlocksRequestMessage:
payload := new(KaspadMessage_AddArchivalBlocksRequest)
err := payload.fromAppMessage(message)
if err != nil {
return nil, err
}
return payload, nil
case *appmessage.AddArchivalBlocksResponseMessage:
payload := new(KaspadMessage_AddArchivalBlocksResponse)
err := payload.fromAppMessage(message)
if err != nil {
return nil, err
}
return payload, nil
default: default:
return nil, nil return nil, nil
} }

View File

@ -0,0 +1,19 @@
package rpcclient
import "github.com/kaspanet/kaspad/app/appmessage"
func (c *RPCClient) AddArchivalBlocks(blocks []*appmessage.ArchivalBlock) (*appmessage.AddArchivalBlocksResponseMessage, error) {
err := c.rpcRouter.outgoingRoute().Enqueue(appmessage.NewAddArchivalBlocksRequestMessage(blocks))
if err != nil {
return nil, err
}
response, err := c.route(appmessage.CmdAddArchivalBlocksResponseMessage).DequeueWithTimeout(c.timeout)
if err != nil {
return nil, err
}
convertedResp := response.(*appmessage.AddArchivalBlocksResponseMessage)
if convertedResp.Error != nil {
return nil, c.convertRPCError(convertedResp.Error)
}
return convertedResp, nil
}

View File

@ -0,0 +1,19 @@
package rpcclient
import "github.com/kaspanet/kaspad/app/appmessage"
func (c *RPCClient) GetPruningWindowRoots() (*appmessage.GetPruningWindowRootsResponseMessage, error) {
err := c.rpcRouter.outgoingRoute().Enqueue(&appmessage.GetPruningWindowRootsRequestMessage{})
if err != nil {
return nil, err
}
response, err := c.route(appmessage.CmdGetPruningWindowRootsResponseMessage).DequeueWithTimeout(c.timeout)
if err != nil {
return nil, err
}
convertedResp := response.(*appmessage.GetPruningWindowRootsResponseMessage)
if convertedResp.Error != nil {
return nil, c.convertRPCError(convertedResp.Error)
}
return convertedResp, nil
}