diff --git a/README.md b/README.md index b28eee7..e71b769 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ USAGE: FLAGS: -d, --debug Enable debug logging level -h, --help Prints help information - --mine-when-not-synced Mine even when kaspad says it is not synced, only useful when passing `--allow-submit- - block-when-not-synced` to kaspad [default: false] + --mine-when-not-synced Mine even when kaspad says it is not synced, only useful when passing + `--enable-unsynced-mining` to kaspad [default: false] --testnet Use testnet instead of mainnet [default: false] -V, --version Prints version information diff --git a/build.rs b/build.rs index 26728ba..4bb825e 100644 --- a/build.rs +++ b/build.rs @@ -1,7 +1,7 @@ use std::env; fn main() -> Result<(), Box> { - let protowire_files = &["proto/messages.proto", "proto/rpc.proto", "proto/p2p.proto"]; + let protowire_files = &["proto/messages.proto", "proto/rpc.proto"]; let dirs = &["proto"]; println!("cargo:rerun-if-changed=proto"); diff --git a/proto/messages.proto b/proto/messages.proto index 079fdc8..af0a916 100644 --- a/proto/messages.proto +++ b/proto/messages.proto @@ -1,136 +1,142 @@ syntax = "proto3"; package protowire; -option go_package = "github.com/kaspanet/kaspad/protowire"; - -import "p2p.proto"; import "rpc.proto"; -message KaspadMessage { +message KaspadRequest { + uint64 id = 101; oneof payload { - AddressesMessage addresses = 1; - BlockMessage block = 2; - TransactionMessage transaction = 3; - BlockLocatorMessage blockLocator = 5; - RequestAddressesMessage requestAddresses = 6; - RequestRelayBlocksMessage requestRelayBlocks = 10; - RequestTransactionsMessage requestTransactions = 12; - BlockMessage ibdBlock = 13; - InvRelayBlockMessage invRelayBlock = 14; - InvTransactionsMessage invTransactions = 15; - PingMessage ping = 16; - PongMessage pong = 17; - VerackMessage verack = 19; - VersionMessage version = 20; - TransactionNotFoundMessage transactionNotFound = 21; - RejectMessage reject = 22; - PruningPointUtxoSetChunkMessage pruningPointUtxoSetChunk = 25; - RequestIBDBlocksMessage requestIBDBlocks = 26; - UnexpectedPruningPointMessage unexpectedPruningPoint = 27; - IbdBlockLocatorMessage ibdBlockLocator = 30; - IbdBlockLocatorHighestHashMessage ibdBlockLocatorHighestHash = 31; - RequestNextPruningPointUtxoSetChunkMessage requestNextPruningPointUtxoSetChunk = 33; - DonePruningPointUtxoSetChunksMessage donePruningPointUtxoSetChunks = 34; - IbdBlockLocatorHighestHashNotFoundMessage ibdBlockLocatorHighestHashNotFound = 35; - BlockWithTrustedDataMessage blockWithTrustedData = 36; - DoneBlocksWithTrustedDataMessage doneBlocksWithTrustedData = 37; - RequestPruningPointAndItsAnticoneMessage requestPruningPointAndItsAnticone = 40; - BlockHeadersMessage blockHeaders = 41; - RequestNextHeadersMessage requestNextHeaders = 42; - DoneHeadersMessage DoneHeaders = 43; - RequestPruningPointUTXOSetMessage requestPruningPointUTXOSet = 44; - RequestHeadersMessage requestHeaders = 45; - RequestBlockLocatorMessage requestBlockLocator = 46; - PruningPointsMessage pruningPoints = 47; - RequestPruningPointProofMessage requestPruningPointProof = 48; - PruningPointProofMessage pruningPointProof = 49; - GetCurrentNetworkRequestMessage getCurrentNetworkRequest = 1001; - GetCurrentNetworkResponseMessage getCurrentNetworkResponse = 1002; SubmitBlockRequestMessage submitBlockRequest = 1003; - SubmitBlockResponseMessage submitBlockResponse = 1004; GetBlockTemplateRequestMessage getBlockTemplateRequest = 1005; - GetBlockTemplateResponseMessage getBlockTemplateResponse = 1006; NotifyBlockAddedRequestMessage notifyBlockAddedRequest = 1007; + // BlockAddedNotificationMessage blockAddedNotification = 1009; + GetPeerAddressesRequestMessage getPeerAddressesRequest = 1010; + GetSinkRequestMessage GetSinkRequest = 1012; + GetMempoolEntryRequestMessage getMempoolEntryRequest = 1014; + GetConnectedPeerInfoRequestMessage getConnectedPeerInfoRequest = 1016; + AddPeerRequestMessage addPeerRequest = 1018; + SubmitTransactionRequestMessage submitTransactionRequest = 1020; + NotifyVirtualChainChangedRequestMessage notifyVirtualChainChangedRequest = 1022; + // VirtualChainChangedNotificationMessage virtualChainChangedNotification = 1024; + GetBlockRequestMessage getBlockRequest = 1025; + GetSubnetworkRequestMessage getSubnetworkRequest = 1027; + GetVirtualChainFromBlockRequestMessage getVirtualChainFromBlockRequest = 1029; + GetBlocksRequestMessage getBlocksRequest = 1031; + GetBlockCountRequestMessage getBlockCountRequest = 1033; + GetBlockDagInfoRequestMessage getBlockDagInfoRequest = 1035; + ResolveFinalityConflictRequestMessage resolveFinalityConflictRequest = 1037; + NotifyFinalityConflictRequestMessage notifyFinalityConflictRequest = 1039; + // FinalityConflictNotificationMessage finalityConflictNotification = 1041; + // FinalityConflictResolvedNotificationMessage finalityConflictResolvedNotification = 1042; + GetMempoolEntriesRequestMessage getMempoolEntriesRequest = 1043; + ShutdownRequestMessage shutdownRequest = 1045; + GetHeadersRequestMessage getHeadersRequest = 1047; + NotifyUtxosChangedRequestMessage notifyUtxosChangedRequest = 1049; + // UtxosChangedNotificationMessage utxosChangedNotification = 1051; + GetUtxosByAddressesRequestMessage getUtxosByAddressesRequest = 1052; + GetSinkBlueScoreRequestMessage getSinkBlueScoreRequest = 1054; + NotifySinkBlueScoreChangedRequestMessage notifySinkBlueScoreChangedRequest = 1056; + // SinkBlueScoreChangedNotificationMessage sinkBlueScoreChangedNotification = 1058; + BanRequestMessage banRequest = 1059; + UnbanRequestMessage unbanRequest = 1061; + GetInfoRequestMessage getInfoRequest = 1063; + StopNotifyingUtxosChangedRequestMessage stopNotifyingUtxosChangedRequest = 1065; + NotifyPruningPointUtxoSetOverrideRequestMessage notifyPruningPointUtxoSetOverrideRequest = 1067; + // PruningPointUtxoSetOverrideNotificationMessage pruningPointUtxoSetOverrideNotification = 1069; + StopNotifyingPruningPointUtxoSetOverrideRequestMessage stopNotifyingPruningPointUtxoSetOverrideRequest = 1070; + EstimateNetworkHashesPerSecondRequestMessage estimateNetworkHashesPerSecondRequest = 1072; + NotifyVirtualDaaScoreChangedRequestMessage notifyVirtualDaaScoreChangedRequest = 1074; + // VirtualDaaScoreChangedNotificationMessage virtualDaaScoreChangedNotification = 1076; + GetBalanceByAddressRequestMessage getBalanceByAddressRequest = 1077; + GetBalancesByAddressesRequestMessage getBalancesByAddressesRequest = 1079; + NotifyNewBlockTemplateRequestMessage notifyNewBlockTemplateRequest = 1081; + // NewBlockTemplateNotificationMessage newBlockTemplateNotification = 1083; + GetMempoolEntriesByAddressesRequestMessage getMempoolEntriesByAddressesRequest = 1084; + GetCoinSupplyRequestMessage getCoinSupplyRequest = 1086; + PingRequestMessage pingRequest = 1088; + GetMetricsRequestMessage getMetricsRequest = 1090; + GetServerInfoRequestMessage getServerInfoRequest = 1092; + GetSyncStatusRequestMessage getSyncStatusRequest = 1094; + GetDaaScoreTimestampEstimateRequestMessage getDaaScoreTimestampEstimateRequest = 1096; + SubmitTransactionReplacementRequestMessage submitTransactionReplacementRequest = 1100; + GetConnectionsRequestMessage getConnectionsRequest = 1102; + GetSystemInfoRequestMessage getSystemInfoRequest = 1104; + GetFeeEstimateRequestMessage getFeeEstimateRequest = 1106; + GetFeeEstimateExperimentalRequestMessage getFeeEstimateExperimentalRequest = 1108; + GetCurrentBlockColorRequestMessage getCurrentBlockColorRequest = 1110; + GetUtxoReturnAddressRequestMessage getUtxoReturnAddressRequest = 1112; + GetVirtualChainFromBlockV2RequestMessage getVirtualChainFromBlockV2Request = 1114; + } +} + +message KaspadResponse { + uint64 id = 101; + oneof payload { + GetCurrentNetworkResponseMessage getCurrentNetworkResponse = 1002; + SubmitBlockResponseMessage submitBlockResponse = 1004; + GetBlockTemplateResponseMessage getBlockTemplateResponse = 1006; NotifyBlockAddedResponseMessage notifyBlockAddedResponse = 1008; BlockAddedNotificationMessage blockAddedNotification = 1009; - GetPeerAddressesRequestMessage getPeerAddressesRequest = 1010; GetPeerAddressesResponseMessage getPeerAddressesResponse = 1011; - GetSelectedTipHashRequestMessage getSelectedTipHashRequest = 1012; - GetSelectedTipHashResponseMessage getSelectedTipHashResponse = 1013; - GetMempoolEntryRequestMessage getMempoolEntryRequest = 1014; + GetSinkResponseMessage GetSinkResponse = 1013; GetMempoolEntryResponseMessage getMempoolEntryResponse = 1015; - GetConnectedPeerInfoRequestMessage getConnectedPeerInfoRequest = 1016; GetConnectedPeerInfoResponseMessage getConnectedPeerInfoResponse = 1017; - AddPeerRequestMessage addPeerRequest = 1018; AddPeerResponseMessage addPeerResponse = 1019; - SubmitTransactionRequestMessage submitTransactionRequest = 1020; SubmitTransactionResponseMessage submitTransactionResponse = 1021; - NotifyVirtualSelectedParentChainChangedRequestMessage notifyVirtualSelectedParentChainChangedRequest = 1022; - NotifyVirtualSelectedParentChainChangedResponseMessage notifyVirtualSelectedParentChainChangedResponse = 1023; - VirtualSelectedParentChainChangedNotificationMessage virtualSelectedParentChainChangedNotification = 1024; - GetBlockRequestMessage getBlockRequest = 1025; + NotifyVirtualChainChangedResponseMessage notifyVirtualChainChangedResponse = 1023; + VirtualChainChangedNotificationMessage virtualChainChangedNotification = 1024; GetBlockResponseMessage getBlockResponse = 1026; - GetSubnetworkRequestMessage getSubnetworkRequest = 1027; GetSubnetworkResponseMessage getSubnetworkResponse = 1028; - GetVirtualSelectedParentChainFromBlockRequestMessage getVirtualSelectedParentChainFromBlockRequest = 1029; - GetVirtualSelectedParentChainFromBlockResponseMessage getVirtualSelectedParentChainFromBlockResponse = 1030; - GetBlocksRequestMessage getBlocksRequest = 1031; + GetVirtualChainFromBlockResponseMessage getVirtualChainFromBlockResponse = 1030; GetBlocksResponseMessage getBlocksResponse = 1032; - GetBlockCountRequestMessage getBlockCountRequest = 1033; GetBlockCountResponseMessage getBlockCountResponse = 1034; - GetBlockDagInfoRequestMessage getBlockDagInfoRequest = 1035; GetBlockDagInfoResponseMessage getBlockDagInfoResponse = 1036; - ResolveFinalityConflictRequestMessage resolveFinalityConflictRequest = 1037; ResolveFinalityConflictResponseMessage resolveFinalityConflictResponse = 1038; - NotifyFinalityConflictsRequestMessage notifyFinalityConflictsRequest = 1039; - NotifyFinalityConflictsResponseMessage notifyFinalityConflictsResponse = 1040; + NotifyFinalityConflictResponseMessage notifyFinalityConflictResponse = 1040; FinalityConflictNotificationMessage finalityConflictNotification = 1041; FinalityConflictResolvedNotificationMessage finalityConflictResolvedNotification = 1042; - GetMempoolEntriesRequestMessage getMempoolEntriesRequest = 1043; GetMempoolEntriesResponseMessage getMempoolEntriesResponse = 1044; - ShutDownRequestMessage shutDownRequest = 1045; - ShutDownResponseMessage shutDownResponse = 1046; - GetHeadersRequestMessage getHeadersRequest = 1047; + ShutdownResponseMessage shutdownResponse = 1046; GetHeadersResponseMessage getHeadersResponse = 1048; - NotifyUtxosChangedRequestMessage notifyUtxosChangedRequest = 1049; NotifyUtxosChangedResponseMessage notifyUtxosChangedResponse = 1050; UtxosChangedNotificationMessage utxosChangedNotification = 1051; - GetUtxosByAddressesRequestMessage getUtxosByAddressesRequest = 1052; GetUtxosByAddressesResponseMessage getUtxosByAddressesResponse = 1053; - GetVirtualSelectedParentBlueScoreRequestMessage getVirtualSelectedParentBlueScoreRequest = 1054; - GetVirtualSelectedParentBlueScoreResponseMessage getVirtualSelectedParentBlueScoreResponse = 1055; - NotifyVirtualSelectedParentBlueScoreChangedRequestMessage notifyVirtualSelectedParentBlueScoreChangedRequest = 1056; - NotifyVirtualSelectedParentBlueScoreChangedResponseMessage notifyVirtualSelectedParentBlueScoreChangedResponse = 1057; - VirtualSelectedParentBlueScoreChangedNotificationMessage virtualSelectedParentBlueScoreChangedNotification = 1058; - BanRequestMessage banRequest = 1059; + GetSinkBlueScoreResponseMessage getSinkBlueScoreResponse = 1055; + NotifySinkBlueScoreChangedResponseMessage notifySinkBlueScoreChangedResponse = 1057; + SinkBlueScoreChangedNotificationMessage sinkBlueScoreChangedNotification = 1058; BanResponseMessage banResponse = 1060; - UnbanRequestMessage unbanRequest = 1061; UnbanResponseMessage unbanResponse = 1062; - GetInfoRequestMessage getInfoRequest = 1063; GetInfoResponseMessage getInfoResponse = 1064; - StopNotifyingUtxosChangedRequestMessage stopNotifyingUtxosChangedRequest = 1065; StopNotifyingUtxosChangedResponseMessage stopNotifyingUtxosChangedResponse = 1066; - NotifyPruningPointUTXOSetOverrideRequestMessage notifyPruningPointUTXOSetOverrideRequest = 1067; - NotifyPruningPointUTXOSetOverrideResponseMessage notifyPruningPointUTXOSetOverrideResponse = 1068; - PruningPointUTXOSetOverrideNotificationMessage pruningPointUTXOSetOverrideNotification = 1069; - StopNotifyingPruningPointUTXOSetOverrideRequestMessage stopNotifyingPruningPointUTXOSetOverrideRequest = 1070; - StopNotifyingPruningPointUTXOSetOverrideResponseMessage stopNotifyingPruningPointUTXOSetOverrideResponse = 1071; - EstimateNetworkHashesPerSecondRequestMessage estimateNetworkHashesPerSecondRequest = 1072; + NotifyPruningPointUtxoSetOverrideResponseMessage notifyPruningPointUtxoSetOverrideResponse = 1068; + PruningPointUtxoSetOverrideNotificationMessage pruningPointUtxoSetOverrideNotification = 1069; + StopNotifyingPruningPointUtxoSetOverrideResponseMessage stopNotifyingPruningPointUtxoSetOverrideResponse = 1071; EstimateNetworkHashesPerSecondResponseMessage estimateNetworkHashesPerSecondResponse = 1073; - NotifyVirtualDaaScoreChangedRequestMessage notifyVirtualDaaScoreChangedRequest = 1074; NotifyVirtualDaaScoreChangedResponseMessage notifyVirtualDaaScoreChangedResponse = 1075; VirtualDaaScoreChangedNotificationMessage virtualDaaScoreChangedNotification = 1076; - NotifyNewBlockTemplateRequestMessage notifyNewBlockTemplateRequest = 1081; + GetBalanceByAddressResponseMessage getBalanceByAddressResponse = 1078; + GetBalancesByAddressesResponseMessage getBalancesByAddressesResponse = 1080; NotifyNewBlockTemplateResponseMessage notifyNewBlockTemplateResponse = 1082; NewBlockTemplateNotificationMessage newBlockTemplateNotification = 1083; + GetMempoolEntriesByAddressesResponseMessage getMempoolEntriesByAddressesResponse = 1085; + GetCoinSupplyResponseMessage getCoinSupplyResponse= 1087; + PingResponseMessage pingResponse= 1089; + GetMetricsResponseMessage getMetricsResponse= 1091; + GetServerInfoResponseMessage getServerInfoResponse = 1093; + GetSyncStatusResponseMessage getSyncStatusResponse = 1095; + GetDaaScoreTimestampEstimateResponseMessage getDaaScoreTimestampEstimateResponse = 1097; + SubmitTransactionReplacementResponseMessage submitTransactionReplacementResponse = 1101; + GetConnectionsResponseMessage getConnectionsResponse= 1103; + GetSystemInfoResponseMessage getSystemInfoResponse= 1105; + GetFeeEstimateResponseMessage getFeeEstimateResponse = 1107; + GetFeeEstimateExperimentalResponseMessage getFeeEstimateExperimentalResponse = 1109; + GetCurrentBlockColorResponseMessage getCurrentBlockColorResponse = 1111; + GetUtxoReturnAddressResponseMessage getUtxoReturnAddressResponse = 1113; + GetVirtualChainFromBlockV2ResponseMessage getVirtualChainFromBlockV2Response = 1115; } } -service P2P { - rpc MessageStream (stream KaspadMessage) returns (stream KaspadMessage) {} -} - service RPC { - rpc MessageStream (stream KaspadMessage) returns (stream KaspadMessage) {} + rpc MessageStream (stream KaspadRequest) returns (stream KaspadResponse) {} } diff --git a/proto/p2p.proto b/proto/p2p.proto deleted file mode 100644 index 890f282..0000000 --- a/proto/p2p.proto +++ /dev/null @@ -1,255 +0,0 @@ -syntax = "proto3"; -package protowire; - -option go_package = "github.com/kaspanet/kaspad/protowire"; - -message RequestAddressesMessage{ - bool includeAllSubnetworks = 1; - SubnetworkId subnetworkId = 2; -} - -message AddressesMessage{ - repeated NetAddress addressList = 1; -} - -message NetAddress{ - int64 timestamp = 1; - bytes ip = 3; - uint32 port = 4; -} - -message SubnetworkId{ - bytes bytes = 1; -} - -message TransactionMessage{ - uint32 version = 1; - repeated TransactionInput inputs = 2; - repeated TransactionOutput outputs = 3; - uint64 lockTime = 4; - SubnetworkId subnetworkId = 5; - uint64 gas = 6; - bytes payload = 8; - uint64 mass = 9; -} - -message TransactionInput{ - Outpoint previousOutpoint = 1; - bytes signatureScript = 2; - uint64 sequence = 3; - uint32 sigOpCount = 4; -} - -message Outpoint{ - TransactionId transactionId = 1; - uint32 index = 2; -} - -message TransactionId{ - bytes bytes = 1; -} -message ScriptPublicKey { - bytes script = 1; - uint32 version = 2; -} - -message TransactionOutput{ - uint64 value = 1; - ScriptPublicKey scriptPublicKey = 2; -} - -message BlockMessage{ - BlockHeader header = 1; - repeated TransactionMessage transactions = 2; -} - -message BlockHeader{ - uint32 version = 1; - repeated BlockLevelParents parents = 12; - Hash hashMerkleRoot = 3; - Hash acceptedIdMerkleRoot = 4; - Hash utxoCommitment = 5; - int64 timestamp = 6; - uint32 bits = 7; - uint64 nonce = 8; - uint64 daaScore = 9; - bytes blueWork = 10; - Hash pruningPoint = 14; - uint64 blueScore = 13; -} - -message BlockLevelParents { - repeated Hash parentHashes = 1; -} - -message Hash{ - bytes bytes = 1; -} - -message RequestBlockLocatorMessage{ - Hash highHash = 1; - uint32 limit = 2; -} - -message BlockLocatorMessage{ - repeated Hash hashes = 1; -} - -message RequestHeadersMessage{ - Hash lowHash = 1; - Hash highHash = 2; -} - -message RequestNextHeadersMessage{ -} - -message DoneHeadersMessage{ -} - -message RequestRelayBlocksMessage{ - repeated Hash hashes = 1; -} - -message RequestTransactionsMessage { - repeated TransactionId ids = 1; -} - -message TransactionNotFoundMessage{ - TransactionId id = 1; -} - -message InvRelayBlockMessage{ - Hash hash = 1; -} - -message InvTransactionsMessage{ - repeated TransactionId ids = 1; -} - -message PingMessage{ - uint64 nonce = 1; -} - -message PongMessage{ - uint64 nonce = 1; -} - -message VerackMessage{ -} - -message VersionMessage{ - uint32 protocolVersion = 1; - uint64 services = 2; - int64 timestamp = 3; - NetAddress address = 4; - bytes id = 5; - string userAgent = 6; - bool disableRelayTx = 8; - SubnetworkId subnetworkId = 9; - string network = 10; -} - -message RejectMessage{ - string reason = 1; -} - -message RequestPruningPointUTXOSetMessage{ - Hash pruningPointHash = 1; -} - -message PruningPointUtxoSetChunkMessage{ - repeated OutpointAndUtxoEntryPair outpointAndUtxoEntryPairs = 1; -} - -message OutpointAndUtxoEntryPair{ - Outpoint outpoint = 1; - UtxoEntry utxoEntry = 2; -} - -message UtxoEntry { - uint64 amount = 1; - ScriptPublicKey scriptPublicKey = 2; - uint64 blockDaaScore = 3; - bool isCoinbase = 4; -} - -message RequestNextPruningPointUtxoSetChunkMessage { -} - -message DonePruningPointUtxoSetChunksMessage { -} - -message RequestIBDBlocksMessage{ - repeated Hash hashes = 1; -} - -message UnexpectedPruningPointMessage{ -} - -message IbdBlockLocatorMessage { - Hash targetHash = 1; - repeated Hash blockLocatorHashes = 2; -} - -message IbdBlockLocatorHighestHashMessage { - Hash highestHash = 1; -} - -message IbdBlockLocatorHighestHashNotFoundMessage { -} - -message BlockHeadersMessage { - repeated BlockHeader blockHeaders = 1; -} - -message RequestPruningPointAndItsAnticoneMessage { -} - -message BlockWithTrustedDataMessage { - BlockMessage block = 1; - uint64 daaScore = 2; - repeated DaaBlock daaWindow = 3; - repeated BlockGhostdagDataHashPair ghostdagData = 4; -} - -message DaaBlock { - BlockMessage block = 3; - GhostdagData ghostdagData = 2; -} - -message BlockGhostdagDataHashPair { - Hash hash = 1; - GhostdagData ghostdagData = 2; -} - -message GhostdagData { - uint64 blueScore = 1; - bytes blueWork = 2; - Hash selectedParent = 3; - repeated Hash mergeSetBlues = 4; - repeated Hash mergeSetReds = 5; - repeated BluesAnticoneSizes bluesAnticoneSizes = 6; -} - -message BluesAnticoneSizes { - Hash blueHash = 1; - uint32 anticoneSize = 2; -} - -message DoneBlocksWithTrustedDataMessage { -} - -message PruningPointsMessage { - repeated BlockHeader headers = 1; -} - -message RequestPruningPointProofMessage { -} - -message PruningPointProofMessage { - repeated PruningPointProofHeaderArray headers = 1; -} - -message PruningPointProofHeaderArray { - repeated BlockHeader headers = 1; -} diff --git a/proto/rpc.proto b/proto/rpc.proto index 9735072..bdc443d 100644 --- a/proto/rpc.proto +++ b/proto/rpc.proto @@ -9,11 +9,10 @@ syntax = "proto3"; package protowire; - // RPCError represents a generic non-internal error. // // Receivers of any ResponseMessage are expected to check whether its error field is not null. -message RPCError{ +message RPCError { string message = 1; } @@ -34,15 +33,22 @@ message RpcBlockHeader { uint64 nonce = 8; uint64 daaScore = 9; string blueWork = 10; - string pruningPoint = 14; uint64 blueScore = 13; + string pruningPoint = 14; + string hash = 15; } message RpcBlockLevelParents { repeated string parentHashes = 1; } -message RpcBlockVerboseData{ +message RpcBlockLevelRun { + repeated string parentHashes = 1; + // must be <= 255 (u8) + uint32 cumulativeLevel = 2; +} + +message RpcBlockVerboseData { string hash = 1; double difficulty = 11; string selectedParentHash = 13; @@ -67,6 +73,14 @@ message RpcTransaction { uint64 mass = 10; } +message RpcTransactionVerboseData { + string transactionId = 1; + string hash = 2; + uint64 computeMass = 4; + string blockHash = 12; + uint64 blockTime = 14; +} + message RpcTransactionInput { RpcOutpoint previousOutpoint = 1; string signatureScript = 2; @@ -75,6 +89,24 @@ message RpcTransactionInput { RpcTransactionInputVerboseData verboseData = 4; } +message RpcTransactionInputVerboseData { + RpcUtxoEntry utxoEntry = 1; // this field is new, if this is null, the utxo cannot be found, or is coinbase. +} + +message RpcUtxoEntry { + uint64 amount = 1; + RpcScriptPublicKey scriptPublicKey = 2; + uint64 blockDaaScore = 3; + bool isCoinbase = 4; + RpcUtxoEntryVerboseData verboseData = 5; + string covenant_id = 6; +} + +message RpcUtxoEntryVerboseData { + string scriptPublicKeyType = 5; + string scriptPublicKeyAddress = 6; +} + message RpcScriptPublicKey { uint32 version = 1; string scriptPublicKey = 2; @@ -97,37 +129,22 @@ message RpcOutpoint { uint32 index = 2; } -message RpcUtxoEntry { - uint64 amount = 1; - RpcScriptPublicKey scriptPublicKey = 2; - uint64 blockDaaScore = 3; - bool isCoinbase = 4; - string covenant_id = 6; -} - -message RpcTransactionVerboseData{ - string transactionId = 1; - string hash = 2; - uint64 mass = 4; - string blockHash = 12; - uint64 blockTime = 14; -} - -message RpcTransactionInputVerboseData{ -} - -message RpcTransactionOutputVerboseData{ +message RpcTransactionOutputVerboseData { string scriptPublicKeyType = 5; string scriptPublicKeyAddress = 6; } +enum RpcNotifyCommand { + NOTIFY_START = 0; + NOTIFY_STOP = 1; +} + // GetCurrentNetworkRequestMessage requests the network kaspad is currently running against. // // Possible networks are: Mainnet, Testnet, Simnet, Devnet -message GetCurrentNetworkRequestMessage{ -} +message GetCurrentNetworkRequestMessage {} -message GetCurrentNetworkResponseMessage{ +message GetCurrentNetworkResponseMessage { string currentNetwork = 1; RPCError error = 1000; } @@ -136,12 +153,12 @@ message GetCurrentNetworkResponseMessage{ // Blocks are generally expected to have been generated using the getBlockTemplate call. // // See: GetBlockTemplateRequestMessage -message SubmitBlockRequestMessage{ +message SubmitBlockRequestMessage { RpcBlock block = 2; bool allowNonDAABlocks = 3; } -message SubmitBlockResponseMessage{ +message SubmitBlockResponseMessage { enum RejectReason { NONE = 0; BLOCK_INVALID = 1; @@ -155,13 +172,13 @@ message SubmitBlockResponseMessage{ // Callers are expected to solve the block template and submit it using the submitBlock call // // See: SubmitBlockRequestMessage -message GetBlockTemplateRequestMessage{ +message GetBlockTemplateRequestMessage { // Which kaspa address should the coinbase block reward transaction pay into string payAddress = 1; string extraData = 2; } -message GetBlockTemplateResponseMessage{ +message GetBlockTemplateResponseMessage { RpcBlock block = 3; // Whether kaspad thinks that it's synced. @@ -176,10 +193,11 @@ message GetBlockTemplateResponseMessage{ // NotifyBlockAddedRequestMessage registers this connection for blockAdded notifications. // // See: BlockAddedNotificationMessage -message NotifyBlockAddedRequestMessage{ +message NotifyBlockAddedRequestMessage { + RpcNotifyCommand command = 101; } -message NotifyBlockAddedResponseMessage{ +message NotifyBlockAddedResponseMessage { RPCError error = 1000; } @@ -187,16 +205,15 @@ message NotifyBlockAddedResponseMessage{ // into the DAG. // // See: NotifyBlockAddedRequestMessage -message BlockAddedNotificationMessage{ +message BlockAddedNotificationMessage { RpcBlock block = 3; } // GetPeerAddressesRequestMessage requests the list of known kaspad addresses in the // current network. (mainnet, testnet, etc.) -message GetPeerAddressesRequestMessage{ -} +message GetPeerAddressesRequestMessage {} -message GetPeerAddressesResponseMessage{ +message GetPeerAddressesResponseMessage { repeated GetPeerAddressesKnownAddressMessage addresses = 1; repeated GetPeerAddressesKnownAddressMessage bannedAddresses = 2; RPCError error = 1000; @@ -206,56 +223,59 @@ message GetPeerAddressesKnownAddressMessage { string Addr = 1; } -// GetSelectedTipHashRequestMessage requests the hash of the current virtual's +// GetSinkRequestMessage requests the hash of the current virtual's // selected parent. -message GetSelectedTipHashRequestMessage{ -} +message GetSinkRequestMessage {} -message GetSelectedTipHashResponseMessage{ - string selectedTipHash = 1; +message GetSinkResponseMessage { + string sink = 1; RPCError error = 1000; } // GetMempoolEntryRequestMessage requests information about a specific transaction // in the mempool. -message GetMempoolEntryRequestMessage{ +message GetMempoolEntryRequestMessage { // The transaction's TransactionID. string txId = 1; + bool includeOrphanPool = 2; + bool filterTransactionPool = 3; } -message GetMempoolEntryResponseMessage{ - MempoolEntry entry = 1; +message GetMempoolEntryResponseMessage { + RpcMempoolEntry entry = 1; RPCError error = 1000; } // GetMempoolEntriesRequestMessage requests information about all the transactions // currently in the mempool. -message GetMempoolEntriesRequestMessage{ +message GetMempoolEntriesRequestMessage { + bool includeOrphanPool = 1; + bool filterTransactionPool = 2; } -message GetMempoolEntriesResponseMessage{ - repeated MempoolEntry entries = 1; +message GetMempoolEntriesResponseMessage { + repeated RpcMempoolEntry entries = 1; RPCError error = 1000; } -message MempoolEntry{ +message RpcMempoolEntry { uint64 fee = 1; RpcTransaction transaction = 3; + bool isOrphan = 4; } // GetConnectedPeerInfoRequestMessage requests information about all the p2p peers // currently connected to this kaspad. -message GetConnectedPeerInfoRequestMessage{ -} +message GetConnectedPeerInfoRequestMessage {} -message GetConnectedPeerInfoResponseMessage{ +message GetConnectedPeerInfoResponseMessage { repeated GetConnectedPeerInfoMessage infos = 1; RPCError error = 1000; } -message GetConnectedPeerInfoMessage{ +message GetConnectedPeerInfoMessage { string id = 1; string address = 2; @@ -279,54 +299,74 @@ message GetConnectedPeerInfoMessage{ // AddPeerRequestMessage adds a peer to kaspad's outgoing connection list. // This will, in most cases, result in kaspad connecting to said peer. -message AddPeerRequestMessage{ +message AddPeerRequestMessage { string address = 1; // Whether to keep attempting to connect to this peer after disconnection bool isPermanent = 2; } -message AddPeerResponseMessage{ +message AddPeerResponseMessage { RPCError error = 1000; } // SubmitTransactionRequestMessage submits a transaction to the mempool -message SubmitTransactionRequestMessage{ +message SubmitTransactionRequestMessage { RpcTransaction transaction = 1; bool allowOrphan = 2; } -message SubmitTransactionResponseMessage{ +message SubmitTransactionResponseMessage { + // The transaction ID of the submitted transaction + string transactionId = 1; + + RPCError error = 1000; +} + +// SubmitTransactionReplacementRequestMessage submits a transaction to the mempool, applying a mandatory Replace by Fee policy +message SubmitTransactionReplacementRequestMessage { + RpcTransaction transaction = 1; +} + +message SubmitTransactionReplacementResponseMessage { // The transaction ID of the submitted transaction string transactionId = 1; + // The previous transaction replaced in the mempool by the newly submitted one + RpcTransaction replacedTransaction = 2; + RPCError error = 1000; } -// NotifyVirtualSelectedParentChainChangedRequestMessage registers this connection for virtualSelectedParentChainChanged notifications. +// NotifyVirtualChainChangedRequestMessage registers this connection for virtualChainChanged notifications. // -// See: VirtualSelectedParentChainChangedNotificationMessage -message NotifyVirtualSelectedParentChainChangedRequestMessage{ +// See: VirtualChainChangedNotificationMessage +message NotifyVirtualChainChangedRequestMessage { + bool includeAcceptedTransactionIds = 1; + RpcNotifyCommand command = 101; } -message NotifyVirtualSelectedParentChainChangedResponseMessage{ +message NotifyVirtualChainChangedResponseMessage { RPCError error = 1000; } -// VirtualSelectedParentChainChangedNotificationMessage is sent whenever the DAG's selected parent +// VirtualChainChangedNotificationMessage is sent whenever the DAG's selected parent // chain had changed. // -// See: NotifyVirtualSelectedParentChainChangedRequestMessage -message VirtualSelectedParentChainChangedNotificationMessage{ +// See: NotifyVirtualChainChangedRequestMessage +message VirtualChainChangedNotificationMessage { // The chain blocks that were removed, in high-to-low order repeated string removedChainBlockHashes = 1; // The chain blocks that were added, in low-to-high order repeated string addedChainBlockHashes = 3; + + // Will be filled only if `includeAcceptedTransactionIds = true` in the notify request. + repeated RpcAcceptedTransactionIds acceptedTransactionIds = 2; } // GetBlockRequestMessage requests information about a specific block -message GetBlockRequestMessage{ +message GetBlockRequestMessage { // The hash of the requested block string hash = 1; @@ -334,7 +374,7 @@ message GetBlockRequestMessage{ bool includeTransactions = 3; } -message GetBlockResponseMessage{ +message GetBlockResponseMessage { RpcBlock block = 3; RPCError error = 1000; } @@ -342,40 +382,56 @@ message GetBlockResponseMessage{ // GetSubnetworkRequestMessage requests information about a specific subnetwork // // Currently unimplemented -message GetSubnetworkRequestMessage{ +message GetSubnetworkRequestMessage { string subnetworkId = 1; } -message GetSubnetworkResponseMessage{ +message GetSubnetworkResponseMessage { uint64 gasLimit = 1; RPCError error = 1000; } -// GetVirtualSelectedParentChainFromBlockRequestMessage requests the virtual selected -// parent chain from some startHash to this kaspad's current virtual -message GetVirtualSelectedParentChainFromBlockRequestMessage{ +/// GetVirtualChainFromBlockRequestMessage requests the virtual selected +/// parent chain from some startHash to this kaspad's current virtual +/// Note: +/// this call batches the response to: +/// a. the network's `mergeset size limit * 10` amount of added chain blocks, if `includeAcceptedTransactionIds = false` +/// b. or `mergeset size limit * 10` amount of merged blocks, if `includeAcceptedTransactionIds = true` +/// c. it does not batch the removed chain blocks, only the added ones. +message GetVirtualChainFromBlockRequestMessage { string startHash = 1; + bool includeAcceptedTransactionIds = 2; + optional uint64 minConfirmationCount = 3; } -message GetVirtualSelectedParentChainFromBlockResponseMessage{ +message RpcAcceptedTransactionIds { + string acceptingBlockHash = 1; + repeated string acceptedTransactionIds = 2; +} + +message GetVirtualChainFromBlockResponseMessage { // The chain blocks that were removed, in high-to-low order repeated string removedChainBlockHashes = 1; // The chain blocks that were added, in low-to-high order repeated string addedChainBlockHashes = 3; + // The transactions accepted by each block in addedChainBlockHashes. + // Will be filled only if `includeAcceptedTransactionIds = true` in the request. + repeated RpcAcceptedTransactionIds acceptedTransactionIds = 2; + RPCError error = 1000; } // GetBlocksRequestMessage requests blocks between a certain block lowHash up to this // kaspad's current virtual. -message GetBlocksRequestMessage{ +message GetBlocksRequestMessage { string lowHash = 1; bool includeBlocks = 2; bool includeTransactions = 3; } -message GetBlocksResponseMessage{ +message GetBlocksResponseMessage { repeated string blockHashes = 4; repeated RpcBlock blocks = 3; RPCError error = 1000; @@ -383,10 +439,9 @@ message GetBlocksResponseMessage{ // GetBlockCountRequestMessage requests the current number of blocks in this kaspad. // Note that this number may decrease as pruning occurs. -message GetBlockCountRequestMessage{ -} +message GetBlockCountRequestMessage {} -message GetBlockCountResponseMessage{ +message GetBlockCountResponseMessage { uint64 blockCount = 1; uint64 headerCount = 2; RPCError error = 1000; @@ -394,10 +449,9 @@ message GetBlockCountResponseMessage{ // GetBlockDagInfoRequestMessage requests general information about the current state // of this kaspad's DAG. -message GetBlockDagInfoRequestMessage{ -} +message GetBlockDagInfoRequestMessage {} -message GetBlockDagInfoResponseMessage{ +message GetBlockDagInfoResponseMessage { string networkName = 1; uint64 blockCount = 2; uint64 headerCount = 3; @@ -407,49 +461,50 @@ message GetBlockDagInfoResponseMessage{ repeated string virtualParentHashes = 7; string pruningPointHash = 8; uint64 virtualDaaScore = 9; + string sink = 10; RPCError error = 1000; } -message ResolveFinalityConflictRequestMessage{ +message ResolveFinalityConflictRequestMessage { string finalityBlockHash = 1; } -message ResolveFinalityConflictResponseMessage{ +message ResolveFinalityConflictResponseMessage { RPCError error = 1000; } -message NotifyFinalityConflictsRequestMessage{ +message NotifyFinalityConflictRequestMessage { + RpcNotifyCommand command = 101; } -message NotifyFinalityConflictsResponseMessage{ +message NotifyFinalityConflictResponseMessage { RPCError error = 1000; } -message FinalityConflictNotificationMessage{ +message FinalityConflictNotificationMessage { string violatingBlockHash = 1; } -message FinalityConflictResolvedNotificationMessage{ +message FinalityConflictResolvedNotificationMessage { string finalityBlockHash = 1; } -// ShutDownRequestMessage shuts down this kaspad. -message ShutDownRequestMessage{ -} +// ShutdownRequestMessage shuts down this kaspad. +message ShutdownRequestMessage {} -message ShutDownResponseMessage{ +message ShutdownResponseMessage { RPCError error = 1000; } // GetHeadersRequestMessage requests headers between the given startHash and the // current virtual, up to the given limit. -message GetHeadersRequestMessage{ +message GetHeadersRequestMessage { string startHash = 1; uint64 limit = 2; bool isAscending = 3; } -message GetHeadersResponseMessage{ +message GetHeadersResponseMessage { repeated string headers = 1; RPCError error = 1000; } @@ -461,7 +516,10 @@ message GetHeadersResponseMessage{ // // See: UtxosChangedNotificationMessage message NotifyUtxosChangedRequestMessage { + // UTXOs addresses to start/stop getting notified about + // Leave empty to start/stop all updates repeated string addresses = 1; + RpcNotifyCommand command = 101; } message NotifyUtxosChangedResponseMessage { @@ -472,11 +530,11 @@ message NotifyUtxosChangedResponseMessage { // // See: NotifyUtxosChangedRequestMessage message UtxosChangedNotificationMessage { - repeated UtxosByAddressesEntry added = 1; - repeated UtxosByAddressesEntry removed = 2; + repeated RpcUtxosByAddressesEntry added = 1; + repeated RpcUtxosByAddressesEntry removed = 2; } -message UtxosByAddressesEntry { +message RpcUtxosByAddressesEntry { string address = 1; RpcOutpoint outpoint = 2; RpcUtxoEntry utxoEntry = 3; @@ -488,6 +546,9 @@ message UtxosByAddressesEntry { // This call is only available when this kaspad was started with `--utxoindex` // // See: UtxosChangedNotificationMessage +// +// This message only exists for backward compatibility reason with kaspad and is deprecated. +// Use instead UtxosChangedNotificationMessage with command = NOTIFY_STOP. message StopNotifyingUtxosChangedRequestMessage { repeated string addresses = 1; } @@ -504,39 +565,69 @@ message GetUtxosByAddressesRequestMessage { } message GetUtxosByAddressesResponseMessage { - repeated UtxosByAddressesEntry entries = 1; + repeated RpcUtxosByAddressesEntry entries = 1; RPCError error = 1000; } -// GetVirtualSelectedParentBlueScoreRequestMessage requests the blue score of the current selected parent -// of the virtual block. -message GetVirtualSelectedParentBlueScoreRequestMessage { +// GetBalanceByAddressRequest returns the total balance in unspent transactions towards a given address +// +// This call is only available when this kaspad was started with `--utxoindex` +message GetBalanceByAddressRequestMessage { + string address = 1; +} + +message GetBalanceByAddressResponseMessage { + uint64 balance = 1; + + RPCError error = 1000; +} + +message GetBalancesByAddressesRequestMessage { + repeated string addresses = 1; +} + +message RpcBalancesByAddressesEntry { + string address = 1; + uint64 balance = 2; + + RPCError error = 1000; +} + +message GetBalancesByAddressesResponseMessage { + repeated RpcBalancesByAddressesEntry entries = 1; + + RPCError error = 1000; } -message GetVirtualSelectedParentBlueScoreResponseMessage { +// GetSinkBlueScoreRequestMessage requests the blue score of the current selected parent +// of the virtual block. +message GetSinkBlueScoreRequestMessage {} + +message GetSinkBlueScoreResponseMessage { uint64 blueScore = 1; RPCError error = 1000; } -// NotifyVirtualSelectedParentBlueScoreChangedRequestMessage registers this connection for -// virtualSelectedParentBlueScoreChanged notifications. +// NotifySinkBlueScoreChangedRequestMessage registers this connection for +// sinkBlueScoreChanged notifications. // -// See: VirtualSelectedParentBlueScoreChangedNotificationMessage -message NotifyVirtualSelectedParentBlueScoreChangedRequestMessage { +// See: SinkBlueScoreChangedNotificationMessage +message NotifySinkBlueScoreChangedRequestMessage { + RpcNotifyCommand command = 101; } -message NotifyVirtualSelectedParentBlueScoreChangedResponseMessage { +message NotifySinkBlueScoreChangedResponseMessage { RPCError error = 1000; } -// VirtualSelectedParentBlueScoreChangedNotificationMessage is sent whenever the blue score +// SinkBlueScoreChangedNotificationMessage is sent whenever the blue score // of the virtual's selected parent changes. // -// See NotifyVirtualSelectedParentBlueScoreChangedRequestMessage -message VirtualSelectedParentBlueScoreChangedNotificationMessage { - uint64 virtualSelectedParentBlueScore = 1; +// See NotifySinkBlueScoreChangedRequestMessage +message SinkBlueScoreChangedNotificationMessage { + uint64 sinkBlueScore = 1; } // NotifyVirtualDaaScoreChangedRequestMessage registers this connection for @@ -544,6 +635,7 @@ message VirtualSelectedParentBlueScoreChangedNotificationMessage { // // See: VirtualDaaScoreChangedNotificationMessage message NotifyVirtualDaaScoreChangedRequestMessage { + RpcNotifyCommand command = 101; } message NotifyVirtualDaaScoreChangedResponseMessage { @@ -558,75 +650,79 @@ message VirtualDaaScoreChangedNotificationMessage { uint64 virtualDaaScore = 1; } -// NotifyPruningPointUTXOSetOverrideRequestMessage registers this connection for +// NotifyPruningPointUtxoSetOverrideRequestMessage registers this connection for // pruning point UTXO set override notifications. // // This call is only available when this kaspad was started with `--utxoindex` // -// See: NotifyPruningPointUTXOSetOverrideResponseMessage -message NotifyPruningPointUTXOSetOverrideRequestMessage { +// See: NotifyPruningPointUtxoSetOverrideResponseMessage +message NotifyPruningPointUtxoSetOverrideRequestMessage { + RpcNotifyCommand command = 101; } - -message NotifyPruningPointUTXOSetOverrideResponseMessage { +message NotifyPruningPointUtxoSetOverrideResponseMessage { RPCError error = 1000; } -// PruningPointUTXOSetOverrideNotificationMessage is sent whenever the UTXO index +// PruningPointUtxoSetOverrideNotificationMessage is sent whenever the UTXO index // resets due to pruning point change via IBD. // -// See NotifyPruningPointUTXOSetOverrideRequestMessage -message PruningPointUTXOSetOverrideNotificationMessage { -} +// See NotifyPruningPointUtxoSetOverrideRequestMessage +message PruningPointUtxoSetOverrideNotificationMessage {} -// StopNotifyingPruningPointUTXOSetOverrideRequestMessage unregisters this connection for +// StopNotifyingPruningPointUtxoSetOverrideRequestMessage unregisters this connection for // pruning point UTXO set override notifications. // // This call is only available when this kaspad was started with `--utxoindex` // -// See: PruningPointUTXOSetOverrideNotificationMessage -message StopNotifyingPruningPointUTXOSetOverrideRequestMessage { -} +// See: PruningPointUtxoSetOverrideNotificationMessage +// +// This message only exists for backward compatibility reason with kaspad and is deprecated. +// Use instead NotifyPruningPointUtxoSetOverrideRequestMessage with command = NOTIFY_STOP. +message StopNotifyingPruningPointUtxoSetOverrideRequestMessage {} -message StopNotifyingPruningPointUTXOSetOverrideResponseMessage { +message StopNotifyingPruningPointUtxoSetOverrideResponseMessage { RPCError error = 1000; } // BanRequestMessage bans the given ip. -message BanRequestMessage{ +message BanRequestMessage { string ip = 1; } -message BanResponseMessage{ +message BanResponseMessage { RPCError error = 1000; } // UnbanRequestMessage unbans the given ip. -message UnbanRequestMessage{ +message UnbanRequestMessage { string ip = 1; } -message UnbanResponseMessage{ +message UnbanResponseMessage { RPCError error = 1000; } // GetInfoRequestMessage returns info about the node. -message GetInfoRequestMessage{ -} +message GetInfoRequestMessage {} -message GetInfoResponseMessage{ +message GetInfoResponseMessage { string p2pId = 1; uint64 mempoolSize = 2; string serverVersion = 3; + bool isUtxoIndexed = 4; + bool isSynced = 5; + bool hasNotifyCommand = 11; + bool hasMessageId = 12; RPCError error = 1000; } -message EstimateNetworkHashesPerSecondRequestMessage{ +message EstimateNetworkHashesPerSecondRequestMessage { uint32 windowSize = 1; string startHash = 2; } -message EstimateNetworkHashesPerSecondResponseMessage{ +message EstimateNetworkHashesPerSecondResponseMessage { uint64 networkHashesPerSecond = 1; RPCError error = 1000; } @@ -636,6 +732,7 @@ message EstimateNetworkHashesPerSecondResponseMessage{ // // See: NewBlockTemplateNotificationMessage message NotifyNewBlockTemplateRequestMessage { + RpcNotifyCommand command = 101; } message NotifyNewBlockTemplateResponseMessage { @@ -646,7 +743,366 @@ message NotifyNewBlockTemplateResponseMessage { // available for miners. // // See NotifyNewBlockTemplateRequestMessage -message NewBlockTemplateNotificationMessage { +message NewBlockTemplateNotificationMessage {} + +message RpcMempoolEntryByAddress { + string address = 1; + repeated RpcMempoolEntry sending = 2; + repeated RpcMempoolEntry receiving = 3; +} + +message GetMempoolEntriesByAddressesRequestMessage { + repeated string addresses = 1; + bool includeOrphanPool = 2; + bool filterTransactionPool = 3; +} + +message GetMempoolEntriesByAddressesResponseMessage { + repeated RpcMempoolEntryByAddress entries = 1; + + RPCError error = 1000; +} + +message GetCoinSupplyRequestMessage {} + +message GetCoinSupplyResponseMessage { + uint64 maxSompi = 1; // note: this is a hard coded maxSupply, actual maxSupply is expected to deviate by upto -5%, but cannot be measured exactly. + uint64 circulatingSompi = 2; + + RPCError error = 1000; +} + +message PingRequestMessage {} + +message PingResponseMessage { + RPCError error = 1000; +} + +message ProcessMetrics { + uint64 residentSetSize = 1; + uint64 virtualMemorySize = 2; + uint32 coreNum = 3; + float cpuUsage = 4; + uint32 fdNum = 5; + uint64 diskIoReadBytes = 6; + uint64 diskIoWriteBytes = 7; + float diskIoReadPerSec = 8; + float diskIoWritePerSec = 9; +} + +message ConnectionMetrics { + uint32 borshLiveConnections = 31; + uint64 borshConnectionAttempts = 32; + uint64 borshHandshakeFailures = 33; + + uint32 jsonLiveConnections = 41; + uint64 jsonConnectionAttempts = 42; + uint64 jsonHandshakeFailures = 43; + + uint32 activePeers = 51; +} + +message BandwidthMetrics { + uint64 borshBytesTx = 61; + uint64 borshBytesRx = 62; + uint64 jsonBytesTx = 63; + uint64 jsonBytesRx = 64; + uint64 grpcP2pBytesTx = 65; + uint64 grpcP2pBytesRx = 66; + uint64 grpcUserBytesTx = 67; + uint64 grpcUserBytesRx = 68; +} + +message ConsensusMetrics { + uint64 blocksSubmitted = 1; + uint64 headerCounts = 2; + uint64 depCounts = 3; + uint64 bodyCounts = 4; + uint64 txsCounts = 5; + uint64 chainBlockCounts = 6; + uint64 massCounts = 7; + + uint64 blockCount = 11; + uint64 headerCount = 12; + uint64 mempoolSize = 13; + uint32 tipHashesCount = 14; + double difficulty = 15; + uint64 pastMedianTime = 16; + uint32 virtualParentHashesCount = 17; + uint64 virtualDaaScore = 18; +} + +message StorageMetrics { + uint64 storageSizeBytes = 1; +} + +message GetConnectionsRequestMessage { + bool includeProfileData = 1; +} + +message ConnectionsProfileData { + double cpuUsage = 1; + uint64 memoryUsage = 2; +} + +message GetConnectionsResponseMessage { + uint32 clients = 1; + uint32 peers = 2; + ConnectionsProfileData profileData = 3; + RPCError error = 1000; +} + +message GetSystemInfoRequestMessage {} + +message GetSystemInfoResponseMessage { + string version = 1; + string systemId = 2; + string gitHash = 3; + uint32 coreNum = 4; + uint64 totalMemory = 5; + uint32 fdLimit = 6; + uint32 proxySocketLimitPerCpuCore = 7; + RPCError error = 1000; +} + +message GetMetricsRequestMessage { + bool processMetrics = 1; + bool connectionMetrics = 2; + bool bandwidthMetrics = 3; + bool consensusMetrics = 4; + bool storageMetrics = 5; + bool customMetrics = 6; +} + +message GetMetricsResponseMessage { + uint64 serverTime = 1; + ProcessMetrics processMetrics = 11; + ConnectionMetrics connectionMetrics = 12; + BandwidthMetrics bandwidthMetrics = 13; + ConsensusMetrics consensusMetrics = 14; + StorageMetrics storageMetrics = 15; + RPCError error = 1000; +} + +message GetServerInfoRequestMessage {} + +message GetServerInfoResponseMessage { + uint32 rpcApiVersion = 1; + uint32 rpcApiRevision = 2; + string serverVersion = 3; + string networkId = 4; + bool hasUtxoIndex = 5; + bool isSynced = 6; + uint64 virtualDaaScore = 7; + RPCError error = 1000; +} + +message GetSyncStatusRequestMessage {} + +message GetSyncStatusResponseMessage { + bool isSynced = 1; + RPCError error = 1000; +} + +message GetDaaScoreTimestampEstimateRequestMessage { + repeated uint64 daaScores = 1; +} + +message GetDaaScoreTimestampEstimateResponseMessage { + repeated uint64 timestamps = 1; + RPCError error = 1000; +} + +message RpcFeerateBucket { + // Fee/mass of a transaction in `sompi/gram` units + double feerate = 1; + double estimatedSeconds = 2; +} + +// Data required for making fee estimates. +// +// Feerate values represent fee/mass of a transaction in `sompi/gram` units. +// Given a feerate value recommendation, calculate the required fee by +// taking the transaction mass and multiplying it by feerate: `fee = feerate * mass(tx)` +message RpcFeeEstimate { + // Top-priority feerate bucket. Provides an estimation of the feerate required for sub-second DAG inclusion. + RpcFeerateBucket priorityBucket = 1; + + // A vector of *normal* priority feerate values. The first value of this vector is guaranteed to exist and + // provide an estimation for sub-*minute* DAG inclusion. All other values will have shorter estimation + // times than all `lowBucket` values. Therefor by chaining `[priority] | normal | low` and interpolating + // between them, one can compose a complete feerate function on the client side. The API makes an effort + // to sample enough "interesting" points on the feerate-to-time curve, so that the interpolation is meaningful. + repeated RpcFeerateBucket normalBuckets = 2; + + // A vector of *low* priority feerate values. The first value of this vector is guaranteed to + // exist and provide an estimation for sub-*hour* DAG inclusion. + repeated RpcFeerateBucket lowBuckets = 3; +} + +message RpcFeeEstimateVerboseExperimentalData { + uint64 mempoolReadyTransactionsCount = 1; + uint64 mempoolReadyTransactionsTotalMass = 2; + uint64 networkMassPerSecond = 3; + + double nextBlockTemplateFeerateMin = 11; + double nextBlockTemplateFeerateMedian = 12; + double nextBlockTemplateFeerateMax = 13; +} + +message GetFeeEstimateRequestMessage {} + +message GetFeeEstimateResponseMessage { + RpcFeeEstimate estimate = 1; + RPCError error = 1000; } +message GetFeeEstimateExperimentalRequestMessage { + bool verbose = 1; +} + +message GetFeeEstimateExperimentalResponseMessage { + RpcFeeEstimate estimate = 1; + RpcFeeEstimateVerboseExperimentalData verbose = 2; + + RPCError error = 1000; +} + +message GetUtxoReturnAddressRequestMessage { + string txid = 1; + uint64 accepting_block_daa_score = 2; +} + +message GetUtxoReturnAddressResponseMessage { + string return_address = 1; + RPCError error = 1000; +} + +// ### messages for vspc v2 ### + +enum RpcDataVerbosityLevel { + NONE = 0; + LOW = 1; + HIGH = 2; + FULL = 3; +} + +message RpcOptionalHeader { + optional string hash = 2; + optional uint32 version = 3; + repeated RpcBlockLevelRun parentsByLevel = 4; + optional string hashMerkleRoot = 5; + optional string acceptedIdMerkleRoot = 6; + optional string utxoCommitment = 7; + optional int64 timestamp = 8; + optional uint32 bits = 9; + optional uint64 nonce = 10; + optional uint64 daaScore = 11; + optional string blueWork = 12; + optional uint64 blueScore = 13; + optional string pruningPoint = 14; +} + +message RpcOptionalTransactionOutpoint { + optional string transactionId = 2; + optional uint32 index = 3; +} + +message RpcOptionalUtxoEntryVerboseData { + optional string scriptPublicKeyType = 2; + optional string scriptPublicKeyAddress = 3; +} + +message RpcOptionalUtxoEntry { + optional uint64 amount = 2; + optional RpcScriptPublicKey scriptPublicKey = 3; + optional uint64 blockDaaScore = 4; + optional bool isCoinbase = 5; + optional RpcOptionalUtxoEntryVerboseData verboseData = 6; + optional string CovenantId = 7; +} + +message RpcOptionalTransactionInputVerboseData { + optional RpcOptionalUtxoEntry utxoEntry = 2; +} + +message RpcOptionalTransactionInput { + optional RpcOptionalTransactionOutpoint previousOutpoint = 2; + optional string signatureScript = 3; + optional uint64 sequence = 4; + optional uint32 sigOpCount = 5; + optional RpcOptionalTransactionInputVerboseData verboseData = 6; +} + +message RpcOptionalTransactionOutputVerboseData { + optional string scriptPublicKeyType = 2; + optional string scriptPublicKeyAddress = 3; +} + +message RpcNullableCovenantBinding { + optional RpcCovenantBinding covenant = 1; +} + +message RpcOptionalTransactionOutput { + optional uint64 value = 2; + optional RpcScriptPublicKey scriptPublicKey = 3; + optional RpcOptionalTransactionOutputVerboseData verboseData = 4; + optional RpcNullableCovenantBinding covenant = 5; +} + +message RpcOptionalTransactionVerboseData { + optional string transactionId = 2; + optional string hash = 3; + optional uint64 computeMass = 4; + optional string blockHash = 5; + optional uint64 blockTime = 6; +} + +message RpcOptionalTransaction { + optional uint32 version = 2; + repeated RpcOptionalTransactionInput inputs = 3; + repeated RpcOptionalTransactionOutput outputs = 4; + optional uint64 lockTime = 5; + optional string subnetworkId = 6; + optional uint64 gas = 7; + optional string payload = 8; + optional uint64 mass = 9; + optional RpcOptionalTransactionVerboseData verboseData = 10; +} + +message RpcChainBlockAcceptedTransactions { + RpcOptionalHeader chainBlockHeader = 2; + repeated RpcOptionalTransaction acceptedTransactions = 3; +} + +/// GetVirtualChainFromBlockV2RequestMessage requests the virtual selected +/// parent chain from some startHash to this kaspad's current virtual +message GetVirtualChainFromBlockV2RequestMessage { + string startHash = 1; + + optional RpcDataVerbosityLevel dataVerbosityLevel = 2; + optional uint64 minConfirmationCount = 3; +} + +message GetVirtualChainFromBlockV2ResponseMessage { + // The chain blocks that were removed, in high-to-low order + repeated string removedChainBlockHashes = 1; + + // The chain blocks that were added, in low-to-high order + repeated string addedChainBlockHashes = 2; + + // Will be filled depending on the supplied RpcDataVerbosityLevel. + repeated RpcChainBlockAcceptedTransactions chainBlockAcceptedTransactions = 3; + + RPCError error = 1000; +} + +message GetCurrentBlockColorRequestMessage { + string hash = 1; +} +message GetCurrentBlockColorResponseMessage { + bool blue = 1; + + RPCError error = 1000; +} diff --git a/src/cli.rs b/src/cli.rs index 9aa92e4..a968bc4 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -36,7 +36,7 @@ pub struct Opt { /// Amount of miner threads to launch [default: number of logical cpus] pub num_threads: Option, #[clap(long = "mine-when-not-synced", display_order = 8)] - /// Mine even when kaspad says it is not synced, only useful when passing `--allow-submit-block-when-not-synced` to kaspad [default: false] + /// Mine even when kaspad says it is not synced, only useful when passing `--enable-unsynced-mining` to kaspad [default: false] pub mine_when_not_synced: bool, #[clap(long = "throttle", display_order = 9)] /// Throttle (milliseconds) between each pow hash generation (used for development testing) diff --git a/src/client.rs b/src/client.rs index f0ff633..f7aad09 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,8 +1,8 @@ use crate::{ miner::MinerManager, proto::{ - kaspad_message::Payload, rpc_client::RpcClient, GetBlockTemplateRequestMessage, GetInfoRequestMessage, - KaspadMessage, + kaspad_response::Payload as ResponsePayload, rpc_client::RpcClient, GetBlockTemplateRequestMessage, + GetInfoRequestMessage, KaspadRequest, KaspadResponse, }, Error, ShutdownHandler, }; @@ -16,8 +16,8 @@ static EXTRA_DATA: &str = concat!(env!("CARGO_PKG_VERSION")); #[allow(dead_code)] pub struct KaspadHandler { client: RpcClient, - pub send_channel: Sender, - stream: Streaming, + pub send_channel: Sender, + stream: Streaming, miner_address: String, mine_when_not_synced: bool, devfund_address: Option, @@ -58,11 +58,11 @@ impl KaspadHandler { self.devfund_percent = percent; } - pub async fn client_send(&self, msg: impl Into) -> Result<(), SendError> { + pub async fn client_send(&self, msg: impl Into) -> Result<(), SendError> { self.send_channel.send(msg.into()).await } - pub async fn client_get_block_template(&mut self) -> Result<(), SendError> { + pub async fn client_get_block_template(&mut self) -> Result<(), SendError> { let pay_address = match &self.devfund_address { Some(devfund_address) if (self.block_template_ctr % 10_000) as u16 <= self.devfund_percent => { devfund_address.clone() @@ -86,28 +86,32 @@ impl KaspadHandler { Ok(()) } - async fn handle_message(&mut self, msg: Payload, miner: &mut MinerManager) -> Result<(), Error> { + async fn handle_message(&mut self, msg: ResponsePayload, miner: &mut MinerManager) -> Result<(), Error> { match msg { - Payload::NewBlockTemplateNotification(_) => self.client_get_block_template().await?, - Payload::GetBlockTemplateResponse(template) => match (template.block, template.is_synced, template.error) { - (Some(b), true, None) => miner.process_block(Some(b))?, - (Some(b), false, None) if self.mine_when_not_synced => miner.process_block(Some(b))?, - (_, false, None) => miner.process_block(None)?, - (_, _, Some(e)) => warn!("GetTemplate returned with an error: {:?}", e), - (None, true, None) => error!("No block and No Error!"), - }, - Payload::SubmitBlockResponse(res) => match res.error { + ResponsePayload::NewBlockTemplateNotification(_) => self.client_get_block_template().await?, + ResponsePayload::GetBlockTemplateResponse(template) => { + match (template.block, template.is_synced, template.error) { + (Some(b), true, None) => miner.process_block(Some(b))?, + (Some(b), false, None) if self.mine_when_not_synced => miner.process_block(Some(b))?, + (_, false, None) => miner.process_block(None)?, + (_, _, Some(e)) => warn!("GetTemplate returned with an error: {:?}", e), + (None, true, None) => error!("No block and No Error!"), + } + } + ResponsePayload::SubmitBlockResponse(res) => match res.error { None => info!("Block submitted successfully!"), Some(e) => warn!("Failed submitting block: {:?}", e), }, - Payload::GetBlockResponse(msg) => { + ResponsePayload::GetBlockResponse(msg) => { if let Some(e) = msg.error { return Err(e.message.into()); } info!("Get block response: {:?}", msg); } - Payload::GetInfoResponse(info) => info!("Kaspad version: {}", info.server_version), - Payload::NotifyNewBlockTemplateResponse(res) => match res.error { + ResponsePayload::GetInfoResponse(info) => { + info!("Kaspad: {} Synced: {}", info.server_version, info.is_synced) + } + ResponsePayload::NotifyNewBlockTemplateResponse(res) => match res.error { None => info!("Registered for new template notifications"), Some(e) => error!("Failed registering for new template notifications: {:?}", e), }, diff --git a/src/kaspad_messages.rs b/src/kaspad_messages.rs index 21b580c..9536e3d 100644 --- a/src/kaspad_messages.rs +++ b/src/kaspad_messages.rs @@ -1,27 +1,36 @@ use crate::{ pow::{self, HeaderHasher}, proto::{ - kaspad_message::Payload, GetBlockTemplateRequestMessage, GetInfoRequestMessage, KaspadMessage, - NotifyBlockAddedRequestMessage, NotifyNewBlockTemplateRequestMessage, RpcBlock, SubmitBlockRequestMessage, + kaspad_request::Payload, GetBlockTemplateRequestMessage, GetInfoRequestMessage, KaspadRequest, + NotifyBlockAddedRequestMessage, NotifyNewBlockTemplateRequestMessage, RpcBlock, RpcNotifyCommand, + SubmitBlockRequestMessage, }, Hash, }; -impl KaspadMessage { +impl KaspadRequest { #[must_use] #[inline(always)] pub fn get_info_request() -> Self { - KaspadMessage { payload: Some(Payload::GetInfoRequest(GetInfoRequestMessage {})) } + KaspadRequest { id: 1063, payload: Some(Payload::GetInfoRequest(GetInfoRequestMessage {})) } } + #[must_use] #[inline(always)] pub fn notify_block_added() -> Self { - KaspadMessage { payload: Some(Payload::NotifyBlockAddedRequest(NotifyBlockAddedRequestMessage {})) } + KaspadRequest { + id: 1007, + payload: Some(Payload::NotifyBlockAddedRequest(NotifyBlockAddedRequestMessage { + command: RpcNotifyCommand::NotifyStart as i32, + })), + } } + #[must_use] #[inline(always)] pub fn submit_block(block: RpcBlock) -> Self { - KaspadMessage { + KaspadRequest { + id: 1003, payload: Some(Payload::SubmitBlockRequest(SubmitBlockRequestMessage { block: Some(block), allow_non_daa_blocks: false, @@ -30,29 +39,31 @@ impl KaspadMessage { } } -impl From for KaspadMessage { +impl From for KaspadRequest { #[inline(always)] fn from(a: GetInfoRequestMessage) -> Self { - KaspadMessage { payload: Some(Payload::GetInfoRequest(a)) } + KaspadRequest { id: 1063, payload: Some(Payload::GetInfoRequest(a)) } } } -impl From for KaspadMessage { + +impl From for KaspadRequest { #[inline(always)] fn from(a: NotifyBlockAddedRequestMessage) -> Self { - KaspadMessage { payload: Some(Payload::NotifyBlockAddedRequest(a)) } + KaspadRequest { id: 1007, payload: Some(Payload::NotifyBlockAddedRequest(a)) } } } -impl From for KaspadMessage { +impl From for KaspadRequest { #[inline(always)] fn from(a: GetBlockTemplateRequestMessage) -> Self { - KaspadMessage { payload: Some(Payload::GetBlockTemplateRequest(a)) } + KaspadRequest { id: 1005, payload: Some(Payload::GetBlockTemplateRequest(a)) } } } -impl From for KaspadMessage { +impl From for KaspadRequest { + #[inline(always)] fn from(a: NotifyNewBlockTemplateRequestMessage) -> Self { - KaspadMessage { payload: Some(Payload::NotifyNewBlockTemplateRequest(a)) } + KaspadRequest { id: 1081, payload: Some(Payload::NotifyNewBlockTemplateRequest(a)) } } } diff --git a/src/main.rs b/src/main.rs index c99ec46..c56f3c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,8 @@ use std::{ }; use crate::{ - cli::Opt, client::KaspadHandler, miner::MinerManager, proto::NotifyNewBlockTemplateRequestMessage, target::Uint256, + cli::Opt, client::KaspadHandler, miner::MinerManager, proto::NotifyNewBlockTemplateRequestMessage, + proto::RpcNotifyCommand, target::Uint256, }; mod cli; @@ -89,7 +90,9 @@ async fn main() -> Result<(), Error> { devfund_address ); } - client.client_send(NotifyNewBlockTemplateRequestMessage {}).await?; + client + .client_send(NotifyNewBlockTemplateRequestMessage { command: RpcNotifyCommand::NotifyStart as i32 }) + .await?; client.client_get_block_template().await?; let mut miner_manager = diff --git a/src/miner.rs b/src/miner.rs index 09e0176..ab4eae1 100644 --- a/src/miner.rs +++ b/src/miner.rs @@ -1,6 +1,6 @@ use crate::{ pow, - proto::{KaspadMessage, RpcBlock}, + proto::{KaspadRequest, RpcBlock}, swap_rust::WatchSwap, Error, ShutdownHandler, }; @@ -26,7 +26,7 @@ type MinerHandler = std::thread::JoinHandle>; pub struct MinerManager { handles: Vec, block_channel: WatchSwap, - send_channel: Sender, + send_channel: Sender, logger_handle: JoinHandle<()>, is_synced: bool, hashes_tried: Arc, @@ -49,7 +49,7 @@ const LOG_RATE: Duration = Duration::from_secs(10); impl MinerManager { pub fn new( - send_channel: Sender, + send_channel: Sender, n_cpus: Option, throttle: Option, shutdown: ShutdownHandler, @@ -78,7 +78,7 @@ impl MinerManager { } fn launch_cpu_threads( - send_channel: Sender, + send_channel: Sender, hashes_tried: Arc, work_channel: WatchSwap, shutdown: ShutdownHandler, @@ -118,7 +118,7 @@ impl MinerManager { } pub fn launch_cpu_miner( - send_channel: Sender, + send_channel: Sender, mut block_channel: WatchSwap, hashes_tried: Arc, throttle: Option, @@ -126,9 +126,9 @@ impl MinerManager { ) -> MinerHandler { // We mark it cold as the function is not called often, and it's not in the hot path #[cold] - fn found_block(send_channel: &Sender, block: RpcBlock) -> Result<(), Error> { + fn found_block(send_channel: &Sender, block: RpcBlock) -> Result<(), Error> { let block_hash = block.block_hash().expect("We just got it from the state, we should be able to hash it"); - send_channel.blocking_send(KaspadMessage::submit_block(block))?; + send_channel.blocking_send(KaspadRequest::submit_block(block))?; info!("Found a block: {:x}", block_hash); Ok(()) } diff --git a/src/pow.rs b/src/pow.rs index 6de24cd..651cd6e 100644 --- a/src/pow.rs +++ b/src/pow.rs @@ -171,6 +171,7 @@ mod tests { fn test_serialize_header() { let header = RpcBlockHeader { version: 24565, + hash: "0000000000000000000000000000000000000000000000000000000000000000".into(), parents: vec![ RpcBlockLevelParents { parent_hashes: vec![