-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter redundant blocks from daa window (#1925)
* Copy blockrelay flows to v4 * Remove duplicate sending of the same DAA blocks * Advance testnet version * Renames and add comments * Add IBD test between v3 and v4 * Fix syncee v4 p2p version * Check if netsync finished with selected tip
- Loading branch information
1 parent
d237960
commit dadacdc
Showing
41 changed files
with
3,683 additions
and
916 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package appmessage | ||
|
||
// MsgBlockWithTrustedDataV4 represents a kaspa BlockWithTrustedDataV4 message | ||
type MsgBlockWithTrustedDataV4 struct { | ||
baseMessage | ||
|
||
Block *MsgBlock | ||
DAAWindowIndices []uint64 | ||
GHOSTDAGDataIndices []uint64 | ||
} | ||
|
||
// Command returns the protocol command string for the message | ||
func (msg *MsgBlockWithTrustedDataV4) Command() MessageCommand { | ||
return CmdBlockWithTrustedDataV4 | ||
} | ||
|
||
// NewMsgBlockWithTrustedDataV4 returns a new MsgBlockWithTrustedDataV4. | ||
func NewMsgBlockWithTrustedDataV4() *MsgBlockWithTrustedDataV4 { | ||
return &MsgBlockWithTrustedDataV4{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package appmessage | ||
|
||
// MsgTrustedData represents a kaspa TrustedData message | ||
type MsgTrustedData struct { | ||
baseMessage | ||
|
||
DAAWindow []*TrustedDataDAAHeader | ||
GHOSTDAGData []*BlockGHOSTDAGDataHashPair | ||
} | ||
|
||
// Command returns the protocol command string for the message | ||
func (msg *MsgTrustedData) Command() MessageCommand { | ||
return CmdTrustedData | ||
} | ||
|
||
// NewMsgTrustedData returns a new MsgTrustedData. | ||
func NewMsgTrustedData() *MsgTrustedData { | ||
return &MsgTrustedData{} | ||
} | ||
|
||
// TrustedDataDAAHeader is an appmessage representation of externalapi.TrustedDataDataDAAHeader | ||
type TrustedDataDAAHeader struct { | ||
Header *MsgBlockHeader | ||
GHOSTDAGData *BlockGHOSTDAGData | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package blockrelay | ||
|
||
import ( | ||
"github.com/kaspanet/kaspad/app/appmessage" | ||
"github.com/kaspanet/kaspad/app/protocol/common" | ||
"github.com/kaspanet/kaspad/app/protocol/protocolerrors" | ||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi" | ||
) | ||
|
||
func (flow *handleRelayInvsFlow) sendGetBlockLocator(highHash *externalapi.DomainHash, limit uint32) error { | ||
msgGetBlockLocator := appmessage.NewMsgRequestBlockLocator(highHash, limit) | ||
return flow.outgoingRoute.Enqueue(msgGetBlockLocator) | ||
} | ||
|
||
func (flow *handleRelayInvsFlow) receiveBlockLocator() (blockLocatorHashes []*externalapi.DomainHash, err error) { | ||
message, err := flow.dequeueIncomingMessageAndSkipInvs(common.DefaultTimeout) | ||
if err != nil { | ||
return nil, err | ||
} | ||
msgBlockLocator, ok := message.(*appmessage.MsgBlockLocator) | ||
if !ok { | ||
return nil, | ||
protocolerrors.Errorf(true, "received unexpected message type. "+ | ||
"expected: %s, got: %s", appmessage.CmdBlockLocator, message.Command()) | ||
} | ||
return msgBlockLocator.BlockLocatorHashes, nil | ||
} |
86 changes: 86 additions & 0 deletions
86
app/protocol/flows/v4/blockrelay/handle_ibd_block_locator.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package blockrelay | ||
|
||
import ( | ||
"github.com/kaspanet/kaspad/app/appmessage" | ||
"github.com/kaspanet/kaspad/app/protocol/peer" | ||
"github.com/kaspanet/kaspad/app/protocol/protocolerrors" | ||
"github.com/kaspanet/kaspad/domain" | ||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi" | ||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router" | ||
) | ||
|
||
// HandleIBDBlockLocatorContext is the interface for the context needed for the HandleIBDBlockLocator flow. | ||
type HandleIBDBlockLocatorContext interface { | ||
Domain() domain.Domain | ||
} | ||
|
||
// HandleIBDBlockLocator listens to appmessage.MsgIBDBlockLocator messages and sends | ||
// the highest known block that's in the selected parent chain of `targetHash` to the | ||
// requesting peer. | ||
func HandleIBDBlockLocator(context HandleIBDBlockLocatorContext, incomingRoute *router.Route, | ||
outgoingRoute *router.Route, peer *peer.Peer) error { | ||
|
||
for { | ||
message, err := incomingRoute.Dequeue() | ||
if err != nil { | ||
return err | ||
} | ||
ibdBlockLocatorMessage := message.(*appmessage.MsgIBDBlockLocator) | ||
|
||
targetHash := ibdBlockLocatorMessage.TargetHash | ||
log.Debugf("Received IBDBlockLocator from %s with targetHash %s", peer, targetHash) | ||
|
||
blockInfo, err := context.Domain().Consensus().GetBlockInfo(targetHash) | ||
if err != nil { | ||
return err | ||
} | ||
if !blockInfo.Exists { | ||
return protocolerrors.Errorf(true, "received IBDBlockLocator "+ | ||
"with an unknown targetHash %s", targetHash) | ||
} | ||
|
||
foundHighestHashInTheSelectedParentChainOfTargetHash := false | ||
for _, blockLocatorHash := range ibdBlockLocatorMessage.BlockLocatorHashes { | ||
blockInfo, err := context.Domain().Consensus().GetBlockInfo(blockLocatorHash) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// The IBD block locator is checking only existing blocks with bodies. | ||
if !blockInfo.Exists || blockInfo.BlockStatus == externalapi.StatusHeaderOnly { | ||
continue | ||
} | ||
|
||
isBlockLocatorHashInSelectedParentChainOfHighHash, err := | ||
context.Domain().Consensus().IsInSelectedParentChainOf(blockLocatorHash, targetHash) | ||
if err != nil { | ||
return err | ||
} | ||
if !isBlockLocatorHashInSelectedParentChainOfHighHash { | ||
continue | ||
} | ||
|
||
foundHighestHashInTheSelectedParentChainOfTargetHash = true | ||
log.Debugf("Found a known hash %s amongst peer %s's "+ | ||
"blockLocator that's in the selected parent chain of targetHash %s", blockLocatorHash, peer, targetHash) | ||
|
||
ibdBlockLocatorHighestHashMessage := appmessage.NewMsgIBDBlockLocatorHighestHash(blockLocatorHash) | ||
err = outgoingRoute.Enqueue(ibdBlockLocatorHighestHashMessage) | ||
if err != nil { | ||
return err | ||
} | ||
break | ||
} | ||
|
||
if !foundHighestHashInTheSelectedParentChainOfTargetHash { | ||
log.Warnf("no hash was found in the blockLocator "+ | ||
"that was in the selected parent chain of targetHash %s", targetHash) | ||
|
||
ibdBlockLocatorHighestHashNotFoundMessage := appmessage.NewMsgIBDBlockLocatorHighestHashNotFound() | ||
err = outgoingRoute.Enqueue(ibdBlockLocatorHighestHashNotFoundMessage) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/protocol/flows/v4/blockrelay/handle_ibd_block_requests.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package blockrelay | ||
|
||
import ( | ||
"github.com/kaspanet/kaspad/app/appmessage" | ||
"github.com/kaspanet/kaspad/app/protocol/protocolerrors" | ||
"github.com/kaspanet/kaspad/domain" | ||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi" | ||
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// HandleIBDBlockRequestsContext is the interface for the context needed for the HandleIBDBlockRequests flow. | ||
type HandleIBDBlockRequestsContext interface { | ||
Domain() domain.Domain | ||
} | ||
|
||
// HandleIBDBlockRequests listens to appmessage.MsgRequestRelayBlocks messages and sends | ||
// their corresponding blocks to the requesting peer. | ||
func HandleIBDBlockRequests(context HandleIBDBlockRequestsContext, incomingRoute *router.Route, | ||
outgoingRoute *router.Route) error { | ||
|
||
for { | ||
message, err := incomingRoute.Dequeue() | ||
if err != nil { | ||
return err | ||
} | ||
msgRequestIBDBlocks := message.(*appmessage.MsgRequestIBDBlocks) | ||
log.Debugf("Got request for %d ibd blocks", len(msgRequestIBDBlocks.Hashes)) | ||
for i, hash := range msgRequestIBDBlocks.Hashes { | ||
// Fetch the block from the database. | ||
blockInfo, err := context.Domain().Consensus().GetBlockInfo(hash) | ||
if err != nil { | ||
return err | ||
} | ||
if !blockInfo.Exists || blockInfo.BlockStatus == externalapi.StatusHeaderOnly { | ||
return protocolerrors.Errorf(true, "block %s not found", hash) | ||
} | ||
block, err := context.Domain().Consensus().GetBlock(hash) | ||
if err != nil { | ||
return errors.Wrapf(err, "unable to fetch requested block hash %s", hash) | ||
} | ||
|
||
// TODO (Partial nodes): Convert block to partial block if needed | ||
|
||
blockMessage := appmessage.DomainBlockToMsgBlock(block) | ||
ibdBlockMessage := appmessage.NewMsgIBDBlock(blockMessage) | ||
err = outgoingRoute.Enqueue(ibdBlockMessage) | ||
if err != nil { | ||
return err | ||
} | ||
log.Debugf("sent %d out of %d", i+1, len(msgRequestIBDBlocks.Hashes)) | ||
} | ||
} | ||
} |
Oops, something went wrong.