The P2P API is part of the Kaspad software. It is used automatically by any running Kaspad for communicating with the Kaspa network and thus is transparent to Kaspad end-users. The information below is intended for software developers.
- MsgVersion
- MsgVerAck
- When a connection is established with a peer, wait for a MsgVersion.
- Check that this Kaspad is compatible with the peer.
- If it is, send MsgVerAck. If not, disconnect.
- MsgVersion
- MsgVerAck
- When a connection is established with a peer, create a MsgVersion and send it to the peer.
- Wait for a MsgVerAck.
- MsgRequestAddresses
- MsgAddresses
- After receiving a MsgVerAck, send a MsgRequestAddresses to the peer.
- Wait for a MsgAddresses.
- Add the received addresses (if there are any) to the Kaspad's address list.
- MsgRequestAddresses
- MsgAddresses
- Wait for a MsgRequestAddresses.
- When a MsgRequestAddresses is received, compile a list of addresses Kaspad knows of and create a MsgAddresses with this list.
- Send the MsgAddresses to the peer.
The above four messages (Version Receive, Version Send, Address Receive and Address Send) together comprise a handshake between two nodes (Kaspads).
- MsgInvRelayBlock
- MsgRequestRelayBlocks
- MsgBlock
- Wait for a MsgInvRelayBlock.
- When a MsgInvRelayBlock is received, check if this block should be downloaded (e.g, it was not already downloaded in the past from another peer).
- If the block should be downloaded, create a new MsgRequestRelayBlocks and include the hash of the wanted block in it.
- Send the MsgRequestRelayBlocks to the peer.
- Wait for a MsgBlock.
- Try to add the MsgBlock to the DAG.
- If successful, broadcast a MsgInvRelayBlock with the block's hash included.If the block turns out to be invalid, return a MsgReject. If the status of the block is unknown (its ancestors are unknown), save the block and do not broadcast a MsgInvRelayBlock.
- MsgRequestRelayBlocks
- MsgBlock
- Wait for MsgRequestRelayBlocks.
- When a MsgRequestRelayBlocks is received, find the block that corresponds to the hash in the message.
- If the block is not found, ban the peer.
- If the block is found, create a new MsgBlock and add the block corresponding to the hash to it.
- Send the MsgBlock to the peer.
- MsgInvTransaction
- MsgRequestTransactions
- MsgTx
- Wait for MsgInvTransaction.
- When a MsgInvTransaction is received, check if this transaction should be downloaded.
- If the transaction should be downloaded, create a new MsgRequestTransactions and include the hash of the wanted transaction in it.
- Send the MsgRequestTransactions to the peer.
- Wait for a MsgTx.
- Try to add the MsgTx to the mempool.
- If successful, broadcast MsgInvTransaction with the transaction's hash included. If not, return a MsgReject and ban the peer.
- MsgRequestTransactions
- MsgTx
- Wait for MsgRequestTransactions.
- When a MsgRequestTransactions is received, find the transaction that corresponds to the hash in the message.
- If the transaction is not found, ban the peer.
- If the transaction is found, create a new MsgTx and add the transaction corresponding to the hash to it.
- Send the MsgTx to the peer.
- MsgBlockLocator
- MsgIBDBlock
- MsgDoneHeaders
- MsgIBDRootNotFound
- MsgIBDRootUTXOSetAndBlock
- MsgHeader
- MsgSelectedTip
- MsgRequestSelectedTip
- MsgRequestBlockLocator
- MsgRequestHeaders
- MsgRequestNextHeaders
- MsgRequestIBDRootUTXOSetAndBlock
- MsgRequestIBDBlocks
This is the protocol to be used by a node that is far behind to "sync up" quickly with the rest of the network. The flow has not been finalized yet.
- MsgPing
- MsgPong
- Wait for a MsgPing.
- When a MsgPing is received, send back a MsgPong with the same nonce as the one received in the MsgPing.
- MsgPing
- MsgPong
- Every two minutes randomly generate a nonce and send a MsgPing with that nonce included.
- Wait for a MsgPong.
- When a MsgPong is received, compare the nonce in the MsgPong with the one that the Kaspad generated.
- If it is not equal, ban the peer.
- MsgReject
- Wait for a MsgReject.
- When a MsgReject is received, print the included Reason and disconnect the peer.