stasatdaglabs 7dd0188838
Move the heavy lifting in BlockLocator from the syncer to the syncee (#1324)
* Add a new message: BlockLocatorHighestHash.

* Add a new message: IBDBlockLocator.

* Implement HandleIBDBlockLocator.

* Reimplement findHighestSharedBlockHash.

* Make HandleIBDBlockLocator only return hashes that are in the selected parent chain of the target hash.

* Increase the cache sizes of blockRelationStore, reachabilityDataStore, and ghostdagDataStore.

* Fix wrong initial highHash in findHighestSharedBlockHash.

* Make go vet happy.

* Protect against receiving wrong messages when expecting MsgIBDBlockLocatorHighestHash.
2020-12-30 15:44:14 +02:00

742 lines
19 KiB
Protocol Buffer

syntax = "proto3";
package protowire;
option go_package = "github.com/kaspanet/kaspad/protowire";
message KaspadMessage {
oneof payload {
AddressesMessage addresses = 1;
BlockMessage block = 2;
TransactionMessage transaction = 3;
RequestBlockLocatorMessage requestBlockLocator = 4;
BlockLocatorMessage blockLocator = 5;
RequestAddressesMessage requestAddresses = 6;
RequestHeadersMessage requestHeaders = 7;
RequestNextHeadersMessage requestNextHeaders = 8;
DoneHeadersMessage DoneHeaders = 9;
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;
BlockHeaderMessage blockHeader = 23;
RequestIBDRootUTXOSetAndBlockMessage requestIBDRootUTXOSetAndBlock = 24;
IBDRootUTXOSetAndBlockMessage ibdRootUTXOSetAndBlock = 25;
RequestIBDBlocksMessage requestIBDBlocks = 26;
IBDRootNotFoundMessage ibdRootNotFound = 27;
RequestIBDRootHashMessage requestIBDRootHash = 28;
IBDRootHashMessage ibdRootHash = 29;
IbdBlockLocatorMessage ibdBlockLocator = 30;
IbdBlockLocatorHighestHashMessage ibdBlockLocatorHighestHash = 31;
GetCurrentNetworkRequestMessage getCurrentNetworkRequest = 1001;
GetCurrentNetworkResponseMessage getCurrentNetworkResponse = 1002;
SubmitBlockRequestMessage submitBlockRequest = 1003;
SubmitBlockResponseMessage submitBlockResponse = 1004;
GetBlockTemplateRequestMessage getBlockTemplateRequest = 1005;
GetBlockTemplateResponseMessage getBlockTemplateResponse = 1006;
NotifyBlockAddedRequestMessage notifyBlockAddedRequest = 1007;
NotifyBlockAddedResponseMessage notifyBlockAddedResponse = 1008;
BlockAddedNotificationMessage blockAddedNotification = 1009;
GetPeerAddressesRequestMessage getPeerAddressesRequest = 1010;
GetPeerAddressesResponseMessage getPeerAddressesResponse = 1011;
GetSelectedTipHashRequestMessage getSelectedTipHashRequest = 1012;
GetSelectedTipHashResponseMessage getSelectedTipHashResponse = 1013;
GetMempoolEntryRequestMessage getMempoolEntryRequest = 1014;
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;
GetBlockResponseMessage getBlockResponse = 1026;
GetSubnetworkRequestMessage getSubnetworkRequest = 1027;
GetSubnetworkResponseMessage getSubnetworkResponse = 1028;
GetVirtualSelectedParentChainFromBlockRequestMessage getVirtualSelectedParentChainFromBlockRequest = 1029;
GetVirtualSelectedParentChainFromBlockResponseMessage getVirtualSelectedParentChainFromBlockResponse = 1030;
GetBlocksRequestMessage getBlocksRequest = 1031;
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;
FinalityConflictNotificationMessage finalityConflictNotification = 1041;
FinalityConflictResolvedNotificationMessage finalityConflictResolvedNotification = 1042;
GetMempoolEntriesRequestMessage getMempoolEntriesRequest = 1043;
GetMempoolEntriesResponseMessage getMempoolEntriesResponse = 1044;
ShutDownRequestMessage shutDownRequest = 1045;
ShutDownResponseMessage shutDownResponse = 1046;
GetHeadersRequestMessage getHeadersRequest = 1047;
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;
}
}
/////////////////////////////////////////////////////////////////////////////
// P2P //
/////////////////////////////////////////////////////////////////////////////
// RequestAddressesMessage start
message RequestAddressesMessage{
bool includeAllSubnetworks = 1;
SubnetworkId subnetworkId = 2;
}
// RequestAddressesMessage end
// AddressesMessage start
message AddressesMessage{
repeated NetAddress addressList = 1;
}
message NetAddress{
int64 timestamp = 1;
uint64 services = 2;
bytes ip = 3;
uint32 port = 4;
}
message SubnetworkId{
bytes bytes = 1;
}
// AddressesMessage end
// TransactionMessage start
message TransactionMessage{
int32 version = 1;
repeated TransactionInput inputs = 2;
repeated TransactionOutput outputs = 3;
uint64 lockTime = 4;
SubnetworkId subnetworkId = 5;
uint64 gas = 6;
Hash payloadHash = 7;
bytes payload = 8;
}
message TransactionInput{
Outpoint previousOutpoint = 1;
bytes signatureScript = 2;
uint64 sequence = 3;
}
message Outpoint{
TransactionId transactionId = 1;
uint32 index = 2;
}
message TransactionId{
bytes bytes = 1;
}
message TransactionOutput{
uint64 value = 1;
bytes scriptPubKey = 2;
}
// TransactionMessage end
// BlockMessage start
message BlockMessage{
BlockHeaderMessage header = 1;
repeated TransactionMessage transactions = 2;
}
message BlockHeaderMessage{
int32 version = 1;
repeated Hash parentHashes = 2;
Hash hashMerkleRoot = 3;
Hash acceptedIdMerkleRoot = 4;
Hash utxoCommitment = 5;
int64 timestamp = 6;
uint32 bits = 7;
uint64 nonce = 8;
}
message Hash{
bytes bytes = 1;
}
// BlockMessage end
// GetBlockLocatorMessage start
message RequestBlockLocatorMessage{
Hash lowHash = 1;
Hash highHash = 2;
uint32 limit = 3;
}
// GetBlockLocatorMessage end
// BlockLocatorMessage start
message BlockLocatorMessage{
repeated Hash hashes = 1;
}
// BlockLocatorMessage end
// GetBlocksMessage start
message RequestHeadersMessage{
Hash lowHash = 1;
Hash highHash = 2;
}
// GetBlocksMessage end
// RequestNextIBDBlocksMessage start
message RequestNextHeadersMessage{
}
// RequestNextIBDBlocksMessage end
// DoneIBDBlocksMessage start
message DoneHeadersMessage{
}
// DoneIBDBlocksMessage end
// RequestRelayBlocksMessage start
message RequestRelayBlocksMessage{
repeated Hash hashes = 1;
}
// RequestRelayBlocksMessage end
// RequestTransactionsMessage start
message RequestTransactionsMessage {
repeated TransactionId ids = 1;
}
// GetTransactionsMessage end
// TransactionNotFoundMessage start
message TransactionNotFoundMessage{
TransactionId id = 1;
}
// TransactionsNotFoundMessage end
// InvRelayBlockMessage start
message InvRelayBlockMessage{
Hash hash = 1;
}
// InvRelayBlockMessage end
// InvTransactionMessage start
message InvTransactionsMessage{
repeated TransactionId ids = 1;
}
// InvTransactionMessage end
// PingMessage start
message PingMessage{
uint64 nonce = 1;
}
// PingMessage end
// PongMessage start
message PongMessage{
uint64 nonce = 1;
}
// PongMessage end
// VerackMessage start
message VerackMessage{
}
// VerackMessage end
// VersionMessage start
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;
}
// VersionMessage end
// RejectMessage start
message RejectMessage{
string reason = 1;
}
// RejectMessage end
// RequestIBDRootUTXOSetAndBlockMessage start
message RequestIBDRootUTXOSetAndBlockMessage{
Hash ibdRoot = 1;
}
// RequestIBDRootUTXOSetAndBlockMessage end
// IBDRootUTXOSetAndBlockMessage start
message IBDRootUTXOSetAndBlockMessage{
bytes utxoSet = 1;
BlockMessage block = 2;
}
// IBDRootUTXOSetAndBlockMessage end
// RequestIBDBlocksMessage start
message RequestIBDBlocksMessage{
repeated Hash hashes = 1;
}
// RequestIBDBlocksMessage end
// IBDRootNotFoundMessage start
message IBDRootNotFoundMessage{
}
// IBDRootNotFoundMessage end
// RequestIBDRootHashMessage start
message RequestIBDRootHashMessage{
}
// RequestIBDRootHashMessage end
// IBDRootHashMessage start
message IBDRootHashMessage{
Hash hash = 1;
}
// IBDRootHashMessage end
// IbdBlockLocatorMessage start
message IbdBlockLocatorMessage {
Hash targetHash = 1;
repeated Hash blockLocatorHashes = 2;
}
// IbdBlockLocatorMessage end
// IbdBlockLocatorHighestHashMessage start
message IbdBlockLocatorHighestHashMessage {
Hash highestHash = 1;
}
// IbdBlockLocatorHighestHashMessage end
service P2P {
rpc MessageStream (stream KaspadMessage) returns (stream KaspadMessage) {}
}
/////////////////////////////////////////////////////////////////////////////
// RPC //
/////////////////////////////////////////////////////////////////////////////
message RPCError{
string message = 1;
}
message GetCurrentNetworkRequestMessage{
}
message GetCurrentNetworkResponseMessage{
string currentNetwork = 1;
RPCError error = 1000;
}
message SubmitBlockRequestMessage{
BlockMessage block = 1;
}
message SubmitBlockResponseMessage{
RPCError error = 1000;
}
message GetBlockTemplateRequestMessage{
string payAddress = 1;
}
message GetBlockTemplateResponseMessage{
BlockMessage blockMessage = 1;
bool isSynced = 2;
RPCError error = 1000;
}
message NotifyBlockAddedRequestMessage{
}
message NotifyBlockAddedResponseMessage{
RPCError error = 1000;
}
message BlockAddedNotificationMessage{
BlockMessage block = 1;
}
message GetPeerAddressesRequestMessage{
}
message GetPeerAddressesResponseMessage{
repeated GetPeerAddressesKnownAddressMessage addresses = 1;
repeated GetPeerAddressesKnownAddressMessage bannedAddresses = 2;
RPCError error = 1000;
}
message GetPeerAddressesKnownAddressMessage {
string Addr = 1;
}
message GetSelectedTipHashRequestMessage{
}
message GetSelectedTipHashResponseMessage{
string selectedTipHash = 1;
RPCError error = 1000;
}
// mempool entries start
message MempoolEntry{
uint64 fee = 1;
TransactionVerboseData transactionVerboseData = 2;
}
message GetMempoolEntryRequestMessage{
string txId = 1;
}
message GetMempoolEntryResponseMessage{
MempoolEntry entry = 1;
RPCError error = 1000;
}
message GetMempoolEntriesRequestMessage{
}
message GetMempoolEntriesResponseMessage{
repeated MempoolEntry entries = 1;
RPCError error = 1000;
}
// mempool entries end
message GetConnectedPeerInfoRequestMessage{
}
message GetConnectedPeerInfoResponseMessage{
repeated GetConnectedPeerInfoMessage infos = 1;
RPCError error = 1000;
}
message GetConnectedPeerInfoMessage{
string id = 1;
string address = 2;
int64 lastPingDuration = 3;
bool isOutbound = 6;
int64 timeOffset = 7;
string userAgent = 8;
uint32 advertisedProtocolVersion = 9;
int64 timeConnected = 10;
}
message AddPeerRequestMessage{
string address = 1;
bool isPermanent = 2;
}
message AddPeerResponseMessage{
RPCError error = 1000;
}
message SubmitTransactionRequestMessage{
RpcTransaction transaction = 1;
}
message SubmitTransactionResponseMessage{
string transactionId = 1;
RPCError error = 1000;
}
message NotifyVirtualSelectedParentChainChangedRequestMessage{
}
message NotifyVirtualSelectedParentChainChangedResponseMessage{
RPCError error = 1000;
}
message VirtualSelectedParentChainChangedNotificationMessage{
repeated string removedChainBlockHashes = 1;
repeated ChainBlock addedChainBlocks = 2;
}
message ChainBlock{
string hash = 1;
repeated AcceptedBlock acceptedBlocks = 2;
}
message AcceptedBlock{
string hash = 1;
repeated string acceptedTransactionIds = 2;
}
message GetBlockRequestMessage{
string hash = 1;
string subnetworkId = 2;
bool includeTransactionVerboseData = 3;
}
message GetBlockResponseMessage{
string blockHash = 1;
BlockVerboseData blockVerboseData = 2;
RPCError error = 1000;
}
message BlockVerboseData{
string hash = 1;
int32 version = 2;
string versionHex = 3;
string hashMerkleRoot = 4;
string acceptedIDMerkleRoot = 5;
string utxoCommitment = 6;
repeated TransactionVerboseData transactionVerboseData = 7;
int64 time = 8;
uint64 nonce = 9;
string bits = 10;
double difficulty = 11;
repeated string parentHashes = 12;
string selectedParentHash = 13;
repeated string transactionIDs = 14;
bool isHeaderOnly = 15;
uint64 blueScore = 16;
}
message TransactionVerboseData{
string txId = 1;
string hash = 2;
uint64 size = 3;
int32 version = 4;
uint64 lockTime = 5;
string subnetworkId = 6;
uint64 gas = 7;
string payloadHash = 8;
string payload = 9;
repeated TransactionVerboseInput transactionVerboseInputs = 10;
repeated TransactionVerboseOutput transactionVerboseOutputs = 11;
string blockHash = 12;
uint64 time = 13;
uint64 blockTime = 14;
}
message TransactionVerboseInput{
string txId = 1;
uint32 outputIndex = 2;
ScriptSig scriptSig = 3;
uint64 sequence = 4;
}
message ScriptSig{
string asm = 1;
string hex = 2;
}
message TransactionVerboseOutput{
uint64 value = 1;
uint32 index = 2;
ScriptPubKeyResult scriptPubKey = 3;
}
message ScriptPubKeyResult{
string asm = 1;
string hex = 2;
string type = 3;
string address = 4;
}
message GetSubnetworkRequestMessage{
string subnetworkId = 1;
}
message GetSubnetworkResponseMessage{
uint64 gasLimit = 1;
RPCError error = 1000;
}
message GetVirtualSelectedParentChainFromBlockRequestMessage{
string startHash = 1;
}
message GetVirtualSelectedParentChainFromBlockResponseMessage{
repeated string removedChainBlockHashes = 1;
repeated ChainBlock addedChainBlocks = 2;
RPCError error = 1000;
}
message GetBlocksRequestMessage{
string lowHash = 1;
bool includeBlockHexes = 2;
bool includeBlockVerboseData = 3;
bool includeTransactionVerboseData = 4;
}
message GetBlocksResponseMessage{
repeated string blockHashes = 1;
repeated string blockHexes = 2;
repeated BlockVerboseData blockVerboseData = 3;
RPCError error = 1000;
}
message GetBlockCountRequestMessage{
}
message GetBlockCountResponseMessage{
uint64 blockCount = 1;
uint64 headerCount = 2;
RPCError error = 1000;
}
message GetBlockDagInfoRequestMessage{
}
message GetBlockDagInfoResponseMessage{
string networkName = 1;
uint64 blockCount = 2;
uint64 headerCount = 3;
repeated string tipHashes = 4;
double difficulty = 5;
int64 pastMedianTime = 6;
repeated string virtualParentHashes = 7;
RPCError error = 1000;
}
message ResolveFinalityConflictRequestMessage{
string finalityBlockHash = 1;
}
message ResolveFinalityConflictResponseMessage{
RPCError error = 1000;
}
message NotifyFinalityConflictsRequestMessage{
}
message NotifyFinalityConflictsResponseMessage{
RPCError error = 1000;
}
message FinalityConflictNotificationMessage{
string violatingBlockHash = 1;
}
message FinalityConflictResolvedNotificationMessage{
string finalityBlockHash = 1;
}
message ShutDownRequestMessage{
}
message ShutDownResponseMessage{
RPCError error = 1000;
}
message GetHeadersRequestMessage{
string startHash = 1;
uint64 limit = 2;
bool isAscending = 3;
}
message GetHeadersResponseMessage{
repeated string headers = 1;
RPCError error = 1000;
}
message NotifyUtxosChangedRequestMessage {
repeated string addresses = 1;
}
message NotifyUtxosChangedResponseMessage {
RPCError error = 1000;
}
message UtxosChangedNotificationMessage {
repeated UtxosByAddressesEntry added = 1;
repeated UtxosByAddressesEntry removed = 2;
}
message UtxosByAddressesEntry {
string address = 1;
RpcOutpoint outpoint = 2;
RpcUtxoEntry utxoEntry = 3;
}
message RpcTransaction {
int32 version = 1;
repeated RpcTransactionInput inputs = 2;
repeated RpcTransactionOutput outputs = 3;
uint64 lockTime = 4;
string subnetworkId = 5;
uint64 gas = 6;
string payloadHash = 7;
string payload = 8;
}
message RpcTransactionInput {
RpcOutpoint previousOutpoint = 1;
string signatureScript = 2;
uint64 sequence = 3;
}
message RpcTransactionOutput {
uint64 amount = 1;
string scriptPubKey = 2;
}
message RpcOutpoint {
string transactionId = 1;
uint32 index = 2;
}
message RpcUtxoEntry {
uint64 amount = 1;
string scriptPubKey = 2;
uint64 blockBlueScore = 3;
bool isCoinbase = 4;
}
message GetUtxosByAddressesRequestMessage {
repeated string addresses = 1;
}
message GetUtxosByAddressesResponseMessage {
repeated UtxosByAddressesEntry entries = 1;
RPCError error = 1000;
}
message GetVirtualSelectedParentBlueScoreRequestMessage {
}
message GetVirtualSelectedParentBlueScoreResponseMessage {
uint64 blueScore = 1;
RPCError error = 1000;
}
message NotifyVirtualSelectedParentBlueScoreChangedRequestMessage {
}
message NotifyVirtualSelectedParentBlueScoreChangedResponseMessage {
RPCError error = 1000;
}
message VirtualSelectedParentBlueScoreChangedNotificationMessage {
uint64 virtualSelectedParentBlueScore = 1;
}
service RPC {
rpc MessageStream (stream KaspadMessage) returns (stream KaspadMessage) {}
}