stasatdaglabs 7f899b0d09
[NOD-1579] Improve the IBD mechanism (#1174)
* [NOD-1579] Remove selected tip hash messages.

* [NOD-1579] Start moving IBD stuff into blockrelay.

* [NOD-1579] Rename relaytransactions to transactionrelay.

* [NOD-1579] Move IBD files into blockrelay.

* [NOD-1579] Remove flow stuff from ibd.go.

* [NOD-1579] Bring back IsInIBD().

* [NOD-1579] Simplify block relay flow.

* [NOD-1579] Check orphan pool for missing parents to avoid unnecessary processing.

* [NOD-1579] Implement processOrphan.

* [NOD-1579] Implement addToOrphanSetAndRequestMissingParents.

* [NOD-1579] Fix TestIBD.

* [NOD-1579] Implement isBlockInOrphanResolutionRange.

* [NOD-1579] Implement limited block locators.

* [NOD-1579] Add some comments.

* [NOD-1579] Specifically check for StatusHeaderOnly in blockrelay.

* [NOD-1579] Simplify runIBDIfNotRunning.

* [NOD-1579] Don't run IBD if it is already running.

* [NOD-1579] Fix a comment.

* [NOD-1579] Rename mode to syncInfo.

* [NOD-1579] Simplify validateAndInsertBlock.

* [NOD-1579] Fix bad SyncStateSynced condition.

* [NOD-1579] Implement validateAgainstSyncStateAndResolveInsertMode.

* [NOD-1579] Use insertModeHeader.

* [NOD-1579] Add logs to TrySetIBDRunning and UnsetIBDRunning.

* [NOD-1579] Implement and use dequeueIncomingMessageAndSkipInvs.

* [NOD-1579] Fix a log.

* [NOD-1579] Fix a bug in createBlockLocator.

* [NOD-1579] Rename a variable.

* [NOD-1579] Fix a slew of bugs in missingBlockBodyHashes and selectedChildIterator.

* [NOD-1579] Fix bad chunk size in syncMissingBlockBodies.

* [NOD-1579] Remove maxOrphanBlueScoreDiff.

* [NOD-1579] Fix merge errors.

* [NOD-1579] Remove a debug log.

* [NOD-1579] Add logs.

* [NOD-1579] Make various go quality tools happy.

* [NOD-1579] Fix a typo in a variable name.

* [NOD-1579] Fix full blocks over header-only blocks not failing the missing-parents validation.

* [NOD-1579] Add an error log about a condition that should never happen.

* [NOD-1579] Check all antiPast hashes instead of just the lowHash's anticone to filter for header-only blocks.

* [NOD-1579] Remove the nil stuff from GetBlockLocator.

* [NOD-1579] Remove superfluous condition in handleRelayInvsFlow.start().

* [NOD-1579] Return a boolean from requestBlock instead of comparing to nil.

* [NOD-1579] Fix a bad log.Debugf.

* [NOD-1579] Remove a redundant check.

* [NOD-1579] Change an info log to a warning log.

* [NOD-1579] Move OnNewBlock out of relayBlock.

* [NOD-1579] Remove redundant exists check from runIBDIfNotRunning.

* [NOD-1579] Fix bad call to OnNewBlock.

* [NOD-1579] Remove an impossible check.

* [NOD-1579] Added a log.

* [NOD-1579] Rename insertModeBlockWithoutUpdatingVirtual to insertModeBlockBody.

* [NOD-1579] Add a check for duplicate headers.

* [NOD-1579] Added a comment.

* [NOD-1579] Tighten a stop condition.

* [NOD-1579] Simplify a log.

* [NOD-1579] Clarify a log.

* [NOD-1579] Move a log.
2020-12-06 16:23:56 +02:00

616 lines
15 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;
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;
NotifyChainChangedRequestMessage notifyChainChangedRequest = 1022;
NotifyChainChangedResponseMessage notifyChainChangedResponse = 1023;
ChainChangedNotificationMessage chainChangedNotification = 1024;
GetBlockRequestMessage getBlockRequest = 1025;
GetBlockResponseMessage getBlockResponse = 1026;
GetSubnetworkRequestMessage getSubnetworkRequest = 1027;
GetSubnetworkResponseMessage getSubnetworkResponse = 1028;
GetChainFromBlockRequestMessage getChainFromBlockRequest = 1029;
GetChainFromBlockResponseMessage getChainFromBlockResponse = 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 = 10347;
GetHeadersResponseMessage getHeadersResponse = 1048;
}
}
/////////////////////////////////////////////////////////////////////////////
// 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
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;
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{
TransactionMessage transaction = 1;
}
message SubmitTransactionResponseMessage{
string txId = 1;
RPCError error = 1000;
}
message NotifyChainChangedRequestMessage{
}
message NotifyChainChangedResponseMessage{
RPCError error = 1000;
}
message ChainChangedNotificationMessage{
repeated string removedChainBlockHashes = 1;
repeated ChainBlock addedChainBlocks = 2;
}
message ChainBlock{
string hash = 1;
repeated AcceptedBlock acceptedBlocks = 2;
}
message AcceptedBlock{
string hash = 1;
repeated string acceptedTxIds = 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;
}
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 GetChainFromBlockRequestMessage{
string startHash = 1;
bool includeBlockVerboseData = 2;
}
message GetChainFromBlockResponseMessage{
repeated string removedChainBlockHashes = 1;
repeated ChainBlock addedChainBlocks = 2;
repeated BlockVerboseData blockVerboseData = 3;
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;
RPCError error = 1000;
}
message GetBlockDagInfoRequestMessage{
}
message GetBlockDagInfoResponseMessage{
string networkName = 1;
uint64 blockCount = 2;
repeated string tipHashes = 3;
double difficulty = 4;
int64 pastMedianTime = 5;
repeated string virtualParentHashes = 6;
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;
}
service RPC {
rpc MessageStream (stream KaspadMessage) returns (stream KaspadMessage) {}
}